jeudi 29 juillet 2021

How to get GDB to show the source code while debugging?

To make gdb make use of a single source file, you can store it in the same directory where gdb is run. How about a complete folder ?

E.g. I have a folder called "bootup" with multiple subfolders and files in it. It generates a binary called "bootup" which I need to debug for a crash and also to understand code flow.

If i just have the bootup folder (containing the source code) in the path it doesn't seem to be enough. When i set a breakpoint and debug it still only shows the file as follows but not the source code.

(gdb)directory /root/bootup
Source directories searched: /root/bootup:/root:$cdir:$cwd
(gdb) n
141     in RecFns.cpp
(gdb)
142     in RecFns.cpp

RecFns.cpp is under /root/bootup/dir1/dir2/dir3/RecFns.cpp

What should I do to be able to get gdb printing the source file contents as I debug along. As per http://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html, directory xyz should be able to make gdb search in the directory specified. But this isn't working for me.

Aucun commentaire:

Enregistrer un commentaire