Skip to content

Commit

Permalink
[debugcommands][crash] add a variant for cortex-m
Browse files Browse the repository at this point in the history
Touching around address 0 doesn't cause a cortex-m device to crash, but
branching to an aligned address absolutely will.
  • Loading branch information
travisg committed Feb 26, 2024
1 parent 5249549 commit 74192ac
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/debugcommands/debugcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,14 @@ static int cmd_timeh(int argc, const console_cmd_args *argv) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
static int cmd_crash(int argc, const console_cmd_args *argv) {
#if ARCH_ARM && ARM_ONLY_THUMB
/* a branch directly to an aligned address should trigger a fault */
asm("bx %0":: "r"(0));
#else
/* should crash */
volatile uint32_t *ptr = (void *)1;
*ptr = 1;
#endif

/* if it didn't, panic the system */
panic("crash");
Expand Down

0 comments on commit 74192ac

Please sign in to comment.