| ... | ... | @@ -77,29 +77,29 @@ const DebugInfo = struct { |
| 77 | 77 | pub fn parseFromObject(allocator: Allocator, object: *const Object) !?DebugInfo { |
| 78 | 78 | var debug_info = blk: { |
| 79 | 79 | const index = object.dwarf_debug_info_index orelse return null; |
| 80 | | break :blk object.getSectionContents(index); |
| 80 | break :blk try object.getSectionContents(index); |
| 81 | 81 | }; |
| 82 | 82 | var debug_abbrev = blk: { |
| 83 | 83 | const index = object.dwarf_debug_abbrev_index orelse return null; |
| 84 | | break :blk object.getSectionContents(index); |
| 84 | break :blk try object.getSectionContents(index); |
| 85 | 85 | }; |
| 86 | 86 | var debug_str = blk: { |
| 87 | 87 | const index = object.dwarf_debug_str_index orelse return null; |
| 88 | | break :blk object.getSectionContents(index); |
| 88 | break :blk try object.getSectionContents(index); |
| 89 | 89 | }; |
| 90 | 90 | var debug_line = blk: { |
| 91 | 91 | const index = object.dwarf_debug_line_index orelse return null; |
| 92 | | break :blk object.getSectionContents(index); |
| 92 | break :blk try object.getSectionContents(index); |
| 93 | 93 | }; |
| 94 | 94 | var debug_line_str = blk: { |
| 95 | 95 | if (object.dwarf_debug_line_str_index) |ind| { |
| 96 | | break :blk object.getSectionContents(ind); |
| 96 | break :blk try object.getSectionContents(ind); |
| 97 | 97 | } |
| 98 | 98 | break :blk &[0]u8{}; |
| 99 | 99 | }; |
| 100 | 100 | var debug_ranges = blk: { |
| 101 | 101 | if (object.dwarf_debug_ranges_index) |ind| { |
| 102 | | break :blk object.getSectionContents(ind); |
| 102 | break :blk try object.getSectionContents(ind); |
| 103 | 103 | } |
| 104 | 104 | break :blk &[0]u8{}; |
| 105 | 105 | }; |
| ... | ... | @@ -429,7 +429,7 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v |
| 429 | 429 | }; |
| 430 | 430 | |
| 431 | 431 | // Read section's code |
| 432 | | const code: ?[]const u8 = if (!is_zerofill) self.getSectionContents(sect_id) else null; |
| 432 | const code: ?[]const u8 = if (!is_zerofill) try self.getSectionContents(sect_id) else null; |
| 433 | 433 | |
| 434 | 434 | // Read section's list of relocations |
| 435 | 435 | const raw_relocs = self.contents[sect.reloff..][0 .. sect.nreloc * @sizeOf(macho.relocation_info)]; |
| ... | ... | @@ -475,10 +475,10 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v |
| 475 | 475 | break :blk sym_index; |
| 476 | 476 | }; |
| 477 | 477 | const atom_size = first_sym.n_value - sect.addr; |
| 478 | | const atom_code: ?[]const u8 = if (code) |cc| |
| 479 | | cc[0..atom_size] |
| 480 | | else |
| 481 | | null; |
| 478 | const atom_code: ?[]const u8 = if (code) |cc| blk: { |
| 479 | const size = math.cast(usize, atom_size) orelse return error.Overflow; |
| 480 | break :blk cc[0..size]; |
| 481 | } else null; |
| 482 | 482 | const atom = try self.createAtomFromSubsection( |
| 483 | 483 | macho_file, |
| 484 | 484 | object_id, |
| ... | ... | @@ -515,10 +515,11 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v |
| 515 | 515 | sect.addr + sect.size; |
| 516 | 516 | break :blk end_addr - addr; |
| 517 | 517 | }; |
| 518 | | const atom_code: ?[]const u8 = if (code) |cc| |
| 519 | | cc[addr - sect.addr ..][0..atom_size] |
| 520 | | else |
| 521 | | null; |
| 518 | const atom_code: ?[]const u8 = if (code) |cc| blk: { |
| 519 | const start = math.cast(usize, addr - sect.addr) orelse return error.Overflow; |
| 520 | const size = math.cast(usize, atom_size) orelse return error.Overflow; |
| 521 | break :blk cc[start..][0..size]; |
| 522 | } else null; |
| 522 | 523 | const atom_align = if (addr > 0) |
| 523 | 524 | math.min(@ctz(u64, addr), sect.@"align") |
| 524 | 525 | else |
| ... | ... | @@ -760,15 +761,16 @@ fn parseDataInCode(self: *Object) void { |
| 760 | 761 | ); |
| 761 | 762 | } |
| 762 | 763 | |
| 763 | | fn getSectionContents(self: Object, sect_id: u16) []const u8 { |
| 764 | fn getSectionContents(self: Object, sect_id: u16) error{Overflow}![]const u8 { |
| 764 | 765 | const sect = self.getSection(sect_id); |
| 766 | const size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 765 | 767 | log.debug("getting {s},{s} data at 0x{x} - 0x{x}", .{ |
| 766 | 768 | sect.segName(), |
| 767 | 769 | sect.sectName(), |
| 768 | 770 | sect.offset, |
| 769 | 771 | sect.offset + sect.size, |
| 770 | 772 | }); |
| 771 | | return self.contents[sect.offset..][0..sect.size]; |
| 773 | return self.contents[sect.offset..][0..size]; |
| 772 | 774 | } |
| 773 | 775 | |
| 774 | 776 | pub fn getString(self: Object, off: u32) []const u8 { |