ChibiOS/RT  5.1.0
chdebug.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
3 
4  This file is part of ChibiOS.
5 
6  ChibiOS is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /**
21  * @file chdebug.h
22  * @brief Debug support macros and structures.
23  *
24  * @addtogroup debug
25  * @{
26  */
27 
28 #ifndef CHDEBUG_H
29 #define CHDEBUG_H
30 
31 /*===========================================================================*/
32 /* Module constants. */
33 /*===========================================================================*/
34 
35 /*===========================================================================*/
36 /* Module pre-compile time settings. */
37 /*===========================================================================*/
38 
39 /**
40  * @name Debug related settings
41  * @{
42  */
43 /**
44  * @brief Fill value for thread stack area in debug mode.
45  */
46 #if !defined(CH_DBG_STACK_FILL_VALUE) || defined(__DOXYGEN__)
47 #define CH_DBG_STACK_FILL_VALUE 0x55
48 #endif
49 /** @} */
50 
51 /*===========================================================================*/
52 /* Derived constants and error checks. */
53 /*===========================================================================*/
54 
55 /*===========================================================================*/
56 /* Module data structures and types. */
57 /*===========================================================================*/
58 
59 /*===========================================================================*/
60 /* Module macros. */
61 /*===========================================================================*/
62 
63 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
64 #define _dbg_enter_lock() (ch.dbg.lock_cnt = (cnt_t)1)
65 #define _dbg_leave_lock() (ch.dbg.lock_cnt = (cnt_t)0)
66 #endif
67 
68 /* When the state checker feature is disabled then the following functions
69  are replaced by an empty macro.*/
70 #if CH_DBG_SYSTEM_STATE_CHECK == FALSE
71 #define _dbg_enter_lock()
72 #define _dbg_leave_lock()
73 #define _dbg_check_disable()
74 #define _dbg_check_suspend()
75 #define _dbg_check_enable()
76 #define _dbg_check_lock()
77 #define _dbg_check_unlock()
78 #define _dbg_check_lock_from_isr()
79 #define _dbg_check_unlock_from_isr()
80 #define _dbg_check_enter_isr()
81 #define _dbg_check_leave_isr()
82 #define chDbgCheckClassI()
83 #define chDbgCheckClassS()
84 #endif
85 
86 /**
87  * @name Macro Functions
88  * @{
89  */
90 /**
91  * @brief Function parameters check.
92  * @details If the condition check fails then the kernel panics and halts.
93  * @note The condition is tested only if the @p CH_DBG_ENABLE_CHECKS switch
94  * is specified in @p chconf.h else the macro does nothing.
95  *
96  * @param[in] c the condition to be verified to be true
97  *
98  * @api
99  */
100 #if !defined(chDbgCheck)
101 #define chDbgCheck(c) do { \
102  /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
103  if (CH_DBG_ENABLE_CHECKS != FALSE) { \
104  if (!(c)) { \
105  /*lint -restore*/ \
106  chSysHalt(__func__); \
107  } \
108  } \
109 } while (false)
110 #endif /* !defined(chDbgCheck) */
111 
112 /**
113  * @brief Condition assertion.
114  * @details If the condition check fails then the kernel panics with a
115  * message and halts.
116  * @note The condition is tested only if the @p CH_DBG_ENABLE_ASSERTS switch
117  * is specified in @p chconf.h else the macro does nothing.
118  * @note The remark string is not currently used except for putting a
119  * comment in the code about the assertion.
120  *
121  * @param[in] c the condition to be verified to be true
122  * @param[in] r a remark string
123  *
124  * @api
125  */
126 #if !defined(chDbgAssert)
127 #define chDbgAssert(c, r) do { \
128  /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
129  if (CH_DBG_ENABLE_ASSERTS != FALSE) { \
130  if (!(c)) { \
131  /*lint -restore*/ \
132  chSysHalt(__func__); \
133  } \
134  } \
135 } while (false)
136 #endif /* !defined(chDbgAssert) */
137 /** @} */
138 
139 /*===========================================================================*/
140 /* External declarations. */
141 /*===========================================================================*/
142 
143 #ifdef __cplusplus
144 extern "C" {
145 #endif
146 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
147  void _dbg_check_disable(void);
148  void _dbg_check_suspend(void);
149  void _dbg_check_enable(void);
150  void _dbg_check_lock(void);
151  void _dbg_check_unlock(void);
152  void _dbg_check_lock_from_isr(void);
153  void _dbg_check_unlock_from_isr(void);
154  void _dbg_check_enter_isr(void);
155  void _dbg_check_leave_isr(void);
156  void chDbgCheckClassI(void);
157  void chDbgCheckClassS(void);
158 #endif
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 /*===========================================================================*/
164 /* Module inline functions. */
165 /*===========================================================================*/
166 
167 #endif /* CHDEBUG_H */
168 
169 /** @} */
void _dbg_check_lock_from_isr(void)
Guard code for chSysLockFromIsr().
Definition: chdebug.c:176
void chDbgCheckClassS(void)
S-class functions context check.
Definition: chdebug.c:250
void _dbg_check_lock(void)
Guard code for chSysLock().
Definition: chdebug.c:150
void _dbg_check_enable(void)
Guard code for chSysEnable().
Definition: chdebug.c:138
void _dbg_check_leave_isr(void)
Guard code for CH_IRQ_EPILOGUE().
Definition: chdebug.c:217
void _dbg_check_enter_isr(void)
Guard code for CH_IRQ_PROLOGUE().
Definition: chdebug.c:202
void _dbg_check_disable(void)
Guard code for chSysDisable().
Definition: chdebug.c:114
void _dbg_check_unlock(void)
Guard code for chSysUnlock().
Definition: chdebug.c:163
void chDbgCheckClassI(void)
I-class functions context check.
Definition: chdebug.c:235
void _dbg_check_unlock_from_isr(void)
Guard code for chSysUnlockFromIsr().
Definition: chdebug.c:189
void _dbg_check_suspend(void)
Guard code for chSysSuspend().
Definition: chdebug.c:126