7 static bool all_enabled;
8 static const char *enabled_classes[MAX_CLASSES];
9 static size_t enabled_cnt;
11 /* Enables the debug message classes specified in CLASSES. The
12 string CLASSES is modified by and becomes owned by this
15 debug_enable (char *classes)
19 for (class = strtok_r (classes, ",", &save); class != NULL;
20 class = strtok_r (NULL, ",", &save))
22 if (strcmp (class, "all") && enabled_cnt < MAX_CLASSES)
23 enabled_classes[enabled_cnt++] = class;
29 /* Checks whether CLASS is enabled. */
31 class_is_enabled (const char *class)
38 for (i = 0; i < enabled_cnt; i++)
39 if (!strcmp (enabled_classes[i], class))
45 /* Prints a debug message along with the source file name, line
46 number, and function name of where it was emitted. CLASS is
47 used to filter out unwanted messages. */
49 debug_message (const char *file, int line, const char *function,
50 const char *class, const char *message, ...)
52 if (class_is_enabled (class))
56 enum if_level old_level = intr_disable ();
57 printk ("%s:%d: %s(): ", file, line, function);
58 va_start (args, message);
59 vprintk (message, args);
62 intr_set_level (old_level);
66 /* Halts the OS, printing the source file name, line number, and
67 function name, plus a user-specific message. */
69 debug_panic (const char *file, int line, const char *function,
70 const char *message, ...)
76 printk ("PANIC at %s:%d in %s(): ", file, line, function);
77 va_start (args, message);
78 vprintk (message, args);
87 /* Prints the call stack, that is, a list of addresses in each of
88 the functions we are nested within. gdb or addr2line may be
89 applied to kernel.o to translate these into file names, line
90 numbers, and function names. */
92 debug_backtrace (void)
96 printk ("Call stack:");
97 for (frame = __builtin_frame_address (0);
98 frame != NULL && frame[0] != NULL;
100 printk (" %p", frame[1]);