38#include "gdbsupport/gdb_string_view.h"
50 gdb::function_view<
void (
const char *)> validator);
162 if (args == NULL || *args ==
'\0')
165 error (_(
"if command requires an argument."));
167 error (_(
"while command requires an argument."));
169 error (_(
"define command requires an argument."));
171 error (_(
"document command requires an argument."));
173 gdb_assert (args != NULL);
192 warning (_(
"Error reading in canned sequence of commands."));
211 uiout->
spaces (2 * depth);
257 uiout->
spaces (2 * depth);
277 uiout->
spaces (2 * depth);
284 uiout->
spaces (2 * depth);
302 uiout->
spaces (2 * depth);
316 uiout->
spaces (2 * depth);
329 uiout->
spaces (2 * depth);
342 uiout->
spaces (2 * depth);
405 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
406 scoped_restore save_nesting
415 warning (_(
"Error executing canned sequence of commands."));
418 cmdlines = cmdlines->
next;
446 if (cmdlines_copy == 0)
454 error (_(
"Max user call depth exceeded -- command aborted."));
458 scoped_restore restore_instream
504 va_start (args, fmt);
583 scoped_restore save_nesting
601 current = current->
next;
639 scoped_restore save_nesting
648 current = current->
next;
690 warning (_(
"Invalid control type in canned commands structure."));
706 scoped_restore save_uiout
735 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
752 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
772 const char *start_arg;
778 while (*p ==
' ' || *p ==
'\t')
787 if (((*p ==
' ' || *p ==
'\t')) && !squote && !dquote && !bsquote)
816 m_args.emplace_back (start_arg, p - start_arg);
826 while ((p = strchr (p,
'$')))
828 if (startswith (p,
"$arg")
829 && (isdigit (p[4]) || p[4] ==
'c'))
847 return args->insert_args (
line);
856 std::string new_line;
861 new_line.append (line, p - line);
865 new_line += std::to_string (
m_args.size ());
874 i = strtoul (p + 4, &tmp, 10);
875 if ((i == 0 && tmp == p + 4) || errno != 0)
877 else if (i >=
m_args.size ())
878 error (_(
"Missing argument %ld in user function."), i);
881 new_line.append (
m_args[i].data (),
m_args[i].length ());
887 new_line.append (line);
901 char *prompt_ptr, control_prompt[256];
906 error (_(
"Control nesting too deep!"));
913 control_prompt[i] =
' ';
914 control_prompt[i] =
'>';
915 control_prompt[i + 1] =
'\0';
916 prompt_ptr = (
char *) &control_prompt[0];
932 return skip_spaces (first_arg);
946 gdb::function_view<
void (
const char *)> validator)
958 p_end = p + strlen (p);
959 while (p_end > p && (p_end[-1] ==
' ' || p_end[-1] ==
'\t'))
964 while (p_start < p_end && (*p_start ==
' ' || *p_start ==
'\t'))
969 if (p_end - p_start == 3 && startswith (p_start,
"end"))
975 const char *cmd_name = p;
978 cmd_name = skip_spaces (cmd_name);
979 bool inline_cmd = *cmd_name !=
'\0';
989 if (p_end == p || p[0] ==
'#')
993 if (p_end - p == 4 && startswith (p,
"else"))
1041 else if (p_end - p == 10 && startswith (p,
"loop_break"))
1043 else if (p_end - p == 13 && startswith (p,
"loop_continue"))
1049 if (!parse_commands || not_handled)
1053 savestring (p, p_end - p)));
1057 validator ((*command)->line);
1070 gdb::function_view<
void (
const char *)> validator)
1078 child_tail =
nullptr;
1082 error (_(
"Recursed on a simple control type."));
1123 child_tail =
nullptr;
1134 if (child_tail !=
nullptr)
1136 child_tail->
next = next.release ();
1137 child_tail = child_tail->
next;
1141 child_tail = next.get ();
1175#define END_MESSAGE "End with a line saying just \"end\"."
1179 gdb::function_view<
void (
const char *)> validator)
1186 (*deprecated_readline_begin_hook) (
"%s %s\n", prompt_arg,
1211 (*deprecated_readline_end_hook) ();
1222 gdb::function_view<
void (
const char *)> validator)
1271 tail->
next = next.release ();
1317 const char *p, *last_word;
1323 p = *comname + strlen (*comname);
1324 while (p > *comname && isspace (p[-1]))
1326 while (p > *comname && !isspace (p[-1]))
1331 if (last_word != *comname)
1336 std::string
prefix (*comname, last_word - 1);
1337 const char *tem =
prefix.c_str ();
1341 error (_(
"\"%s\" is not a prefix command."),
prefix.c_str ());
1344 *comname = last_word;
1351 error (_(
"Junk in argument list: \"%s\""), p);
1381 const char *comfull;
1383 int hook_name_size = 0;
1385#define HOOK_STRING "hook-"
1387#define HOOK_POST_STRING "hookpost-"
1388#define HOOK_POST_LEN 9
1395 if (c && commands ==
nullptr)
1406 ||
query (_(
"Keeping subcommands of prefix command \"%s\".\n"
1407 "Redefine command \"%s\"? "), c->
name, c->
name));
1409 q =
query (_(
"Redefine command \"%s\"? "), c->
name);
1412 q =
query (_(
"Really redefine built-in command \"%s\"? "), c->
name);
1414 error (_(
"Command \"%s\" not redefined."), c->
name);
1437 if (!hookc && commands ==
nullptr)
1439 warning (_(
"Your new `%s' command does not "
1440 "hook any existing command."),
1442 if (!
query (_(
"Proceed? ")))
1443 error (_(
"Not confirmed."));
1447 comname = xstrdup (comname);
1450 if (commands ==
nullptr)
1453 = string_printf (
"Type commands for definition of \"%s\".", comfull);
1465 ? c->
doc : xstrdup (
"User-defined."), list);
1470 if (c_subcommands !=
nullptr)
1496 internal_error (_(
"bad switch"));
1516 const char *comfull;
1523 error (_(
"Undefined command: \"%s\"."), comfull);
1528 if (
alias ==
nullptr)
1529 error (_(
"Command \"%s\" is built-in."), comfull);
1531 error (_(
"Alias \"%s\" is built-in."), comfull);
1536 if (
alias !=
nullptr)
1541 if (commands ==
nullptr)
1544 = string_printf (
"Type documentation for \"%s\".", comfull);
1548 doclines = *commands;
1558 for (cl1 = doclines.get (); cl1; cl1 = cl1->
next)
1559 len += strlen (cl1->
line) + 1;
1561 doc = (
char *)
xmalloc (len + 1);
1564 for (cl1 = doclines.get (); cl1; cl1 = cl1->
next)
1566 strcat (doc, cl1->
line);
1588 const char *comfull;
1596 error (_(
"Command \"%s\" is built-in."), comfull);
1607 comname = xstrdup (comname);
1609 xstrdup (
"User-defined."), list);
1630 internal_error (_(
"called with NULL file pointer!"));
1632 scoped_restore restore_line_number
1634 scoped_restore restore_file
1635 = make_scoped_restore<std::string, const std::string &> (&
source_file_name,
1638 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
1644 catch (
const gdb_exception_error &e)
1648 throw_error (e.error,
1649 _(
"%s:%d: Error in sourced command file:\n%s"),
1681 const std::string prefixname = c->
prefixname ();
1701Document a user-defined command or user-defined alias.\n\
1702Give command or alias name as argument. Give documentation on following lines.\n\
1703End with a line of just \"end\"."));
1706Define a new command name. Command name is argument.\n\
1707Definition appears on following lines, one command per line.\n\
1708End with a line of just \"end\".\n\
1709Use the \"document\" command to give documentation for the new command.\n\
1710Commands defined in this way may accept an unlimited number of arguments\n\
1711accessed via $arg0 .. $argN. $argc tells how many arguments have\n\
1716Define or mark a command as a user-defined prefix command.\n\
1717User defined prefix commands can be used as prefix commands for\n\
1718other user defined commands.\n\
1719If the command already exists, it is changed to a prefix command."));
1723Execute nested commands WHILE the conditional expression is non zero.\n\
1724The conditional expression must follow the word `while' and must in turn be\n\
1725followed by a new line. The nested commands must be entered one per line,\n\
1726and should be terminated by the word `end'."));
1729Execute nested commands once IF the conditional expression is non zero.\n\
1730The conditional expression must follow the word `if' and must in turn be\n\
1731followed by a new line. The nested commands must be entered one per line,\n\
1732and should be terminated by the word 'else' or `end'. If an else clause\n\
1733is used, the same rules apply to its nested commands as to the first ones."));
enum command_control_type commands_from_control_command(const char *arg, struct command_line *cmd)
cmd_list_element * commands_cmd_element
ui_file_style style() const
virtual ui_out * interp_ui_out()=0
scoped_restore_hook_in & operator=(const scoped_restore_hook_in &)=delete
scoped_restore_hook_in(struct cmd_list_element *c)
~scoped_restore_hook_in()
scoped_restore_hook_in(const scoped_restore_hook_in &)=delete
struct cmd_list_element * m_cmd
void void void spaces(int numspaces)
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
void field_fmt(const char *fldname, const char *format,...) ATTRIBUTE_PRINTF(3
void text(const char *string)
user_args(const user_args &)=delete
user_args(const char *line)
std::string m_command_line
user_args & operator=(const user_args &)=delete
std::vector< gdb::string_view > m_args
std::string insert_args(const char *line) const
unsigned int max_user_call_depth
void error_no_arg(const char *why)
struct cmd_list_element * cmdlist
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, const char *cmdtype, std::string *default_args, int allow_unknown, int ignore_help_classes)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
bool valid_cmd_char_p(int c)
struct cmd_list_element * lookup_cmd_1(const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, std::string *default_args, int ignore_help_classes, bool lookup_for_completion_p)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
int find_command_name_length(const char *text)
int lookup_cmd_composition(const char *text, struct cmd_list_element **alias, struct cmd_list_element **prefix_cmd, struct cmd_list_element **cmd)
struct cmd_list_element * lookup_cmd_exact(const char *name, struct cmd_list_element *list, bool ignore_help_classes)
int cli_user_command_p(struct cmd_list_element *cmd)
void show_user_1(struct cmd_list_element *c, const char *prefix, const char *name, struct ui_file *stream)
static struct cmd_list_element ** validate_comname(const char **comname)
static void do_document_command(const char *comname, int from_tty, const counted_command_line *commands)
counted_command_line read_command_lines_1(read_next_line_ftype read_next_line_func, int parse_commands, gdb::function_view< void(const char *)> validator)
static int suppress_next_print_command_trace
void execute_control_commands(struct command_line *cmdlines, int from_tty)
static cmd_list_element * define_cmd_element
static void define_command(const char *comname, int from_tty)
static std::vector< std::unique_ptr< user_args > > user_args_stack
static int command_nest_depth
static void while_command(const char *arg, int from_tty)
static const char * line_first_arg(const char *p)
std::string insert_user_defined_cmd_args(const char *line)
void script_from_file(FILE *stream, const char *file)
static int multi_line_command_p(enum command_control_type type)
static enum misc_command_type process_next_line(const char *p, command_line_up *command, int parse_commands, gdb::function_view< void(const char *)> validator)
void reset_command_nest_depth(void)
static cmd_list_element * while_cmd_element
void execute_cmd_pre_hook(struct cmd_list_element *c)
static void user_defined_command(const char *ignore, int from_tty)
counted_command_line read_command_lines(const char *prompt_arg, int from_tty, int parse_commands, gdb::function_view< void(const char *)> validator)
static const char * read_next_line(std::string &buffer)
counted_command_line get_command_line(enum command_control_type type, const char *arg)
static cmd_list_element * if_cmd_element
static command_line_up build_command_line(enum command_control_type type, const char *args)
static void document_command(const char *comname, int from_tty)
static void define_prefix_command(const char *comname, int from_tty)
void print_command_trace(const char *fmt,...)
static enum command_control_type execute_control_command_1(struct command_line *cmd, int from_tty)
void execute_cmd_post_hook(struct cmd_list_element *c)
static enum command_control_type recurse_read_control_structure(read_next_line_ftype read_next_line_func, struct command_line *current_cmd, gdb::function_view< void(const char *)> validator)
void print_command_lines(struct ui_out *uiout, struct command_line *cmd, unsigned int depth)
enum command_control_type execute_control_command(struct command_line *cmd, int from_tty)
static cmd_list_element * document_cmd_element
static void do_define_command(const char *comname, int from_tty, const counted_command_line *commands)
static const char * locate_arg(const char *p)
enum command_control_type execute_control_command_untraced(struct command_line *cmd)
void _initialize_cli_script()
void free_command_lines(struct command_line **lptr)
static void if_command(const char *arg, int from_tty)
std::string execute_control_commands_to_string(struct command_line *commands, int from_tty)
void execute_user_command(struct cmd_list_element *c, const char *args)
std::unique_ptr< command_line, command_lines_deleter > command_line_up
gdb::function_view< const char *(std::string &)> read_next_line_ftype
std::shared_ptr< command_line > counted_command_line
cli_style_option title_style
void eval_compile_command(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope, void *scope_data)
cmd_list_element * compile_cmd_element
void command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void(* hook_type)(const char *)
void(* deprecated_readline_end_hook)(void)
@ COMPILE_I_INVALID_SCOPE
char *(* deprecated_readline_hook)(const char *)
int void void(* deprecated_readline_begin_hook)(const char *,...) ATTRIBUTE_FPTR_PRINTF_1
const char * command_line_input(std::string &cmd_line_buffer, const char *, const char *)
std::unique_ptr< expression > expression_up
expression_up parse_expression(const char *, innermost_block_tracker *=nullptr, parser_flags flags=0)
void eval_ext_lang_from_control_command(struct command_line *cmd)
static void ATTRIBUTE_PRINTF(1, 0)
void execute_fn_to_string(std::string &res, std::function< void(void)> fn, bool term_out)
void execute_command(const char *, int)
cmd_list_element * guile_cmd_element
struct interp * interp_lookup(struct ui *ui, const char *name)
int current_interp_named_p(const char *interp_name)
#define prefix(a, b, R, do)
cmd_list_element * python_cmd_element
unsigned int doc_allocated
struct cmd_list_element * hook_post
struct cmd_list_element * hookee_post
struct cmd_list_element * hookee_pre
struct cmd_list_element * hook_pre
std::string prefixname() const
struct cmd_list_element ** subcommands
counted_command_line user_commands
struct cmd_list_element * next
unsigned int allow_unknown
enum command_class theclass
counted_command_line body_list_0
struct command_line::@29::@30 compile
counted_command_line body_list_1
enum compile_i_scope_types scope
struct command_line * next
enum command_control_type control_type
union command_line::@29 control_u
~scoped_user_args_level()
scoped_user_args_level(const char *line)
bool input_interactive_p() const
void read_command_file(FILE *stream)
std::string source_file_name
cmd_list_element * while_stepping_cmd_element
void gdb_vprintf(struct ui_file *stream, const char *format, va_list args)
int query(const char *ctlstr,...)
void fprintf_styled(struct ui_file *stream, const ui_file_style &style, const char *format,...)
void gdb_printf(struct ui_file *stream, const char *format,...)
void printf_unfiltered(const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)
static bool value_true(struct value *val)