]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix dwarf_getmacros so that it passes newly-added test
authorPetr Machata <pmachata@redhat.com>
Thu, 7 May 2009 19:02:33 +0000 (21:02 +0200)
committerPetr Machata <pmachata@redhat.com>
Thu, 7 May 2009 19:02:33 +0000 (21:02 +0200)
libdw/ChangeLog
libdw/dwarf_getmacros.c

index 93a5967333b28aec6973109046199f4b19a2fa13..a3d9170a8dffe3353e398b827c20a62504cbe4df 100644 (file)
@@ -1,3 +1,8 @@
+2009-05-07  Petr Machata  <pmachata@redhat.com>
+
+       * dwarf_getmacros.c (dwarf_getmacros): Take into account offset in
+       DW_AT_macro_info attribute of CU DIE.
+
 2009-04-15  Roland McGrath  <roland@redhat.com>
 
        * dwarf.h (DW_CIE_ID): Removed.
index 743ade3bb4aa6000a1a59cbe178574e2928917b9..5f24d37bd43a8bbc15745ac0d11084fbd03d16fc 100644 (file)
@@ -75,17 +75,20 @@ dwarf_getmacros (die, callback, arg, offset)
   if (INTUSE(dwarf_formudata) (&attr, &macoff) != 0)
     return -1;
 
-  const unsigned char *readp
-    = die->cu->dbg->sectiondata[IDX_debug_macinfo]->d_buf + offset;
-  const unsigned char *readendp
-    = readp + die->cu->dbg->sectiondata[IDX_debug_macinfo]->d_size;
+  Elf_Data *d = die->cu->dbg->sectiondata[IDX_debug_macinfo];
+  if (unlikely (d == NULL) || unlikely (d->d_buf == NULL))
+    {
+      __libdw_seterrno (DWARF_E_NO_ENTRY);
+      return -1;
+    }
+
+  const unsigned char *macdata = d->d_buf + macoff;
+  const unsigned char *readp =  macdata + offset;
+  const unsigned char *readendp = d->d_buf + d->d_size;
 
   if (readp == readendp)
     return 0;
 
-  if (*readp != DW_MACINFO_start_file)
-    goto invalid;
-
   while (readp < readendp)
     {
       unsigned int opcode = *readp++;
@@ -142,9 +145,7 @@ dwarf_getmacros (die, callback, arg, offset)
        mac.param2.s = str;
 
       if (callback (&mac, arg) != DWARF_CB_OK)
-       return (readp
-               - ((unsigned char *) die->cu->dbg->sectiondata[IDX_debug_macinfo]->d_buf
-                  + offset));
+       return readp - macdata;
     }
 
   /* If we come here the termination of the data for the CU is not