| ... | ... | @@ -532,6 +532,8 @@ pub const StackIterator = struct { |
| 532 | 532 | if (self.next_dwarf()) |_| { |
| 533 | 533 | return self.dwarf_context.pc; |
| 534 | 534 | } else |err| { |
| 535 | if (err != error.MissingFDE) print("DWARF unwind error: {}\n", .{err}); |
| 536 | |
| 535 | 537 | // Fall back to fp unwinding on the first failure, |
| 536 | 538 | // as the register context won't be updated |
| 537 | 539 | |
| ... | ... | @@ -540,9 +542,6 @@ pub const StackIterator = struct { |
| 540 | 542 | |
| 541 | 543 | self.fp = self.dwarf_context.getFp() catch 0; |
| 542 | 544 | self.debug_info = null; |
| 543 | | |
| 544 | | // TODO: Remove |
| 545 | | print("\ndwarf unwind error {}, placing fp at 0x{x}\n\n", .{err, self.fp}); |
| 546 | 545 | } |
| 547 | 546 | } |
| 548 | 547 | |
| ... | ... | @@ -1570,7 +1569,6 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1570 | 1569 | .macos, .ios, .watchos, .tvos => struct { |
| 1571 | 1570 | base_address: usize, |
| 1572 | 1571 | mapped_memory: []align(mem.page_size) const u8, |
| 1573 | | external_mapped_memory: ?[]align(mem.page_size) const u8, |
| 1574 | 1572 | symbols: []const MachoSymbol, |
| 1575 | 1573 | strings: [:0]const u8, |
| 1576 | 1574 | ofiles: OFileTable, |
| ... | ... | @@ -1591,7 +1589,6 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1591 | 1589 | self.ofiles.deinit(); |
| 1592 | 1590 | allocator.free(self.symbols); |
| 1593 | 1591 | os.munmap(self.mapped_memory); |
| 1594 | | if (self.external_mapped_memory) |m| os.munmap(m); |
| 1595 | 1592 | } |
| 1596 | 1593 | |
| 1597 | 1594 | fn loadOFile(self: *@This(), allocator: mem.Allocator, o_file_path: []const u8) !OFileInfo { |
| ... | ... | @@ -1637,102 +1634,37 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1637 | 1634 | addr_table.putAssumeCapacityNoClobber(sym_name, sym.n_value); |
| 1638 | 1635 | } |
| 1639 | 1636 | |
| 1640 | | var opt_debug_line: ?macho.section_64 = null; |
| 1641 | | var opt_debug_info: ?macho.section_64 = null; |
| 1642 | | var opt_debug_abbrev: ?macho.section_64 = null; |
| 1643 | | var opt_debug_str: ?macho.section_64 = null; |
| 1644 | | var opt_debug_str_offsets: ?macho.section_64 = null; |
| 1645 | | var opt_debug_line_str: ?macho.section_64 = null; |
| 1646 | | var opt_debug_ranges: ?macho.section_64 = null; |
| 1647 | | var opt_debug_loclists: ?macho.section_64 = null; |
| 1648 | | var opt_debug_rnglists: ?macho.section_64 = null; |
| 1649 | | var opt_debug_addr: ?macho.section_64 = null; |
| 1650 | | var opt_debug_names: ?macho.section_64 = null; |
| 1651 | | var opt_debug_frame: ?macho.section_64 = null; |
| 1652 | | |
| 1637 | var sections: DW.DwarfInfo.SectionArray = DW.DwarfInfo.null_section_array; |
| 1653 | 1638 | for (segcmd.?.getSections()) |sect| { |
| 1654 | 1639 | const name = sect.sectName(); |
| 1655 | | if (mem.eql(u8, name, "__debug_line")) { |
| 1656 | | opt_debug_line = sect; |
| 1657 | | } else if (mem.eql(u8, name, "__debug_info")) { |
| 1658 | | opt_debug_info = sect; |
| 1659 | | } else if (mem.eql(u8, name, "__debug_abbrev")) { |
| 1660 | | opt_debug_abbrev = sect; |
| 1661 | | } else if (mem.eql(u8, name, "__debug_str")) { |
| 1662 | | opt_debug_str = sect; |
| 1663 | | } else if (mem.eql(u8, name, "__debug_str_offsets")) { |
| 1664 | | opt_debug_str_offsets = sect; |
| 1665 | | } else if (mem.eql(u8, name, "__debug_line_str")) { |
| 1666 | | opt_debug_line_str = sect; |
| 1667 | | } else if (mem.eql(u8, name, "__debug_ranges")) { |
| 1668 | | opt_debug_ranges = sect; |
| 1669 | | } else if (mem.eql(u8, name, "__debug_loclists")) { |
| 1670 | | opt_debug_loclists = sect; |
| 1671 | | } else if (mem.eql(u8, name, "__debug_rnglists")) { |
| 1672 | | opt_debug_rnglists = sect; |
| 1673 | | } else if (mem.eql(u8, name, "__debug_addr")) { |
| 1674 | | opt_debug_addr = sect; |
| 1675 | | } else if (mem.eql(u8, name, "__debug_names")) { |
| 1676 | | opt_debug_names = sect; |
| 1677 | | } else if (mem.eql(u8, name, "__debug_frame")) { |
| 1678 | | opt_debug_frame = sect; |
| 1640 | |
| 1641 | var section_index: ?usize = null; |
| 1642 | inline for (@typeInfo(DW.DwarfSection).Enum.fields, 0..) |section, i| { |
| 1643 | if (mem.eql(u8, "__" ++ section.name, name)) section_index = i; |
| 1679 | 1644 | } |
| 1645 | if (section_index == null) continue; |
| 1646 | |
| 1647 | const section_bytes = try chopSlice(mapped_mem, sect.offset, sect.size); |
| 1648 | sections[section_index.?] = .{ |
| 1649 | .data = section_bytes, |
| 1650 | .owned = false, |
| 1651 | }; |
| 1680 | 1652 | } |
| 1681 | 1653 | |
| 1682 | | const debug_line = opt_debug_line orelse |
| 1683 | | return error.MissingDebugInfo; |
| 1684 | | const debug_info = opt_debug_info orelse |
| 1685 | | return error.MissingDebugInfo; |
| 1686 | | const debug_str = opt_debug_str orelse |
| 1687 | | return error.MissingDebugInfo; |
| 1688 | | const debug_abbrev = opt_debug_abbrev orelse |
| 1689 | | return error.MissingDebugInfo; |
| 1654 | const missing_debug_info = |
| 1655 | sections[@enumToInt(DW.DwarfSection.debug_info)] == null or |
| 1656 | sections[@enumToInt(DW.DwarfSection.debug_abbrev)] == null or |
| 1657 | sections[@enumToInt(DW.DwarfSection.debug_str)] == null or |
| 1658 | sections[@enumToInt(DW.DwarfSection.debug_line)] == null; |
| 1659 | if (missing_debug_info) return error.MissingDebugInfo; |
| 1690 | 1660 | |
| 1691 | 1661 | var di = DW.DwarfInfo{ |
| 1692 | 1662 | .endian = .Little, |
| 1663 | .sections = sections, |
| 1693 | 1664 | .is_macho = true, |
| 1694 | | |
| 1695 | | // TODO: Get this compiling |
| 1696 | | |
| 1697 | | .debug_info = try chopSlice(mapped_mem, debug_info.offset, debug_info.size), |
| 1698 | | .debug_abbrev = try chopSlice(mapped_mem, debug_abbrev.offset, debug_abbrev.size), |
| 1699 | | .debug_str = try chopSlice(mapped_mem, debug_str.offset, debug_str.size), |
| 1700 | | .debug_str_offsets = if (opt_debug_str_offsets) |debug_str_offsets| |
| 1701 | | try chopSlice(mapped_mem, debug_str_offsets.offset, debug_str_offsets.size) |
| 1702 | | else |
| 1703 | | null, |
| 1704 | | .debug_line = try chopSlice(mapped_mem, debug_line.offset, debug_line.size), |
| 1705 | | .debug_line_str = if (opt_debug_line_str) |debug_line_str| |
| 1706 | | try chopSlice(mapped_mem, debug_line_str.offset, debug_line_str.size) |
| 1707 | | else |
| 1708 | | null, |
| 1709 | | .debug_ranges = if (opt_debug_ranges) |debug_ranges| |
| 1710 | | try chopSlice(mapped_mem, debug_ranges.offset, debug_ranges.size) |
| 1711 | | else |
| 1712 | | null, |
| 1713 | | .debug_loclists = if (opt_debug_loclists) |debug_loclists| |
| 1714 | | try chopSlice(mapped_mem, debug_loclists.offset, debug_loclists.size) |
| 1715 | | else |
| 1716 | | null, |
| 1717 | | .debug_rnglists = if (opt_debug_rnglists) |debug_rnglists| |
| 1718 | | try chopSlice(mapped_mem, debug_rnglists.offset, debug_rnglists.size) |
| 1719 | | else |
| 1720 | | null, |
| 1721 | | .debug_addr = if (opt_debug_addr) |debug_addr| |
| 1722 | | try chopSlice(mapped_mem, debug_addr.offset, debug_addr.size) |
| 1723 | | else |
| 1724 | | null, |
| 1725 | | .debug_names = if (opt_debug_names) |debug_names| |
| 1726 | | try chopSlice(mapped_mem, debug_names.offset, debug_names.size) |
| 1727 | | else |
| 1728 | | null, |
| 1729 | | .debug_frame = if (opt_debug_frame) |debug_frame| |
| 1730 | | try chopSlice(mapped_mem, debug_frame.offset, debug_frame.size) |
| 1731 | | else |
| 1732 | | null, |
| 1733 | 1665 | }; |
| 1734 | 1666 | |
| 1735 | | try DW.openDwarfDebugInfo(&di, allocator); |
| 1667 | try DW.openDwarfDebugInfo(&di, allocator, mapped_mem); |
| 1736 | 1668 | var info = OFileInfo{ |
| 1737 | 1669 | .di = di, |
| 1738 | 1670 | .addr_table = addr_table, |
| ... | ... | @@ -1784,7 +1716,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1784 | 1716 | .compile_unit_name = compile_unit.die.getAttrString( |
| 1785 | 1717 | o_file_di, |
| 1786 | 1718 | DW.AT.name, |
| 1787 | | o_file_di.debug_str, |
| 1719 | o_file_di.section(.debug_str), |
| 1788 | 1720 | compile_unit.*, |
| 1789 | 1721 | ) catch |err| switch (err) { |
| 1790 | 1722 | error.MissingDebugInfo, error.InvalidDebugInfo => "???", |