Use RAII to save and restore scalars
[deliverable/binutils-gdb.git] / gdb / machoread.c
index 28e0640c407afe87b108387aeb09e6ac44952188..2eff5346f50300efbfc2c4fc3d83ecb73860dfe3 100644 (file)
@@ -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;
@@ -162,7 +163,6 @@ macho_symtab_read (struct objfile *objfile,
                   VEC (oso_el) **oso_vector_ptr)
 {
   long i;
-  const asymbol *dir_so = NULL;
   const asymbol *file_so = NULL;
   asymbol **oso_file = NULL;
   unsigned int nbr_syms = 0;
@@ -208,7 +208,6 @@ macho_symtab_read (struct objfile *objfile,
               else
                 {
                   file_so = sym;
-                  dir_so = NULL;
                   state = S_FIRST_SO;
                 }
             }
@@ -245,7 +244,6 @@ macho_symtab_read (struct objfile *objfile,
               else if (state == S_FIRST_SO)
                 {
                   /* Second SO stab for the file name.  */
-                  dir_so = file_so;
                   file_so = sym;
                   state = S_SECOND_SO;
                 }
@@ -292,7 +290,6 @@ macho_symtab_read (struct objfile *objfile,
                 {
                   complaint (&symfile_complaints, _("Missing nul SO"));
                   file_so = sym;
-                  dir_so = NULL;
                   state = S_FIRST_SO;
                 }
             }
@@ -639,7 +636,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),
@@ -655,37 +651,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;
@@ -696,7 +688,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;
@@ -760,8 +752,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.
@@ -838,7 +828,6 @@ static void
 macho_symfile_read (struct objfile *objfile, int symfile_flags)
 {
   bfd *abfd = objfile->obfd;
-  CORE_ADDR offset;
   long storage_needed;
   bfd *dsym_bfd;
   VEC (oso_el) *oso_vector = NULL;
@@ -891,8 +880,6 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
       dsym_bfd = macho_check_dsym (objfile, &dsym_filename);
       if (dsym_bfd != NULL)
        {
-         int ix;
-         oso_el *oso;
           struct bfd_section *asect, *dsect;
 
          make_cleanup (xfree, dsym_filename);
@@ -963,7 +950,6 @@ macho_symfile_offsets (struct objfile *objfile,
                        const struct section_addr_info *addrs)
 {
   unsigned int i;
-  unsigned int num_sections;
   struct obj_section *osect;
 
   /* Allocate section_offsets.  */
This page took 0.025423 seconds and 4 git commands to generate.