【问题标题】:Why does gdb not break on strcpy? [duplicate]为什么 gdb 不会在 strcpy 上中断? [复制]
【发布时间】:2016-05-19 05:28:56
【问题描述】:

请看下面的命令行。我设置了两个断点:一个在 strcpy 上,另一个在 printf 上。为什么跳过断点 1?

root@ninja:~/Desktop/Programs# gcc -g -o exp exp.c
root@ninja:~/Desktop/Programs# gdb -q exp
Reading symbols from /root/Desktop/Programs/exp...done.
(gdb) list
1   #include <stdio.h>
2   #include <string.h>
3   
4   int main()  {
5       char str_a[20];
6       
7       strcpy(str_a, "Hello world!\n");
8       printf(str_a);
9   }
(gdb) break strcpy
Function "strcpy" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (strcpy) pending.
(gdb) break printf
Breakpoint 2 at 0x8048300
(gdb) run
Starting program: /root/Desktop/Programs/exp 

Breakpoint 2, 0xb7eabf54 in printf () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
(gdb) i r eip
eip            0xb7eabf54   0xb7eabf54 <printf+4>
(gdb) cont
Continuing.
Hello world!
[Inferior 1 (process 3726) exited with code 015]

【问题讨论】:

  • 它可能会被优化并简化为内联代码而不是函数调用。尝试不优化编译。
  • @Rohan 我使用了gcc -g -O0 -o exp exp.c,但它不起作用。
  • @W.Zhu 检查汇编代码。你会发现即使使用-O0 也没有调用strcpy
  • @kaylum 我检查并发现没有调用 strcpy。它被简化为内联代码。现在我明白了。谢谢。
  • 尝试添加-fno-builtin 编译器选项。

标签: c gdb breakpoints


【解决方案1】:

第一个断点处于挂起状态。

(gdb) break strcpy
Function "strcpy" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (strcpy) pending.                                                 <<here

试试:(gdb) break 7

7 是行号。

【讨论】:

    猜你喜欢
    • 2014-06-12
    • 2021-11-06
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2012-06-04
    • 2012-04-12
    相关资源
    最近更新 更多