This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stack specific breakpoint


On Sun, Feb 22, 2015 at 9:15 PM, kamaraju kusumanchi
<raju.mailinglists@gmail.com> wrote:
> Is there a way to set a breakpoint in a function A only when it is
> called from function B? In my case, I have
>
> funcB()
> {
>     ....
>     funcA( funcD(), funcE())
>     ....
> }
>
> funcC()
> {
>     ....
>     funcA(funcD(), funcE())
>     ....
> }
>
> where funcA is called by both funcB and funcC. funcC is called a lot
> of times (the exact number is not known either at run time or compile
> time) and funcB is called only a handful of times. The additional
> twist is that the arguments passed to funcA are the return values from
> other functions - funcD and funcE.
>
> I am interested in stepping into funcA only when it is called from
> funcB. Is there a way to specify the function hierarchy when setting a
> break point?
>
> I tried setting a break point where funcB calls funcA and then use the
> "step" command. But this steps into funcD() instead of funcA().
>
> Currently, my work around is to first set a breakpoint where funcB
> calls funcA and when the code hits that set another break point in
> funcA. Once code finishes funcA, I will disable it (since it could be
> called by funcC afterwards). I will reenable it when it hits the funcA
> line in funcB definition. But doing this enable/disable dance is
> tiresome. Is there a better way to achiever this?

(gdb) break funcA if $_caller_is("funcB")

https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Funs.html#Convenience-Funs

This requires gdb 7.9 configured with python support.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]