1 /* CC0 (Public domain) - see LICENSE file for details
3 * Idea for implementation thanks to stackoverflow.com:
4 * http://stackoverflow.com/questions/3596781/detect-if-gdb-is-running
6 #include <ccan/breakpoint/breakpoint.h>
8 bool breakpoint_initialized;
9 bool breakpoint_under_debug;
11 /* This doesn't get called if we're under GDB. */
12 static void trap(int signum)
14 breakpoint_initialized = true;
17 void breakpoint_init(void)
19 struct sigaction old, new;
21 new.sa_handler = trap;
23 sigemptyset(&new.sa_mask);
24 sigaction(SIGTRAP, &new, &old);
25 kill(getpid(), SIGTRAP);
26 sigaction(SIGTRAP, &old, NULL);
28 if (!breakpoint_initialized) {
29 breakpoint_initialized = true;
30 breakpoint_under_debug = true;