93c395208068801dcdbca3b4dffbec7b64c74712
[pintos-anon] / src / lib / kernel / debug.c
1 #include <debug.h>
2 #include <console.h>
3 #include <stdarg.h>
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include "threads/init.h"
9 #include "threads/interrupt.h"
10 #include "devices/serial.h"
11
12 /* Halts the OS, printing the source file name, line number, and
13    function name, plus a user-specific message. */
14 void
15 debug_panic (const char *file, int line, const char *function,
16              const char *message, ...)
17 {
18   static int level;
19   va_list args;
20
21   intr_disable ();
22   console_panic ();
23
24   level++;
25   if (level == 1) 
26     {
27       printf ("Kernel PANIC at %s:%d in %s(): ", file, line, function);
28
29       va_start (args, message);
30       vprintf (message, args);
31       printf ("\n");
32       va_end (args);
33
34       debug_backtrace ();
35     }
36   else if (level == 2)
37     printf ("Kernel PANIC recursion at %s:%d in %s().\n",
38             file, line, function);
39   else 
40     {
41       /* Don't print anything: that's probably why we recursed. */
42     }
43
44   serial_flush ();
45   if (power_off_when_done)
46     power_off ();
47   for (;;);
48 }