BUG_ON()和WARN_ON()的用法
来源:互联网 发布:mac 应用程序图标 编辑:程序博客网 时间:2024/05/18 02:43
if (bad_thing)
BUG();
或者使用更好的形式:
BUG_ON(bad_thing);
BUG_ON && WARN_ON
Linux中BUG_ON,WARN_ON用于调试,比如
#define BUG_ON(condition) do { /
if (unlikely((condition)!=0)) /
BUG(); /
} while(0)
如果觉得该condition下是一个BUG,可以添加此调试信息,查看对应堆栈内容
具体的BUG_ON最终调用__bug
__bug
{
*(int*)0=0;//在linux里面NULL就是定义在0地址的指针,你给他赋值怎么可以呢
}
从而地址非法访问,
例如在你的驱动中调用BUG_ON(1),dmesg会出现下面类似信息
[ 19.360000] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[ 19.360000] pgd = c0004000
[ 19.360000] [00000000] *pgd=00000000
[ 19.360000] Internal error: Oops: 817 [#1] PREEMPT
[ 19.360000] Modules linked in: 。。。。
[ 19.360000] CPU: 0 Tainted: P (2.6.31 #201)
[ 19.360000] pc : [<bf04c1e4>] lr : [<bf04c1c4>] psr: 40000013
[ 19.360000] sp : c705ff50 ip : c705ff50 fp : c705ffc4
[ 19.360000] r10: 00000000 r9 : 00000000 r8 : 00000000
[ 19.360000] r7 : bf04c0b0 r6 : c705e000 r5 : c7908c80 r4 : 00000000
[ 19.360000] r3 : 00000000 r2 : c705ff40 r1 : c705ff84 r0 : 00000000
[ 19.360000] Flags: nZcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
[ 19.360000] Control: 0005317f Table: 87150000 DAC: 00000017
[ 19.360000] Process ts_thread (pid: 230, stack limit = 0xc705e270)
[ 19.360000] Stack: (0xc705ff50 to 0xc7060000)
[ 19.360000] ff40: c0056590 c00560e8 00000000 c003466c
[ 19.360000] ff60: c781c01c c7908c80 c705ff8c c705ff78 c00565dc c005656c 00000000 c7030480
[ 19.360000] ff80: c705ffc4 00000000 c7908c80 c0051238 c705ff90 c705ff90 c705ffc4 c705ffcc
[ 19.360000] ffa0: c7053dc0 00000000 bf04c0b0 00000000 00000000 00000000 c705fff4 c705ffc8
[ 19.360000] ffc0: c0050fc4 bf04c0c0 00000000 00000000 c705ffd0 c705ffd0 00000000 00000000
[ 19.360000] ffe0: 00000000 00000000 00000000 c705fff8 c003e0d8 c0050f4c 80376031 80376431
[ 19.360000] Backtrace:
[ 19.360000] Function entered at [<bf04c0b0>] from [<c0050fc4>]
[ 19.360000] Function entered at [<c0050f3c>] from [<c003e0d8>]
[ 19.360000] r7:00000000 r6:00000000 r5:00000000 r4:00000000
[ 19.360000] Code: 0a000001 eb4031aa eaffffc0 e3a03000 (e5833000)
[ 19.360000] ---[ end trace 3b848f3e016c12c9 ]---
二.WARN_ON
而WARN_ON则是调用dump_stack,打印堆栈信息,不会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)
具体的调用情况与中断有关,可以通过linux中断机制来学习。
- BUG_ON()和WARN_ON()的用法
- BUG_ON && WARN_ON
- 内核 BUG_ON 以及WARN_ON 用法作用
- linux中BUG_ON和WARN_ON解析
- BUG_ON and WARN_ON
- linux 调试语句BUG_ON WARN_ON dump_stack panic
- linux 内核态调试函数BUG_ON()与WARN_ON区别
- panic 和 bug_on
- BUG 和 BUG_ON
- linux panic 和 bug_on
- BUG 和 BUG_ON
- panic和bug_on
- BUG 和 BUG_ON
- BUG 和BUG_ON
- linux panic 和 bug_on
- 有关BUG_ON()的实现
- 有关BUG_ON()的实现
- BUG_ON()
- 异或运算
- 接口
- 一个MySQL 5.7 分区表性能下降的案例分析
- 函数分布
- Immutable 入门
- BUG_ON()和WARN_ON()的用法
- hdu In Action-最短路+01背包
- 2.1 Kotlin 搭建简单Kotlin 命令行开发环境
- 数组指针和指针数组的区别,以及如何利用他们访问数组里面的元素
- Github Pages 自定义域名
- 跨域传递cookie
- 阿里云香港vps亲测
- idea创建springcloud项目图文教程(创建服务提供者)(七)
- 用Battery Historian 3.0分析android手机电池消耗