【问题标题】:gdb cannot step into printfgdb 无法进入 printf
【发布时间】:2011-04-01 11:46:09
【问题描述】:

这是我的示例程序:

#include<stdio.h>

int main()
{

printf("hello good morning \n");
return 0;
}


gcc -Wall -g temp.c


/opt/langtools/bin/gdb a.out
HP gdb 3.3 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 3.3 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.
..
(gdb) b 6
Breakpoint 1 at 0x2b14: file temp.c, line 6.
(gdb) run
Starting program: /oo_dgfqausr/test/dfqwrk4/temp/a.out

Breakpoint 1, main () at temp.c:6
6       printf("hello good morning \n");
(gdb) step
hello good morning
7       return 0;
(gdb)

只要我尝试进入 printf 函数,它就会退出并返回到 main。 这是否意味着定义 printf 函数的 shred 库没有提供调试符号?还是我做错了什么?

【问题讨论】:

    标签: c++ c gdb


    【解决方案1】:

    这意味着 printf 没有可用的源代码/调试符号。无论如何,您都可以使用stepi 进入printf,您只能进行反汇编(使用disas 命令)。

    【讨论】:

    • 出于好奇,存在源而不是调试符号是否意味着您可以进入函数?
    • @Ricko M:不,您需要调试符号才能单步执行,并且需要在单步执行时让 gdb 显示源代码行。
    【解决方案2】:

    没错,您可能没有可用的调试符号。确保已安装 libc-devel 或类似软件。另外,请确保使用-O0 进行编译以防止优化;优化使调试更难遵循。

    【讨论】:

      【解决方案3】:

      另外,-g3 是最大符号所必需的。使用-g3,甚至可以使用符号常量。 -ggdb 也可能有帮助。来自 GDB 的 Jan 告诉我们没有主线 GDB 扩展,但 Apple 可能提供了一些并省略了 backstrem 补丁。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-23
        • 2012-12-05
        • 2015-06-13
        • 2011-02-07
        • 2012-03-22
        • 2011-11-09
        • 1970-01-01
        相关资源
        最近更新 更多