I've been using gdb normally for 1 or 2 projects. I.e. I invoke gdb --args prog args
. gdb runs in the same tty as the program I'm debugging.
However my latest project is modifying the dtach utility. This is a program like screen, so the tty's are redirected elsewhere, thus I have to use gdb's attach functionality.
The problem with gdb attach is that obviously you can't attach from the very beginning as you need to run the program first in order to get a pid to attach to.
Is there any way I can get a program to wait at a point until gdb is attached?
I can't use gdbserver as I'm on cygwin. Also I tried using pause()
, but that just hung when I tried to continue.
A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.
This command sets the values of a debugger variable, memory address, or expression that is accessible according to the scope and visibility rules of the language. The expression can be any expression that is valid in the current context. The set variable command evaluates the specified expression.
To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.
At least with LLDB making the process send SIGSTOP
to itself should do the trick. Debugger continue command will then issue the SIGCONT
. This should work with GDB too. Alternatively try SIGINT
instead of SIGSTOP
.
Include header
#include <signal.h>
#include <csignal> // or C++ style alternative
then
raise(SIGSTOP)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With