GDB:仅当前一个Break在func2上时,才在func1上Break
GDB: Break on func1 only if previous break was on func2
我有两个函数,func1
和func2
,每个函数都有一个断点集。
如果上一个断点命中是func1
,是否可以在func2
断点上停止GDB?
实现这一点的最佳方法是在断点中使用命令。
当命中两个断点时,您可以指示GDB执行某些命令(例如,增加计数器)。根据这些变量/标志的计数,有条件地暂停执行。
我在这个链接上找到了这些信息。请参阅相同内容以了解更多详细信息。这篇文章写得很好,有恰当的例子。希望这能有所帮助。
define
来创建函数。
main.cpp
int c1=0, c2=0;
void func1(){
c1++;
}
void func2(){
c2++;
}
int main(){
// we shouldn't see a breakpoint here
for(int i=0; i < 5; i++)
func1();
func2();
// get a breakpoint
func1();
return 0;
}
编译并运行gdb
clang++ main.cpp -o main.exe -g
gdb --args ./main.exe
gdb命令
break func2
commands
break func1
# run a few commands when we hit func1()
commands
print c1
backtrace
end
# continue to func1() breakpoint
continue
end
run
相关文章:
- 在 c++ 中在开关情况下使用和不使用"break"时的不同输出
- 使用flag、return、exception、goto或break中止过程
- 使用C 中的链接seam break static变量依赖关系
- 为什么在使用 select() 时连接到带有第二个套接字的服务器"break"第一次连接?
- 我的 break 语句没有中断 for 循环
- 海湾合作委员会 7、aligned_storage 和 "dereferencing type-punned pointer will break strict-aliasing rules"
- 为什么在使用LLVM时,std::ifstream的缓冲"break" std::getline?
- GDB:仅当前一个Break在func2上时,才在func1上Break
- if(!getline(std::cin,str1))break;这个条件检查什么
- 在基于 lambda 的 foreach 循环中模拟 'continue;', 'break;“
- 为什么我不能在C++的三元条件语句中使用 "break" 语句?
- 而带有逗号运算符的循环与重复的代码与“break;”
- C++ 如果 (func1() && func2()),func1 是否必须在 func2 之前调用?
- Visual Studio中可能"break the debugger"什么(也许是std::string?)
- VS 2012:调试器:"Break all in 5 seconds"
- 有没有办法使用 break 语句来解决
- 为什么我们要尽量减少循环中break和continue的使用
- LeetCode Word Break,未通过在线评委,但通过了在线测试
- 海湾合作委员会警告"dereferencing type-punned pointer will break strict-aliasing rules"
- "Illegal Break"时'Outputting Multiples of a Number, Input 0 or Non # to exit'