Skip to content

Commit

Permalink
macho: flag an error when parsing __DWARF fails
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 5, 2024
1 parent b79c6de commit ada3065
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/MachO/Object.zig
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void {
}

self.initPlatform();
try self.initDwarfInfo(gpa);
try self.initDwarfInfo(macho_file);

for (self.atoms.items) |atom_index| {
const atom = macho_file.getAtom(atom_index).?;
Expand Down Expand Up @@ -917,10 +917,12 @@ fn initPlatform(self: *Object) void {
/// and record that so that we can emit symbol stabs.
/// TODO in the future, we want parse debug info and debug line sections so that
/// we can provide nice error locations to the user.
fn initDwarfInfo(self: *Object, allocator: Allocator) !void {
fn initDwarfInfo(self: *Object, macho_file: *MachO) !void {
const tracy = trace(@src());
defer tracy.end();

const gpa = macho_file.base.allocator;

var debug_info_index: ?usize = null;
var debug_abbrev_index: ?usize = null;
var debug_str_index: ?usize = null;
Expand All @@ -939,7 +941,10 @@ fn initDwarfInfo(self: *Object, allocator: Allocator) !void {
.debug_abbrev = self.getSectionData(@intCast(debug_abbrev_index.?)),
.debug_str = if (debug_str_index) |index| self.getSectionData(@intCast(index)) else "",
};
dwarf_info.init(allocator) catch return; // TODO flag an error
dwarf_info.init(gpa) catch {
macho_file.base.fatal("{}: invalid __DWARF info found", .{self.fmtPath()});
return error.ParseFailed;
};
self.dwarf_info = dwarf_info;
}

Expand Down

0 comments on commit ada3065

Please sign in to comment.