Gcc does not generate debugger information when using -g, -ggdb, -g3, or -ggdb3

I am using GCC 4.4.1 and GDB 7.0-ubuntu on Ubuntu 9.10. However, GCC will not generate debugger information when using any of the following switches: -g, -g3, -ggdb, or -ggdb3. So when I run the program with GDB, it doesn't seem to generate debug information. I created very simple test source files in a new empty folder.

Here's one example:

#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
     char    msg[4];
     // allocate 4 bytes on the stack
     strcpy (msg, "hello world");
     // overflow 
     printf ("%s\n", msg);
     return 0;
}

      

UPDATE: here is my command line sequence:
gcc -g./mytest.c -o mytest
gdb./mytest

UPDATE: I previously enabled MALLOC_CHECK_ = 1 to check the problem in code. And it works, which is why I get the stack trace. But the stack trace is no different from whether debug information is enabled or not. What I was expecting to see with the debugger info was the line number of the file where the problem occurred in GDB. However, this does not happen.

+2


a source to share


3 answers


It works great. I launched the debugger on my computer. I had to add

#include <string.h>

      

to compile it. I named the file debugger.c

. Here are the steps:

gcc -g debugger.c 
gdb a.out

      



which will start the debugger

GNU gdb 6.3.50-20050815
... 
...
(gdb) run
Starting program: /Developer/stackoverflow/extern/a.out 
Reading symbols for shared libraries +. done

Program received signal SIGABRT, Aborted.
0x00007fff88040886 in __kill ()
(gdb) backtrace
#0  0x00007fff88040886 in __kill ()
#1  0x00007fff880e0e4f in __abort ()
#2  0x00007fff880d5693 in __chk_fail ()
#3  0x00007fff8802f851 in __strcpy_chk ()
#4  0x0000000100000f04 in main (argc=1, argv=0x7fff5fbff958) at debugger.c:9
(gdb) 

      

Edit: Sorry, didn't notice that this was marked c, not C ++. However, it doesn't change anything when the debugger is running. Changed it accordingly.

Edit2: After reading your edit, it looks like your problem was not triggered by the debugger, but information was received where your code was crashing. You can use backtrace

to achieve this.

+1


a source


Do you want to:

gcc -g test.c -o mytest
gdb mytest

      



Never call anything "test" - it collides with the inline shell. "test.o" by convention will be the name of the object file, not the executable.

0


a source


Your comment says you were running:

gcc -ggdb ./test.c -o test.o

      

This may not be what you want.

gcc -ggdb -o mytest test.c

      

is more successful. If gdb ralphs is on this then you have something wrong with your gcc or gdb installation.

0


a source







All Articles