1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#ifndef __LIB_DEBUG_H
#define __LIB_DEBUG_H
/* klaar@ida 2011-01-12: A macro to allow debug printouts without
* interfering with the test programs. The first argument must be a
* literal string (in double-quotes). */
#define debug(fmt, ...) printf("# " fmt, ##__VA_ARGS__)
/* 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)))
/* 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);
/* klaar@ida Parts from 100 to 210 exists (only in reference solution) */
#define PART 210
#endif
/* 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 */
|