static void gcore_command (char *args, int from_tty) { struct cleanup *filename_chain; struct cleanup *bfd_chain; char *corefilename; bfd *obfd; /* No use generating a corefile without a target process. */ if (!target_has_execution) noprocess (); if (args && *args) corefilename = tilde_expand (args); else { /* Default corefile name is "core.PID". */ corefilename = xstrprintf ("core.%d", ptid_get_pid (inferior_ptid)); } filename_chain = make_cleanup (xfree, corefilename); if (info_verbose) fprintf_filtered (gdb_stdout, "Opening corefile '%s' for output.\n", corefilename); /* Open the output file. */ obfd = create_gcore_bfd (corefilename); /* Need a cleanup that will close and delete the file. */ bfd_chain = make_cleanup (do_bfd_delete_cleanup, obfd); /* Call worker function. */ write_gcore_file (obfd); /* Succeeded. */ discard_cleanups (bfd_chain); gdb_bfd_unref (obfd); fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename); do_cleanups (filename_chain); }
static void gcore_command (char *args, int from_tty) { struct cleanup *old_chain; char *corefilename, corefilename_buffer[40]; bfd *obfd; /* No use generating a corefile without a target process. */ if (!target_has_execution) noprocess (); if (args && *args) corefilename = args; else { /* Default corefile name is "core.PID". */ xsnprintf (corefilename_buffer, sizeof (corefilename_buffer), "core.%d", PIDGET (inferior_ptid)); corefilename = corefilename_buffer; } if (info_verbose) fprintf_filtered (gdb_stdout, "Opening corefile '%s' for output.\n", corefilename); /* Open the output file. */ obfd = create_gcore_bfd (corefilename); /* 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); /* Succeeded. */ fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename); discard_cleanups (old_chain); gdb_bfd_unref (obfd); }