]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
54 #include <mach_assert.h>
56 #include <mach_kgdb.h>
60 #include <kern/cpu_number.h>
61 #include <kern/lock.h>
63 #include <kern/thread.h>
64 #include <kern/assert.h>
65 #include <kern/sched_prim.h>
66 #include <kern/misc_protos.h>
67 #include <vm/vm_kern.h>
71 #include <ppc/Firmware.h>
72 #include <ppc/low_trace.h>
75 unsigned int halt_in_debugger
= 0;
76 unsigned int switch_debugger
= 0;
77 unsigned int current_debugger
= 0;
78 unsigned int active_debugger
= 0;
79 unsigned int debug_mode
=0;
80 unsigned int disableDebugOuput
= TRUE
;
81 unsigned int systemLogDiags
= FALSE
;
82 unsigned int logPanicDataToScreen
= FALSE
;
84 unsigned int panicDebugging
= FALSE
;
86 unsigned int panicDebugging
= TRUE
;
91 const char *panicstr
= (char *) 0;
92 decl_simple_lock_data(,panic_lock
)
94 volatile int panicwait
;
95 volatile int nestedpanic
= 0;
96 unsigned int panic_is_inited
= 0;
97 unsigned int return_on_panic
= 0;
98 wait_queue_t save_waits
[NCPUS
];
102 unsigned int debug_buf_size
= 0;
108 const char *expression
)
113 panic("{%d} Assertion failed: file \"%s\", line %d: %s\n",
114 cpu_number(), file
, line
, expression
);
118 * Carefully use the panic_lock. There's always a chance that
119 * somehow we'll call panic before getting to initialize the
120 * panic_lock -- in this case, we'll assume that the world is
121 * in uniprocessor mode and just avoid using the panic lock.
123 #define PANIC_LOCK() \
125 if (panic_is_inited) \
126 simple_lock(&panic_lock); \
129 #define PANIC_UNLOCK() \
131 if (panic_is_inited) \
132 simple_unlock(&panic_lock); \
139 simple_lock_init(&panic_lock
, ETAP_NO_TRACE
);
144 panic(const char *str
, ...)
151 disable_preemption();
154 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
157 thread
= current_thread(); /* Get failing thread */
158 save_waits
[cpu_number()] = thread
->wait_queue
; /* Save the old value */
159 thread
->wait_queue
= 0; /* Clear the wait so we do not get double panics when we try locks */
161 if( logPanicDataToScreen
)
162 disableDebugOuput
= FALSE
;
168 if (cpu_number() != paniccpu
) {
171 * Wait until message has been printed to identify correct
172 * cpu that made the first panic.
180 Debugger("double panic");
181 printf("double panic: We are hanging here...\n");
187 paniccpu
= cpu_number();
191 kdb_printf("panic(cpu %d): ", (unsigned) paniccpu
);
192 va_start(listp
, str
);
193 _doprnt(str
, &listp
, consdebug_putc
, 0);
198 * Release panicwait indicator so that other cpus may call Debugger().
203 * Release panicstr so that we can handle normally other panics.
206 panicstr
= (char *)0;
208 thread
->wait_queue
= save_waits
[cpu_number()]; /* Restore the wait queue */
209 if (return_on_panic
) {
214 kdb_printf("panic: We are hanging here...\n");
220 log(int level
, char *fmt
, ...)
228 disable_preemption();
229 va_start(listp
, fmt
);
230 _doprnt(fmt
, &listp
, conslog_putc
, 0);
239 if (debug_buf_size
!= 0)
241 if (kmem_alloc(kernel_map
, (vm_offset_t
*) &debug_buf
, PAGE_SIZE
) != KERN_SUCCESS
)
242 panic("cannot allocate debug_buf \n");
243 debug_buf_ptr
= debug_buf
;
244 debug_buf_size
= PAGE_SIZE
;
250 if ((debug_buf_size
!= 0) && ((debug_buf_ptr
-debug_buf
) < debug_buf_size
)) {