Navigate using function call stack in gdb

此生再无相见时 提交于 2019-12-12 12:03:47

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/38448284/navigate-using-function-call-stack-in-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!