6.4. shell — Debug shell

The shell is a command line interface where the user can execute various commands to control, debug and monitor its application.


The shell module has a few configuration variables that can be used to tailor the shell to the application requirements. Most noticeably is the configuration variable CONFIG_SHELL_MINIMAL. If set to 0 all the shell functionality is built; including tab completion, cursor movement, line editing and command history. If set to 1 only the minimal functionality is built; only including tab completion and line editing at the end of the line.

See Configuration for a list of all configuration variables.

Source code: src/oam/shell.h, src/oam/shell.c

Test code: tst/oam/shell/main.c

Test coverage: src/oam/shell.c

Example code: examples/shell/main.c


int shell_module_init(void)

Initialize the shell module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

zero(0) or negative error code.

int shell_init(struct shell_t *self_p, void *chin_p, void *chout_p, void *arg_p, const char *name_p, const char *username_p, const char *password_p)

Initialize a shell with given parameters.

  • chin_p: The shell input channel. The shell waits for commands on this channel.
  • chout_p: The shell output channel. The shell writes responses on this channel.
  • arg_p: User supplied argument passed to all commands.
  • name_p: The shell thread name.
  • username_p: Shell login username, or NULL if no username is required to use the shell.
  • password_p: Shell login password. This field is unused if username_p is NULL.

void *shell_main(void *arg_p)

The shell main function that listens for commands on the input channel and send response on the output channel. All received commands are passed to the debug file system function fs_call() for execution.

Here is an example of using the shell to list and execute debug file system commands.

$ <tab>
$ kernel/ <tab>
$ kernel/thrd/list
            NAME        STATE  PRIO   CPU  LOGMASK
            main      current     0    0%     0x0f
            idle        ready   127    0%     0x0f
         monitor        ready   -80    0%     0x0f

Never returns.
  • arg_p: Pointer to the shell arguemnt struct struct shell_args_t. See the struct definition for a description of it’s content.

#include <shell.h>

Public Members

struct shell_history_elem_t *shell_history_elem_t::next_p
struct shell_history_elem_t *shell_history_elem_t::prev_p
char shell_history_elem_t::buf[1]

Public Members

char shell_line_t::buf[CONFIG_SHELL_COMMAND_MAX]
int shell_line_t::length
int shell_line_t::cursor

Public Members

void *shell_t::chin_p
void *shell_t::chout_p
void *shell_t::arg_p
const char *shell_t::name_p
const char *shell_t::username_p
const char *shell_t::password_p
struct shell_line_t shell_t::line
struct shell_line_t shell_t::prev_line
int shell_t::carriage_return_received
int shell_t::newline_received
int shell_t::authorized
struct shell_history_elem_t *shell_t::head_p
struct shell_history_elem_t *shell_t::tail_p
struct shell_history_elem_t *shell_t::current_p
struct shell_line_t shell_t::pattern
struct shell_line_t shell_t::match
int shell_t::line_valid
struct circular_heap_t shell_t::heap
uint8_t shell_t::buf[CONFIG_SHELL_HISTORY_SIZE]
struct shell_t::@86::@87 shell_t::heap
struct shell_t::@86 shell_t::history