linux内核调试方法,交叉编译程序出现Illegal instruction的调试方法

来源:互联网 发布:博弈矩阵怎么看 编辑:程序博客网 时间:2024/06/07 03:02

user_debug,linux kernel debug, linux kernel user debug,内核调试,打开内核调试


嵌入式内核: linux-2.6.32;
交叉编译工具链: arm-2007q1.tar.gz
host: Debian 5.0.3 32bit


1. 最近做一个项目,调用库的时候,出现了错误,是内核级别的:

/lib/libpng.so open successfullydlopen: /lib/libcapi.soIllegal instruction

由于库不是我编的,但是,用arm-none-eabixxx-ld, 和arm-none-eabixxx-string去看库的信息,没有错误,那么比较确定是编译的库存在指令不匹配的错误!为了辅助库的编译者找到问题,需要打开linux内核的调试信息,出错的时候,显示更多的详细信息;

2. 参考文章:

  • http://blog.chinaunix.net/uid-25756789-id-3420210.html
  • http://blog.csdn.net/chuanzhilong/article/details/52891578

  • 要进行Illegal instruction调试,需要知道哪个指令不兼容,需要在内核 (arch/arm/kernel/traps.c) 中找到相关的异常处理函数(do_undefinstr) ,其中部分代码为:

#ifdef CONFIG_DEBUG_USER        if (user_debug & UDBG_UNDEFINED)    {              printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",    current->comm,                   task_pid_nr(current), pc);              dump_instr(regs);       }#endif

所以,在内核根目录下面的.config文件中,增加设定:CONFIG_DEBUG_USER=y

  • 在bootstrap工程中,修改main.c,添加命令行: user_debug=31

user_debug的值可根据情况选定,下面这几个宏与上面的粗体部分可对照一下,可得知各个bit使能之后能得到的信息。

#define UDBG_UNDEFINED (1 << 0)#define UDBG_SYSCALL (1 << 1)#define UDBG_BADABORT (1 << 2)#define UDBG_SEGV (1 << 3)#define UDBG_BUS (1 << 4)

3. 验证测试:

  • 重新编译bootstrap和linux内核,下载到设备中,
    再次出现:Illegal instructiond提示的时候,发现,比以前增加了更多信息,例如:
test_lib_lading (356): undefined instruction: pc=4031bbd0Code: e3a04000 e3a08001 e1a03418 e1a00006 (e6ff3073)Illegal instruction
原创粉丝点击