ラベル トラブルシューティング の投稿を表示しています。 すべての投稿を表示
ラベル トラブルシューティング の投稿を表示しています。 すべての投稿を表示

2021年7月25日

「Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.」への対処

Android Studioで「Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.」エラーが発生する際の対処方法。

発生条件/Condition

  • Android Studio 4.2.2

発生タイミング/Timing

  • Build実行時 / At build

対策/Measures

以下の2つのファイルをリネーム / Rename two following files

(1つ目/1st)
C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\d8.bat

C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\dx.bat

(2つ目/2nd)
C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\lib\d8.jar

C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\lib\dx.jar

参考/Reference

2019年7月20日

【Windows】画面左上に白抜きで「Static」と表示される

画面左上に白抜きで「Static」と表示される。以下のYahoo!知恵袋と同じ症状に見える。"Csr Bluetooth OSD Settings"というプロセスを強制終了させたら消えた。
以上

2016年1月3日

VMware Playerで ASSERT d:/build/ob/bora-2844087・・・が発生

VMware Playerで下記のエラーが発生したが、再インストールすることで解消。
原因は分からなかったが、まずは記録まで。
  • ASSERT d:/build/ob/bora-2844087/bora/vmcore/vmx/main/timeTracker_user.c:234 bugNr=148722

発生現象

[仮想マシンの再生]をクリックしたあと、"ASSERT d:/build/ob/bora-2844087/bora/vmcore/vmx/main/timeTracker_user.c:234 bugNr=148722"のメッセージを含むポップアップ画面が現れ、仮想マシンの再生が出来ない。

発生環境

VMware Player 6.0.7 on Windows VISTA SP2

再現性

発生させる方法は不明。ただし、現象発生後は、どの仮想マシンに対しても発生。

原因

不明。

対応

VMware Playerを再インストール

2011年6月11日

khungtaskdについて

カーネルスレッドにkhungtaskdというものがあるが、何者か、何ができるか少し実験。

確認環境
  • CentOS 5.6
実験

