]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Improve reader hook functions a bit
authorPetr Machata <pmachata@redhat.com>
Tue, 5 May 2009 13:34:13 +0000 (15:34 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 5 May 2009 13:34:13 +0000 (15:34 +0200)
* ... so that they are closer match to what's need on call sites

libdw/dwarf_formudata.c
libdw/dwarf_getlocation.c
libdw/dwarf_getsrclines.c
libdw/dwarf_ranges.c
libdw/libdwP.h

index 4550b2cf72d348754f6d67f2dfdea54ce3f92065..de0489db7d38afbde0cd02d71940ed3c39dc0cea 100644 (file)
@@ -57,7 +57,8 @@
 
 internal_function unsigned char *
 __libdw_formptr (Dwarf_Attribute *attr, int sec_index,
-                int err_nodata, unsigned char **endpp)
+                int err_nodata, unsigned char **endpp,
+                Dwarf_Off *offsetp)
 {
   if (attr == NULL)
     return NULL;
@@ -93,7 +94,10 @@ __libdw_formptr (Dwarf_Attribute *attr, int sec_index,
       return NULL;
     }
 
-  *endpp = endp;
+  if (endpp != NULL)
+    *endpp = endp;
+  if (offsetp != NULL)
+    *offsetp = offset;
   return readp;
 }
 
index 83da7cdf2cda4bf6839f583163eb02af4073d65d..8092ecedae002d562a5bfd4967afc177d26b4982 100644 (file)
@@ -379,8 +379,7 @@ dwarf_getlocation_addr (attr, address, llbufs, listlens, maxlocs)
     }
 
   unsigned char *endp, *readp
-    = __libdw_formptr (attr, IDX_debug_loc,
-                      DWARF_E_NO_LOCLIST, &endp);
+    = __libdw_formptr (attr, IDX_debug_loc, DWARF_E_NO_LOCLIST, &endp, NULL);
   if (readp == NULL)
     return -1;
 
index bc36e8b2fe05bdd31fce68de9e5165d66555cd64..2158f2687159f594e4ef65ade8500d0b6e15306e 100644 (file)
@@ -136,9 +136,8 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines)
       /* Get the offset into the .debug_line section.  NB: this call
         also checks whether the previous dwarf_attr call failed.  */
       const unsigned char *lineendp, *linep
-       = __libdw_formptr (stmt_list, IDX_debug_line,
-                          DWARF_E_NO_DEBUG_LINE,
-                          (unsigned char **) &lineendp);
+       = __libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE,
+                          (unsigned char **) &lineendp, NULL);
       if (linep == NULL)
        goto out;
 
index d49c6ab9da656e84e6d116129dcba55650d130f8..68301295685fb0448069f3ee3911531617256a90 100644 (file)
@@ -139,13 +139,12 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
        /* No PC attributes in this DIE at all, so an empty range list.  */
        return 0;
 
+      Dwarf_Word start_offset;
       if ((readp = __libdw_formptr (attr, IDX_debug_ranges,
                                    DWARF_E_NO_DEBUG_RANGES,
-                                   &readendp)) == NULL)
+                                   &readendp, &start_offset)) == NULL)
        return -1;
 
-      Dwarf_Word start_offset = (void *) readp - d->d_buf;
-
       offset = start_offset;
       assert ((Dwarf_Word) offset == start_offset);
 
@@ -173,11 +172,9 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
     }
   else
     {
-      if (offset < 0 || (size_t) offset >= d->d_size)
-       {
-         __libdw_seterrno (DWARF_E_INVALID_OFFSET);
-         return -1l;
-       }
+      if (!__libdw_offset_in_section (die->cu->dbg,
+                                     IDX_debug_ranges, offset, 1))
+       return -1l;
 
       readp = d->d_buf + offset;
       readendp = d->d_buf + d->d_size;
index 85b1398d7eb42b3fa0a405839f38c72cbd94d0b9..9d1bc93f86687621d4a01e973167591bc41a830f 100644 (file)
@@ -438,6 +438,14 @@ __libdw_in_section (Dwarf *dbg, int sec_index,
   return true;
 }
 
+static inline bool
+__libdw_offset_in_section (Dwarf *dbg, int sec_index,
+                          Dwarf_Off offset, int width)
+{
+  Elf_Data *data = dbg->sectiondata[sec_index];
+  return __libdw_in_section (dbg, sec_index, data->d_buf + offset, width);
+}
+
 /* Relocation hooks return -1 on error, 0 if there is no relocation
    and 1 if a relocation was present.*/
 int __libdw_relocate_address (Dwarf *dbg,
@@ -490,8 +498,7 @@ __libdw_read_offset_inc (Dwarf *dbg,
   Dwarf_Off val;
   READ_AND_RELOCATE (__libdw_relocate_offset, val);
 
-  Elf_Data *data = dbg->sectiondata[sec_ret];
-  if (!__libdw_in_section (dbg, sec_ret, data->d_buf + val, width))
+  if (!__libdw_offset_in_section (dbg, sec_ret, val, width))
     return -1;
 
   *ret = val;
@@ -512,7 +519,7 @@ __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index,
 
 unsigned char *
 __libdw_formptr (Dwarf_Attribute *attr, int sec_index,
-                int err_nodata, unsigned char **endpp)
+                int err_nodata, unsigned char **endpp, Dwarf_Off *offsetp)
   internal_function;
 
 static inline int