Gdb跳过汇编代码的某些部分 [英] Gdb jumping some parts of the assembly codes

查看:221
本文介绍了Gdb跳过汇编代码的某些部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having a difficult to debug a program at assembly level because GDB is jumping some parts of the code. The code is:

#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;
}

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

The program was compiled with gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=4 -o exploit1 exploit1.c In gdb, I added break getInput and when I run disas getInput it returns me:

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,我会注意到程序停止在0x00000000004005d4行,而不是我期望的在函数0x00000000004005cc的第一行.为什么会这样?

If I type run I noticed that the program stops at the line 0x00000000004005d4 and not in the first line of the function 0x00000000004005cc as I expected. Why is this happening?

顺便说一句,这让我感到困惑,因为我注意到某些额外的数据正在添加到堆栈中,并且我希望逐步查看堆栈的增长情况.

By the way, this is messing me up because I'm noticing that some extra data is being added to the Stack and I want to see step by step the stack growing.

推荐答案

如果我输入run,我会注意到程序停止在行0x00000000004005d4而不是函数0x00000000004005cc的第一行.

If I type run I noticed that the program stops at the line 0x00000000004005d4 and not in the first line of the function 0x00000000004005cc as I expected.

您的期望不正确.

为什么会这样?

Why is this happening?

因为通过break getInput设置断点,GDB会在函数prolog之后设置断点.来自文档:

Because when you set breakpoint via break getInput, GDB sets the breakpoint after function prolog. From documentation:

-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. 

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

If you want to set breakpoint on the first instruction, use break *getInput instead.

文档此处 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