break;
case DW_FORM_block4:
- return_block->length = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
+ if (__libdw_read_length (attr->cu->dbg, IDX_debug_info, attr->valp,
+ 4, &return_block->length))
+ return -1;
return_block->data = attr->valp + 4;
break;
}
uint64_t off;
- // XXX We need better boundary checks.
- if (attrp->cu->offset_size == 8)
- off = read_8ubyte_unaligned (dbg, attrp->valp);
- else
- off = read_4ubyte_unaligned (dbg, attrp->valp);
+ if (__libdw_read_offset (dbg, IDX_debug_info, attrp->valp,
+ attrp->cu->offset_size, &off))
+ return NULL;
if (off >= dbg->sectiondata[IDX_debug_str]->d_size)
goto invalid_error;
break;
case DW_FORM_data4:
- *return_uval = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
- break;
-
case DW_FORM_data8:
- *return_uval = read_8ubyte_unaligned (attr->cu->dbg, attr->valp);
+ if (__libdw_read_offset (attr->cu->dbg, IDX_debug_info, attr->valp,
+ attr->form == DW_FORM_data4 ? 4 : 8,
+ return_uval))
+ return -1;
break;
case DW_FORM_sdata:
}
Dwarf_Word offset;
- if (length_bytes == 4)
- offset = read_4ubyte_unaligned_inc (dbg, readp);
- else
- offset = read_8ubyte_unaligned_inc (dbg, readp);
+ if (__libdw_read_offset_inc (dbg,
+ IDX_debug_aranges, (unsigned char **)&readp,
+ length_bytes, &offset))
+ return -1;
/* Sanity-check the offset. */
if (offset + 4 > dbg->sectiondata[IDX_debug_info]->d_size)
Dwarf_Word range_address;
Dwarf_Word range_length;
- if (address_size == 4)
- {
- range_address = read_4ubyte_unaligned_inc (dbg, readp);
- range_length = read_4ubyte_unaligned_inc (dbg, readp);
- }
- else
- {
- range_address = read_8ubyte_unaligned_inc (dbg, readp);
- range_length = read_8ubyte_unaligned_inc (dbg, readp);
- }
+ if (__libdw_read_address_inc (dbg, IDX_debug_aranges,
+ (unsigned char **)&readp,
+ address_size, &range_address)
+ || __libdw_read_length_inc (dbg, IDX_debug_aranges,
+ (unsigned char **)&readp,
+ address_size, &range_length))
+ return -1;
/* Two zero values mark the end. */
if (range_address == 0 && range_length == 0)
/* The value is an address. The size is defined as
apporiate for the target machine. We use the
address size field from the CU header. */
- if (cu->address_size == 4)
- address = read_4ubyte_unaligned_inc (dbg, linep);
- else
- address = read_8ubyte_unaligned_inc (dbg, linep);
+ if (__libdw_read_address_inc (dbg, IDX_debug_line,
+ (unsigned char **)&linep,
+ cu->address_size, &address))
+ goto out;
break;
case DW_LNE_define_file:
/* This points into the .debug_info section to the beginning of the
CU entry. */
- char *bytes = (char *) dwarf->sectiondata[IDX_debug_info]->d_buf + off;
+ unsigned char *data = (unsigned char *) dwarf->sectiondata[IDX_debug_info]->d_buf;
+ unsigned char *bytes = data + off;
/* The format of the CU header is described in dwarf2p1 7.5.1:
/* Get offset in .debug_abbrev. Note that the size of the entry
depends on whether this is a 32-bit or 64-bit DWARF definition. */
uint64_t abbrev_offset;
- if (offset_size == 4)
- abbrev_offset = read_4ubyte_unaligned_inc (dwarf, bytes);
- else
- abbrev_offset = read_8ubyte_unaligned_inc (dwarf, bytes);
+ if (__libdw_read_offset_inc (dwarf, IDX_debug_info, &bytes,
+ offset_size, &abbrev_offset))
+ return -1;
+
if (abbrev_offsetp != NULL)
*abbrev_offsetp = abbrev_offset;
/* Store the header length. */
if (header_sizep != NULL)
- *header_sizep = (bytes
- - ((char *) dwarf->sectiondata[IDX_debug_info]->d_buf
- + off));
+ *header_sizep = bytes - (data + off);
/* See definition of DIE_OFFSET_FROM_CU_OFFSET macro
for an explanation of the trick in this expression. */