+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
/* 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.
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))
{
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)
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