[19/20] Use SCOPE_EXIT in write_gcore_file

Message ID 20190213212927.9474-20-tom@tromey.com
State Superseded
Headers show
Series
  • Remove cleanups
Related show

Commit Message

Tom Tromey Feb. 13, 2019, 9:29 p.m.
This replaces a try/catch in write_gcore_file with a use of SCOPE_EXIT
instead.  I find that this is simpler to understand.

gdb/ChangeLog
2019-02-13  Tom Tromey  <tom@tromey.com>

	* gcore.c (write_gcore_file): Use SCOPE_EXIT.
---
 gdb/ChangeLog |  4 ++++
 gdb/gcore.c   | 19 +++----------------
 2 files changed, 7 insertions(+), 16 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/gcore.c b/gdb/gcore.c
index 0684ac17c33..21d9ee88671 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -37,6 +37,7 @@ 
 #include <algorithm>
 #include "common/gdb_unlinker.h"
 #include "common/byte-vector.h"
+#include "common/scope-exit.h"
 
 /* The largest amount of memory to read from the target at once.  We
    must throttle it to limit the amount of memory used by GDB during
@@ -114,23 +115,9 @@  write_gcore_file_1 (bfd *obfd)
 void
 write_gcore_file (bfd *obfd)
 {
-  struct gdb_exception except = exception_none;
-
   target_prepare_to_generate_core ();
-
-  try
-    {
-      write_gcore_file_1 (obfd);
-    }
-  catch (struct gdb_exception_RETURN_MASK_ALL &e)
-    {
-      except = e;
-    }
-
-  target_done_generating_core ();
-
-  if (except.reason < 0)
-    throw_exception (except);
+  SCOPE_EXIT { target_done_generating_core (); };
+  write_gcore_file_1 (obfd);
 }
 
 /* gcore_command -- implements the 'gcore' command.