11 #ifndef OPENOCD_HELPER_COMMAND_H
12 #define OPENOCD_HELPER_COMMAND_H
24 #if (defined(IS_MINGW) && (((__GNUC__ << 16) + __GNUC_MINOR__) >= 0x00040004)) && !defined(__clang__)
25 #define PRINTF_ATTRIBUTE_FORMAT gnu_printf
27 #define PRINTF_ATTRIBUTE_FORMAT printf
102 #define __COMMAND_HANDLER(name, extra ...) \
103 int name(struct command_invocation *cmd, ## extra)
118 #define CALL_COMMAND_HANDLER(name, extra ...) \
127 #define COMMAND_HANDLER(name) \
128 static __COMMAND_HANDLER(name)
135 #define COMMAND_HELPER(name, extra ...) __COMMAND_HANDLER(name, extra)
146 #define CMD_CTX (cmd->ctx)
151 #define CMD_ARGC (cmd->argc)
156 #define CMD_ARGV (cmd->argv)
161 #define CMD_JIMTCL_ARGV (cmd->jimtcl_argv)
166 #define CMD_NAME (cmd->name)
171 #define CMD_CURRENT (cmd->current)
176 #define CMD_DATA (CMD_CURRENT->jim_handler_data)
214 return Jim_CmdPrivData(interp);
253 #define COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL }
257 struct target *override_target);
329 const char *cmd_prefix);
401 #define ERROR_COMMAND_CLOSE_CONNECTION (-600)
402 #define ERROR_COMMAND_SYNTAX_ERROR (-601)
403 #define ERROR_COMMAND_NOTFOUND (-602)
404 #define ERROR_COMMAND_ARGUMENT_INVALID (-603)
405 #define ERROR_COMMAND_ARGUMENT_OVERFLOW (-604)
406 #define ERROR_COMMAND_ARGUMENT_UNDERFLOW (-605)
414 #define DECLARE_PARSE_WRAPPER(name, type) \
415 int parse ## name(const char *str, type * ul)
442 #define COMMAND_PARSE_NUMBER(type, in, out) \
444 int retval_macro_tmp = parse_ ## type(in, &(out)); \
445 if (retval_macro_tmp != ERROR_OK) { \
446 command_print(CMD, stringify(out) \
447 " option value ('%s') is not valid", in); \
448 return retval_macro_tmp; \
452 #define COMMAND_PARSE_ADDRESS(in, out) \
453 COMMAND_PARSE_NUMBER(target_addr, in, out)
467 #define COMMAND_PARSE_ADDITIONAL_NUMBER(type, argn, out, name_str) \
469 if (argn+1 >= CMD_ARGC || CMD_ARGV[argn+1][0] == '-') { \
470 command_print(CMD, "no " name_str " given"); \
474 COMMAND_PARSE_NUMBER(type, CMD_ARGV[argn], out); \
489 #define COMMAND_PARSE_OPTIONAL_NUMBER(type, argn, out) \
491 if (argn+1 < CMD_ARGC && CMD_ARGV[argn+1][0] != '-') { \
493 COMMAND_PARSE_NUMBER(type, CMD_ARGV[argn], out); \
503 #define COMMAND_PARSE_BOOL(in, out, on, off) \
506 int retval_macro_tmp = command_parse_bool_arg(in, &value); \
507 if (retval_macro_tmp != ERROR_OK) { \
508 command_print(CMD, stringify(out) \
509 " option value ('%s') is not valid", in); \
510 command_print(CMD, " choices are '%s' or '%s'", \
512 return retval_macro_tmp; \
527 COMMAND_HELPER(command_parse_str_to_buf,
const char *str,
void *buf,
unsigned int buf_len);
530 #define COMMAND_PARSE_ON_OFF(in, out) \
531 COMMAND_PARSE_BOOL(in, out, "on", "off")
533 #define COMMAND_PARSE_ENABLE(in, out) \
534 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 qn908x_flash_bank __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
Jim_Obj *const * jimtcl_argv
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