Linux kernel oops panic 調試技巧


轉自點擊打開鏈接

http://blog.chinaunix.net/uid-291731-id-3142689.html


最近在調試USB驅動的過程中,偶爾會出現拔出USB線纜時kernel會有oops錯誤,以下是對kernel oops錯誤調試的簡單記錄,該方法也適用於panic錯誤。

oops錯誤日誌信息:

  1. Unable to handle kernel NULL pointer dereference at virtual address 00000020
  2. pgd = 80004000
  3. [00000020] *pgd=00000000
  4. Internal error: Oops: 17 [#1] PREEMPT
  5. last sysfs file: /sys/devices/platform/mxsdhci.2/mmc_host/mmc0/mmc0:0001/boot_bus_config
  6. CPU: 0 Not tainted (2.6.35.3 #10)
  7. PC is at fsg_main_thread+0x144/0x730
  8. LR is at schedule+0x2ac/0x328
  9. pc : [<8025b0b4>] lr : [<802ac778>] psr: 60000013
  10. sp : cfcd3f88 ip : cfcd3f38 fp : cfcd3fc4
  11. r10: cfcd2000 r9 : cf081640 r8 : 00000200
  12. r7 : 80356ac8 r6 : cfcd2000 r5 : cf081678 r4 : cf081600
  13. r3 : 00000000 r2 : 00000000 r1 : 00000000 r0 : 00000000
  14. Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
  15. Control: 10c5387d Table: bd2a0019 DAC: 00000017
  16. Process file-storage-ga (pid: 871, stack limit = 0xcfcd22e8)
  17. Stack: (0xcfcd3f88 to 0xcfcd4000)
  18. 3f80: cf08167c cfcd3f98 802ac648 cf0816b0 00000000 cf029ed8
  19. 3fa0: cfcd3fcc 8025af70 cf081600 00000000 00000000 00000000 cfcd3ff4 cfcd3fc8
  20. 3fc0: 8006565c 8025af7c 00000000 00000000 cfcd3fd0 cfcd3fd0 cf029ed8 800655d8
  21. 3fe0: 80051d14 00000013 00000000 cfcd3ff8 80051d14 800655e4 eda8ff35 f7efad76
  22. Backtrace:
  23. [<8025af70>] (fsg_main_thread+0x0/0x730) from [<8006565c>] (kthread+0x84/0x8c)
  24. [<800655d8>] (kthread+0x0/0x8c) from [<80051d14>] (do_exit+0x0/0x65c)
  25. r7:00000013 r6:80051d14 r5:800655d8 r4:cf029ed8
  26. Code: e5953004 e3530001 1afffff8 e5953018 (e5932020)
  27. ---[ end trace 38aa9563884a33ec ]---

遇到了空指針錯誤,PC指針指向fsg_main_thread+0x144 處,fsg_main_thread()函數位於driver/usb/gadgate/file_storage.c這個文件內,但是0x144的offset是哪一行呢?由於發生這個oops的kernel缺省沒有包含debug信息,所以需要重新生成一個帶debug info的vmlinux,步驟如下:
運行make menuconfig之後選中,

  1. kernel hacking->Kernel debugging->Compile the kernel with debug info
這樣編譯出來的vmlinux就帶調試符號了。

打開編譯好的kernel vmlinux所在目錄的符號表文件System.map,搜索fsg_main_thread,找到所在的行,最左邊的就是fsg_main_thread的地址了,即8025af70,偏移0x144,最終出錯的地址是:

  1. 0x8025af70+0x144=0x8025b0b4

此時用編譯kernel的toolchain中的gdb工具打開帶調式符號的vmlinux,

  1. toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb kernel/vmlinux
在gdb中使用b命令設置斷點

  1. (gdb) b *0x8025b0b4
最終得到了出錯的代碼行號

  1. Breakpoint 1 at 0x8025b0b4 : file drivers/usb/gadget/file_storage.c, line 2750.
拿到了行號就可以繼續深入debug了,在該行前後加一些BUG_ON()宏對變量進行測試,最終找到出錯的語句。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章