The kernel debug macro described in this article is a static debugging method, which is triggered oops by the debug macro to print out the function call stack information.
1) bug_on View the stack contents of the BUG, and actively manufacture the Oops
Linux bug_on,warn_on are used for debugging, such as
#define BUG_ON (condition) do {/
if (unlikely ((condition)!=0))/
BUG (); /
} while (0)
If you feel that the condition is a bug, you can add this debug information to view the corresponding stack contents
The specific bug_on final call __bug
__bug
{
* (int*) 0=0;
}
In order to address illegal access, such as calling bug_on (1) in your driver, DMESG will appear similar to the following information:
[19.360000] Unable to handle kernel NULL pointer dereference at virtual Address 00000000
[19.360000] PGD = c0004000
[19.360000] [00000000] *pgd=00000000
The procedure for calling a function is
Fault.c
__do_kernel_fault--------[19.360000] Unable to handle kernel NULL pointer dereference at virtual Address 00000000
Traps.c
Die--->__die--->__show_regs/dump_mem
2) warn_on call dump_stack print stack information, does not oops
#define WARN_ON (condition) do{/
if (unlikely ((condition)! = 0)) {/
PRINTK ("Badness in%s at%s:%d\n", __function__, __file__, __line__);
Dump_stack ();
}
}while (0)
3) build_bug_on compile debug Macro
#define BUILD_BUG_ON (condition) (void) sizeof (char[1-2*!! (condition)]))
BUILD_BUG_ON macros in the condition if True will be an error. Assuming the condition is true, the build_bug_on changes to: (void) sizeof (char[-1]), which is difficult to understand because char[-1] is inherently illegal. The result is a compilation error.
Example:
#define CONDITION 0
static int __init main_init (void)
{
PRINTK ("in%s function\n", __func__);
BUILD_BUG_ON (condition);/*if the macro "Confition" is not zero, and the program can isn't compiled to success. The build_bug_on used for the BUILD of program*/
WARN_ON (!condition);/*if the macro "Confition" is not zero, there would dump the SATCK information for this program. So the warn_on used for Debugof program*/
BUG_ON (condition); /*IF the macro "Confition" is not zero, the kernel would occur an Oops Errro "unable to handle kernel NULL pointer derefere NCE at virtual Address 00000000 ". So the bug_on used for ending the BUG program*/
return 0;
}
Debug macro for Linux kernel Debug Method summary