gdb 跳转某些部分的汇编代码

Fab*_*otk 4 c assembly gdb

我很难在汇编级别调试程序,因为 GDB 正在跳过代码的某些部分。代码是:

#include <stdio.h>
#define BUF_SIZE 8

void getInput(){
    char buf[BUF_SIZE];
    gets(buf);
    puts(buf);
}

int main(int argc, char* argv){
    printf("Digite alguma coisa, tamanho do buffer eh: %d\n", BUF_SIZE);

    getInput();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该程序是用gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=4 -o exploit1 exploit1.c 在 gdb中编译的,我添加了break getInput,当我运行disas getInput它时返回我:

Dump of assembler code for function getInput:
0x00000000004005cc <+0>:    push   %rbp
0x00000000004005cd <+1>:    mov    %rsp,%rbp
0x00000000004005d0 <+4>:    sub    $0x10,%rsp
0x00000000004005d4 <+8>:    lea    -0x10(%rbp),%rax
0x00000000004005d8 <+12>:   mov    %rax,%rdi
0x00000000004005db <+15>:   mov    $0x0,%eax
0x00000000004005e0 <+20>:   callq  0x4004a0 <gets@plt>
0x00000000004005e5 <+25>:   lea    -0x10(%rbp),%rax
0x00000000004005e9 <+29>:   mov    %rax,%rdi
0x00000000004005ec <+32>:   callq  0x400470 <puts@plt>
0x00000000004005f1 <+37>:   nop
0x00000000004005f2 <+38>:   leaveq 
0x00000000004005f3 <+39>:   retq  
Run Code Online (Sandbox Code Playgroud)

如果我输入,run我注意到程序停止在该行0x00000000004005d4而不是0x00000000004005cc我预期的函数的第一行。为什么会这样?

顺便说一句,这让我很困惑,因为我注意到一些额外的数据被添加到堆栈中,我想逐步看到堆栈的增长。

Emp*_*ian 5

如果我输入 run 我注意到程序停止在该行0x00000000004005d4而不是0x00000000004005cc我预期的函数的第一行。

你的期望是错误的。

为什么会这样?

因为当你通过 设置断点时break getInput,GDB 在函数 prolog 之后设置断点。从文档:

-function function
  The value specifies the name of a function. Operations on function locations
  unmodified by other options (such as -label or -line) refer to the line that
  begins the body of the function. In C, for example, this is the line with the
  open brace. 
Run Code Online (Sandbox Code Playgroud)

如果要在第一条指令上设置断点,请break *getInput改用。

文档在这里和这里。