ChibiOS/RT
2.5.1
Debug
Collaboration diagram for Debug:

Detailed Description

Debug APIs and services:

Note:
Stack checks are not implemented in this module but in the port layer in an architecture-dependent way.

Data Structures

struct  ch_swc_event_t
 Trace buffer record. More...
struct  ch_trace_buffer_t
 Trace buffer header. More...

Functions

void _trace_init (void)
 Trace circular buffer subsystem initialization.
void dbg_trace (Thread *otp)
 Inserts in the circular debug trace buffer a context switch record.
void dbg_check_disable (void)
 Guard code for chSysDisable().
void dbg_check_suspend (void)
 Guard code for chSysSuspend().
void dbg_check_enable (void)
 Guard code for chSysEnable().
void dbg_check_lock (void)
 Guard code for chSysLock().
void dbg_check_unlock (void)
 Guard code for chSysUnlock().
void dbg_check_lock_from_isr (void)
 Guard code for chSysLockFromIsr().
void dbg_check_unlock_from_isr (void)
 Guard code for chSysUnlockFromIsr().
void dbg_check_enter_isr (void)
 Guard code for CH_IRQ_PROLOGUE().
void dbg_check_leave_isr (void)
 Guard code for CH_IRQ_EPILOGUE().
void chDbgCheckClassI (void)
 I-class functions context check.
void chDbgCheckClassS (void)
 S-class functions context check.
void chDbgPanic (const char *msg)
 Prints a panic message on the console and then halts the system.

Variables

cnt_t dbg_isr_cnt
 ISR nesting level.
cnt_t dbg_lock_cnt
 Lock nesting level.
ch_trace_buffer_t dbg_trace_buffer
 Public trace buffer.
const char * dbg_panic_msg
 Pointer to the panic message.

Debug related settings

#define CH_TRACE_BUFFER_SIZE   64
 Trace buffer entries.
#define CH_STACK_FILL_VALUE   0x55
 Fill value for thread stack area in debug mode.
#define CH_THREAD_FILL_VALUE   0xFF
 Fill value for thread area in debug mode.

Macro Functions

#define chDbgCheck(c, func)
 Function parameter check.
#define chDbgAssert(c, m, r)
 Condition assertion.

Function Documentation

void _trace_init ( void  )

Trace circular buffer subsystem initialization.

Note:
Internal use only.

Definition at line 222 of file chdebug.c.

References CH_TRACE_BUFFER_SIZE, ch_trace_buffer_t::tb_buffer, ch_trace_buffer_t::tb_ptr, and ch_trace_buffer_t::tb_size.

Referenced by chSysInit().

void dbg_trace ( Thread otp)

Inserts in the circular debug trace buffer a context switch record.

Parameters:
[in]otpthe thread being switched out
Function Class:
Not an API, this function is for internal use only.

Definition at line 235 of file chdebug.c.

References CH_TRACE_BUFFER_SIZE, chTimeNow, currp, Thread::p_state, ch_swc_event_t::se_state, ch_swc_event_t::se_time, ch_swc_event_t::se_tp, ch_swc_event_t::se_wtobjp, ch_trace_buffer_t::tb_buffer, ch_trace_buffer_t::tb_ptr, and Thread::wtobjp.

void dbg_check_disable ( void  )

Guard code for chSysDisable().

Function Class:
Not an API, this function is for internal use only.

Definition at line 74 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_suspend ( void  )

Guard code for chSysSuspend().

Function Class:
Not an API, this function is for internal use only.

Definition at line 85 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_enable ( void  )

Guard code for chSysEnable().

Function Class:
Not an API, this function is for internal use only.

Definition at line 96 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_lock ( void  )

Guard code for chSysLock().

Function Class:
Not an API, this function is for internal use only.

Definition at line 107 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_unlock ( void  )

Guard code for chSysUnlock().

Function Class:
Not an API, this function is for internal use only.

Definition at line 119 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_lock_from_isr ( void  )

Guard code for chSysLockFromIsr().

Function Class:
Not an API, this function is for internal use only.

Definition at line 131 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_unlock_from_isr ( void  )

Guard code for chSysUnlockFromIsr().

Function Class:
Not an API, this function is for internal use only.

Definition at line 143 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Here is the call graph for this function:

void dbg_check_enter_isr ( void  )

Guard code for CH_IRQ_PROLOGUE().

Function Class:
Not an API, this function is for internal use only.

Definition at line 155 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, dbg_lock_cnt, port_lock_from_isr, and port_unlock_from_isr.

Here is the call graph for this function:

void dbg_check_leave_isr ( void  )

Guard code for CH_IRQ_EPILOGUE().

Function Class:
Not an API, this function is for internal use only.

Definition at line 169 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, dbg_lock_cnt, port_lock_from_isr, and port_unlock_from_isr.

Here is the call graph for this function:

void chDbgCheckClassI ( void  )

