GDB調試程序常用命令

記得用gcc 加-g 參數編譯措施,以便天生的措施中帶有調試信息。

1。gdb載入措施
gdb a.out

2。運行措施
run 加措施必要的參數

3。設置源代碼目次
gdb directory /代碼目次

4。查察函數名字用 info
gdb info functions
類似的有
gdb info files
查察函數地點的源代碼行數
gdb info line 函數名字

5。下斷點
(gdb) br net.c:911 在源代碼的 net.c 文件911行下斷點
Breakpoint 2 at 0x4163fc: file net.c, line 911.

在改函數崎嶇斷點
br 函數名字

6。 查察寄放器 內容
info regiseter 查察寄放器 簡寫 i reg

7.查察堆棧
bt

8.查察變量的值 用 print 加表達式
(gdb) print (struct intfconfig_s *) 0x7fff2d15f878
$21 = (struct intfconfig_s *) 0x7fff2d15f878

9。查察範例 用ptype
(gdb) ptype struct intfconfig_s
type = struct intfconfig_s {
newtComponent ipv4Entry;
newtComponent cidr4Entry;
newtComponent ipv6Entry;
newtComponent cidr6Entry;
newtComponent gwEntry;
newtComponent nsEntry;
const char *ipv4;
const char *cidr4;
const char *ipv6;
const char *cidr6;
const char *gw;
const char *ns;
}
10。 查察結構的子成員
(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->ipv6
$25 = 0x1bf63740 " \025- \177"

(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->ipv4
$26 = 0x0
(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->ipv6Entry
$27 = (newtComponent) 0x1bf916e0

(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->ipv4Entry
$28 = (newtComponent) 0x7fff2d15fb90

(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->cidr6
$29 = 0x30687465 <Address 0x30687465 out of bounds>

(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->cidr4
$30 = 0x1bf91580 " \027 \033"
(gdb) print ((struct intfconfig_s *) 0x7fff2d15f878)->gw
$31 = 0x1bf92410 "\004"

11 推行下一句
next
nexti

12。運行時批改數據
set


13。 更多內容 輸入 help 看贊助,呵呵。根本上上面這些就已經夠用了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章