I was trying to use GDB to troubleshoot a segfault in code I'm writing. GDB does not show line numbers or function names when I use the backtrace
command. Here's a short sample program that illustrates my problem:
void segfault(int *b) { // This causes a segfault on CentOS7 Intel 64-bit b[-1] = 5;}void main() { int a[10]; segfault(a);}
However when I compile with
gcc -ggdb -O0 test.c -o segfaulttest
And use gdb segfaulttest
to run it, when I use gdb's backtrace command I don't get any line numbers or function names. I would expect it to list main()
and segfault()
in the trace.
Sample output
Reading symbols from /home/user/test/segfaulttest...done.(gdb) runStarting program: /home/user/test/segfaulttest Program received signal SIGSEGV, Segmentation fault.0x000000050040051c in ?? ()(gdb) bt#0 0x000000050040051c in ?? ()#1 0x0000000000000000 in ?? ()(gdb)
I'm using:
- CentOS 7 (64 bit)
- GCC:
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
- GDB is
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
(Aside: I fixed the actual bug in my code, I just don't understand why gdb backtrace doesn't show me more information).