This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file


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-27  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(-)

diff --git a/gdb/gcore.c b/gdb/gcore.c
index 0e4596241b7..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 (const struct gdb_exception &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.
-- 
2.17.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]