]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use gdb::byte_vector when reading section data
authorTom Tromey <tom@tromey.com>
Fri, 9 Mar 2018 05:28:54 +0000 (22:28 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 12 Mar 2018 14:24:17 +0000 (08:24 -0600)
This changes a couple of spots that read section data to use
gdb::byte_vector rather than a cleanup.

Regression tested by the buildbot.  I am not certain that the buildbot
actually tests the code in question, so I recommend careful review.

gdb/ChangeLog
2018-03-12  Tom Tromey  <tom@tromey.com>

* rs6000-aix-tdep.c (rs6000_aix_core_xfer_shared_libraries_aix):
Use gdb::byte_vector.
* arm-tdep.c (arm_exidx_new_objfile): Use gdb::byte_vector.

gdb/ChangeLog
gdb/arm-tdep.c
gdb/rs6000-aix-tdep.c

index 3ca9e6ffdf9a212d3136ded98396b47b5ccb226c..a783a5d2980acdc69f78eb99110b13fbd04c3fca 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-12  Tom Tromey  <tom@tromey.com>
+
+       * rs6000-aix-tdep.c (rs6000_aix_core_xfer_shared_libraries_aix):
+       Use gdb::byte_vector.
+       * arm-tdep.c (arm_exidx_new_objfile): Use gdb::byte_vector.
+
 2018-03-12  Yao Qi  <yao.qi@linaro.org>
 
        * ia64-libunwind-tdep.c (libunwind_get_reg_special): Change
index ef7e66b36afe34aed3880b86d16b466984481131..539ee756e1b77a272094e5f79c6e25fbfc3d93ae 100644 (file)
@@ -2040,50 +2040,40 @@ arm_obj_section_from_vma (struct objfile *objfile, bfd_vma vma)
 static void
 arm_exidx_new_objfile (struct objfile *objfile)
 {
-  struct cleanup *cleanups;
   struct arm_exidx_data *data;
   asection *exidx, *extab;
   bfd_vma exidx_vma = 0, extab_vma = 0;
-  bfd_size_type exidx_size = 0, extab_size = 0;
-  gdb_byte *exidx_data = NULL, *extab_data = NULL;
   LONGEST i;
 
   /* If we've already touched this file, do nothing.  */
   if (!objfile || objfile_data (objfile, arm_exidx_data_key) != NULL)
     return;
-  cleanups = make_cleanup (null_cleanup, NULL);
 
   /* Read contents of exception table and index.  */
   exidx = bfd_get_section_by_name (objfile->obfd, ELF_STRING_ARM_unwind);
+  gdb::byte_vector exidx_data;
   if (exidx)
     {
       exidx_vma = bfd_section_vma (objfile->obfd, exidx);
-      exidx_size = bfd_get_section_size (exidx);
-      exidx_data = (gdb_byte *) xmalloc (exidx_size);
-      make_cleanup (xfree, exidx_data);
+      exidx_data.resize (bfd_get_section_size (exidx));
 
       if (!bfd_get_section_contents (objfile->obfd, exidx,
-                                    exidx_data, 0, exidx_size))
-       {
-         do_cleanups (cleanups);
-         return;
-       }
+                                    exidx_data.data (), 0,
+                                    exidx_data.size ()))
+       return;
     }
 
   extab = bfd_get_section_by_name (objfile->obfd, ".ARM.extab");
+  gdb::byte_vector extab_data;
   if (extab)
     {
       extab_vma = bfd_section_vma (objfile->obfd, extab);
-      extab_size = bfd_get_section_size (extab);
-      extab_data = (gdb_byte *) xmalloc (extab_size);
-      make_cleanup (xfree, extab_data);
+      extab_data.resize (bfd_get_section_size (extab));
 
       if (!bfd_get_section_contents (objfile->obfd, extab,
-                                    extab_data, 0, extab_size))
-       {
-         do_cleanups (cleanups);
-         return;
-       }
+                                    extab_data.data (), 0,
+                                    extab_data.size ()))
+       return;
     }
 
   /* Allocate exception table data structure.  */
@@ -2094,11 +2084,12 @@ arm_exidx_new_objfile (struct objfile *objfile)
                                       VEC(arm_exidx_entry_s) *);
 
   /* Fill in exception table.  */
