]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/debug.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
51 #include <mach_assert.h>
53 #include <mach_kgdb.h>
57 #include <kern/cpu_number.h>
58 #include <kern/lock.h>
60 #include <kern/thread.h>
61 #include <kern/assert.h>
62 #include <kern/sched_prim.h>
63 #include <kern/misc_protos.h>
66 unsigned int halt_in_debugger
= 0;
67 unsigned int switch_debugger
= 0;
68 unsigned int current_debugger
= 0;
69 unsigned int active_debugger
= 0;
70 unsigned int debug_mode
=0;
71 unsigned int disableDebugOuput
= TRUE
;
72 unsigned int systemLogDiags
= FALSE
;
77 decl_simple_lock_data(,panic_lock
)
79 volatile int panicwait
;
80 volatile int nestedpanic
= 0;
81 unsigned int panic_is_inited
= 0;
82 unsigned int return_on_panic
= 0;
83 wait_queue_t save_waits
[NCPUS
];
89 const char *expression
)
94 panic("{%d} Assertion failed: file \"%s\", line %d: %s\n",
95 cpu_number(), file
, line
, expression
);
99 * Carefully use the panic_lock. There's always a chance that
100 * somehow we'll call panic before getting to initialize the
101 * panic_lock -- in this case, we'll assume that the world is
102 * in uniprocessor mode and just avoid using the panic lock.
104 #define PANIC_LOCK() \
106 if (panic_is_inited) \
107 simple_lock(&panic_lock); \
110 #define PANIC_UNLOCK() \
112 if (panic_is_inited) \
113 simple_unlock(&panic_lock); \
120 simple_lock_init(&panic_lock
, ETAP_NO_TRACE
);
125 panic(const char *str
, ...)
133 thread
= current_thread(); /* Get failing thread */
134 save_waits
[cpu_number()] = thread
->wait_queue
; /* Save the old value */
135 thread
->wait_queue
= 0; /* Clear the wait so we do not get double panics when we try locks */
137 mp_disable_preemption();
138 disableDebugOuput
= FALSE
;
143 if (cpu_number() != paniccpu
) {
146 * Wait until message has been printed to identify correct
147 * cpu that made the first panic.
155 Debugger("double panic");
156 mp_enable_preemption();
158 printf("double panic: We are hanging here...\n");
164 paniccpu
= cpu_number();
168 printf("panic(cpu %d): ", (unsigned) paniccpu
);
169 va_start(listp
, str
);
170 _doprnt(str
, &listp
, cnputc
, 0);
175 * Release panicwait indicator so that other cpus may call Debugger().
180 * Release panicstr so that we can handle normally other panics.
183 panicstr
= (char *)0;
185 mp_enable_preemption();
187 thread
->wait_queue
= save_waits
[cpu_number()]; /* Restore the wait queue */
190 printf("panic: We are hanging here...\n");
196 log(int level
, char *fmt
, ...)
199 extern void conslog_putc(char);
205 disable_preemption();
206 va_start(listp
, fmt
);
207 _doprnt(fmt
, &listp
, conslog_putc
, 0);