Skip to content

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

Merged
benpicco merged 3 commits intoRIOT-OS:masterfrom
benpicco:assert-zombi
Apr 29, 2024
Merged

core/assert: halt running thread instead of panic#20627
benpicco merged 3 commits intoRIOT-OS:masterfrom
benpicco:assert-zombi

Conversation

@benpicco
Copy link
Copy Markdown
Contributor

@benpicco benpicco commented Apr 26, 2024

Contribution description

Instead of taking down the whole system, just kill the running thread.

Testing procedure

Add an assert(0) somewhere.

Issues/PRs references

fixes #20626

@benpicco benpicco requested a review from kaspar030 as a code owner April 26, 2024 12:17
@github-actions github-actions bot added the Area: core Area: RIOT kernel. Handle PRs marked with this with care! label Apr 26, 2024
@benpicco benpicco requested review from MrKevinWeiss and chrysn April 26, 2024 12:23
* If the assertion failed in an interrupt, the system will still panic.
*/
#ifndef DEBUG_ASSERT_ZOMBIFY
#define DEBUG_ASSERT_ZOMBIFY (1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#define DEBUG_ASSERT_ZOMBIFY (1)
# define DEBUG_ASSERT_ZOMBIFY (0)

Maybe not change the default to avoid the API change discussion here to get this feature in quickly, and change the default in a follow up PR and let the discussion unfold there?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have a pattern of including useful features that are just not used because people don't know they exist, or don't turn them on manually all the time (eg. MOST_RECENT_PORT=1), I'd rather not make this one of them.

If there is any pushback on the API change and this makes it faster, fine. If not, let's not hurry to comply with non-requirements.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, then let's quickly merge this before there is a large discussion 👿

@maribu maribu enabled auto-merge April 26, 2024 13:31
@maribu maribu added the Process: needs >1 ACK Integration Process: This PR requires more than one ACK label Apr 26, 2024
@github-actions github-actions bot added the Process: missing approvals Integration Process: PR needs more ACKS (handled by action) label Apr 26, 2024
@benpicco benpicco changed the title core/assert: zombify running thread instead of panic core/assert: halt running thread instead of panic Apr 26, 2024
@chrysn chrysn added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 27, 2024
@riot-ci
Copy link
Copy Markdown

riot-ci commented Apr 27, 2024

Murdock results

✔️ PASSED

a28e98b examples/dtls-wolfssl: add maple-mini to Makefile.ci

Success Failures Total Runtime
10059 0 10063 14m:58s

Artifacts

Copy link
Copy Markdown
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.

Tested using this change

diff --git a/examples/gcoap/server.c b/examples/gcoap/server.c
index bf2315cd01..e10885a6b6 100644
--- a/examples/gcoap/server.c
+++ b/examples/gcoap/server.c
@@ -151,2 +151,4 @@ static ssize_t _riot_board_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, co
 
+    assert(0);
+
     /* write the RIOT board name in the response buffer */

and by CoAP requesting .well-known/core (works), /riot/board (causes the panic), and while CoAP is down, the shell still works.

I've pushed a check for a missing include (irq.h, failed to build on native), please confirm and squash.

@github-actions github-actions bot removed the Process: missing approvals Integration Process: PR needs more ACKS (handled by action) label Apr 27, 2024
@maribu maribu added this pull request to the merge queue Apr 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 28, 2024
@maribu
Copy link
Copy Markdown
Member

maribu commented Apr 28, 2024

Looks like some Makefile.cis are in need of bumping

Copy link
Copy Markdown

@Tanyajackson638 Tanyajackson638 left a comment

Choose a reason for hiding this comment

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

core/lib/include/assert.h
core/lib/assert.c

#include "backtrace.h"
#endif

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

Choose a reason for hiding this comment

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

Architecture.h

__NORETURN void _assert_failure(const char *file, unsigned line)
__NORETURN static inline void _assert_common(void)
{
printf("%s:%u => ", file, line);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CPU.h

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

Choose a reason for hiding this comment

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

Debug.h

{
printf("%" PRIxTXTPTR "\n", cpu_get_caller_pc());
#if IS_USED(MODULE_BACKTRACE)
backtrace_print();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Irq.h

printf("%" PRIxTXTPTR "\n", cpu_get_caller_pc());
#if IS_USED(MODULE_BACKTRACE)
backtrace_print();
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Panic.h

#if IS_USED(MODULE_BACKTRACE)
backtrace_print();
#endif
#ifdef DEBUG_ASSERT_BREAKPOINT
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Module backtrace

backtrace_print();
#endif
#ifdef DEBUG_ASSERT_BREAKPOINT
DEBUG_BREAKPOINT(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Backtrace.h

#endif
#ifdef DEBUG_ASSERT_BREAKPOINT
DEBUG_BREAKPOINT(1);
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No return

#ifdef DEBUG_ASSERT_BREAKPOINT
DEBUG_BREAKPOINT(1);
#endif
core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Irq.h

@maribu
Copy link
Copy Markdown
Member

maribu commented Apr 29, 2024

core/lib/include/assert.h
core/lib/assert.c

@Tanyajackson638 Could you please explain with a few words what you want to say regarding every single comment above? I think in most cases it coule be something like "missing include of ...", but in some of the cases this does not make sense.

Just to be sure: You are a human and not a bot, right?

@github-actions github-actions bot added the Area: examples Area: Example Applications label Apr 29, 2024
@benpicco
Copy link
Copy Markdown
Contributor Author

Weird that DEBUG_ASSERT_NO_PANIC adds 116 bytes of text

@benpicco benpicco enabled auto-merge April 29, 2024 09:02
@benpicco benpicco added this pull request to the merge queue Apr 29, 2024
Merged via the queue into RIOT-OS:master with commit 6c15495 Apr 29, 2024
@benpicco benpicco deleted the assert-zombi branch April 29, 2024 12:33
@maribu
Copy link
Copy Markdown
Member

maribu commented Apr 30, 2024

@Tanyajackson638 Just to be sure: We were unable to understand your review. (To be honest it left me so puzzled I wouldn't be surprised if your review would be the result of a bot/script behaving unexpectedly.)

If you do have any concerns or questions regarding this PR, please voice them here and we will try our best to address them.

@benpicco benpicco requested a review from kfessel May 6, 2024 10:58
@mguetschow mguetschow added this to the Release 2024.07 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: examples Area: Example Applications CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs >1 ACK Integration Process: This PR requires more than one ACK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High-level stdio is not beginner friendly when they use asserts

6 participants