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 */に変わった。バイナリとソースのバージョンは正確に一致していないとデバッグは出来ないようだ。

コメント