This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 15/22] Use std::string in macho_symfile_read_all_oso


This changes macho_symfile_read_all_oso to use std::string.  This
avoids a cleanup.

2016-09-26  Tom Tromey  <tom@tromey.com>

	* machoread.c (macho_symfile_read_all_oso): Use std::string.
---
 gdb/ChangeLog   |  4 ++++
 gdb/machoread.c | 20 +++++++-------------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 42101fc..3744387 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2016-09-26  Tom Tromey  <tom@tromey.com>
 
+	* machoread.c (macho_symfile_read_all_oso): Use std::string.
+
+2016-09-26  Tom Tromey  <tom@tromey.com>
+
 	* cli/cli-dump.c (dump_memory_to_file): Use std::vector.
 	(restore_binary_file): Likewise.
 
diff --git a/gdb/machoread.c b/gdb/machoread.c
index df0333a..eefc1bb 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -33,6 +33,7 @@
 #include "psympriv.h"
 #include "complaints.h"
 #include "gdb_bfd.h"
+#include <string>
 
 /* If non-zero displays debugging message.  */
 static unsigned int mach_o_debug_level = 0;
@@ -636,7 +637,6 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
   int ix;
   VEC (oso_el) *vec = *oso_vector_ptr;
   oso_el *oso;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
 
   /* Sort oso by name so that files from libraries are gathered.  */
   qsort (VEC_address (oso_el, vec), VEC_length (oso_el, vec),
@@ -652,37 +652,33 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
 	{
 	  bfd *archive_bfd;
 	  bfd *member_bfd;
-	  char *archive_name = XNEWVEC (char, pfx_len + 1);
           int last_ix;
           oso_el *oso2;
           int ix2;
 
-	  memcpy (archive_name, oso->name, pfx_len);
-	  archive_name[pfx_len] = '\0';
-
-	  make_cleanup (xfree, archive_name);
+	  std::string archive_name (oso->name, pfx_len);
 
           /* Compute number of oso for this archive.  */
           for (last_ix = ix;
                VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++)
             {
-              if (strncmp (oso2->name, archive_name, pfx_len) != 0)
+              if (strncmp (oso2->name, archive_name.c_str (), pfx_len) != 0)
                 break;
             }
 
 	  /* Open the archive and check the format.  */
-	  archive_bfd = gdb_bfd_open (archive_name, gnutarget, -1);
+	  archive_bfd = gdb_bfd_open (archive_name.c_str (), gnutarget, -1);
 	  if (archive_bfd == NULL)
 	    {
 	      warning (_("Could not open OSO archive file \"%s\""),
-		       archive_name);
+		       archive_name.c_str ());
               ix = last_ix;
 	      continue;
 	    }
 	  if (!bfd_check_format (archive_bfd, bfd_archive))
 	    {
 	      warning (_("OSO archive file \"%s\" not an archive."),
-		       archive_name);
+		       archive_name.c_str ());
 	      gdb_bfd_unref (archive_bfd);
               ix = last_ix;
 	      continue;
@@ -693,7 +689,7 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
 	  if (member_bfd == NULL)
 	    {
 	      warning (_("Could not read archive members out of "
-			 "OSO archive \"%s\""), archive_name);
+			 "OSO archive \"%s\""), archive_name.c_str ());
 	      gdb_bfd_unref (archive_bfd);
               ix = last_ix;
 	      continue;
@@ -757,8 +753,6 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
           ix++;
         }
     }
-
-  do_cleanups (cleanup);
 }
 
 /* DSYM (debug symbols) files contain the debug info of an executable.
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]