- if (note_data != NULL && note_size != 0)
- {
- if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size))
- warning (_("writing note section (%s)"),
- bfd_errmsg (bfd_get_error ()));
- }
+ if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size))
+ warning (_("writing note section (%s)"), bfd_errmsg (bfd_get_error ()));
+
+ do_cleanups (cleanup);
+}
+
+/* write_gcore_file -- helper for gcore_command (exported).
+ Compose and write the corefile data to the core file. */
+
+void
+write_gcore_file (bfd *obfd)
+{
+ volatile struct gdb_exception except;
+
+ target_prepare_to_generate_core ();
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ write_gcore_file_1 (obfd);
+
+ target_done_generating_core ();
+
+ if (except.reason < 0)
+ throw_exception (except);
+}
+
+static void
+do_bfd_delete_cleanup (void *arg)
+{
+ bfd *obfd = arg;
+ const char *filename = obfd->filename;
+
+ gdb_bfd_unref (arg);
+ unlink (filename);