]>
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>
64 #include <vm/vm_kern.h>
68 #include <ppc/Firmware.h>
69 #include <ppc/low_trace.h>
72 unsigned int halt_in_debugger
= 0;
73 unsigned int switch_debugger
= 0;
74 unsigned int current_debugger
= 0;
75 unsigned int active_debugger
= 0;
76 unsigned int debug_mode
=0;
77 unsigned int disableDebugOuput
= TRUE
;
78 unsigned int systemLogDiags
= FALSE
;
79 unsigned int logPanicDataToScreen
= FALSE
;
81 unsigned int panicDebugging
= FALSE
;
83 unsigned int panicDebugging
= TRUE
;
88 const char *panicstr
= (char *) 0;
89 decl_simple_lock_data(,panic_lock
)
91 volatile int panicwait
;
92 volatile int nestedpanic
= 0;
93 unsigned int panic_is_inited
= 0;
94 unsigned int return_on_panic
= 0;
95 wait_queue_t save_waits
[NCPUS
];
99 unsigned int debug_buf_size
= 0;
105 const char *expression
)
110 panic("{%d} Assertion failed: file \"%s\", line %d: %s\n",
111 cpu_number(), file
, line
, expression
);
115 * Carefully use the panic_lock. There's always a chance that
116 * somehow we'll call panic before getting to initialize the
117 * panic_lock -- in this case, we'll assume that the world is
118 * in uniprocessor mode and just avoid using the panic lock.
120 #define PANIC_LOCK() \
122 if (panic_is_inited) \
123 simple_lock(&panic_lock); \
126 #define PANIC_UNLOCK() \
128 if (panic_is_inited) \
129 simple_unlock(&panic_lock); \
136 simple_lock_init(&panic_lock
, ETAP_NO_TRACE
);
141 panic(const char *str
, ...)
148 disable_preemption();
151 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
154 thread
= current_thread(); /* Get failing thread */
155 save_waits
[cpu_number()] = 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
;
165 if (cpu_number() != paniccpu
) {
168 * Wait until message has been printed to identify correct
169 * cpu that made the first panic.
177 Debugger("double panic");
178 printf("double panic: We are hanging here...\n");
184 paniccpu
= cpu_number();
188 kdb_printf("panic(cpu %d): ", (unsigned) paniccpu
);
189 va_start(listp
, str
);
190 _doprnt(str
, &listp
, consdebug_putc
, 0);
195 * Release panicwait indicator so that other cpus may call Debugger().
200 * Release panicstr so that we can handle normally other panics.
203 panicstr
= (char *)0;
205 thread
->wait_queue
= save_waits
[cpu_number()]; /* Restore the wait queue */
206 if (return_on_panic
) {
211 kdb_printf("panic: We are hanging here...\n");
217 log(int level
, char *fmt
, ...)
225 disable_preemption();
226 va_start(listp
, fmt
);
227 _doprnt(fmt
, &listp
, conslog_putc
, 0);
236 if (debug_buf_size
!= 0)
238 if (kmem_alloc(kernel_map
, (vm_offset_t
*) &debug_buf
, PAGE_SIZE
) != KERN_SUCCESS
)
239 panic("cannot allocate debug_buf \n");
240 debug_buf_ptr
= debug_buf
;
241 debug_buf_size
= PAGE_SIZE
;
247 if ((debug_buf_size
!= 0) && ((debug_buf_ptr
-debug_buf
) < debug_buf_size
)) {