Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb not showing the line source

Tags:

gdb

GDB is not showing me the line source after next/stop , and displays only line number and source file , like this :

(gdb) n
7   in test/test.c

whereas I expect it to display the current line , like this :

(gdb) next
17        char * good_message = "Hello, world.";

any settings in .gdbinit that might help me do this ?

like image 589
KernelMonk Avatar asked Sep 05 '12 17:09

KernelMonk


2 Answers

whereas I expect it to display the current line , like this

On many platforms, such as ELF, the compiler records both the path to the source (test/test.c in your case), and the compilation directory, allowing GDB to display source regardless of which directory you invoke it in.

But many platforms are less flexible, and don't have a place to record compilation directory. On such platforms (e.g. AIX), you must either start GDB in the compilation directory, or tell it where to look for sources with directory command.

like image 94
Employed Russian Avatar answered Oct 11 '22 12:10

Employed Russian


Probably my answer may not be a perfect solution but the way you compile your source program matters. For example in my case if you do g++ fib.cpp -o fib and then try to run gdb fib it won't print the source code with list. Using debug flag g++ -g fib.cpp -o fib and then running with gdb solved my problem.

like image 43
owsmmj Avatar answered Oct 11 '22 12:10

owsmmj