GDB 格式化结构体输出及记录到文件

来源:互联网 发布:哈工大 大数据 编辑:程序博客网 时间:2024/06/06 15:48

GDB 常用命令参考手册



set print address
set print address on
打开地址输出,当程序显示函数信息时,GDB会显出函数的参数地址。系统默认为打开的,
show print address
查看当前地址显示选项是否打开。

set print array
set print array on
打开数组显示,打开后当数组显示时,每个元素占一行,如果不打开的话,每个元素则以逗号分隔。这个选项默认是关闭的。与之相关的两个命令如下,我就不再多说了。

set print array off
show print array

set print elements
这个选项主要是设置数组的,如果你的数组太大了,那么就可以指定一个来指定数据显示的最大长度,当到达这个长度时,GDB就不再往下显示了。如果设置为0,则表示不限制。

show print elements
查看print elements的选项信息。

set print null-stop
如果打开了这个选项,那么当显示字符串时,遇到结束符则停止显示。这个选项默认为off。

set print pretty on
如果打开printf pretty这个选项,那么当GDB显示结构体时会比较漂亮。

------------------------------------------------

Controlling GDB
 
set print array on
set print array off
show print array
 以可读形式打印数组。默认是 off 。
 
set print array-indexes on
set print array-indexes off
show print array-indexes
 打印数组元素的下标。默认是 off 。
 
set print pretty on
set print pretty off
show print pretty
 格式化打印 C 结构体的输出。
 
set print union on
set print union off
show print union
 打印 C 中的联合体。默认是 on 。
 

 -----------------输出文件-----------------------------------------

1、# (gdb) set logging file <文件名>
设置输出的文件名称

2、# (gdb) set logging on
输入这个命令后,此后的调试信息将输出到指定文件

3、# (gdb) thread apply all bt
打印说有线程栈信息

4、# (gdb) set logging off
输入这个命令,关闭到指定文件的输出


将GDB的输出重定向到文件
set logging on
     Enable logging. 
set logging off
     Disable logging. 
set logging file file
     Change the name of the current logfile. The default logfile is gdb.txt. 
set logging overwrite [on|off]
     By default, gdb will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead. 
set logging redirect [on|off]
     By default, gdb output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file. 
show logging
     Show the current values of the logging settings.
https://sourceware.org/gdb/onlinedocs/gdb/Logging-Output.html

0 0
原创粉丝点击