I am booting a Linux kernel in Qemu using an Ubuntu machine.
I can successfully set breakpoints on certain functions, like "start_kernel".
However, when enabling the -tui option for GDB, I get a "Source Not Available" error in the top window.
I am running GDB within the Linux source code folder.
I am using the following command to invoke GDB:
gdb -tui -ex ‘file vmlinux’ -ex ‘target remote localhost:1234’
Any advice on how I can get the source code to be displayed?
2
Answers
The CONFIG_DEBUG_INFO_NONE option was set to 'y' in the Linux kernel's .config file. I changed this option to 'n' and I recompiled the kernel and was able to view source code in GDB -tui.
If you are stopped in the inferior at a location where you cannot view the source then you can try the
info source
command, here’s an example of its output:The other interesting setting is:
The
directories
setting controls where GDB looks for source files. The default value consists of$cdir
, the compilation directory, and$cwd
, the current working directory.So, in our example the source file is
hello.c
and the compilation directory is/tmp
. If our current working directory is/root
then GDB will look in the following locations, in this order:If you repeat this experiment and you think that the source files should be locatable then you can update the question with this information.
If the source files are not located in one of the paths GDB will check then you can (a) move the source to a location where GDB can find it, or (b) tell GDB where the source is.
To do (b) we use the
directory
command, like this:This has added
/blah/
to the start of the list of locations to check, so now GDB will check these locations, in this order:If you want to remove entries from the directories list then you can use
set directories
. Unlike thedirectories
command which just adds new entries to the front of the list,set directories
allows you to completely rewrite the list.The above is the most likely solution to missing source files, but GDB also has the ability to rewrite source paths if needed. The full documentation of GDB’s source path handling can be found here.