Set breakpoint in C or C++ code programmatically for gdb on Linux
One way is to signal an interrupt:
#include <csignal>// Generate an interruptstd::raise(SIGINT);
In C:
#include <signal.h>raise(SIGINT);
UPDATE: MSDN states that Windows doesn't really support SIGINT
, so if portability is a concern, you're probably better off using SIGABRT
.
In a project I work on, we do this:
raise(SIGABRT); /* To continue from here in GDB: "signal 0". */
(In our case we wanted to crash hard if this happened outside the debugger, generating a crash report if possible. That's one reason we used SIGABRT. Doing this portably across Windows, Mac, and Linux took several attempts. We ended up with a few #ifdefs, helpfully commented here: http://hg.mozilla.org/mozilla-central/file/98fa9c0cff7a/js/src/jsutil.cpp#l66 .)