8 #include "threads/init.h"
9 #include "threads/interrupt.h"
10 #include "devices/serial.h"
15 #define MAX_CLASSES 16
16 static bool all_enabled;
17 static const char *enabled_classes[MAX_CLASSES];
18 static size_t enabled_cnt;
20 static bool class_is_enabled (const char *class);
22 /* Enables the debug message classes specified in CLASSES. The
23 string CLASSES is modified by and becomes owned by this
26 debug_enable (char *classes)
30 for (class = strtok_r (classes, ",", &save); class != NULL;
31 class = strtok_r (NULL, ",", &save))
33 if (strcmp (class, "all") && enabled_cnt < MAX_CLASSES)
34 enabled_classes[enabled_cnt++] = class;
40 /* Prints a debug message along with the source file name, line
41 number, and function name of where it was emitted. CLASS is
42 used to filter out unwanted messages. */
44 debug_message (const char *file, int line, const char *function,
45 const char *class, const char *message, ...)
47 if (class_is_enabled (class))
52 enum intr_level old_level = intr_disable ();
54 printf ("%s:%d: %s(): ", file, line, function);
55 va_start (args, message);
56 vprintf (message, args);
60 intr_set_level (old_level);
65 /* Halts the OS or user program, printing the source file name,
66 line number, and function name, plus a user-specific
69 debug_panic (const char *file, int line, const char *function,
70 const char *message, ...)
79 printf ("Kernel PANIC at %s:%d in %s(): ", file, line, function);
81 printf ("User process panic at %s:%d in %s(): ", file, line, function);
84 va_start (args, message);
85 vprintf (message, args);
91 printf ("The `backtrace' program can make call stacks useful.\n"
92 "Read \"Backtraces\" in the \"Debugging Tools\" chapter\n"
93 "of the Pintos documentation for more information.\n");
97 if (power_off_when_done)
105 /* Prints the call stack, that is, a list of addresses, one in
106 each of the functions we are nested within. gdb or addr2line
107 may be applied to kernel.o to translate these into file names,
108 line numbers, and function names. */
110 debug_backtrace (void)
114 printf ("Call stack:");
115 for (frame = __builtin_frame_address (0);
116 frame != NULL && frame[0] != NULL;
118 printf (" %p", frame[1]);
123 /* Returns true if CLASS is enabled, false otherwise. */
125 class_is_enabled (const char *class)
132 for (i = 0; i < enabled_cnt; i++)
133 if (!strcmp (enabled_classes[i], class))