kernel backtrace 方法

林意蕴
2023-12-01

主要有四种,加入backtrace的方法:
1. WARN_ON(cond)   //比如  WARN_ON(!host->claimed);
条件满足时,输出如下log:
  WARNING: at drivers/mmc/core/core.c:240 mmc_wait_for_cmd+0x2c/0x74()    //by warn_slowpath_common
  Modules linked in: bcm4330         //by print_modules
  [<8006df6c>] (unwind_backtrace+0x0/0xf0) from [<8008f7c8>] (warn_slowpath_common+0x4c/0x64)  //by dump_stack                    
  [<8008f7c8>] (warn_slowpath_common+0x4c/0x64) from [<8008f7f8>] (warn_slowpath_null+0x18/0x1c)                  
  [<8008f7f8>] (warn_slowpath_null+0x18/0x1c) from [<802fdc0c>] (mmc_wait_for_cmd+0x2c/0x74)                      
  [<802fdc0c>] (mmc_wait_for_cmd+0x2c/0x74) from [<802fffec>] (mmc_go_idle+0x60/0xac)                             
  [<802fffec>] (mmc_go_idle+0x60/0xac) from [<80301288>] (sdio_reset_comm+0x2c/0x15c)                             
  [<80301288>] (sdio_reset_comm+0x2c/0x15c) from [<7f01c410>] (sdioh_start+0x2c/0x10c [bcm4330])                  
  [<7f01c410>] (sdioh_start+0x2c/0x10c [bcm4330]) from [<7f00c334>] (wl_control_wl_start+0x5c/0xa8 [bcm4330])     
  [<7f00c334>] (wl_control_wl_start+0x5c/0xa8 [bcm4330]) from [<7f00c38c>] (wl_iw_control_wl_on+0xc/0x34 [bcm4330])
  [<7f00c38c>] (wl_iw_control_wl_on+0xc/0x34 [bcm4330]) from [<7f00cd14>] (wl_iw_set_priv+0xb4/0xb50 [bcm4330])   
  [<7f00cd14>] (wl_iw_set_priv+0xb4/0xb50 [bcm4330]) from [<8042e614>] (ioctl_standard_call+0x64/0x388)           
  [<8042e614>] (ioctl_standard_call+0x64/0x388) from [<8042e9e8>] (wext_handle_ioctl+0xb0/0x1f4)                  
  [<8042e9e8>] (wext_handle_ioctl+0xb0/0x1f4) from [<80358604>] (dev_ioctl+0x754/0x784)                           
  [<80358604>] (dev_ioctl+0x754/0x784) from [<8010088c>] (vfs_ioctl+0x2c/0xac)                                    
  [<8010088c>] (vfs_ioctl+0x2c/0xac) from [<80100f40>] (do_vfs_ioctl+0x540/0x5a0)                                 
  [<80100f40>] (do_vfs_ioctl+0x540/0x5a0) from [<80100fec>] (sys_ioctl+0x4c/0x6c)                                 
  [<80100fec>] (sys_ioctl+0x4c/0x6c) from [<80069960>] (ret_fast_syscall+0x0/0x30)                                
  ---[ end trace 1b75b31a2719ed1e ]---                                                 //by print_oops_end_marker                                                          

2. BUG_ON(cond);   //比如 BUG_ON(in_atomic());
 
