Initial revision
[pintos-anon] / src / lib / debug.h
1 #ifndef HEADER_DEBUG_H
2 #define HEADER_DEBUG_H 1
3
4 #ifndef NDEBUG
5 #define ASSERT(CONDITION)                                               \
6         if (CONDITION) {                                                \
7                 /* Nothing. */                                          \
8         } else {                                                        \
9                 panic ("%s:%d: %s(): assertion `%s' failed.",           \
10                        __FILE__, __LINE__, __func__, #CONDITION);       \
11         }
12 #define NOT_REACHED() ASSERT (0)
13 #else
14 #define ASSERT(CONDITION) ((void) 0)
15 #define NOT_REACHED() for (;;)
16 #endif
17
18 void panic (const char *, ...)
19      __attribute__ ((format (printf, 1, 2), noreturn));
20
21 #if __GNUC__ > 1
22 #define ATTRIBUTE(X) __attribute__ (X)
23 #else
24 #define ATTRIBUTE(X)
25 #endif
26
27 #define UNUSED ATTRIBUTE ((unused))
28 #define NO_RETURN ATTRIBUTE ((noreturn))
29 #define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST)))
30 #define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST)))
31
32 #endif /* debug.h */