}
}
-/* 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;
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);
}
cmdlines = cmdlines->next;
}
- command_nest_depth--;
- do_cleanups (old_chain);
}
/* This function is called every time GDB prints a prompt. It ensures
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. */
/* 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)
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);
}
}
\f
-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 save_async = make_scoped_restore (¤t_ui->async, 0);
+ scoped_restore restore_line_number
+ = make_scoped_restore (&source_line_number, 0);
+ scoped_restore resotre_file
+ = make_scoped_restore (&source_file_name, file);
- 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