rurouniwallace
rurouniwallace

Reputation: 2087

How do I get the variable names and line numbers to appear in GDB?

I have a program that I'm writing and I'm getting some memory errors. I run it through gdb and do a where call after the memory error occurs, and I get the following output:

#0  0xb7fdd424 in __kernel_vsyscall ()
#1  0xb7f189b1 in ?? () from /lib/i386-linux-gnu/libc.so.6
#2  0xb7e979fe in ?? () from /lib/i386-linux-gnu/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

I've had similar errors before, and the solution was to use the -ggdb compiler option. But I am using that option as you'll see in my Makefile:

shell: myshell.c
        gcc -ansi -ggdb -Wall -pedantic-errors -o myshell myshell.c

Why aren't the line numbers or variable names showing up in gdb?

Upvotes: 1

Views: 506

Answers (1)

jxh
jxh

Reputation: 70392

The reason you are not seeing line numbers or variable names is already provided by GDB itself:

Backtrace stopped: previous frame identical to this frame (corrupt stack?)

GDB believes that some error created a situation that it cannot safely recover from, and does not try to decode the backtrace stack any further. It diagnoses the possible cause of the error to be a corrupt stack.

You can proceed to debug the issue in a few ways. One way is to try using valgrind to see if it can identify the source of corruption for you. If it is not already installed on your system, an RPM package should be available, and retrieved in the usual way (probably apt-get or yum, depending on your Linux provider).

You can also try stepping through your program within the debugger until the error occurs. This will at least tell you the line of code within your program at which the error occurs. You can then repeat the experiment up to the error, and inspect the state of your program before the error actually happens.

Upvotes: 2

Related Questions