X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fdebug.h;fp=src%2Flib%2Fdebug.h;h=2af8ba421ebe248b07c3a03d5e80fe09dbba3acc;hb=ff144294a54d14af3c9324e6a336a3102094dea4;hp=4f3cb5b662dd07d54adcba4debccc7017e70e897;hpb=994aa9cbadb9bb822df3adfffad8de40997fc562;p=pintos-anon diff --git a/src/lib/debug.h b/src/lib/debug.h index 4f3cb5b..2af8ba4 100644 --- a/src/lib/debug.h +++ b/src/lib/debug.h @@ -1,22 +1,35 @@ #ifndef HEADER_DEBUG_H #define HEADER_DEBUG_H 1 -#if __GNUC__ > 1 -#define ATTRIBUTE(X) __attribute__ (X) -#else -#define ATTRIBUTE(X) -#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))) + +/* Prints a debug message along with the source file name, line + number, and function name of where it was emitted. CLASS is + used to filter out unwanted messages. */ +#define DEBUG(CLASS, ...) \ + debug_message (__FILE__, __LINE__, __func__, #CLASS, __VA_ARGS__) -#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))) +/* 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_enable (char *classes); +void debug_message (const char *file, int line, const char *function, + const char *class, const char *message, ...) + PRINTF_FORMAT (5, 6); +void debug_panic (const char *file, int line, const char *function, + const char *message, ...) PRINTF_FORMAT (4, 5) NO_RETURN; +void debug_backtrace (void); + +#endif -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. */ @@ -24,14 +37,11 @@ void backtrace (void); #undef NOT_REACHED #ifndef NDEBUG -#define ASSERT(CONDITION) \ - if (CONDITION) { \ - /* Nothing. */ \ - } else { \ - panic ("%s:%d: %s(): assertion `%s' failed.", \ - __FILE__, __LINE__, __func__, #CONDITION); \ +#define ASSERT(CONDITION) \ + if (CONDITION) { } else { \ + PANIC ("assertion `%s' failed.", #CONDITION); \ } -#define NOT_REACHED() ASSERT (0) +#define NOT_REACHED() PANIC ("executed an unreachable statement"); #else #define ASSERT(CONDITION) ((void) 0) #define NOT_REACHED() for (;;)