LoginSignup
53
44

More than 5 years have passed since last update.

gdbを使う

Last updated at Posted at 2017-09-23

はじめに

gdb の使い方を記載します。

The GNU Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java and partially others.

from https://en.wikipedia.org/wiki/GNU_Debugger

gdbはsource-level debuggerです。ソースコードの行単位でステップ実行できます。
machine-language debuggerとしても利用できます。機械語単位でステップ実行できます。

sample program

次のsample programを用いて説明します。

test.c
#include <stdio.h>

int sum = 0;

int add(int a, int b)
{
    return a + b;
}

int main(int argc, char* argv[])
{
    int a = atoi(argv[1]);
    int b = atoi(argv[2]);
    sum = add(a, b);

    printf("sum=%d\n", sum);
    return 0;
}

コンパイルオプション(-g -O0)

デバッグ対象のプログラムは次のオプションを指定してコンパイルします。
-gを指定します。debugging informationを生成します。
-O0を指定します。最適化を無効にします。

console
gcc -g -O0 test.c -o test
./test 10 20
sum=30

gdb 起動 / 終了 q(uit)

引数にプログラムを指定してgdbを起動します。
runコマンドで明示的に開始するまではプログラムは実行開始しません。

console
gdb ./test
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
(snip)
Reading symbols from ./test...done.

引数はset argsで設定します。show argsで確認できます。

console
(gdb) set args 10 20
(gdb) show args
Argument list to give program being debugged when it is started is "10 20".

q(uit)でgdbを終了します。

console
(gdb) q
$ 

Configuration Variables

次の形式でnameというConfiguration Variablesに値valueを設定します。

set name value

Configuration Variablesに応じてgdbの動作を設定できます。
次のConfiguration Variablesがあります。

name description
confirm 0 : 確認を無効にする、1 : 有効にする
pagination 0 : ページ送りの確認を無効にする、1 : 有効にする
disassemble-next-line 0 : 実行停止時にassemblerを表示しない、1 : 表示する

confirm

0 : ユーザ確認を無効にします
1 : ユーザ確認を有効にします(default)

(gdb) set confirm 1
(gdb) d
Delete all breakpoints? (y or n) n
(gdb) set confirm 0
(gdb) d

pagination

0 : ページ送りの確認を無効にします
1 : ページ送りの確認を有効にします(default)

(gdb) set pagination 1
(gdb) info file
Symbols from "/home/user/tmp/a.out".
...
---Type <return> to continue, or q <return> to quit---q
Quit
(gdb) set pagination 0
(gdb) info file
Symbols from "/home/user/tmp/a.out".
...
gnu/libc.so.6

---Type to continue, or q to quit---

0に設定すると上記、確認をしません。

.gdbinit

.gdbinitはgdbの初期化スクリプトファイルです。起動時に定型コマンドを自動入力できます。

具体例を以下に示します。

~/.gdbinit
set auto-load safe-path ~
set pagination 0
.gdbinit
set args 10 20

よく使う.gdbinit

.gdbinit
set confirm 0
set pagination 0
target remote :1234

command list

gdbコマンドの一覧を以下に示します。()内の文字列は省略できます。r(un)を例に説明します。
runを入力する代わりにrのみの入力でrunコマンドを実行できます。

コマンド 説明
r(un) プログラム実行を開始します
c(ontinue) プログラム実行を再開します
q(uit) gdbを終了します
b(reak) break pointを設定します
n(ext) 次のソースコード行を実行します。関数内に入りません
s(tep) 次のソースコード行を実行します。関数内に入ります
ni 次の機械語命令を実行します。call先に入りません
si 次の機械語命令を実行します。call先に入ります
bt backtraceを表示します
up 1つ上のframeに移動します 実行はしません
down 1つ下のframeに移動します 実行はしません
u(ntil) 指定した位置まで実行します
fin(ish) 現在の関数の実行を完了します
p(rint) var 変数を表示します
disp(lay) 実行停止時に表示する変数を登録します
x メモリをダンプします
d(elete) d(isplay) displayの登録を解除します
d(elete) br(eak) break pointを削除します
i(nfo) r(egisters) レジスタの内容を表示します
i(nfo) b(reakpoints) ブレークポイントを表示します
i(nfo) sh(aredlibrary) 共有ライブラリを表示します
i(nfo) lo(cals) ローカル変数を表示します
i(nfo) i(nferiors) プロセスリストを表示します
i(nfo) th(reads) スレッドリストを表示します
i(nfo) f(rame) スタックを表示します
i(nfo) fi(les) or i tar(get) 実行ファイルの情報を表示します
i(nfo) li(ne) breakしている位置を表示します
i(nfo) li(ne) symbol シンボルの位置を表示します
i(nfo) o(s) OSの情報を表示します、サブコマンドで情報を指定します(*1)
i(nfo) fu(nctions) regex 関数シンボルを正規表現で指定します
i(nfo) va(riables) regex 変数シンボルを正規表現で指定します
disas(semble) disassembleします

