Re: Detecting when gdb is attached

Doug Evans
2010-11-04T16:19:09Z

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.