[commit] Delete partial core file if gcore fails
Daniel Jacobowitz
dan@codesourcery.com
Tue Feb 16 20:48:00 GMT 2010
Noticed while tracking down a bug in a local patch. There's a FIXME
in gcore.c that says we should delete core files on error; I agree,
and it's easy to do.
Tested on arm-none-eabi (which no longer leaves empty core files
around after saying that gcore is not supported) and on x86_64-linux;
committed to trunk.
--
Daniel Jacobowitz
CodeSourcery
2010-02-16 Daniel Jacobowitz <dan@codesourcery.com>
gdb/
* gcore.c (do_bfd_delete_cleanup): New function.
(gcore_command): Use it. Discard the cleanup after success.
(gcore_copy_callback): Delete dead code.
diff -urp gdb-merged-orig/gdb/gcore.c gdb-merged/gdb/gcore.c
--- gdb-merged-orig/gdb/gcore.c 2010-02-11 13:05:09.000000000 -0800
+++ gdb-merged/gdb/gcore.c 2010-02-14 09:50:42.000000000 -0800
@@ -102,6 +102,16 @@ write_gcore_file (bfd *obfd)
}
}
+static void
+do_bfd_delete_cleanup (void *arg)
+{
+ bfd *obfd = arg;
+ const char *filename = obfd->filename;
+
+ bfd_close (arg);
+ unlink (filename);
+}
+
/* gcore_command -- implements the 'gcore' command.
Generate a core file from the inferior process. */
@@ -132,8 +142,8 @@ gcore_command (char *args, int from_tty)
/* Open the output file. */
obfd = create_gcore_bfd (corefilename);
- /* Need a cleanup that will close the file (FIXME: delete it?). */
- old_chain = make_cleanup_bfd_close (obfd);
+ /* Need a cleanup that will close and delete the file. */
+ old_chain = make_cleanup (do_bfd_delete_cleanup, obfd);
/* Call worker function. */
write_gcore_file (obfd);
@@ -141,9 +151,8 @@ gcore_command (char *args, int from_tty)
/* Succeeded. */
fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename);
- /* Clean-ups will close the output file and free malloc memory. */
- do_cleanups (old_chain);
- return;
+ discard_cleanups (old_chain);
+ bfd_close (obfd);
}
static unsigned long
@@ -521,9 +530,6 @@ gcore_copy_callback (bfd *obfd, asection
size = min (total_size, MAX_COPY_BYTES);
memhunk = xmalloc (size);
- /* ??? This is crap since xmalloc should never return NULL. */
- if (memhunk == NULL)
- error (_("Not enough memory to create corefile."));
old_chain = make_cleanup (xfree, memhunk);
while (total_size > 0)
More information about the Gdb-patches
mailing list