* Detecting when gdb is attached
@ 2010-11-04 13:40 Gruenhagen, Andreas
2010-11-04 16:19 ` Doug Evans
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gruenhagen, Andreas @ 2010-11-04 13:40 UTC (permalink / raw)
To: gdb
Dear gdb community,
I'm developing an application which cannot be started from within the gdb. Therefore, I have the start the application and attach the gdb afterwards. In some cases it would be nice to have the application wait in a spin loop until the debugger is attached. Is there any way of accomplishing such a thing?
I certainly can program the spin loop myself, attach the debugger, and then manually change a variable from within the debugger to end the loop. But, obviously, this is not an elegant solution (lots of manual work, code has to be changed and it has to be recompiled,and eventually, I might forget to delete the spin loop after debugging).
I thought of having some sort of action which is executed when the gdb is attached and detached, this could be for example used to switch a static flag in the debugee.
Is something like this possible ?
Best regards
Andreas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Detecting when gdb is attached
2010-11-04 13:40 Detecting when gdb is attached Gruenhagen, Andreas
@ 2010-11-04 16:19 ` Doug Evans
2010-11-04 17:26 ` paawan oza
2010-11-10 14:57 ` Steffen Dettmer
2 siblings, 0 replies; 4+ messages in thread
From: Doug Evans @ 2010-11-04 16:19 UTC (permalink / raw)
To: Gruenhagen, Andreas; +Cc: gdb
On Thu, Nov 4, 2010 at 6:40 AM, Gruenhagen, Andreas
<andreas.gruenhagen@sap.com> wrote:
> Dear gdb community,
> I'm developing an application which cannot be started from within the gdb. Therefore, I have the start the application and attach the gdb afterwards. In some cases it would be nice to have the application wait in a spin loop until the debugger is attached. Is there any way of accomplishing such a thing?
> I certainly can program the spin loop myself, attach the debugger, and then manually change a variable from within the debugger to end the loop. But, obviously, this is not an elegant solution (lots of manual work, code has to be changed and it has to be recompiled,and eventually, I might forget to delete the spin loop after debugging).
>
> I thought of having some sort of action which is executed when the gdb is attached and detached, this could be for example used to switch a static flag in the debugee.
> Is something like this possible ?
Hi. I'm not sure I understand the issue.
I can't tell if adding code to the app to detect when gdb has attached
is ok or not.
[e.g. "it would be nice to have the application wait in a spin loop
until the debugger is attached. Is there any way of accomplishing such
a thing?" versus "I might forget to delete the spin loop"]
Guessing, what if you passed a flag to the app to enable the spin
loop? Then you can keep the spin loop and only specify the flag when
you want to attach with gdb.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Detecting when gdb is attached
2010-11-04 13:40 Detecting when gdb is attached Gruenhagen, Andreas
2010-11-04 16:19 ` Doug Evans
@ 2010-11-04 17:26 ` paawan oza
2010-11-10 14:57 ` Steffen Dettmer
2 siblings, 0 replies; 4+ messages in thread
From: paawan oza @ 2010-11-04 17:26 UTC (permalink / raw)
To: Gruenhagen, Andreas; +Cc: gdb
Hi,
In my knowledge, the moment you attach gdb, your process is in stopped state and
done by kernel using SIGSTOP.
that time you process is already at some instruction.
I am not sure about youre requirement, but just after attach you can use signal
command to signals the process and write your own signal handler to notify you
app (for example 'signal SIGCONT').
but again you need to modify code.
if you are looking for no insn execution until gdb attached proabably try with
sigsuspend, sigprocmask sort of stuff.. but that changes code too.
I am not sure that helps.
Regards,
Oza.
----- Original Message ----
From: "Gruenhagen, Andreas" <andreas.gruenhagen@sap.com>
To: "gdb@sourceware.org" <gdb@sourceware.org>
Sent: Thu, November 4, 2010 7:10:21 PM
Subject: Detecting when gdb is attached
Dear gdb community,
I'm developing an application which cannot be started from within the gdb.
Therefore, I have the start the application and attach the gdb afterwards. In
some cases it would be nice to have the application wait in a spin loop until
the debugger is attached. Is there any way of accomplishing such a thing?
I certainly can program the spin loop myself, attach the debugger, and then
manually change a variable from within the debugger to end the loop. But,
obviously, this is not an elegant solution (lots of manual work, code has to be
changed and it has to be recompiled,and eventually, I might forget to delete the
spin loop after debugging).
I thought of having some sort of action which is executed when the gdb is
attached and detached, this could be for example used to switch a static flag in
the debugee.
Is something like this possible ?
Best regards
Andreas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Detecting when gdb is attached
2010-11-04 13:40 Detecting when gdb is attached Gruenhagen, Andreas
2010-11-04 16:19 ` Doug Evans
2010-11-04 17:26 ` paawan oza
@ 2010-11-10 14:57 ` Steffen Dettmer
2 siblings, 0 replies; 4+ messages in thread
From: Steffen Dettmer @ 2010-11-10 14:57 UTC (permalink / raw)
To: gdb
On Thu, Nov 4, 2010 at 2:40 PM, Gruenhagen, Andreas
<andreas.gruenhagen@sap.com> wrote:
> I'm developing an application which cannot be started from
> within the gdb. Therefore, I have the start the application and
> attach the gdb afterwards. In some cases it would be nice to
> have the application wait in a spin loop until the debugger is
> attached. Is there any way of accomplishing such a thing?
how should the application know whether to enter the wait loop
until gdb is attached or run as usual?
> I thought of having some sort of action which is executed when
> the gdb is attached and detached, this could be for example
> used to switch a static flag in the debugee. Is something like
> this possible ?
via ~/.gdbinit for example you could simply try:
print some_sort_of_action()
to invoke the function some_sort_of_action in the application
maybe?
oki,
Steffen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-11-10 14:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-04 13:40 Detecting when gdb is attached Gruenhagen, Andreas
2010-11-04 16:19 ` Doug Evans
2010-11-04 17:26 ` paawan oza
2010-11-10 14:57 ` Steffen Dettmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox