In a C++, how can I pause execution and wait for a debugger (e.g. GDB or LLDB) to attach to the process (if it isn't already)?
Some other question suggested raise(SIGTRAP)
but that simply breaks into the debugger if it is already attached. I want to pause execution until the debugger attaches.
I also can't really mess around with signals because the my code runs inside a program that installs its own signal handlers.
It only needs to work on Linux.