breakpoint.h 574 B

123456789101112131415161718192021222324
  1. /* CC0 (Public domain) - see LICENSE file for details */
  2. #ifndef CCAN_BREAKPOINT_H
  3. #define CCAN_BREAKPOINT_H
  4. #include <ccan/compiler/compiler.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. #include <signal.h>
  8. #include <stdbool.h>
  9. void breakpoint_init(void) COLD;
  10. extern bool breakpoint_initialized;
  11. extern bool breakpoint_under_debug;
  12. /**
  13. * breakpoint - stop if running under the debugger.
  14. */
  15. static inline void breakpoint(void)
  16. {
  17. if (!breakpoint_initialized)
  18. breakpoint_init();
  19. if (breakpoint_under_debug)
  20. kill(getpid(), SIGTRAP);
  21. }
  22. #endif /* CCAN_BREAKPOINT_H */