Linux内核调试之使用BUG_ON 和dump_stack
来源:互联网 发布:Linux开机自启tomcat 编辑:程序博客网 时间:2024/05/02 12:54
Asserting Bugs and Dumping Information
A 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 cause an 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();}
- Linux内核调试之使用BUG_ON 和dump_stack
- linux 调试语句BUG_ON WARN_ON dump_stack panic
- linux 内核调试(dump_stack)
- 内核调试之dump_stack
- linux内核调试技巧 dump_stack()
- linux 内核态调试函数BUG_ON()
- linux 内核态调试函数BUG_ON()
- linux内核调试技巧之一 dump_stack
- linux内核调试技巧之一 dump_stack
- linux内核调试技巧之一 dump_stack
- linux内核调试技巧之一 dump_stack
- linux内核调试技巧二:dump_stack
- linux内核中的BUG 和 BUG_ON
- linux内核中的BUG 和 BUG_ON
- dump_stack内核调试
- linux 内核态调试函数BUG_ON()与WARN_ON区别
- BUG BUG_ON dump_stack
- linux panic 和 bug_on
- 数据可视化----Flotr2和Raphaël 绘制气泡图
- NYOJ_58 最少步数
- JQuery实现select互换数据和上下移动
- 关于opencv摄像头图像显示 经常出现select timeout的问题
- ubantu软件源更新的问题
- Linux内核调试之使用BUG_ON 和dump_stack
- 关于CCproxy的二级代理设置
- kvc简单介绍
- docker科普
- 共享打印机无法保存和应用的解决办法
- IOS中截取当前屏幕,并保存图片
- 海水淡化膜:世韩8040海水淡化膜产品说明
- mfc 按钮 实现多个界面跳转
- 黑马程序员--【强哥笔记】系列之Java高新技术笔记之类加载器(第7天)