(*1)サブコマンド一覧

(gdb) i o
Type       Description 
processes  Listing of all processes 
procgroups Listing of all process groups 
threads    Listing of all threads 
files      Listing of all file descriptors 
sockets    Listing of all internet-domain sockets 
shm        Listing of all shared-memory regions 
semaphores Listing of all semaphores 
msg        Listing of all message queues 
modules    Listing of all loaded kernel modules 

command

r(un)

プログラムを開始します。

console
$ gdb ./test 
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
(snip)
Reading symbols from ./test...done.
(gdb) set args 10 20
(gdb) r
Starting program: /home/user/test 10 20
sum=30
[Inferior 1 (process 11695) exited normally]

b(reak)

Locationを指定してbreak pointを作成します。

Location

Locationについて説明します。Locationには

  • Linespec locations
  • Address locations

があります。

Linespec locationsは次のように指定します。

  • linenum

例. b 10
現在のファイルの10行目にbreak pointを設定します。

  • filename:linenum

例. b test.c:10
test.cの10行目にbreak pointを設定します。

  • function

例. b main
mainの定義位置にbreak pointを設定します。

Address locationsは次のように指定します。

  • *address

例. b *0x00000000004005ce
アドレス0x00000000004005ceの命令にbreak pointを設定します。

mainのシンボルでbreakする例です。

$ gdb ./test 
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
(snip)
Reading symbols from ./test...done.
(gdb) set args 10 20
(gdb) b main
Breakpoint 1 at 0x4005a0: file test.c, line 12.
(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000004005a0 in main at test.c:12
(gdb) r
Starting program: /home/user/test 10 20

Breakpoint 1, main (argc=3, argv=0x7fffffffdfe8) at test.c:12
12      int a = atoi(argv[1]);

アドレス指定でbreakする例です。

(gdb) b *0x00000000004005ce
Breakpoint 2 at 0x4005ce: file test.c, line 11.
(gdb) c
Continuing.

Breakpoint 2, 0x00000000004005ce in main (argc=3, argv=0x7fffffffdfa8) at test.c:11
11      int b = atoi(argv[2]);

c(ontinue)

プログラムを再開します。一時停止中から再開します。

(gdb) c
Continuing.
sum=30
[Inferior 1 (process 3868) exited normally]

n(ext)

次のソースコード行を実行します。関数内に入りません

Breakpoint 2, main (argc=3, argv=0x7fffffffdff8) at test.c:14
14      sum = add(a, b);
(gdb) l
9   
10  int main(int argc, char* argv[])
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
17      return 0;
18  }
(gdb) n
16      printf("sum=%d\n", sum);
(gdb) l
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
17      return 0;
18  }

s(tep)

次のソースコード行を実行します。関数内に入ります

