This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 19/20] Use SCOPE_EXIT in write_gcore_file
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Wed, 13 Feb 2019 14:29:26 -0700
- Subject: [PATCH 19/20] Use SCOPE_EXIT in write_gcore_file
- References: <20190213212927.9474-1-tom@tromey.com>
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(-)
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.
--
2.17.2