6.5. 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_t. See the struct definition for a description of it’s content.

struct shell_history_elem_t
#include <shell.h>

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

int length
int cursor
struct shell_t

Public Members

void *chin_p
void *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
struct shell_t::@114::@115 shell_t::heap
struct shell_t::@114 shell_t::history