debug.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef DEBUG_H
25 #define DEBUG_H
26 
27 #include <stdio.h>
28 #include "sched.h"
29 #include "thread.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
45 #ifdef DEVELHELP
46 #include "cpu_conf.h"
47 #define DEBUG_PRINT(...) \
48  do { \
49  if ((thread_get_active() == NULL) || \
50  (thread_get_active()->stack_size >= \
51  THREAD_EXTRA_STACKSIZE_PRINTF)) { \
52  printf(__VA_ARGS__); \
53  } \
54  else { \
55  puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
56  } \
57  } while (0)
58 #else
59 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
60 #endif
61 
70 #if !defined(ENABLE_DEBUG) || defined(DOXYGEN)
71 #define ENABLE_DEBUG (0)
72 #endif
73 
80 # if defined(__cplusplus) && defined(__GNUC__)
81 # define DEBUG_FUNC __PRETTY_FUNCTION__
82 # elif __STDC_VERSION__ >= 199901L
83 # define DEBUG_FUNC __func__
84 # elif __GNUC__ >= 2
85 # define DEBUG_FUNC __FUNCTION__
86 # else
87 # define DEBUG_FUNC ""
88 # endif
89 
97 #define DEBUG(...) if (ENABLE_DEBUG) { DEBUG_PRINT(__VA_ARGS__); }
98 
105 #define DEBUG_PUTS(str) if (ENABLE_DEBUG) { puts(str); }
106 
113 #if ENABLE_DEBUG
114 #define DEBUG_EXTRA_STACKSIZE THREAD_EXTRA_STACKSIZE_PRINTF
115 #else
116 #define DEBUG_EXTRA_STACKSIZE (0)
117 #endif
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif /* DEBUG_H */
124 
Threading API.
Scheduler API definition.