TUI(TextUser Interface)为GDB调试的文本用户界面,可以方便地显示源代码、汇编和寄存器文本窗口
Tui界面可以通过运行gdbtui或gdb-tui命令进入(其它变种gdb也一样,如arm-none-eabi-gdb-tui),当然也可以进入gdb界面后使用TUI快捷键打开,如C-xC-a快捷键
在TUI模式中,可以显示以下几个窗口:
命令窗口
用于 GDB调试时的命令输入和命令结果输出显示,与普通 GDB窗口无异。
源代码窗口
用于显示程序源代码,包括当前运行行、中断以中断标识等。
汇编窗口
显示当前程序的汇编代码。
寄存器窗口
显示处理器的寄存器内容,当寄存器内容发生改变时会高亮显示。
源代码窗口和汇编窗口会高亮显示程序运行位置并以’>’符号标记。有两个特殊标记用于标识断点,第一个标记用于标识断点类型:
B
程序至少有一次运行到了该断点
b
程序没有运行到过该断点
H
程序至少有一次运行到了该硬件断点
h
程序没有运行到过该硬件断点
第二个标记用于标识断点使能与否:
+
断点使能 Breakpointis enabled.
-
断点被禁用 Breakpointis disabled.
当调试程序时,源代码窗口、汇编窗口和寄存器窗口的内容会自动更新。
TUI运行时,命令窗口是一直可见不可隐藏的,而源代码窗口、汇编窗口和寄存器窗口则不能同时显示,只能显示一个或两个窗口,但不能只显示寄存器窗口。
C-x 2
使TUI显示两个窗口,连接使用此快捷键可在三种窗口组合(只能同时显示两个,共3种组合)中不断切换。
TUI-specific Commands
TheTUI has specific commands to control the text windows. These commandsare always available, even when GDB is not in the TUI mode. When GDBis in the standard mode, most of these commands will automaticallyswitch to the TUI mode. 当处理GDB标准模式时,下列的大多数命令会自动切换到TUI模式。
info win:显示正在显示的窗口大小信息
Listand give the size of all displayed windows.
layout next:显示下一个窗口
Displaythe next layout.
layout prev:显示上一个窗口
Displaythe previous layout.
layout src:显示源代码窗口
Displaythe source window only.
layout asm:显示汇编窗口
Displaythe assembly window only.
layout split:显示源代码和汇编窗口
Displaythe source and assembly window.
layout regs:显示寄存器窗口
Displaythe register window together with the source or assembly window.
focus next:将一个窗口置为激活状态
Make the next window active for scrolling.
focus prev:将上一个窗口置为激活状态
Make the previous window active for scrolling.
focus src:将源代码窗口置为激活状态
Make the source window active for scrolling.
focus asm:将汇编窗口置为激活状态
Make the assembly window active for scrolling.
focus regs:将寄存器窗口置为激活状态
Make the register window active for scrolling.
focus cmd:将命令行窗口置为激活状态
Make the command window active for scrolling.
refresh:更新窗口,与 C-L快捷键同
Refresh the screen. This is similar to typing C-L.
tuireg float:寄存器窗口显示内容为浮点寄存器
Showthe floating point registers in the register window.
tuireg general:寄存器窗口显示内容为普通寄存器
Show the general registers in the register window.
tuireg next:显示下一组寄存器
Show the next register group. The list of register groups as well astheir order is target specific. The predefined register groups are the following:
general, float,system, vector,all, save,restore.
tuireg system :显示上一组寄存器
Show the system registers in the register window.
update :更新源代码窗口到当前运行点
Update the source window and the current execution point.
winheight winname +count:增加指定窗口的高度 winheight winname -count:减小指定窗口的高度
Changethe height of the window name by count lines.Positive counts increase the height, while negative counts decreaseit.
tabset nchars
Set the width of tab stops to be nchars characters.
https://blog.csdn.net/xu415/article/details/19021759/
https://www.cnblogs.com/wuchanming/p/4494141.html
https://blog.csdn.net/qq_41071068/article/details/103007550
http://sourceware.org/gdb/onlinedocs/gdb/TUI.html
https://www.cnblogs.com/csstudy/p/4498367.html
https://stackoverflow.com/questions/61675698/lldb-how-to-use-the-tui
http://peeterjoot.com/2019/08/26/the-lldb-tui-text-user-interface/
(llvm) gui
https://stackoverflow.com/questions/19820247/is-there-a-tui-mode-for-standalone-lldb
https://stackoverflow.com/questions/6612133/no-tui-support-for-gdb-on-mac
GDB can be built without tui, and this may be the case. Compile gdb for yourself, and enable TUI in configure.
Or, compile a cgdb, which is very like TUI.
How to install cgdb http://lists.apple.com/archives/Xcode-users/2009/Jul/msg00194.html Also this letter says:
https://stackoverflow.com/questions/38803783/how-to-automatically-refresh-gdb-in-tui-mode
https://www.codenong.com/19820247/
https://www.coder.work/article/6219230
set disassemble-next-line command
Controls whether GDB should show the disassembly of the next line each time it stops at a breakpoint or after a step.
set disassemble-next-line on
set disassemble-next-line off
show disassemble-next-line
https://visualgdb.com/gdbreference/commands/set_disassemble-next-line
x command
Displays the memory contents at a given address using the specified format.
Syntax
x [Address expression]
x /[Format] [Address expression]
x /[Length][Format] [Address expression]
x
https://visualgdb.com/gdbreference/commands/x
可以使用examine命令(简写是x)来查看内存地址中的值。x命令的语法如下所示:
x/<n/f/u>
n、f、u是可选的参数。
n是一个正整数,表示需要显示的内存单元的个数,也就是说从当前地址向后显示几个内存单元的内容,一个内存单元的大小由后面的u定义。
f 表示显示的格式,参见下面。如果地址所指的是字符串,那么格式可以是s,如果地十是指令地址,那么格式可以是i。
u 表示从当前地址往后请求的字节数,如果不指定的话,GDB默认是4个bytes。u参数可以用下面的字符来代替,b表示单字节,h表示双字节,w表示四字 节,g表示八字节。当我们指定了字节长度后,GDB会从指内存定的内存地址开始,读写指定字节,并把其当作一个值取出来。