]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Slight optimization of dwarf_getmacros for loops.
authorRoland McGrath <roland@redhat.com>
Fri, 8 May 2009 01:54:52 +0000 (18:54 -0700)
committerRoland McGrath <roland@redhat.com>
Fri, 8 May 2009 01:54:52 +0000 (18:54 -0700)
libdw/ChangeLog
libdw/dwarf_getmacros.c

index a3d9170a8dffe3353e398b827c20a62504cbe4df..0e317d7c77dca7be4c01b599e5d09618bd678cae 100644 (file)
@@ -1,3 +1,9 @@
+2009-05-07  Roland McGrath  <roland@redhat.com>
+
+       * dwarf_getmacros.c (dwarf_getmacros): Use absolute section offset in
+       return value and OFFSET argument, not CU-relative.  Only fetch the
+       attribute data when called with OFFSET of 0.
+
 2009-05-07  Petr Machata  <pmachata@redhat.com>
 
        * dwarf_getmacros.c (dwarf_getmacros): Take into account offset in
index 5f24d37bd43a8bbc15745ac0d11084fbd03d16fc..22afbc3faa34842fc89015f07cc38dc6f13bbc02 100644 (file)
@@ -1,5 +1,5 @@
 /* Get macro information.
-   Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
+   Copyright (C) 2002-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -65,16 +65,6 @@ dwarf_getmacros (die, callback, arg, offset)
      void *arg;
      ptrdiff_t offset;
 {
-  /* Get the appropriate attribute.  */
-  Dwarf_Attribute attr;
-  if (INTUSE(dwarf_attr) (die, DW_AT_macro_info, &attr) == NULL)
-    return -1;
-
-  /* Offset into the .debug_macinfo section.  */
-  Dwarf_Word macoff;
-  if (INTUSE(dwarf_formudata) (&attr, &macoff) != 0)
-    return -1;
-
   Elf_Data *d = die->cu->dbg->sectiondata[IDX_debug_macinfo];
   if (unlikely (d == NULL) || unlikely (d->d_buf == NULL))
     {
@@ -82,8 +72,24 @@ dwarf_getmacros (die, callback, arg, offset)
       return -1;
     }
 
-  const unsigned char *macdata = d->d_buf + macoff;
-  const unsigned char *readp =  macdata + offset;
+  if (offset == 0)
+    {
+      /* Get the appropriate attribute.  */
+      Dwarf_Attribute attr;
+      if (INTUSE(dwarf_attr) (die, DW_AT_macro_info, &attr) == NULL)
+       return -1;
+
+      /* Offset into the .debug_macinfo section.  */
+      Dwarf_Word macoff;
+      if (INTUSE(dwarf_formudata) (&attr, &macoff) != 0)
+       return -1;
+
+      offset = macoff;
+    }
+  if (unlikely (offset > (ptrdiff_t) d->d_size))
+    goto invalid;
+
+  const unsigned char *readp = d->d_buf + offset;
   const unsigned char *readendp = d->d_buf + d->d_size;
 
   if (readp == readendp)
@@ -145,7 +151,7 @@ dwarf_getmacros (die, callback, arg, offset)
        mac.param2.s = str;
 
       if (callback (&mac, arg) != DWARF_CB_OK)
-       return readp - macdata;
+       return readp - (const unsigned char *) d->d_buf;
     }
 
   /* If we come here the termination of the data for the CU is not