[19/20] Use SCOPE_EXIT in write_gcore_file
Commit Message
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(-)
@@ -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.