C言語で書いたプログラムが、SIGSGVのシグナルを受けて終了、セグメンテーションフォルトになる場合のデバッグ方法
isii> ./a.out 1301051.htm
Segmentation fault
メモリ操作の誤りによって、不正な位置に書き込んだりすると、
セグメンテーションフォールトとなり、プログラムは殺されます。
ソース中の問題箇所を探す場合はデバッガを使います。
ここでは、GNUのgdbを紹介します。
(1)デバッグ情報を埋め込む
まず、コンパイル時に-gオプションを指定して、デバッグ情報を埋め込みます。
> gcc -g getword.c
(2)デバッガーを起動する
gdbを起動して、問題の実行ファイルをロードします。
> gdb a.out
GDB is free software and you are welcome to 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.
GDB 4.16 (sparc-sun-solaris2.5.1),
Copyright 1996 Free Software Foundation, Inc...
(gdb)
(3) プログラムを実行する。
gdbのrunコマンドで実行します。パラメータがある場合は、指定します。
(gdb) run 1301051.htm
Program received signal SIGSEGV, Segmentation fault.
0xef7291fc in strcpy ()
(gdb)
(4) 問題の場所を特定します
(gdb) where
#0 0xef7291fc in strcpy ()
#1 0x10ab4 in GetWord (fp=0xef79ab40, wd=0xefffed08 ">",
demilit=0x10e50 ";#<>()[]!\n", line=0xeffff10c) at getword.c:169
#2 0x10d4c in main (argc=2, argv=0xeffff18c) at getword.c:242
(gdb)
2007年8月10日金曜日
登録:
コメントの投稿 (Atom)

0 件のコメント:
コメントを投稿