Breakpoint 2, main (argc=3, argv=0x7fffffffdff8) at test.c:14
14      sum = add(a, b);
(gdb) l
9   
10  int main(int argc, char* argv[])
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
17      return 0;
18  }
(gdb) s
add (a=10, b=20) at test.c:7
7       return a + b;
(gdb) l
2   
3   int sum = 0;
4   
5   int add(int a, int b)
6   {
7       return a + b;
8   }
9   
10  int main(int argc, char* argv[])
11  {

ni

次の機械語命令を実行します。call先に入りません

Breakpoint 3, 0x00000000004005b3 in main (argc=3, argv=0x7fffffffdff8) at test.c:12
12      int a = atoi(argv[1]);
(gdb) disas
Dump of assembler code for function main:
(snip)
   0x00000000004005ae <+29>:    mov    $0x0,%eax
=> 0x00000000004005b3 <+34>:    callq  0x400480 <atoi@plt>
   0x00000000004005b8 <+39>:    mov    %eax,-0x8(%rbp)
(snip)
End of assembler dump.
(gdb) ni
0x00000000004005b8  12      int a = atoi(argv[1]);
(gdb) disas
Dump of assembler code for function main:
(snip)
   0x00000000004005ae <+29>:    mov    $0x0,%eax
   0x00000000004005b3 <+34>:    callq  0x400480 <atoi@plt>
=> 0x00000000004005b8 <+39>:    mov    %eax,-0x8(%rbp)
   0x00000000004005bb <+42>:    mov    -0x20(%rbp),%rax
(snip)
End of assembler dump.

si

次の機械語命令を実行します。call先に入ります

Breakpoint 3, 0x00000000004005b3 in main (argc=3, argv=0x7fffffffdff8) at test.c:12
12      int a = atoi(argv[1]);
(gdb) disas
Dump of assembler code for function main:
(snip)
   0x00000000004005ae <+29>:    mov    $0x0,%eax
=> 0x00000000004005b3 <+34>:    callq  0x400480 <atoi@plt>
   0x00000000004005b8 <+39>:    mov    %eax,-0x8(%rbp)
(snip)
End of assembler dump.
(gdb) si
0x0000000000400480 in atoi@plt ()
(gdb) disas
Dump of assembler code for function atoi@plt:
=> 0x0000000000400480 <+0>: jmpq   *0x200baa(%rip)        # 0x601030 <atoi@got.plt>
   0x0000000000400486 <+6>: pushq  $0x3
   0x000000000040048b <+11>:    jmpq   0x400440
End of assembler dump.

bt

backtraceを表示します
addにbreakを設定して、breakします。btでbacktraceを表示します
main -> add という順番で関数callされていることが分かります

(gdb) b add
Breakpoint 6 at 0x400587: file test.c, line 7.
(gdb) r
Starting program: /home/user/tmp/a.out 10 20

Breakpoint 6, add (a=10, b=20) at test.c:7
7       return a + b;
(gdb) bt
#0  add (a=10, b=20) at test.c:7
#1  0x00000000004005e5 in main (argc=3, argv=0x7fffffffe008) at test.c:14

up

1つ上のframeに移動します
実行はしません ソースコード or assemblerの表示移動のみです
addの呼出し元に移動します

(gdb) bt
#0  add (a=10, b=20) at test.c:7
#1  0x00000000004005e5 in main (argc=3, argv=0x7fffffffe008) at test.c:14
(gdb) up
#1  0x00000000004005e5 in main (argc=3, argv=0x7fffffffe008) at test.c:14
14      sum = add(a, b);
(gdb) l
9   
10  int main(int argc, char* argv[])
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
17      return 0;
18  }

down

1つ下のframeに移動します
実行はしません ソースコード or assemblerの表示移動のみです
addの呼出し元からaddに移動します

(gdb) down
#0  add (a=10, b=20) at test.c:7
7       return a + b;
(gdb) l
2   
3   int sum = 0;
4   
5   int add(int a, int b)
6   {
7       return a + b;
8   }
9   
10  int main(int argc, char* argv[])

u(ntil)

指定した位置まで実行します
main関数の先頭でbreakします
16行目まで実行を進めます

(gdb) b main
Breakpoint 7 at 0x4005a0: file test.c, line 12.
(gdb) r
Starting program: /home/user/tmp/a.out 10 20

Breakpoint 7, main (argc=3, argv=0x7fffffffe008) at test.c:12
12      int a = atoi(argv[1]);
(gdb) l
7       return a + b;
8   }
9   
10  int main(int argc, char* argv[])
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
(gdb) u 16
main (argc=3, argv=0x7fffffffe008) at test.c:16
16      printf("sum=%d\n", sum);

fin(ish)

現在の関数の実行を完了します 呼出し元に戻ります
addでbreakします
addの関数から戻ります

(gdb) b add
Breakpoint 8 at 0x400587: file test.c, line 7.
(gdb) r
Starting program: /home/user/tmp/a.out 10 20

Breakpoint 8, add (a=10, b=20) at test.c:7
7       return a + b;
(gdb) fin
Run till exit from #0  add (a=10, b=20) at test.c:7
0x00000000004005e5 in main (argc=3, argv=0x7fffffffe008) at test.c:14
14      sum = add(a, b);
Value returned is $3 = 30
(gdb) l
9   
10  int main(int argc, char* argv[])
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
17      return 0;
18  }

p(rint)

変数を表示します

