[RFA,18/23] Use a scoped_restore for command_nest_depth

Message ID 20170503224626.2818-19-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey May 3, 2017, 10:46 p.m. UTC
  This changes a couple of places to use a scoped_restore when
manipulating command_nest_depth.

2017-05-02  Tom Tromey  <tom@tromey.com>

	* cli/cli-script.c (execute_user_command)
	(execute_control_command): Use scoped_restore.
---
 gdb/ChangeLog        |  5 +++++
 gdb/cli/cli-script.c | 12 ++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)
  

Comments

Pedro Alves June 5, 2017, 1:38 p.m. UTC | #1
On 05/03/2017 11:46 PM, Tom Tromey wrote:
> This changes a couple of places to use a scoped_restore when
> manipulating command_nest_depth.
> 
> 2017-05-02  Tom Tromey  <tom@tromey.com>
> 
> 	* cli/cli-script.c (execute_user_command)
> 	(execute_control_command): Use scoped_restore.

OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 873b404..a27feda 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2017-05-02  Tom Tromey  <tom@tromey.com>
 
+	* cli/cli-script.c (execute_user_command)
+	(execute_control_command): Use scoped_restore.
+
+2017-05-02  Tom Tromey  <tom@tromey.com>
+
 	* cli/cli-script.c (do_restore_user_call_depth): Remove.
 	(execute_user_command): Use scoped_restore.
 
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 7f90d27..c0e6716 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -401,7 +401,8 @@  execute_user_command (struct cmd_list_element *c, char *args)
 
   scoped_restore save_async = make_scoped_restore (&current_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);
@@ -412,7 +413,6 @@  execute_user_command (struct cmd_list_element *c, char *args)
 	}
       cmdlines = cmdlines->next;
     }
-  command_nest_depth--;
   do_cleanups (old_chain);
 }
 
@@ -532,9 +532,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.  */
@@ -591,9 +591,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)