authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-05-27 14:14:43-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:13-04:00
log5ebca4392e3d3e616607c00785d67c4ae31330cb
tree2f984b0fdb53e68d0a2a773f86731c20e4007da6
parent551f153718ee1f670ce95c4e485bfb759b84632e

debug: fixing more compile errors on arches that I hadn't tested on yet


3 files changed, 70 insertions(+), 29 deletions(-)

lib/std/debug.zig+58-29
......@@ -421,7 +421,11 @@ pub const StackIterator = struct {
421421 // stacks with frames that don't use a frame pointer (ie. -fomit-frame-pointer).
422422 debug_info: ?*DebugInfo,
423423 dwarf_context: if (supports_context) DW.UnwindContext else void = undefined,
424 const supports_context = @hasDecl(os.system, "ucontext_t");
424 const supports_context = @hasDecl(os.system, "ucontext_t") and
425 (builtin.os.tag != .linux or switch (builtin.cpu.arch) {
426 .mips, .riscv64 => false,
427 else => true,
428 });
425429
426430 pub fn init(first_address: ?usize, fp: ?usize) StackIterator {
427431 if (native_arch == .sparc64) {
......@@ -528,7 +532,7 @@ pub const StackIterator = struct {
528532
529533 fn next_dwarf(self: *StackIterator) !void {
530534 const module = try self.debug_info.?.getModuleForAddress(self.dwarf_context.pc);
531 if (module.getDwarfInfo()) |di| {
535 if (try module.getDwarfInfoForAddress(self.debug_info.?.allocator, self.dwarf_context.pc)) |di| {
532536 self.dwarf_context.reg_ctx.eh_frame = true;
533537 self.dwarf_context.reg_ctx.is_macho = di.is_macho;
534538 try di.unwindFrame(self.debug_info.?.allocator, &self.dwarf_context, module.base_address);
......@@ -1684,6 +1688,26 @@ pub const ModuleDebugInfo = switch (native_os) {
16841688 return info;
16851689 }
16861690
1691 fn getOFileForAddress(self: *@This(), allocator: mem.Allocator, address: usize) !?*OFileInfo {
1692 nosuspend {
1693 const relocated_address = address - self.base_address;
1694 const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
1695 return null;
1696
1697 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
1698 var o_file_info = self.ofiles.get(o_file_path) orelse
1699 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
1700 error.FileNotFound,
1701 error.MissingDebugInfo,
1702 error.InvalidDebugInfo,
1703 => return null,
1704 else => return err,
1705 });
1706
1707 return &o_file_info.di;
1708 }
1709 }
1710
16871711 pub fn getSymbolAtAddress(self: *@This(), allocator: mem.Allocator, address: usize) !SymbolInfo {
16881712 nosuspend {
16891713 // Translate the VA into an address into this object
......@@ -1749,40 +1773,38 @@ pub const ModuleDebugInfo = switch (native_os) {
17491773 }
17501774 }
17511775
1752 pub fn getDwarfInfo(self: *@This()) ?*const DW.DwarfInfo {
1753 // TODO: Implement
1754 _ = self;
1755 return null;
1776 pub fn getDwarfInfoForAddress(self: *@This(), allocator: mem.Allocator, address: usize) !?*const DW.DwarfInfo {
1777 nosuspend {
1778 const relocated_address = address - self.base_address;
1779 const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
1780 return null;
1781
1782 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
1783 var o_file_info = self.ofiles.get(o_file_path) orelse
1784 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
1785 error.FileNotFound,
1786 error.MissingDebugInfo,
1787 error.InvalidDebugInfo,
1788 => return null,
1789 else => return err,
1790 });
1791
1792 return &o_file_info.di;
1793 }
17561794 }
17571795 },
17581796 .uefi, .windows => struct {
17591797 base_address: usize,
17601798 debug_data: PdbOrDwarf,
17611799 coff_image_base: u64,
1800 /// Only used if debug_data is .pdb
17621801 coff_section_headers: []coff.SectionHeader,
17631802
17641803 fn deinit(self: *@This(), allocator: mem.Allocator) void {
1765 switch (self.debug_data) {
1766 .dwarf => |*dwarf| {
1767 allocator.free(dwarf.debug_info);
1768 allocator.free(dwarf.debug_abbrev);
1769 allocator.free(dwarf.debug_str);
1770 allocator.free(dwarf.debug_line);
1771 if (dwarf.debug_str_offsets) |d| allocator.free(d);
1772 if (dwarf.debug_line_str) |d| allocator.free(d);
1773 if (dwarf.debug_ranges) |d| allocator.free(d);
1774 if (dwarf.debug_loclists) |d| allocator.free(d);
1775 if (dwarf.debug_rnglists) |d| allocator.free(d);
1776 if (dwarf.debug_addr) |d| allocator.free(d);
1777 if (dwarf.debug_names) |d| allocator.free(d);
1778 if (dwarf.debug_frame) |d| allocator.free(d);
1779 },
1780 .pdb => {
1781 allocator.free(self.coff_section_headers);
1782 },
1783 }
1784
17851804 self.debug_data.deinit(allocator);
1805 if (self.debug_data == .pdb) {
1806 allocator.free(self.coff_section_headers);
1807 }
17861808 }
17871809
17881810 pub fn getSymbolAtAddress(self: *@This(), allocator: mem.Allocator, address: usize) !SymbolInfo {
......@@ -1835,7 +1857,10 @@ pub const ModuleDebugInfo = switch (native_os) {
18351857 };
18361858 }
18371859
1838 pub fn getDwarfInfo(self: *@This()) ?*const DW.DwarfInfo {
1860 pub fn getDwarfInfoForAddress(self: *@This(), allocator: mem.Allocator, address: usize) !?*const DW.DwarfInfo {
1861 _ = allocator;
1862 _ = address;
1863
18391864 return switch (self.debug_data) {
18401865 .dwarf => |*dwarf| dwarf,
18411866 else => null,
......@@ -1860,7 +1885,9 @@ pub const ModuleDebugInfo = switch (native_os) {
18601885 return getSymbolFromDwarf(allocator, relocated_address, &self.dwarf);
18611886 }
18621887
1863 pub fn getDwarfInfo(self: *@This()) ?*const DW.DwarfInfo {
1888 pub fn getDwarfInfoForAddress(self: *@This(), allocator: mem.Allocator, address: usize) !?*const DW.DwarfInfo {
1889 _ = allocator;
1890 _ = address;
18641891 return &self.dwarf;
18651892 }
18661893 },
......@@ -1877,8 +1904,10 @@ pub const ModuleDebugInfo = switch (native_os) {
18771904 return SymbolInfo{};
18781905 }
18791906
1880 pub fn getDwarfInfo(self: *@This()) ?*const DW.DwarfInfo {
1907 pub fn getDwarfInfoForAddress(self: *@This(), allocator: mem.Allocator, address: usize) !?*const DW.DwarfInfo {
18811908 _ = self;
1909 _ = allocator;
1910 _ = address;
18821911 return null;
18831912 }
18841913 },
lib/std/dwarf.zig+1
......@@ -1556,6 +1556,7 @@ pub const DwarfInfo = struct {
15561556 }
15571557
15581558 pub fn unwindFrame(di: *const DwarfInfo, allocator: mem.Allocator, context: *UnwindContext, module_base_address: usize) !void {
1559 if (!comptime abi.isSupportedArch(builtin.target.cpu.arch)) return error.UnsupportedCpuArchitecture;
15591560 if (context.pc == 0) return;
15601561
15611562 // TODO: Handle signal frame (ie. use_prev_instr in libunwind)
lib/std/dwarf/abi.zig+11
......@@ -8,6 +8,17 @@ pub const RegisterContext = struct {
88 is_macho: bool,
99};
1010
11pub fn isSupportedArch(arch: std.Target.Cpu.Arch) bool {
12 return switch (arch) {
13 .x86,
14 .x86_64,
15 .arm,
16 .aarch64,
17 => true,
18 else => false,
19 };
20}
21
1122pub fn ipRegNum() u8 {
1223 return switch (builtin.cpu.arch) {
1324 .x86 => 8,