]> git.ozlabs.org Git - ccan/blobdiff - ccan/breakpoint/breakpoint.h
breakpoint: new module.
[ccan] / ccan / breakpoint / breakpoint.h
diff --git a/ccan/breakpoint/breakpoint.h b/ccan/breakpoint/breakpoint.h
new file mode 100644 (file)
index 0000000..6283a01
--- /dev/null
@@ -0,0 +1,24 @@
+/* CC0 (Public domain) - see LICENSE file for details */
+#ifndef CCAN_BREAKPOINT_H
+#define CCAN_BREAKPOINT_H
+#include <ccan/compiler/compiler.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdbool.h>
+
+void breakpoint_init(void) COLD;
+extern bool breakpoint_initialized;
+extern bool breakpoint_under_debug;
+
+/**
+ * breakpoint - stop if running under the debugger.
+ */
+static inline void breakpoint(void)
+{
+       if (!breakpoint_initialized)
+               breakpoint_init();
+       if (breakpoint_under_debug)
+               kill(getpid(), SIGTRAP);
+}
+#endif /* CCAN_BREAKPOINT_H */