This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: stack specific breakpoint
- From: Doug Evans <dje at google dot com>
- To: kamaraju kusumanchi <raju dot mailinglists at gmail dot com>
- Cc: "gdb at sourceware dot org" <gdb at sourceware dot org>
- Date: Sun, 22 Feb 2015 21:44:47 -0800
- Subject: Re: stack specific breakpoint
- Authentication-results: sourceware.org; auth=none
- References: <CABpbYadoRdLsKn+iCWPJwkeYg_1JDGbXxY0geKsiAynqGpoVrg at mail dot gmail dot com>
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.