]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Convert several new functions to use read hooks
authorPetr Machata <pmachata@redhat.com>
Tue, 28 Apr 2009 16:39:04 +0000 (18:39 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 28 Apr 2009 16:39:04 +0000 (18:39 +0200)
libdw/dwarf_formblock.c
libdw/dwarf_formstring.c
libdw/dwarf_formudata.c
libdw/dwarf_getaranges.c
libdw/dwarf_getsrclines.c
libdw/dwarf_nextcu.c

index 51396d47078a0f347d10f49226553581d14686ab..486dc19837b8a98cc333c12b73cd1f378ca5cb8a 100644 (file)
@@ -79,7 +79,9 @@ dwarf_formblock (attr, return_block)
       break;
 
     case DW_FORM_block4:
-      return_block->length = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
+      if (__libdw_read_length (attr->cu->dbg, IDX_debug_info, attr->valp,
+                              4, &return_block->length))
+       return -1;
       return_block->data = attr->valp + 4;
       break;
 
index 790831ea3e7bca5401dfcc3792f8e3d1320ec7e3..63eca9b1dd13c843f1e18a20d7a3cafbab02b5ad 100644 (file)
@@ -80,11 +80,9 @@ dwarf_formstring (attrp)
     }
 
   uint64_t off;
-  // XXX We need better boundary checks.
-  if (attrp->cu->offset_size == 8)
-    off = read_8ubyte_unaligned (dbg, attrp->valp);
-  else
-    off = read_4ubyte_unaligned (dbg, attrp->valp);
+  if (__libdw_read_offset (dbg, IDX_debug_info, attrp->valp,
+                          attrp->cu->offset_size, &off))
+    return NULL;
 
   if (off  >= dbg->sectiondata[IDX_debug_str]->d_size)
     goto invalid_error;
index b5c40bb5da5fac76262b2b1cc87bbee06364eb75..e2f1d023b95aadfe5c6548c685777a48ecdecf15 100644 (file)
@@ -77,11 +77,11 @@ dwarf_formudata (attr, return_uval)
       break;
 
     case DW_FORM_data4:
-      *return_uval = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
-      break;
-
     case DW_FORM_data8:
-      *return_uval = read_8ubyte_unaligned (attr->cu->dbg, attr->valp);
+      if (__libdw_read_offset (attr->cu->dbg, IDX_debug_info, attr->valp,
+                              attr->form == DW_FORM_data4 ? 4 : 8,
+                              return_uval))
+       return -1;
       break;
 
     case DW_FORM_sdata:
index 96e9962060b4a6fdb6c292d8237ad7f36465df75..78086fb8a179804f79aed1c1ab1e0c53b8c2673c 100644 (file)
@@ -149,10 +149,10 @@ dwarf_getaranges (dbg, aranges, naranges)
        }
 
       Dwarf_Word offset;
-      if (length_bytes == 4)
-       offset = read_4ubyte_unaligned_inc (dbg, readp);
-      else
-       offset = read_8ubyte_unaligned_inc (dbg, readp);
+      if (__libdw_read_offset_inc (dbg,
+                                  IDX_debug_aranges, (unsigned char **)&readp,
+                                  length_bytes, &offset))
+       return -1;
 
       /* Sanity-check the offset.  */
       if (offset + 4 > dbg->sectiondata[IDX_debug_info]->d_size)
@@ -175,16 +175,13 @@ dwarf_getaranges (dbg, aranges, naranges)
          Dwarf_Word range_address;
          Dwarf_Word range_length;
 
-         if (address_size == 4)
-           {
-             range_address = read_4ubyte_unaligned_inc (dbg, readp);
-             range_length = read_4ubyte_unaligned_inc (dbg, readp);
-           }
-         else
-           {
-             range_address = read_8ubyte_unaligned_inc (dbg, readp);
-             range_length = read_8ubyte_unaligned_inc (dbg, readp);
-           }
+         if (__libdw_read_address_inc (dbg, IDX_debug_aranges,
+                                       (unsigned char **)&readp,
+                                       address_size, &range_address)
+             || __libdw_read_length_inc (dbg, IDX_debug_aranges,
+                                         (unsigned char **)&readp,
+                                         address_size, &range_length))
+           return -1;
 
          /* Two zero values mark the end.  */
          if (range_address == 0 && range_length == 0)
index fe0e67d6a00142b9d2bbe87ac3f745ea02def5c5..67b62aacf9df968e87b9aac23166dee1e4525857 100644 (file)
@@ -429,10 +429,10 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines)
                  /* The value is an address.  The size is defined as
                     apporiate for the target machine.  We use the
                     address size field from the CU header.  */
-                 if (cu->address_size == 4)
-                   address = read_4ubyte_unaligned_inc (dbg, linep);
-                 else
-                   address = read_8ubyte_unaligned_inc (dbg, linep);
+                 if (__libdw_read_address_inc (dbg, IDX_debug_line,
+                                               (unsigned char **)&linep,
+                                               cu->address_size, &address))
+                   goto out;
                  break;
 
                case DW_LNE_define_file:
index 9e5a96bc64c1eb8a1742e96b4800d253fef2aa40..abffe7ec088ef0dd020132383a36ed112e4b03a4 100644 (file)
@@ -84,7 +84,8 @@ dwarf_nextcu (dwarf, off, next_off, header_sizep, abbrev_offsetp,
 
   /* This points into the .debug_info section to the beginning of the
      CU entry.  */
-  char *bytes = (char *) dwarf->sectiondata[IDX_debug_info]->d_buf + off;
+  unsigned char *data = (unsigned char *) dwarf->sectiondata[IDX_debug_info]->d_buf;
+  unsigned char *bytes = data + off;
 
   /* The format of the CU header is described in dwarf2p1 7.5.1:
 
@@ -144,10 +145,10 @@ dwarf_nextcu (dwarf, off, next_off, header_sizep, abbrev_offsetp,
   /* Get offset in .debug_abbrev.  Note that the size of the entry
      depends on whether this is a 32-bit or 64-bit DWARF definition.  */
   uint64_t abbrev_offset;
-  if (offset_size == 4)
-    abbrev_offset = read_4ubyte_unaligned_inc (dwarf, bytes);
-  else
-    abbrev_offset = read_8ubyte_unaligned_inc (dwarf, bytes);
+  if (__libdw_read_offset_inc (dwarf, IDX_debug_info, &bytes,
+                              offset_size, &abbrev_offset))
+    return -1;
+
   if (abbrev_offsetp != NULL)
     *abbrev_offsetp = abbrev_offset;
 
@@ -162,9 +163,7 @@ dwarf_nextcu (dwarf, off, next_off, header_sizep, abbrev_offsetp,
 
   /* Store the header length.  */
   if (header_sizep != NULL)
-    *header_sizep = (bytes
-                    - ((char *) dwarf->sectiondata[IDX_debug_info]->d_buf
-                       + off));
+    *header_sizep = bytes - (data + off);
 
   /* See definition of DIE_OFFSET_FROM_CU_OFFSET macro
      for an explanation of the trick in this expression.  */