]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/debug.c
60b1f107cc811c7806d5ea3532ef5e79b048d872
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
59 #include <mach_assert.h>
61 #include <mach_kgdb.h>
64 #include <kern/cpu_number.h>
65 #include <kern/lock.h>
67 #include <kern/thread.h>
68 #include <kern/assert.h>
69 #include <kern/sched_prim.h>
70 #include <kern/misc_protos.h>
71 #include <vm/vm_kern.h>
76 #include <ppc/Firmware.h>
77 #include <ppc/low_trace.h>
80 unsigned int halt_in_debugger
= 0;
81 unsigned int switch_debugger
= 0;
82 unsigned int current_debugger
= 0;
83 unsigned int active_debugger
= 0;
84 unsigned int debug_mode
=0;
85 unsigned int disableDebugOuput
= TRUE
;
86 unsigned int systemLogDiags
= FALSE
;
87 unsigned int logPanicDataToScreen
= FALSE
;
88 unsigned int panicDebugging
= FALSE
;
92 const char *panicstr
= (char *) 0;
93 decl_simple_lock_data(,panic_lock
)
95 volatile int panicwait
;
96 volatile unsigned int nestedpanic
= 0;
97 unsigned int panic_is_inited
= 0;
98 unsigned int return_on_panic
= 0;
99 unsigned long panic_caller
;
102 ppnum_t debug_buf_page
;
104 unsigned int debug_buf_size
= 0;
110 const char *expression
)
115 panic("{%d} Assertion failed: file \"%s\", line %d: %s\n",
116 cpu_number(), file
, line
, expression
);
120 * Carefully use the panic_lock. There's always a chance that
121 * somehow we'll call panic before getting to initialize the
122 * panic_lock -- in this case, we'll assume that the world is
123 * in uniprocessor mode and just avoid using the panic lock.
125 #define PANIC_LOCK() \
127 if (panic_is_inited) \
128 simple_lock(&panic_lock); \
131 #define PANIC_UNLOCK() \
133 if (panic_is_inited) \
134 simple_unlock(&panic_lock); \
141 simple_lock_init(&panic_lock
, 0);
147 panic(const char *str
, ...)
155 disable_preemption();
158 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
161 thread
= current_thread(); /* Get failing thread */
162 wq
= thread
->wait_queue
; /* Save the old value */
163 thread
->wait_queue
= 0; /* Clear the wait so we do not get double panics when we try locks */
165 if( logPanicDataToScreen
)
166 disableDebugOuput
= FALSE
;
170 /* panic_caller is initialized to 0. If set, don't change it */
171 if ( ! panic_caller
)
172 panic_caller
= (unsigned long) __builtin_return_address(0);
177 if (cpu_number() != paniccpu
) {
180 * Wait until message has been printed to identify correct
181 * cpu that made the first panic.
189 Debugger("double panic");
190 printf("double panic: We are hanging here...\n");
196 paniccpu
= cpu_number();
200 kdb_printf("panic(cpu %d caller 0x%08X): ", (unsigned) paniccpu
, panic_caller
);
201 va_start(listp
, str
);
202 _doprnt(str
, &listp
, consdebug_putc
, 0);
207 * Release panicwait indicator so that other cpus may call Debugger().
212 * Release panicstr so that we can handle normally other panics.
215 panicstr
= (char *)0;
217 thread
->wait_queue
= wq
; /* Restore the wait queue */
218 if (return_on_panic
) {
223 kdb_printf("panic: We are hanging here...\n");
229 log(int level
, char *fmt
, ...)
237 disable_preemption();
238 va_start(listp
, fmt
);
239 _doprnt(fmt
, &listp
, conslog_putc
, 0);
248 if (debug_buf_size
!= 0)
250 if (kmem_alloc(kernel_map
, (vm_offset_t
*) &debug_buf
, PAGE_SIZE
) != KERN_SUCCESS
)
251 panic("cannot allocate debug_buf \n");
252 debug_buf_ptr
= debug_buf
;
253 debug_buf_size
= PAGE_SIZE
;
254 debug_buf_page
= pmap_find_phys(kernel_pmap
, (addr64_t
)(uintptr_t)debug_buf_ptr
);
260 if ((debug_buf_size
!= 0) && ((debug_buf_ptr
-debug_buf
) < debug_buf_size
)) {