Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/assert: halt running thread instead of panic #20627

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions core/lib/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,42 @@
#include "architecture.h"
#include "cpu.h"
#include "debug.h"
#include "irq.h"
#include "panic.h"
#if IS_USED(MODULE_BACKTRACE)
#include "backtrace.h"
#endif

__NORETURN void _assert_failure(const char *file, unsigned line)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architecture.h

__NORETURN static inline void _assert_common(void)
{
printf("%s:%u => ", file, line);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU.h

#if IS_USED(MODULE_BACKTRACE)
#ifdef DEBUG_ASSERT_VERBOSE
printf("failed assertion. Backtrace:\n");
#endif
backtrace_print();
#endif
#ifdef DEBUG_ASSERT_BREAKPOINT
DEBUG_BREAKPOINT(1);
#endif
if (DEBUG_ASSERT_NO_PANIC && !irq_is_in() && irq_is_enabled()) {
puts("FAILED ASSERTION.");
while (1) {
thread_sleep();
}
}
core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION.");
}

__NORETURN void _assert_failure(const char *file, unsigned line)
{
printf("%s:%u => ", file, line);
_assert_common();
}

__NORETURN void _assert_panic(void)
{
printf("%" PRIxTXTPTR "\n", cpu_get_caller_pc());
#if IS_USED(MODULE_BACKTRACE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug.h

backtrace_print();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irq.h

#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panic.h

#ifdef DEBUG_ASSERT_BREAKPOINT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module backtrace

DEBUG_BREAKPOINT(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backtrace.h

#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No return

core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irq.h

_assert_common();
}

/** @} */
9 changes: 9 additions & 0 deletions core/lib/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ __NORETURN void _assert_panic(void);
#endif
#endif

/**
* @brief Don't panic on a failed assertion, just halt the running thread.
*
* If the assertion failed in an interrupt, the system will still panic.
*/
#ifndef DEBUG_ASSERT_NO_PANIC
#define DEBUG_ASSERT_NO_PANIC (1)
#endif

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions examples/dtls-wolfssl/Makefile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ BOARD_INSUFFICIENT_MEMORY := \
nucleo-l031k6 \
nucleo-l053r8 \
nucleo-l412kb \
maple-mini \
olimexino-stm32 \
opencm904 \
samd10-xmini \
Expand Down