OpenOCD
|
Go to the source code of this file.
Data Structures | |
struct | command |
struct | command_context |
struct | command_invocation |
When run_command is called, a new instance will be created on the stack, filled with the proper values, and passed by reference to the required COMMAND_HANDLER routine. More... | |
struct | command_registration |
Macros | |
#define | __COMMAND_HANDLER(name, extra ...) int name(struct command_invocation *cmd, ## extra) |
Command handlers may be defined with more parameters than the base set provided by command.c. More... | |
#define | CALL_COMMAND_HANDLER(name, extra ...) name(cmd, ## extra) |
Use this to macro to call a command helper (or a nested handler). More... | |
#define | CMD (cmd) |
Use this macro to access the command being handled, rather than accessing the variable directly. More... | |
#define | CMD_ARGC (cmd->argc) |
Use this macro to access the number of arguments for the command being handled, rather than accessing the variable directly. More... | |
#define | CMD_ARGV (cmd->argv) |
Use this macro to access the arguments for the command being handled, rather than accessing the variable directly. More... | |
#define | CMD_CTX (cmd->ctx) |
Use this macro to access the context of the command being handled, rather than accessing the variable directly. More... | |
#define | CMD_CURRENT (cmd->current) |
Use this macro to access the current command being handled, rather than accessing the variable directly. More... | |
#define | CMD_DATA (CMD_CURRENT->jim_handler_data) |
Use this macro to access the invoked command handler's data pointer, rather than accessing the variable directly. More... | |
#define | CMD_NAME (cmd->name) |
Use this macro to access the name of the command being handled, rather than accessing the variable directly. More... | |
#define | COMMAND_HANDLER(name) static __COMMAND_HANDLER(name) |
Always use this macro to define new command handler functions. More... | |
#define | COMMAND_HELPER(name, extra ...) __COMMAND_HANDLER(name, extra) |
Similar to COMMAND_HANDLER, except some parameters are expected. More... | |
#define | COMMAND_PARSE_ADDITIONAL_NUMBER(type, argn, out, name_str) |
parses the command argument at position argn into out as a type, or prints a command error referring to name_str and passes the error code to the caller. More... | |
#define | COMMAND_PARSE_ADDRESS(in, out) COMMAND_PARSE_NUMBER(target_addr, in, out) |
#define | COMMAND_PARSE_BOOL(in, out, on, off) |
Parse the string as a binary parameter, storing the boolean value in out . More... | |
#define | COMMAND_PARSE_ENABLE(in, out) COMMAND_PARSE_BOOL(in, out, "enable", "disable") |
parses an enable/disable command argument More... | |
#define | COMMAND_PARSE_NUMBER(type, in, out) |
parses the string in into out as a type, or prints a command error and passes the error code to the caller. More... | |
#define | COMMAND_PARSE_ON_OFF(in, out) COMMAND_PARSE_BOOL(in, out, "on", "off") |
parses an on/off command argument More... | |
#define | COMMAND_PARSE_OPTIONAL_NUMBER(type, argn, out) |
parses the command argument at position argn into out as a type if the argument argn does not start with '-'. More... | |
#define | COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL } |
Use this as the last entry in an array of command_registration records. More... | |
#define | DECLARE_PARSE_WRAPPER(name, type) int parse ## name(const char *str, type * ul) |
#define | ERROR_COMMAND_ARGUMENT_INVALID (-603) |
#define | ERROR_COMMAND_ARGUMENT_OVERFLOW (-604) |
#define | ERROR_COMMAND_ARGUMENT_UNDERFLOW (-605) |
#define | ERROR_COMMAND_CLOSE_CONNECTION (-600) |
#define | ERROR_COMMAND_NOTFOUND (-602) |
#define | ERROR_COMMAND_SYNTAX_ERROR (-601) |
#define | PRINTF_ATTRIBUTE_FORMAT printf |
Typedefs | |
typedef int(* | command_output_handler_t) (struct command_context *context, const char *line) |
The type signature for command context's output handler. More... | |
Enumerations | |
enum | command_mode { COMMAND_EXEC , COMMAND_CONFIG , COMMAND_ANY , COMMAND_UNKNOWN = -1 } |
OpenOCD command mode is COMMAND_CONFIG at start, then switches to COMMAND_EXEC during the execution of command 'init'. More... | |
Functions | |
typedef | __COMMAND_HANDLER ((*command_handler_t)) |
The type signature for command handling functions. More... | |
int | __register_commands (struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds, void *data, struct target *override_target) |
int | command_context_mode (struct command_context *context, enum command_mode mode) |
void | command_done (struct command_context *context) |
Frees the resources associated with a command context. More... | |
void | command_exit (struct command_context *context) |
Shutdown a command context. More... | |
COMMAND_HELPER (handle_command_parse_bool, bool *out, const char *label) | |
struct command_context * | command_init (const char *startup_tcl, Jim_Interp *interp) |
Creates a new command context using the startup TCL provided and the existing Jim interpreter, if any. More... | |
int void | command_output_text (struct command_context *context, const char *data) |
int | command_parse_bool_arg (const char *in, bool *out) |
void | command_print (struct command_invocation *cmd, const char *format,...) __attribute__((format(PRINTF_ATTRIBUTE_FORMAT |
void void | command_print_sameline (struct command_invocation *cmd, const char *format,...) __attribute__((format(PRINTF_ATTRIBUTE_FORMAT |
void void int | command_run_line (struct command_context *context, char *line) |
int | command_run_linef (struct command_context *context, const char *format,...) __attribute__((format(PRINTF_ATTRIBUTE_FORMAT |
void | command_set_output_handler (struct command_context *context, command_output_handler_t output_handler, void *priv) |
struct command_context * | copy_command_context (struct command_context *cmd_ctx) |
Creates a copy of an existing command context. More... | |
struct command_context * | current_command_context (Jim_Interp *interp) |
DECLARE_PARSE_WRAPPER (_int, int) | |
DECLARE_PARSE_WRAPPER (_s16, int16_t) | |
DECLARE_PARSE_WRAPPER (_s32, int32_t) | |
DECLARE_PARSE_WRAPPER (_s64, int64_t) | |
DECLARE_PARSE_WRAPPER (_s8, int8_t) | |
DECLARE_PARSE_WRAPPER (_target_addr, target_addr_t) | |
DECLARE_PARSE_WRAPPER (_u16, uint16_t) | |
DECLARE_PARSE_WRAPPER (_u32, uint32_t) | |
DECLARE_PARSE_WRAPPER (_u64, uint64_t) | |
DECLARE_PARSE_WRAPPER (_u8, uint8_t) | |
DECLARE_PARSE_WRAPPER (_uint, unsigned) | |
int | help_del_all_commands (struct command_context *cmd_ctx) |
Unregisters the help for all commands. More... | |
static struct command * | jim_to_command (Jim_Interp *interp) |
bool | jimcmd_is_oocd_command (Jim_Cmd *cmd) |
Return true if the command cmd is registered by OpenOCD. More... | |
void * | jimcmd_privdata (Jim_Cmd *cmd) |
Return the pointer to the command's private data specified during the registration of command cmd . More... | |
int | parse_llong (const char *str, long long *ul) |
int | parse_long (const char *str, long *ul) |
int | parse_ullong (const char *str, unsigned long long *ul) |
int | parse_ulong (const char *str, unsigned long *ul) |
void | process_jim_events (struct command_context *cmd_ctx) |
static int | register_commands (struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds) |
Register one or more commands in the specified context, as children of parent (or top-level commends, if NULL). More... | |
static int | register_commands_override_target (struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds, struct target *target) |
Register one or more commands, as register_commands(), plus specify that command should override the current target. More... | |
static int | register_commands_with_data (struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds, void *data) |
Register one or more commands, as register_commands(), plus specify a pointer to command private data that would be accessible through the macro CMD_DATA. More... | |
int | unregister_all_commands (struct command_context *cmd_ctx, const char *cmd_prefix) |
Unregisters all commands from the specified context. More... | |
#define __COMMAND_HANDLER | ( | name, | |
extra ... | |||
) | int name(struct command_invocation *cmd, ## extra) |
Use this to macro to call a command helper (or a nested handler).
It provides command handler authors protection against reordering or removal of unused parameters.
Note: This macro uses lexical capture to provide some arguments. As a result, this macro should be used only within functions defined by the COMMAND_HANDLER or COMMAND_HELPER macros. Those macros provide the expected lexical context captured by this macro. Furthermore, it should be used only from the top-level of handler or helper function, or care must be taken to avoid redefining the same variables in intervening scope(s) by accident.
#define CMD (cmd) |
#define CMD_ARGC (cmd->argc) |
#define CMD_ARGV (cmd->argv) |
#define CMD_CTX (cmd->ctx) |
#define CMD_CURRENT (cmd->current) |
#define CMD_DATA (CMD_CURRENT->jim_handler_data) |
#define COMMAND_HANDLER | ( | name | ) | static __COMMAND_HANDLER(name) |
Always use this macro to define new command handler functions.
It ensures the parameters are ordered, typed, and named properly, so they be can be used by other macros (e.g. COMMAND_PARSE_NUMBER). All command handler functions must be defined as static in scope.
#define COMMAND_HELPER | ( | name, | |
extra ... | |||
) | __COMMAND_HANDLER(name, extra) |
#define COMMAND_PARSE_ADDITIONAL_NUMBER | ( | type, | |
argn, | |||
out, | |||
name_str | |||
) |
parses the command argument at position argn into out as a type, or prints a command error referring to name_str and passes the error code to the caller.
argn will be incremented if no error occurred. Otherwise the calling function will return the error code produced by the parsing function.
This function may cause the calling function to return immediately, so it should be used carefully to avoid leaking resources. In most situations, parsing should be completed in full before proceeding to allocate resources, and this strategy will most prevents leaks.
#define COMMAND_PARSE_ADDRESS | ( | in, | |
out | |||
) | COMMAND_PARSE_NUMBER(target_addr, in, out) |
#define COMMAND_PARSE_BOOL | ( | in, | |
out, | |||
on, | |||
off | |||
) |
Parse the string as
a binary parameter, storing the boolean value in out
.
The strings on
and off
are used to match different strings for true and false options (e.g. "on" and "off" or "enable" and "disable").
#define COMMAND_PARSE_ENABLE | ( | in, | |
out | |||
) | COMMAND_PARSE_BOOL(in, out, "enable", "disable") |
#define COMMAND_PARSE_NUMBER | ( | type, | |
in, | |||
out | |||
) |
parses the string in into out as a type, or prints a command error and passes the error code to the caller.
If an error does occur, the calling function will return the error code produced by the parsing function (one of ERROR_COMMAND_ARGUMENT_*).
This function may cause the calling function to return immediately, so it should be used carefully to avoid leaking resources. In most situations, parsing should be completed in full before proceeding to allocate resources, and this strategy will most prevents leaks.
#define COMMAND_PARSE_ON_OFF | ( | in, | |
out | |||
) | COMMAND_PARSE_BOOL(in, out, "on", "off") |
#define COMMAND_PARSE_OPTIONAL_NUMBER | ( | type, | |
argn, | |||
out | |||
) |
parses the command argument at position argn into out as a type if the argument argn does not start with '-'.
and passes the error code to the caller. argn will be incremented if no error occurred. Otherwise the calling function will return the error code produced by the parsing function.
This function may cause the calling function to return immediately, so it should be used carefully to avoid leaking resources. In most situations, parsing should be completed in full before proceeding to allocate resources, and this strategy will most prevents leaks.
Use this as the last entry in an array of command_registration records.
typedef int(* command_output_handler_t) (struct command_context *context, const char *line) |
enum command_mode |
OpenOCD command mode is COMMAND_CONFIG at start, then switches to COMMAND_EXEC during the execution of command 'init'.
The field 'mode' in struct command_registration specifies in which command mode the command can be executed:
Enumerator | |
---|---|
COMMAND_EXEC | |
COMMAND_CONFIG | |
COMMAND_ANY | |
COMMAND_UNKNOWN |
typedef __COMMAND_HANDLER | ( | * | command_handler_t | ) |
The type signature for command handling functions.
They are usually registered as part of command_registration, providing a high-level means for executing a command.
If the command fails, it MUST return a value != ERROR_OK (many commands break this rule, patches welcome!)
This is especially important for commands such as writing to flash or verifying memory. The reason is that those commands can be used by programs to determine if the operation succeeded or not. If the operation failed, then a program can try an alternative approach.
Returning ERROR_COMMAND_SYNTAX_ERROR will have the effect of printing out the syntax of the command.
int __register_commands | ( | struct command_context * | cmd_ctx, |
const char * | cmd_prefix, | ||
const struct command_registration * | cmds, | ||
void * | data, | ||
struct target * | override_target | ||
) |
Definition at line 316 of file command.c.
References alloc_printf(), command_registration::chain, ERROR_FAIL, ERROR_OK, command::jim_handler_data, command::jim_override_target, command_registration::name, name, NULL, register_command(), and unregister_command().
Referenced by register_commands(), register_commands_override_target(), and register_commands_with_data().
int command_context_mode | ( | struct command_context * | context, |
enum command_mode | mode | ||
) |
Definition at line 1290 of file command.c.
References ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, command_context::mode, and mode.
Referenced by COMMAND_HANDLER(), and openocd_main().
void command_done | ( | struct command_context * | context | ) |
Frees the resources associated with a command context.
The commands are not removed, so unregister_all_commands() must be called first.
context | The command_context that will be destroyed. |
Definition at line 651 of file command.c.
Referenced by add_connection(), command_exit(), remove_connection(), and setup_command_handler().
void command_exit | ( | struct command_context * | context | ) |
Shutdown a command context.
Free the command context and the associated Jim interpreter.
context | The command_context that will be destroyed. |
Definition at line 1280 of file command.c.
References command_done(), command_context::help_list, and command_context::interp.
Referenced by openocd_main().
COMMAND_HELPER | ( | handle_command_parse_bool | , |
bool * | out, | ||
const char * | label | ||
) |
struct command_context* command_init | ( | const char * | startup_tcl, |
Jim_Interp * | interp | ||
) |
Creates a new command context using the startup TCL provided and the existing Jim interpreter, if any.
If interp == NULL, then command_init creates a command interpreter.
Definition at line 1245 of file command.c.
References command_builtin_handlers, COMMAND_EXEC, command_context::help_list, INIT_LIST_HEAD(), command_context::interp, LOG_ERROR, LOG_USER_N, command_context::mode, NULL, and register_commands().
Referenced by setup_command_handler().
int void command_output_text | ( | struct command_context * | context, |
const char * | data | ||
) |
Definition at line 444 of file command.c.
References command_context::output_handler.
Referenced by command_run_line(), target_asciimsg(), and target_hexmsg().
int command_parse_bool_arg | ( | const char * | in, |
bool * | out | ||
) |
Definition at line 1384 of file command.c.
References command_parse_bool(), ERROR_COMMAND_SYNTAX_ERROR, and ERROR_OK.
Referenced by COMMAND_HELPER().
void command_print | ( | struct command_invocation * | cmd, |
const char * | format, | ||
... | |||
) |
void void command_print_sameline | ( | struct command_invocation * | cmd, |
const char * | format, | ||
... | |||
) |
void void int command_run_line | ( | struct command_context * | context, |
char * | line | ||
) |
Definition at line 554 of file command.c.
References command_output_text(), command_context::current_target_override, ERROR_COMMAND_CLOSE_CONNECTION, ERROR_FAIL, ERROR_OK, command_context::interp, LOG_USER, and NULL.
Referenced by COMMAND_HANDLER(), command_run_linef(), openocd_thread(), parse_config_file(), server_loop(), tcl_input(), and telnet_exec_line().
int command_run_linef | ( | struct command_context * | context, |
const char * | format, | ||
... | |||
) |
void command_set_output_handler | ( | struct command_context * | context, |
command_output_handler_t | output_handler, | ||
void * | priv | ||
) |
Definition at line 635 of file command.c.
References command_context::output_handler, command_context::output_handler_priv, and priv.
Referenced by gdb_new_connection(), openocd_main(), and telnet_new_connection().
struct command_context* copy_command_context | ( | struct command_context * | cmd_ctx | ) |
Creates a copy of an existing command context.
This does not create a deep copy of the command list, so modifications in one context will affect all shared contexts. The caller must track reference counting and ensure the commands are freed before destroying the last instance.
cmd_ctx | The command_context that will be copied. |
Definition at line 642 of file command.c.
Referenced by add_connection().
struct command_context* current_command_context | ( | Jim_Interp * | interp | ) |
Definition at line 187 of file command.c.
References global_cmd_ctx, and command_context::interp.
Referenced by arm_tpiu_swo_create(), arm_tpiu_swo_handle_event(), cti_create(), dap_create(), jim_aice_arp_init_reset(), jim_arc_add_reg(), jim_arc_add_reg_type_flags(), jim_arc_add_reg_type_struct(), jim_arc_get_aux_reg(), jim_arc_get_core_reg(), jim_arc_get_reg_field(), jim_arc_set_aux_reg(), jim_arm_tpiu_swo_enable(), jim_arm_tpiu_swo_init(), jim_command_dispatch(), jim_command_mode(), jim_jtag_arp_init(), jim_jtag_arp_init_reset(), jim_nds32_bulk_read(), jim_nds32_bulk_write(), jim_nds32_multi_write(), jim_nds32_read_edm_sr(), jim_nds32_write_edm_sr(), jim_target_array2mem(), jim_target_configure(), jim_target_current(), jim_target_current_state(), jim_target_examine(), jim_target_examine_deferred(), jim_target_halt(), jim_target_halt_gdb(), jim_target_invoke_event(), jim_target_mem2array(), jim_target_poll(), jim_target_reset(), jim_target_wait_state(), jim_target_was_examined(), target_configure(), target_create(), target_handle_event(), target_jim_get_reg(), target_jim_read_memory(), target_jim_set_reg(), and target_jim_write_memory().
DECLARE_PARSE_WRAPPER | ( | _int | , |
int | |||
) |
DECLARE_PARSE_WRAPPER | ( | _s16 | , |
int16_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _s32 | , |
int32_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _s64 | , |
int64_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _s8 | , |
int8_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _target_addr | , |
target_addr_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _u16 | , |
uint16_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _u32 | , |
uint32_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _u64 | , |
uint64_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _u8 | , |
uint8_t | |||
) |
DECLARE_PARSE_WRAPPER | ( | _uint | , |
unsigned | |||
) |
int help_del_all_commands | ( | struct command_context * | cmd_ctx | ) |
Unregisters the help for all commands.
Used at exit to remove the help added through the commands 'add_help_text' and 'add_usage_text'.
cmd_ctx | The context that will be cleared of registered helps. |
Definition at line 1024 of file command.c.
References help_entry::cmd_name, ERROR_OK, help_entry::help, command_context::help_list, help_entry::lh, lh(), list_del(), list_for_each_entry_safe, and help_entry::usage.
Referenced by openocd_main().
|
inlinestatic |
Definition at line 206 of file command.h.
Referenced by jim_arm_tpiu_swo_configure(), jim_arm_tpiu_swo_enable(), jim_command_dispatch(), jim_jtag_configure(), jim_jtag_tap_enabler(), and jim_target_configure().
bool jimcmd_is_oocd_command | ( | Jim_Cmd * | cmd | ) |
Return true if the command cmd
is registered by OpenOCD.
Definition at line 54 of file command.c.
References cmd, and jim_command_dispatch().
Referenced by command_find_from_name(), jim_command_mode(), and telnet_auto_complete().
void* jimcmd_privdata | ( | Jim_Cmd * | cmd | ) |
Return the pointer to the command's private data specified during the registration of command cmd .
Definition at line 59 of file command.c.
Referenced by command_find_from_name(), jim_command_mode(), and telnet_auto_complete().
int parse_llong | ( | const char * | str, |
long long * | ul | ||
) |
int parse_long | ( | const char * | str, |
long * | ul | ||
) |
Referenced by add_service(), and gdb_target_add_one().
int parse_ullong | ( | const char * | str, |
unsigned long long * | ul | ||
) |
int parse_ulong | ( | const char * | str, |
unsigned long * | ul | ||
) |
void process_jim_events | ( | struct command_context * | cmd_ctx | ) |
Definition at line 1299 of file command.c.
References command_context::interp.
Referenced by server_loop().
|
inlinestatic |
Register one or more commands in the specified context, as children of parent
(or top-level commends, if NULL).
In a registration's record contains a non-NULL chain
member and name is NULL, the commands on the chain will be registered in the same context. Otherwise, the chained commands are added as children of the command.
cmd_ctx | The command_context in which to register the command. |
cmd_prefix | Register this command as a child of this, or NULL to register a top-level command. |
cmds | Pointer to an array of command_registration records that contains the desired command parameters. The last record must have NULL for all fields. |
Definition at line 268 of file command.h.
References __register_commands(), and NULL.
Referenced by adapter_register_commands(), aice_transport_register_commands(), COMMAND_HANDLER(), COMMAND_HELPER(), command_init(), dapdirect_jtag_select(), dapdirect_swd_select(), etm_register_user_commands(), FLASH_BANK_COMMAND_HANDLER(), flash_init_drivers(), flash_register_commands(), gdb_register_commands(), hl_jtag_transport_select(), ipdbg_register_commands(), jsp_register_commands(), jtag_register_commands(), log_register_commands(), nand_init(), nand_register_commands(), openocd_register_commands(), pld_init(), pld_register_commands(), rtt_server_register_commands(), server_register_commands(), svf_register_commands(), swd_select(), swim_transport_select(), target_create(), target_register_commands(), target_register_user_commands(), target_request_register_commands(), tcl_register_commands(), telnet_register_commands(), trace_register_commands(), transport_register_commands(), util_init(), workaround_for_jimtcl_expr(), and xsvf_register_commands().
|
inlinestatic |
Register one or more commands, as register_commands(), plus specify that command should override the current target.
cmd_ctx | The command_context in which to register the command. |
cmd_prefix | Register this command as a child of this, or NULL to register a top-level command. |
cmds | Pointer to an array of command_registration records that contains the desired command parameters. The last record must have NULL for all fields. |
target | The target that has to override current target. |
Definition at line 287 of file command.h.
References __register_commands(), and NULL.
Referenced by target_create().
|
inlinestatic |
Register one or more commands, as register_commands(), plus specify a pointer to command private data that would be accessible through the macro CMD_DATA.
The private data will not be freed when command is unregistered.
cmd_ctx | The command_context in which to register the command. |
cmd_prefix | Register this command as a child of this, or NULL to register a top-level command. |
cmds | Pointer to an array of command_registration records that contains the desired command parameters. The last record must have NULL for all fields. |
data | The command private data. |
Definition at line 309 of file command.h.
References __register_commands(), and NULL.
Referenced by arm_tpiu_swo_create(), cti_create(), and dap_create().
int unregister_all_commands | ( | struct command_context * | cmd_ctx, |
const char * | cmd_prefix | ||
) |
Unregisters all commands from the specified context.
cmd_ctx | The context that will be cleared of registered commands. |
cmd_prefix | If given, only clear commands from under this one command. |
Definition at line 416 of file command.c.
References ERROR_OK.
Referenced by openocd_main().