I want to set a condition on a gdb breakpoint to only break if a certain function name appears in the backtrace. What's the best way to do this?
I am not sure how to do exactly what you ask for, but a possible workaround, if you have access to the source code of the relevant function, is to set some global boolean variable to true
in the beginning of the function, and set it to false
just before the function exits. Then you could set a conditional breakpoint (using the condition
command) to stop only when this boolean variable is true
.
A simpler solution than Python scripting is using a temporary breakpoint.
It looks like this:
b ParentFunction
command 1
tb FunctionImInterestedIn
c
end
Every time you break in ParentFunction
, you'll set a one-time breakpoint on the function you're actually interested in, then continue running (presumably until you hit that breakpoint).
Since you'll break exactly once on FunctionImInterestedIn
, this won't work if FunctionImInterestedIn
is called multiple times in the context of ParentFunction
and you want to break on each invocation.
I am not sure how to do exactly what you ask for, but a possible workaround, if you have access to the source code of the relevant function, is to set some global boolean variable to true
in the beginning of the function, and set it to false
just before the function exits. Then you could set a conditional breakpoint (using the condition
command) to stop only when this boolean variable is true
.
Alternative to rix0rrr's answer:
b main
commands
set $inParentFunction = 0
c
end
b ParentFunction
commands
set $inParentFunction = 1
c
end
b FunctionImInterestedIn if ($inParentFunction)
© 2022 - 2024 — McMap. All rights reserved.