Unixコマンド/gdb

gdb

gdb は Gnu DeBugger の略称で、gcc(もしくは互換のコンパイラ)でコンパイルしたプログラムのデバッグを支援します。

プログラムのコンパイル

gcc -g -O0 <ソースファイル名>

オプション

オプション             意味 
-g            ファイルにデバッグ情報を付加する。これがないとデバッグ時に変数名や行番号が表示されない 
-O0           最適化を行わない。最適化を行うと、コードの入れ替えや削除が行われてしまい、デバッグしにくくなる

使用例

$ gdb a.out
GNU gdb 6.1.1 [FreeBSD]
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 "i386-marcel-freebsd"...
(gdb) break main ・・ブレイクポイントをmainに
(gdb) run        ・・スタート
(gdb) next       ・・次へ
(gdb) next       ・・次へ
(gdb) next       ・・次へ
(gdb) next       ・・次へ
(gdb) next       ・・次へ
(gdb) quit       ・・終了

参考サイト

http://uguisu.skr.jp/Windows/gdb.html