tags:

views:

179

answers:

3

I'm using GCC 4.4.1 and GDB 7.0-ubuntu on Ubuntu 9.10. However, GCC won't generate debugger info when using any of the following switches: -g, -g3, -ggdb, or -ggdb3. So when I run the program with GDB, its as if there was no debugger information generated. I have created very simple test source files in a new, empty folder.

Here is 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 have previously turned on MALLOC_CHECK_=1 in order to test the stack overflow problem in the code. And this works so I get a stack trace. But the stack trace is no different whether I include the debug info or not. What I expected to see with the debugger information was a line number of a file for where the problem occurred under GDB. However this doesn't happen.

A: 

You want:

gcc -g test.c -o mytest
gdb mytest

Never call anything "test" - it clashes with a shell built in. and "test.o" would by convention be the name of an object file, not an executable.

anon
Good points. But that doesn't solve the problem. Is there another reason this might happen?
CJJ
@CJJ You still haven't said why you think the executable doesn't have debug information - what message are you getting that makes you think that is the case?
anon
A: 

Your comment says you ran:

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

That's probably not what you want.

gcc -ggdb -o mytest test.c

is likelier to be successful. If gdb ralphs on that then you have something wrong with your installation of gcc or gdb.

bmargulies
A: 

It works fine. I ran the debugger on my computer. I had to add

#include <string.h>

to compile it though. I called 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 see that this was tagged c and not c++. Doesn't change anything running the debugger though. Changed it accordingly.

Edit2: Reading your edit, it seems like your problem wasn't running the debugger but getting the information where your code failed. You can use backtrace to achieve that.

Lucas