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 
9 #pragma once
10 
26 #include <stdio.h>
27 #include "sched.h"
28 #include "thread.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
44 #ifdef DEVELHELP
45 #include "cpu_conf.h"
46 #define DEBUG_PRINT(...) \
47  do { \
48  if ((thread_get_active() == NULL) || \
49  (thread_get_active()->stack_size >= \
50  THREAD_EXTRA_STACKSIZE_PRINTF)) { \
51  printf(__VA_ARGS__); \
52  } \
53  else { \
54  puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
55  } \
56  } while (0)
57 #else
58 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
59 #endif
60 
75 #ifdef DEVELHELP
76 #include "architecture.h"
77 #define DEBUG_BREAKPOINT(val) ARCHITECTURE_BREAKPOINT(val)
78 #else
79 #define DEBUG_BREAKPOINT(val) (void)0
80 #endif
81 
90 #if !defined(ENABLE_DEBUG) || defined(DOXYGEN)
91 #define ENABLE_DEBUG 0
92 #endif
93 
100 # if defined(__cplusplus) && defined(__GNUC__)
101 # define DEBUG_FUNC __PRETTY_FUNCTION__
102 # elif __STDC_VERSION__ >= 199901L
103 # define DEBUG_FUNC __func__
104 # elif __GNUC__ >= 2
105 # define DEBUG_FUNC __FUNCTION__
106 # else
107 # define DEBUG_FUNC ""
108 # endif
109 
124 #define DEBUG(...) do { if (ENABLE_DEBUG) { DEBUG_PRINT(__VA_ARGS__); } } while (0)
125 
132 #define DEBUG_PUTS(str) do { if (ENABLE_DEBUG) { puts(str); } } while (0)
140 #if ENABLE_DEBUG
141 #define DEBUG_EXTRA_STACKSIZE THREAD_EXTRA_STACKSIZE_PRINTF
142 #else
143 #define DEBUG_EXTRA_STACKSIZE (0)
144 #endif
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
Platform-independent access to architecture details.
Scheduler API definition.