Compile with the -g option, but "Single stepping before exiting the main function, which has no line number information"

I have problems with gdb. This is my code in a single file called 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; } 

I used this command to compile this code:

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

Next, I used 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. 

What did I do wrong? I use the -g option, but I still have this error.

Configuration:

  • 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

I installed these tools using the classics: sudo apt-get install

Thanks in advance for any answer :-)

+4
c ++ debugging ubuntu gdb
Dec 09 '13 at 15:45
source share
3 answers

Thank you for your responses. I found that not so. As jcm says my gcc is relatively new. I have an update of gdb to the latest current version, which is GNU gdb (GDB) 7.6. Now it works fine.

By the way, with version 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 works fine.

Thank you all.

+6
Dec 10 '13 at 11:54
source share

Compile using the -g and -ggdb .

Your team should be

 g++ -g -ggdb -Wall main.cpp -o foo 
0
Apr 04 '16 at 10:50
source share

Try using '-og' too. Maybe this will help, because, as @KevinDTimm wrote, the compiler can optimize it.

Link:

  • "C ++ --help = optimizers"
-one
Dec 09 '13 at 18:48
source share



All Articles