I'd like to write an assert-style macro that stops only if I am running the program in a debugger. AFAIK, the only available debugger on my box is gdb, so I'll talk about that one.
The documentation for the SIGTRAP signal indicates that it is intended for pausing the debugger, so I should be able to put
if (!assertion) raise(SIGTRAP);
in my code. It works to break GDB at the right point, but just running this from the command line also halts the program, as both bash and zsh helpfully interpret the "trace/breakpoint trap" signal to mean that the program should halt entirely.
Are there any signals that GDB uses but which I can expect that everything else ignores? Or is there a method beyond signals to pause execution in GDB without disrupting non-debugger operation?