Skip to content

Commit f33d3a5

Browse files
committed
std.debug: greatly expand target support for segfault handling/unwinding
I made a couple of decisions for this based on the fact that we don't expose the signal_ucontext_t type outside of the file: * Adding all the floating point and vector state to every ucontext_t and mcontext_t variant was way, way too much work, especially when we don't even use the stuff. So I deleted all that and kept only the bare minimum needed to reach into general-purpose registers. * There is no particularly compelling reason to stick to the naming and struct nesting used in the system headers. So we can actually unify the access patterns for almost all of these variants by taking some liberties here; as a result, fromPosixSignalContext() is now much nicer to read and extend.
1 parent 3f5e782 commit f33d3a5

File tree

3 files changed

+922
-681
lines changed

3 files changed

+922
-681
lines changed

lib/std/debug.zig

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,15 +1315,26 @@ fn getDebugInfoAllocator() Allocator {
13151315

13161316
/// Whether or not the current target can print useful debug information when a segfault occurs.
13171317
pub const have_segfault_handling_support = switch (native_os) {
1318+
.haiku,
13181319
.linux,
1319-
.macos,
1320+
.serenity,
1321+
1322+
.dragonfly,
1323+
.freebsd,
13201324
.netbsd,
1321-
.solaris,
1325+
.openbsd,
1326+
1327+
.driverkit,
1328+
.ios,
1329+
.macos,
1330+
.tvos,
1331+
.visionos,
1332+
.watchos,
1333+
13221334
.illumos,
1335+
.solaris,
1336+
13231337
.windows,
1324-
.freebsd,
1325-
.openbsd,
1326-
.serenity,
13271338
=> true,
13281339

13291340
else => false,
@@ -1406,11 +1417,26 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
14061417
}
14071418
}
14081419
const addr: usize = switch (native_os) {
1409-
.linux => @intFromPtr(info.fields.sigfault.addr),
1410-
.freebsd, .macos, .serenity => @intFromPtr(info.addr),
1411-
.netbsd => @intFromPtr(info.info.reason.fault.addr),
1412-
.openbsd => @intFromPtr(info.data.fault.addr),
1413-
.solaris, .illumos => @intFromPtr(info.reason.fault.addr),
1420+
.serenity,
1421+
.dragonfly,
1422+
.freebsd,
1423+
.driverkit,
1424+
.ios,
1425+
.macos,
1426+
.tvos,
1427+
.visionos,
1428+
.watchos,
1429+
=> @intFromPtr(info.addr),
1430+
.linux,
1431+
=> @intFromPtr(info.fields.sigfault.addr),
1432+
.netbsd,
1433+
=> @intFromPtr(info.info.reason.fault.addr),
1434+
.haiku,
1435+
.openbsd,
1436+
=> @intFromPtr(info.data.fault.addr),
1437+
.illumos,
1438+
.solaris,
1439+
=> @intFromPtr(info.reason.fault.addr),
14141440
else => comptime unreachable,
14151441
};
14161442
const name = switch (sig) {

lib/std/debug/SelfInfo/Elf.zig

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ pub const can_unwind: bool = s: {
9494
// Notably, we are yet to support unwinding on ARM. There, unwinding is not done through
9595
// `.eh_frame`, but instead with the `.ARM.exidx` section, which has a different format.
9696
const archs: []const std.Target.Cpu.Arch = switch (builtin.target.os.tag) {
97+
// Not supported yet: arm, m68k, sparc64
98+
.haiku => &.{
99+
.aarch64,
100+
.powerpc,
101+
.riscv64,
102+
.x86,
103+
.x86_64,
104+
},
105+
// Not supported yet: arc, arm/armeb/thumb/thumbeb, csky, m68k, or1k, sparc/sparc64, xtensa
97106
.linux => &.{
98107
.aarch64,
99108
.aarch64_be,
@@ -113,31 +122,54 @@ pub const can_unwind: bool = s: {
113122
.x86,
114123
.x86_64,
115124
},
116-
.netbsd => &.{
125+
.serenity => &.{
117126
.aarch64,
118-
.aarch64_be,
119-
.x86,
120127
.x86_64,
128+
.riscv64,
121129
},
122-
.freebsd => &.{
130+
131+
.dragonfly => &.{
123132
.x86_64,
133+
},
134+
// Not supported yet: arm
135+
.freebsd => &.{
124136
.aarch64,
137+
.powerpc64,
138+
.powerpc64le,
139+
.riscv64,
140+
.x86_64,
125141
},
126-
.openbsd => &.{
142+
// Not supported yet: arm/armeb, m68k, mips64/mips64el, sparc/sparc64
143+
.netbsd => &.{
144+
.aarch64,
145+
.aarch64_be,
146+
.mips,
147+
.mipsel,
148+
.powerpc,
149+
.x86,
127150
.x86_64,
128151
},
129-
.solaris => &.{
152+
// Not supported yet: arm, sparc64
153+
.openbsd => &.{
154+
.aarch64,
155+
.mips64,
156+
.mips64el,
157+
.powerpc,
158+
.powerpc64,
159+
.riscv64,
160+
.x86,
130161
.x86_64,
131162
},
163+
132164
.illumos => &.{
133165
.x86,
134166
.x86_64,
135167
},
136-
.serenity => &.{
168+
// Not supported yet: sparc64
169+
.solaris => &.{
137170
.x86_64,
138-
.aarch64,
139-
.riscv64,
140171
},
172+
141173
else => unreachable,
142174
};
143175
for (archs) |a| {

0 commit comments

Comments
 (0)