PKUOS - Pintos
Pintos source browser for PKU Operating System course
debug.h
Go to the documentation of this file.
1#ifndef __LIB_DEBUG_H
2#define __LIB_DEBUG_H
3
4/** GCC lets us add "attributes" to functions, function
5 parameters, etc. to indicate their properties.
6 See the GCC manual for details. */
7#define UNUSED __attribute__ ((unused))
8#define NO_RETURN __attribute__ ((noreturn))
9#define NO_INLINE __attribute__ ((noinline))
10#define PRINTF_FORMAT(FMT, FIRST) __attribute__ ((format (printf, FMT, FIRST)))
11
12/** Halts the OS, printing the source file name, line number, and
13 function name, plus a user-specific message. */
14#define PANIC(...) debug_panic (__FILE__, __LINE__, __func__, __VA_ARGS__)
15
16void debug_panic (const char *file, int line, const char *function,
17 const char *message, ...) PRINTF_FORMAT (4, 5) NO_RETURN;
18void debug_backtrace (void);
19void debug_backtrace_all (void);
20
21#endif
22
23
24
25/** This is outside the header guard so that debug.h may be
26 included multiple times with different settings of NDEBUG. */
27#undef ASSERT
28#undef NOT_REACHED
29
30#ifndef NDEBUG
31#define ASSERT(CONDITION) \
32 if (CONDITION) { } else { \
33 PANIC ("assertion `%s' failed.", #CONDITION); \
34 }
35#define NOT_REACHED() PANIC ("executed an unreachable statement");
36#else
37#define ASSERT(CONDITION) ((void) 0)
38#define NOT_REACHED() for (;;)
39#endif /**< lib/debug.h */
#define PRINTF_FORMAT(FMT, FIRST)
Definition: debug.h:10
void debug_backtrace_all(void)
Prints call stack of all threads.
Definition: debug.c:117
void debug_backtrace(void)
Prints the call stack, that is, a list of addresses, one in each of the functions we are nested withi...
Definition: debug.c:13
void debug_panic(const char *file, int line, const char *function, const char *message,...) PRINTF_FORMAT(4
#define NO_RETURN
Definition: debug.h:8
An open file.
Definition: file.c:8