debug.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2014 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
23 #include <stdio.h>
24 #include "sched.h"
25 #include "thread.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
41 #ifdef DEVELHELP
42 #include "cpu_conf.h"
43 #define DEBUG_PRINT(...) \
44  do { \
45  if ((thread_get_active() == NULL) || \
46  (thread_get_active()->stack_size >= \
47  THREAD_EXTRA_STACKSIZE_PRINTF)) { \
48  printf(__VA_ARGS__); \
49  } \
50  else { \
51  puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
52  } \
53  } while (0)
54 #else
55 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
56 #endif
57 
72 #ifdef DEVELHELP
73 #include "architecture.h"
74 #define DEBUG_BREAKPOINT(val) ARCHITECTURE_BREAKPOINT(val)
75 #else
76 #define DEBUG_BREAKPOINT(val) (void)0
77 #endif
78 
87 #if !defined(ENABLE_DEBUG) || defined(DOXYGEN)
88 #define ENABLE_DEBUG 0
89 #endif
90 
97 # if defined(__cplusplus) && defined(__GNUC__)
98 # define DEBUG_FUNC __PRETTY_FUNCTION__
99 # elif __STDC_VERSION__ >= 199901L
100 # define DEBUG_FUNC __func__
101 # elif __GNUC__ >= 2
102 # define DEBUG_FUNC __FUNCTION__
103 # else
104 # define DEBUG_FUNC ""
105 # endif
106 
121 #define DEBUG(...) do { if (ENABLE_DEBUG) { DEBUG_PRINT(__VA_ARGS__); } } while (0)
122 
129 #define DEBUG_PUTS(str) do { if (ENABLE_DEBUG) { puts(str); } } while (0)
137 #if ENABLE_DEBUG
138 #define DEBUG_EXTRA_STACKSIZE THREAD_EXTRA_STACKSIZE_PRINTF
139 #else
140 #define DEBUG_EXTRA_STACKSIZE (0)
141 #endif
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
Platform-independent access to architecture details.
Scheduler API definition.