Breakpoint 4, main (argc=3, argv=0x7fffffffdff8) at test.c:12
12      int a = atoi(argv[1]);
(gdb) l
7       return a + b;
8   }
9   
10  int main(int argc, char* argv[])
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
(gdb) p a
$2 = 0
(gdb) p b
$3 = 0
(gdb) p sum
$4 = 0
(gdb) p argc
$5 = 3
(gdb) p argv
$6 = (char **) 0x7fffffffdff8
(gdb) p argv[0]
$7 = 0x7fffffffe362 "/home/user/gdbsample/test"
(gdb) p argv[1]
$8 = 0x7fffffffe37c "10"
(gdb) p argv[2]
$9 = 0x7fffffffe37f "20"
(gdb) p argv[3]
$10 = 0x0

disp(lay)

実行停止時に表示する変数を登録します

Breakpoint 1, main (argc=3, argv=0x7fffffffdff8) at test.c:12
12      int a = atoi(argv[1]);
(gdb) b +1
Breakpoint 2 at 0x4005bb: file test.c, line 13.
(gdb) b +2
Breakpoint 3 at 0x4005d6: file test.c, line 14.
(gdb) disp sum
1: sum = 0
(gdb) n

Breakpoint 2, main (argc=3, argv=0x7fffffffdff8) at test.c:13
13      int b = atoi(argv[2]);
1: sum = 0
(gdb) 

Breakpoint 3, main (argc=3, argv=0x7fffffffdff8) at test.c:14
14      sum = add(a, b);
1: sum = 0
(gdb) 
16      printf("sum=%d\n", sum);
1: sum = 30
(gdb) i disp
Auto-display expressions now in effect:
Num Enb Expression
1:   y  sum
(gdb) d disp
Delete all auto-display expressions? (y or n) y
(gdb) i disp
There are no auto-display expressions now.

x

メモリをダンプします
フォーマットは

x/nfu addr

です。
nは繰り返し回数を指定します。
fはフォーマットを指定します。
printfのx/d/u/o/t/a/c/f/sが指定できます。iは機械語を指定します。
uはunitを指定します。
b : Bytes.
h : Halfwords (two bytes).
w : Words (four bytes). This is the initial default.
g : Giant words (eight bytes).

x/10bxは
10byte
b : byte区切りで
x : 16進数表示
するように指示します。

(gdb) x/10bx 0x00000000004005ce
0x4005ce <main+61>: 0xe8    0xad    0xfe    0xff    0xff    0x89    0x45    0xfc
0x4005d6 <main+69>: 0x8b    0x55

d(elete) d(isplay)

displayの登録を解除します。

(gdb) d disp
Delete all auto-display expressions? (y or n) y

d(elete) br(eak)

break pointを削除します

(gdb) d br
Delete all breakpoints? (y or n) y
(gdb) b +1
Breakpoint 4 at 0x400602: file test.c, line 17.
(gdb) b +2
Breakpoint 5 at 0x400607: file test.c, line 18.
(gdb) i b
Num     Type           Disp Enb Address            What
4       breakpoint     keep y   0x0000000000400602 in main at test.c:17
5       breakpoint     keep y   0x0000000000400607 in main at test.c:18
(gdb) d br 4
(gdb) i b
Num     Type           Disp Enb Address            What
5       breakpoint     keep y   0x0000000000400607 in main at test.c:18

i(nfo) reg(isters)

レジスタ値を表示します。一時停止中に入力します

