Is there any way to set a breakpoint in gdb that is conditional on the call stack?

前端 未结 6 469
野的像风
野的像风 2020-11-28 13:15

I am debugging C++ in gdb 7.1 on Linux.

I have a function a() that is called in many places in the code. I want to set a breakpoint in it, but only if

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 14:05

    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.

提交回复
热议问题