Gdb doesn't show row source

GDB does not show me the source of the line after next / stop and only displays the line number and source file, for example:

(gdb) n 7 in test/test.c 

whereas I expect it to display the current line, for example:

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

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

+4
source share
2 answers

whereas I expect it to display the current line, for example

On many platforms, such as ELF , the compiler writes both the path to the source ( test/test.c in your case) and the compilation directory, allowing GDB to map the source no matter what directory it calls it to.

But many platforms are less flexible and do not have a place to write the compilation directory. On such platforms (for example, AIX), you must either run GDB in the compilation directory, or specify where to look for sources using the directory command.

+2
source

Perhaps my answer may not be the perfect solution, but the way you compile the source program. For example, in my case, if you run g++ fib.cpp -o fib , and then try running gdb fib , it will not print the source code using list . Using the debug flag g++ -g fib.cpp -o fib and then starting with gdb solved my problem.

+1
source

Source: https://habr.com/ru/post/1432534/


All Articles