Skip to content

Commit 10fe322

Browse files
committed
mbed_error: Print thread names
As part of this, don't show empty current thread info in non-RTOS build.
1 parent c3d0e2c commit 10fe322

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

platform/mbed_error.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,16 @@ mbed_error_status_t mbed_clear_all_errors(void)
270270
return status;
271271
}
272272

273+
static const char *name_or_unnamed(const char *name)
274+
{
275+
return name ? name : "<unnamed>";
276+
}
277+
273278
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
274279
/* Prints info of a thread(using osRtxThread_t struct)*/
275280
static void print_thread(const osRtxThread_t *thread)
276281
{
277-
mbed_error_printf("\nState: 0x%08X Entry: 0x%08X Stack Size: 0x%08X Mem: 0x%08X SP: 0x%08X", thread->state, thread->thread_addr, thread->stack_size, (uint32_t)thread->stack_mem, thread->sp);
282+
mbed_error_printf("\n%s State: 0x%X Entry: 0x%08X Stack Size: 0x%08X Mem: 0x%08X SP: 0x%08X", name_or_unnamed(thread->name), thread->state, thread->thread_addr, thread->stack_size, (uint32_t)thread->stack_mem, thread->sp);
278283
}
279284

280285
/* Prints thread info from a list */
@@ -348,8 +353,11 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
348353
#endif
349354

350355
mbed_error_printf("\nError Value: 0x%X", ctx->error_value);
351-
mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X ",
356+
#ifdef MBED_CONF_RTOS_PRESENT
357+
mbed_error_printf("\nCurrent Thread: %s Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X ",
358+
name_or_unnamed(((osRtxThread_t *)ctx->thread_id)->name),
352359
ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
360+
#endif
353361

354362
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
355363
mbed_error_printf("\nNext:");

0 commit comments

Comments
 (0)