[Linux]GDBの基本的な使い方

スポンサーリンク

昔の情報

※GDBは、GNU General Public License (GPL) の下でリリースしている フリーソフトウェア

=====

  • Linuxでのコンソール
    >
  • gdbでのデバッグ状態
    (gdb)
  • lcrashコマンド実行状態
    >>

gdbを用いてlcrashの起動(デバッグ対象ツールを読み込み)

> gdb ./lcrash
GNU gdb 6.6
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 "i586-suse-linux"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb)

引数の設定

(gdb) set args System.map dump_file Kerntypes

lcrash起動(run)

(gdb) r
Starting program: ./lcrash System.map dump_file Kerntypes
lcrash 0.10.2 (xlcrash) build at Jan  9 2008 11:57:42
Lcrash is free software. It is covered by the GNU General Public License.
You are welcome to change it and/or distribute copies of it under certain
conditions. Type "help -C" to see the conditions. Absolutely no warranty
is given for Lcrash. Type "help -W" for warranty details.
...
...
>>

gdb状況へ戻る

「Ctrl+C」を押す

>>
Program received signal SIGINT, Interrupt.
0xffffe410 in __kernel_vsyscall ()
(gdb)

ブレイクポイントを指定

(gdb) b module_cmd
Breakpoint 1 at 0x80f6698: file cmd_module.c, line 32.
(gdb) b 50
Breakpoint 2 at 0x805d414: file main.c, line 50.

ブレイクポイント1、2が指定された。

次のブレイクポイントまで進む、lcrash実行状態へ戻る(continue、c)

(gdb) c
Continuing.
>>

ブレイクポイントで止めてみる

>> module
Breakpoint 1, module_cmd (cmd=0x83ae990) at cmd_module.c:32
32              void * modptr = NULL;

次のコードへ進む(next、n)

(gdb) n
33              kaddr_t modaddr = 0;

何も指定せずに「Enter」を押すと前の命令と同じ物を繰り返す。

(gdb)
34              char * modname = NULL;
(gdb)
36              if(cmd->nargs==0){
(gdb)

ステップ実行(setp、s)

コード確認(list、l)

変数値確認、変数値変更(関数へのアドレスなども変更可能)(point、p)

変数値の表示(display)

info

(gdb) info b

→ブレイクポイント情報の表示


追記、実際の例

コメント

タイトルとURLをコピーしました