public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* stack specific breakpoint
@ 2015-02-23  5:15 kamaraju kusumanchi
  2015-02-23  5:44 ` Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: kamaraju kusumanchi @ 2015-02-23  5:15 UTC (permalink / raw)
  To: gdb

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?

If this is feature is not supported, could you please add this to the wishlist?

thanks
raju
-- 
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stack specific breakpoint
  2015-02-23  5:15 stack specific breakpoint kamaraju kusumanchi
@ 2015-02-23  5:44 ` Doug Evans
  2015-02-24  6:08   ` kamaraju kusumanchi
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Evans @ 2015-02-23  5:44 UTC (permalink / raw)
  To: kamaraju kusumanchi; +Cc: gdb

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stack specific breakpoint
  2015-02-23  5:44 ` Doug Evans
@ 2015-02-24  6:08   ` kamaraju kusumanchi
  2015-02-27 18:38     ` kamaraju kusumanchi
  0 siblings, 1 reply; 4+ messages in thread
From: kamaraju kusumanchi @ 2015-02-24  6:08 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb

>
> (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.

Thanks. I will try to compile gdb 7.9 then and see how it goes.

raju
-- 
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stack specific breakpoint
  2015-02-24  6:08   ` kamaraju kusumanchi
@ 2015-02-27 18:38     ` kamaraju kusumanchi
  0 siblings, 0 replies; 4+ messages in thread
From: kamaraju kusumanchi @ 2015-02-27 18:38 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb

On Tue, Feb 24, 2015 at 1:07 AM, kamaraju kusumanchi
<raju.mailinglists@gmail.com> wrote:
>>
>> (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.
>
> Thanks. I will try to compile gdb 7.9 then and see how it goes.
>

It works great! Thanks for the pointer in the right direction.

I have documented the whole thing in
http://raju.shoutwiki.com/wiki/Stack_specific_breakpoints_in_gdb with
some sample code and commands to compile a local version of gdb. I
thought that having all the instructions in one place might help
someone.

thanks
raju
-- 
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-27  2:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23  5:15 stack specific breakpoint kamaraju kusumanchi
2015-02-23  5:44 ` Doug Evans
2015-02-24  6:08   ` kamaraju kusumanchi
2015-02-27 18:38     ` kamaraju kusumanchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).