It's called the TUI (no kidding). Start for example with gdbtui or gdb -tui ...
Please also see this answer by Ciro Santilli. It wasn't available in 2012 to the best of my knowledge, but definitely worth a look.
Answer from 0xC0000022L on Stack OverflowIt's called the TUI (no kidding). Start for example with gdbtui or gdb -tui ...
Please also see this answer by Ciro Santilli. It wasn't available in 2012 to the best of my knowledge, but definitely worth a look.
You can trigger it dynamically by push ctrl+x and ctrl+a.
Videos
You can enter or leave the TUI mode with code window using Ctrl+x A key binding. Or use layout src command to enter TUI mode. See other TUI key bindings and commands.
Start gdb using
gdb -tui. tui stands for Text User Interface.Or, use 'ddd' -- a graphical front end for gdb.
You can use the list command to show sources. list takes a "linespec", which is gdb terminology for the kinds of arguments accepted by break. So, you can either pass it whatever argument you used to make the breakpoint in the first place (e.g., list function) or you can pass it the file and line shown by info b (e.g., list mysource.c:75).
* The correct answer is below *
This is a 10 year old Q&A so it's not likely this will become the correct answer, but it should. The other responses suggest work-arounds, not a direct solution.
There is a way as follows, (at least in GDB 13.1+) from reading the following carefully:
help info break
First, display the breakpoint in question:
info break <breakpoint-number>
List the address of expression $_ (last displayed breakpoint):
list *$_
In short:
i b <bp-number>
l *$_
Combining this into a User Command, put the following in your ~/.gdbinit, restart gdb, and then you can run the command listbr 2 to see the listing of breakpoint #2.
define listbr
info br $arg0
list *$_
end
document listbr
listbr <n> list code at breakpoint <n>
end
Use:
(gdb) list FUNCTION
See the online help of the list command for details:
(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'll probably hit a case like this:
$ 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 the multiple definitions of a function in a code base. In the printf() case above, the non-overloaded pure C function has two definitions. One defined in stdio2.h. You can then use the list FILE:LINENUM form to specify which one you want to list:
(gdb) list printf.c:29
24
25 /* Write formatted output to stdout from the format string FORMAT. */
26 /* VARARGS1 */
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 you're seeing, you need to tell GDB where to look for the source code. See GDB Manual: Source Path. Obviously you'll need to actually have the source code for the function you want to list on your machine.
For gcc:
Add a debugging option flag -g with the compilation of your source:
gcc -g test.c
To test, use:
gdb ./a.out
(gdb) list
For even more functionality, check out the man pages:
man gcc
man gdb
Hello reddit, I am trying to git into the world of assembly language but I am in a bit of a pickle regarding gdb
I am compiling assembly code that has calls to C functions on it. I am using nasm and gcc to compile the entirety of my code. However, when I try to debug it using GDB I can't see my source code (I get Source not available).
I have installed:
- gcc :(GCC) 12.2.0
- ld :GNU ld (GNU Binutils) 2.39.0
- NASM version 2.15.05
And I run:
nasm -f elf64 -o hello.o hello.asm
gcc -g hello.o -o hello -no-pie
gdb ./hello
I would like to see my assembly code and go step by step, just like one would with C code.
What am I missing? No matter what I do I keep getting the no source error