Make debug.h non-idempotent, like <assert.h>.
[pintos-anon] / src / lib / debug.h
index 138247339fcb72357b2ccf69bf88873ccb7b0e79..4f3cb5b662dd07d54adcba4debccc7017e70e897 100644 (file)
@@ -1,6 +1,28 @@
 #ifndef HEADER_DEBUG_H
 #define HEADER_DEBUG_H 1
 
+#if __GNUC__ > 1
+#define ATTRIBUTE(X) __attribute__ (X)
+#else
+#define ATTRIBUTE(X)
+#endif
+
+#define UNUSED ATTRIBUTE ((unused))
+#define NO_RETURN ATTRIBUTE ((noreturn))
+#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST)))
+#define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST)))
+
+void panic (const char *, ...)
+     __attribute__ ((format (printf, 1, 2), noreturn));
+void backtrace (void);
+
+#endif /* debug.h */
+
+/* This is outside the header guard so that debug.h may be
+   included multiple times with different settings of NDEBUG. */
+#undef ASSERT
+#undef NOT_REACHED
+
 #ifndef NDEBUG
 #define ASSERT(CONDITION)                                               \
         if (CONDITION) {                                                \
 #define ASSERT(CONDITION) ((void) 0)
 #define NOT_REACHED() for (;;)
 #endif
-
-void panic (const char *, ...)
-     __attribute__ ((format (printf, 1, 2), noreturn));
-
-#if __GNUC__ > 1
-#define ATTRIBUTE(X) __attribute__ (X)
-#else
-#define ATTRIBUTE(X)
-#endif
-
-#define UNUSED ATTRIBUTE ((unused))
-#define NO_RETURN ATTRIBUTE ((noreturn))
-#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST)))
-#define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST)))
-
-#endif /* debug.h */