| author | |
| committer | |
| log | 6d606cc38b4df2b20af9d77367f8ab22bbbea092 |
| tree | fd00a5a549afccf68b6b50cb1f693dc4251eb4a9 |
| parent | 975c185b92a7d470ea705b28f46a8004bdda3c60 |
There are two concepts here: one for whether dwarf supports unwinding on
that target, and another for whether the Zig standard library
implements it yet.3 files changed, 61 insertions(+), 25 deletions(-)
lib/std/debug/Dwarf.zig-24| ... | @@ -2023,27 +2023,3 @@ fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize { | ... | @@ -2023,27 +2023,3 @@ fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize { |
| 2023 | return std.math.add(usize, field_ptr, @as(usize, @intCast(pc_rel_offset))); | 2023 | return std.math.add(usize, field_ptr, @as(usize, @intCast(pc_rel_offset))); |
| 2024 | } | 2024 | } |
| 2025 | } | 2025 | } |
| 2026 | |||
| 2027 | pub fn supportsUnwinding(target: std.Target) bool { | ||
| 2028 | return switch (target.cpu.arch) { | ||
| 2029 | .x86 => switch (target.os.tag) { | ||
| 2030 | .linux, .netbsd, .solaris, .illumos => true, | ||
| 2031 | else => false, | ||
| 2032 | }, | ||
| 2033 | .x86_64 => switch (target.os.tag) { | ||
| 2034 | .linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true, | ||
| 2035 | else => false, | ||
| 2036 | }, | ||
| 2037 | .arm => switch (target.os.tag) { | ||
| 2038 | .linux => true, | ||
| 2039 | else => false, | ||
| 2040 | }, | ||
| 2041 | .aarch64 => switch (target.os.tag) { | ||
| 2042 | .linux, .netbsd, .freebsd, .macos, .ios => true, | ||
| 2043 | else => false, | ||
| 2044 | }, | ||
| 2045 | // Unwinding is possible on other targets but this implementation does | ||
| 2046 | // not support them...yet! | ||
| 2047 | else => false, | ||
| 2048 | }; | ||
| 2049 | } |
lib/std/debug/Dwarf/abi.zig+25| ... | @@ -5,6 +5,31 @@ const mem = std.mem; | ... | @@ -5,6 +5,31 @@ const mem = std.mem; |
| 5 | const posix = std.posix; | 5 | const posix = std.posix; |
| 6 | const Arch = std.Target.Cpu.Arch; | 6 | const Arch = std.Target.Cpu.Arch; |
| 7 | 7 | ||
| 8 | /// Tells whether unwinding for this target is supported by the Dwarf standard. | ||
| 9 | /// | ||
| 10 | /// See also `std.debug.SelfInfo.supportsUnwinding` which tells whether the Zig | ||
| 11 | /// standard library has a working implementation of unwinding for this target. | ||
| 12 | pub fn supportsUnwinding(target: std.Target) bool { | ||
| 13 | return switch (target.cpu.arch) { | ||
| 14 | .amdgcn, | ||
| 15 | .nvptx, | ||
| 16 | .nvptx64, | ||
| 17 | .spirv, | ||
| 18 | .spirv32, | ||
| 19 | .spirv64, | ||
| 20 | .spu_2, | ||
| 21 | => false, | ||
| 22 | |||
| 23 | // Enabling this causes relocation errors such as: | ||
| 24 | // error: invalid relocation type R_RISCV_SUB32 at offset 0x20 | ||
| 25 | .riscv64, .riscv32 => false, | ||
| 26 | |||
| 27 | // Conservative guess. Feel free to update this logic with any targets | ||
| 28 | // that are known to not support Dwarf unwinding. | ||
| 29 | else => true, | ||
| 30 | }; | ||
| 31 | } | ||
| 32 | |||
| 8 | /// Returns `null` for CPU architectures without an instruction pointer register. | 33 | /// Returns `null` for CPU architectures without an instruction pointer register. |
| 9 | pub fn ipRegNum(arch: Arch) ?u8 { | 34 | pub fn ipRegNum(arch: Arch) ?u8 { |
| 10 | return switch (arch) { | 35 | return switch (arch) { |
lib/std/debug/SelfInfo.zig+36-1| ... | @@ -1982,7 +1982,42 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 { | ... | @@ -1982,7 +1982,42 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 { |
| 1982 | } | 1982 | } |
| 1983 | 1983 | ||
| 1984 | const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?; | 1984 | const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?; |
| 1985 | pub const supports_unwinding = Dwarf.supportsUnwinding(builtin.target); | 1985 | |
| 1986 | /// Tells whether unwinding for the host is implemented. | ||
| 1987 | pub const supports_unwinding = supportsUnwinding(builtin.target); | ||
| 1988 | |||
| 1989 | comptime { | ||
| 1990 | if (supports_unwinding) assert(Dwarf.abi.supportsUnwinding(builtin.target)); | ||
| 1991 | } | ||
| 1992 | |||
| 1993 | /// Tells whether unwinding for this target is *implemented* here in the Zig | ||
| 1994 | /// standard library. | ||
| 1995 | /// | ||
| 1996 | /// See also `Dwarf.abi.supportsUnwinding` which tells whether Dwarf supports | ||
| 1997 | /// unwinding on that target *in theory*. | ||
| 1998 | pub fn supportsUnwinding(target: std.Target) bool { | ||
| 1999 | return switch (target.cpu.arch) { | ||
| 2000 | .x86 => switch (target.os.tag) { | ||
| 2001 | .linux, .netbsd, .solaris, .illumos => true, | ||
| 2002 | else => false, | ||
| 2003 | }, | ||
| 2004 | .x86_64 => switch (target.os.tag) { | ||
| 2005 | .linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true, | ||
| 2006 | else => false, | ||
| 2007 | }, | ||
| 2008 | .arm => switch (target.os.tag) { | ||
| 2009 | .linux => true, | ||
| 2010 | else => false, | ||
| 2011 | }, | ||
| 2012 | .aarch64 => switch (target.os.tag) { | ||
| 2013 | .linux, .netbsd, .freebsd, .macos, .ios => true, | ||
| 2014 | else => false, | ||
| 2015 | }, | ||
| 2016 | // Unwinding is possible on other targets but this implementation does | ||
| 2017 | // not support them...yet! | ||
| 2018 | else => false, | ||
| 2019 | }; | ||
| 2020 | } | ||
| 1986 | 2021 | ||
| 1987 | fn unwindFrameMachODwarf( | 2022 | fn unwindFrameMachODwarf( |
| 1988 | context: *UnwindContext, | 2023 | context: *UnwindContext, |