Under the debugger
How can I tell my program that it is running under the debugger? I know this seems to indicate that I'm trying to do something that I shouldn't, and it's too messy. I think this is an interesting question. In particular, is there a way to do this in a POSIX environment? For example using sigaction (2) to detect if any handler is set? Even the worst thought; is there any inline assembly code that I could use on x86 architecture?
As we discuss, it will eventually be possible to start a debugger like gdb (1) and break where you are doing this possible hack. Thanks for any dirty one-liners or unlikely standards references related to this.
a source to share
Provides this article ( archive link ) to help?
This assumes, among other things:
- file descriptors leaking from the parent process
- environment variables ($ _)
- process state (
getsid()
etc.).
Note that most (if not all) of them rely on the debugger spawning the process that is being debugged. They are ineffective if the debugger is attached to an already running process.
a source to share
There is no reliable way to detect that you are running under a debugger. This is because the debugger can use any number of methods to actually debug your code, some of which will almost certainly not be caught by your method.
My question is, why do you need this? Unless you're trying to hide something :-)
a source to share