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
This commit is contained in:
gdisirio 2011-07-09 09:15:49 +00:00
parent a53bc3d266
commit b38e1f2c96
4 changed files with 36 additions and 37 deletions

View File

@ -32,15 +32,15 @@
/** /**
* @brief Trace buffer entries. * @brief Trace buffer entries.
*/ */
#ifndef TRACE_BUFFER_SIZE #ifndef CH_TRACE_BUFFER_SIZE
#define TRACE_BUFFER_SIZE 64 #define CH_TRACE_BUFFER_SIZE 64
#endif #endif
/** /**
* @brief Fill value for thread stack area in debug mode. * @brief Fill value for thread stack area in debug mode.
*/ */
#ifndef STACK_FILL_VALUE #ifndef CH_STACK_FILL_VALUE
#define STACK_FILL_VALUE 0x55 #define CH_STACK_FILL_VALUE 0x55
#endif #endif
/** /**
@ -50,39 +50,34 @@
* a debugger. A uninitialized field is not an error in itself but it * a debugger. A uninitialized field is not an error in itself but it
* better to know it. * better to know it.
*/ */
#ifndef THREAD_FILL_VALUE #ifndef CH_THREAD_FILL_VALUE
#define THREAD_FILL_VALUE 0xFF #define CH_THREAD_FILL_VALUE 0xFF
#endif #endif
#define __QUOTE_THIS(p) #p
#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__)
/** /**
* @brief Trace buffer record. * @brief Trace buffer record.
*/ */
typedef struct { typedef struct {
void *cse_wtobjp; /**< @brief Object where going to systime_t se_time; /**< @brief Time of the switch event. */
sleep. */ Thread *se_tp; /**< @brief Switched in thread. */
systime_t cse_time; /**< @brief Time of the switch void *se_wtobjp; /**< @brief Object where going to sleep.*/
event. */ uint8_t se_state; /**< @brief Switched out thread state. */
uint16_t cse_state: 4; /**< @brief Switched out thread } ch_swc_event_t;
state. */
uint16_t cse_tid: 12; /**< @brief Switched in thread id. */
} CtxSwcEvent;
/** /**
* @brief Trace buffer header. * @brief Trace buffer header.
*/ */
typedef struct { typedef struct {
unsigned tb_size; /**< @brief Trace buffer size unsigned tb_size; /**< @brief Trace buffer size (entries).*/
(entries). */ ch_swc_event_t *tb_ptr; /**< @brief Pointer to the buffer front.*/
CtxSwcEvent *tb_ptr; /**< @brief Pointer to the ring buffer
front. */
/** @brief Ring buffer.*/ /** @brief Ring buffer.*/
CtxSwcEvent tb_buffer[TRACE_BUFFER_SIZE]; ch_swc_event_t tb_buffer[CH_TRACE_BUFFER_SIZE];
} TraceBuffer; } ch_trace_buffer_t;
#endif /* CH_DBG_ENABLE_TRACE */ #endif /* CH_DBG_ENABLE_TRACE */
#define __QUOTE_THIS(p) #p
#if CH_DBG_ENABLE_CHECKS || defined(__DOXYGEN__) #if CH_DBG_ENABLE_CHECKS || defined(__DOXYGEN__)
/** /**
* @brief Function parameter check. * @brief Function parameter check.
@ -150,12 +145,12 @@ typedef struct {
extern "C" { extern "C" {
#endif #endif
#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__)
extern TraceBuffer trace_buffer; extern ch_trace_buffer_t ch_dbg_trace_buffer;
void _trace_init(void); void _trace_init(void);
void chDbgTrace(Thread *otp); void chDbgTrace(Thread *otp);
#endif #endif
#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
extern char *panic_msg; extern char *ch_dbg_panic_msg;
void chDbgPanic(char *msg); void chDbgPanic(char *msg);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -40,7 +40,7 @@
/** /**
* @brief Public trace buffer. * @brief Public trace buffer.
*/ */
TraceBuffer trace_buffer; ch_trace_buffer_t ch_dbg_trace_buffer;
/** /**
* @brief Trace circular buffer subsystem initialization. * @brief Trace circular buffer subsystem initialization.
@ -48,8 +48,8 @@ TraceBuffer trace_buffer;
*/ */
void _trace_init(void) { void _trace_init(void) {
trace_buffer.tb_size = TRACE_BUFFER_SIZE; ch_dbg_trace_buffer.tb_size = CH_TRACE_BUFFER_SIZE;
trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; 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) { void chDbgTrace(Thread *otp) {
trace_buffer.tb_ptr->cse_wtobjp = otp->p_u.wtobjp; ch_dbg_trace_buffer.tb_ptr->se_time = chTimeNow();
trace_buffer.tb_ptr->cse_time = chTimeNow(); ch_dbg_trace_buffer.tb_ptr->se_tp = currp;
trace_buffer.tb_ptr->cse_state = otp->p_state; ch_dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp;
trace_buffer.tb_ptr->cse_tid = (unsigned)currp >> 6; ch_dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state;
if (++trace_buffer.tb_ptr >= &trace_buffer.tb_buffer[TRACE_BUFFER_SIZE]) if (++ch_dbg_trace_buffer.tb_ptr >=
trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; &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 */ #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 * 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; char *ch_dbg_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.
@ -87,7 +88,7 @@ char *panic_msg;
*/ */
void chDbgPanic(char *msg) { void chDbgPanic(char *msg) {
panic_msg = msg; ch_dbg_panic_msg = msg;
chSysHalt(); chSysHalt();
} }
#endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */ #endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */

View File

@ -181,10 +181,10 @@ Thread *chThdCreateStatic(void *wsp, size_t size,
#if CH_DBG_FILL_THREADS #if CH_DBG_FILL_THREADS
_thread_memfill((uint8_t *)wsp, _thread_memfill((uint8_t *)wsp,
(uint8_t *)wsp + sizeof(Thread), (uint8_t *)wsp + sizeof(Thread),
THREAD_FILL_VALUE); CH_THREAD_FILL_VALUE);
_thread_memfill((uint8_t *)wsp + sizeof(Thread), _thread_memfill((uint8_t *)wsp + sizeof(Thread),
(uint8_t *)wsp + size, (uint8_t *)wsp + size,
STACK_FILL_VALUE); CH_STACK_FILL_VALUE);
#endif #endif
chSysLock(); chSysLock();
chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK); chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK);

View File

@ -84,6 +84,9 @@
(backported to 2.2.4). (backported to 2.2.4).
- FIX: Fixed timeout problem in the lwIP interface layer (bug 3302420) - FIX: Fixed timeout problem in the lwIP interface layer (bug 3302420)
(backported to 2.2.4). (backported to 2.2.4).
- NEW: Improvements to the trace buffer, now it stores a full thread pointer
and event time, changed names of debug variables by addin the "ch_dbg_"
prefix.
- NEW: Added a new functionality to the registry subsystem, now it is possible - NEW: Added a new functionality to the registry subsystem, now it is possible
to associate a name to the threads using chRegSetThreadName. The main and to associate a name to the threads using chRegSetThreadName. The main and
idle threads have their name assigned by default. idle threads have their name assigned by default.