]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
propagate from branch 'com.redhat.elfutils.nickc.pending' (head 28d6423325f0cc14a133e...
authorUlrich Drepper <drepper@redhat.com>
Fri, 18 Jan 2008 19:59:08 +0000 (19:59 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 18 Jan 2008 19:59:08 +0000 (19:59 +0000)
            to branch 'com.redhat.elfutils' (head 6ef48518ed8497626058574c787852bd939d46ee)

20 files changed:
config/elfutils.spec.in
libdw/ChangeLog
libdw/dwarf.h
libdw/dwarf_child.c
libdw/dwarf_diecu.c
libdw/dwarf_entry_breakpoints.c
libdw/dwarf_formref.c
libdw/dwarf_getaranges.c
libdw/dwarf_getattrs.c
libdw/dwarf_getpubnames.c
libdw/dwarf_getsrclines.c
libdw/dwarf_haschildren.c
libdw/dwarf_nextcu.c
libdw/dwarf_siblingof.c
libdw/dwarf_tag.c
libdw/libdw.h
libdw/libdwP.h
libdwarf/ChangeLog
libdwarf/libdwarf.h
src/readelf.c

index 5c5fc54085cefe327ee5671adc3cf8d5bcd7e75c..380e5c5af5f505750a7606baa40077461c4355ac 100644 (file)
@@ -8,7 +8,7 @@ Group: Development/Tools
 Source: elfutils-%{version}.tar.gz
 Obsoletes: libelf libelf-devel
 Requires: elfutils-libelf = %{version}-%{release}
-Requires: glibc >= 2.7
+Requires: glibc >= 2.3.1-2
 
 # ExcludeArch: xxx
 
index 3b4162426ca64550bee18112a7cbdd72f1aa4738..004e0fa11d36596ec1ad3b50101bb8215c44119b 100644 (file)
@@ -1,3 +1,49 @@
+2008-01-17  Nick Clifton  <nickc@redhat.com>
+
+       * dwarf.h (DWARF3_LENGTH_MIN_ESCAPE_CODE): New define.
+       (DWARF3_LENGTH_MAX_ESCAPE_CODE): New define.
+       (DWARF3_LENGTH_64_BIT): New define.
+       * dwarf_getaranges (dwarf_getaranges): Use the new definitions.
+       * dwarf_getpubnames: Include dwarf.h.
+       (get_offsets): Use the new definitions.
+       * dwarf_getsrclines.c (dwarf_getsrclines): Use the new defintions.
+       * dwarf_nextcu.c: Include dwarf.h.  Correct comment.
+       (dwarf_nextcu): Use the new definitions.
+
+       * libdwP.h (DIE_OFFSET_FROM_CU_OFFSET): New macro.
+       * dwarf_die.c (dwarf_diecu): Use the new macro.
+       * dwarf_getaranges (dwarf_getaranges): Use the new macro.
+       * dwarf_nextcu.c (dwarf_nextcu): Use the new macro.
+
+       * dwarf_getpubnames (get_offsets): Replace assertion with test and
+       error return.
+
+       * dwarf_entry_breakpoints.c (dwarf_entry_breakpoints): Use CUDIE.
+
+       * dwarf_siblingof (dwarf_siblingof): Detect a NULL return pointer.
+       Set the address in the return structure to the address of the next
+       non-sibling die, if there is no sibling and the return pointer is
+       not the same as the die pointer.
+       * libdw.h: Expand the description of the dwarf_siblingof prototype.
+
+       * dwarf_child.c: Fix typo in comment.
+
+       * libdwP.h (DWARF_VERSION): Change to 3.
+
+       * dwarf_formref.c (__libdw_formref.c): Handle attributes which do
+       not have a initialised valp pointer.
+
+       * dwarf_getattrs.c (dwarf_getattrs): Return 1 rather than 0 when
+       the end of the attributes is reached.  When the callback fails,
+       return the address of the failing attribute, not the address of
+       its successor.
+       * libdw.h: Expand the description of the dwarf_getattrs prototype.
+
+       * dwarf_child.c (__libdw_find_attr): Use the new definition.
+       (dwarf_child): Likewise.
+       * dwarf_tag.c (__libdw_findabbrev): Likewise.
+       (dwarf_tag): Likewise.
+
 2008-01-08  Roland McGrath  <roland@redhat.com>
 
        * Makefile.am (euinclude): Variable removed.
index 4b763ffa853911c6282918aef3e24f5e31e42682..f760b9d549dce9a32c7038b1b1e74f16f6212301 100644 (file)
@@ -672,4 +672,19 @@ enum
 /* DWARF XXX.  */
 #define DW_ADDR_none   0
 
+/* Section 7.2.2 of the DWARF3 specification defines a range of escape
+   codes that can appear in the length field of certain DWARF structures.
+   
+   These defines enumerate the minium and maximum values of this range.
+   Currently only the maximum value is used (to indicate that 64-bit
+   values are going to be used in the dwarf data that accompanies the
+   structure).  The other values are reserved.
+
+   Note: There is a typo in DWARF3 spec (published Dec 20, 2005).  In
+   sections 7.4, 7.5.1, 7.19, 7.20 the minimum escape code is referred to
+   as 0xffffff00 whereas in fact it should be 0xfffffff0.  */
+#define DWARF3_LENGTH_MIN_ESCAPE_CODE 0xfffffff0u
+#define DWARF3_LENGTH_MAX_ESCAPE_CODE 0xffffffffu
+#define DWARF3_LENGTH_64_BIT          DWARF3_LENGTH_MAX_ESCAPE_CODE
+
 #endif /* dwarf.h */
index b22b010eff456f9bce8a280312c2f093357dd967..bbc750756c9d6702c8dc4a9de5d21a90301ad8d5 100644 (file)
@@ -1,4 +1,4 @@
-/* Return vhild of current DIE.
+/* Return child of current DIE.
    Copyright (C) 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -77,9 +77,9 @@ __libdw_find_attr (Dwarf_Die *die, unsigned int search_name,
   if (abbrevp == NULL)
     {
       abbrevp = __libdw_findabbrev (die->cu, abbrev_code);
-      die->abbrev = abbrevp ?: (Dwarf_Abbrev *) -1l;
+      die->abbrev = abbrevp ?: DWARF_END_ABBREV;
     }
-  if (unlikely (die->abbrev == (Dwarf_Abbrev *) -1l))
+  if (unlikely (die->abbrev == DWARF_END_ABBREV))
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return NULL;
@@ -163,7 +163,7 @@ dwarf_child (die, result)
   void *addr = NULL;
 
   /* If we already know there are no children do not search.  */
-  if (die->abbrev != (Dwarf_Abbrev *) -1
+  if (die->abbrev != DWARF_END_ABBREV
       && (die->abbrev == NULL || die->abbrev->has_children))
     addr = __libdw_find_attr (die, INVALID, NULL, NULL);
   if (die->abbrev == (Dwarf_Abbrev *) -1l)
index 0724ee0625a7dfccda4140634375e2873bad5aa2..963c7d06ab52b3ff37e0807b17e73dddcea88cdd 100644 (file)
@@ -70,7 +70,7 @@ dwarf_diecu (die, result, address_sizep, offset_sizep)
   memset (result, '\0', sizeof (Dwarf_Die));
 
   result->addr = ((char *) die->cu->dbg->sectiondata[IDX_debug_info]->d_buf
-                 + die->cu->start + 3 * die->cu->offset_size - 4 + 3);
+                 + DIE_OFFSET_FROM_CU_OFFSET (die->cu->start, die->cu->offset_size));
   result->cu = die->cu;
 
   if (address_sizep != NULL)
index e568bc99af5a9ef8ab3904701fafa89cf28ec67e..d4966e9582f3b09c9a159a399f020bc0b5671a08 100644 (file)
@@ -87,12 +87,7 @@ dwarf_entry_breakpoints (die, bkpts)
     }
 
   /* Fetch the CU's line records to look for this DIE's addresses.  */
-  Dwarf_Die cudie =
-    {
-      .cu = die->cu,
-      .addr = ((char *) die->cu->dbg->sectiondata[IDX_debug_info]->d_buf
-              + die->cu->start + 3 * die->cu->offset_size - 4 + 3),
-    };
+  Dwarf_Die cudie = CUDIE (die->cu);
   Dwarf_Lines *lines;
   size_t nlines;
   if (INTUSE(dwarf_getsrclines) (&cudie, &lines, &nlines) < 0)
index 7c4fb71a532d068fb1d1a755d4227d7b6f56c227..9d472df8cf246bad6a890fbec1ce34a23f190b4e 100644 (file)
@@ -62,6 +62,12 @@ __libdw_formref (attr, return_offset)
 {
   const unsigned char *datap;
 
+  if (attr->valp == NULL)
+    {
+      __libdw_seterrno (DWARF_E_INVALID_REFERENCE);
+      return -1;
+    }
+
   switch (attr->form)
     {
     case DW_FORM_ref1:
index d2294ea3e859a068363ae055bf4acbde6192f3f2..b6c194255b8734b8ac95d1815204f6147009e833 100644 (file)
@@ -55,7 +55,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include "libdwP.h"
-
+#include <dwarf.h>
 
 struct arangelist
 {
@@ -131,11 +131,14 @@ dwarf_getaranges (dbg, aranges, naranges)
         a segment descriptor on the target system.  */
       Dwarf_Word length = read_4ubyte_unaligned_inc (dbg, readp);
       unsigned int length_bytes = 4;
-      if (length == 0xffffffff)
+      if (length == DWARF3_LENGTH_64_BIT)
        {
          length = read_8ubyte_unaligned_inc (dbg, readp);
          length_bytes = 8;
        }
+      else if (unlikely (length >= DWARF3_LENGTH_MIN_ESCAPE_CODE
+                        && length <= DWARF3_LENGTH_MAX_ESCAPE_CODE))
+       goto invalid;
 
       unsigned int version = read_2ubyte_unaligned_inc (dbg, readp);
       if (version != 2)
@@ -197,11 +200,11 @@ dwarf_getaranges (dbg, aranges, naranges)
          const char *cu_header = (dbg->sectiondata[IDX_debug_info]->d_buf
                                   + offset);
          unsigned int offset_size;
-         if (read_4ubyte_unaligned_noncvt (cu_header) == 0xffffffff)
+         if (read_4ubyte_unaligned_noncvt (cu_header) == DWARF3_LENGTH_64_BIT)
            offset_size = 8;
          else
            offset_size = 4;
-         new_arange->arange.offset = offset + 3 * offset_size - 4 + 3;
+         new_arange->arange.offset = DIE_OFFSET_FROM_CU_OFFSET (offset, offset_size);
 
          /* Sanity-check the data.  */
          if (new_arange->arange.offset
index ebf0869c74e62a31a8bd40003929571683485e37..876475e60a62bda8f8fbf5addafa248cc3b6d06b 100644 (file)
@@ -72,7 +72,7 @@ dwarf_getattrs (Dwarf_Die *die, int (*callback) (Dwarf_Attribute *, void *),
     /* Find the abbreviation.  */
     die->abbrev = __libdw_findabbrev (die->cu, u128);
 
-  if (die->abbrev == (Dwarf_Abbrev *) -1l)
+  if (die->abbrev == DWARF_END_ABBREV)
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return -1l;
@@ -96,13 +96,19 @@ dwarf_getattrs (Dwarf_Die *die, int (*callback) (Dwarf_Attribute *, void *),
 
       /* Get attribute name and form.  */
       Dwarf_Attribute attr;
+      const unsigned char * remembered_attrp = attrp;
+
       // XXX Fix bound checks
       get_uleb128 (attr.code, attrp);
       get_uleb128 (attr.form, attrp);
 
       /* We can stop if we found the attribute with value zero.  */
       if (attr.code == 0 && attr.form == 0)
-        return 0;
+       /* Do not return 0 here - there would be no way to
+          distinguish this value from the attribute at offset 0.
+          Instead we return +1 which would never be a valid
+          offset of an attribute.  */
+        return 1l;
 
       /* Fill in the rest.  */
       attr.valp = (unsigned char *) die_addr;
@@ -110,7 +116,10 @@ dwarf_getattrs (Dwarf_Die *die, int (*callback) (Dwarf_Attribute *, void *),
 
       /* Now call the callback function.  */
       if (callback (&attr, arg) != DWARF_CB_OK)
-       return attrp - die->abbrev->attrp;
+       /* Return the offset of the start of the attribute, so that
+          dwarf_getattrs() can be restarted from this point if the
+          caller so desires.  */
+       return remembered_attrp - die->abbrev->attrp;
 
       /* Skip over the rest of this attribute (if there is any).  */
       if (attr.form != 0)
index 6d07a3b72867f387cab5f3ca0d5007362ee192e7..91dad3117d1d36d5bfafcee5b79f88f9da503468 100644 (file)
@@ -58,6 +58,7 @@
 #include <sys/param.h>
 
 #include <libdwP.h>
+#include <dwarf.h>
 
 
 static int
@@ -93,11 +94,17 @@ get_offsets (Dwarf *dbg)
       /* Read the set header.  */
       int len_bytes = 4;
       Dwarf_Off len = read_4ubyte_unaligned_inc (dbg, readp);
-      if (len == 0xffffffff)
+      if (len == DWARF3_LENGTH_64_BIT)
        {
          len = read_8ubyte_unaligned_inc (dbg, readp);
          len_bytes = 8;
        }
+      else if (unlikely (len >= DWARF3_LENGTH_MIN_ESCAPE_CODE
+                        && len <= DWARF3_LENGTH_MAX_ESCAPE_CODE))
+       {
+         __libdw_seterrno (DWARF_E_INVALID_DWARF);
+         goto err_return;
+       }
 
       /* Now we know the offset of the first offset/name pair.  */
       mem[cnt].set_start = readp + 2 + 2 * len_bytes - startp;
@@ -122,14 +129,17 @@ get_offsets (Dwarf *dbg)
        mem[cnt].cu_offset = read_8ubyte_unaligned (dbg, readp + 2);
 
       /* Determine the size of the CU header.  */
-      assert (dbg->sectiondata[IDX_debug_info] != NULL);
-      assert (dbg->sectiondata[IDX_debug_info]->d_buf != NULL);
-      assert (mem[cnt].cu_offset + 3
-             < dbg->sectiondata[IDX_debug_info]->d_size);
+      if (dbg->sectiondata[IDX_debug_info] == NULL
+         || dbg->sectiondata[IDX_debug_info]->d_buf == NULL
+         || mem[cnt].cu_offset + 3 >= dbg->sectiondata[IDX_debug_info]->d_size)
+       {
+         __libdw_seterrno (DWARF_E_INVALID_DWARF);
+         goto err_return;
+       }      
       unsigned char *infop
        = ((unsigned char *) dbg->sectiondata[IDX_debug_info]->d_buf
           + mem[cnt].cu_offset);
-      if (read_4ubyte_unaligned_noncvt (infop) == 0xffffffff)
+      if (read_4ubyte_unaligned_noncvt (infop) == DWARF3_LENGTH_64_BIT)
        mem[cnt].cu_header_size = 23;
       else
        mem[cnt].cu_header_size = 11;
index 666cca22f9011e4d965696bb86c668506a12dfa3..e4ec267ffdcc95ce793ae93e908421b791d44c52 100644 (file)
@@ -164,7 +164,7 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines)
        }
       Dwarf_Word unit_length = read_4ubyte_unaligned_inc (dbg, linep);
       unsigned int length = 4;
-      if (unlikely (unit_length == 0xffffffff))
+      if (unlikely (unit_length == DWARF3_LENGTH_64_BIT))
        {
          if (unlikely (linep + 8 > lineendp))
            goto invalid_data;
index 7b21f690b13f2f7b81209e70b16b4bcc2258ef9d..fe4319559561b901b3f78bad6c4ff2fa1a4fb660 100644 (file)
@@ -62,7 +62,7 @@ dwarf_haschildren (die)
 {
   /* Find the abbreviation entry.  */
   Dwarf_Abbrev *abbrevp = die->abbrev;
-  if (abbrevp != (Dwarf_Abbrev *) -1l)
+  if (abbrevp != DWARF_END_ABBREV)
     {
       const unsigned char *readp = (unsigned char *) die->addr;
 
@@ -72,9 +72,9 @@ dwarf_haschildren (die)
       get_uleb128 (abbrev_code, readp);
 
       abbrevp = __libdw_findabbrev (die->cu, abbrev_code);
-      die->abbrev = abbrevp ?: (Dwarf_Abbrev *) -1l;
+      die->abbrev = abbrevp ?: DWARF_END_ABBREV;
     }
-  if (unlikely (die->abbrev == (Dwarf_Abbrev *) -1l))
+  if (unlikely (die->abbrev == DWARF_END_ABBREV))
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return 0;
index 30743022adc56bccba9156576fd3105b8cb545c3..3927c41eb02cf09d99719afd2506b73c8d245608 100644 (file)
@@ -53,6 +53,7 @@
 #endif
 
 #include <libdwP.h>
+#include <dwarf.h>
 
 
 int
@@ -91,9 +92,9 @@ dwarf_nextcu (dwarf, off, next_off, header_sizep, abbrev_offsetp,
         of the .debug_info contribution for that compilation unit, not
         including the length field itself. In the 32-bit DWARF format,
         this is a 4-byte unsigned integer (which must be less than
-        0xffffff00); in the 64-bit DWARF format, this consists of the
+        0xfffffff0); in the 64-bit DWARF format, this consists of the
         4-byte value 0xffffffff followed by an 8-byte unsigned integer
-        that gives the actual length (see Section 7.4).
+        that gives the actual length (see Section 7.2.2).
 
       2. A 2-byte unsigned integer representing the version of the
         DWARF information for that compilation unit. For DWARF Version
@@ -112,22 +113,27 @@ dwarf_nextcu (dwarf, off, next_off, header_sizep, abbrev_offsetp,
         offset portion of an address.  */
   uint64_t length = read_4ubyte_unaligned_inc (dwarf, bytes);
   size_t offset_size = 4;
-  if (length == 0xffffffffu)
+  /* Lengths of 0xfffffff0 - 0xffffffff are escape codes.  Oxffffffff is
+     used to indicate that 64-bit dwarf information is being used, the
+     other values are currently reserved.  */
+  if (length == DWARF3_LENGTH_64_BIT)
     offset_size = 8;
+  else if (unlikely (length >= DWARF3_LENGTH_MIN_ESCAPE_CODE
+                    && length <= DWARF3_LENGTH_MAX_ESCAPE_CODE))
+    {
+      __libdw_seterrno (DWARF_E_INVALID_DWARF);
+      return -1;
+    }
 
-  /* Now we know how large the header is.  Note the trick in the
-     computation.  If the offset_size is 4 the '- 4' term undoes the
-     '2 *'.  If offset_size is 8 this term computes the size of the
-     escape value plus the 8 byte offset.  */
-  if (unlikely (off + 2 * offset_size - 4 + sizeof (uint16_t)
-               + offset_size + sizeof (uint8_t)
+  /* Now we know how large the header is.  */
+  if (unlikely (DIE_OFFSET_FROM_CU_OFFSET (off, offset_size)
                >= dwarf->sectiondata[IDX_debug_info]->d_size))
     {
       *next_off = -1;
       return 1;
     }
 
-  if (length == 0xffffffffu)
+  if (length == DWARF3_LENGTH_64_BIT)
     /* This is a 64-bit DWARF format.  */
     length = read_8ubyte_unaligned_inc (dwarf, bytes);
 
@@ -160,7 +166,8 @@ dwarf_nextcu (dwarf, off, next_off, header_sizep, abbrev_offsetp,
                     - ((char *) dwarf->sectiondata[IDX_debug_info]->d_buf
                        + off));
 
-  /* See above for an explanation of the trick in this formula.  */
+  /* See definition of DIE_OFFSET_FROM_CU_OFFSET macro
+     for an explanation of the trick in this expression.  */
   *next_off = off + 2 * offset_size - 4 + length;
 
   return 0;
index a6cca394b5646dac3abe9387d01d2771ad4b2045..ac9d28774b2cb0370b4177764300a2282fa6db31 100644 (file)
@@ -56,7 +56,6 @@
 #include <dwarf.h>
 #include <string.h>
 
-
 int
 dwarf_siblingof (die, result)
      Dwarf_Die *die;
@@ -66,6 +65,12 @@ dwarf_siblingof (die, result)
   if (die == NULL)
     return -1;
 
+  if (result == NULL)
+    return -1;
+
+  if (result != die)
+    result->addr = NULL;
+
   unsigned int level = 0;
 
   /* Copy of the current DIE.  */
@@ -102,13 +107,12 @@ dwarf_siblingof (die, result)
                  + sibattr.cu->start + offset);
        }
       else if (unlikely (addr == NULL)
-              || unlikely (this_die.abbrev == (Dwarf_Abbrev *) -1l))
+              || unlikely (this_die.abbrev == DWARF_END_ABBREV))
        return -1;
       else if (this_die.abbrev->has_children)
        /* This abbreviation has children.  */
        ++level;
 
-
       while (1)
        {
          /* Make sure we are still in range.  Some producers might skip
@@ -120,8 +124,12 @@ dwarf_siblingof (die, result)
            break;
 
          if (level-- == 0)
-           /* No more sibling at all.  */
-           return 1;
+           {
+             if (result != die)
+               result->addr = addr;
+             /* No more sibling at all.  */
+             return 1;
+           }
 
          ++addr;
        }
index 05222821b8768b9c6b8fdf7d5859ab8a5c8d8390..7fcd89ca1099296f4d9ca4f8ace6d64995943204 100644 (file)
@@ -76,8 +76,7 @@ __libdw_findabbrev (struct Dwarf_CU *cu, unsigned int code)
          {
            /* Make sure we do not try to search for it again.  */
            cu->last_abbrev_offset = (size_t) -1l;
-           abb = (void *) -1l;
-           break;
+           return DWARF_END_ABBREV;
          }
 
        cu->last_abbrev_offset += length;
@@ -107,7 +106,7 @@ dwarf_tag (die)
       die->abbrev = __libdw_findabbrev (die->cu, u128);
     }
 
-  if (die->abbrev == (Dwarf_Abbrev *) -1l)
+  if (die->abbrev == DWARF_END_ABBREV)
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
       return DW_TAG_invalid;
index 6242d04f8cef941aaa18811cc51204bf2d7c967a..4720739a1c54f009b675586e711e1a812b7d33f8 100644 (file)
@@ -252,14 +252,24 @@ extern Dwarf_Die *dwarf_addrdie (Dwarf *dbg, Dwarf_Addr addr,
 extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
      __nonnull_attribute__ (2);
 
-/* Return sibling of given DIE.  */
+/* Locates the first sibling of DIE and places it in RESULT.
+   Returns 0 if a sibling was found, -1 if something went wrong.
+   Returns 1 if no sibling could be found and, if RESULT is not
+   the same as DIE, it sets RESULT->addr to the address of the
+   (non-sibling) DIE that follows this one, or NULL if this DIE
+   was the last one in the cokmpilation unit.  */
 extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
      __nonnull_attribute__ (2);
 
 /* Check whether the DIE has children.  */
 extern int dwarf_haschildren (Dwarf_Die *die) __nonnull_attribute__ (1);
 
-/* Get attributes of the DIE.  */
+/* Walks the attributes of DIE, starting at the one OFFSET bytes in,
+   calling the CALLBACK function for each one.  Stops if the callback
+   function ever returns a value other than DWARF_CB_OK and returns the
+   offset of the offending attribute.  If the end of the attributes
+   is reached 1 is returned.  If something goes wrong -1 is returned and
+   the dwarf error number is set.  */
 extern ptrdiff_t dwarf_getattrs (Dwarf_Die *die,
                                 int (*callback) (Dwarf_Attribute *, void *),
                                 void *arg, ptrdiff_t offset)
index 78fd5ce7d31d4e9daa20dacdfe658c22c08ba81b..2277f39cdce58294e02d65833584b4c7648efbad 100644 (file)
@@ -62,7 +62,7 @@
 
 
 /* Version of the DWARF specification we support.  */
-#define DWARF_VERSION 2
+#define DWARF_VERSION 3
 
 /* Version of the CIE format.  */
 #define CIE_VERSION 1
@@ -286,6 +286,19 @@ struct Dwarf_CU
   void *locs;
 };
 
+/* Compute the offset of a CU's first DIE from its offset.  This
+   is either:
+        LEN       VER     OFFSET    ADDR
+      4-bytes + 2-bytes + 4-bytes + 1-byte  for 32-bit dwarf
+     12-bytes + 2-bytes + 8-bytes + 1-byte  for 64-bit dwarf
+     
+   Note the trick in the computation.  If the offset_size is 4
+   the '- 4' term changes the '3 *' into a '2 *'.  If the
+   offset_size is 8 it accounts for the 4-byte escape value
+   used at the start of the length.  */
+#define DIE_OFFSET_FROM_CU_OFFSET(cu_offset, offset_size) \
+  ((cu_offset) + 3 * (offset_size) - 4 + 3)
+
 #define CUDIE(fromcu) \
   ((Dwarf_Die)                                                               \
    {                                                                         \
index c46ffcb6e2a698d1b397fe3125a49832d84e6846..4c63735e44548d9c09b0bca9306ef5f021669adf 100644 (file)
@@ -1,3 +1,7 @@
+2008-01-17  Nick Clifton  <nickc@redhat.com>
+
+       * libdwarf.h: Fix typo in comment.
+
 2003-08-11  Ulrich Drepper  <drepper@redhat.com>
 
         * Moved to CVS archive.
index 284b8a38e1af2f43a974cb21c9e42c6fb9b7759b..2a2b9e3e14af5c5ea5c5d32623c93a061cf0bf37 100644 (file)
@@ -134,7 +134,7 @@ extern int dwarf_init (int fd, Dwarf_Unsigned access,
                       Dwarf_Handler errhand, Dwarf_Ptr errarg,
                       Dwarf_Debug *dbg, Dwarf_Error *errdesc);
 
-/* Similar to `dwarf_init' but instead of a file descriptor of ELF
+/* Similar to `dwarf_init' but instead of a file descriptor an ELF
    descriptor is passed.  */
 extern int dwarf_elf_init (Elf *elf, Dwarf_Unsigned access,
                           Dwarf_Handler errhand, Dwarf_Ptr errarg,
index d65f8103409ef3b8945f8c34c5be5497dd330dbd..f243f62699697b32cb9eb3d006266ab5f9d48995 100644 (file)
@@ -4041,7 +4041,8 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
        if (unlikely (dwarf_formaddr (attrp, &addr) != 0))
          {
          attrval_out:
-           error (0, 0, gettext ("cannot get attribute value: %s"),
+           error (0, 0, gettext ("offset: %" PRIx64 " cannot get attribute value: %s"),
+                  attrp->valp - (unsigned char *) attrp->cu->dbg->sectiondata[IDX_debug_info]->d_buf,
                   dwarf_errmsg (-1));
            return DWARF_CB_ABORT;
          }
@@ -4285,7 +4286,7 @@ print_debug_info_section (Dwfl_Module *dwflmod,
       int tag = dwarf_tag (&dies[level]);
       if (unlikely (tag == DW_TAG_invalid))
        {
-         error (0, 0, gettext ("cannot get tag of DIE at offset %" PRIu64
+         error (0, 0, gettext ("cannot get tag of DIE at offset %" PRIx64
                                " in section '%s': %s"),
                 (uint64_t) offset, ".debug_info", dwarf_errmsg (-1));
          goto do_return;
@@ -4309,8 +4310,10 @@ print_debug_info_section (Dwfl_Module *dwflmod,
       if (res > 0)
        {
          while ((res = dwarf_siblingof (&dies[level], &dies[level])) == 1)
-           if (level-- == 0)
-             break;
+           {
+             if (level-- == 0)
+               break;
+           }
 
          if (unlikely (res == -1))
            {