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

前端 未结 6 463
野的像风
野的像风 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 13:49

    An easy one for arm is:

    Set the breakpoint in the function you are interested.

    break a
    

    Attach an gdb command to that breakpoint.

    command 1
     up 1
     if $lr == 0x12345678
      echo match \n
      down 1
     else
      echo no match \n
      echo $lr \n
      down 1
      cont 
     end 
    end 
    

    When ever you arrive in the function a(), the command temporarily pops up one stack frame thus updating the link register. The callers link register value can then be used continue when the caller is not the execution path you need.

    Enjoy.

提交回复
热议问题