-  for (i = 0; i < exidx_size / 8; i++)
+  for (i = 0; i < exidx_data.size () / 8; i++)
     {
       struct arm_exidx_entry new_exidx_entry;
-      bfd_vma idx = bfd_h_get_32 (objfile->obfd, exidx_data + i * 8);
-      bfd_vma val = bfd_h_get_32 (objfile->obfd, exidx_data + i * 8 + 4);
+      bfd_vma idx = bfd_h_get_32 (objfile->obfd, exidx_data.data () + i * 8);
+      bfd_vma val = bfd_h_get_32 (objfile->obfd,
+                                 exidx_data.data () + i * 8 + 4);
       bfd_vma addr = 0, word = 0;
       int n_bytes = 0, n_words = 0;
       struct obj_section *sec;
@@ -2132,10 +2123,10 @@ arm_exidx_new_objfile (struct objfile *objfile)
          addr = ((val & 0x7fffffff) ^ 0x40000000) - 0x40000000;
          addr += exidx_vma + i * 8 + 4;
 
-         if (addr >= extab_vma && addr + 4 <= extab_vma + extab_size)
+         if (addr >= extab_vma && addr + 4 <= extab_vma + extab_data.size ())
            {
              word = bfd_h_get_32 (objfile->obfd,
-                                  extab_data + addr - extab_vma);
+                                  extab_data.data () + addr - extab_vma);
              addr += 4;
 
              if ((word & 0xff000000) == 0x80000000)
@@ -2190,10 +2181,11 @@ arm_exidx_new_objfile (struct objfile *objfile)
                     byte, followed by the same unwind instructions as the
                     pre-defined forms.  */
                  if (gnu_personality
-                     && addr + 4 <= extab_vma + extab_size)
+                     && addr + 4 <= extab_vma + extab_data.size ())
                    {
                      word = bfd_h_get_32 (objfile->obfd,
-                                          extab_data + addr - extab_vma);
+                                          (extab_data.data ()
+                                           + addr - extab_vma));
                      addr += 4;
                      n_bytes = 3;
                      n_words = ((word >> 24) & 0xff);
@@ -2204,7 +2196,8 @@ arm_exidx_new_objfile (struct objfile *objfile)
 
       /* Sanity check address.  */
       if (n_words)
-       if (addr < extab_vma || addr + 4 * n_words > extab_vma + extab_size)
+       if (addr < extab_vma
+           || addr + 4 * n_words > extab_vma + extab_data.size ())
          n_words = n_bytes = 0;
 
       /* The unwind instructions reside in WORD (only the N_BYTES least
@@ -2222,7 +2215,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
          while (n_words--)
            {
              word = bfd_h_get_32 (objfile->obfd,
-                                  extab_data + addr - extab_vma);
+                                  extab_data.data () + addr - extab_vma);
              addr += 4;
 
              *p++ = (gdb_byte) ((word >> 24) & 0xff);
@@ -2243,8 +2236,6 @@ arm_exidx_new_objfile (struct objfile *objfile)
                     data->section_maps[sec->the_bfd_section->index],
                     &new_exidx_entry);
     }
-
-  do_cleanups (cleanups);
 }
 
 /* Search for the exception table entry covering MEMADDR.  If one is found,
index 38c86d4cd85a0c503e9704f8df586167590fc987..e3e086c2102ccaa91551400ae5d38fa9545d45e8 100644 (file)
@@ -1007,9 +1007,6 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 {
   struct bfd_section *ldinfo_sec;
   int ldinfo_size;
-  gdb_byte *ldinfo_buf;
-  struct cleanup *cleanup;
-  LONGEST result;
 
   ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
   if (ldinfo_sec == NULL)
@@ -1017,19 +1014,15 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
           bfd_errmsg (bfd_get_error ()));
   ldinfo_size = bfd_get_section_size (ldinfo_sec);
 
-  ldinfo_buf = (gdb_byte *) xmalloc (ldinfo_size);
-  cleanup = make_cleanup (xfree, ldinfo_buf);
+  gdb::byte_vector ldinfo_buf (ldinfo_size);
 
   if (! bfd_get_section_contents (core_bfd, ldinfo_sec,
-                                 ldinfo_buf, 0, ldinfo_size))
+                                 ldinfo_buf.data (), 0, ldinfo_size))
     error (_("unable to read .ldinfo section from core file: %s"),
          bfd_errmsg (bfd_get_error ()));
 
-  result = rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf, readbuf,
-                                     offset, len, 0);
-
-  do_cleanups (cleanup);
-  return result;
+  return rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf.data (), readbuf,
+                                   offset, len, 0);
 }
 
 static void