GDB可以在一系列函数调用上设置断点吗? [英] Can GDB set a breakpoint on a sequence of function calls?
问题描述
我想在崩溃发生之前检查一些全局变量.该问题仅在特定的堆栈跟踪中重现,并且在最内层函数(或堆栈中的任何其他函数)上设置断点将无法使我足够接近.
I'd like to inspect some global variables before a crash happens. The issue only reproduces on a certain stack trace and setting a breakpoint on the innermost function (or any other from the stack) will not get me close enough.
仅当堆栈顶部包含类似内容时,我才能达到中断的结果吗?
Can I achieve the result of breaking only when the top of the stack contains something like this ?
#0 __GI_connect
#1 curl_connect
#2 get_file
#3 init_assets
只要做
b init_assets
c
b get_file
c
...
不起作用,因为多次调用了init_assets,并且每次都不调用curl,因此gdb会中断使用curl的无关代码.
doesn't work since init_assets is called multiple times and it doesn't call curl every time, so gdb will break in unrelated code that uses curl.
稍后另一种方法是:
b inner_func
ignore 1 10000
r
# app crashes
info b
Breakpoint 1 has been hit 10 times.
然后您删除断点,将其添加回并且仅忽略9次.再次运行该应用程序时,gdb将在第10次停止-当inner_func崩溃时.
Then you remove the breakpoint, add it back and only ignore 9 times. When you run the app again, gdb will stop on the 10th time -- when inner_func crashes.
如果执行差异太大,您也可以将应用程序记录在mozilla的rr
中.
You can also record the app in mozilla's rr
if the execution varies too much.
推荐答案
You can use a conditional breakpoint with the the $_caller_is
convenience function. Something like this:
(gdb) break connect
Breakpoint 1 at 0x7ffff7ee6820
(gdb) cond 1 $_caller_is("curl_connect") && $_caller_is("get_file", 2) && $_caller_is("init_assets", 3)
这篇关于GDB可以在一系列函数调用上设置断点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!