break命令创建,程序执行到指定行停止;
2.观察断点
watch命令创建,观察变量或表达式的值,一旦观测对象发生变化,程序停止执行;
info watchpoints // 查看设定的观察断点 watch num // 监控的num发生改变,就停止执行。读取num不会停止执行 rwatch num // 程序中出现读取num,就停止执行 awatch num // 程序中读取或改变num,就停止执行
catch命令创建,监控某一事件发生,停止运行程序
catch event // event 参数表示要监控的具体事件 catch throw [exception] // 抛出异常,如 catch throw int catch [exception] // 捕获异常,如 catch int catch load [regexp] // 加载动态库, 如 catch load libstdc++.so.6 catch unload [regexp] // 卸载动态库, 如 catch unload libstdc++.so.6 tcatch // 和catch作用相同,catch永久监控,tcatch紧监控一次
/* 设置断点 */ (gdb) b 1 Breakpoint 1 at 0x1189: file main.c, line 2. (gdb) watch num Hardware watchpoint 2: num (gdb) catch throw int Catchpoint 3 (throw)
/* 查看断点 */ info breakpoint [n] // 查看普通断点 info watchpoint [n] // 查看观察断点 info break [n] i b [n] // 查看第n个断点
/* 删除断点 */ clear location // 参数 location通常为某一行代码的行号或者某个具体的函数名 delete [num] // 参数 num 为指定断点的编号, 不写num会删除所有断点
/* 禁用断点 */ disable [num...] // 参数 num... 表示断点的编号,可以是多个 enable [num...] // 重新激活断点 enable once num... // 临时激活1次 enable count num... // 激活count次 enable delete num... // 激活1次断点,使用后删除
设置条件,满足条件后才触发
condition bnum expression // 给编号bnum的断点增加或修改表达式expression condition bunm // 删除编号bnum的表达式 ignore bnum count // 如 ignore 1 3 count指设置断点忽略的次数
// 编号1 为普通断点, 编号2 为观察断点, 编号3 为捕获断点 condition 1 num==3 // 普通断点添加条件表达式 condition 2 num==4 // 观察断点添加条件表达式 condition 3 num==5 // 捕捉断点添加条件表达式
参考:http://c.biancheng.net/view/8219.html
原文:https://www.cnblogs.com/qing2105/p/14287374.html