X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fdebug.h;h=888ab7b9d985d96033f9ee3c00a2876476256a7c;hb=3edcfedb8e62970f3293fa676b6691f8658c3c11;hp=138247339fcb72357b2ccf69bf88873ccb7b0e79;hpb=750d21936d284127e265d050ccbce76fca1ece1a;p=pintos-anon diff --git a/src/lib/debug.h b/src/lib/debug.h index 1382473..888ab7b 100644 --- a/src/lib/debug.h +++ b/src/lib/debug.h @@ -1,32 +1,39 @@ -#ifndef HEADER_DEBUG_H -#define HEADER_DEBUG_H 1 +#ifndef __LIB_DEBUG_H +#define __LIB_DEBUG_H -#ifndef NDEBUG -#define ASSERT(CONDITION) \ - if (CONDITION) { \ - /* Nothing. */ \ - } else { \ - panic ("%s:%d: %s(): assertion `%s' failed.", \ - __FILE__, __LINE__, __func__, #CONDITION); \ - } -#define NOT_REACHED() ASSERT (0) -#else -#define ASSERT(CONDITION) ((void) 0) -#define NOT_REACHED() for (;;) -#endif +/* GCC lets us add "attributes" to functions, function + parameters, etc. to indicate their properties. + See the GCC manual for details. */ +#define UNUSED __attribute__ ((unused)) +#define NO_RETURN __attribute__ ((noreturn)) +#define NO_INLINE __attribute__ ((noinline)) +#define PRINTF_FORMAT(FMT, FIRST) __attribute__ ((format (printf, FMT, FIRST))) -void panic (const char *, ...) - __attribute__ ((format (printf, 1, 2), noreturn)); +/* Halts the OS, printing the source file name, line number, and + function name, plus a user-specific message. */ +#define PANIC(...) debug_panic (__FILE__, __LINE__, __func__, __VA_ARGS__) + +void debug_panic (const char *file, int line, const char *function, + const char *message, ...) PRINTF_FORMAT (4, 5) NO_RETURN; +void debug_backtrace (void); +void debug_backtrace_all (void); -#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 */ + +/* 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) { } else { \ + PANIC ("assertion `%s' failed.", #CONDITION); \ + } +#define NOT_REACHED() PANIC ("executed an unreachable statement"); +#else +#define ASSERT(CONDITION) ((void) 0) +#define NOT_REACHED() for (;;) +#endif /* lib/debug.h */