FreeBSD/Linux Kernel Cross Reference
sys/kern/debug.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993-1989 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: debug.c,v $
29 * Revision 2.24 93/11/17 17:08:08 dbg
30 * ANSI-fied.
31 * [93/06/16 dbg]
32 *
33 * Revision 2.23 93/01/27 09:34:42 danner
34 * Updated copyright.
35 * [93/01/12 berman]
36 * Changed sun conditional to be sun3, and added sun4 code
37 * in Debugger().
38 * [93/01/11 berman]
39 *
40 * Revision 2.22 93/01/14 17:33:54 danner
41 * Added alpha, simplified.
42 * [92/11/30 af]
43 *
44 * Revision 2.21 92/08/03 17:36:45 jfriedl
45 * removed silly prototypes
46 * Added pc532 support [Johannes Helander (jvh@cs.hut.fi)]
47 * [92/08/02 jfriedl]
48 *
49 * Revision 2.20 92/05/21 17:13:07 jfriedl
50 * Added void type to functions that needed it.
51 * [92/05/16 jfriedl]
52 *
53 * Revision 2.19 92/02/19 11:19:26 elf
54 * Added cpu number print, locking to print in Assert for
55 * multiprocessor case.
56 * [92/01/12 danner]
57 *
58 * Revision 2.18 91/12/10 16:32:45 jsb
59 * Fixes from Intel
60 * [91/12/10 15:51:54 jsb]
61 *
62 * Revision 2.17 91/08/03 18:18:47 jsb
63 * Replaced obsolete NORMA tag with NORMA_IPC.
64 * [91/07/27 18:13:01 jsb]
65 *
66 * Revision 2.16 91/07/31 17:44:28 dbg
67 * Minor SUN changes.
68 * [91/07/12 dbg]
69 *
70 * Revision 2.15 91/07/09 23:16:17 danner
71 * Luna88k support.
72 * [91/06/26 danner]
73 *
74 * Revision 2.14 91/06/17 15:46:57 jsb
75 * Renamed NORMA conditionals.
76 * [91/06/17 10:49:18 jsb]
77 *
78 * Revision 2.13 91/05/14 16:40:46 mrt
79 * Correcting copyright
80 *
81 * Revision 2.12 91/03/16 14:49:39 rpd
82 * In panic, only call halt_cpu when not calling Debugger.
83 * [91/03/12 rpd]
84 *
85 * Revision 2.11 91/02/05 17:25:52 mrt
86 * Changed to new Mach copyright
87 * [91/02/01 16:11:43 mrt]
88 *
89 * Revision 2.10 90/12/14 11:02:02 jsb
90 * NORMA_IPC support: print node number as well as cpu in panic.
91 * [90/12/13 21:40:37 jsb]
92 *
93 * Revision 2.9 90/12/04 14:51:00 jsb
94 * Added i860 support for Debugger function.
95 * [90/12/04 11:01:25 jsb]
96 *
97 * Revision 2.8 90/11/05 14:30:49 rpd
98 * Added Assert.
99 * [90/11/04 rpd]
100 *
101 * Revision 2.7 90/10/25 14:45:10 rwd
102 * Change sun3 debugger invocation.
103 * [90/10/17 rwd]
104 *
105 * Revision 2.6 90/09/09 23:20:09 rpd
106 * Fixed panic and log to supply cnputc to _doprnt.
107 * [90/09/09 rpd]
108 *
109 * Revision 2.5 90/09/09 14:32:03 rpd
110 * Use decl_simple_lock_data.
111 * [90/08/30 rpd]
112 *
113 * Revision 2.4 90/08/27 22:02:14 dbg
114 * Pass extra argument to _doprnt.
115 * [90/08/21 dbg]
116 *
117 * Revision 2.3 90/05/03 15:46:53 dbg
118 * Added i386 case.
119 * [90/02/21 dbg]
120 *
121 * Revision 2.2 89/11/29 14:09:04 af
122 * Added mips case, RCS-ed.
123 * [89/10/28 af]
124 *
125 */
126
127 #include <mach_kdb.h>
128 #include <norma_ipc.h>
129 #include <cpus.h>
130
131 #include <kern/assert.h>
132 #include <kern/cpu_number.h>
133 #include <kern/kern_io.h>
134 #include <kern/lock.h>
135 #include <kern/machine.h>
136 #include <kern/thread.h>
137 #include <sys/stdarg.h>
138
139
140 #if MACH_KDB
141 extern int db_breakpoints_inserted;
142 #endif
143
144 #if NCPUS > 1
145 simple_lock_data_t Assert_print_lock; /* uninited, we take our chances */
146 #endif
147
148 void Assert(
149 const char *file,
150 const int line)
151 {
152 #if NCPUS > 1
153 simple_lock(&Assert_print_lock);
154 printf("{%d} Assertion failed: file \"%s\", line %d\n",
155 cpu_number(), file, line);
156 simple_unlock(&Assert_print_lock);
157 #else
158 printf("Assertion failed: file \"%s\", line %d\n", file, line);
159 #endif
160
161 #if MACH_KDB
162 if (db_breakpoints_inserted)
163 #endif
164 Debugger("assertion failure");
165 }
166
167 void Debugger(
168 const char * message)
169 {
170 #ifdef lint
171 message++;
172 #endif /* lint */
173
174 #if defined(vax) || defined(PC532)
175 asm("bpt");
176 #endif /* vax */
177
178 #ifdef sun3
179 current_thread()->pcb->flag |= TRACE_KDB;
180 asm("orw #0x00008000,sr");
181 #endif /* sun3 */
182 #ifdef sun4
183 current_thread()->pcb->pcb_flag |= TRACE_KDB;
184 asm("ta 0x81");
185 #endif /* sun4 */
186
187 #if defined(mips ) || defined(luna88k) || defined(i860) || defined(alpha)
188 gimmeabreak();
189 #endif
190
191 #ifdef i386
192 asm("int3");
193 #endif
194 }
195
196 const char *panicstr;
197 decl_simple_lock_data(, panic_lock)
198 int paniccpu;
199
200 void
201 panic_init(void)
202 {
203 simple_lock_init(&panic_lock);
204 }
205
206 /*VARARGS1*/
207 void
208 panic(const char *s, ...)
209 {
210 va_list listp;
211 #if NORMA_IPC
212 extern int _node_self; /* node_self() may not be callable yet */
213 #endif /* NORMA_IPC */
214
215 simple_lock(&panic_lock);
216 if (panicstr) {
217 if (cpu_number() != paniccpu) {
218 simple_unlock(&panic_lock);
219 halt_cpu();
220 /* NOTREACHED */
221 }
222 }
223 else {
224 panicstr = s;
225 paniccpu = cpu_number();
226 }
227 simple_unlock(&panic_lock);
228 printf("panic");
229 #if NORMA_IPC
230 printf("(node %U)", _node_self);
231 #endif
232 #if NCPUS > 1
233 printf("(cpu %U)", paniccpu);
234 #endif
235 printf(": ");
236 va_start(listp, s);
237 _doprnt(s, &listp, (void (*)(char, void *))cnputc, 16, 0);
238 va_end(listp);
239 printf("\n");
240
241 #if MACH_KDB
242 Debugger("panic");
243 #else
244 halt_cpu();
245 #endif
246 }
247
248 /*
249 * We'd like to use BSD's log routines here...
250 */
251 /*VARARGS2*/
252 void
253 log(int level, const char *fmt, ...)
254 {
255 va_list listp;
256
257 #ifdef lint
258 level++;
259 #endif
260 va_start(listp, fmt);
261 _doprnt(fmt, &listp, (void (*)(char, void *))cnputc, 16, 0);
262 va_end(listp);
263 }
Cache object: 2040457de297199b0bbc701b77cebcee
|