SystemTap で Linux のカーネル内のコールスタックを見てみる

SystemTap を使って Linux カーネル内のコールスタックを見てみた。

  • submit_bio.stp
probe kernel.function("submit_bio"){
        printf("%s[%d]\n",execname(),pid())
        print_backtrace()
}
  • 実行結果
[root@localhost ~]# stap submit_bio.stp 
kjournald[316]
 0xc04e28ea : submit_bio+0x0/0xdd [kernel]
 0xc047766b : submit_bh+0xe8/0x106 [kernel]
 0xf884d7a3
 0xcbc925c0 (inexact)
kjournald[316]
 0xc04e28ea : submit_bio+0x0/0xdd [kernel]
 0xc047766b : submit_bh+0xe8/0x106 [kernel]
 0xc047a996 : sync_dirty_buffer+0x6b/0xb8 [kernel]
 0xc9fb188c (inexact)
 0xc0c9fb18 (inexact)
oracle[2937]
 0xc04e28ea : submit_bio+0x0/0xdd [kernel]
 0xc0496ad9 : dio_bio_submit+0x46/0x57 [kernel]
 0xc049767b : __blockdev_direct_IO+0x974/0xbd9 [kernel]
 0xf8884fd8
 0xf7d69640 (inexact)
 0xc0f7d696 (inexact)
oracle[2937]
 0xc04e28ea : submit_bio+0x0/0xdd [kernel]
 0xc0496ad9 : dio_bio_submit+0x46/0x57 [kernel]
 0xc049767b : __blockdev_direct_IO+0x974/0xbd9 [kernel]
 0xf8884fd8
 0xf7d69640 (inexact)
 0xc0f7d696 (inexact)

関数名が表示されないアドレスを crash コマンドで調べて見ると、

[root@localhost ~]# crash
...
crash> dis f8884fd8 10
0xf8884fd8 <ext3_direct_IO+317>:        mov    %eax,%ebx
0xf8884fda <ext3_direct_IO+319>:        add    $0x20,%esp
0xf8884fdd <ext3_direct_IO+322>:        jmp    0xf8885056
0xf8884fdf <ext3_direct_IO+324>:        cmpl   $0x0,0x2c(%esi)
0xf8884fe3 <ext3_direct_IO+328>:        je     0xf8884fec
0xf8884fe5 <ext3_direct_IO+330>:        mov    %esi,%edx
0xf8884fe7 <ext3_direct_IO+332>:        call   0xf8888b16 <ext3_orphan_del>
0xf8884fec <ext3_direct_IO+337>:        test   %edi,%edi
0xf8884fee <ext3_direct_IO+339>:        jle    0xf8885033
0xf8884ff0 <ext3_direct_IO+341>:        mov    %edi,%ecx
crash> dis f7d69640 10
dis: WARNING: f7d69640: no associated kernel symbol found
0xf7d69640:     inc    %ecx
0xf7d69641:     add    %dh,(%eax)
0xf7d69643:     add    %cl,%al
0xf7d69645:     xchg   %eax,%esi
0xf7d69646:     (bad)  
0xf7d69647:     testl  $0x1000000,(%ecx)
0xf7d6964d:     add    %al,(%eax)
0xf7d6964f:     add    %al,(%ecx)
0xf7d69651:     add    %al,(%eax)
0xf7d69653:     add    %dl,-0x2a(%esi,%edx,4)
crash> dis c0f7d696 10
dis: WARNING: c0f7d696: no associated kernel symbol found
0xc0f7d696:     add    %al,(%eax)
0xc0f7d698:     add    %al,(%eax)
0xc0f7d69a:     add    %al,(%eax)
0xc0f7d69c:     add    %al,(%eax)
0xc0f7d69e:     add    %al,(%eax)
0xc0f7d6a0:     add    %al,(%eax)
0xc0f7d6a2:     add    %al,(%eax)
0xc0f7d6a4:     add    %al,(%eax)
0xc0f7d6a6:     add    %al,(%eax)
0xc0f7d6a8:     add    %al,(%eax)

