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 or user program, printing the source file name,
65 line number, and function name, plus a user-specific
68 debug_panic (const char *file, int line, const char *function,
69 const char *message, ...)
78 printf ("Kernel PANIC at %s:%d in %s(): ", file, line, function);
80 printf ("User process panic at %s:%d in %s(): ", file, line, function);
83 va_start (args, message);
84 vprintf (message, args);
98 /* Prints the call stack, that is, a list of addresses, one in
99 each of the functions we are nested within. gdb or addr2line
100 may be applied to kernel.o to translate these into file names,
101 line numbers, and function names. */
103 debug_backtrace (void)
107 printf ("Call stack:");
108 for (frame = __builtin_frame_address (0);
109 frame != NULL && frame[0] != NULL;
111 printf (" %p", frame[1]);
116 /* Returns true if CLASS is enabled, false otherwise. */
118 class_is_enabled (const char *class)
125 for (i = 0; i < enabled_cnt; i++)
126 if (!strcmp (enabled_classes[i], class))