macho+zld: return null rather than error on invalid AbbrevKind

This commit is contained in:
Jakub Konka 2023-03-21 11:38:49 +01:00
parent a88ffa7fa9
commit 073f9a18a9

View File

@ -27,7 +27,7 @@ const CompileUnitIterator = struct {
pub fn next(self: *CompileUnitIterator) !?CompileUnit {
if (self.pos >= self.ctx.debug_info.len) return null;
var stream = std.io.fixedBufferStream(self.ctx.debug_info);
var stream = std.io.fixedBufferStream(self.ctx.debug_info[self.pos..]);
var creader = std.io.countingReader(stream.reader());
const reader = creader.reader();
@ -37,7 +37,7 @@ const CompileUnitIterator = struct {
const cu = CompileUnit{
.cuh = cuh,
.debug_info_off = offset,
.debug_info_off = self.pos + offset,
};
self.pos += (math.cast(usize, total_length) orelse return error.Overflow);
@ -188,7 +188,7 @@ const AbbrevEntryIterator = struct {
return AbbrevEntry.null();
}
const abbrev_pos = lookup.get(kind) orelse return error.MalformedDwarf;
const abbrev_pos = lookup.get(kind) orelse return null;
const len = try findAbbrevEntrySize(
self.ctx,
abbrev_pos.pos,
@ -290,21 +290,6 @@ pub const Attribute = struct {
};
}
pub fn getReference(self: Attribute, ctx: DwarfInfo) !?u64 {
const debug_info = self.getDebugInfo(ctx);
var stream = std.io.fixedBufferStream(debug_info);
const reader = stream.reader();
return switch (self.form) {
dwarf.FORM.ref1 => debug_info[0],
dwarf.FORM.ref2 => mem.readIntLittle(u16, debug_info[0..2]),
dwarf.FORM.ref4 => mem.readIntLittle(u32, debug_info[0..4]),
dwarf.FORM.ref8 => mem.readIntLittle(u64, debug_info[0..8]),
dwarf.FORM.ref_udata => try leb.readULEB128(u64, reader),
else => null,
};
}
pub fn getAddr(self: Attribute, ctx: DwarfInfo, cuh: CompileUnit.Header) ?u64 {
if (self.form != dwarf.FORM.addr) return null;
const debug_info = self.getDebugInfo(ctx);