Function read [src]
Reads a header for either an FDE or a CIE, then advances the fbr to the
position after the trailing structure.
fbr must be backed by either the .eh_frame or .debug_frame sections.
TODO that's a bad API, don't do that. this function should neither require
a fixed reader nor depend on seeking.
Prototype
pub fn read(fbr: *Reader, dwarf_section: Section.Id, endian: Endian) !EntryHeader
Parameters
fbr: *Reader
dwarf_section: Section.Id
endian: Endian
Source
pub fn read(fbr: *Reader, dwarf_section: Section.Id, endian: Endian) !EntryHeader {
assert(dwarf_section == .eh_frame or dwarf_section == .debug_frame);
const length_offset = fbr.seek;
const unit_header = try readUnitHeader(fbr, endian);
const unit_length = cast(usize, unit_header.unit_length) orelse return bad();
if (unit_length == 0) return .{
.length_offset = length_offset,
.format = unit_header.format,
.type = .terminator,
.entry_bytes = &.{},
};
const start_offset = fbr.seek;
const end_offset = start_offset + unit_length;
defer fbr.seek = end_offset;
const id = try readAddress(fbr, unit_header.format, endian);
const entry_bytes = fbr.buffer[fbr.seek..end_offset];
const cie_id: u64 = switch (dwarf_section) {
.eh_frame => CommonInformationEntry.eh_id,
.debug_frame => switch (unit_header.format) {
.@"32" => CommonInformationEntry.dwarf32_id,
.@"64" => CommonInformationEntry.dwarf64_id,
},
else => unreachable,
};
return .{
.length_offset = length_offset,
.format = unit_header.format,
.type = if (id == cie_id) .cie else .{ .fde = switch (dwarf_section) {
.eh_frame => try std.math.sub(u64, start_offset, id),
.debug_frame => id,
else => unreachable,
} },
.entry_bytes = entry_bytes,
};
}