The Vivandiere
The Vivandiere

Reputation: 3201

Navigate using function call stack in gdb

In Visual Studio, if you click on an entry in the call stack, that opens editor and shows you the source code for that function. Is something similar possible in gdb? I use tui (text user interface) in gdb. Is it possible to make tui show source code for a given entry in backtrace?

If not, then how do you make use of information in backtrace? Do you manually open the files and navigate to correct line?

Upvotes: 6

Views: 9959

Answers (2)

osgx
osgx

Reputation: 94445

When you stopped with gdb (in any mode) in breakpoint and can see backtrace with backtrace or where commands, use up and down commands to focus on different functions (frames) of backtrace.

You may use up 2 to go two frames upper. list command will show you source lines around current frame.

I think, tui will change current displayed function/registers after up/down commands; and there can be no point-and-click backtrace in tui (is there any support of mouse in tui?). Only documented windows of tui are https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html

source, assembly, and command windows.

There are keys to change current frame in TUI, but not in the normal TUI mode (https://sourceware.org/gdb/onlinedocs/gdb/TUI-Keys.html), so you can use text commands of gdb.

There is also "TUI Single Key Mode", activated by Ctrl-x s, and there are up/down commands in this mode: u/d and w to get backtrace. The mode is documented at https://sourceware.org/gdb/onlinedocs/gdb/TUI-Single-Key-Mode.html#TUI-Single-Key-Mode:

25.3 TUI Single Key Mode

 w    where
 u    up
 d    down
 r    run
 s    step
 n    next
 c    continue
 f    finish
 q    exit the SingleKey mode.
 v    info locals

Other keys temporarily switch to the gdb command prompt. The key that was pressed is inserted in the editing buffer so that it is possible to type most gdb commands without interaction with the TUI SingleKey mode. Once the command is entered the TUI SingleKey mode is restored. The only way to permanently leave this mode is by typing q or C-x s.

You may also try some debugger with GUI (gnu ddd or KDbg), or any other gdb wrapper builtin in most Linux IDEs (list, wiki list: Eclipse, Netbeans, CLion, KDevelop, Code::Blocks, CodeLite, ...). They all are more modern and convenient for debugging.

Upvotes: 12

Keith M
Keith M

Reputation: 893

To add to osgx's answer, you can also use e.g. frame 7 to go to the frame labeled #7 in the backtrace instead of just using up/down.

Upvotes: 9

Related Questions