6.3. shell — Debug shell

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

../../_images/shell.png

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


Functions

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.

Return
zero(0) or negative error code.

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

Initialize a shell with given parameters.

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>
drivers/
kernel/
$ kernel/ <tab>
fs/
sys/
thrd/
$ kernel/thrd/list
            NAME        STATE  PRIO   CPU  LOGMASK
            main      current     0    0%     0x0f
            idle        ready   127    0%     0x0f
         monitor        ready   -80    0%     0x0f
$

Return
Never returns.
Parameters
  • arg_p -

    Pointer to the shell arguemnt struct struct shell_args_t. See the struct definition for a description of it’s content.

struct shell_history_elem_t

Public Members

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

Public Members

char buf[CONFIG_SHELL_COMMAND_MAX]
int length
int cursor
struct shell_t

Public Members

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