authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-13 10:29:20+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-30 13:44:54+01:00
log51d08f4b9b051d66534b77462a3bfb9bace9f1fb
treefb486d669517bc50049cff0d2e693230a6141686
parent5f0073896977fe4a177b4b7817ce2b59160ab29d
signaturelock-open Commit is signed but in an unrecognized format.

fix compile errors and minor bugs


5 files changed, 28 insertions(+), 20 deletions(-)

lib/compiler/test_runner.zig+4-4
......@@ -140,7 +140,7 @@ fn mainServer() !void {
140140 else => {
141141 fail = true;
142142 if (@errorReturnTrace()) |trace| {
143 std.debug.dumpStackTrace(trace.*);
143 std.debug.dumpStackTrace(trace);
144144 }
145145 },
146146 };
......@@ -182,7 +182,7 @@ fn mainServer() !void {
182182 error.SkipZigTest => return,
183183 else => {
184184 if (@errorReturnTrace()) |trace| {
185 std.debug.dumpStackTrace(trace.*);
185 std.debug.dumpStackTrace(trace);
186186 }
187187 std.debug.print("failed with error.{t}\n", .{err});
188188 std.process.exit(1);
......@@ -261,7 +261,7 @@ fn mainTerminal() void {
261261 std.debug.print("FAIL ({t})\n", .{err});
262262 }
263263 if (@errorReturnTrace()) |trace| {
264 std.debug.dumpStackTrace(trace.*);
264 std.debug.dumpStackTrace(trace);
265265 }
266266 test_node.end();
267267 },
......@@ -398,7 +398,7 @@ pub fn fuzz(
398398 error.SkipZigTest => return,
399399 else => {
400400 std.debug.lockStdErr();
401 if (@errorReturnTrace()) |trace| std.debug.dumpStackTrace(trace.*);
401 if (@errorReturnTrace()) |trace| std.debug.dumpStackTrace(trace);
402402 std.debug.print("failed with error.{t}\n", .{err});
403403 std.process.exit(1);
404404 },
lib/std/debug.zig+16-10
......@@ -754,6 +754,10 @@ pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void {
754754
755755/// Write a previously captured stack trace to `writer`, annotated with source locations.
756756pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_config: tty.Config) Writer.Error!void {
757 // Fetch `st.index` straight away. Aside from avoiding redundant loads, this prevents issues if
758 // `st` is `@errorReturnTrace()` and errors are encountered while writing the stack trace.
759 const n_frames = st.index;
760 if (n_frames == 0) return writer.writeAll("(empty stack trace)\n");
757761 const di_gpa = getDebugInfoAllocator();
758762 const di = getSelfDebugInfo() catch |err| switch (err) {
759763 error.UnsupportedTarget => {
......@@ -763,14 +767,13 @@ pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_c
763767 return;
764768 },
765769 };
766 if (st.index == 0) return writer.writeAll("(empty stack trace)\n");
767 const captured_frames = @min(st.index, st.instruction_addresses.len);
770 const captured_frames = @min(n_frames, st.instruction_addresses.len);
768771 for (st.instruction_addresses[0..captured_frames]) |return_address| {
769772 try printSourceAtAddress(di_gpa, di, writer, return_address -| 1, tty_config);
770773 }
771 if (st.index > captured_frames) {
774 if (n_frames > captured_frames) {
772775 tty_config.setColor(writer, .bold) catch {};
773 try writer.print("({d} additional stack frames skipped...)\n", .{st.index - captured_frames});
776 try writer.print("({d} additional stack frames skipped...)\n", .{n_frames - captured_frames});
774777 tty_config.setColor(writer, .reset) catch {};
775778 }
776779}
......@@ -853,7 +856,7 @@ const StackIterator = union(enum) {
853856 const di = getSelfDebugInfo() catch unreachable;
854857 const di_gpa = getDebugInfoAllocator();
855858 if (di.unwindFrame(di_gpa, unwind_context)) |ra| {
856 if (ra == 0) return .end;
859 if (ra <= 1) return .end;
857860 return .{ .frame = ra };
858861 } else |err| {
859862 const pc = unwind_context.pc;
......@@ -888,7 +891,9 @@ const StackIterator = union(enum) {
888891 if (bp != 0 and bp <= fp) return .end;
889892
890893 it.fp = bp;
891 return .{ .frame = ra_ptr.* };
894 const ra = ra_ptr.*;
895 if (ra <= 1) return .end;
896 return .{ .frame = ra };
892897 },
893898 }
894899 }
......@@ -1409,11 +1414,12 @@ test "manage resources correctly" {
14091414 return @returnAddress();
14101415 }
14111416 };
1412 var discarding: std.io.Writer.Discarding = .init(&.{});
1413 var di: SelfInfo = try .open(testing.allocator);
1414 defer di.deinit();
1417 const gpa = std.testing.allocator;
1418 var discarding: std.Io.Writer.Discarding = .init(&.{});
1419 var di: SelfInfo = .init;
1420 defer di.deinit(gpa);
14151421 try printSourceAtAddress(
1416 testing.allocator,
1422 gpa,
14171423 &di,
14181424 &discarding.writer,
14191425 S.showMyTrace(),
lib/std/debug/SelfInfo.zig+3-3
......@@ -18,8 +18,8 @@ const root = @import("root");
1818
1919const SelfInfo = @This();
2020
21modules: std.AutoArrayHashMapUnmanaged(usize, Module.DebugInfo),
22lookup_cache: Module.LookupCache,
21modules: if (target_supported) std.AutoArrayHashMapUnmanaged(usize, Module.DebugInfo) else void,
22lookup_cache: if (target_supported) Module.LookupCache else void,
2323
2424pub const Error = error{
2525 /// The required debug info is invalid or corrupted.
......@@ -40,7 +40,7 @@ pub const target_supported: bool = Module != void;
4040/// Indicates whether the `SelfInfo` implementation has support for unwinding on this target.
4141///
4242/// For whether DWARF unwinding is *theoretically* possible, see `Dwarf.abi.supportsUnwinding`.
43pub const supports_unwinding: bool = Module.supports_unwinding;
43pub const supports_unwinding: bool = target_supported and Module.supports_unwinding;
4444
4545pub const UnwindContext = if (supports_unwinding) Module.UnwindContext;
4646
lib/std/start.zig+4-2
......@@ -635,8 +635,10 @@ pub inline fn callMain() u8 {
635635 else => {},
636636 }
637637 std.log.err("{s}", .{@errorName(err)});
638 if (@errorReturnTrace()) |trace| {
639 std.debug.dumpStackTrace(trace);
638 if (native_os != .freestanding) {
639 if (@errorReturnTrace()) |trace| {
640 std.debug.dumpStackTrace(trace);
641 }
640642 }
641643 return 1;
642644 };
lib/std/testing/FailingAllocator.zig+1-1
......@@ -64,7 +64,7 @@ fn alloc(
6464 const self: *FailingAllocator = @ptrCast(@alignCast(ctx));
6565 if (self.alloc_index == self.fail_index) {
6666 if (!self.has_induced_failure) {
67 const st = std.debug.captureCurrentStackTrace(return_address, &self.stack_addresses);
67 const st = std.debug.captureCurrentStackTrace(.{ .first_address = return_address }, &self.stack_addresses);
6868 @memset(self.stack_addresses[@min(st.index, self.stack_addresses.len)..], 0);
6969 self.has_induced_failure = true;
7070 }