structstd.debug.Dwarf.EntryHeader[src]

Fields

length_offset: usize

Offset of the length field in the backing buffer

format: Format
type: union(enum) {
    cie,
    /// Value is the offset of the corresponding CIE
    fde: u64,
    terminator,
}
entry_bytes: []const u8

The entry's contents, not including the ID field

Functions

FunctionentryLength[src]

pub fn entryLength(self: EntryHeader) usize

The length of the entry including the ID field, but not the length field itself

Parameters

Source Code

Source code
pub fn entryLength(self: EntryHeader) usize {
    return self.entry_bytes.len + @as(u8, if (self.format == .@"64") 8 else 4);
}

Functionread[src]

pub fn read( fbr: *FixedBufferReader, opt_ma: ?*MemoryAccessor, dwarf_section: Section.Id, ) !EntryHeader

Reads a header for either an FDE or a CIE, then advances the fbr to the position after the trailing structure. fbr must be a FixedBufferReader backed by either the .eh_frame or .debug_frame sections.

Parameters

opt_ma: ?*MemoryAccessor
dwarf_section: Section.Id

Source Code

Source code
pub fn read(
    fbr: *FixedBufferReader,
    opt_ma: ?*MemoryAccessor,
    dwarf_section: Section.Id,
) !EntryHeader {
    assert(dwarf_section == .eh_frame or dwarf_section == .debug_frame);

    const length_offset = fbr.pos;
    const unit_header = try readUnitHeader(fbr, opt_ma);
    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.pos;
    const end_offset = start_offset + unit_length;
    defer fbr.pos = end_offset;

    const id = try if (opt_ma) |ma|
        fbr.readAddressChecked(unit_header.format, ma)
    else
        fbr.readAddress(unit_header.format);
    const entry_bytes = fbr.buf[fbr.pos..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,
    };
}

Source Code

Source code
pub const EntryHeader = struct {
    /// Offset of the length field in the backing buffer
    length_offset: usize,
    format: Format,
    type: union(enum) {
        cie,
        /// Value is the offset of the corresponding CIE
        fde: u64,
        terminator,
    },
    /// The entry's contents, not including the ID field
    entry_bytes: []const u8,

    /// The length of the entry including the ID field, but not the length field itself
    pub fn entryLength(self: EntryHeader) usize {
        return self.entry_bytes.len + @as(u8, if (self.format == .@"64") 8 else 4);
    }

    /// Reads a header for either an FDE or a CIE, then advances the fbr to the position after the trailing structure.
    /// `fbr` must be a FixedBufferReader backed by either the .eh_frame or .debug_frame sections.
    pub fn read(
        fbr: *FixedBufferReader,
        opt_ma: ?*MemoryAccessor,
        dwarf_section: Section.Id,
    ) !EntryHeader {
        assert(dwarf_section == .eh_frame or dwarf_section == .debug_frame);

        const length_offset = fbr.pos;
        const unit_header = try readUnitHeader(fbr, opt_ma);
        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.pos;
        const end_offset = start_offset + unit_length;
        defer fbr.pos = end_offset;

        const id = try if (opt_ma) |ma|
            fbr.readAddressChecked(unit_header.format, ma)
        else
            fbr.readAddress(unit_header.format);
        const entry_bytes = fbr.buf[fbr.pos..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,
        };
    }
}