==Linux C gdbによるデバッグ==
[[Programming C][Linux]]
以下の本からのメモ。良書。
{{amazon|4797328355}}
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.2)
Copyright (C) 2009 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"
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<<http://www.gnu.org/software/gdb/bugs/>>...
Reading symbols from /root/workspace/myhead/src/myhead...done.
(gdb)
0x00bfe50b in ____strtol_l_internal () from /lib/libc.so.6
<<blockquote>>Segmentation fault が発生したので、その場所で停止し、問題の起きた場所を表示<</blockquote>>
===スタックトレースを backtrace コマンドで表示する===
#3 0x0804862b in main (argc=3, argv=0xbfffe864) at myhead.c:31
31 nlines = atol(optarg);
<<blockquote>>実行中の関数が、main になり、実行中の行が表示される<</blockquote>>
*もう少し広い範囲を見るときには、listコマンドを使用する
(gdb) list
(gdb) print optarg
$1 = 0x0
<<blockquote>>中身がNULL。Nullポインタがセグメンテーション違反の原因と判明<</blockquote>>
===continue 、quit で、デバッグを終了する===