diff options
Diffstat (limited to 'gdb/cli/cli-script.c')
-rw-r--r-- | gdb/cli/cli-script.c | 157 |
1 files changed, 53 insertions, 104 deletions
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 5674404..37466fd 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -147,7 +147,8 @@ build_command_line (enum command_control_type type, const char *args) { struct command_line *cmd; - if (args == NULL && (type == if_control || type == while_control)) + if ((args == NULL || *args == '\0') + && (type == if_control || type == while_control)) error (_("if/while commands require arguments.")); gdb_assert (args != NULL); @@ -339,23 +340,36 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd, /* Handle pre-post hooks. */ -static void -clear_hook_in_cleanup (void *data) +class scoped_restore_hook_in { - struct cmd_list_element *c = (struct cmd_list_element *) data; +public: - c->hook_in = 0; /* Allow hook to work again once it is complete. */ -} + scoped_restore_hook_in (struct cmd_list_element *c) + : m_cmd (c) + { + } + + ~scoped_restore_hook_in () + { + m_cmd->hook_in = 0; + } + + scoped_restore_hook_in (const scoped_restore_hook_in &) = delete; + scoped_restore_hook_in &operator= (const scoped_restore_hook_in &) = delete; + +private: + + struct cmd_list_element *m_cmd; +}; void execute_cmd_pre_hook (struct cmd_list_element *c) { if ((c->hook_pre) && (!c->hook_in)) { - struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c); + scoped_restore_hook_in restore_hook (c); c->hook_in = 1; /* Prevent recursive hooking. */ execute_user_command (c->hook_pre, (char *) 0); - do_cleanups (cleanups); } } @@ -364,34 +378,18 @@ execute_cmd_post_hook (struct cmd_list_element *c) { if ((c->hook_post) && (!c->hook_in)) { - struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c); - + scoped_restore_hook_in restore_hook (c); c->hook_in = 1; /* Prevent recursive hooking. */ execute_user_command (c->hook_post, (char *) 0); - do_cleanups (cleanups); } } -/* Execute the command in CMD. */ -static void -do_restore_user_call_depth (void * call_depth) -{ - int *depth = (int *) call_depth; - - (*depth)--; - if ((*depth) == 0) - in_user_command = 0; -} - - void execute_user_command (struct cmd_list_element *c, char *args) { struct ui *ui = current_ui; struct command_line *cmdlines; - struct cleanup *old_chain; enum command_control_type ret; - static int user_call_depth = 0; extern unsigned int max_user_call_depth; cmdlines = c->user_commands; @@ -401,23 +399,18 @@ execute_user_command (struct cmd_list_element *c, char *args) scoped_user_args_level push_user_args (args); - if (++user_call_depth > max_user_call_depth) + if (user_args_stack.size () > max_user_call_depth) error (_("Max user call depth exceeded -- command aborted.")); - old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth); - /* Set the instream to 0, indicating execution of a user-defined function. */ - make_cleanup (do_restore_instream_cleanup, ui->instream); - ui->instream = NULL; - - /* Also set the global in_user_command, so that NULL instream is - not confused with Insight. */ - in_user_command = 1; + scoped_restore restore_instream + = make_scoped_restore (&ui->instream, nullptr); scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); - command_nest_depth++; + scoped_restore save_nesting + = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); while (cmdlines) { ret = execute_control_command (cmdlines); @@ -428,8 +421,6 @@ execute_user_command (struct cmd_list_element *c, char *args) } cmdlines = cmdlines->next; } - command_nest_depth--; - do_cleanups (old_chain); } /* This function is called every time GDB prints a prompt. It ensures @@ -548,9 +539,9 @@ execute_control_command (struct command_line *cmd) current = *cmd->body_list; while (current) { - command_nest_depth++; + scoped_restore save_nesting + = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); ret = execute_control_command (current); - command_nest_depth--; /* If we got an error, or a "break" command, then stop looping. */ @@ -607,9 +598,9 @@ execute_control_command (struct command_line *cmd) /* Execute commands in the given arm. */ while (current) { - command_nest_depth++; + scoped_restore save_nesting + = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); ret = execute_control_command (current); - command_nest_depth--; /* If we got an error, get out. */ if (ret != simple_control) @@ -908,7 +899,7 @@ line_first_arg (const char *p) { const char *first_arg = p + find_command_name_length (p); - return skip_spaces_const (first_arg); + return skip_spaces (first_arg); } /* Process one input line. If the command is an "end", return such an @@ -952,7 +943,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands, const char *cmd_name = p; struct cmd_list_element *cmd = lookup_cmd_1 (&cmd_name, cmdlist, NULL, 1); - cmd_name = skip_spaces_const (cmd_name); + cmd_name = skip_spaces (cmd_name); bool inline_cmd = *cmd_name != '\0'; /* If commands are parsed, we skip initial spaces. Otherwise, @@ -1178,12 +1169,6 @@ recurse_read_control_structure (char * (*read_next_line_func) (void), return ret; } -static void -restore_interp (void *arg) -{ - interp_set_temp (interp_name ((struct interp *)arg)); -} - /* Read lines from the input stream and accumulate them in a chain of struct command_line's, which is then returned. For input from a terminal, the special command "end" is used to mark the end of the @@ -1223,12 +1208,10 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, validator, closure); else { - struct interp *old_interp = interp_set_temp (INTERP_CONSOLE); - struct cleanup *old_chain = make_cleanup (restore_interp, old_interp); + scoped_restore_interp interp_restorer (INTERP_CONSOLE); head = read_command_lines_1 (read_next_line, parse_commands, validator, closure); - do_cleanups (old_chain); } if (from_tty && input_interactive_p (current_ui) @@ -1499,12 +1482,6 @@ define_command (char *comname, int from_tty) comname = xstrdup (comname); - /* If the rest of the commands will be case insensitive, this one - should behave in the same manner. */ - for (tem = comname; *tem; tem++) - if (isupper (*tem)) - *tem = tolower (*tem); - xsnprintf (tmpbuf, sizeof (tmpbuf), "Type commands for definition of \"%s\".", comfull); command_line_up cmds = read_command_lines (tmpbuf, from_tty, 1, 0, 0); @@ -1585,58 +1562,34 @@ document_command (char *comname, int from_tty) } } -struct source_cleanup_lines_args -{ - int old_line; - const char *old_file; -}; - -static void -source_cleanup_lines (void *args) -{ - struct source_cleanup_lines_args *p = - (struct source_cleanup_lines_args *) args; - - source_line_number = p->old_line; - source_file_name = p->old_file; -} - /* Used to implement source_command. */ void script_from_file (FILE *stream, const char *file) { - struct cleanup *old_cleanups; - struct source_cleanup_lines_args old_lines; - if (stream == NULL) internal_error (__FILE__, __LINE__, _("called with NULL file pointer!")); - old_lines.old_line = source_line_number; - old_lines.old_file = source_file_name; - old_cleanups = make_cleanup (source_cleanup_lines, &old_lines); - source_line_number = 0; - source_file_name = file; + scoped_restore restore_line_number + = make_scoped_restore (&source_line_number, 0); + scoped_restore resotre_file + = make_scoped_restore (&source_file_name, file); - { - scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); - - TRY - { - read_command_file (stream); - } - CATCH (e, RETURN_MASK_ERROR) - { - /* Re-throw the error, but with the file name information - prepended. */ - throw_error (e.error, - _("%s:%d: Error in sourced command file:\n%s"), - source_file_name, source_line_number, e.message); - } - END_CATCH - } + scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); - do_cleanups (old_cleanups); + TRY + { + read_command_file (stream); + } + CATCH (e, RETURN_MASK_ERROR) + { + /* Re-throw the error, but with the file name information + prepended. */ + throw_error (e.error, + _("%s:%d: Error in sourced command file:\n%s"), + source_file_name, source_line_number, e.message); + } + END_CATCH } /* Print the definition of user command C to STREAM. Or, if C is a @@ -1668,10 +1621,6 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name, fputs_filtered ("\n", stream); } - - -initialize_file_ftype _initialize_cli_script; - void _initialize_cli_script (void) { |