Slight optimization of dwarf_getmacros for loops.
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index a3d9170..0e317d7 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -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
diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c
index 5f24d37..22afbc3 100644
--- a/libdw/dwarf_getmacros.c
+++ b/libdw/dwarf_getmacros.c
@@ -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 @@
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 @@
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 @@
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