linux宕机时Oops分析及问题定位

本文详细解析了在Linux内核代码中,人为制造的野指针错误导致的Oops异常,通过分析错误代码、PC指针位置和栈回溯,定位到test_init函数中特定行。学习如何利用objdump工具和Oops信息进行故障诊断。

以下面这个例子说明(下面这个例子就是造一个野指针所引发的错误):

/*
 * test-debug-scr.c
 *
 * Copyright (C) 2012 - 2021 Reuuimlla Limited
 * 
 * Adapt to support xxx
 */

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ide.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/vmalloc.h>

/*-------------------------------------------------------------------------------*/
/*    DEFINITION                                         */
/*-------------------------------------------------------------------------------*/

/*
 * @description	: 驱动入口函数
 * @param 		: 无
 * @return 		: 无
 */
static int __init test_init(void)
{
     int *p = 0x1231223;
     *p = 0x1231223;
    printk("module loaded.\n");
    return 0;
}

/*
 * @description	: 驱动出口函数
 * @param 		: 无
 * @return 		: 无
 */
static void __exit test_exit(void)
{
    printk("module unloaded.\n");
    return;
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("test-debug-scr generic test driver");
MODULE_AUTHOR("xxxx");


很明显,人为制造错误的地方就是test_init函数内的 “ *p = 0x1231223 ”语句。

然后,把这个模块编译出来,再用insmod来插入到内核空间,Oops出现了。

# insmod test-debug.ko 
[   61.715630] Internal error: Oops: 805 [#1] PREEMPT SMP ARM
[   61.721656] Modules linked in: test_debug(O+) shb_uart(O) shb_lcd(O) adc(O) i2c(O)
[   61.721904] CPU: 2 PID: 1177 Comm: insmod Tainted: G           O 3.10.65 #493
[   61.721904] task: e6265500 ti: e5d5a000 task.ti: e5d5a000
[   61.721904] PC is at test_init+0x1c/0x44 [test_debug]
[   61.721904] LR is at do_one_initcall+0xa8/0x144
[   61.721904] pc : [<bf01a01c>]    lr : [<c000a4d8>]    psr: 600c0013
[   61.721904] sp : e5d5be40  ip : e5d5be50  fp : e5d5be4c
[   61.721904] r10: e5ff7124  r9 : 00000001  r8 : 00000000
[   61.721904] r7 : bf0180d4  r6 : c0967100  r5 : bf01a000  r4 : e5d5a000
[   61.721904] r3 : 01231000  r2 : 00000023  r1 : 00000012  r0 : bf018044
[   61.721904] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
[   61.721904] Control: 10c53c7d  Table: 66b0c06a  DAC: 00000015
[   61.721904] 
[   61.721904] LR: 0xc000a458:
[   61.721904] a458  e3c4403f e5d6301c e5948004 e3530000 0a000019 e594300c e1a01000 e59f00dc
[   61.721904] a478  e593215c eb1754da e24b002c eb017781 e14b22dc e14b23f4 e12fff35 e1a07000
[   61.721904] a498  e24b002c eb01777b e14b22dc e14b03d4 e0520000 e1a02520 e0c31001 e1a03521
[   61.721904] a4b8  e59f009c e1822b01 e1a01005 e88d000c e1a02007 eb1754c6 ea000001 e12fff30
[   61.721904] a4d8  e1a07000 e3a03000 e5c6301d e5943004 e1580003 0a000003 e59f1068 e59f0068
[   61.721904] a4f8  eb09c6d5 e5848004 e10f3000 e3130080 0a000004 e3a02040 e59f1050 e59f0048
[   61.721904] a518  eb09c895 f1080080 e5d6301d e3530000 0a000006 e59f3030 e30012c5 e59f2030
[   61.721904] a538  e59f0030 e58d3000 e1a03005 eb0065a6 e1a00007 e24bd020 e89da9f0 c0967100
[   61.721904] 
[   61.721904] SP: 0xe5d5bdc0:
[   61.721904] bd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值