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 看赞助,呵呵。根本上上面这些就已经够用了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章