8 #include "threads/interrupt.h"
13 #define MAX_CLASSES 16
14 static bool all_enabled;
15 static const char *enabled_classes[MAX_CLASSES];
16 static size_t enabled_cnt;
18 static bool class_is_enabled (const char *class);
20 /* Enables the debug message classes specified in CLASSES. The
21 string CLASSES is modified by and becomes owned by this
24 debug_enable (char *classes)
28 for (class = strtok_r (classes, ",", &save); class != NULL;
29 class = strtok_r (NULL, ",", &save))
31 if (strcmp (class, "all") && enabled_cnt < MAX_CLASSES)
32 enabled_classes[enabled_cnt++] = class;
38 /* Prints a debug message along with the source file name, line
39 number, and function name of where it was emitted. CLASS is
40 used to filter out unwanted messages. */
42 debug_message (const char *file, int line, const char *function,
43 const char *class, const char *message, ...)
45 if (class_is_enabled (class))
50 enum intr_level old_level = intr_disable ();
52 printf ("%s:%d: %s(): ", file, line, function);
53 va_start (args, message);
54 vprintf (message, args);
58 intr_set_level (old_level);
63 /* Halts the OS, printing the source file name, line number, and
64 function name, plus a user-specific message. */
66 debug_panic (const char *file, int line, const char *function,
67 const char *message, ...)
75 printf ("PANIC at %s:%d in %s(): ", file, line, function);
76 va_start (args, message);
77 vprintf (message, args);
90 /* Prints the call stack, that is, a list of addresses, one in
91 each of the functions we are nested within. gdb or addr2line
92 may be applied to kernel.o to translate these into file names,
93 line numbers, and function names. */
95 debug_backtrace (void)
99 printf ("Call stack:");
100 for (frame = __builtin_frame_address (0);
101 frame != NULL && frame[0] != NULL;
103 printf (" %p", frame[1]);
108 /* Returns true if CLASS is enabled, false otherwise. */
110 class_is_enabled (const char *class)
117 for (i = 0; i < enabled_cnt; i++)
118 if (!strcmp (enabled_classes[i], class))