GDB 格式化結構體輸出及記錄到文件

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章