skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. 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:

    (gdb) info source
    Current source file is hello.c
    Compilation directory is /tmp
    Source language is c.
    Producer is GNU C17 9.3.1 20200408 (Red Hat 9.3.1-2) -mtune=generic -march=x86-64 -g3 -O0.
    Compiled with DWARF 4 debugging format.
    Includes preprocessor macro info.
    (gdb) 
    

    The other interesting setting is:

    (gdb) show directories 
    Source directories searched: $cdir:$cwd
    

    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:

    • /tmp/hello.c
    • /root/hello.c

    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:

    (gdb) directory /blah
    Source directories searched: /blah:$cdir:$cwd
    

    This has added /blah/ to the start of the list of locations to check, so now GDB will check these locations, in this order:

    • /blah/hello.c
    • /tmp/hello.c
    • /root/hello.c

    If you want to remove entries from the directories list then you can use set directories. Unlike the directories 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search