J. Polfer J. Polfer - 1 year ago 262
Linux Question

Set breakpoint in C or C++ code programmatically for gdb on Linux

How can I set a breakpoint in C or C++ code programatically that will work for gdb on Linux?


int main(int argc, char** argv)
/* set breakpoint here! */
int a = 3;
a++; /* In gdb> print a; expect result to be 3 */
return 0;

Answer Source

One way is to signal an interrupt:

#include <csignal>

// Generate an interrupt

In C:

#include <signal.h>

UPDATE: MSDN states that Windows doesn't really support SIGINT, so if portability is a concern, you're probably better off using SIGABRT.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download