diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c index 4f0177dab09..52a5c47a9b0 100644 --- a/subsys/shell/modules/kernel_service.c +++ b/subsys/shell/modules/kernel_service.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #define SHELL_KERNEL "kernel" @@ -48,32 +49,39 @@ static int shell_cmd_cycles(int argc, char *argv[]) } #if defined(CONFIG_OBJECT_TRACING) && defined(CONFIG_THREAD_MONITOR) +static void shell_tdata_dump(const struct k_thread *thread, void *user_data) +{ + printk("%s%p: options: 0x%x priority: %d\n", + (thread == k_current_get()) ? "*" : " ", + thread, + thread->base.user_options, + thread->base.prio); +} + static int shell_cmd_threads(int argc, char *argv[]) { ARG_UNUSED(argc); ARG_UNUSED(argv); - struct k_thread *thread_list = NULL; printk("Threads:\n"); + k_thread_foreach(shell_tdata_dump, NULL); - thread_list = (struct k_thread *)SYS_THREAD_MONITOR_HEAD; - while (thread_list != NULL) { - printk("%s%p: options: 0x%x priority: %d\n", - (thread_list == k_current_get()) ? "*" : " ", - thread_list, - thread_list->base.user_options, - k_thread_priority_get(thread_list)); - thread_list = (struct k_thread *)SYS_THREAD_MONITOR_NEXT(thread_list); - } return 0; } #endif -#if defined(CONFIG_INIT_STACKS) +#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_MONITOR) \ + && defined(CONFIG_THREAD_STACK_INFO) +static void shell_stack_dump(const struct k_thread *thread, void *user_data) +{ + stack_analyze((char *)user_data, (char *)thread->stack_info.start, + thread->stack_info.size); +} + static int shell_cmd_stack(int argc, char *argv[]) { - k_call_stacks_analyze(); + k_thread_foreach(shell_stack_dump, "Shell"); return 0; } #endif @@ -107,7 +115,8 @@ struct shell_cmd kernel_commands[] = { #if defined(CONFIG_OBJECT_TRACING) && defined(CONFIG_THREAD_MONITOR) { "threads", shell_cmd_threads, "show running threads" }, #endif -#if defined(CONFIG_INIT_STACKS) +#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_MONITOR) \ + && defined(CONFIG_THREAD_STACK_INFO) { "stacks", shell_cmd_stack, "show system stacks" }, #endif #if defined(CONFIG_REBOOT)