Contiki 3.x
debug.h
Go to the documentation of this file.
1 /**
2  * \file
3  * Debug helpers.
4  *
5  * Define DEBUG_ON before this file is included to enable debug printing. Do not define it to disable it.
6  * Call DEBUG() to print.
7  *
8  * Implementation note:
9  * Purpusfully not in an include guard as it should only be included by c files.
10  * This will cause a compile time error if it is included more than once.
11  *
12  * \author
13  * Arthur Fabre <af1g12@ecs.soton.ac.uk>
14  */
15 
16 /**
17  * Globally turn debugging on and off.
18  * 0: Off
19  */
20 #define GLOBAL_DEBUG 0
21 
22 #if GLOBAL_DEBUG
23  #ifdef DEBUG_ON
24  #define DEBUG_VAL 1
25  #warning "DEBUG Output Enabled"
26  #else
27  #define DEBUG_VAL 0
28  #endif
29 #else
30  #define DEBUG_VAL 0
31 #endif
32 
33 #define STRINGIFY(x) #x
34 #define TOSTRING(x) STRINGIFY(x)
35 #define AT __FILE__ ":" TOSTRING(__LINE__) ":"
36 
37 /**
38  * DEBUG Printing.
39  *
40  * Implementation note:
41  * A c and not a macro if statement is used to ensure that the print statement is passed to the compiler.
42  * This ensures that the DEBUG statement is always valid, even when debugging is disabled.
43  * If debugging is disabled this will be optimized out by the compiler.
44  * The do while loop makes the macro exapand to a proper statement (and not a conditional).
45  */
46 #define DEBUG(fmt, ...) \
47  do { if (DEBUG_VAL) printf("%16s%-36s " fmt, AT, __func__, ## __VA_ARGS__); } while(0)