ChibiOS 21.11.4
Checks and Assertions

Detailed Description

Debug APIs and services:

  • Runtime system state and call protocol check. The following panic messages can be generated:
    • SV#1, misplaced chSysDisable().
      • Called from an ISR.
      • Called from a critical zone.
    • SV#2, misplaced chSysSuspend()
      • Called from an ISR.
      • Called from a critical zone.
    • SV#3, misplaced chSysEnable().
      • Called from an ISR.
      • Called from a critical zone.
    • SV#4, misplaced chSysLock().
      • Called from an ISR.
      • Called from a critical zone.
    • SV#5, misplaced chSysUnlock().
      • Called from an ISR.
      • Not called from a critical zone.
    • SV#6, misplaced chSysLockFromISR().
      • Not called from an ISR.
      • Called from a critical zone.
    • SV#7, misplaced chSysUnlockFromISR().
      • Not called from an ISR.
      • Not called from a critical zone.
    • SV#8, misplaced CH_IRQ_PROLOGUE().
      • Not called at ISR begin.
      • Called from a critical zone.
    • SV#9, misplaced CH_IRQ_EPILOGUE().
    • SV#10, misplaced I-class function.
      • I-class function not called from within a critical zone.
    • SV#11, misplaced S-class function.
      • S-class function not called from within a critical zone.
      • Called from an ISR.
  • Parameters check.
  • Kernel assertions.
Note
Stack checks are not implemented in this module but in the port layer in an architecture-dependent way.
Collaboration diagram for Checks and Assertions:

Debug related settings

#define CH_DBG_STACK_FILL_VALUE   0x55
 Fill value for thread stack area in debug mode.

Macro Functions

#define chDbgCheck(c)
 Function parameters check.
#define chDbgAssert(c, r)
 Condition assertion.

Data Structures

struct  ch_system_debug
 System debug data structure. More...

Macros

#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()

Typedefs

typedef struct ch_system_debug system_debug_t
 System debug data structure.

Functions

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.
static void __dbg_object_init (system_debug_t *sdp)
 Debug support initialization.

Macro Definition Documentation

◆ __dbg_check_disable

void __dbg_check_disable ( )

Definition at line 90 of file chdebug.h.

Referenced by chSysDisable().

◆ __dbg_check_suspend

void __dbg_check_suspend ( )

Definition at line 91 of file chdebug.h.

Referenced by chSysSuspend().

◆ __dbg_check_enable

void __dbg_check_enable ( )

Definition at line 92 of file chdebug.h.

Referenced by chSysEnable().

◆ __dbg_check_lock

void __dbg_check_lock ( )

Definition at line 93 of file chdebug.h.

Referenced by chSysLock().

◆ __dbg_check_unlock

void __dbg_check_unlock ( )

Definition at line 94 of file chdebug.h.

Referenced by chSysUnlock().

◆ __dbg_check_lock_from_isr

void __dbg_check_lock_from_isr ( )

Definition at line 95 of file chdebug.h.

Referenced by chSysLockFromISR().

◆ __dbg_check_unlock_from_isr

void __dbg_check_unlock_from_isr ( )

Definition at line 96 of file chdebug.h.

Referenced by chSysUnlockFromISR().

◆ __dbg_check_enter_isr

void __dbg_check_enter_isr ( )

Definition at line 97 of file chdebug.h.

◆ __dbg_check_leave_isr

void __dbg_check_leave_isr ( )

Definition at line 98 of file chdebug.h.

◆ chDbgCheckClassI

◆ chDbgCheckClassS

◆ CH_DBG_STACK_FILL_VALUE

#define CH_DBG_STACK_FILL_VALUE   0x55

Fill value for thread stack area in debug mode.

Definition at line 47 of file chdebug.h.

Referenced by __thd_stackfill().

◆ chDbgCheck

#define chDbgCheck ( c)
Value:
do { \
/*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
if (unlikely(!(c))) { \
/*lint -restore*/ \
chSysHalt(__func__); \
} \
} \
} while (false)
#define CH_DBG_ENABLE_CHECKS
Debug option, parameters checks.
#define FALSE
Generic 'false' preprocessor boolean constant.
#define unlikely(x)
Marks a boolean expression as likely false.
Definition chearly.h:191

Function parameters 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
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 118 of file chdebug.h.

