]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/debug.c
49bbc8ca0a61e8e8c53db36127db56767a03ba62
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
52 #include <mach_assert.h>
54 #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>
64 #include <vm/vm_kern.h>
69 #include <ppc/Firmware.h>
70 #include <ppc/low_trace.h>
73 unsigned int halt_in_debugger
= 0;
74 unsigned int switch_debugger
= 0;
75 unsigned int current_debugger
= 0;
76 unsigned int active_debugger
= 0;
77 unsigned int debug_mode
=0;
78 unsigned int disableDebugOuput
= TRUE
;
79 unsigned int systemLogDiags
= FALSE
;
80 unsigned int logPanicDataToScreen
= FALSE
;
81 unsigned int panicDebugging
= FALSE
;
85 const char *panicstr
= (char *) 0;
86 decl_simple_lock_data(,panic_lock
)
88 volatile int panicwait
;
89 volatile unsigned int nestedpanic
= 0;
90 unsigned int panic_is_inited
= 0;
91 unsigned int return_on_panic
= 0;
92 unsigned long panic_caller
;
95 ppnum_t debug_buf_page
;
97 unsigned int debug_buf_size
= 0;
103 const char *expression
)
108 panic("{%d} Assertion failed: file \"%s\", line %d: %s\n",
109 cpu_number(), file
, line
, expression
);
113 * Carefully use the panic_lock. There's always a chance that
114 * somehow we'll call panic before getting to initialize the
115 * panic_lock -- in this case, we'll assume that the world is
116 * in uniprocessor mode and just avoid using the panic lock.
118 #define PANIC_LOCK() \
120 if (panic_is_inited) \
121 simple_lock(&panic_lock); \
124 #define PANIC_UNLOCK() \
126 if (panic_is_inited) \
127 simple_unlock(&panic_lock); \
134 simple_lock_init(&panic_lock
, 0);
140 panic(const char *str
, ...)
148 disable_preemption();
151 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
154 thread
= current_thread(); /* Get failing thread */
155 wq
= thread
->wait_queue
; /* Save the old value */
156 thread
->wait_queue
= 0; /* Clear the wait so we do not get double panics when we try locks */
158 if( logPanicDataToScreen
)
159 disableDebugOuput
= FALSE
;
163 /* panic_caller is initialized to 0. If set, don't change it */
164 if ( ! panic_caller
)
165 panic_caller
= (unsigned long) __builtin_return_address(0);
170 if (cpu_number() != paniccpu
) {
173 * Wait until message has been printed to identify correct
174 * cpu that made the first panic.
182 Debugger("double panic");
183 printf("double panic: We are hanging here...\n");
189 paniccpu
= cpu_number();
193 kdb_printf("panic(cpu %d caller 0x%08X): ", (unsigned) paniccpu
, panic_caller
);
194 va_start(listp
, str
);
195 _doprnt(str
, &listp
, consdebug_putc
, 0);
200 * Release panicwait indicator so that other cpus may call Debugger().
205 * Release panicstr so that we can handle normally other panics.
208 panicstr
= (char *)0;
210 thread
->wait_queue
= wq
; /* Restore the wait queue */
211 if (return_on_panic
) {
216 kdb_printf("panic: We are hanging here...\n");
222 log(int level
, char *fmt
, ...)
230 disable_preemption();
231 va_start(listp
, fmt
);
232 _doprnt(fmt
, &listp
, conslog_putc
, 0);
241 if (debug_buf_size
!= 0)
243 if (kmem_alloc(kernel_map
, (vm_offset_t
*) &debug_buf
, PAGE_SIZE
) != KERN_SUCCESS
)
244 panic("cannot allocate debug_buf \n");
245 debug_buf_ptr
= debug_buf
;
246 debug_buf_size
= PAGE_SIZE
;
247 debug_buf_page
= pmap_find_phys(kernel_pmap
, (addr64_t
)(uintptr_t)debug_buf_ptr
);
253 if ((debug_buf_size
!= 0) && ((debug_buf_ptr
-debug_buf
) < debug_buf_size
)) {