8 #include "threads/interrupt.h"
9 #include "devices/serial.h"
14 #define MAX_CLASSES 16
15 static bool all_enabled;
16 static const char *enabled_classes[MAX_CLASSES];
17 static size_t enabled_cnt;
19 static bool class_is_enabled (const char *class);
21 /* Enables the debug message classes specified in CLASSES. The
22 string CLASSES is modified by and becomes owned by this
25 debug_enable (char *classes)
29 for (class = strtok_r (classes, ",", &save); class != NULL;
30 class = strtok_r (NULL, ",", &save))
32 if (strcmp (class, "all") && enabled_cnt < MAX_CLASSES)
33 enabled_classes[enabled_cnt++] = class;
39 /* Prints a debug message along with the source file name, line
40 number, and function name of where it was emitted. CLASS is
41 used to filter out unwanted messages. */
43 debug_message (const char *file, int line, const char *function,
44 const char *class, const char *message, ...)
46 if (class_is_enabled (class))
51 enum intr_level old_level = intr_disable ();
53 printf ("%s:%d: %s(): ", file, line, function);
54 va_start (args, message);
55 vprintf (message, args);
59 intr_set_level (old_level);
64 /* Halts the OS, printing the source file name, line number, and
65 function name, plus a user-specific message. */
67 debug_panic (const char *file, int line, const char *function,
68 const char *message, ...)
76 printf ("PANIC at %s:%d in %s(): ", file, line, function);
77 va_start (args, message);
78 vprintf (message, args);
92 /* Prints the call stack, that is, a list of addresses, one in
93 each of the functions we are nested within. gdb or addr2line
94 may be applied to kernel.o to translate these into file names,
95 line numbers, and function names. */
97 debug_backtrace (void)
101 printf ("Call stack:");
102 for (frame = __builtin_frame_address (0);
103 frame != NULL && frame[0] != NULL;
105 printf (" %p", frame[1]);
110 /* Returns true if CLASS is enabled, false otherwise. */
112 class_is_enabled (const char *class)
119 for (i = 0; i < enabled_cnt; i++)
120 if (!strcmp (enabled_classes[i], class))