Some kernel calls can be used to easily mark Bugs, provide assertions, and output information. The two most common are bug () and bug_on ().
When called, they trigger oops, which causes the stack's backtracking and error messages to be printed. Why these claims lead to oops and hardware architectures
is relevant. Most architectures define bugs () and bug_on () as some kind of illegal operation, which naturally generates the Oops needed. You can use these calls as assertions, and you want to assert that a situation should not occur:
if (bad_thing)
BUG (); requires Linux kernel to open general Setup->configure standard kernel features->bug () support
Or use a better form:
BUG_ON (bad_thing);
A more serious error can be raised with panic (). calling Panic () will not only print error messages (Oops) but will also suspend the entire system . Obviously, you should only use it in extremely bad situations:
if (terrible_thing)
Panic ("Foo is%ld\n", foo);
Sometimes you just need to print a stack of backtracking information on the terminal to help you test. You can use Dump_stack () at this time. It only prints trace clues for the register context and function on the terminal:
if (!debug_check) {
PRINTK (kern_debug "provide some information...\n");
Dump_stack ();
}
Linux kernel-state debug function bug_on () [Go]