(gdb) i reg
rax            0x400591 4195729
rbx            0x0  0
rcx            0x0  0
rdx            0x7fffffffdfc8   140737488347080
rsi            0x7fffffffdfa8   140737488347048
rdi            0x3  3
rbp            0x7fffffffdec0   0x7fffffffdec0
rsp            0x7fffffffdea0   0x7fffffffdea0
r8             0x7ffff7dd4e80   140737351863936
r9             0x7ffff7dea560   140737351951712
r10            0x7fffffffdd50   140737488346448
r11            0x7ffff7a35dd0   140737348066768
r12            0x400490 4195472
r13            0x7fffffffdfa0   140737488347040
r14            0x0  0
r15            0x0  0
rip            0x4005a0 0x4005a0 <main+15>
eflags         0x206    [ PF IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0

i(nfo) b(reakpoints)

ブレークポイントを表示します

(gdb) b main
Breakpoint 7 at 0x4005a0: file test.c, line 12.
(gdb) b +1
Breakpoint 8 at 0x400602: file test.c, line 17.
(gdb) i b
Num     Type           Disp Enb Address            What
7       breakpoint     keep y   0x00000000004005a0 in main at test.c:12
8       breakpoint     keep y   0x0000000000400602 in main at test.c:17

i(nfo) sh(aredlibrary)

共有ライブラリを表示します

(gdb) i sh
From                To                  Syms Read   Shared Object Library
0x00007ffff7ddaae0  0x00007ffff7df54e0  Yes         /lib64/ld-linux-x86-64.so.2
0x00007ffff7a334a0  0x00007ffff7b79413  Yes         /lib/x86_64-linux-gnu/libc.so.6

i(nfo) lo(cals)

ローカル変数を表示します

(gdb) i lo
a = 10
b = 20
(gdb) l
11  {
12      int a = atoi(argv[1]);
13      int b = atoi(argv[2]);
14      sum = add(a, b);
15  
16      printf("sum=%d\n", sum);
17      return 0;
18  }

i(nfo) i(nferiors)

プロセスリストを表示します

(gdb) i i
  Num  Description       Executable        
* 1    process 21305     /home/user/gdbsample/test 

i(nfo) th(reads)

スレッドリストを表示します

(gdb) i th
  Id   Target Id         Frame 
* 1    process 21305 "test" main (argc=3, argv=0x7fffffffdff8) at test.c:16

i(nfo) f(rame)

スタックを表示します

(gdb) i f
Stack level 0, frame at 0x7fffffffdf20:
 rip = 0x4005eb in main (test.c:16); saved rip = 0x7ffff7a35ec5
 source language c.
 Arglist at 0x7fffffffdf10, args: argc=3, argv=0x7fffffffdff8
 Locals at 0x7fffffffdf10, Previous frame's sp is 0x7fffffffdf20
 Saved registers:
  rbp at 0x7fffffffdf10, rip at 0x7fffffffdf18

i(nfo) fi(les) or i tar(get)

実行ファイルの情報を表示します

(gdb) i fi
Symbols from "/home/user/gdbsample/test".
Unix child process:
    Using the running image of child process 21305.
    While running this, GDB does not access memory from...
Local exec file:
    `/home/user/gdbsample/test', file type elf64-x86-64.
    Entry point: 0x400490
    0x0000000000400238 - 0x0000000000400254 is .interp
    0x0000000000400254 - 0x0000000000400274 is .note.ABI-tag
(snip)
    0x0000000000601048 - 0x0000000000601050 is .bss
    0x00007ffff7dda1c8 - 0x00007ffff7dda1ec is .note.gnu.build-id in /lib64/ld-linux-x86-64.so.2
(snip)
    0x00007ffff7dd48a0 - 0x00007ffff7dd92c0 is .bss in /lib/x86_64-linux-gnu/libc.so.

i(nfo) li(ne)

breakしている位置を表示します

(gdb) i li
Line 18 of "test.c" starts at address 0x400607 <main+118> and ends at 0x400609.

i(nfo) li(ne) symbol

シンボルの位置を表示します

(gdb) i li add
Line 6 of "test.c" starts at address 0x40057d <add> and ends at 0x400587 <add+10>.

i(nfo) o(s)

OSの情報を表示します、サブコマンドで情報を指定します

(gdb) i o
Type       Description 
processes  Listing of all processes 
procgroups Listing of all process groups 
threads    Listing of all threads 
files      Listing of all file descriptors 
sockets    Listing of all internet-domain sockets 
shm        Listing of all shared-memory regions 
semaphores Listing of all semaphores 
msg        Listing of all message queues 
modules    Listing of all loaded kernel modules 

processes

(gdb) i o processes
pid        user       command    cores      
1          root       /sbin/init 1          
2          root       [kthreadd] 0          
3          root       [ksoftirqd/0] 0    
(snip)

procgroups

(gdb) i o procgroups
pgid       leader command pid        command line 
1          init       1          /sbin/init 
576        576        577        upstart-udev-bridge --daemon 
589        systemd-udevd 589        /lib/systemd/systemd-udevd --daemon 
748        dbus-daemon 748        dbus-daemon --system --fork 
748        dbus-daemon 1068       /usr/lib/policykit-1/polkitd --no-debug 
748        dbus-daemon 1337       /usr/lib/accountsservice/accounts-daemon 
748        dbus-daemon 1778       /usr/lib/upower/upowerd 
(snip)

threads

(gdb) i o threads
pid        command    tid        core       
1          init       1          1          
2          kthreadd   2          0          
3          ksoftirqd/0 3          0          
5          kworker/0:0H 5          0          
7          rcu_sched  7          1          
8          rcuos/0    8          0          
9          rcuos/1    9          1          
10         rcuos/2    10         0          
11         rcuos/3    11         0      
(snip)

files

(gdb) i o files
pid        command    file descriptor name       
2243       init       0          /dev/null  
2243       init       1          /dev/null  
2243       init       2          /home/user/.xsession-errors 
(snip)

sockets

(gdb) i o sockets
local address local port remote address remote port state      user       family     protocol   
127.0.1.1  53         0.0.0.0    0          LISTEN     root       INET       STREAM     
127.0.0.1  631        0.0.0.0    0          LISTEN     root       INET       STREAM     
0.0.0.0    445        0.0.0.0    0          LISTEN     root       INET       STREAM   
(snip)

shm

(gdb) i o shm
key        shmid      permissions size       creator command last op. command num attached user       group      creator user creator group last shmat() time last shmdt() time last shmctl() time 
0          2064384    1600       524288     gnome-terminal 21333      2          user       user       user       user       Mon May  8 01:27:19 2017 Mon May  8 01:27:19 2017 Mon May  8 00:42:47 2017 
0          393217     1600       524288     ibus-ui-gtk3 2476       2          user       user       user       user       Sun May  7 23:56:49 2017 Sun May  7 23:56:49 2017 Sun May  7 23:56:48 2017 
(snip)

(*) semaphores / msgは何も表示されなかったため未記載とします。

modules

(gdb) i o modules
name       size       num uses   dependencies status     address    
vmw_vsock_vmci_transport 26278      0          -          Live       0          
vsock      34895      5          vmw_vsock_vmci_transport, Live       0          
vmhgfs     54305      1          -          Live       0          
coretemp   13435      0          -          Live       0          
crct10dif_pclmul 14289      0          -          Live       0          
crc32_pclmul 13113      0          -          Live       0          
vmw_balloon 13415      0          -          Live       0     
(snip)

i(nfo) fu(nctions) regex

関数シンボルを正規表現で指定します

(gdb) i fu atoi
All functions matching regular expression "atoi":

File atoi.c:
int atoi(const char *);

Non-debugging symbols:
0x0000000000400480  atoi@plt

i(nfo) va(riables) regex

変数シンボルを正規表現で指定します

(gdb) i va sum
All variables matching regular expression "sum":

File ../sysdeps/gnu/unwind-resume.c:
static void (*libgcc_s_resume)(struct _Unwind_Exception *);

File test.c:
int sum;

disas(semble)

disassembleします

(gdb) b main
Breakpoint 11 at 0x4005a0: file test.c, line 12.
(gdb) r
Starting program: /home/user/tmp/a.out 10 20

Breakpoint 11, main (argc=3, argv=0x7fffffffe008) at test.c:12
12      int a = atoi(argv[1]);
(gdb) disas $rip
Dump of assembler code for function main:
   0x0000000000400591 <+0>: push   %rbp
   0x0000000000400592 <+1>: mov    %rsp,%rbp
   0x0000000000400595 <+4>: sub    $0x20,%rsp
   0x0000000000400599 <+8>: mov    %edi,-0x14(%rbp)
   0x000000000040059c <+11>:    mov    %rsi,-0x20(%rbp)
=> 0x00000000004005a0 <+15>:    mov    -0x20(%rbp),%rax
...
(gdb) disas 0x00000000004005e0
Dump of assembler code for function main:
   0x0000000000400591 <+0>: push   %rbp
   0x0000000000400592 <+1>: mov    %rsp,%rbp
   0x0000000000400595 <+4>: sub    $0x20,%rsp
   0x0000000000400599 <+8>: mov    %edi,-0x14(%rbp)
   0x000000000040059c <+11>:    mov    %rsi,-0x20(%rbp)
=> 0x00000000004005a0 <+15>:    mov    -0x20(%rbp),%rax
...

TUI mode

C-x + C-a を入力することでTUI modeに入ります。
再度、C-x + C-a を入力することでTUI modeから出ます。

画面の下にはcommand入力画面が表示されます。
画面の上にはTUI layoutを1つまたは2つ表示できます。

TUI layoutはsrc / asm / regs があります。

  • layout src : TUI layoutをソースコード表示画面に設定します。
  • layout asm : TUI layoutをアセンブラ表示画面に設定します。
  • layout regs : TUI layoutをレジスタ表示画面に設定します。
  • C-x 1 : TUI layoutを1つにします。
  • C-x 2 : TUI layoutを2つにします。
  • C-l or refresh : 画面を再描画します。

TUI layout

  • layout src

layout_src.JPG

  • layout asm

layout_asm.JPG

  • layout regs

layout_regs.JPG

references

53
44
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
44