[comp.unix.questions] Detecting Presence of Debugger

penneyj@servio.UUCP (D. Jason Penney) (05/24/89)

We have a host-independent function HostCallDebugger, which is supposed
to synchronously invoke the host debugger (typically dbx in Unix systems).
If the debugger is not present, it generates a core, which is reasonable.

It is implemented by issuing a SIGTRAP (SIGTERM on Sun-3's).  If dbx is
present, you get an "Unexpected SIGTRAP" message, which you can subsequently
continue from.

If dbx is not present, the default core-producing behaviour is invoked.

Now, I saw some discussion a little while back on renaming your core files.
I've incorporated this into our general-purpose fault handler with good
results.

The problem is, if HostCallDebugger is invoked when no debugger is present
(such as a program assert failure), core gets dumped without any renaming.
It's not acceptable to always generate a core when calling HostCallDebugger
-- what if the program is being debugged?

What I would like is a way for a process to query whether or not it's being
debugged.  If it is, I'll just call SIGTRAP.  Otherwise I'll print a
nice message and invoke the smart coredump routine.

Thanks in advance.
-- 
D. Jason Penney                  Ph: (503) 629-8383
Beaverton, OR 97006              uucp: ...ogccse!servio!penneyj
STANDARD DISCLAIMER:  Should I or my opinions be caught or killed, the
company will disavow any knowledge of my actions...