문제

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.

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top