Referenced by chCacheObjectInit(), chCondBroadcastI(), chCondObjectInit(), chCondSignal(), chCondSignalI(), chCondWaitS(), chCondWaitTimeoutS(), chCoreAllocFromBaseI(), chCoreAllocFromTopI(), chEvtBroadcastFlagsI(), chEvtDispatch(), chEvtGetAndClearFlags(), chEvtGetAndClearFlagsI(), chEvtRegisterMaskWithFlags(), chEvtRegisterMaskWithFlagsI(), chEvtSignal(), chEvtSignalI(), chEvtUnregister(), chFifoObjectInitAligned(), chGuardedPoolLoadArray(), chHeapAllocAligned(), chHeapFree(), chHeapObjectInit(), chJobObjectInit(), chMBFetchI(), chMBFetchTimeoutS(), chMBObjectInit(), chMBPostAheadI(), chMBPostAheadTimeoutS(), chMBPostI(), chMBPostTimeoutS(), chMBResetI(), chMsgSend(), chMtxLockS(), chMtxObjectInit(), chMtxTryLockS(), chMtxUnlock(), chMtxUnlockS(), chPipeObjectInit(), chPipeReadTimeout(), chPipeReset(), chPipeWriteTimeout(), chPoolAllocI(), chPoolFreeI(), chPoolLoadArray(), chPoolObjectInitAligned(), chSchReadyI(), chSchReadyI(), chSemAddCounterI(), chSemObjectInit(), chSemResetWithMessageI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chThdCreateFromMemoryPool(), chThdCreateI(), chThdCreateStatic(), chThdCreateSuspendedI(), chThdDequeueAllI(), chThdDequeueNextI(), chThdEnqueueTimeoutS(), chThdSetPriority(), chThdSleepS(), chThdWait(), chTimeAddX(), chVTDoResetI(), chVTDoSetContinuousI(), chVTDoSetI(), dyn_create_object_heap(), dyn_create_object_pool(), dyn_find_object(), dyn_release_object_heap(), and dyn_release_object_pool().

◆ chDbgAssert

#define chDbgAssert ( c,
r )
Value:
do { \
/*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
if (unlikely(!(c))) { \
/*lint -restore*/ \
chSysHalt(__func__); \
} \
} \
} while (false)
#define CH_DBG_ENABLE_ASSERTS
Debug option, consistency checks.

Condition assertion.

If the condition check fails then the kernel panics with a 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 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]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 144 of file chdebug.h.

Referenced by __sch_ready_ahead(), __sch_ready_behind(), ch_dlist_insert(), chCacheGetObject(), chCacheReleaseObjectI(), chCondWaitS(), chCondWaitTimeoutS(), chEvtDispatch(), chFifoSendObject(), chFifoSendObjectAhead(), chFifoSendObjectAheadI(), chFifoSendObjectAheadS(), chFifoSendObjectI(), chFifoSendObjectS(), chHeapFree(), chInstanceObjectInit(), chJobDispatch(), chJobDispatchTimeout(), chJobPost(), chJobPostAhead(), chJobPostAheadI(), chJobPostAheadS(), chJobPostI(), chJobPostS(), chMsgGet(), chMsgRelease(), chMtxLockS(), chMtxTryLockS(), chMtxUnlock(), chMtxUnlockS(), chPoolAllocI(), chRegNextThread(), chSchGoSleepS(), chSchGoSleepTimeoutS(), chSchReadyI(), chSchWakeupS(), chSemAddCounterI(), chSemResetWithMessageI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chSysGetIdleThreadX(), chSysTimerHandlerI(), chSysUnlock(), chThdAddRef(), chThdCreate(), chThdCreateI(), chThdCreateStatic(), chThdCreateSuspended(), chThdDoDequeueNextI(), chThdDoDequeueNextI(), chThdEnqueueTimeoutS(), chThdExit(), chThdExitS(), chThdRelease(), chThdResumeI(), chThdResumeS(), chThdStart(), chThdStartI(), chThdSuspendS(), chThdSuspendTimeoutS(), chThdWait(), chTimeI2MS(), chTimeI2S(), chTimeI2US(), chTimeMS2I(), chTimeS2I(), chTimeStampDiffX(), chTimeUS2I(), chVTDoResetI(), chVTDoTickI(), chVTGetRemainingIntervalI(), chVTGetTimeStampI(), dyn_release_object_heap(), dyn_release_object_pool(), lru_get_last_s(), nil_ready_all(), vt_insert_first(), and vt_set_alarm().

Typedef Documentation

◆ system_debug_t

System debug data structure.

Function Documentation

◆ __dbg_check_disable()

void __dbg_check_disable ( void )

Guard code for chSysDisable().

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

Definition at line 112 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_suspend()

void __dbg_check_suspend ( void )

Guard code for chSysSuspend().

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

Definition at line 126 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_enable()

void __dbg_check_enable ( void )

Guard code for chSysEnable().

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

Definition at line 140 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_lock()

void __dbg_check_lock ( void )

Guard code for chSysLock().

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

Definition at line 154 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_unlock()

void __dbg_check_unlock ( void )

Guard code for chSysUnlock().

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

Definition at line 169 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_lock_from_isr()

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 184 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_unlock_from_isr()

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 199 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_check_enter_isr()

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 214 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, port_lock_from_isr(), port_unlock_from_isr(), and unlikely.

Here is the call graph for this function:

◆ __dbg_check_leave_isr()

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 231 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, port_lock_from_isr(), port_unlock_from_isr(), and unlikely.

Here is the call graph for this function:

◆ chDbgCheckClassI()

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 251 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ chDbgCheckClassS()

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 268 of file chdebug.c.

References chSysHalt(), currcore, ch_os_instance::dbg, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and unlikely.

Here is the call graph for this function:

◆ __dbg_object_init()

void __dbg_object_init ( system_debug_t * sdp)
inlinestatic

Debug support initialization.

Note
Internal use only.
Parameters
[out]sdppointer to the system_debug_t structure
Function Class:
Not an API, this function is for internal use only.

Definition at line 192 of file chdebug.h.

References ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, and ch_system_debug::panic_msg.

Referenced by chInstanceObjectInit().