機能の確認
日本語での情報は見当たらず。英語だが以下のサイトを発見。
超訳だが、「ブロックされハングアップしたプロセスを定期巡回から発見し、プロセスのスタックダンプを取る機能」 らしい。(間違い指摘歓迎)

    姿の確認
    [owner@localhost ~]$ ps -ef | grep hung
    root       156     7  0 Jun05 ?        00:00:00 [khungtaskd]
    owner    17774 17750  0 21:27 pts/0    00:00:00 grep hung
    [owner@localhost ~]$

    カーネルパラメータの確認
    [root@localhost ~]# sysctl -a | grep hung
    kernel.hung_task_warnings = 10
    kernel.hung_task_timeout_secs = 120
    kernel.hung_task_check_count = 32768
    kernel.hung_task_panic = 0
    [root@localhost ~]#

    ソースコードの確認

    http://lxr.linux.no/#linux+v2.6.30/kernel/hung_task.c参照のこと
    kernel.hung_task_warnings
    定期巡回で異常を発見する都度、カウントダウンされる。つまり、ワーニングを発生させる回数と同値。(多分)
    kernel.hung_task_timeout_secs
    0 : 機能の停止、1~ : 機能の巡回秒数(デフォルトは120)
    kernel.hung_task_check_count
    定期巡回で検査対象にするプロセスIDの最大値?
    kernel.hung_task_panic
    0 : パニックしない(デフォルト) 、1 : パニックする

    動作実験
    何かハングアップを意図的に発生させようと考えたが、方法を思いつかず。
    そこで、kernel.hung_task_timeout_secs=1(下記のようにして設定)にして、放置すれば、そのうち何かが引っかかるだろう、と待つことに。

    [root@localhost ~]# echo 1 > /proc/sys/kernel/hung_task_timeout_secs

    一晩放置したら、出てる出てる。

    Jun 11 20:59:27 localhost kernel: INFO: task kjournald:359 blocked for more than 1 secon
    ds.
    Jun 11 20:59:27 localhost kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" dis
    ables this message.
    Jun 11 20:59:27 localhost kernel: kjournald     D 000048EF  2900   359      7
    390   348 (L-TLB)
    Jun 11 20:59:27 localhost kernel:        f7c80ed4 00000046 a751e9d4 000048ef c042e51c 00
    000082 f7d80b60 0000000a
    Jun 11 20:59:27 localhost kernel:        f7c82000 a7548843 000048ef 00029e6f 00000000 f7
    c8210c c17e7200 f393ee40
    Jun 11 20:59:27 localhost kernel:        0fd00000 c041e388 c18c5a04 c18c59fc 09923ea8 c0
    42d0bb c17e76bc 09923ea8
    Jun 11 20:59:27 localhost kernel: Call Trace:
    Jun 11 20:59:27 localhost kernel:  [<c042e51c>] del_timer+0x62/0x69
    Jun 11 20:59:27 localhost kernel:  [<c041e388>] find_busiest_group+0x177/0x462
    Jun 11 20:59:27 localhost kernel:  [<c042d0bb>] getnstimeofday+0x30/0xb6
    Jun 11 20:59:27 localhost kernel:  [<c061fe36>] io_schedule+0x36/0x59
    Jun 11 20:59:27 localhost kernel:  [<c0479a25>] sync_buffer+0x30/0x33
    Jun 11 20:59:27 localhost kernel:  [<c062000d>] __wait_on_bit+0x33/0x58
    Jun 11 20:59:27 localhost kernel:  [<c04799f5>] sync_buffer+0x0/0x33
    Jun 11 20:59:27 localhost kernel:  [<c04799f5>] sync_buffer+0x0/0x33
    Jun 11 20:59:27 localhost kernel:  [<c0620094>] out_of_line_wait_on_bit+0x62/0x6a
    Jun 11 20:59:27 localhost kernel:  [<c0436bf4>] wake_bit_function+0x0/0x3c
    Jun 11 20:59:27 localhost kernel:  [<c04799a2>] __wait_on_buffer+0x1c/0x1f
    Jun 11 20:59:27 localhost kernel:  [<f8885422>] journal_commit_transaction+0x4be/0xefc [
    jbd]
    Jun 11 20:59:27 localhost kernel:  [<c042df0b>] lock_timer_base+0x15/0x2f
    Jun 11 20:59:27 localhost kernel:  [<c042df8a>] try_to_del_timer_sync+0x65/0x6c
    Jun 11 20:59:27 localhost kernel:  [<f8888c21>] kjournald+0xa1/0x1c2 [jbd]
    Jun 11 20:59:27 localhost kernel:  [<c0436bc7>] autoremove_wake_function+0x0/0x2d
    Jun 11 20:59:27 localhost kernel:  [<f8888b80>] kjournald+0x0/0x1c2 [jbd]
    Jun 11 20:59:27 localhost kernel:  [<c0436b03>] kthread+0xc0/0xed
    Jun 11 20:59:27 localhost kernel:  [<c0436a43>] kthread+0x0/0xed
    Jun 11 20:59:27 localhost kernel:  [<c0405c87>] kernel_thread_helper+0x7/0x10
    Jun 11 20:59:27 localhost kernel:  =======================

    Jun 11 21:01:02 localhost kernel: INFO: task crond:6060 blocked for more than 1 seconds.
    Jun 11 21:01:02 localhost kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" dis
    ables this message.
    Jun 11 21:01:02 localhost kernel: crond         D 00004905  2584  6060   2288
              (NOTLB)
    Jun 11 21:01:02 localhost kernel:        cb17cdcc 00000082 b815344b 00004905 00000082 f7
    d80b60 f7d80b60 00000006
    Jun 11 21:01:02 localhost kernel:        e1ef3000 b828a8bb 00004905 00137470 00000000 e1
    ef310c c17e7200 ebc42040
    Jun 11 21:01:02 localhost kernel:        00000000 cb17cdc4 00000000 cb17cdc4 0995240e c0
    42d0bb f394193c 0995240e
    Jun 11 21:01:02 localhost kernel: Call Trace:
    Jun 11 21:01:02 localhost kernel:  [<c042d0bb>] getnstimeofday+0x30/0xb6
    Jun 11 21:01:02 localhost kernel:  [<c061fe36>] io_schedule+0x36/0x59
    Jun 11 21:01:02 localhost kernel:  [<c0459db8>] sync_page+0x0/0x3b
    Jun 11 21:01:02 localhost kernel:  [<c0459df0>] sync_page+0x38/0x3b
    Jun 11 21:01:02 localhost kernel:  [<c061ff48>] __wait_on_bit_lock+0x2a/0x52
    Jun 11 21:01:02 localhost kernel:  [<c0459d33>] __lock_page+0x52/0x59
    Jun 11 21:01:02 localhost kernel:  [<c0436bf4>] wake_bit_function+0x0/0x3c
    Jun 11 21:01:02 localhost kernel:  [<c045a55b>] do_generic_mapping_read+0x1f7/0x380
    Jun 11 21:01:02 localhost kernel:  [<c045af56>] __generic_file_aio_read+0x16a/0x1a3
    Jun 11 21:01:02 localhost kernel:  [<c0459a29>] file_read_actor+0x0/0xd5
    Jun 11 21:01:03 localhost kernel:  [<c045afca>] generic_file_aio_read+0x3b/0x42
    Jun 11 21:01:03 localhost kernel:  [<c0476d87>] do_sync_read+0xb6/0xf1
    Jun 11 21:01:03 localhost kernel:  [<c0436bc7>] autoremove_wake_function+0x0/0x2d
    Jun 11 21:01:03 localhost kernel:  [<c0476cd1>] do_sync_read+0x0/0xf1
    Jun 11 21:01:03 localhost kernel:  [<c0477660>] vfs_read+0x9f/0x141
    Jun 11 21:01:03 localhost kernel:  [<c0477ae6>] sys_read+0x3c/0x63
    Jun 11 21:01:03 localhost kernel:  [<c0404f4b>] syscall_call+0x7/0xb
    Jun 11 21:01:03 localhost kernel:  =======================

    Jun 11 21:13:21 localhost kernel: INFO: task smartd:2498 blocked for more than 1 seconds
    .
    Jun 11 21:13:21 localhost kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" dis
    ables this message.
    Jun 11 21:13:21 localhost kernel: smartd        D 000049B1  2592  2498      1          2
    503  2409 (NOTLB)
    Jun 11 21:13:21 localhost kernel:        ec3e6c7c 00000086 8ff2a672 000049b1 c084e114 ec
    3e6cd8 c0575173 0000000a
    Jun 11 21:13:21 localhost kernel:        ec4b1000 8ff4aa79 000049b1 00020407 00000000 ec
    4b110c c17e7200 f3961200
    Jun 11 21:13:21 localhost kernel:        00000000 00000000 ffffffff f7d7adc0 00000000 00
    000000 00000000 ffffffff
    Jun 11 21:13:21 localhost kernel: Call Trace:
    Jun 11 21:13:21 localhost kernel:  [<c0575173>] execute_drive_cmd+0x169/0x1ab
    Jun 11 21:13:21 localhost kernel:  [<c061f905>] wait_for_completion+0x6b/0x8f
    Jun 11 21:13:21 localhost kernel:  [<c041f80f>] default_wake_function+0x0/0xc
    Jun 11 21:13:21 localhost kernel:  [<c0575b1b>] ide_do_drive_cmd+0xd7/0xfa
    Jun 11 21:13:21 localhost kernel:  [<c0579ac7>] ide_task_ioctl+0x45/0x6b
    Jun 11 21:13:21 localhost kernel:  [<c04e29ee>] blk_end_sync_rq+0x0/0x1d
    Jun 11 21:13:21 localhost kernel:  [<c0574793>] generic_ide_ioctl+0x257/0x450
    Jun 11 21:13:21 localhost kernel:  [<c057d8eb>] idedisk_ioctl+0x1c/0x20
    Jun 11 21:13:21 localhost kernel:  [<c04e51f3>] blkdev_driver_ioctl+0x4b/0x5b
    Jun 11 21:13:21 localhost kernel:  [<c04e590e>] blkdev_ioctl+0x70b/0x759
    Jun 11 21:13:21 localhost kernel:  [<c04c9c29>] inode_has_perm+0x54/0x5c
    Jun 11 21:13:21 localhost kernel:  [<c06200e8>] mutex_lock+0xb/0x19
    Jun 11 21:13:21 localhost kernel:  [<c057e05e>] idedisk_open+0x38/0xb3
    Jun 11 21:13:21 localhost kernel:  [<c04c95c3>] avc_has_perm+0x3c/0x46
    Jun 11 21:13:21 localhost kernel:  [<c04c9c29>] inode_has_perm+0x54/0x5c
    Jun 11 21:13:21 localhost kernel:  [<c047e7f7>] blkdev_open+0x0/0x44
    Jun 11 21:13:21 localhost kernel:  [<c047e813>] blkdev_open+0x1c/0x44
    Jun 11 21:13:21 localhost kernel:  [<c047595a>] __dentry_open+0xea/0x1ab
    Jun 11 21:13:21 localhost kernel:  [<c047dd12>] block_ioctl+0x13/0x16
    Jun 11 21:13:21 localhost kernel:  [<c047dcff>] block_ioctl+0x0/0x16
    Jun 11 21:13:21 localhost kernel:  [<c0487629>] do_ioctl+0x1c/0x5d
    Jun 11 21:13:21 localhost kernel:  [<c0487bbd>] vfs_ioctl+0x47b/0x4d3
    Jun 11 21:13:21 localhost kernel:  [<c0487c5d>] sys_ioctl+0x48/0x5f
    Jun 11 21:13:21 localhost kernel:  [<c0404f4b>] syscall_call+0x7/0xb
    Jun 11 21:13:21 localhost kernel:  =======================

    出た結果の見方は分からないが、検知してくれていることを確認。

    以上

    2011年1月6日

    トラブル対応20111105 - 運用日誌

    SELinuxのエラーログに以下が発生。

    host=localhost.localdomain type=AVC msg=audit(1294116997.483:57): avc: denied { read } for pid=4029 comm="smartd" name="libm.so.6" dev=sda2 ino=1508034 scontext=system_u:system_r:fsdaemon_t:s0 tcontext=system_u:object_r:file_t:s0 tclass=lnk_file


    2010年10月17日

    Linuxのcore dumpの中身についてその2

    "DEBUG HACKS"を読んでいて(P.61-62辺り)、pmapで見た内容がcoreに出力されてんじゃないの?と気がついたので確かめてみた。

     

    ※知ってる人はとっくに知ってるんだろうけど。


     

    調査ターゲットを探す

     
    # ps
      PID TTY          TIME CMD
    3578 pts/0    00:00:00 su
    3579 pts/0    00:00:00 bash ←こいつをターゲットにしてみよう
    3671 pts/0    00:00:00 ps

    ターゲット(pid=3579)のpmapを確認

    # pmap 3579
    3579:   -bash
    0019e000     36K r-x--  /lib/libnss_files-2.5.so
    001a7000      4K r----  /lib/libnss_files-2.5.so
    001a8000      4K rw---  /lib/libnss_files-2.5.so
    008db000    100K r-x--  /lib/ld-2.5.so
    008f4000      4K r----  /lib/ld-2.5.so
    008f5000      4K rw---  /lib/ld-2.5.so
    008f8000   1256K r-x--  /lib/libc-2.5.so
    00a32000      8K r----  /lib/libc-2.5.so
    00a34000      4K rw---  /lib/libc-2.5.so
    00a35000     12K rw---    [ anon ]
    00a3a000      8K r-x--  /lib/libdl-2.5.so
    00a3c000      4K r----  /lib/libdl-2.5.so
    00a3d000      4K rw---  /lib/libdl-2.5.so
    00a82000     12K r-x--  /lib/libtermcap.so.2.0.8
    00a85000      4K rw---  /lib/libtermcap.so.2.0.8
    00d7b000      4K r-x--    [ anon ]
    08047000    684K r-x--  /bin/bash
    080f2000     20K rw---  /bin/bash
    080f7000     20K rw---    [ anon ]
    08d6e000    132K rw---    [ anon ]
    b7c8d000      8K rw---    [ anon ]
    b7c8f000     28K r--s-  /usr/lib/gconv/gconv-modules.cache
    b7c96000    940K r----  /usr/lib/locale/locale-archive
    b7d81000   2048K r----  /usr/lib/locale/locale-archive
    b7f81000      8K rw---    [ anon ]
    bfe87000     88K rw---    [ stack ]
    total     5444K

    gcoreでcore dumpを無理やり取ってみる

    # gcore 3579
    (no debugging symbols found)
    Using host libthread_db library "/lib/libthread_db.so.1".
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    0x00d7b410 in __kernel_vsyscall ()
    Saved corefile core.3579

    gdbでcore dumpを確認してみる('->'から右は比較のためpmapの実行結果をコピペしている)

    # gdb -c ./core.3579
    ...
    Core was generated by `/bin/bash'.
    #0  0x00d7b410 in __kernel_vsyscall ()
    (gdb) info files
    Local core dump file:
            `/root/./core.3579', file type elf32-i386.
            0x001a8000 - 0x001a9000 is load3  -> 001a8000      4K rw---  /lib/libnss_files-2.5.so
            0x008f5000 - 0x008f6000 is load6  -> 008f5000      4K rw---  /lib/ld-2.5.so
            0x00a34000 - 0x00a35000 is load9  -> 00a34000      4K rw---  /lib/libc-2.5.so
            0x00a35000 - 0x00a38000 is load10 -> 00a35000     12K rw---    [ anon ]
            0x00a3d000 - 0x00a3e000 is load13 -> 00a3d000      4K rw---  /lib/libdl-2.5.so
            0x00a85000 - 0x00a86000 is load15 -> 00a85000      4K rw---  /lib/libtermcap.so.2.0.8
            0x00d7b000 - 0x00d7c000 is load16 -> 00d7b000      4K r-x--    [ anon ]
            0x080f2000 - 0x080f7000 is load18 -> 080f2000     20K rw---  /bin/bash
            0x080f7000 - 0x080fc000 is load19 -> 080f7000     20K rw---    [ anon ]
            0x08d6e000 - 0x08d8f000 is load20 -> 08d6e000    132K rw---    [ anon ]
            0xb7c8d000 - 0xb7c8f000 is load21 -> b7c8d000      8K rw---    [ anon ]
            0xb7c8f000 - 0xb7c96000 is load22 -> b7c8f000     28K r--s-  /usr/lib/gconv/gconv-modules.cache
            0xb7c96000 - 0xb7d81000 is load23 -> b7c96000    940K r----  /usr/lib/locale/locale-archive
            0xb7d81000 - 0xb7f81000 is load24 -> b7d81000   2048K r----  /usr/lib/locale/locale-archive
            0xb7f81000 - 0xb7f83000 is load25 -> b7f81000      8K rw---    [ anon ]
            0xbfe87000 - 0xbfe9d000 is load26 -> bfe87000     88K rw---    [ stack ]
    (gdb)

    2010年10月14日

    スタックオーバーフロー

    "DEBUG HACKS"記載のスタックオーバーフロー事例の追試結果を示す。

     

     

         
    • sum.cを準備する(ソースは参考文献の"DEBUG HACKS"を確認のこと)
    •    
    • コンパイルする      
      $ make sum
      cc     sum.c   -o sum

       
    •  

    • 実行する
         
      $ uname -a
      Linux localhost.localdomain 2.6.18-53.el5PAE #1 SMP Wed Oct 10 16:48:18 EDT 2007 i686 athlon i386 GNU/Linux $ ulimit -c unlimited
      $ ./sum
      セグメンテーション違反です (core dumped)
      $ ls core*
      core.16163

       
    •  

    • gdbで読み込む
         
      $ gdb -c core.16163
      ...
      Program terminated with signal 11, Segmentation fault.
      #0  0x08048454 in ?? ()
      (gdb) p $sp
      $1 = (void *) 0xbf3c0000
      (gdb) info files
      Local core dump file:
              `/home/nekonoshin/proc/sum/core.16163', file type elf32-i386.
              0x00314000 - 0x00315000 is load1
              0x008f4000 - 0x008f5000 is load3
              0x008f5000 - 0x008f6000 is load4
              0x00a32000 - 0x00a34000 is load6
              0x00a34000 - 0x00a35000 is load7
              0x00a35000 - 0x00a38000 is load8
              0x08049000 - 0x0804a000 is load10
              0xb7fef000 - 0xb7ff1000 is load11
              0xbf3c0000 - 0xbffc0000 is load12
      (gdb)

       

    load12(stack領域のダンプ)が0xbf3c0000 - 0xbffc0000。スタックポインター($sp)の値、0xbf3c0000はstack領域の範囲外。

    参考文献

       
    • DEBUG HACKS, P.53, "HACK#9 デバッグに必要なスタックの基礎知識"吉岡弘隆, 大和一洋, 大岩尚宏, 安部東洋, 吉田俊輔, 株式会社オライリー・ジャパン, ISBN978-4-87311-4040    

    gdb - リモートデバッグ

    gdbを使ってリモートデバッグを行う手順例を示す。


     

    ロスプラットフォームでの開発や、CUIアプリの実際の実行画面を確認しながらのデバッグを行いたい場合にリモートデバッグを使う。

     

    環境

     
    +-------+    +---------+
    |デバッグ|--->|デバッグ  |
    |ホスト  |    |ターゲット|
    +-------+    +---------+

    実行例

    デバッグターゲットとデバッグホストが同じだが、2つの端末を用いた例を解説。例は、端末1と端末2の2つの端末が同一マシンの同一ユーザにログインしている状態とする。

       
    • 端末1(デバッグターゲット)でテストプログラムを作成    
      guest@debian5:~$ cat tst.c
      #include <stdio.h>

      int main()
      {
              printf("h"); fflush(stdout);
              printf("e"); fflush(stdout);
              printf("l"); fflush(stdout);
              printf("l"); fflush(stdout);
              printf("o"); fflush(stdout);
              printf(" "); fflush(stdout);
              printf("w"); fflush(stdout);
              printf("o"); fflush(stdout);
              printf("r"); fflush(stdout);
              printf("l"); fflush(stdout);
              printf("d"); fflush(stdout);
              printf("\n"); fflush(stdout);

              return 0;
      }

      guest@debian5:~$ gcc -g tst.c -o tst
      guest@debian5:~$


       

       
    • 端末1(デバッグターゲット)でgdbserverを起動    
      guest@debian5:~$ gdbserver localhost:1234 tst
      Process tst created; pid = 3181
      Listening on port 1234
       
       
    • 端末2(デバッグホスト)でgdbを起動    
      guest@debian5:~$ gdb ./tst
      GNU gdb 6.8-debian
      Copyright (C) 2008 Free Software Foundation, Inc.
      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
      and "show warranty" for details.
      This GDB was configured as "i486-linux-gnu"...
      (gdb) break main
      Breakpoint 1 at 0x8048415: file tst.c, line 5.
      (gdb) target remote localhost:1234
      Remote debugging using localhost:1234
      [New Thread 3181]
      0xb7f07810 in ?? () from /lib/ld-linux.so.2
      (gdb) c
      Continuing.

      Breakpoint 1, main () at tst.c:5
      5               printf("h"); fflush(stdout);
      (gdb) s
      6               printf("e"); fflush(stdout);
      (gdb)
      7               printf("l"); fflush(stdout);
      (gdb)
      8               printf("l"); fflush(stdout);
      (gdb)
      9               printf("o"); fflush(stdout);
      (gdb)
      10              printf(" "); fflush(stdout);
      (gdb)
      11              printf("w"); fflush(stdout);
      (gdb)
      12              printf("o"); fflush(stdout);
      (gdb)
      13              printf("r"); fflush(stdout);
      (gdb)
      14              printf("l"); fflush(stdout);
      (gdb)
      15              printf("d"); fflush(stdout);
      (gdb)
      16              printf("\n"); fflush(stdout);
      (gdb)
      18              return 0;
      (gdb)
      19      }
      (gdb)
      0xb7dbb455 in __libc_start_main () from /lib/i686/cmov/libc.so.6
      (gdb) c
      Continuing.

      Program exited normally.
      (gdb)


       

       
    • 端末1(デバッグターゲット)の表示に以下が追加される(特に"hello world"が端末2のステップ実行に合わせて1文字づつ表示されている状況が必見)    
      Remote debugging from host 127.0.0.1
      hello world

      Child exited with retcode = 0

      Child exited with status 0
      GDBserver exiting
      guest@debian5:~$


       

       
    • 因みに、リモートデバッグをやらずにローカルで直接デバッグすると以下の様になる。 ※"hello world"がデバッガの出力と混ざってしまっている。    
      guest@debian5:~$ gdb ./tst
      GNU gdb 6.8-debian
      Copyright (C) 2008 Free Software Foundation, Inc.
      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
      and "show warranty" for details.
      This GDB was configured as "i486-linux-gnu"...
      (gdb) break main
      Breakpoint 1 at 0x8048415: file tst.c, line 5.
      (gdb) r
      Starting program: /home/guest/tst

      Breakpoint 1, main () at tst.c:5
      5               printf("h"); fflush(stdout);
      (gdb) s
      h6              printf("e"); fflush(stdout);
      (gdb)
      e7              printf("l"); fflush(stdout);
      (gdb)
      l8              printf("l"); fflush(stdout);
      (gdb)
      l9              printf("o"); fflush(stdout);
      (gdb)
      o10             printf(" "); fflush(stdout);
      (gdb)
      11             printf("w"); fflush(stdout);
      (gdb)
      w12             printf("o"); fflush(stdout);
      (gdb)
      o13             printf("r"); fflush(stdout);
      (gdb)
      r14             printf("l"); fflush(stdout);
      (gdb)
      l15             printf("d"); fflush(stdout);
      (gdb)
      d16             printf("\n"); fflush(stdout);
      (gdb)

      18              return 0;
      (gdb)
      19      }
      (gdb)
      0xb7e6f455 in __libc_start_main () from /lib/i686/cmov/libc.so.6
      (gdb) c
      Continuing.

      Program exited normally.
      (gdb)


       

    備考

       
    • RHELをターゲットにリモートデバッグを行うとSIGTRAPが大量に発生する。正しい対処法かどうかはわからないが、以下で抑制可能。    
      (gdb) handle SIGTRAP nostop noprint nopass
      SIGTRAP is used by the debugger.
      Are you sure you want to change it? (y or n) y

      Signal        Stop      Print   Pass to program Description
      SIGTRAP       No        No      No              Trace/breakpoint trap
      (gdb)


       

    参考資料

       
    • "info gdb"の"Remote Debugging"

    CentOSでcrashコマンドを試してみる

    CentOSでcrashコマンドでカーネルデバッグできる環境を構築する手順例を示す。


    まず何も考えずcrashコマンドを叩いてみる。   

    # crash

    crash 4.0-5.0.3.el5.centos
    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008  Red Hat, Inc.
    Copyright (C) 2004, 2005, 2006  IBM Corporation
    Copyright (C) 1999-2006  Hewlett-Packard Co
    Copyright (C) 2005, 2006  Fujitsu Limited
    Copyright (C) 2006, 2007  VA Linux Systems Japan K.K.
    Copyright (C) 2005  NEC Corporation
    Copyright (C) 1999, 2002, 2007  Silicon Graphics, Inc.
    Copyright (C) 1999, 2000, 2001, 2002  Mission Critical Linux, Inc.
    This program is free software, covered by the GNU General Public License,
    and you are welcome to change it and/or distribute copies of it under
    certain conditions.  Enter "help copying" to see the conditions.
    This program has absolutely no warranty.  Enter "help warranty" for details.

    crash: cannot find booted kernel -- please enter namelist argument

    Usage:
      crash [-h [opt]][-v][-s][-i file][-d num] [-S] [mapfile] [namelist] [dumpfile]

    Enter "crash -h" for details.
    #

    なにもエラーが出なければ既に設定はされており、手順はここで終了。

    上記の様にエラーがでるなら、http://debuginfo.centos.org/からkernel-debuginfoをダウンロードしてくる。

    例では以下をダウンロードしたした。※現在動作中のカーネル版数と同じにすること。

    インストールから動作確認まで、以下手順で行う。

    # rpm -ihv kernel-debuginfo-common-2.6.18-92.1.1.el5.i686.rpm
    # rpm -ihv kernel-debuginfo-2.6.18-92.1.22.el5.i686.rpm
    # crash

    crash 4.0-5.0.3.el5.centos
    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008  Red Hat, Inc.
    Copyright (C) 2004, 2005, 2006  IBM Corporation
    Copyright (C) 1999-2006  Hewlett-Packard Co
    Copyright (C) 2005, 2006  Fujitsu Limited
    Copyright (C) 2006, 2007  VA Linux Systems Japan K.K.
    Copyright (C) 2005  NEC Corporation
    Copyright (C) 1999, 2002, 2007  Silicon Graphics, Inc.
    Copyright (C) 1999, 2000, 2001, 2002  Mission Critical Linux, Inc.
    This program is free software, covered by the GNU General Public License,
    and you are welcome to change it and/or distribute copies of it under
    certain conditions.  Enter "help copying" to see the conditions.
    This program has absolutely no warranty.  Enter "help warranty" for details.

    GNU gdb 6.1
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i686-pc-linux-gnu"...

          KERNEL: /usr/lib/debug/lib/modules/2.6.18-92.1.22.el5/vmlinux
        DUMPFILE: /dev/crash
            CPUS: 1
            DATE: Thu Mar  5 12:22:00 2009
          UPTIME: 02:24:35
    LOAD AVERAGE: 2.14, 0.97, 0.65
           TASKS: 159
        NODENAME: localhost.localdomain
         RELEASE: 2.6.18-92.1.22.el5
         VERSION: #1 SMP Tue Dec 16 12:03:43 EST 2008
         MACHINE: i686  (1728 Mhz)
          MEMORY: 256 MB
             PID: 7203
         COMMAND: "crash"
            TASK: c75ef550  [THREAD_INFO: c6d1a000]
             CPU: 0
           STATE: TASK_RUNNING (ACTIVE)

    crash>

    完了。

    gdbでcore dumpをいろんなパターンで調べてみる

    gdbの使い方を知るため、各種試行した内容を以下に残す。


     

    ※具体的な各ファイルの読み込ませ方まで記載していない。後日改善予定。

     

    試行1.core dumpのみでgdbを起動してみる。 

     
    $ gdb -c core.7030 
    GNU gdb Red Hat Linux (6.5-37.el5_2.2rh)
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu".
    (no debugging symbols found)
    Using host libthread_db library "/lib/libthread_db.so.1".
    Core was generated by `./test_core'.
    Program terminated with signal 8, Arithmetic exception.
    #0  0x0012f3c3 in ?? ()
    (gdb) where
    #0  0x0012f3c3 in ?? ()
    #1  0x00000001 in ?? ()
    #2  0xbffedfc0 in ?? ()
    #3  0x0012f3ac in ?? ()
    #4  0x00207658 in ?? ()
    #5  0xbffedfa8 in ?? ()
    #6  0x0804845a in ?? ()
    #7  0x001fa5d0 in ?? ()
    #8  0xbffedfc0 in ?? ()
    #9  0xbffee018 in ?? ()
    #10 0x0021fdec in ?? ()
    #11 0x00206ca0 in ?? ()
    #12 0x08048480 in ?? ()
    #13 0xbffee018 in ?? ()
    #14 0x0021fdec in ?? ()
    #15 0x00000001 in ?? ()
    #16 0xbffee044 in ?? ()
    #17 0xbffee04c in ?? ()
    #18 0x00207810 in ?? ()
    #19 0x00000000 in ?? ()
    (gdb)

    とりあえず、アドレス0x0012f3c3で落ちたのが分かる。

    ただ、この状態だとマシン語を逆アセンブルしながら追わないことには分からない。

    試行2.core dumpファイルとexeファイルを指定してみる。

    $ gdb test_core -c core.7030 
    GNU gdb Red Hat Linux (6.5-37.el5_2.2rh)
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

    warning: Can't read pathname for load map: 入力/出力エラーです.
    Error while mapping shared library sections:
    ./liba.so.1: そのようなファイルやディレクトリはありません.
    Error while reading shared library symbols:
    ./liba.so.1: そのようなファイルやディレクトリはありません.
    Reading symbols from /lib/libc.so.6...done.
    Loaded symbols for /lib/libc.so.6
    Reading symbols from /lib/ld-linux.so.2...done.
    Loaded symbols for /lib/ld-linux.so.2
    Error while reading shared library symbols:
    ./liba.so.1: そのようなファイルやディレクトリはありません.
    Core was generated by `./test_core'.
    Program terminated with signal 8, Arithmetic exception.
    #0  0x0012f3c3 in ?? ()
    (gdb) where
    #0  0x0012f3c3 in ?? ()
    #1  0x00000001 in ?? ()
    #2  0xbffedfc0 in ?? ()
    #3  0x0012f3ac in ?? ()
    #4  0x00207658 in _r_debug ()
    #5  0xbffedfa8 in ?? ()
    #6  0x0804845a in main () at test_core.c:8
    (gdb)

    test_core.cの8行目から呼び出されてとんだ先の0x0012f3c3で落ちたのは分かるようになった。0x0012f3c3に何の処理があるのか分からない。情報が少なくてデバッグにはならない。

    試行3.core dumpファイルとexeファイルとliba.so.1(自分で作った共有ライブラリ)で調べてみる 

    $ gdb test_core -c core.7030 
    GNU gdb Red Hat Linux (6.5-37.el5_2.2rh)
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

    warning: Can't read pathname for load map: 入力/出力エラーです.
    Reading symbols from /home/takeshi/temp/liba.so.1...done.
    Loaded symbols for ./liba.so.1
    Reading symbols from /lib/libc.so.6...done.
    Loaded symbols for /lib/libc.so.6
    Reading symbols from /lib/ld-linux.so.2...done.
    Loaded symbols for /lib/ld-linux.so.2
    Core was generated by `./test_core'.
    Program terminated with signal 8, Arithmetic exception.
    #0  0x0012f3c3 in liba () at liba.c:6
    6       liba.c: そのようなファイルやディレクトリはありません.
            in liba.c
    (gdb) where
    #0  0x0012f3c3 in liba () at liba.c:6
    #1  0x0804845a in main () at test_core.c:8
    (gdb)

    liba.cの6行目の処理で落ちたことが分かるようになった。

    試行4.さらにソースコードも読み込ませてみる

    $ gdb test_core -c core.7030 
    GNU gdb Red Hat Linux (6.5-37.el5_2.2rh)
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

    warning: Can't read pathname for load map: 入力/出力エラーです.
    Reading symbols from /home/takeshi/temp/liba.so.1...done.
    Loaded symbols for ./liba.so.1
    Reading symbols from /lib/libc.so.6...done.
    Loaded symbols for /lib/libc.so.6
    Reading symbols from /lib/ld-linux.so.2...done.
    Loaded symbols for /lib/ld-linux.so.2
    Core was generated by `./test_core'.
    Program terminated with signal 8, Arithmetic exception.
    #0  0x0012f3c3 in liba () at liba.c:6
    6               int i = 10 / 0;
    (gdb) where
    #0  0x0012f3c3 in liba () at liba.c:6
    #1  0x0804845a in main () at test_core.c:8
    (gdb)

    liba.cの6行目のint i = 10 /0;の処理で落ちたことが分かる。0での除算は致命的エラーなので、落ちて当たり前だ。

    おまけ.ソースコードliba.cの6行目を変更してみる

    $ gdb test_core -c core.7030 
    GNU gdb Red Hat Linux (6.5-37.el5_2.2rh)
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

    warning: Can't read pathname for load map: 入力/出力エラーです.
    Reading symbols from /home/takeshi/temp/liba.so.1...done.
    Loaded symbols for ./liba.so.1
    Reading symbols from /lib/libc.so.6...done.
    Loaded symbols for /lib/libc.so.6
    Reading symbols from /lib/ld-linux.so.2...done.
    Loaded symbols for /lib/ld-linux.so.2
    Core was generated by `./test_core'.
    Program terminated with signal 8, Arithmetic exception.
    #0  0x0012f3c3 in liba () at liba.c:6

    warning: Source file is more recent than executable.
    6               /* comment add for test */
    (gdb) where
    #0  0x0012f3c3 in liba () at liba.c:6
    #1  0x0804845a in main () at test_core.c:8
    (gdb)

    表示されるソースが/* comment add for test */に変わった。バイナリとソースのバージョンは正確に一致していないとデバッグは出来ないようだ。

    2010年10月13日

    ポートを開いているプロセスを特定する(Linux)

    TCPおよびUDPポートを占有しているプロセスを特定する方法を示す。


    [root@localhost ~]# netstat -nap
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PI
    D/Program name
    tcp        0      0 0.0.0.0:961                 0.0.0.0:*                   LISTEN      24
    75/rpc.statd
    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      24
    50/portmap
    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      27
    49/cupsd
    tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      27
    81/sendmail: acce
    tcp        0      0 :::22                       :::*                        LISTEN      27
    38/sshd
    tcp        0    148 ::ffff:192.168.201.129:22   ::ffff:192.168.201.1:3255   ESTABLISHED 31
    42/1
    udp        0      0 0.0.0.0:955                 0.0.0.0:*                               24
    75/rpc.statd
    udp        0      0 0.0.0.0:958                 0.0.0.0:*                               24
    75/rpc.statd
    udp        0      0 0.0.0.0:68                  0.0.0.0:*                               23
    64/dhclient
    udp        0      0 0.0.0.0:5353                0.0.0.0:*                               28
    96/avahi-daemon:
    udp        0      0 0.0.0.0:111                 0.0.0.0:*                               24
    50/portmap
    udp        0      0 0.0.0.0:36469               0.0.0.0:*                               28
    96/avahi-daemon:
    udp        0      0 0.0.0.0:631                 0.0.0.0:*                               27
    49/cupsd
    udp        0      0 :::51878                    :::*                                    28
    96/avahi-daemon:
    udp        0      0 :::5353                     :::*                                    28
    96/avahi-daemon:
    ...

    >

    2010年8月29日

    MBRをダンプしてみる

    ハードディスクのMBR(マスターブートレコード)の設定状況を直接確認する方法を示す。



    UNIX系ではHDDも所詮ファイル扱いなので、以下で可能。
    [root@localhost ~]# hexdump -C -n 512 /dev/sda
    00000000  eb 48 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.H..............|
    00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
    00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
    00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 03 02  |.........|...t..|
    00000040  81 00 00 80 41 b4 00 00  00 08 fa 90 90 f6 c2 80  |....A...........|
    00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
    00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 be 7f 7d  |. ..@|<.t...R..}|
    00000070  e8 34 01 f6 c2 80 74 54  b4 41 bb aa 55 cd 13 5a  |.4....tT.A..U..Z|
    00000080  52 72 49 81 fb 55 aa 75  43 a0 41 7c 84 c0 75 05  |RrI..U.uC.A|..u.|
    00000090  83 e1 01 74 37 66 8b 4c  10 be 05 7c c6 44 ff 01  |...t7f.L...|.D..|
    000000a0  66 8b 1e 44 7c c7 04 10  00 c7 44 02 01 00 66 89  |f..D|.....D...f.|
    000000b0  5c 08 c7 44 06 00 70 66  31 c0 89 44 04 66 89 44  |\..D..pf1..D.f.D|
    000000c0  0c b4 42 cd 13 72 05 bb  00 70 eb 7d b4 08 cd 13  |..B..r...p.}....|
    000000d0  73 0a f6 c2 80 0f 84 ea  00 e9 8d 00 be 05 7c c6  |s.............|.|
    000000e0  44 ff 00 66 31 c0 88 f0  40 66 89 44 04 31 d2 88  |D..f1...@f.D.1..|
    000000f0  ca c1 e2 02 88 e8 88 f4  40 89 44 08 31 c0 88 d0  |........@.D.1...|
    00000100  c0 e8 02 66 89 04 66 a1  44 7c 66 31 d2 66 f7 34  |...f..f.D|f1.f.4|
    00000110  88 54 0a 66 31 d2 66 f7  74 04 88 54 0b 89 44 0c  |.T.f1.f.t..T..D.|
    00000120  3b 44 08 7d 3c 8a 54 0d  c0 e2 06 8a 4c 0a fe c1  |;D.}<.T.....L...|
    00000130  08 d1 8a 6c 0c 5a 8a 74  0b bb 00 70 8e c3 31 db  |...l.Z.t...p..1.|
    00000140  b8 01 02 cd 13 72 2a 8c  c3 8e 06 48 7c 60 1e b9  |.....r*....H|`..|
    00000150  00 01 8e db 31 f6 31 ff  fc f3 a5 1f 61 ff 26 42  |....1.1.....a.&B|
    00000160  7c be 85 7d e8 40 00 eb  0e be 8a 7d e8 38 00 eb  ||..}.@.....}.8..|
    00000170  06 be 94 7d e8 30 00 be  99 7d e8 2a 00 eb fe 47  |...}.0...}.*...G|
    00000180  52 55 42 20 00 47 65 6f  6d 00 48 61 72 64 20 44  |RUB .Geom.Hard D|
    00000190  69 73 6b 00 52 65 61 64  00 20 45 72 72 6f 72 00  |isk.Read. Error.|
    000001a0  bb 01 00 b4 0e cd 10 ac  3c 00 75 f4 c3 00 00 00  |........<.u.....|
    000001b0  00 00 00 00 00 00 00 00  9b ef 0e 00 00 00 80 01  |................|
    000001c0  01 00 83 fe 3f 20 3f 00  00 00 a2 16 08 00 00 00  |....? ?.........|
    000001d0  01 21 83 fe ff ff e1 16  08 00 d9 e5 3f 01 00 fe  |.!..........?...|
    000001e0  ff ff 82 fe ff ff ba fc  47 01 c5 fa 3f 00 00 fe  |........G...?...|
    000001f0  ff ff 0f fe ff ff 00 00  88 01 00 00 b8 00 55 aa  |..............U.|
    00000200
    [root@localhost ~]#
    

    カーネルデバッグインフォの設定方法 - RHEL

    カーネルデバッグ環境の追加設定方法。

    ※下記に示したのは特定バージョンでの例。
    STEP1. カーネルバージョンの確認


    [root@localhost ~]# uname -a
    Linux localhost.localdomain 2.6.18-164.2.1.el5PAE #1 SMP Mon Sep 21 04:45:05 EDT
      2009 i686 i686 i386 GNU/Linux
    

    STEP2. デバッグインフォ(debuginfo)の入手


    [root@localhost ~]# wget http://ftp.redhat.com/pub/redhat/linux/enterprise/5Serv
    er/en/os/i686/Debuginfo/kernel-PAE-debuginfo-2.6.18-164.2.1.el5.i686.rpm
    ...
    [root@localhost ~]# wget http://ftp.redhat.com/pub/redhat/linux/enterprise/5Serv
    er/en/os/i686/Debuginfo/kernel-debuginfo-common-2.6.18-164.2.1.el5.i686.rpm
    ...
    

    STEP3. 既存のデバッグインフォパッケージの確認と削除


    [root@localhost ~]# rpm -qa | grep debug
    kernel-PAE-debuginfo-2.6.18-128.el5
    kernel-debuginfo-common-2.6.18-128.el5
    [root@localhost ~]# rpm -e kernel-PAE-debuginfo-2.6.18-128.el5
    [root@localhost ~]# rpm -e kernel-debuginfo-common-2.6.18-128.el5
    [root@localhost ~]# rpm -qa | grep debug
    [root@localhost ~]#
    

    STEP4. デバッグインフォのインストール


    [root@localhost ~]# rpm -ivh kernel-debuginfo-common-2.6.18-164.2.1.el5.i686.rpm
    ...
    [root@localhost ~]# rpm -ivh kernel-PAE-debuginfo-2.6.18-164.2.1.el5.i686.rpm
    ...
    

    STEP5. 確認(crash>プロンプトが出ればOK)


    [root@localhost ~]# crash
    ...
    crash>

    2009年8月7日

    イキナリ! rootでログインできない! - Ubuntu初日

     ubuntuはrootでログインできない。調べてみると、そういう操作をさせないことが売りだそうだ。

     一般ユーザでログインし、端末から"sudo su"と打てばrootになれてしまったが、ubuntuの趣旨に出きるだけ従うことにする。

    2009年6月24日

    カーネルデバッグ環境の設定

    また今日もマニアックなことに挑戦。
    CentOSでcrashコマンドを試してみることに。


    詳細はこちら




    RHEL4系

    例)
    [root@localhost ~]# uname -a
    Linux localhost.localdomain 2.6.9-78.0.1.EL #1 Tue Jul 22 17:50:01 EDT 2008 i686 i686 i386 GNU/Linux
    [root@localhost rpm-work]# wget http://ftp.redhat.com/pub/redhat/linux/updates/enterprise/4AS/en/os/Debuginfo/i686/RPMS/kernel-debuginfo-2.6.9-78.0.1.EL.i686.rpm
    [root@localhost rpm-work]# rpm -ivh kernel-debuginfo-2.6.9-78.0.1.EL.i686.rpm

    履歴

    2009年06月24日 RHEL4系記載追加
    2009年03月05日 新規作成

    2009年6月6日

    Linuxのcore dumpの中身についてその3

    coreファイル内のnoteセクションにどんな情報が含まれているのか調べてみた。


    まず、objdumpでセクション情報を調べる

    $ objdump -h core.3313
    core.3313:     file format elf32-i386
    Sections:
    Idx Name          Size      VMA       LMA       File off  Algn
    0 note0         000001d8  00000000  00000000  000001d4  2**0
    CONTENTS, READONLY
    ...

    readelfで見てみる

    $ readelf -a core.3313
    ...
    Notes at offset 0x000001d4 with length 0x000001d8:
    Owner         Data size       Description
    CORE          0x00000090      NT_PRSTATUS (prstatus structure)
    CORE          0x0000007c      NT_PRPSINFO (prpsinfo structure)
    CORE          0x00000090      NT_AUXV (auxiliary vector)

    出力の一番最後にnoteの情報が出ている。

    更に、note0のダンプを取り、readelfの結果と付き合わせてみる。

    $ objdump -s -j note0 core.3313
    core.3313:     file format elf32-i386
    Contents of section note0:
    0000 05000000 90000000 01000000 434f5245  ............CORE
    0010 00000000 0b000000 00000000 00000000  ................
    0020 0b000000 00000000 00000000 f10c0000  ................
    0030 460c0000 f10c0000 460c0000 00000000  F.......F.......
    0040 e7030000 00000000 87130000 00000000  ................
    0050 00000000 00000000 00000000 f43fa300  .............?..
    0060 b01db4bf 01000000 a04c8f00 00000000  .........L......
    0070 981db4bf 341eb4bf 7b000000 7b000000  ....4...{...{...
    0080 00000000 33000000 ffffffff 79830408  ....3.......y...
    0090 73000000 82020100 80150590 7b000000  s...........{...
    00a0 00000000 05000000 7c000000 03000000  ........|.......
    00b0 434f5245 00000000 00520000 00064000  CORE.....R....@.
    00c0 f401f401 f10c0000 460c0000 f10c0000  ........F.......
    00d0 460c0000 6269675f 61727261 79000000  F...big_array...
    00e0 00000000 2e2f6269 675f6172 72617920  ...../big_array
    00f0 00000000 00000000 00000000 00000000  ................
    0100 00000000 00000000 00000000 00000000  ................
    0110 00000000 00000000 00000000 00000000  ................
    0120 00000000 00000000 00000000 00000000  ................
    0130 00000000 05000000 90000000 06000000  ................
    0140 434f5245 00000000 20000000 00c43d00  CORE.... .....=.
    0150 21000000 00c03d00 10000000 fffbeb0f  !.....=.........
    0160 06000000 00100000 11000000 64000000  ............d...
    0170 03000000 34800408 04000000 20000000  ....4....... ...
    0180 05000000 07000000 07000000 00000000  ................
    0190 08000000 00000000 09000000 80820408  ................
    01a0 0b000000 f4010000 0c000000 f4010000  ................
    01b0 0d000000 f4010000 0e000000 f4010000  ................
    01c0 17000000 00000000 0f000000 3b1fb4bf  ............;...
    01d0 00000000 00000000                    ........

    noteセクションの構造は、以下のようになっている。

    [ ][ ][ ][ ] namesz(4byte)  ノート名の長さ
    [ ][ ][ ][ ] descsz(4byte)  ノート本体の長さ
    [ ][ ][ ][ ] type(4byte)    ノートのタイプ
    [ ][ ][ ]…[ ] name(Nbyte)  ノート名(長さはnamesz) ※4バイト境界
    [ ][ ][ ]…[ ] desc(Nbyte)  ノート本体(長さはdescs) ※4バイト境界

    次に、NT_PRSTATUS (prstatus structure)、NT_PRPSINFO (prpsinfo structure)、NT_AUXV (auxiliary vector)といったノートのタイプとノート本体。ノート名は只のテキスト情報なので、ダンプ結果を見れば一目瞭然と思う。

    ノートのタイプは、/usr/include/elf.hに定義がある。

    $ grep "define NT_" /usr/include/elf.h
    #define NT_PRSTATUS     1               /* Contains copy of prstatus struct */
    #define NT_FPREGSET     2               /* Contains copy of fpregset struct */
    #define NT_PRPSINFO     3               /* Contains copy of prpsinfo struct */
    #define NT_PRXREG       4               /* Contains copy of prxregset struct */
    #define NT_TASKSTRUCT   4               /* Contains copy of task structure */
    #define NT_PLATFORM     5               /* String from sysinfo(SI_PLATFORM) */
    #define NT_AUXV         6               /* Contains copy of auxv array */
    #define NT_GWINDOWS     7               /* Contains copy of gwindows struct */
    #define NT_ASRS         8               /* Contains copy of asrset struct */
    #define NT_PSTATUS      10              /* Contains copy of pstatus struct */
    #define NT_PSINFO       13              /* Contains copy of psinfo struct */
    #define NT_PRCRED       14              /* Contains copy of prcred struct */
    #define NT_UTSNAME      15              /* Contains copy of utsname struct */
    #define NT_LWPSTATUS    16              /* Contains copy of lwpstatus struct */
    #define NT_LWPSINFO     17              /* Contains copy of lwpinfo struct */
    #define NT_PRFPXREG     20              /* Contains copy of fprxregset struct*/
    #define NT_VERSION      1               /* Contains a version string.  */

    ノートの本体のうち、今回出てきたprstatus structureとprpsinfo structureは、/usr/include/sys/procfs.hに定義がある。

    $ cat /usr/include/sys/procfs.h
    ...
    struct elf_prstatus
    {
    struct elf_siginfo pr_info;         /* Info associated with signal.  */
    short int pr_cursig;                /* Current signal.  */
    unsigned long int pr_sigpend;       /* Set of pending signals.  */
    unsigned long int pr_sighold;       /* Set of held signals.  */
    __pid_t pr_pid;
    __pid_t pr_ppid;
    __pid_t pr_pgrp;
    __pid_t pr_sid;
    struct timeval pr_utime;            /* User time.  */
    struct timeval pr_stime;            /* System time.  */
    struct timeval pr_cutime;           /* Cumulative user time.  */
    struct timeval pr_cstime;           /* Cumulative system time.  */
    elf_gregset_t pr_reg;               /* GP registers.  */
    int pr_fpvalid;                     /* True if math copro being used.  */
    };
    ...
    struct elf_prpsinfo
    {
    char pr_state;                      /* Numeric process state.  */
    char pr_sname;                      /* Char for pr_state.  */
    char pr_zomb;                       /* Zombie.  */
    char pr_nice;                       /* Nice val.  */
    unsigned long int pr_flag;          /* Flags.  */
    unsigned short int pr_uid;
    unsigned short int pr_gid;
    int pr_pid, pr_ppid, pr_pgrp, pr_sid;
    /* Lots missing */
    char pr_fname[16];                  /* Filename of executable.  */
    char pr_psargs[ELF_PRARGSZ];        /* Initial part of arg list.  */
    };
    ...

    auxiliary vectorとは、id(4byte)とその値Val(4byte)が交互に並んだ構造をしており、id=0となったところが構造の終わりとなっている。

    [id(4byte)][val(4byte)][id(4byte)][val(4byte)]...[id(4byte)][val(4byte)]

    idは/usr/include/elf.hに定義されている

    $ grep "define AT_" /usr/include/elf.h
    #define AT_NULL         0               /* End of vector */
    #define AT_IGNORE       1               /* Entry should be ignored */
    #define AT_EXECFD       2               /* File descriptor of program */
    #define AT_PHDR         3               /* Program headers for program */
    #define AT_PHENT        4               /* Size of program header entry */
    #define AT_PHNUM        5               /* Number of program headers */
    #define AT_PAGESZ       6               /* System page size */
    #define AT_BASE         7               /* Base address of interpreter */
    #define AT_FLAGS        8               /* Flags */
    #define AT_ENTRY        9               /* Entry point of program */
    #define AT_NOTELF       10              /* Program is not ELF */
    #define AT_UID          11              /* Real uid */
    #define AT_EUID         12              /* Effective uid */
    #define AT_GID          13              /* Real gid */
    #define AT_EGID         14              /* Effective gid */
    #define AT_CLKTCK       17              /* Frequency of times() */
    #define AT_PLATFORM     15              /* String identifying platform.  */
    #define AT_HWCAP        16              /* Machine dependent hints about
    #define AT_FPUCW        18              /* Used FPU control word.  */
    #define AT_DCACHEBSIZE  19              /* Data cache block size.  */
    #define AT_ICACHEBSIZE  20              /* Instruction cache block size.  */
    #define AT_UCACHEBSIZE  21              /* Unified cache block size.  */
    #define AT_IGNOREPPC    22              /* Entry should be ignored.  */
    #define AT_SYSINFO      32
    #define AT_SYSINFO_EHDR 33
    #define AT_L1I_CACHESHAPE       34
    #define AT_L1D_CACHESHAPE       35
    #define AT_L2_CACHESHAPE        36
    #define AT_L3_CACHESHAPE        37

    2009年5月28日

    カーネルのライブHacking(RHEL AS 4U4)

    lockdのnlm_hosts構造体の内容を確認することがあったので、その際のcrashコマンドの使い方をメモ書きしておく。


    crashコマンドを起動

    # crash
    ...
    crash>

    デバッグモジュールの読み込み

    crash> mod -s lockd lockd.ko.debug

    構造体のアドレスを確認

    crash> list nlm_hosts
    d0b8c7a0

    構造体の内容表示

    crash> struct nlm_host d0b8c7a0
    ...

    以上

    debuginfoの設定(RHEL AS 4U4)

    故あって、RHEL AS 4U4にカーネルdebuginfoを設定し、crashコマンドが使えるようにすることに。



    まず、カーネルのバージョンを確認。

    # uname -a
    Linux localhost.localdomain 2.6.9-42.EL #1 Wed Jul 12 23:16:43
    EDT 2006 i686 athlon i386 GNU/Linux

    debuginfoパッケージを入手。

    # wget http://ftp.redhat.com/pub/redhat/linux/updates/enterpri
    se/4AS/en/os/Debuginfo/i386/RPMS/kernel-debuginfo-2.6.9-42.EL.
    i686.rpm

    インストール。

    # rpm -ihv kernel-debuginfo-2.6.9-42.EL.i686.rpm

    最後に確認。

    # crash
    ...
    crash>

    crashコマンドのプロンプトが出ればOK。