I-class functions context check.

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.

Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 186 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Referenced by chCondBroadcastI(), chCondSignalI(), chCoreAllocI(), chEvtBroadcastFlagsI(), chEvtSignalI(), chIQPutI(), chIQResetI(), chMBFetchI(), chMBPostAheadI(), chMBPostI(), chOQGetI(), chOQResetI(), chPoolAllocI(), chPoolFreeI(), chSchReadyI(), chSemAddCounterI(), chSemResetI(), chSemSignalI(), chSysTimerHandlerI(), chThdCreateI(), chVTResetI(), and chVTSetI().

Here is the call graph for this function:

void chDbgCheckClassS ( void  )

S-class functions context check.

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.

Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 200 of file chdebug.c.

References chDbgPanic(), dbg_isr_cnt, and dbg_lock_cnt.

Referenced by chCondWaitS(), chCondWaitTimeoutS(), chMBFetchS(), chMBPostAheadS(), chMBPostS(), chMtxLockS(), chMtxTryLockS(), chMtxUnlockS(), chSchGoSleepS(), chSchGoSleepTimeoutS(), chSchRescheduleS(), chSchWakeupS(), chSemWaitS(), and chSemWaitTimeoutS().

Here is the call graph for this function:

void chDbgPanic ( const char *  msg)

Prints a panic message on the console and then halts the system.

Parameters:
[in]msgthe pointer to the panic message string

Definition at line 264 of file chdebug.c.

References chSysHalt, and dbg_panic_msg.

Referenced by chDbgCheckClassI(), chDbgCheckClassS(), dbg_check_disable(), dbg_check_enable(), dbg_check_enter_isr(), dbg_check_leave_isr(), dbg_check_lock(), dbg_check_lock_from_isr(), dbg_check_suspend(), dbg_check_unlock(), and dbg_check_unlock_from_isr().


Variable Documentation

Public trace buffer.

Definition at line 216 of file chdebug.c.

const char* dbg_panic_msg

Pointer to the panic message.

This pointer is meant to be accessed through the debugger, it is written once and then the system is halted.

Definition at line 257 of file chdebug.c.

Referenced by chDbgPanic().


Define Documentation

#define CH_TRACE_BUFFER_SIZE   64

Trace buffer entries.

Definition at line 52 of file chdebug.h.

Referenced by _trace_init(), and dbg_trace().

#define CH_STACK_FILL_VALUE   0x55

Fill value for thread stack area in debug mode.

Definition at line 59 of file chdebug.h.

Referenced by chThdCreateFromHeap(), chThdCreateFromMemoryPool(), and chThdCreateStatic().

#define CH_THREAD_FILL_VALUE   0xFF

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.

Definition at line 70 of file chdebug.h.

Referenced by chThdCreateFromHeap(), chThdCreateFromMemoryPool(), and chThdCreateStatic().

#define chDbgCheck (   c,
  func 
)
Value:
{                                               \
  if (!(c))                                                                 \
    chDbgPanic(__QUOTE_THIS(func)"()");                                     \
}

Function parameter check.

If the condition check fails then the kernel panics and halts.

Note:
The condition is tested only if the CH_DBG_ENABLE_CHECKS switch is specified in chconf.h else the macro does nothing.
Parameters:
[in]cthe condition to be verified to be true
[in]functhe undecorated function name
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 156 of file chdebug.h.

Referenced by chCondBroadcastI(), chCondInit(), chCondSignal(), chCondSignalI(), chCondWaitS(), chCondWaitTimeoutS(), chEvtBroadcastFlagsI(), chEvtDispatch(), chEvtRegisterMask(), chEvtSignal(), chEvtSignalI(), chEvtUnregister(), chHeapFree(), chHeapInit(), chIQReadTimeout(), chMBFetchI(), chMBFetchS(), chMBInit(), chMBPostAheadI(), chMBPostAheadS(), chMBPostI(), chMBPostS(), chMBReset(), chMsgSend(), chMtxInit(), chMtxLockS(), chMtxTryLockS(), chOQWriteTimeout(), chPoolAllocI(), chPoolFreeI(), chPoolInit(), chPoolLoadArray(), chSemAddCounterI(), chSemInit(), chSemResetI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chThdCreateFromMemoryPool(), chThdCreateI(), chThdSetPriority(), chThdSleep(), chThdWait(), chVTResetI(), and chVTSetI().

#define chDbgAssert (   c,
  m,
 
)
Value:
{                                              \
  if (!(c))                                                                 \
    chDbgPanic(m);                                                          \
}

Condition assertion.

If the condition check fails then the kernel panics with the specified message and halts.

Note:
The condition is tested only if the CH_DBG_ENABLE_ASSERTS switch is specified in chconf.h else the macro does nothing.
The convention for the message is the following:
<function_name>(), #<assert_number>
The remark string is not currently used except for putting a comment in the code about the assertion.
Parameters:
[in]cthe condition to be verified to be true
[in]mthe text message
[in]ra remark string
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 195 of file chdebug.h.

Referenced by chCondWaitS(), chCondWaitTimeoutS(), chEvtDispatch(), chHeapFree(), chMsgRelease(), chMtxLockS(), chMtxUnlock(), chMtxUnlockS(), chRegNextThread(), chSchReadyI(), chSemAddCounterI(), chSemResetI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chThdAddRef(), chThdExitS(), chThdRelease(), chThdResume(), chThdWait(), and chVTResetI().