37#include "gdbsupport/gdb_string_view.h"
49 gdb::function_view<
void (
const char *)> validator);
161 if (args == NULL || *args ==
'\0')
164 error (_(
"if command requires an argument."));
166 error (_(
"while command requires an argument."));
168 error (_(
"define command requires an argument."));
170 error (_(
"document command requires an argument."));
172 gdb_assert (args != NULL);
191 warning (_(
"Error reading in canned sequence of commands."));
210 uiout->
spaces (2 * depth);
256 uiout->
spaces (2 * depth);
276 uiout->
spaces (2 * depth);
283 uiout->
spaces (2 * depth);
301 uiout->
spaces (2 * depth);
315 uiout->
spaces (2 * depth);
328 uiout->
spaces (2 * depth);
341 uiout->
spaces (2 * depth);
404 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
405 scoped_restore save_nesting
414 warning (_(
"Error executing canned sequence of commands."));
417 cmdlines = cmdlines->
next;
445 if (cmdlines_copy == 0)
453 error (_(
"Max user call depth exceeded -- command aborted."));
457 scoped_restore restore_instream
503 va_start (args, fmt);
582 scoped_restore save_nesting
600 current = current->
next;
638 scoped_restore save_nesting
647 current = current->
next;
689 warning (_(
"Invalid control type in canned commands structure."));
705 scoped_restore save_uiout
734 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
751 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
771 const char *start_arg;
777 while (*p ==
' ' || *p ==
'\t')
786 if (((*p ==
' ' || *p ==
'\t')) && !squote && !dquote && !bsquote)
815 m_args.emplace_back (start_arg, p - start_arg);
825 while ((p = strchr (p,
'$')))
827 if (startswith (p,
"$arg")
828 && (isdigit (p[4]) || p[4] ==
'c'))
846 return args->insert_args (
line);
855 std::string new_line;
860 new_line.append (line, p - line);
864 new_line += std::to_string (
m_args.size ());
873 i = strtoul (p + 4, &tmp, 10);
874 if ((i == 0 && tmp == p + 4) || errno != 0)
876 else if (i >=
m_args.size ())
877 error (_(
"Missing argument %ld in user function."), i);
880 new_line.append (
m_args[i].data (),
m_args[i].length ());
886 new_line.append (line);
900 char *prompt_ptr, control_prompt[256];
905 error (_(
"Control nesting too deep!"));
912 control_prompt[i] =
' ';
913 control_prompt[i] =
'>';
914 control_prompt[i + 1] =
'\0';
915 prompt_ptr = (
char *) &control_prompt[0];
931 return skip_spaces (first_arg);
945 gdb::function_view<
void (
const char *)> validator)
957 p_end = p + strlen (p);
958 while (p_end > p && (p_end[-1] ==
' ' || p_end[-1] ==
'\t'))
963 while (p_start < p_end && (*p_start ==
' ' || *p_start ==
'\t'))
968 if (p_end - p_start == 3 && startswith (p_start,
"end"))
974 const char *cmd_name = p;
977 cmd_name = skip_spaces (cmd_name);
978 bool inline_cmd = *cmd_name !=
'\0';
988 if (p_end == p || p[0] ==
'#')
992 if (p_end - p == 4 && startswith (p,
"else"))
1040 else if (p_end - p == 10 && startswith (p,
"loop_break"))
1042 else if (p_end - p == 13 && startswith (p,
"loop_continue"))
1048 if (!parse_commands || not_handled)
1052 savestring (p, p_end - p)));
1056 validator ((*command)->line);
1069 gdb::function_view<
void (
const char *)> validator)
1077 child_tail =
nullptr;
1081 error (_(
"Recursed on a simple control type."));
1122 child_tail =
nullptr;
1133 if (child_tail !=
nullptr)
1135 child_tail->
next =
next.release ();
1136 child_tail = child_tail->
next;
1140 child_tail =
next.get ();
1174#define END_MESSAGE "End with a line saying just \"end\"."
1178 gdb::function_view<
void (
const char *)> validator)
1185 (*deprecated_readline_begin_hook) (
"%s %s\n", prompt_arg,
1210 (*deprecated_readline_end_hook) ();
1221 gdb::function_view<
void (
const char *)> validator)
1316 const char *p, *last_word;
1322 p = *comname + strlen (*comname);
1323 while (p > *comname && isspace (p[-1]))
1325 while (p > *comname && !isspace (p[-1]))
1330 if (last_word != *comname)
1335 std::string
prefix (*comname, last_word - 1);
1336 const char *tem =
prefix.c_str ();
1340 error (_(
"\"%s\" is not a prefix command."),
prefix.c_str ());
1343 *comname = last_word;
1350 error (_(
"Junk in argument list: \"%s\""), p);
1380 const char *comfull;
1382 int hook_name_size = 0;
1384#define HOOK_STRING "hook-"
1386#define HOOK_POST_STRING "hookpost-"
1387#define HOOK_POST_LEN 9
1394 if (c && commands ==
nullptr)
1405 ||
query (_(
"Keeping subcommands of prefix command \"%s\".\n"
1406 "Redefine command \"%s\"? "), c->
name, c->
name));
1408 q =
query (_(
"Redefine command \"%s\"? "), c->
name);
1411 q =
query (_(
"Really redefine built-in command \"%s\"? "), c->
name);
1413 error (_(
"Command \"%s\" not redefined."), c->
name);
1436 if (!hookc && commands ==
nullptr)
1438 warning (_(
"Your new `%s' command does not "
1439 "hook any existing command."),
1441 if (!
query (_(
"Proceed? ")))
1442 error (_(
"Not confirmed."));
1446 comname = xstrdup (comname);
1449 if (commands ==
nullptr)
1452 = string_printf (
"Type commands for definition of \"%s\".", comfull);
1464 ? c->
doc : xstrdup (
"User-defined."), list);
1469 if (c_subcommands !=
nullptr)
1495 internal_error (_(
"bad switch"));
1515 const char *comfull;
1522 error (_(
"Undefined command: \"%s\"."), comfull);
1527 if (
alias ==
nullptr)
1528 error (_(
"Command \"%s\" is built-in."), comfull);
1530 error (_(
"Alias \"%s\" is built-in."), comfull);
1535 if (
alias !=
nullptr)
1540 if (commands ==
nullptr)
1543 = string_printf (
"Type documentation for \"%s\".", comfull);
1547 doclines = *commands;
1557 for (cl1 = doclines.get (); cl1; cl1 = cl1->
next)
1558 len += strlen (cl1->
line) + 1;
1560 doc = (
char *)
xmalloc (len + 1);
1563 for (cl1 = doclines.get (); cl1; cl1 = cl1->
next)
1565 strcat (doc, cl1->
line);
1587 const char *comfull;
1595 error (_(
"Command \"%s\" is built-in."), comfull);
1606 comname = xstrdup (comname);
1608 xstrdup (
"User-defined."), list);
1629 internal_error (_(
"called with NULL file pointer!"));
1631 scoped_restore restore_line_number
1633 scoped_restore restore_file
1634 = make_scoped_restore<std::string, const std::string &> (&
source_file_name,
1637 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
1643 catch (
const gdb_exception_error &e)
1647 throw_error (e.error,
1648 _(
"%s:%d: Error in sourced command file:\n%s"),
1680 const std::string prefixname = c->
prefixname ();
1700Document a user-defined command or user-defined alias.\n\
1701Give command or alias name as argument. Give documentation on following lines.\n\
1702End with a line of just \"end\"."));
1705Define a new command name. Command name is argument.\n\
1706Definition appears on following lines, one command per line.\n\
1707End with a line of just \"end\".\n\
1708Use the \"document\" command to give documentation for the new command.\n\
1709Commands defined in this way may accept an unlimited number of arguments\n\
1710accessed via $arg0 .. $argN. $argc tells how many arguments have\n\
1715Define or mark a command as a user-defined prefix command.\n\
1716User defined prefix commands can be used as prefix commands for\n\
1717other user defined commands.\n\
1718If the command already exists, it is changed to a prefix command."));
1722Execute nested commands WHILE the conditional expression is non zero.\n\
1723The conditional expression must follow the word `while' and must in turn be\n\
1724followed by a new line. The nested commands must be entered one per line,\n\
1725and should be terminated by the word `end'."));
1728Execute nested commands once IF the conditional expression is non zero.\n\
1729The conditional expression must follow the word `if' and must in turn be\n\
1730followed by a new line. The nested commands must be entered one per line,\n\
1731and should be terminated by the word 'else' or `end'. If an else clause\n\
1732is 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
int(*) void(*) void(* deprecated_readline_begin_hook)(const char *,...) ATTRIBUTE_FPTR_PRINTF_1
char *(* deprecated_readline_hook)(const char *)
const char * command_line_input(std::string &cmd_line_buffer, const char *, const char *)
struct value * evaluate_expression(struct expression *exp, struct type *expect_type)
std::unique_ptr< expression > expression_up
expression_up parse_expression(const char *, innermost_block_tracker *=nullptr, bool void_context_p=false)
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
union command_line::@27 control_u
struct command_line::@27::@28 compile
counted_command_line body_list_1
enum compile_i_scope_types scope
struct command_line * next
enum command_control_type control_type
~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)