【问题标题】:GDB can't create a breakpoint [duplicate]GDB 无法创建断点 [重复]
【发布时间】:2018-10-24 01:02:13
【问题描述】:

我正在实现一个简单的堆栈溢出,我正在使用 gdb 进行检查。我不断提出的一个问题是 gdb 不接受我的断点。我的 c 代码很简单:

void function(int a, int b, int c) {
   ...//stuff
}

void main() {
  int x;

  x = 0;
  function(1,2,3);
  x = 1;
  printf("%d\n",x);
}

我正在使用 gcc -m32 -fno-stack-protector -o example3test example3test.c 来编译它。

我尝试在 行设置一个简单的断点,只是为了测试它是否有效。

(gdb) disass main
Dump of assembler code for function main:
   0x000005d1 <+0>:     lea    0x4(%esp),%ecx
   0x000005d5 <+4>:     and    $0xfffffff0,%esp
   0x000005d8 <+7>:     pushl  -0x4(%ecx)
   0x000005db <+10>:    push   %ebp
   0x000005dc <+11>:    mov    %esp,%ebp
   0x000005de <+13>:    push   %ebx
   0x000005df <+14>:    push   %ecx
   0x000005e0 <+15>:    sub    $0x10,%esp
   0x000005e3 <+18>:    call   0x470 <__x86.get_pc_thunk.bx>
   0x000005e8 <+23>:    add    $0x1a18,%ebx
   0x000005ee <+29>:    movl   $0x0,-0xc(%ebp)
   0x000005f5 <+36>:    push   $0x3
   0x000005f7 <+38>:    push   $0x2
   0x000005f9 <+40>:    push   $0x1
   0x000005fb <+42>:    call   0x5a0 <function>
   0x00000600 <+47>:    add    $0xc,%esp
   0x00000603 <+50>:    movl   $0x1,-0xc(%ebp)
   0x0000060a <+57>:    sub    $0x8,%esp
   0x0000060d <+60>:    pushl  -0xc(%ebp)
   0x00000610 <+63>:    lea    -0x1950(%ebx),%eax
   0x00000616 <+69>:    push   %eax
   0x00000617 <+70>:    call   0x400 <printf@plt>
   0x0000061c <+75>:    add    $0x10,%esp
   0x0000061f <+78>:    nop
   0x00000620 <+79>:    lea    -0x8(%ebp),%esp
   0x00000623 <+82>:    pop    %ecx
   0x00000624 <+83>:    pop    %ebx
   0x00000625 <+84>:    pop    %ebp
   0x00000626 <+85>:    lea    -0x4(%ecx),%esp
   0x00000629 <+88>:    ret
End of assembler dump.
(gdb) break *0x000005fb
Breakpoint 1 at 0x5fb
(gdb) run
Starting program: /home/jasmine/tutorials/smashingTheStackForFun/example3test
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x5fb

我不知道为什么它不接受这个断点。此处已经给出的大多数答案都涉及不使用 * 或使用错误的符号,据我所见,我的答案看起来是正确的,但我可能是错的。

【问题讨论】:

    标签: gdb breakpoints


    【解决方案1】:

    我不知道为什么它不接受这个断点。

    你有一个位置无关的可执行文件,它在运行时被重定位到不同的地址。

    这将起作用:

    (gdb) start
    # GDB stops at main
    
    (gdb) break *&main+42
    (gdb) continue
    

    另见this answer

    【讨论】:

    • 哇,行得通,我很困惑,因为我事先已经在 gdb 中处理了这个问题,并且我使用了 break *0x.... 这会起作用,但我想不通找出它现在不起作用的原因。
    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 2012-03-22
    • 1970-01-01
    • 2016-11-26
    相关资源
    最近更新 更多