Linux内核调试之使用BUG_ON 和dump_stack
2014-08-19 09:29
351 查看
Asserting Bugs and Dumping InformationA number of kernel routines make it easy to flag bugs, provide assertions, and dump information. Two of the most common are BUG() and BUG_ON(). When called, they causean oops, which results in a stack trace and an error message dumped to the kernel. Why these statements cause an oops is architecture-dependent. Most architectures define BUG() and BUG_ON() as illegal instructions, which result in the desired oops. You normally use these routines as assertions, to flag situations that should not happen: if (bad_thing) BUG(); Or, even better, BUG_ON(bad_thing); Most kernel developers believe that BUG_ON() is easier to read and more self-documenting compared to BUG(). Also, BUG_ON() wraps its assertion in an unlikely() statement. Do note that some developers have discussed the idea of having an option to compile BUG_ON() statements away, saving space in embedded kernels. This means that your assertion inside a BUG_ON() should not have any side effects. A more critical error is signaled via panic(). A call to panic() prints an error message and then halts the kernel. Obviously, you want to use it only in the worst of situations: if (terrible_thing) panic("foo is %ld!\n", foo); Sometimes, you just want a simple stack trace issued on the console to help you in debugging. In those cases, dump_stack() is used. It simply dumps the contents of the registers and a function back trace to the console: if (!debug_check) { printk(KERN_DEBUG "provide some information...\n"); dump_stack(); } |
相关文章推荐
- 关于BUG_ON() dump_stack 的一点笔记
- linux内核调试技巧之一 dump_stack
- linux内核调试技巧之一 dump_stack
- 总结一下内核DEBUG中的dump_stack, BUG, BUG_ON以及panic
- linux内核调试技巧之一 dump_stack
- linux 调试语句BUG_ON WARN_ON dump_stack panic
- BUG BUG_ON dump_stack
- 使用dump_stack查看内核函数调用
- 使用kgdb进行Linux内核调试(未完成!)
- 资源受限--使用signaltapII调试FPGA设计中的bug
- 使用windbg调试iis应用程序池崩溃的asp.net 2.0 bug.
- Ruby on Rails,使用Rails Console进行ActiveRecord调试
- linux内核调试环境的搭建(使用qemu)
- 使用DUMP 文件调试分析内核驱动
- 使用dump_stack()打印出内核调用堆栈
- 使用StackTraceElement封装,打印调试代码!
- 使用systemtap调试linux内核
- 将信号用作 Linux 调试工具--使用智能信号处理更快地寻找 bug
- 使用Qemu来调试linux内核
- 使用qemu调试linux内核