aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-09-12 03:24:24 +0100
committermlugg <mlugg@mlugg.co.uk>2025-09-30 13:44:53 +0100
commit344ab62b3fa4fc286b76a51ac47f0b8363339bee (patch)
tree0b89d332e961a968854142697ed72a55b8a1522f /lib/std/debug.zig
parentcf13b40946d5fbac1eb8963418a19b12a69023e8 (diff)
downloadzig-344ab62b3fa4fc286b76a51ac47f0b8363339bee.tar.gz
zig-344ab62b3fa4fc286b76a51ac47f0b8363339bee.zip
std.debug: don't attempt SelfInfo unwinding when unsupported
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 56769826b1..1fdf4f2495 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -678,6 +678,12 @@ pub fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_
tty_config.setColor(writer, .reset) catch {};
return;
},
+ error.CannotUnwindFromContext => {
+ tty_config.setColor(writer, .dim) catch {};
+ try writer.print("Cannot print stack trace: context unwind unavailable for target\n", .{});
+ tty_config.setColor(writer, .reset) catch {};
+ return;
+ },
};
defer it.deinit();
if (!it.stratOk(options.allow_unsafe_unwind)) {
@@ -787,7 +793,7 @@ const StackIterator = union(enum) {
/// It is important that this function is marked `inline` so that it can safely use
/// `@frameAddress` and `getContext` as the caller's stack frame and our own are one
/// and the same.
- inline fn init(context_opt: ?ThreadContextPtr, context_buf: *ThreadContextBuf) error{OutOfMemory}!StackIterator {
+ inline fn init(context_opt: ?ThreadContextPtr, context_buf: *ThreadContextBuf) error{ OutOfMemory, CannotUnwindFromContext }!StackIterator {
if (builtin.cpu.arch.isSPARC()) {
// Flush all the register windows on stack.
if (builtin.cpu.has(.sparc, .v9)) {
@@ -797,11 +803,12 @@ const StackIterator = union(enum) {
}
}
if (context_opt) |context| {
+ if (!SelfInfo.supports_unwinding) return error.CannotUnwindFromContext;
context_buf.* = context.*;
relocateContext(context_buf);
return .{ .di = try .init(context_buf, getDebugInfoAllocator()) };
}
- if (getContext(context_buf)) {
+ if (SelfInfo.supports_unwinding and getContext(context_buf)) {
return .{ .di = try .init(context_buf, getDebugInfoAllocator()) };
}
return .{ .fp = @frameAddress() };