| ... | ... | @@ -1362,6 +1362,8 @@ fn parseDebugInfo(self: *Object, macho_file: *MachO) !void { |
| 1362 | 1362 | if (mem.eql(u8, sect.sectName(), "__debug_str")) { |
| 1363 | 1363 | dwarf.debug_str = try self.readSectionData(gpa, file, n_sect); |
| 1364 | 1364 | } |
| 1365 | // __debug_str_offs[ets] section is a new addition in DWARFv5 and is generally |
| 1366 | // required in order to correctly parse strings. |
| 1365 | 1367 | if (mem.eql(u8, sect.sectName(), "__debug_str_offs")) { |
| 1366 | 1368 | dwarf.debug_str_offsets = try self.readSectionData(gpa, file, n_sect); |
| 1367 | 1369 | } |
| ... | ... | @@ -1369,20 +1371,22 @@ fn parseDebugInfo(self: *Object, macho_file: *MachO) !void { |
| 1369 | 1371 | |
| 1370 | 1372 | if (dwarf.debug_info.len == 0) return; |
| 1371 | 1373 | |
| 1372 | | self.compile_unit = try self.findCompileUnit(gpa, dwarf, macho_file); |
| 1374 | // TODO return error once we fix emitting DWARF in self-hosted backend. |
| 1375 | // https://github.com/ziglang/zig/issues/21719 |
| 1376 | self.compile_unit = self.findCompileUnit(gpa, dwarf) catch null; |
| 1373 | 1377 | } |
| 1374 | 1378 | |
| 1375 | | fn findCompileUnit(self: *Object, gpa: Allocator, ctx: Dwarf, macho_file: *MachO) !CompileUnit { |
| 1379 | fn findCompileUnit(self: *Object, gpa: Allocator, ctx: Dwarf) !CompileUnit { |
| 1376 | 1380 | var info_reader = Dwarf.InfoReader{ .ctx = ctx }; |
| 1377 | 1381 | var abbrev_reader = Dwarf.AbbrevReader{ .ctx = ctx }; |
| 1378 | 1382 | |
| 1379 | | const cuh = try info_reader.readCompileUnitHeader(macho_file); |
| 1383 | const cuh = try info_reader.readCompileUnitHeader(); |
| 1380 | 1384 | try abbrev_reader.seekTo(cuh.debug_abbrev_offset); |
| 1381 | 1385 | |
| 1382 | 1386 | const cu_decl = (try abbrev_reader.readDecl()) orelse return error.UnexpectedEndOfFile; |
| 1383 | 1387 | if (cu_decl.tag != Dwarf.TAG.compile_unit) return error.UnexpectedTag; |
| 1384 | 1388 | |
| 1385 | | try info_reader.seekToDie(cu_decl.code, cuh, &abbrev_reader, macho_file); |
| 1389 | try info_reader.seekToDie(cu_decl.code, cuh, &abbrev_reader); |
| 1386 | 1390 | |
| 1387 | 1391 | const Pos = struct { |
| 1388 | 1392 | pos: usize, |
| ... | ... | @@ -1405,10 +1409,10 @@ fn findCompileUnit(self: *Object, gpa: Allocator, ctx: Dwarf, macho_file: *MachO |
| 1405 | 1409 | Dwarf.AT.str_offsets_base => saved.str_offsets_base = pos, |
| 1406 | 1410 | else => {}, |
| 1407 | 1411 | } |
| 1408 | | try info_reader.skip(attr.form, cuh, macho_file); |
| 1412 | try info_reader.skip(attr.form, cuh); |
| 1409 | 1413 | } |
| 1410 | 1414 | |
| 1411 | | if (saved.comp_dir == null) return error.MissingCompDir; |
| 1415 | if (saved.comp_dir == null) return error.MissingCompileDir; |
| 1412 | 1416 | if (saved.tu_name == null) return error.MissingTuName; |
| 1413 | 1417 | |
| 1414 | 1418 | const str_offsets_base: ?u64 = if (saved.str_offsets_base) |str_offsets_base| str_offsets_base: { |
| ... | ... | @@ -1433,7 +1437,7 @@ fn findCompileUnit(self: *Object, gpa: Allocator, ctx: Dwarf, macho_file: *MachO |
| 1433 | 1437 | Dwarf.FORM.strx3, |
| 1434 | 1438 | Dwarf.FORM.strx4, |
| 1435 | 1439 | => blk: { |
| 1436 | | const base = str_offsets_base orelse return error.MalformedDwarf; |
| 1440 | const base = str_offsets_base orelse return error.MissingStrOffsetsBase; |
| 1437 | 1441 | break :blk try self.addString(gpa, try info_reader.readStringIndexed(pos.form, cuh, base)); |
| 1438 | 1442 | }, |
| 1439 | 1443 | else => return error.InvalidForm, |