From 1ea7355d85e316aadfd90468b3e808bb3dc95ee9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Aug 2009 13:07:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1073 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 os/kernel/src/chdebug.c (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c new file mode 100644 index 000000000..9a8120b29 --- /dev/null +++ b/os/kernel/src/chdebug.c @@ -0,0 +1,81 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 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.c + * @brief ChibiOS/RT Debug code. + * @addtogroup Debug + * @{ + */ + +#include + +#if CH_DBG_ENABLE_TRACE +/** + * @brief Public trace buffer. + */ +TraceBuffer trace_buffer; + +/** + * @brief Trace circular buffer subsystem initialization. + */ +void trace_init(void) { + + trace_buffer.tb_size = TRACE_BUFFER_SIZE; + trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; +} + +/** + * @brief Inserts in the circular debug trace buffer a context switch record. + * + * @param[in] otp the thread being switched out + * @param[in] ntp the thread to be switched in + */ +void chDbgTrace(Thread *otp, Thread *ntp) { + + trace_buffer.tb_ptr->cse_wtobjp = otp->p_wtobjp; + trace_buffer.tb_ptr->cse_time = chTimeNow(); + trace_buffer.tb_ptr->cse_state = otp->p_state; + trace_buffer.tb_ptr->cse_tid = (unsigned)ntp >> 4; + if (++trace_buffer.tb_ptr >= &trace_buffer.tb_buffer[TRACE_BUFFER_SIZE]) + trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; +} +#endif /* CH_DBG_ENABLE_TRACE */ + +#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK +/** + * @brief Pointer to the panic message. + * @details This pointer is meant to be accessed through the debugger, it is + * written once and then the system is halted. + */ +char *panic_msg; + +/** + * @brief Prints a panic message on the console and then halts the system. + * + * @param[in] msg the pointer to the panic message string + */ +void chDbgPanic(char *msg) { + + panic_msg = msg; + chSysHalt(); +} +#endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */ + +/** @} */ -- cgit v1.2.3 From 397ccffac55ffd139d0e3e82add83e51413c1347 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 30 Aug 2009 06:59:43 +0000 Subject: Documentation reorganization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1133 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 9a8120b29..f5e6bef7a 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -20,7 +20,7 @@ /** * @file chdebug.c * @brief ChibiOS/RT Debug code. - * @addtogroup Debug + * @addtogroup debug * @{ */ -- cgit v1.2.3 From 2c41c0d442aa3cea412fba318d4fe0a7cfd276d6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 19 Oct 2009 18:33:53 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1241 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index f5e6bef7a..3049e03e7 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -62,7 +62,8 @@ void chDbgTrace(Thread *otp, Thread *ntp) { /** * @brief Pointer to the panic message. * @details This pointer is meant to be accessed through the debugger, it is - * written once and then the system is halted. + * written once and then the system is halted. This variable can be + * set to @p NULL if the halt is caused by a stack overflow. */ char *panic_msg; -- cgit v1.2.3 From bdb7f4ab20bd3daf261ab93dfe733e0ff11dca0f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 17:37:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1397 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 3049e03e7..4868090b5 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -24,7 +24,7 @@ * @{ */ -#include +#include "ch.h" #if CH_DBG_ENABLE_TRACE /** -- cgit v1.2.3 From f17db1931e95f5ebb42f557b6eead2bf1320db5a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Feb 2010 10:55:53 +0000 Subject: Reformatted doxygen tags into the kernel sources to make them more readable. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1567 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 4868090b5..8a5b58744 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -18,8 +18,9 @@ */ /** - * @file chdebug.c - * @brief ChibiOS/RT Debug code. + * @file chdebug.c + * @brief ChibiOS/RT Debug code. + * * @addtogroup debug * @{ */ @@ -28,12 +29,12 @@ #if CH_DBG_ENABLE_TRACE /** - * @brief Public trace buffer. + * @brief Public trace buffer. */ TraceBuffer trace_buffer; /** - * @brief Trace circular buffer subsystem initialization. + * @brief Trace circular buffer subsystem initialization. */ void trace_init(void) { @@ -42,10 +43,10 @@ void trace_init(void) { } /** - * @brief Inserts in the circular debug trace buffer a context switch record. + * @brief Inserts in the circular debug trace buffer a context switch record. * - * @param[in] otp the thread being switched out - * @param[in] ntp the thread to be switched in + * @param[in] otp the thread being switched out + * @param[in] ntp the thread to be switched in */ void chDbgTrace(Thread *otp, Thread *ntp) { @@ -60,7 +61,7 @@ void chDbgTrace(Thread *otp, Thread *ntp) { #if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK /** - * @brief Pointer to the panic message. + * @brief Pointer to the panic message. * @details This pointer is meant to be accessed through the debugger, it is * written once and then the system is halted. This variable can be * set to @p NULL if the halt is caused by a stack overflow. @@ -68,9 +69,9 @@ void chDbgTrace(Thread *otp, Thread *ntp) { char *panic_msg; /** - * @brief Prints a panic message on the console and then halts the system. + * @brief Prints a panic message on the console and then halts the system. * - * @param[in] msg the pointer to the panic message string + * @param[in] msg the pointer to the panic message string */ void chDbgPanic(char *msg) { -- cgit v1.2.3 From d9442768e2c56370801118cd719d7fa131066b39 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 12 Feb 2010 19:00:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1594 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 8a5b58744..38626387b 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -50,7 +50,7 @@ void trace_init(void) { */ void chDbgTrace(Thread *otp, Thread *ntp) { - trace_buffer.tb_ptr->cse_wtobjp = otp->p_wtobjp; + trace_buffer.tb_ptr->cse_wtobjp = otp->p_u.wtobjp; trace_buffer.tb_ptr->cse_time = chTimeNow(); trace_buffer.tb_ptr->cse_state = otp->p_state; trace_buffer.tb_ptr->cse_tid = (unsigned)ntp >> 4; -- cgit v1.2.3 From 157b6f9695e7f72f2d54b231c19cb4045710ed01 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Feb 2010 07:24:53 +0000 Subject: Updated license dates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1646 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 38626387b..ebe93e8a5 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -64,7 +64,7 @@ void chDbgTrace(Thread *otp, Thread *ntp) { * @brief Pointer to the panic message. * @details This pointer is meant to be accessed through the debugger, it is * written once and then the system is halted. This variable can be - * set to @p NULL if the halt is caused by a stack overflow. + * set to @p NULL if the halt is caused by a stack overflow. */ char *panic_msg; -- cgit v1.2.3 From 075b89133ec371480bdcf670d3f412b1cf131b0e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 14 Mar 2010 09:13:21 +0000 Subject: Performance optimization (not complete yet). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1739 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index ebe93e8a5..969718082 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -45,10 +45,10 @@ void trace_init(void) { /** * @brief Inserts in the circular debug trace buffer a context switch record. * - * @param[in] otp the thread being switched out * @param[in] ntp the thread to be switched in + * @param[in] otp the thread being switched out */ -void chDbgTrace(Thread *otp, Thread *ntp) { +void chDbgTrace(Thread *ntp, Thread *otp) { trace_buffer.tb_ptr->cse_wtobjp = otp->p_u.wtobjp; trace_buffer.tb_ptr->cse_time = chTimeNow(); -- cgit v1.2.3 From ad3d21e81592481539a56e93234f5bf1fa2c0504 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Mar 2010 19:36:21 +0000 Subject: Documentation reorganization. Moved the description from kernel.dox into the source code for ease of editing and reference. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1746 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 969718082..462f2559e 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -22,6 +22,11 @@ * @brief ChibiOS/RT Debug code. * * @addtogroup debug + * @details Debug APIs and services: + * - Trace buffer. + * - Parameters check. + * - Kernel assertions. + * . * @{ */ -- cgit v1.2.3 From e55b9dfdcb1a285aed416fc49d702b01e18de03f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Mar 2010 20:39:23 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1759 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 462f2559e..15a2f3e92 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -50,15 +50,14 @@ void trace_init(void) { /** * @brief Inserts in the circular debug trace buffer a context switch record. * - * @param[in] ntp the thread to be switched in * @param[in] otp the thread being switched out */ -void chDbgTrace(Thread *ntp, Thread *otp) { +void chDbgTrace(Thread *otp) { trace_buffer.tb_ptr->cse_wtobjp = otp->p_u.wtobjp; trace_buffer.tb_ptr->cse_time = chTimeNow(); trace_buffer.tb_ptr->cse_state = otp->p_state; - trace_buffer.tb_ptr->cse_tid = (unsigned)ntp >> 4; + trace_buffer.tb_ptr->cse_tid = (unsigned)currp >> 6; if (++trace_buffer.tb_ptr >= &trace_buffer.tb_buffer[TRACE_BUFFER_SIZE]) trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; } -- cgit v1.2.3 From 9ffea7e261ec4016d788abbbf7c4a6d3a78e0a04 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Sep 2010 06:48:56 +0000 Subject: Documentation improvements, renamed some event APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2179 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 15a2f3e92..dcf42c2b3 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -27,12 +27,15 @@ * - Parameters check. * - Kernel assertions. * . + * @pre In order to use the debug APIs the @p CH_DBG_ENABLE_TRACE, + * @p CH_DBG_ENABLE_ASSERTS, @p CH_DBG_ENABLE_CHECKS options must + * be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_DBG_ENABLE_TRACE +#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) /** * @brief Public trace buffer. */ @@ -40,6 +43,7 @@ TraceBuffer trace_buffer; /** * @brief Trace circular buffer subsystem initialization. + * @note Internal use only. */ void trace_init(void) { @@ -63,7 +67,8 @@ void chDbgTrace(Thread *otp) { } #endif /* CH_DBG_ENABLE_TRACE */ -#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK +#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || \ + CH_DBG_ENABLE_STACK_CHECK || defined(__DOXYGEN__) /** * @brief Pointer to the panic message. * @details This pointer is meant to be accessed through the debugger, it is -- cgit v1.2.3 From 07351222e6d0b6b3dcd4f50ecb18bc09e7402d1c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Sep 2010 10:22:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2184 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index dcf42c2b3..80323e183 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -55,6 +55,8 @@ void trace_init(void) { * @brief Inserts in the circular debug trace buffer a context switch record. * * @param[in] otp the thread being switched out + * + * @notapi */ void chDbgTrace(Thread *otp) { -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 80323e183..be98cd40b 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From f5ae2552307f20f3fa3d987591fa60576981ce3d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 Mar 2011 14:51:08 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2850 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index be98cd40b..3c3c34c70 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -46,7 +46,7 @@ TraceBuffer trace_buffer; * @brief Trace circular buffer subsystem initialization. * @note Internal use only. */ -void trace_init(void) { +void _trace_init(void) { trace_buffer.tb_size = TRACE_BUFFER_SIZE; trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; -- cgit v1.2.3 From b38e1f2c96ca1940f210be9ec2de6eeb076f1a10 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 9 Jul 2011 09:15:49 +0000 Subject: Improvements to the trace buffer and other debug features. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3139 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 3c3c34c70..208ac2a69 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -40,7 +40,7 @@ /** * @brief Public trace buffer. */ -TraceBuffer trace_buffer; +ch_trace_buffer_t ch_dbg_trace_buffer; /** * @brief Trace circular buffer subsystem initialization. @@ -48,8 +48,8 @@ TraceBuffer trace_buffer; */ void _trace_init(void) { - trace_buffer.tb_size = TRACE_BUFFER_SIZE; - trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; + ch_dbg_trace_buffer.tb_size = CH_TRACE_BUFFER_SIZE; + ch_dbg_trace_buffer.tb_ptr = &ch_dbg_trace_buffer.tb_buffer[0]; } /** @@ -61,12 +61,13 @@ void _trace_init(void) { */ void chDbgTrace(Thread *otp) { - trace_buffer.tb_ptr->cse_wtobjp = otp->p_u.wtobjp; - trace_buffer.tb_ptr->cse_time = chTimeNow(); - trace_buffer.tb_ptr->cse_state = otp->p_state; - trace_buffer.tb_ptr->cse_tid = (unsigned)currp >> 6; - if (++trace_buffer.tb_ptr >= &trace_buffer.tb_buffer[TRACE_BUFFER_SIZE]) - trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; + ch_dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); + ch_dbg_trace_buffer.tb_ptr->se_tp = currp; + ch_dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; + ch_dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; + if (++ch_dbg_trace_buffer.tb_ptr >= + &ch_dbg_trace_buffer.tb_buffer[CH_TRACE_BUFFER_SIZE]) + ch_dbg_trace_buffer.tb_ptr = &ch_dbg_trace_buffer.tb_buffer[0]; } #endif /* CH_DBG_ENABLE_TRACE */ @@ -78,7 +79,7 @@ void chDbgTrace(Thread *otp) { * written once and then the system is halted. This variable can be * set to @p NULL if the halt is caused by a stack overflow. */ -char *panic_msg; +char *ch_dbg_panic_msg; /** * @brief Prints a panic message on the console and then halts the system. @@ -87,7 +88,7 @@ char *panic_msg; */ void chDbgPanic(char *msg) { - panic_msg = msg; + ch_dbg_panic_msg = msg; chSysHalt(); } #endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */ -- cgit v1.2.3 From fbdd64538eb54452fd320e20eaba2fb094874a3e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Jul 2011 08:45:36 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3144 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 208ac2a69..0e378cc6d 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -40,7 +40,7 @@ /** * @brief Public trace buffer. */ -ch_trace_buffer_t ch_dbg_trace_buffer; +ch_trace_buffer_t dbg_trace_buffer; /** * @brief Trace circular buffer subsystem initialization. @@ -48,8 +48,8 @@ ch_trace_buffer_t ch_dbg_trace_buffer; */ void _trace_init(void) { - ch_dbg_trace_buffer.tb_size = CH_TRACE_BUFFER_SIZE; - ch_dbg_trace_buffer.tb_ptr = &ch_dbg_trace_buffer.tb_buffer[0]; + dbg_trace_buffer.tb_size = CH_TRACE_BUFFER_SIZE; + dbg_trace_buffer.tb_ptr = &dbg_trace_buffer.tb_buffer[0]; } /** @@ -61,13 +61,13 @@ void _trace_init(void) { */ void chDbgTrace(Thread *otp) { - ch_dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); - ch_dbg_trace_buffer.tb_ptr->se_tp = currp; - ch_dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; - ch_dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; - if (++ch_dbg_trace_buffer.tb_ptr >= - &ch_dbg_trace_buffer.tb_buffer[CH_TRACE_BUFFER_SIZE]) - ch_dbg_trace_buffer.tb_ptr = &ch_dbg_trace_buffer.tb_buffer[0]; + dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); + dbg_trace_buffer.tb_ptr->se_tp = currp; + dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; + dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; + if (++dbg_trace_buffer.tb_ptr >= + &dbg_trace_buffer.tb_buffer[CH_TRACE_BUFFER_SIZE]) + dbg_trace_buffer.tb_ptr = &dbg_trace_buffer.tb_buffer[0]; } #endif /* CH_DBG_ENABLE_TRACE */ @@ -79,7 +79,7 @@ void chDbgTrace(Thread *otp) { * written once and then the system is halted. This variable can be * set to @p NULL if the halt is caused by a stack overflow. */ -char *ch_dbg_panic_msg; +char *dbg_panic_msg; /** * @brief Prints a panic message on the console and then halts the system. @@ -88,7 +88,7 @@ char *ch_dbg_panic_msg; */ void chDbgPanic(char *msg) { - ch_dbg_panic_msg = msg; + dbg_panic_msg = msg; chSysHalt(); } #endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */ -- cgit v1.2.3 From b9933c2089f5f0cd93738ae9081c45fcf3df54b7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 11 Aug 2011 17:51:37 +0000 Subject: Implemented system state checker debug option, remove the option CH_USE_NESTED_LOCKS. Documentation improvements and fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3221 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 163 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 154 insertions(+), 9 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 0e378cc6d..28d4f7520 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -24,18 +24,161 @@ * * @addtogroup debug * @details Debug APIs and services: + * - Runtime system state and call protocol check. The following + * panic messages can be generated: + * - SV#1, misplaced @p chSysDisable(). + * - SV#2, misplaced @p chSysSuspend() + * - SV#3, misplaced @p chSysEnable(). + * - SV#4, misplaced @p chSysLock(). + * - SV#5, misplaced @p chSysUnlock(). + * - SV#6, misplaced @p chSysLockFromIsr(). + * - SV#7, misplaced @p chSysUnlockFromIsr(). + * - SV#8, misplaced @p CH_IRQ_PROLOGUE(). + * - SV#9, misplaced @p CH_IRQ_EPILOGUE(). + * . * - Trace buffer. * - Parameters check. * - Kernel assertions. + * - Kernel panics. * . - * @pre In order to use the debug APIs the @p CH_DBG_ENABLE_TRACE, - * @p CH_DBG_ENABLE_ASSERTS, @p CH_DBG_ENABLE_CHECKS options must - * be enabled in @p chconf.h. + * @note Stack checks are not implemented in this module but in the port + * layer in an architecture-dependent way. * @{ */ #include "ch.h" +/*===========================================================================*/ +/* System state checker related code and variables. */ +/*===========================================================================*/ + +#if CH_DBG_SYSTEM_STATE_CHECK || defined(__DOXYGEN__) + +/** + * @brief ISR nesting level. + */ +cnt_t dbg_isr_cnt; + +/** + * @brief Lock nesting level. + */ +cnt_t dbg_lock_cnt; + +/** + * @brief Guard code for @p chSysDisable(). + * + * @notapi + */ +void dbg_check_disable(void) { + + if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + chDbgPanic("SV#1"); +} + +/** + * @brief Guard code for @p chSysSuspend(). + * + * @notapi + */ +void dbg_check_suspend(void) { + + if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + chDbgPanic("SV#2"); +} + +/** + * @brief Guard code for @p chSysEnable(). + * + * @notapi + */ +void dbg_check_enable(void) { + + if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + chDbgPanic("SV#3"); +} + +/** + * @brief Guard code for @p chSysLock(). + * + * @notapi + */ +void dbg_check_lock(void) { + + if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + chDbgPanic("SV#4"); + dbg_lock_cnt = 1; +} + +/** + * @brief Guard code for @p chSysUnlock(). + * + * @notapi + */ +void dbg_check_unlock(void) { + + if ((dbg_isr_cnt != 0) || (dbg_lock_cnt <= 0)) + chDbgPanic("SV#5"); + dbg_lock_cnt = 0; +} + +/** + * @brief Guard code for @p chSysLockFromIsr(). + * + * @notapi + */ +void dbg_check_lock_from_isr(void) { + + if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt != 0)) + chDbgPanic("SV#6"); + dbg_lock_cnt = 1; +} + +/** + * @brief Guard code for @p chSysUnlockFromIsr(). + * + * @notapi + */ +void dbg_check_unlock_from_isr(void) { + + if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt <= 0)) + chDbgPanic("SV#7"); + dbg_lock_cnt = 0; +} + +/** + * @brief Guard code for @p CH_IRQ_PROLOGUE(). + * + * @notapi + */ +void dbg_check_enter_isr(void) { + + port_lock_from_isr(); + if (dbg_isr_cnt < 0) + chDbgPanic("SV#8"); + dbg_isr_cnt++; + port_unlock_from_isr(); +} + +/** + * @brief Guard code for @p CH_IRQ_EPILOGUE(). + * + * @notapi + */ +void dbg_check_leave_isr(void) { + + port_lock_from_isr(); + if (dbg_isr_cnt <= 0) + chDbgPanic("SV#9"); + dbg_isr_cnt--; + port_unlock_from_isr(); +} + +#endif /* CH_DBG_SYSTEM_STATE_CHECK */ + +/*===========================================================================*/ +/* Trace related code and variables. */ +/*===========================================================================*/ + #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) /** * @brief Public trace buffer. @@ -59,7 +202,7 @@ void _trace_init(void) { * * @notapi */ -void chDbgTrace(Thread *otp) { +void dbg_trace(Thread *otp) { dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); dbg_trace_buffer.tb_ptr->se_tp = currp; @@ -71,13 +214,15 @@ void chDbgTrace(Thread *otp) { } #endif /* CH_DBG_ENABLE_TRACE */ -#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || \ - CH_DBG_ENABLE_STACK_CHECK || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Panic related code and variables. */ +/*===========================================================================*/ + +#if CH_DBG_ENABLED || defined(__DOXYGEN__) /** * @brief Pointer to the panic message. * @details This pointer is meant to be accessed through the debugger, it is - * written once and then the system is halted. This variable can be - * set to @p NULL if the halt is caused by a stack overflow. + * written once and then the system is halted. */ char *dbg_panic_msg; @@ -91,6 +236,6 @@ void chDbgPanic(char *msg) { dbg_panic_msg = msg; chSysHalt(); } -#endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */ +#endif /* CH_DBG_ENABLED */ /** @} */ -- cgit v1.2.3 From 43752ee8d132fc57028a9ff15156c5bfcd81c013 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 12 Aug 2011 11:10:19 +0000 Subject: Extended state check to all kernel I-class and s-class APIs, corrected some test cases where call protocol rules were not strictly observerd. No the whole test suite pass with the state checker enabled. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3223 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 28d4f7520..8fd081c05 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -35,6 +35,8 @@ * - SV#7, misplaced @p chSysUnlockFromIsr(). * - SV#8, misplaced @p CH_IRQ_PROLOGUE(). * - SV#9, misplaced @p CH_IRQ_EPILOGUE(). + * - SV#10, misplaced I-class function. + * - SV#11, misplaced S-class function. * . * - Trace buffer. * - Parameters check. @@ -153,7 +155,7 @@ void dbg_check_unlock_from_isr(void) { void dbg_check_enter_isr(void) { port_lock_from_isr(); - if (dbg_isr_cnt < 0) + if ((dbg_isr_cnt < 0) || (dbg_lock_cnt != 0)) chDbgPanic("SV#8"); dbg_isr_cnt++; port_unlock_from_isr(); @@ -167,12 +169,40 @@ void dbg_check_enter_isr(void) { void dbg_check_leave_isr(void) { port_lock_from_isr(); - if (dbg_isr_cnt <= 0) + if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt != 0)) chDbgPanic("SV#9"); dbg_isr_cnt--; port_unlock_from_isr(); } +/** + * @brief I-class functions context check. + * @details Verifies that the system is in an appropriate state for invoking + * an I-class API function. A panic is generated if the state is + * not compatible. + * + * @api + */ +void chDbgCheckClassI(void) { + + if ((dbg_isr_cnt < 0) || (dbg_lock_cnt <= 0)) + chDbgPanic("SV#10"); +} + +/** + * @brief S-class functions context check. + * @details Verifies that the system is in an appropriate state for invoking + * an S-class API function. A panic is generated if the state is + * not compatible. + * + * @api + */ +void chDbgCheckClassS(void) { + + if ((dbg_isr_cnt != 0) || (dbg_lock_cnt <= 0)) + chDbgPanic("SV#11"); +} + #endif /* CH_DBG_SYSTEM_STATE_CHECK */ /*===========================================================================*/ -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 8fd081c05..8d38dcd6e 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From c6914081835f10258d873af8526ae405ffe5b25c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 17 Jun 2012 06:53:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4283 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 8d38dcd6e..0bee1b4ea 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -108,7 +108,7 @@ void dbg_check_lock(void) { if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) chDbgPanic("SV#4"); - dbg_lock_cnt = 1; + dbg_enter_lock(); } /** @@ -120,7 +120,7 @@ void dbg_check_unlock(void) { if ((dbg_isr_cnt != 0) || (dbg_lock_cnt <= 0)) chDbgPanic("SV#5"); - dbg_lock_cnt = 0; + dbg_leave_lock(); } /** @@ -132,7 +132,7 @@ void dbg_check_lock_from_isr(void) { if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt != 0)) chDbgPanic("SV#6"); - dbg_lock_cnt = 1; + dbg_enter_lock(); } /** @@ -144,7 +144,7 @@ void dbg_check_unlock_from_isr(void) { if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt <= 0)) chDbgPanic("SV#7"); - dbg_lock_cnt = 0; + dbg_leave_lock(); } /** -- cgit v1.2.3 From 2abe2c479f15f9b4c66af007461c1ab2e2626ee0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 23 Jun 2012 12:03:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4328 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 0bee1b4ea..55631481f 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -254,14 +254,14 @@ void dbg_trace(Thread *otp) { * @details This pointer is meant to be accessed through the debugger, it is * written once and then the system is halted. */ -char *dbg_panic_msg; +const char *dbg_panic_msg; /** * @brief Prints a panic message on the console and then halts the system. * * @param[in] msg the pointer to the panic message string */ -void chDbgPanic(char *msg) { +void chDbgPanic(const char *msg) { dbg_panic_msg = msg; chSysHalt(); -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chdebug.c') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 55631481f..c69ce8f3f 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3