prepare_for_detach: don't release scoped_restore at the end
authorPedro Alves <pedro@palves.net>
Mon, 11 Jan 2021 18:52:12 +0000 (18:52 +0000)
committerPedro Alves <pedro@palves.net>
Wed, 3 Feb 2021 01:15:05 +0000 (01:15 +0000)
After detaching from a process, the inf->detaching flag is
inadvertently left set to true.  If you afterwards reuse the same
inferior to start a new process, GDB will mishave...

The problem is that prepare_for_detach discards the scoped_restore at
the end, while the intention is for the flag to be set only for the
duration of prepare_for_detach.

This was already a bug in the original commit that added
prepare_for_detach, commit 24291992dac3 ("PR gdb/11321"), by yours
truly.  Back then, we still used cleanups, and the function called
discard_cleanups instead of do_cleanups, by mistake.

gdb/ChangeLog:

* infrun.c (prepare_for_detach): Don't release scoped_restore
before returning.

gdb/ChangeLog
gdb/infrun.c

index 920df3ec3125277e46c7d9315c5c255aaffbf150..256b9d080614175434f9a5a3211c3202626ef19e 100644 (file)
@@ -1,3 +1,8 @@
+2021-02-03  Pedro Alves  <pedro@palves.net>
+
+       * infrun.c (prepare_for_detach): Don't release scoped_restore
+       before returning.
+
 2021-02-03  Pedro Alves  <pedro@palves.net>
 
        * infrun.c (handle_one): New function, factored out from ...
index 51d60f4962959b9d30f81a4e1da0afba9ed25507..895f47457fd16a80fb073d6bc487d2240172cddd 100644 (file)
@@ -3607,13 +3607,8 @@ prepare_for_detach (void)
         at this point, and signals are passed directly to the
         inferior, so this must mean the process is gone.  */
       if (!ecs->wait_some_more)
-       {
-         restore_detaching.release ();
-         error (_("Program exited while detaching"));
-       }
+       error (_("Program exited while detaching"));
     }
-
-  restore_detaching.release ();
 }
 
 /* Wait for control to return from inferior to debugger.