Introduce bfd_set_filename
authorTom Tromey <tom@tromey.com>
Sun, 8 Sep 2019 17:38:24 +0000 (11:38 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 11 Sep 2019 13:02:46 +0000 (07:02 -0600)
This introduces a new bfd_set_filename function, which is then used in
various spots in gdb.  This allows for the removal of some casts.

bfd/ChangeLog
2019-09-11  Tom Tromey  <tom@tromey.com>

* opncls.c (bfd_set_filename): New function.
* bfd-in2.h: Regenerate.

gdb/ChangeLog
2019-09-11  Tom Tromey  <tom@tromey.com>

* symfile-mem.c (symbol_file_add_from_memory): Use
bfd_set_filename.
* solib-darwin.c (darwin_bfd_open): Use bfd_set_filename.
* solib-aix.c (solib_aix_bfd_open): Use bfd_set_filename.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/opncls.c
gdb/ChangeLog
gdb/solib-aix.c
gdb/solib-darwin.c
gdb/symfile-mem.c

index f498a91b88f9b54b11620ee8ab2c56654837a69e..ea0f06041b0e26f2e6fcd8e654d543f4340568e9 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-11  Tom Tromey  <tom@tromey.com>
+
+       * opncls.c (bfd_set_filename): New function.
+       * bfd-in2.h: Regenerate.
+
 2019-09-11  Alan Modra  <amodra@gmail.com>
 
        * targets.c (struct bfd_target): Add _bfd_group_name.
index dc9b5daf9460cf067369f0d6069106999fb48850..13445a1de71bd6cc44e13fece30c072fb8967ea9 100644 (file)
@@ -1193,6 +1193,8 @@ bfd_boolean bfd_fill_in_gnu_debuglink_section
 
 char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir);
 
+void bfd_set_filename (bfd *abfd, char *filename);
+
 /* Extracted from libbfd.c.  */
 
 /* Byte swapping macros for user section data.  */
index 07f89b9a4c152a1c69933cea62a84c5e2c4be3c3..d14dfe932066dbb964f9e14fb8d505ec298fc29b 100644 (file)
@@ -2089,3 +2089,23 @@ bfd_follow_build_id_debuglink (bfd *abfd, const char *dir)
                                   get_build_id_name,
                                   check_build_id_file, &build_id);
 }
+
+/*
+FUNCTION
+       bfd_set_filename
+
+SYNOPSIS
+       void bfd_set_filename (bfd *abfd, char *filename);
+
+DESCRIPTION
+       Set the filename of @var{abfd}.  The old filename, if any, is freed.
+       @var{filename} must be allocated using @code{xmalloc}.  After
+       this call, it is owned @var{abfd}.
+*/
+
+void
+bfd_set_filename (bfd *abfd, char *filename)
+{
+  free ((char *) abfd->filename);
+  abfd->filename = filename;
+}
index dace64e6be336a1d4d26c1d2d0793dcccbffebe3..e4b18fa1dece32f27dc9250c132c9825c30f67b6 100644 (file)
@@ -1,3 +1,10 @@
+2019-09-11  Tom Tromey  <tom@tromey.com>
+
+       * symfile-mem.c (symbol_file_add_from_memory): Use
+       bfd_set_filename.
+       * solib-darwin.c (darwin_bfd_open): Use bfd_set_filename.
+       * solib-aix.c (solib_aix_bfd_open): Use bfd_set_filename.
+
 2019-09-10  Tom Tromey  <tromey@adacore.com>
 
        * dwarf-index-write.c (write_psymbols): Extend error message.
index 2b5444293e26eaa6a2f7cde1899f1351880645de..0c8a18267c95103cec28afa6fc4d9b7ffad208d9 100644 (file)
@@ -643,10 +643,10 @@ solib_aix_bfd_open (const char *pathname)
      along with appended parenthesized member name in order to allow commands
      listing all shared libraries to display.  Otherwise, we would only be
      displaying the name of the archive member object.  */
-  xfree ((char *) bfd_get_filename (object_bfd.get ()));
-  object_bfd->filename = xstrprintf ("%s%s",
-                                    bfd_get_filename (archive_bfd.get ()),
-                                    sep);
+  bfd_set_filename (object_bfd.get (),
+                   xstrprintf ("%s%s",
+                               bfd_get_filename (archive_bfd.get ()),
+                               sep));
 
   return object_bfd;
 }
index 3dd30d2aa3c003a2385e9714117ba8364be05734..778c6d9f6173dd6f45fc25e32f1d222a71b5f07f 100644 (file)
@@ -670,8 +670,7 @@ darwin_bfd_open (const char *pathname)
   /* The current filename for fat-binary BFDs is a name generated
      by BFD, usually a string containing the name of the architecture.
      Reset its value to the actual filename.  */
-  xfree ((char *) bfd_get_filename (res.get ()));
-  res->filename = xstrdup (pathname);
+  bfd_set_filename (res.get (), xstrdup (pathname));
 
   return res;
 }
index 6d1deae1e0ec6d349573b8d1972a6854f90ab201..05542c13915cbe1fb269353a79b5737c418e5983 100644 (file)
@@ -101,11 +101,9 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr,
   /* Manage the new reference for the duration of this function.  */
   gdb_bfd_ref_ptr nbfd_holder = gdb_bfd_ref_ptr::new_reference (nbfd);
 
-  xfree ((char *) bfd_get_filename (nbfd));
   if (name == NULL)
-    nbfd->filename = xstrdup ("shared object read from target memory");
-  else
-    nbfd->filename = name;
+    name = xstrdup ("shared object read from target memory");
+  bfd_set_filename (nbfd, name);
 
   if (!bfd_check_format (nbfd, bfd_object))
     error (_("Got object file from memory but can't read symbols: %s."),
This page took 0.034829 seconds and 4 git commands to generate.