Skip to content

Commit b757110

Browse files
Jakub Rzeszutkonashif
authored andcommitted
shell: fix assert in panic mode
In panic mode, the function: z_shell_fprintf is expected to be called from an interrupt context. Therefore, the dedicated assert cannot be checked in this case. Fixes #38612 Signed-off-by: Jakub Rzeszutko <[email protected]>
1 parent 6173013 commit b757110

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

include/shell/shell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ struct shell_flags {
629629
uint32_t last_nl :8; /*!< Last received new line character */
630630
uint32_t cmd_ctx :1; /*!< Shell is executing command */
631631
uint32_t print_noinit:1; /*!< Print request from not initialized shell*/
632+
uint32_t panic_mode :1; /*!< Shell in panic mode */
632633
};
633634

634635
BUILD_ASSERT((sizeof(struct shell_flags) == sizeof(uint32_t)),

subsys/shell/shell_log_backend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static void panic(const struct log_backend *const backend)
289289
if (err == 0) {
290290
shell->log_backend->control_block->state =
291291
SHELL_LOG_BACKEND_PANIC;
292+
z_flag_panic_mode_set(shell, true);
292293

293294
/* Move to the start of next line. */
294295
z_shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons,

subsys/shell/shell_ops.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,19 +479,20 @@ void z_shell_vfprintf(const struct shell *shell, enum shell_vt100_color color,
479479
}
480480
}
481481

482-
void z_shell_fprintf(const struct shell *shell,
483-
enum shell_vt100_color color,
484-
const char *fmt, ...)
485-
{
486-
__ASSERT_NO_MSG(shell);
487-
__ASSERT(!k_is_in_isr(), "Thread context required.");
488-
__ASSERT_NO_MSG(shell->ctx);
489-
__ASSERT_NO_MSG(shell->fprintf_ctx);
482+
void z_shell_fprintf(const struct shell *sh,
483+
enum shell_vt100_color color,
484+
const char *fmt, ...)
485+
{
486+
__ASSERT_NO_MSG(sh);
487+
__ASSERT_NO_MSG(sh->ctx);
488+
__ASSERT_NO_MSG(sh->fprintf_ctx);
490489
__ASSERT_NO_MSG(fmt);
490+
__ASSERT(z_flag_panic_mode_get(sh) || !k_is_in_isr(),
491+
"Thread context required.");
491492

492493
va_list args;
493494

494495
va_start(args, fmt);
495-
z_shell_vfprintf(shell, color, fmt, args);
496+
z_shell_vfprintf(sh, color, fmt, args);
496497
va_end(args);
497498
}

subsys/shell/shell_ops.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ static inline bool z_flag_print_noinit_set(const struct shell *shell, bool val)
219219
return ret;
220220
}
221221

222+
static inline bool z_flag_panic_mode_get(const struct shell *sh)
223+
{
224+
return sh->ctx->internal.flags.panic_mode == 1;
225+
}
226+
227+
static inline bool z_flag_panic_mode_set(const struct shell *sh, bool val)
228+
{
229+
bool ret;
230+
231+
Z_SHELL_SET_FLAG_ATOMIC(sh, panic_mode, val, ret);
232+
return ret;
233+
}
234+
222235
void z_shell_op_cursor_vert_move(const struct shell *shell, int32_t delta);
223236
void z_shell_op_cursor_horiz_move(const struct shell *shell, int32_t delta);
224237

0 commit comments

Comments
 (0)