Make debug.h non-idempotent, like <assert.h>.
[pintos-anon] / src / lib / debug.h
1 #ifndef HEADER_DEBUG_H
2 #define HEADER_DEBUG_H 1
3
4 #if __GNUC__ > 1
5 #define ATTRIBUTE(X) __attribute__ (X)
6 #else
7 #define ATTRIBUTE(X)
8 #endif
9
10 #define UNUSED ATTRIBUTE ((unused))
11 #define NO_RETURN ATTRIBUTE ((noreturn))
12 #define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST)))
13 #define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST)))
14
15 void panic (const char *, ...)
16      __attribute__ ((format (printf, 1, 2), noreturn));
17 void backtrace (void);
18
19 #endif /* debug.h */
20
21 /* This is outside the header guard so that debug.h may be
22    included multiple times with different settings of NDEBUG. */
23 #undef ASSERT
24 #undef NOT_REACHED
25
26 #ifndef NDEBUG
27 #define ASSERT(CONDITION)                                               \
28         if (CONDITION) {                                                \
29                 /* Nothing. */                                          \
30         } else {                                                        \
31                 panic ("%s:%d: %s(): assertion `%s' failed.",           \
32                        __FILE__, __LINE__, __func__, #CONDITION);       \
33         }
34 #define NOT_REACHED() ASSERT (0)
35 #else
36 #define ASSERT(CONDITION) ((void) 0)
37 #define NOT_REACHED() for (;;)
38 #endif