debug.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef _DEBUG_H
  2. #define _DEBUG_H
  3. #ifdef HAVE_CONFIG_H
  4. # include "config.h"
  5. #endif
  6. #define GET_BUFS 30
  7. #define get_buf_inc() if (++current_get_buf == GET_BUFS) current_get_buf = 0;
  8. #define Context do { \
  9. simple_snprintf(get_buf[current_get_buf], sizeof(get_buf[current_get_buf]), "Context: %s:%d", __FILE__, __LINE__); \
  10. get_buf_inc(); \
  11. } while (0)
  12. #define ContextNote(_from, _buf) do { \
  13. simple_snprintf(get_buf[current_get_buf], sizeof(get_buf[current_get_buf]), "%s: %s", _from, _buf); \
  14. get_buf_inc(); \
  15. } while(0)
  16. /*
  17. * Handy aliases for memory tracking and core dumps
  18. */
  19. #define debug0(x) putlog(LOG_DEBUG,"*",x)
  20. #define debug1(x,a1) putlog(LOG_DEBUG,"*",x,a1)
  21. #define debug2(x,a1,a2) putlog(LOG_DEBUG,"*",x,a1,a2)
  22. #define debug3(x,a1,a2,a3) putlog(LOG_DEBUG,"*",x,a1,a2,a3)
  23. #define debug4(x,a1,a2,a3,a4) putlog(LOG_DEBUG,"*",x,a1,a2,a3,a4)
  24. #include "net.h"
  25. extern bool sdebug, segfaulted;
  26. extern size_t current_get_buf;
  27. extern char get_buf[GET_BUFS][SGRAB + 5];
  28. void setlimits();
  29. void sdprintf (const char *, ...) __attribute__((format(printf, 1, 2)));
  30. void init_signals();
  31. void init_debug();
  32. void got_int(int z);
  33. #ifdef DEBUG
  34. #undef _assert
  35. void _assert(int, const char *, int, const char *, const char *,
  36. const char *, ...) __attribute__((format(printf, 6, 7)));
  37. #define _ASSERT(recoverable, cond, msg...) do { \
  38. if (__predict_false(!(cond))) { \
  39. _assert(recoverable, __FILE__, __LINE__, __func__, # cond, msg); \
  40. } \
  41. Context; \
  42. } while (0)
  43. #else
  44. #define _ASSERT(recoverable, cond, msg...) do { \
  45. } while (0)
  46. #endif
  47. #define ASSERT(cond, msg...) _ASSERT(0, cond, msg)
  48. #define ASSERT0(cond) ASSERT(cond, NULL)
  49. #define WARN(cond, msg...) _ASSERT(1, cond, msg)
  50. #endif /* !_DEBUG_H */