41 void (*validator)(
char *,
void *),
54 static int command_nest_depth = 1;
57 static int suppress_next_print_command_trace = 0;
60 #define MAXUSERARGS 10
109 error (
_(
"if/while commands require arguments."));
121 cmd->
line = xstrdup (args);
133 struct cleanup *old_chain = NULL;
144 warning (
_(
"Error reading in canned sequence of commands."));
347 int *depth = call_depth;
361 static int user_call_depth = 0;
371 if (++user_call_depth > max_user_call_depth)
372 error (
_(
"Max user call depth exceeded -- command aborted."));
388 command_nest_depth++;
394 warning (
_(
"Error executing canned sequence of commands."));
397 cmdlines = cmdlines->
next;
399 command_nest_depth--;
409 command_nest_depth = 1;
412 suppress_next_print_command_trace = 0;
428 if (suppress_next_print_command_trace)
430 suppress_next_print_command_trace = 0;
450 struct value *val_mark;
489 int len = strlen (cmd->
line) + 7;
490 char *
buffer = alloca (len);
527 command_nest_depth++;
529 command_nest_depth--;
545 current = current->
next;
558 int len = strlen (cmd->
line) + 4;
559 char *
buffer = alloca (len);
590 command_nest_depth++;
592 command_nest_depth--;
599 current = current->
next;
632 warning (
_(
"Invalid control type in canned commands structure."));
647 suppress_next_print_command_trace = 1;
708 _(
"arg_cleanup called with no user args.\n"));
723 unsigned int arg_count = 0;
726 memset (args, 0,
sizeof (
struct user_args));
746 error (
_(
"user defined function may only have %d arguments."),
750 while (*p ==
' ' || *p ==
'\t')
760 if (((*p ==
' ' || *p ==
'\t')) && !squote && !dquote && !bsquote)
802 while ((p = strchr (p,
'$')))
805 && (isdigit (p[4]) || p[4] ==
'c'))
819 char *p, *save_line, *new_line;
825 return xstrdup (line);
843 error (
_(
"Missing argument %d in user function."), i);
854 len += strlen (line);
857 new_line = (
char *)
xmalloc (len + 1);
858 if (new_line == NULL)
865 save_line = new_line;
871 memcpy (new_line, line, p - line);
872 new_line += p -
line;
898 strcpy (new_line, line);
925 memset (body_list + n, 0,
sizeof (
struct command_line *) * (new_length - n));
939 char *prompt_ptr, control_prompt[256];
942 if (control_level >= 254)
943 error (
_(
"Control nesting too deep!"));
949 control_prompt[i] =
' ';
950 control_prompt[i] =
'>';
951 control_prompt[i + 1] =
'\0';
952 prompt_ptr = (
char *) &control_prompt[0];
970 void (*validator)(
char *,
void *),
void *closure)
981 p_end = p + strlen (p);
982 while (p_end > p && (p_end[-1] ==
' ' || p_end[-1] ==
'\t'))
987 while (p_start < p_end && (*p_start ==
' ' || *p_start ==
'\t'))
992 if (p_end - p_start == 3 &&
startswith (p_start,
"end"))
1005 if (p_end == p || p[0] ==
'#')
1009 if (p_end - p == 4 &&
startswith (p,
"else"))
1014 if ((p_end - p >= 14 &&
startswith (p,
"while-stepping"))
1015 || (p_end - p >= 8 &&
startswith (p,
"stepping"))
1031 else if (p_end - p > 5 &&
startswith (p,
"while"))
1036 while (first_arg < p_end && isspace (*first_arg))
1040 else if (p_end - p > 2 &&
startswith (p,
"if"))
1045 while (first_arg < p_end && isspace (*first_arg))
1049 else if (p_end - p >= 8 &&
startswith (p,
"commands"))
1054 while (first_arg < p_end && isspace (*first_arg))
1058 else if (p_end - p == 6 &&
startswith (p,
"python"))
1064 else if (p_end - p == 6 &&
startswith (p,
"compile"))
1072 else if (p_end - p == 5 &&
startswith (p,
"guile"))
1077 else if (p_end - p == 10 &&
startswith (p,
"loop_break"))
1081 (*command)->next = NULL;
1082 (*command)->line = NULL;
1084 (*command)->body_count = 0;
1085 (*command)->body_list = NULL;
1087 else if (p_end - p == 13 &&
startswith (p,
"loop_continue"))
1091 (*command)->next = NULL;
1092 (*command)->line = NULL;
1094 (*command)->body_count = 0;
1095 (*command)->body_list = NULL;
1101 if (!parse_commands || not_handled)
1106 (*command)->next = NULL;
1107 (*command)->line =
savestring (p, p_end - p);
1109 (*command)->body_count = 0;
1110 (*command)->body_list = NULL;
1118 validator ((*command)->line, closure);
1139 void (*validator)(
char *,
void *),
1142 int current_body, i;
1152 error (
_(
"Recursed on a simple control type."));
1155 error (
_(
"Allocated body is smaller than this command type needs."));
1167 validator, closure);
1192 && current_body == 1)
1213 for (i = 1; i < current_body; i++)
1228 validator, closure);
1256 #define END_MESSAGE "End with a line saying just \"end\"."
1260 void (*validator)(
char *,
void *),
void *closure)
1269 (*deprecated_readline_begin_hook) (
"%s %s\n", prompt_arg,
1284 validator, closure);
1291 validator, closure);
1297 (*deprecated_readline_end_hook) ();
1307 void (*validator)(
char *,
void *),
void *closure)
1321 validator, closure);
1343 validator, closure);
1420 result->
line = xstrdup (cmds->
line);
1450 char *p, *last_word;
1456 p = *comname + strlen (*comname);
1457 while (p > *comname && isspace (p[-1]))
1459 while (p > *comname && !isspace (p[-1]))
1464 if (last_word != *comname)
1468 const char *tem = *comname;
1471 saved_char = last_word[-1];
1472 last_word[-1] =
'\0';
1476 error (
_(
"\"%s\" is not a prefix command."), *comname);
1479 last_word[-1] = saved_char;
1480 *comname = last_word;
1486 if (!isalnum (*p) && *p !=
'-' && *p !=
'_')
1487 error (
_(
"Junk in argument list: \"%s\""), p);
1503 #define MAX_TMPBUF 128
1512 char *tem, *comfull;
1516 int hook_name_size = 0;
1518 #define HOOK_STRING "hook-"
1520 #define HOOK_POST_STRING "hookpost-"
1521 #define HOOK_POST_LEN 9
1529 if (c && strcmp (comname, c->
name) != 0)
1537 q =
query (
_(
"Redefine command \"%s\"? "), c->
name);
1539 q =
query (
_(
"Really redefine built-in command \"%s\"? "), c->
name);
1541 error (
_(
"Command \"%s\" not redefined."), c->
name);
1550 hook_type = CMD_PRE_HOOK;
1555 hook_type = CMD_POST_HOOK;
1559 if (hook_type != CMD_NO_HOOK)
1562 tem_c = comname + hook_name_size;
1563 hookc =
lookup_cmd (&tem_c, *list,
"", -1, 0);
1564 if (hookc && strcmp (comname + hook_name_size, hookc->
name) != 0)
1568 warning (
_(
"Your new `%s' command does not "
1569 "hook any existing command."),
1571 if (!
query (
_(
"Proceed? ")))
1572 error (
_(
"Not confirmed."));
1576 comname = xstrdup (comname);
1580 for (tem = comname; *tem; tem++)
1582 *tem = tolower (*tem);
1585 "Type commands for definition of \"%s\".", comfull);
1593 ? c->
doc : xstrdup (
"User-defined."), list);
1634 error (
_(
"Command \"%s\" is built-in."), comfull);
1636 xsnprintf (tmpbuf,
sizeof (tmpbuf),
"Type documentation for \"%s\".",
1648 for (cl1 = doclines; cl1; cl1 = cl1->
next)
1649 len += strlen (cl1->
line) + 1;
1651 doc = (
char *)
xmalloc (len + 1);
1654 for (cl1 = doclines; cl1; cl1 = cl1->
next)
1656 strcat (doc, cl1->
line);
1692 internal_error (__FILE__, __LINE__,
_(
"called with NULL file pointer!"));
1714 _(
"%s:%d: Error in sourced command file:\n%s"),
1760 Document a user-defined command.\n\
1761 Give command name as argument. Give documentation on following lines.\n\
1762 End with a line of just \"end\"."));
1764 Define a new command name. Command name is argument.\n\
1765 Definition appears on following lines, one command per line.\n\
1766 End with a line of just \"end\".\n\
1767 Use the \"document\" command to give documentation for the new command.\n\
1768 Commands defined in this way may have up to ten arguments."));
1771 Execute nested commands WHILE the conditional expression is non zero.\n\
1772 The conditional expression must follow the word `while' and must in turn be\n\
1773 followed by a new line. The nested commands must be entered one per line,\n\
1774 and should be terminated by the word `end'."));
1777 Execute nested commands once IF the conditional expression is non zero.\n\
1778 The conditional expression must follow the word `if' and must in turn be\n\
1779 followed by a new line. The nested commands must be entered one per line,\n\
1780 and should be terminated by the word 'else' or `end'. If an else clause\n\
1781 is used, the same rules apply to its nested commands as to the first ones."));
void error_no_arg(const char *why)
static void do_free_command_lines_cleanup(void *arg)
struct value * value_mark(void)
struct cmd_list_element * next
void eval_compile_command(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope, void *scope_data)
struct command_line::@48::@49 compile
union command_line::@48 control_u
void value_free_to_mark(struct value *mark)
void execute_cmd_pre_hook(struct cmd_list_element *c)
enum command_control_type execute_control_command_untraced(struct command_line *cmd)
void ui_out_spaces(struct ui_out *uiout, int numspaces)
static struct cmd_list_element ** validate_comname(char **comname)
void execute_user_command(struct cmd_list_element *c, char *args)
void warning(const char *fmt,...)
int query(const char *ctlstr,...)
struct command_line * read_command_lines_1(char *(*read_next_line_func)(void), int parse_commands, void(*validator)(char *, void *), void *closure)
struct cmd_list_element * hook_post
static void document_command(char *comname, int from_tty)
struct ui_file * gdb_stdout
void internal_error(const char *file, int line, const char *fmt,...)
struct cmd_list_element * hookee_post
enum command_control_type commands_from_control_command(char *arg, struct command_line *cmd)
struct cmd_list_element * cmdlist
void execute_command(char *, int)
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, char *cmdtype, int allow_unknown, int ignore_help_classes)
static struct command_line * build_command_line(enum command_control_type type, char *args)
static enum misc_command_type process_next_line(char *p, struct command_line **command, int parse_commands, void(*validator)(char *, void *), void *closure)
void ui_out_field_fmt(struct ui_out *uiout, const char *fldname, const char *format,...)
void ui_out_text(struct ui_out *uiout, const char *string)
static char * locate_arg(char *p)
void printf_filtered(const char *format,...)
struct user_args::@38 a[MAXUSERARGS]
struct command_line * user_commands
void null_cleanup(void *arg)
struct value * evaluate_expression(struct expression *exp)
struct command_line * get_command_line(enum command_control_type type, char *arg)
char * command_line_input(const char *, int, char *)
#define CATCH(EXCEPTION, MASK)
static void arg_cleanup(void *ignore)
struct cmd_list_element * hook_pre
struct cleanup * make_cleanup_restore_integer(int *variable)
const char * source_file_name
static char * read_next_line(void)
void(* hook_type)(const char *)
void initialize_file_ftype(void)
void eval_ext_lang_from_control_command(struct command_line *cmd)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
static void do_restore_user_call_depth(void *call_depth)
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
void free_current_contents(void *ptr)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static char * insert_args(char *line)
static int startswith(const char *string, const char *pattern)
static void user_defined_command(char *ignore, int from_tty)
static enum command_control_type recurse_read_control_structure(char *(*read_next_line_func)(void), struct command_line *current_cmd, void(*validator)(char *, void *), void *closure)
unsigned int max_user_call_depth
void printf_unfiltered(const char *format,...)
void print_command_lines(struct ui_out *uiout, struct command_line *cmd, unsigned int depth)
void script_from_file(FILE *stream, const char *file)
struct command_line * copy_command_lines(struct command_line *cmds)
struct expression * parse_expression(const char *)
initialize_file_ftype _initialize_cli_script
const char * interp_name(struct interp *interp)
int input_from_terminal_p(void)
void throw_exception(struct gdb_exception exception)
struct command_line * next
enum command_control_type control_type
void discard_cleanups(struct cleanup *old_chain)
void(* deprecated_readline_end_hook)(void)
void execute_cmd_post_hook(struct cmd_list_element *c)
static int multi_line_command_p(enum command_control_type type)
int xsnprintf(char *str, size_t size, const char *format,...)
void do_restore_instream_cleanup(void *stream)
static void source_cleanup_lines(void *args)
static void restore_interp(void *arg)
void(* deprecated_readline_begin_hook)(char *,...) ATTRIBUTE_FPTR_PRINTF_1
enum command_class theclass
struct user_args * user_args
struct cleanup * make_cleanup_free_command_lines(struct command_line **arg)
static struct cleanup * setup_user_args(char *p)
static int command_nest_depth
void reset_command_nest_depth(void)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
static void while_command(char *arg, int from_tty)
char * savestring(const char *ptr, size_t len)
static void clear_hook_in_cleanup(void *data)
static void if_command(char *arg, int from_tty)
struct cmd_list_element ** prefixlist
void show_user_1(struct cmd_list_element *c, const char *prefix, const char *name, struct ui_file *stream)
void ui_out_field_string(struct ui_out *uiout, const char *fldname, const char *string)
struct cmd_list_element * hookee_pre
static void define_command(char *comname, int from_tty)
void print_command_trace(const char *cmd)
void gdb_flush(struct ui_file *file)
struct ui_out * current_uiout
int value_true(struct value *val)
static void realloc_body_list(struct command_line *command, int new_length)
struct command_line ** body_list
int current_interp_named_p(const char *interp_name)
void error(const char *fmt,...)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
void throw_error(enum errors error, const char *fmt,...)
void free_command_lines(struct command_line **lptr)
enum command_control_type execute_control_command(struct command_line *cmd)
void do_cleanups(struct cleanup *old_chain)
struct command_line * read_command_lines(char *prompt_arg, int from_tty, int parse_commands, void(*validator)(char *, void *), void *closure)
struct interp * interp_set_temp(const char *name)
void read_command_file(FILE *stream)
const ULONGEST const LONGEST len
char *(* deprecated_readline_hook)(const char *)