From a1435e018bfc9919cb76b1356509ecc883767fb4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:51:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6123 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 257 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 os/rt/include/chdebug.h (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h new file mode 100644 index 000000000..836645f07 --- /dev/null +++ b/os/rt/include/chdebug.h @@ -0,0 +1,257 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012,2013 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file chdebug.h + * @brief Debug macros and structures. + * + * @addtogroup debug + * @{ + */ + +#ifndef _CHDEBUG_H_ +#define _CHDEBUG_H_ + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @name Debug related settings + * @{ + */ +/** + * @brief Trace buffer entries. + */ +#ifndef CH_DBG_TRACE_BUFFER_SIZE +#define CH_DBG_TRACE_BUFFER_SIZE 64 +#endif + +/** + * @brief Fill value for thread stack area in debug mode. + */ +#ifndef CH_DBG_STACK_FILL_VALUE +#define CH_DBG_STACK_FILL_VALUE 0x55 +#endif + +/** + * @brief Fill value for thread area in debug mode. + * @note The chosen default value is 0xFF in order to make evident which + * thread fields were not initialized when inspecting the memory with + * a debugger. A uninitialized field is not an error in itself but it + * better to know it. + */ +#ifndef CH_DBG_THREAD_FILL_VALUE +#define CH_DBG_THREAD_FILL_VALUE 0xFF +#endif +/** @} */ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || \ + CH_DBG_ENABLE_STACK_CHECK || CH_DBG_SYSTEM_STATE_CHECK +#define CH_DBG_ENABLED TRUE +#else +#define CH_DBG_ENABLED FALSE +#endif + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) +/** + * @brief Trace buffer record. + */ +typedef struct { + /** + * @brief Time of the switch event. + */ + systime_t se_time; + /** + * @brief Switched in thread. + */ + thread_t *se_tp; + /** + * @brief Object where going to sleep. + */ + void *se_wtobjp; + /** + * @brief Switched out thread state. + */ + uint8_t se_state; +} ch_swc_event_t; + +/** + * @brief Trace buffer header. + */ +typedef struct { + /** + * @brief Trace buffer size (entries). + */ + unsigned tb_size; + /** + * @brief Pointer to the buffer front. + */ + ch_swc_event_t *tb_ptr; + /** + * @brief Ring buffer. + */ + ch_swc_event_t tb_buffer[CH_DBG_TRACE_BUFFER_SIZE]; +} ch_trace_buffer_t; +#endif /* CH_DBG_ENABLE_TRACE */ + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +#define __QUOTE_THIS(p) #p + +#if CH_DBG_SYSTEM_STATE_CHECK +#define _dbg_enter_lock() (ch.dbg_lock_cnt = 1) +#define _dbg_leave_lock() (ch.dbg_lock_cnt = 0) +#endif + +/* When the state checker feature is disabled then the following functions + are replaced by an empty macro.*/ +#if !CH_DBG_SYSTEM_STATE_CHECK +#define _dbg_enter_lock() +#define _dbg_leave_lock() +#define _dbg_check_disable() +#define _dbg_check_suspend() +#define _dbg_check_enable() +#define _dbg_check_lock() +#define _dbg_check_unlock() +#define _dbg_check_lock_from_isr() +#define _dbg_check_unlock_from_isr() +#define _dbg_check_enter_isr() +#define _dbg_check_leave_isr() +#define chDbgCheckClassI() +#define chDbgCheckClassS() +#endif + +/* When the trace feature is disabled this function is replaced by an empty + macro.*/ +#if !CH_DBG_ENABLE_TRACE +#define _dbg_trace(otp) +#endif + +/* When the debug features are disabled this function is replaced by an empty + macro.*/ +#if !CH_DBG_ENABLED +#define chDbgPanic(msg) {} +#endif + +/** + * @name Macro Functions + * @{ + */ +#if CH_DBG_ENABLE_CHECKS || defined(__DOXYGEN__) +/** + * @brief Function parameters check. + * @details If the condition check fails then the kernel panics and halts. + * @note The condition is tested only if the @p CH_DBG_ENABLE_CHECKS switch + * is specified in @p chconf.h else the macro does nothing. + * + * @param[in] c the condition to be verified to be true + * + * @api + */ +#if !defined(chDbgCheck) +#define chDbgCheck(c) { \ + if (!(c)) \ + chDbgPanic("C:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ +} +#endif /* !defined(chDbgCheck) */ + +#else /* !CH_DBG_ENABLE_CHECKS */ +#define chDbgCheck(c) {(void)(c);} +#endif /* !CH_DBG_ENABLE_CHECKS */ + +#if CH_DBG_ENABLE_ASSERTS || defined(__DOXYGEN__) +/** + * @brief Condition assertion. + * @details If the condition check fails then the kernel panics with a + * message and halts. + * @note The condition is tested only if the @p CH_DBG_ENABLE_ASSERTS switch + * is specified in @p chconf.h else the macro does nothing. + * @note The remark string is not currently used except for putting a + * comment in the code about the assertion. + * + * @param[in] c the condition to be verified to be true + * @param[in] r a remark string + * + * @api + */ +#if !defined(chDbgAssert) +#define chDbgAssert(c, r) { \ + if (!(c)) \ + chDbgPanic("A:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ +} +#endif /* !defined(chDbgAssert) */ +#else /* !CH_DBG_ENABLE_ASSERTS */ +#define chDbgAssert(c, r) {(void)(c);} +#endif /* !CH_DBG_ENABLE_ASSERTS */ +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif +#if CH_DBG_SYSTEM_STATE_CHECK + void _dbg_check_disable(void); + void _dbg_check_suspend(void); + void _dbg_check_enable(void); + void _dbg_check_lock(void); + void _dbg_check_unlock(void); + void _dbg_check_lock_from_isr(void); + void _dbg_check_unlock_from_isr(void); + void _dbg_check_enter_isr(void); + void _dbg_check_leave_isr(void); + void chDbgCheckClassI(void); + void chDbgCheckClassS(void); +#endif +#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) + void _trace_init(void); + void _dbg_trace(thread_t *otp); +#endif +#if CH_DBG_ENABLED + void chDbgPanic(const char *msg); +#endif +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* _CHDEBUG_H_ */ + +/** @} */ -- cgit v1.2.3 From 155ef8ed75b12442fde1d80e4ca880d0e7f7c1f1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Aug 2013 11:52:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6169 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 836645f07..c33d078d3 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -71,13 +71,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || \ - CH_DBG_ENABLE_STACK_CHECK || CH_DBG_SYSTEM_STATE_CHECK -#define CH_DBG_ENABLED TRUE -#else -#define CH_DBG_ENABLED FALSE -#endif - /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ @@ -159,12 +152,6 @@ typedef struct { #define _dbg_trace(otp) #endif -/* When the debug features are disabled this function is replaced by an empty - macro.*/ -#if !CH_DBG_ENABLED -#define chDbgPanic(msg) {} -#endif - /** * @name Macro Functions * @{ @@ -183,7 +170,7 @@ typedef struct { #if !defined(chDbgCheck) #define chDbgCheck(c) { \ if (!(c)) \ - chDbgPanic("C:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ + chSysHalt("C:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ } #endif /* !defined(chDbgCheck) */ @@ -209,7 +196,7 @@ typedef struct { #if !defined(chDbgAssert) #define chDbgAssert(c, r) { \ if (!(c)) \ - chDbgPanic("A:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ + chSysHalt("A:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ } #endif /* !defined(chDbgAssert) */ #else /* !CH_DBG_ENABLE_ASSERTS */ @@ -241,9 +228,6 @@ extern "C" { void _trace_init(void); void _dbg_trace(thread_t *otp); #endif -#if CH_DBG_ENABLED - void chDbgPanic(const char *msg); -#endif #ifdef __cplusplus } #endif -- cgit v1.2.3 From 52e34df5767ed023955d295cc118d92bb42cff46 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 19 Aug 2013 14:26:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6181 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index c33d078d3..ee49eec00 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -196,7 +196,7 @@ typedef struct { #if !defined(chDbgAssert) #define chDbgAssert(c, r) { \ if (!(c)) \ - chSysHalt("A:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ + chSysHalt("A:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ } #endif /* !defined(chDbgAssert) */ #else /* !CH_DBG_ENABLE_ASSERTS */ -- cgit v1.2.3 From 960847273c5015002fff1bb7c483556140746de2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 23 Aug 2013 07:57:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6205 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index ee49eec00..0fdc865eb 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -175,7 +175,7 @@ typedef struct { #endif /* !defined(chDbgCheck) */ #else /* !CH_DBG_ENABLE_CHECKS */ -#define chDbgCheck(c) {(void)(c);} +#define chDbgCheck(c) /*{(void)(c);}*/ #endif /* !CH_DBG_ENABLE_CHECKS */ #if CH_DBG_ENABLE_ASSERTS || defined(__DOXYGEN__) @@ -200,7 +200,7 @@ typedef struct { } #endif /* !defined(chDbgAssert) */ #else /* !CH_DBG_ENABLE_ASSERTS */ -#define chDbgAssert(c, r) {(void)(c);} +#define chDbgAssert(c, r) /*{(void)(c);}*/ #endif /* !CH_DBG_ENABLE_ASSERTS */ /** @} */ -- cgit v1.2.3 From ca516fd8e648681b1e729c0191604b10106f3f44 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 23 Sep 2013 13:03:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6314 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 0fdc865eb..63440e4ee 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -121,8 +121,6 @@ typedef struct { /* Module macros. */ /*===========================================================================*/ -#define __QUOTE_THIS(p) #p - #if CH_DBG_SYSTEM_STATE_CHECK #define _dbg_enter_lock() (ch.dbg_lock_cnt = 1) #define _dbg_leave_lock() (ch.dbg_lock_cnt = 0) @@ -170,12 +168,12 @@ typedef struct { #if !defined(chDbgCheck) #define chDbgCheck(c) { \ if (!(c)) \ - chSysHalt("C:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ + chSysHalt(__func__); \ } #endif /* !defined(chDbgCheck) */ #else /* !CH_DBG_ENABLE_CHECKS */ -#define chDbgCheck(c) /*{(void)(c);}*/ +#define chDbgCheck(c) {if (0) (void)(c);} #endif /* !CH_DBG_ENABLE_CHECKS */ #if CH_DBG_ENABLE_ASSERTS || defined(__DOXYGEN__) @@ -196,11 +194,11 @@ typedef struct { #if !defined(chDbgAssert) #define chDbgAssert(c, r) { \ if (!(c)) \ - chSysHalt("A:"__QUOTE_THIS(__FUNCTION__)":"__QUOTE_THIS(__LINE__)); \ + chSysHalt(__func__); \ } #endif /* !defined(chDbgAssert) */ #else /* !CH_DBG_ENABLE_ASSERTS */ -#define chDbgAssert(c, r) /*{(void)(c);}*/ +#define chDbgAssert(c, r) {if (0) (void)(c);} #endif /* !CH_DBG_ENABLE_ASSERTS */ /** @} */ -- cgit v1.2.3 From c0372b43443df18547157d289542db47bdd9599c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 23 Sep 2013 19:16:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6316 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 63440e4ee..98cb24e37 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -154,7 +154,6 @@ typedef struct { * @name Macro Functions * @{ */ -#if CH_DBG_ENABLE_CHECKS || defined(__DOXYGEN__) /** * @brief Function parameters check. * @details If the condition check fails then the kernel panics and halts. @@ -167,16 +166,11 @@ typedef struct { */ #if !defined(chDbgCheck) #define chDbgCheck(c) { \ - if (!(c)) \ - chSysHalt(__func__); \ + if (CH_DBG_ENABLE_CHECKS && !(c)) \ + chSysHalt(__func__); \ } #endif /* !defined(chDbgCheck) */ -#else /* !CH_DBG_ENABLE_CHECKS */ -#define chDbgCheck(c) {if (0) (void)(c);} -#endif /* !CH_DBG_ENABLE_CHECKS */ - -#if CH_DBG_ENABLE_ASSERTS || defined(__DOXYGEN__) /** * @brief Condition assertion. * @details If the condition check fails then the kernel panics with a @@ -193,13 +187,10 @@ typedef struct { */ #if !defined(chDbgAssert) #define chDbgAssert(c, r) { \ - if (!(c)) \ - chSysHalt(__func__); \ + if (CH_DBG_ENABLE_ASSERTS && !(c)) \ + chSysHalt(__func__); \ } #endif /* !defined(chDbgAssert) */ -#else /* !CH_DBG_ENABLE_ASSERTS */ -#define chDbgAssert(c, r) {if (0) (void)(c);} -#endif /* !CH_DBG_ENABLE_ASSERTS */ /** @} */ /*===========================================================================*/ -- cgit v1.2.3 From 191a1672e2f44f9d28d0bbf9d56ed4a22efec0a1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 24 Sep 2013 13:00:46 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6317 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 98cb24e37..6ae948bc3 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -165,10 +165,10 @@ typedef struct { * @api */ #if !defined(chDbgCheck) -#define chDbgCheck(c) { \ +#define chDbgCheck(c) do { \ if (CH_DBG_ENABLE_CHECKS && !(c)) \ chSysHalt(__func__); \ -} +} while (0) #endif /* !defined(chDbgCheck) */ /** @@ -186,10 +186,10 @@ typedef struct { * @api */ #if !defined(chDbgAssert) -#define chDbgAssert(c, r) { \ +#define chDbgAssert(c, r) do { \ if (CH_DBG_ENABLE_ASSERTS && !(c)) \ chSysHalt(__func__); \ -} +} while (0) #endif /* !defined(chDbgAssert) */ /** @} */ -- cgit v1.2.3 From 5a70ffdbf38323a58d2e1fa6289ad7caea1fe12a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 12 Nov 2013 11:05:57 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6464 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdebug.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'os/rt/include/chdebug.h') diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 6ae948bc3..44f44116f 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -71,6 +71,13 @@ /* Derived constants and error checks. */ /*===========================================================================*/ +#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || \ + CH_DBG_ENABLE_STACK_CHECK || CH_DBG_SYSTEM_STATE_CHECK +#define CH_DBG_ENABLED TRUE +#else +#define CH_DBG_ENABLED FALSE +#endif + /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ -- cgit v1.2.3