summaryrefslogtreecommitdiff
path: root/gdb/gcore.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2013-08-09 15:30:48 +0000
committerPedro Alves <palves@redhat.com>2013-08-09 15:30:48 +0000
commit6669a858252514823c40915027816d24c5f5e180 (patch)
treec83e48f7ee5c13c0b4cb77238a088445fd20638a /gdb/gcore.c
parenta19a342155f0f8b7d511f8721fbe1b3954ed2493 (diff)
downloadgdb-6669a858252514823c40915027816d24c5f5e180.tar.gz
gcore: Make tilde-expanded filename visible.
Most commands in GDB show the tilde-expanded filename in user visible output. This makes gcore behave the same. Before: (gdb) generate-core-file ~/a/b Failed to open '~/a/b' for output. (gdb) generate-core-file ~/core Saved corefile ~/core After: (gdb) generate-core-file ~/a/b Failed to open '/home/pedro/a/b' for output. (gdb) generate-core-file ~/core Saved corefile /home/pedro/core Tested on x86_64 Fedora 17. gdb/ 2013-08-09 Pedro Alves <palves@redhat.com> * gcore.c (create_gcore_bfd): Don't use tilde_expand here. (gcore_command): Use tilde_expand here, and when showing the filename to the user, show the expanded version.
Diffstat (limited to 'gdb/gcore.c')
-rw-r--r--gdb/gcore.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 9c83ec82f89..a4bb9ca6493 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -52,12 +52,7 @@ static int gcore_memory_sections (bfd *);
bfd *
create_gcore_bfd (const char *filename)
{
- char *fullname;
- bfd *obfd;
-
- fullname = tilde_expand (filename);
- obfd = gdb_bfd_openw (fullname, default_gcore_target ());
- xfree (fullname);
+ bfd *obfd = gdb_bfd_openw (filename, default_gcore_target ());
if (!obfd)
error (_("Failed to open '%s' for output."), filename);
@@ -127,8 +122,9 @@ do_bfd_delete_cleanup (void *arg)
static void
gcore_command (char *args, int from_tty)
{
- struct cleanup *old_chain;
- char *corefilename, corefilename_buffer[40];
+ struct cleanup *filename_chain;
+ struct cleanup *bfd_chain;
+ char *corefilename;
bfd *obfd;
/* No use generating a corefile without a target process. */
@@ -136,14 +132,13 @@ gcore_command (char *args, int from_tty)
noprocess ();
if (args && *args)
- corefilename = args;
+ corefilename = tilde_expand (args);
else
{
/* Default corefile name is "core.PID". */
- xsnprintf (corefilename_buffer, sizeof (corefilename_buffer),
- "core.%d", PIDGET (inferior_ptid));
- corefilename = corefilename_buffer;
+ corefilename = xstrprintf ("core.%d", PIDGET (inferior_ptid));
}
+ filename_chain = make_cleanup (xfree, corefilename);
if (info_verbose)
fprintf_filtered (gdb_stdout,
@@ -153,16 +148,17 @@ gcore_command (char *args, int from_tty)
obfd = create_gcore_bfd (corefilename);
/* Need a cleanup that will close and delete the file. */
- old_chain = make_cleanup (do_bfd_delete_cleanup, obfd);
+ bfd_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);
+ discard_cleanups (bfd_chain);
gdb_bfd_unref (obfd);
+
+ fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename);
+ do_cleanups (filename_chain);
}
static unsigned long