刚刚接触,慢慢学吧!
1:如何开始调试程序
netstat -anp|grep 1466(回车)1466是我运行程序所监听的端口,程序会运行多个线程,但不管哪个线程,监听端口就行。
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:1466 0.0.0.0:* LISTEN 10701/XXX (此处显示程序ID:10701)
gdb ./bin/XXX -d=src/ (回车) 此处关联源代码
(gdb)attach 10701 (回车)这就可以了。
2:设置断点:
(gdb)b cxxx.cpp:行号
(gdb)b bxxx.cpp:行号
(gdb)b axxx.cpp:行号
(gdb)info b 显示断点
Num Type Disp Enb Address What
1 breakpoint keep y 0x00007f0a0fe07e30 in
2 breakpoint keep y 0x00007f0a0efcfba4 in
3 breakpoint keep y 0x00007f0a11e6e424 in
(gdb)dis 3 使断点3无效,但不删除
(gdb)info b 显示断点
Num Type Disp Enb Address What
1 breakpoint keep y 0x00007f0a0fe07e30 in
2 breakpoint keep y 0x00007f0a0efcfba4 in
3 breakpoint keep n 0x00007f0a11e6e424 in
(gdb)d 3 (delete 的意思)删除断点3
(gdb)info b 显示断点
Num Type Disp Enb Address What
1 breakpoint keep y 0x00007f0a0fe07e30 in
2 breakpoint keep y 0x00007f0a0efcfba4 in
clear
用法:clear
删除所在行的多有断点。
clear location
clear 删除所选定的环境中所有的断点
clear location location描述具体的断点。
例如:
clear list_insert //删除函数的所有断点
clear list.c:list_delet //删除文件:函数的所有断点
clear 12 //删除行号的所有断点
clear list.c:12 //删除文件:行号的所有断点
clear 删除断点是基于行的,不是把所有的断点都删除。