]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/debug.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
57 #include <mach_assert.h>
59 #include <mach_kgdb.h>
62 #include <kern/cpu_number.h>
63 #include <kern/lock.h>
65 #include <kern/thread.h>
66 #include <kern/assert.h>
67 #include <kern/sched_prim.h>
68 #include <kern/misc_protos.h>
69 #include <vm/vm_kern.h>
74 #include <ppc/Firmware.h>
75 #include <ppc/low_trace.h>
78 unsigned int halt_in_debugger
= 0;
79 unsigned int switch_debugger
= 0;
80 unsigned int current_debugger
= 0;
81 unsigned int active_debugger
= 0;
82 unsigned int debug_mode
=0;
83 unsigned int disableDebugOuput
= TRUE
;
84 unsigned int systemLogDiags
= FALSE
;
85 unsigned int logPanicDataToScreen
= FALSE
;
86 unsigned int panicDebugging
= FALSE
;
90 const char *panicstr
= (char *) 0;
91 decl_simple_lock_data(,panic_lock
)
93 volatile int panicwait
;
94 volatile unsigned int nestedpanic
= 0;
95 unsigned int panic_is_inited
= 0;
96 unsigned int return_on_panic
= 0;
97 unsigned long panic_caller
;
100 ppnum_t debug_buf_page
;
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
, 0);
145 panic(const char *str
, ...)
153 disable_preemption();
156 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
159 thread
= current_thread(); /* Get failing thread */
160 wq
= thread
->wait_queue
; /* Save the old value */
161 thread
->wait_queue
= 0; /* Clear the wait so we do not get double panics when we try locks */
163 if( logPanicDataToScreen
)
164 disableDebugOuput
= FALSE
;
168 /* panic_caller is initialized to 0. If set, don't change it */
169 if ( ! panic_caller
)
170 panic_caller
= (unsigned long) __builtin_return_address(0);
175 if (cpu_number() != paniccpu
) {
178 * Wait until message has been printed to identify correct
179 * cpu that made the first panic.
187 Debugger("double panic");
188 printf("double panic: We are hanging here...\n");
194 paniccpu
= cpu_number();
198 kdb_printf("panic(cpu %d caller 0x%08X): ", (unsigned) paniccpu
, panic_caller
);
199 va_start(listp
, str
);
200 _doprnt(str
, &listp
, consdebug_putc
, 0);
205 * Release panicwait indicator so that other cpus may call Debugger().
210 * Release panicstr so that we can handle normally other panics.
213 panicstr
= (char *)0;
215 thread
->wait_queue
= wq
; /* Restore the wait queue */
216 if (return_on_panic
) {
221 kdb_printf("panic: We are hanging here...\n");
227 log(int level
, char *fmt
, ...)
235 disable_preemption();
236 va_start(listp
, fmt
);
237 _doprnt(fmt
, &listp
, conslog_putc
, 0);
246 if (debug_buf_size
!= 0)
248 if (kmem_alloc(kernel_map
, (vm_offset_t
*) &debug_buf
, PAGE_SIZE
) != KERN_SUCCESS
)
249 panic("cannot allocate debug_buf \n");
250 debug_buf_ptr
= debug_buf
;
251 debug_buf_size
= PAGE_SIZE
;
252 debug_buf_page
= pmap_find_phys(kernel_pmap
, (addr64_t
)(uintptr_t)debug_buf_ptr
);
258 if ((debug_buf_size
!= 0) && ((debug_buf_ptr
-debug_buf
) < debug_buf_size
)) {