Reputation: 13
I need to verify that the latest changes to the header file were included in my executable that was compiled via GDB. Basically I want to run the gdb on the executable and list the source code in the header file.
I've tried gdb load_update_recs (executable) list (only lists the lines from the c program I compiled and not the header file)
I would like to list the source code of the header file in GDB
Upvotes: 0
Views: 1030
Reputation: 14432
GDB provides two functions to help you view header files: (1) list sources, and (2) edit filename:linenum. Asnoted y previous answer, gdb cannot tell if the file is current
The list sources
will show you all source files in the build (for files compiled with -g). For example, the program
#include <stdlib.h>
#include <stdio.h>
void main(void) { int x ;
fgets(NULL, 100, stdin) ;
}
Will show
gdb a.out
(gdb) info sources
Source files for which symbols have been read in:
/home/owner/a.c, /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h, /usr/include/x86_64-linux-gnu/bits/types.h, /usr/include/x86_64-linux-gnu/bits/libio.h,
/usr/include/stdio.h, /usr/include/x86_64-linux-gnu/bits/sys_errlist.h
You can request editing/viewing of any file using 'edit filename:line'. Filename can be specified without a path, if it's distinct
edit stdio.h:1
# If base name not unique, use full path:
edit /usr/include/stddef.h:1
Note that the line number is mandatory
Upvotes: 1
Reputation: 4751
The debug information doesn't include a copy of the source code, it includes a reference to the file and line number. So, if you change the header file and then list the source file, you'll see the latest source file version, even if this isn't what is actually compiled into your program. In theory GDB should warn you if it can see that the source file was modified after the executable, however, if for some reason timestamps are not working / corrupted on your source file or executable, then this warning might not appear.
With that warning out of the way, if you just list
then GDB will try to list source lines around the current location, or if you're not running, I think the first main source file (not header file) from your program.
What you can do though is supply list with a location, so list my_header.h:20
to list line 20 of my_header.h
. Though this is only going to show you the current contents of that file.
Upvotes: 3