KernelMonk
KernelMonk

Reputation: 341

gdb not showing the line source

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 ?

Upvotes: 10

Views: 12333

Answers (2)

owsmmj
owsmmj

Reputation: 178

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.

Upvotes: 2

Employed Russian
Employed Russian

Reputation: 213799

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.

Upvotes: 6

Related Questions