Using:
(gdb) list FUNCTION
For more information, see the list command online help:
(gdb) help list List specified function or line. With no argument, lists ten more lines after or around previous listing. "list -" lists the ten lines before a previous ten-line listing. One argument specifies a line, and ten lines are listed around that line. Two arguments with comma between specify starting and ending lines to list. Lines can be specified in these ways: LINENUM, to list around that line in current file, FILE:LINENUM, to list around that line in that file, FUNCTION, to list around beginning of that function, FILE:FUNCTION, to distinguish among like-named static functions. *ADDRESS, to list around the line containing that address. With two args if one is empty it stands for ten lines away from the other arg.
For any non-toy projects, you are likely to fall into this case:
$ gdb /bin/true <...> (gdb) start <...> (gdb) list printf file: "/usr/include/bits/stdio2.h", line number: 104 file: "printf.c", line number: 29
Which lists multiple function definitions in a code base. In the above case of printf() unloaded overhead C function has two definitions. One of them is defined in stdio2.h . Then you can use the list FILE:LINENUM to indicate which one you want to list:
(gdb) list printf.c:29 24 25 26 27 int 28 __printf (const char *format, ...) 29 { 30 va_list arg; 31 int done; 32 33 va_start (arg, format);
For the "sourcefile.c: No such file or directory" errors that you see, you need to tell GDB where to look for the source code. See GDB Handbook: Source Path . Obviously, you will need to have the source code for the function that you want to list on your computer.
source share