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