7 static bool all_enabled;
8 static const char *enabled_classes[MAX_CLASSES];
9 static size_t enabled_cnt;
11 static bool class_is_enabled (const char *class);
13 /* Enables the debug message classes specified in CLASSES. The
14 string CLASSES is modified by and becomes owned by this
17 debug_enable (char *classes)
21 for (class = strtok_r (classes, ",", &save); class != NULL;
22 class = strtok_r (NULL, ",", &save))
24 if (strcmp (class, "all") && enabled_cnt < MAX_CLASSES)
25 enabled_classes[enabled_cnt++] = class;
31 /* Prints a debug message along with the source file name, line
32 number, and function name of where it was emitted. CLASS is
33 used to filter out unwanted messages. */
35 debug_message (const char *file, int line, const char *function,
36 const char *class, const char *message, ...)
38 if (class_is_enabled (class))
42 enum intr_level old_level = intr_disable ();
43 printk ("%s:%d: %s(): ", file, line, function);
44 va_start (args, message);
45 vprintk (message, args);
48 intr_set_level (old_level);
52 /* Halts the OS, printing the source file name, line number, and
53 function name, plus a user-specific message. */
55 debug_panic (const char *file, int line, const char *function,
56 const char *message, ...)
62 printk ("PANIC at %s:%d in %s(): ", file, line, function);
63 va_start (args, message);
64 vprintk (message, args);
73 /* Prints the call stack, that is, a list of addresses in each of
74 the functions we are nested within. gdb or addr2line may be
75 applied to kernel.o to translate these into file names, line
76 numbers, and function names. */
78 debug_backtrace (void)
82 printk ("Call stack:");
83 for (frame = __builtin_frame_address (0);
84 frame != NULL && frame[0] != NULL;
86 printk (" %p", frame[1]);
91 /* Returns true if CLASS is enabled, false otherwise. */
93 class_is_enabled (const char *class)
100 for (i = 0; i < enabled_cnt; i++)
101 if (!strcmp (enabled_classes[i], class))