使用 -g 选项编译,但"Single stepping until exit from function main, which has no line number information"



我在gdb方面遇到了一些问题。这是我在一个名为main.cpp 的文件中的代码

#include <iostream>
void myfunc();
int main(){
    char msg[] = "Hello World!";
    myfunc();
    std::cout << msg << std::endl;
    return 0;
}
void myfunc(){
    int boo = 16;
}

我用这个命令编译了这个代码:

g++ -g -Wall main.cpp -o foo

接下来,我使用gdb:

$ gdb foo
(gdb) start
Temporary breakpoint 1 at 0x80487c3
Starting program: /home/laptop/workspace/foo 
Temporary breakpoint 1, 0x080487c3 in main ()
(gdb) s
Single stepping until exit from function main,
which has no line number information.
Hello World!
__libc_start_main (main=0x80487c0 <main>, argc=1, ubp_av=0xbffff3a4, init=0x80488b0 <__libc_csu_init>, fini=0x8048920 <__libc_csu_fini>, rtld_fini=0xb7fed280 <_dl_fini>, stack_end=0xbffff39c) at libc-start.c:258
258 libc-start.c: No such file or directory.

我做错了什么?我使用了-g选项,但仍然出现了这个错误。

配置:

  • GDB:GNU GDB(Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04
  • GCC:g++(Ubuntu 4.8.1-2ubuntu1~12.04)4.8.1

我安装了这些工具与一个经典:sudo apt-get-install

提前感谢您的任何回答:-)

感谢您的回答。我发现了问题所在。正如jcm所说,我的gcc相对较新。我已经将gdb更新到最新版本,即GNU gdb(gdb)7.6。现在这很好用。

顺便说一句,对于g++版本(Ubuntu/Linaro 4.6.4-1ubuntu1~12.04)4.6.4,gdb(Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04运行得很好。

谢谢大家。

使用-g-ggdb标志编译。

你的命令应该是

g++ -g -ggdb -Wall main.cpp -o foo

也尝试使用'-Og'。也许这会有所帮助,因为正如@KevinDTimm所写:编译器可能会优化它

参考:

  • "c++--help=优化器"

最新更新