You may specify arguments to give it. Args may include "*", or "[…]"; they are expanded using the shell that will start the program (specified by the "$SHELL" environment variable). Input and output redirection with ">", "<", or ">>" are also allowed. With no arguments, uses arguments last specified (with "run" or "set args"). To cancel previous arguments and run with no arguments, use "set args" without arguments. To start the inferior without using a shell, use "set startup-with-shell off".
break / b
b fuction
設立中斷點在函數「function」
b N
設立中斷點在當前執行來源檔的第N行
b file.c:N
設立中斷點在file.c檔案中的第N行
b ClassName::funcName
設立中斷點在「ClassName::funcName」
b +line-offset
設立中斷點到目前執行到行數加上位移量的行數 e.g. b +3 //current line no = 26. then set b 29
The argument is the function name and arguments, in the notation of the current working language. The result is printed and saved in the value history, if it is not void.
重複數量(repeat count):根據格式(由後兩者組成的),印出指定大小的指定數量的物件,如果數量是負的,檢查記憶體是從address向後(變小)的方式去做(e.g., x /-1db 0xff4 會輸出記憶體位置 0xff3:十進位的值。)
格式字母(format letters):
d:十進位
o:八進位
f:浮點數
u:無符號
x:十六進位
t:二進位
i:指令
s:字串
c:字元
z:十六進位,在左側填充0
長度字母(size letter):
b(byte):單位元組
h(halfword):雙位元組
w(word):四位元組
g(giant):八位元組
set
set var=val
設定變數「var」給予「val」的值
set args
設定命令列的參數
set print pretty
增加輸出的可讀性
unset [3]
unset
取消特定參數。如:unset env,刪除環境變數
show [3]
show
顯示特定參數。如:show environment,顯示環境變數
attach [3]
attach PID
載入已執行中的程式以進行除錯。其中的 PID 可由 ps 指令取得
detach [3]
detach PID
釋放已 attach 的程式
list / l
l
印出程式碼,執行到的該行程式碼上面五行和下面四行,包含執行中的該行程式碼共十行程式碼。
透過行數range,以comma分隔印出特定段落程式碼。 e.g., l 5,10
shell [3]
shell
執行 Shell 指令。如:shell ls,呼叫 sh 以執行 ls 指令
whatis
whatis var/function name
印出var/function name型態
where [4]
where
顯示目前副程式層層呼叫的狀況
until
until line-no
可用來直接跑完一個迴圈
Execute until past the current line or past a LOCATION. Execute until the program reaches a source line greater than the current or a specified location (same args as break command) within the current frame.
先找出行程的 pid: To see every process on the system using standard syntax
ps -ef | grep <行程名>
將 child process 連上目前的行程
gdb -p <pid>
gdb attach <pid>
顯示目前設定
show follow-fork-mode
切換到 child
set follow-fork-mode child
non-GDB commands
非GDB指令,但是與除錯「完」相關
strip [3]
strip file(binary file)
從可執行的二進位程式和目的檔,移除不必要資訊,像是the line number information, relocation information, the debug section, the typchk section, the comment section, file headers, and all or part of the symbol table from the XCOFF object files –> 簡單來說,就是使執行檔size變小