I too dislike the idea of gdb unconditionally setting a particular environment variable. My first suggestion is that if you want to do this, then do
alias gdb='IN_GDB=yes gdb' Note that both with this implementation and the implementation proposed by the submitter, it only works for processes initiated by gdb, not when one uses gdb to attach to an existing process. I suggest that the program test this variable only on startup, and set a variable, and subsequently test that variable rather than call getenv. This isn't just about efficiency, this is to cover the attach case: when attaching to a program, you can do p in_gdb = 1 and then p in_gdb = 0 when detaching. See section ‘User-defined command hooks’ in the gdb manual (http://www.delorie.com/gnu/docs/gdb/gdb_190.html) for how to have these happen automatically every time you attach or detach the program. (See also section ‘Command files’ for description of .gdbinit processing, and section ‘User-defined commands’ for the general syntax for defining functions in gdb. If you implement this, then I suggest posting the resulting .gdbinit file/fragment to this bug report for the benefit of anyone else looking at this bug report and wanting to do the same thing.) Finally, if you really want to test for being debugged without help from .gdbinit files or any other user help, man ptrace and see what it says about how gdb becomes effectively the parent for many purposes. If using Linux, then man 5 proc and look at the descriptions of the stat and status files. However, I don't recommend this: it's harder to implement than .gdbinit files, and it probably only serves to mystify the person using the debugger rather than help them. I suggest closing this bug. pjrm.