表示されてないアドレスはカーネルモジュールでデバッグ情報がないからのような気がする。

crash> mod
f8818300  dm_mem_cache      9537  (not loaded)  [CONFIG_KALLSYMS]
f881b900  dm_message        6977  (not loaded)  [CONFIG_KALLSYMS]
f8825200  ehci_hcd         33869  (not loaded)  [CONFIG_KALLSYMS]
f882cf80  ohci_hcd         25065  (not loaded)  [CONFIG_KALLSYMS]
f8835100  uhci_hcd         25421  (not loaded)  [CONFIG_KALLSYMS]
f883d080  sd_mod           25281  (not loaded)  [CONFIG_KALLSYMS]
f8844a00  ata_piix         23621  (not loaded)  [CONFIG_KALLSYMS]
f8847980  pcspkr            7105  (not loaded)  [CONFIG_KALLSYMS]
f8857d80  jbd              57321  (not loaded)  [CONFIG_KALLSYMS]
f887b600  scsi_mod        141973  (not loaded)  [CONFIG_KALLSYMS]
f889c800  ext3            125513  (not loaded)  [CONFIG_KALLSYMS]
f88a7700  dm_log           14657  (not loaded)  [CONFIG_KALLSYMS]
f88acb00  dm_region_hash   15681  (not loaded)  [CONFIG_KALLSYMS]
f88b0280  mii               9409  (not loaded)  [CONFIG_KALLSYMS]
f88c1080  dm_mod           63225  (not loaded)  [CONFIG_KALLSYMS]
f88cb880  cdrom            36577  (not loaded)  [CONFIG_KALLSYMS]
f88f4400  libata          157317  (not loaded)  [CONFIG_KALLSYMS]
f88f9880  lp               15849  (not loaded)  [CONFIG_KALLSYMS]
f88fd780  serio_raw        10693  (not loaded)  [CONFIG_KALLSYMS]
f8904b80  i2c_core         24001  (not loaded)  [CONFIG_KALLSYMS]
f8908780  button           10705  (not loaded)  [CONFIG_KALLSYMS]
f891a400  dm_raid45        67145  (not loaded)  [CONFIG_KALLSYMS]
f891f100  i2c_piix4        13133  (not loaded)  [CONFIG_KALLSYMS]
f8923180  ac                9157  (not loaded)  [CONFIG_KALLSYMS]
f8927500  backlight        10049  (not loaded)  [CONFIG_KALLSYMS]
f892ae80  dell_wmi          8401  (not loaded)  [CONFIG_KALLSYMS]
f8931900  asus_acpi        19289  (not loaded)  [CONFIG_KALLSYMS]
f8940000  floppy           57125  (not loaded)  [CONFIG_KALLSYMS]
f894b700  pcnet32          35269  (not loaded)  [CONFIG_KALLSYMS]
f8956680  ide_cd           40161  (not loaded)  [CONFIG_KALLSYMS]
f8961000  parport          37513  (not loaded)  [CONFIG_KALLSYMS]
f8969f00  parport_pc       29157  (not loaded)  [CONFIG_KALLSYMS]
f896f300  battery          13637  (not loaded)  [CONFIG_KALLSYMS]
f8973d00  wmi              12137  (not loaded)  [CONFIG_KALLSYMS]
f8977100  i2c_ec            9025  (not loaded)  [CONFIG_KALLSYMS]
f897aa80  hwmon             7365  (not loaded)  [CONFIG_KALLSYMS]
f8980600  sbs              18533  (not loaded)  [CONFIG_KALLSYMS]
f8985e00  power_meter      16461  (not loaded)  [CONFIG_KALLSYMS]

例えば 0xf8884fd8 は ata_piix とかみたい。