11 #ifndef OPENOCD_HELPER_COMMAND_H
12 #define OPENOCD_HELPER_COMMAND_H
24 #if (defined(IS_MINGW) && (((__GNUC__ << 16) + __GNUC_MINOR__) >= 0x00040004))
25 #define PRINTF_ATTRIBUTE_FORMAT gnu_printf
27 #define PRINTF_ATTRIBUTE_FORMAT printf
101 #define __COMMAND_HANDLER(name, extra ...) \
102 int name(struct command_invocation *cmd, ## extra)
117 #define CALL_COMMAND_HANDLER(name, extra ...) \
126 #define COMMAND_HANDLER(name) \
127 static __COMMAND_HANDLER(name)
134 #define COMMAND_HELPER(name, extra ...) __COMMAND_HANDLER(name, extra)
145 #define CMD_CTX (cmd->ctx)
150 #define CMD_ARGC (cmd->argc)
155 #define CMD_ARGV (cmd->argv)
160 #define CMD_NAME (cmd->name)
165 #define CMD_CURRENT (cmd->current)
170 #define CMD_DATA (CMD_CURRENT->jim_handler_data)
208 return Jim_CmdPrivData(interp);
247 #define COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL }
251 struct target *override_target);
323 const char *cmd_prefix);
384 #define ERROR_COMMAND_CLOSE_CONNECTION (-600)
385 #define ERROR_COMMAND_SYNTAX_ERROR (-601)
386 #define ERROR_COMMAND_NOTFOUND (-602)
387 #define ERROR_COMMAND_ARGUMENT_INVALID (-603)
388 #define ERROR_COMMAND_ARGUMENT_OVERFLOW (-604)
389 #define ERROR_COMMAND_ARGUMENT_UNDERFLOW (-605)
397 #define DECLARE_PARSE_WRAPPER(name, type) \
398 int parse ## name(const char *str, type * ul)
425 #define COMMAND_PARSE_NUMBER(type, in, out) \
427 int retval_macro_tmp = parse_ ## type(in, &(out)); \
428 if (retval_macro_tmp != ERROR_OK) { \
429 command_print(CMD, stringify(out) \
430 " option value ('%s') is not valid", in); \
431 return retval_macro_tmp; \
435 #define COMMAND_PARSE_ADDRESS(in, out) \
436 COMMAND_PARSE_NUMBER(target_addr, in, out)
450 #define COMMAND_PARSE_ADDITIONAL_NUMBER(type, argn, out, name_str) \
452 if (argn+1 >= CMD_ARGC || CMD_ARGV[argn+1][0] == '-') { \
453 command_print(CMD, "no " name_str " given"); \
457 COMMAND_PARSE_NUMBER(type, CMD_ARGV[argn], out); \
472 #define COMMAND_PARSE_OPTIONAL_NUMBER(type, argn, out) \
474 if (argn+1 < CMD_ARGC && CMD_ARGV[argn+1][0] != '-') { \
476 COMMAND_PARSE_NUMBER(type, CMD_ARGV[argn], out); \
486 #define COMMAND_PARSE_BOOL(in, out, on, off) \
489 int retval_macro_tmp = command_parse_bool_arg(in, &value); \
490 if (retval_macro_tmp != ERROR_OK) { \
491 command_print(CMD, stringify(out) \
492 " option value ('%s') is not valid", in); \
493 command_print(CMD, " choices are '%s' or '%s'", \
495 return retval_macro_tmp; \
504 #define COMMAND_PARSE_ON_OFF(in, out) \
505 COMMAND_PARSE_BOOL(in, out, "on", "off")
507 #define COMMAND_PARSE_ENABLE(in, out) \
508 COMMAND_PARSE_BOOL(in, out, "enable", "disable")
struct command_context * current_command_context(Jim_Interp *interp)
void command_print(struct command_invocation *cmd, const char *format,...) __attribute__((format(PRINTF_ATTRIBUTE_FORMAT
int void command_output_text(struct command_context *context, const char *data)
int command_parse_bool_arg(const char *in, bool *out)
int help_del_all_commands(struct command_context *cmd_ctx)
Unregisters the help for all commands.
bool jimcmd_is_oocd_command(Jim_Cmd *cmd)
Return true if the command cmd is registered by OpenOCD.
#define __COMMAND_HANDLER(name, extra ...)
Command handlers may be defined with more parameters than the base set provided by command....
int command_context_mode(struct command_context *context, enum command_mode mode)
int parse_ulong(const char *str, unsigned long *ul)
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...
#define PRINTF_ATTRIBUTE_FORMAT
int parse_llong(const char *str, long long *ul)
void * jimcmd_privdata(Jim_Cmd *cmd)
Return the pointer to the command's private data specified during the registration of command cmd .
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 ...
int command_run_linef(struct command_context *context, const char *format,...) __attribute__((format(PRINTF_ATTRIBUTE_FORMAT
void process_jim_events(struct command_context *cmd_ctx)
void command_done(struct command_context *context)
Frees the resources associated with a command context.
int parse_long(const char *str, long *ul)
void command_exit(struct command_context *context)
Shutdown a command context.
void void command_print_sameline(struct command_invocation *cmd, const char *format,...) __attribute__((format(PRINTF_ATTRIBUTE_FORMAT
int unregister_all_commands(struct command_context *cmd_ctx, const char *cmd_prefix)
Unregisters all commands from the specified context.
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,...
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_output_handler_t)(struct command_context *context, const char *line)
The type signature for command context's output handler.
void command_set_output_handler(struct command_context *context, command_output_handler_t output_handler, void *priv)
static struct command * jim_to_command(Jim_Interp *interp)
void void int command_run_line(struct command_context *context, char *line)
#define COMMAND_HELPER(name, extra ...)
Similar to COMMAND_HANDLER, except some parameters are expected.
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,...
#define DECLARE_PARSE_WRAPPER(name, type)
struct command_context * copy_command_context(struct command_context *cmd_ctx)
Creates a copy of an existing command context.
command_mode
OpenOCD command mode is COMMAND_CONFIG at start, then switches to COMMAND_EXEC during the execution o...
int parse_ullong(const char *str, unsigned long long *ul)
static struct esp_usb_jtag * priv
struct esp_usb_jtag __attribute__
struct list_head * help_list
void * output_handler_priv
struct target * current_target_override
struct target * current_target
command_output_handler_t output_handler
When run_command is called, a new instance will be created on the stack, filled with the proper value...
struct command_context * ctx
command_handler_t handler
Jim_CmdProc * jim_handler
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
const char * usage
a string listing the options and arguments, required or optional
Jim_CmdProc * jim_handler
command_handler_t handler
struct target * jim_override_target