条件断点
- b 函数名称 if a==5 //整数类型
- b 函数名称 if 0==strcmp(a,”abcdefg”) //字符串类型比较
- https://paper.seebug.org/papers/scz/unix/201806221643.txt
1 2 3 4 5 6 7 |
// 或者 $_memeq(buf1, buf2, length)` $_streq(str1, str2) $_strlen(str) $_regex(str, regex) break <where> if $_streq(x, "hello") // 亲测好用 |
反向执行代码(后退代码)
rs rn命令(多线程不支持?):
– https://www.ibm.com/developerworks/cn/linux/l-cn-gdb7rd/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
root@ceph-l ~ $ gdb a.out GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1 (gdb) b main Breakpoint 1 at 0x40088e: file test.c, line 6. (gdb) run Starting program: /root/a.out Breakpoint 1, main () at test.c:6 6 const char *s = "abc123def"; (gdb) record (gdb) n 7 const char *ss = "hig"; (gdb) 8 const char *s1 = strstr(s, ss); (gdb) 9 if (s1) { (gdb) 12 cout < < "NULL" << endl; (gdb) rn 9 if (s1) { (gdb) rn 8 const char *s1 = strstr(s, ss); (gdb) rn 7 const char *ss = "hig"; (gdb) q |
在断点处自动执行命令
command命令
- https://codeday.me/bug/20171029/90042.html
例如自动打印指定变量
1 2 3 4 5 6 7 8 9 |
(gdb) commands 1 Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >silent >print "name: %s", h->name >shell sleep 1 >cont >end |
gdb执行脚本
source 脚本名
gdb调用函数
call命令
展开宏
macro expend
- https://www.cnblogs.com/idorax/p/6423222.html
调试父、子进程
set follow-fork-mode [parent|child]