使用gdb作为监视器?

5 assembly gdb

GDB可以像传统的装配监视器一样使用吗?

一进入eg.它返回的库代码:

No function contains program counter for selected frame
Run Code Online (Sandbox Code Playgroud)

GDB调试器能够进入未知代码,但GDB UI停止工作.

在这个相关的问题,你可以找到一对建议的解决方案,但都不能完全满足我.

如果二进制库没有调试符号包怎么办?如果程序跳转到运行时生成的代码怎么办?

由于UI忽略了代码,因此反汇编代码并不是真正的解决方案,最重要的是,在返回到原始已知代码之前,寄存器的值不会更新.info registers工作,但这很难互动.

有什么建议吗?

谢谢!

Mat*_*ery 8

您可以使用该display命令执行此类操作.

display/i $pc 将在每次打印提示之前反汇编当前指令:

(gdb) b main
Breakpoint 1 at 0x80483b5: file hw.c, line 5.
(gdb) display/i $pc
(gdb) r
Starting program: /tmp/hw

Breakpoint 1, main () at hw.c:5
5         puts("Hello world");
1: x/i $pc
0x80483b5 <main+17>:    movl   $0x8048490,(%esp)
Run Code Online (Sandbox Code Playgroud)

现在执行一条指令(然后继续按Enter键重复):

(gdb) si
0x080483bc      5         puts("Hello world");
1: x/i $pc
0x80483bc <main+24>:    call   0x80482d4 <puts@plt>
(gdb) 
0x080482d4 in puts@plt ()
1: x/i $pc
0x80482d4 <puts@plt>:   jmp    *0x804959c
Current language:  auto; currently asm
(gdb) 
0x080482da in puts@plt ()
1: x/i $pc
0x80482da <puts@plt+6>: push   $0x10
(gdb) 
0x080482df in puts@plt ()
1: x/i $pc
0x80482df <puts@plt+11>:        jmp    0x80482a4 <_init+48>
Run Code Online (Sandbox Code Playgroud)

当我们到达这一点时,它仍然有效:

(gdb) 
0x080482a4 in ?? ()
1: x/i $pc
0x80482a4 <_init+48>:   pushl  0x804958c
(gdb) 
0x080482aa in ?? ()
1: x/i $pc
0x80482aa <_init+54>:   jmp    *0x8049590
(gdb) 
0xb7f052d0 in _dl_runtime_resolve () from /lib/ld-linux.so.2
1: x/i $pc
0xb7f052d0 <_dl_runtime_resolve>:       push   %eax
Run Code Online (Sandbox Code Playgroud)

一次display可以激活多个表达式(用于undisplay <number>删除它们).例如,要观察发生的事情%eax:

(gdb) display/x $eax
2: /x $eax = 0xbf90ab34
(gdb) si
0xb7f052d1 in _dl_runtime_resolve () from /lib/ld-linux.so.2
2: /x $eax = 0xbf90ab34
1: x/i $pc
0xb7f052d1 <_dl_runtime_resolve+1>:     push   %ecx
(gdb) 
0xb7f052d2 in _dl_runtime_resolve () from /lib/ld-linux.so.2
2: /x $eax = 0xbf90ab34
1: x/i $pc
0xb7f052d2 <_dl_runtime_resolve+2>:     push   %edx
(gdb) 
0xb7f052d3 in _dl_runtime_resolve () from /lib/ld-linux.so.2
2: /x $eax = 0xbf90ab34
1: x/i $pc
0xb7f052d3 <_dl_runtime_resolve+3>:     mov    0x10(%esp),%edx
(gdb) 
0xb7f052d7 in _dl_runtime_resolve () from /lib/ld-linux.so.2
2: /x $eax = 0xbf90ab34
1: x/i $pc
0xb7f052d7 <_dl_runtime_resolve+7>:     mov    0xc(%esp),%eax
Run Code Online (Sandbox Code Playgroud)

......在这里%eax可以看到变化:

(gdb) 
0xb7f052db in _dl_runtime_resolve () from /lib/ld-linux.so.2
2: /x $eax = 0xb7f0d668
1: x/i $pc
0xb7f052db <_dl_runtime_resolve+11>:    call   0xb7eff780 <_dl_fixup>
(gdb) 
Run Code Online (Sandbox Code Playgroud)