理解汇编和堆栈 %ebp above vs below

understanding assembly and stack %ebp above vs below

如果我的汇编代码...

   0x08048cc4 <+0>:     push   %ebp
   0x08048cc5 <+1>:     mov    %esp,%ebp
   0x08048cc7 <+3>:     push   %esi
   0x08048cc8 <+4>:     push   %ebx
   0x08048cc9 <+5>:     sub    [=10=]x20,%esp
   0x08048ccc <+8>:     lea    -0x10(%ebp),%eax    // input 3
   0x08048ccf <+11>:    mov    %eax,0xc(%esp)
   0x08048cd3 <+15>:    lea    -0xc(%ebp),%eax     // input 2
   0x08048cd6 <+18>:    mov    %eax,0x8(%esp)
   0x08048cda <+22>:    movl   [=10=]x804a1aa,0x4(%esp)
   0x08048ce2 <+30>:    mov    0x8(%ebp),%eax      // input 1
   0x08048ce5 <+33>:    mov    %eax,(%esp)
   0x08048ce8 <+36>:    call   0x804870c <__isoc99_sscanf@plt>

如果我在 <+36> 设置断点,有没有办法打印输入 1,2,3 的值?

我知道我可以在 <+8> 处保持中断并每次执行一些 (gdb) i r 以获得 %eax。但是有没有更好的方法可以在 <+36>

的一个断点处执行此操作

我的输入是14、115(输入2、输入3) 输入 1 是格式 ("%d, %d")

我试过做类似的事情,但不太明白我在读什么..

(gdb) x /20wx $esp
0xbffff070: 0x0804b820  0x0804a1aa  0xbffff08c  0xbffff088
0xbffff080: 0x00000001  0x7a000002  0x00000073  0x0000000e
0xbffff090: 0xbffff168  0xbffff164  0xbffff0c8  0x08048a4d
0xbffff0a0: 0x0804b820  0x08049f2c  0x00000000  0xb7e5164d
0xbffff0b0: 0xb7fc93c4  0xb7fff000  0xb7fc9000  0x00000000

(gdb) x /20wx $ebp
0xbffff098: 0xbffff0c8  0x08048a4d  0x0804b820  0x08049f2c
0xbffff0a8: 0x00000000  0xb7e5164d  0xb7fc93c4  0xb7fff000
0xbffff0b8: 0xb7fc9000  0x00000000  0x08049e60  0x00000000
0xbffff0c8: 0x00000000  0xb7e37a83  0x00000002  0xbffff164
0xbffff0d8: 0xbffff170  0xb7feccea  0x00000002  0xbffff164

(gdb) x /20wd $ebp
0xbffff098: -1073745720 134515277   134527008   134520620
0xbffff0a8: 0   -1209723315 -1208183868 -1207963648
0xbffff0b8: -1208184832 0   134520416   0
0xbffff0c8: 0   -1209828733 2   -1073745564
0xbffff0d8: -1073745552 -1208038166 2   -1073745564

在 +36 sscanf 尚未被调用,因此您只会看到调用 input2/3.

的两个输出变量的随机内存垃圾

Input1不是格式,是要解析的字符串

那个电话看起来像:sscanf(input1, "%d %d", &input2, &input3)

您当然可以检查变量,对 input1 使用 x/s $eax,对 input2/3 使用 x/d:

(gdb) x/s $eax
0xffffdba6:     "14 115"
(gdb) ni
(gdb) x/d $ebp-0xc
0xffffd97c:     14
(gdb) x/d $ebp-0x10
0xffffd978:     115

(注意我在 sscanf 之前打印了 input1,但其他的在之后。) 请参阅格式说明符的 gdb 帮助。