| ... | ... | @@ -41,7 +41,7 @@ pub const SymbolInfo = struct { |
| 41 | 41 | compile_unit_name: []const u8 = "???", |
| 42 | 42 | line_info: ?LineInfo = null, |
| 43 | 43 | |
| 44 | | pub fn deinit(self: @This(), allocator: mem.Allocator) void { |
| 44 | pub fn deinit(self: SymbolInfo, allocator: mem.Allocator) void { |
| 45 | 45 | if (self.line_info) |li| { |
| 46 | 46 | li.deinit(allocator); |
| 47 | 47 | } |
| ... | ... | @@ -50,6 +50,13 @@ pub const SymbolInfo = struct { |
| 50 | 50 | const PdbOrDwarf = union(enum) { |
| 51 | 51 | pdb: pdb.Pdb, |
| 52 | 52 | dwarf: DW.DwarfInfo, |
| 53 | |
| 54 | fn deinit(self: *PdbOrDwarf, allocator: mem.Allocator) void { |
| 55 | switch (self.*) { |
| 56 | .pdb => |*inner| inner.deinit(), |
| 57 | .dwarf => |*inner| inner.deinit(allocator), |
| 58 | } |
| 59 | } |
| 53 | 60 | }; |
| 54 | 61 | |
| 55 | 62 | var stderr_mutex = std.Thread.Mutex{}; |
| ... | ... | @@ -793,6 +800,7 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo |
| 793 | 800 | errdefer coff_file.close(); |
| 794 | 801 | |
| 795 | 802 | const coff_obj = try allocator.create(coff.Coff); |
| 803 | errdefer allocator.destroy(coff_obj); |
| 796 | 804 | coff_obj.* = coff.Coff.init(allocator, coff_file); |
| 797 | 805 | |
| 798 | 806 | var di = ModuleDebugInfo{ |
| ... | ... | @@ -1386,7 +1394,7 @@ pub const DebugInfo = struct { |
| 1386 | 1394 | pub const ModuleDebugInfo = switch (native_os) { |
| 1387 | 1395 | .macos, .ios, .watchos, .tvos => struct { |
| 1388 | 1396 | base_address: usize, |
| 1389 | | mapped_memory: []const u8, |
| 1397 | mapped_memory: []align(mem.page_size) const u8, |
| 1390 | 1398 | symbols: []const MachoSymbol, |
| 1391 | 1399 | strings: [:0]const u8, |
| 1392 | 1400 | ofiles: OFileTable, |
| ... | ... | @@ -1406,6 +1414,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1406 | 1414 | } |
| 1407 | 1415 | self.ofiles.deinit(); |
| 1408 | 1416 | allocator.free(self.symbols); |
| 1417 | os.munmap(self.mapped_memory); |
| 1409 | 1418 | } |
| 1410 | 1419 | |
| 1411 | 1420 | fn loadOFile(self: *@This(), allocator: mem.Allocator, o_file_path: []const u8) !OFileInfo { |
| ... | ... | @@ -1609,18 +1618,20 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1609 | 1618 | debug_data: PdbOrDwarf, |
| 1610 | 1619 | coff: *coff.Coff, |
| 1611 | 1620 | |
| 1612 | | pub fn allocator(self: @This()) mem.Allocator { |
| 1613 | | return self.coff.allocator; |
| 1621 | fn deinit(self: *@This(), allocator: mem.Allocator) void { |
| 1622 | self.debug_data.deinit(allocator); |
| 1623 | self.coff.deinit(); |
| 1624 | allocator.destroy(self.coff); |
| 1614 | 1625 | } |
| 1615 | 1626 | |
| 1616 | | pub fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo { |
| 1627 | pub fn getSymbolAtAddress(self: *@This(), allocator: mem.Allocator, address: usize) !SymbolInfo { |
| 1617 | 1628 | // Translate the VA into an address into this object |
| 1618 | 1629 | const relocated_address = address - self.base_address; |
| 1619 | 1630 | |
| 1620 | 1631 | switch (self.debug_data) { |
| 1621 | 1632 | .dwarf => |*dwarf| { |
| 1622 | 1633 | const dwarf_address = relocated_address + self.coff.pe_header.image_base; |
| 1623 | | return getSymbolFromDwarf(dwarf_address, dwarf); |
| 1634 | return getSymbolFromDwarf(allocator, dwarf_address, dwarf); |
| 1624 | 1635 | }, |
| 1625 | 1636 | .pdb => { |
| 1626 | 1637 | // fallthrough to pdb handling |
| ... | ... | @@ -1666,17 +1677,28 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1666 | 1677 | .linux, .netbsd, .freebsd, .dragonfly, .openbsd, .haiku, .solaris => struct { |
| 1667 | 1678 | base_address: usize, |
| 1668 | 1679 | dwarf: DW.DwarfInfo, |
| 1669 | | mapped_memory: []const u8, |
| 1680 | mapped_memory: []align(mem.page_size) const u8, |
| 1681 | |
| 1682 | fn deinit(self: *@This(), allocator: mem.Allocator) void { |
| 1683 | self.dwarf.deinit(allocator); |
| 1684 | os.munmap(self.mapped_memory); |
| 1685 | } |
| 1670 | 1686 | |
| 1671 | | pub fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo { |
| 1687 | pub fn getSymbolAtAddress(self: *@This(), allocator: mem.Allocator, address: usize) !SymbolInfo { |
| 1672 | 1688 | // Translate the VA into an address into this object |
| 1673 | 1689 | const relocated_address = address - self.base_address; |
| 1674 | | return getSymbolFromDwarf(relocated_address, &self.dwarf); |
| 1690 | return getSymbolFromDwarf(allocator, relocated_address, &self.dwarf); |
| 1675 | 1691 | } |
| 1676 | 1692 | }, |
| 1677 | 1693 | .wasi => struct { |
| 1678 | | pub fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo { |
| 1694 | fn deinit(self: *@This(), allocator: mem.Allocator) void { |
| 1695 | _ = self; |
| 1696 | _ = allocator; |
| 1697 | } |
| 1698 | |
| 1699 | pub fn getSymbolAtAddress(self: *@This(), allocator: mem.Allocator, address: usize) !SymbolInfo { |
| 1679 | 1700 | _ = self; |
| 1701 | _ = allocator; |
| 1680 | 1702 | _ = address; |
| 1681 | 1703 | return SymbolInfo{}; |
| 1682 | 1704 | } |
| ... | ... | @@ -1684,14 +1706,14 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1684 | 1706 | else => DW.DwarfInfo, |
| 1685 | 1707 | }; |
| 1686 | 1708 | |
| 1687 | | fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo { |
| 1709 | fn getSymbolFromDwarf(allocator: mem.Allocator, address: u64, di: *DW.DwarfInfo) !SymbolInfo { |
| 1688 | 1710 | if (nosuspend di.findCompileUnit(address)) |compile_unit| { |
| 1689 | 1711 | return SymbolInfo{ |
| 1690 | 1712 | .symbol_name = nosuspend di.getSymbolName(address) orelse "???", |
| 1691 | 1713 | .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) { |
| 1692 | 1714 | error.MissingDebugInfo, error.InvalidDebugInfo => "???", |
| 1693 | 1715 | }, |
| 1694 | | .line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) { |
| 1716 | .line_info = nosuspend di.getLineNumberInfo(allocator, compile_unit.*, address) catch |err| switch (err) { |
| 1695 | 1717 | error.MissingDebugInfo, error.InvalidDebugInfo => null, |
| 1696 | 1718 | else => return err, |
| 1697 | 1719 | }, |