3. 系统的OOPS,可能无法打印到kernel.log中,而是只能显示在串口中,比如:
  [  302.253861] Unable to handle kernel paging request at virtual address a0000013
   [  302.286587] pgd = cf5c4000
   [  302.296897] [a0000013] *pgd=00000000
   [  302.309751] Internal error: Oops: 805 [#1] PREEMPT
   [  302.314550] last sysfs file: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
   [  302.322382] Modules linked in: [last unloaded: bcm4330]
   [  302.327634] CPU: 0    Not tainted  (2.6.35.3+ #246)
   [  302.332516] PC is at 0x7f0870b4
   [  302.335666] LR is at del_timer+0x20/0xc4
   [  302.339592] pc : [<7f0870b4>]    lr : [<8009ad60>]    psr: 60000013
   [  302.339597] sp : cffe5e90  ip : 00000000  fp : 00000000
   [  302.351082] r10: c3061588  r9 : 00000000  r8 : 00000680
   [  302.356308] r7 : cf38772c  r6 : cffe5ecf  r5 : 00000000  r4 : 00000000
   [  302.362837] r3 : 000000c1  r2 : cffe5e60  r1 : a0000013  r0 : 00000680
   [  302.369368] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
   [  302.376679] Control: 10c5387d  Table: bf4f0019  DAC: 00000017
   [  302.382428] Process dhd_sysioc (pid: 2720, stack limit = 0xcffe42e8)
   [  302.388784] Stack: (0xcffe5e90 to 0xcffe6000)
   [  302.393144] 5e80:                                     c3061400 00000000 cffdc000 8008c4fc
   [  302.401327] 5ea0: cf38772c cf38772c 00000000 c3061400 cf3870b0 00000000 cfe14000 0000001f
   [  302.409511] 5ec0: cfe14038 7f09dd50 c3061400 cfe14038 0000001f 00000000 cf3870b0 cfe14000
   [  302.417693] 5ee0: cfe14000 cff3e2a0 0000000f 7f0a144c ffffffff 00000000 00000000 00000062
   [  302.425876] 5f00: cfe14000 cfe14038 00000000 00000000 80854e30 809952e0 cf387800 cf3870b0
   [  302.434060] 5f20: cff3e2a0 cffe5fb0 00000000 cffe5fb0 c3061d18 cf387000 c3061c00 7f08d53c
   [  302.442242] 5f40: 0000000f 00000000 cffe5fb0 00000000 cf387000 cf3870b0 cffe4000 7f089414
   [  302.450425] 5f60: 0000000f 00000000 cff3e2af cff3e2a0 0000000f cf3877f0 cf3877d0 cf387890
   [  302.458607] 5f80: cf3878aa cf3877e0 cf387000 c3061c00 00000000 00000000 cffe5fac 8008c548
   [  302.466790] 5fa0: 00000000 00000000 00000000 800699ec 00000107 cff3e2a0 0000000f 00000001
   [  302.474972] 5fc0: 00000000 00000000 00000000 00000000 00000000 cf3877d0 7f0891b0 8006a3c0
   [  302.483155] 5fe0: 00000013 00000000 00000000 00000000 00000000 8006a3c0 71737011 71737411
   [  302.491355] [<8009ad60>] (del_timer+0x20/0xc4) from [<8008c4fc>] (default_wake_function+0x0/0x14)
   [  302.500236] Code: 00019970 0005571c 000199a8 0005441c (000199b4)
   [  302.506352] imx_ssi_irq mxc_ssi SISR 801121 SIER 180100 fifo_errs=1
   [  302.538716] enter mx_wifi_powerup
   [  302.639406]
   [  302.639416] end of mxc_mmc_force_detect
   [  302.644820] esdhc_cd_callback..cd_status=0 inserted
   [  302.694776] ---[ end trace 7ff6b3e3d944f8e7 ]---
   [  302.701656] Kernel panic - not syncing: Fatal exception
   [  302.706955] [<8006df6c>] (unwind_backtrace+0x0/0xf0) from [<8043ae34>] (panic+0x6c/0xe0)
   [  302.715187] [<8043ae34>] (panic+0x6c/0xe0) from [<8006ce00>] (die+0x2b4/0x304)
   [  302.722478] [<8006ce00>] (die+0x2b4/0x304) from [<8006ed6c>] (__do_kernel_fault+0x64/0x84)
   [  302.730774] [<8006ed6c>] (__do_kernel_fault+0x64/0x84) from [<8043f2fc>] (do_translation_fault+0x88/0x94)
   [  302.740390] [<8043f2fc>] (do_translation_fault+0x88/0x94) from [<800692c8>] (do_DataAbort+0x34/0x94)
   [  302.749569] [<800692c8>] (do_DataAbort+0x34/0x94) from [<8043d3ac>] (__dabt_svc+0x4c/0x60)
   [  302.757837] Exception stack(0xcffe5e48 to 0xcffe5e90)
   [  302.762904] 5e40:                   00000680 a0000013 cffe5e60 000000c1 00000000 00000000
   [  302.771095] 5e60: cffe5ecf cf38772c 00000680 00000000 c3061588 00000000 00000000 cffe5e90
   [  302.779276] 5e80: 8009ad60 7f0870b4 60000013 ffffffff
   [  302.784345] [<8043d3ac>] (__dabt_svc+0x4c/0x60) from [<7f0870b4>] (0x7f0870b4)
  
4. 直接调用 dump_stack /show_stack / 等
   比如:sched_show_task

   wpa_supplican D 8043a3b4     0 24957      1 0x00080001 ______               //24957 是wpa_supplicant 的PID
   [<8043a3b4>] (schedule+0x2a4/0x324) from [<8043aa2c>] (schedule_timeout+0x18/0x1fc)
   [<8043aa2c>] (schedule_timeout+0x18/0x1fc) from [<8043bae4>] (__down+0x7c/0xb4)
   [<8043bae4>] (__down+0x7c/0xb4) from [<800aab40>] (down+0x3c/0x7c)
   [<800aab40>] (down+0x3c/0x7c) from [<7f07c3e8>] (dhd_bus_rxctl+0x54/0x220 [bcm4330])
   [<7f07c3e8>] (dhd_bus_rxctl+0x54/0x220 [bcm4330]) from [<7f07dd34>] (dhdcdc_cmplt+0x44/0x68 [bcm4330])
   [<7f07dd34>] (dhdcdc_cmplt+0x44/0x68 [bcm4330]) from [<7f07e1a8>] (dhd_prot_ioctl+0x450/0x600 [bcm4330])
   [<7f07e1a8>] (dhd_prot_ioctl+0x450/0x600 [bcm4330]) from [<7f06132c>] (dhd_wl_ioctl+0x34/0x48 [bcm4330])
   [<7f06132c>] (dhd_wl_ioctl+0x34/0x48 [bcm4330]) from [<7f059820>] (dhd_ioctl_entry+0x3c0/0x4b0 [bcm4330])
   [<7f059820>] (dhd_ioctl_entry+0x3c0/0x4b0 [bcm4330]) from [<7f0630c4>] (dev_wlc_ioctl+0xf0/0x150 [bcm4330])
   [<7f0630c4>] (dev_wlc_ioctl+0xf0/0x150 [bcm4330]) from [<7f064238>] (wl_iw_mlme+0x64/0x80 [bcm4330])
   [<7f064238>] (wl_iw_mlme+0x64/0x80 [bcm4330]) from [<8042ec68>] (ioctl_standard_call+0x2a0/0x388)
   [<8042ec68>] (ioctl_standard_call+0x2a0/0x388) from [<8042ee00>] (wext_handle_ioctl+0xb0/0x1f4)
   [<8042ee00>] (wext_handle_ioctl+0xb0/0x1f4) from [<80358a1c>] (dev_ioctl+0x754/0x784)
   [<80358a1c>] (dev_ioctl+0x754/0x784) from [<80100814>] (vfs_ioctl+0x2c/0xac)
   [<80100814>] (vfs_ioctl+0x2c/0xac) from [<80100ec8>] (do_vfs_ioctl+0x540/0x5a0)
   [<80100ec8>] (do_vfs_ioctl+0x540/0x5a0) from [<80100f74>] (sys_ioctl+0x4c/0x6c)
   [<80100f74>] (sys_ioctl+0x4c/0x6c) from [<80069960>] (ret_fast_syscall+0x0/0x30)    


————————————————
版权声明:本文为CSDN博主「勤奋专注」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/do_script/article/details/7896805

 类似资料: