authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-04-11 23:28:45-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-04-12 04:01:30-07:00
logdf2413cf69a834253bf36a45242a92da6fa8ecae
tree8f388776a64fc8a5ddeca6300150e170420e5a0b
parent312ef9558b68898b5402796a94f4bc97a05b308d

Removes dead code, updates some tests, fixes typos in comments, formats


10 files changed, 48 insertions(+), 72 deletions(-)

lib/std/debug.zig-1
......@@ -622,7 +622,6 @@ pub const StackTrace = struct {
622622 return_addresses: []usize,
623623 /// Indicates whether any stack frames were omitted from `return_addresses`.
624624 skipped: SkippedAddresses,
625
626625};
627626
628627/// Indicates how many addresses were skipped in a trace.
lib/std/debug/Pdb.zig+30-33
......@@ -285,7 +285,7 @@ pub const InlineSiteSymIterator = struct {
285285 .inlinesite,
286286 .inlinesite2,
287287 => return @ptrCast(inline_prefix),
288 else => {}
288 else => {},
289289 }
290290 }
291291
......@@ -332,9 +332,9 @@ pub const BinaryAnnotation = union(enum) {
332332 .file_id = self.file_id,
333333 .code_offset = self.code_offset,
334334 .code_length = b: {
335 if (self.code_length) |l| break :b l;
336 const end = next_code_offset orelse return null;
337 break :b end - self.code_offset;
335 if (self.code_length) |l| break :b l;
336 const end = next_code_offset orelse return null;
337 break :b end - self.code_offset;
338338 },
339339 };
340340 }
......@@ -345,7 +345,7 @@ pub const BinaryAnnotation = union(enum) {
345345 .annotations = annotations,
346346 .curr = .{
347347 .line_offset = 0,
348 .file_id = null,
348 .file_id = null,
349349 .code_offset = 0,
350350 .code_length = null,
351351 },
......@@ -395,22 +395,22 @@ pub const BinaryAnnotation = union(enum) {
395395 },
396396
397397 // Not emitted by LLVM at the time of writing, and we don't want to add support
398 // without a test csae. Safe to ignore since we don't use this info right now.
398 // without a test case. Safe to ignore since we don't use this info right now.
399399 .change_line_end_delta,
400400 .change_column_start,
401401 .change_column_end_delta,
402402 .change_column_end,
403 => {},
403 => {},
404404
405 // Not emitted by LLVM at the time of writing. Various sources conflict on how
406 // these opcodes should be interpreted, so we make no attempt to handle them.
405 // Not emitted by LLVM at the time of writing. Various sources conflict on how
406 // these opcodes should be interpreted, so we make no attempt to handle them.
407407 .code_offset,
408408 .change_code_offset_base,
409409 .change_range_kind,
410410 => {
411 self.annotations = .empty;
412 self.prev = null;
413 return null;
411 self.annotations = .empty;
412 self.prev = null;
413 return null;
414414 },
415415 }
416416
......@@ -457,8 +457,8 @@ pub const BinaryAnnotation = union(enum) {
457457 switch (op) {
458458 // Microsoft's docs say that invalid is used as padding, though it is left ambiguous
459459 // whether padding is allowed internally or only after all instructions are complete.
460 // Empircally, the latter appears to be the case, at lest with the output from LLVM that
461 // I've tested.
460 // Empirically, the latter appears to be the case, at least with the output from LLVM
461 // that I've tested.
462462 .invalid => return error.EndOfStream,
463463 .code_offset => return .{
464464 .code_offset = try expect(takePackedU32(reader)),
......@@ -547,7 +547,7 @@ pub const BinaryAnnotation = union(enum) {
547547 }
548548 }
549549
550 fn expect(value: anytype) error { ReadFailed }!@typeInfo(@TypeOf(value)).error_union.payload {
550 fn expect(value: anytype) error{ReadFailed}!@typeInfo(@TypeOf(value)).error_union.payload {
551551 comptime assert(@typeInfo(@TypeOf(value)).error_union.error_set == Io.Reader.Error);
552552 return value catch error.ReadFailed;
553553 }
......@@ -661,16 +661,16 @@ pub fn getSymbolName(self: *Pdb, proc_sym: *align(1) const pdb.ProcSym) []const
661661}
662662
663663pub const InlineeSourceLine = struct {
664 signature: pdb.InlineeSourceLineSignature,
665 info: *align(1) const pdb.InlineeSourceLine,
664 signature: pdb.InlineeSourceLineSignature,
665 info: *align(1) const pdb.InlineeSourceLine,
666666
667 fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool {
668 return lhs.info.inlinee < rhs.info.inlinee;
669 }
667 fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool {
668 return lhs.info.inlinee < rhs.info.inlinee;
669 }
670670
671 fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order {
672 return std.math.order(inlinee, self.info.inlinee);
673 }
671 fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order {
672 return std.math.order(inlinee, self.info.inlinee);
673 }
674674};
675675
676676/// Returns all `InlineeSourceLine`s for a given module with the given inlinee. Ideally there would
......@@ -694,7 +694,7 @@ pub fn getInlineeSourceLines(
694694
695695 // Linearly scan to the first match
696696 const begin = b: {
697 var begin = any;
697 var begin = any;
698698 while (begin > 0) {
699699 const prev = begin - 1;
700700 if (mod.inlinee_source_lines[prev].info.inlinee != inlinee) break;
......@@ -706,10 +706,9 @@ pub fn getInlineeSourceLines(
706706 // Linearly scan to the last match
707707 const end = b: {
708708 var end = any + 1;
709 while (
710 end < mod.inlinee_source_lines.len and
711 mod.inlinee_source_lines[end].info.inlinee == inlinee
712 ) : (end += 1) {}
709 while (end < mod.inlinee_source_lines.len and
710 mod.inlinee_source_lines[end].info.inlinee == inlinee) : (end += 1)
711 {}
713712 break :b end;
714713 };
715714
......@@ -844,8 +843,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
844843 while (subsects.takeStructPointer(pdb.DebugSubsectionHeader) catch null) |subsect_hdr| {
845844 var subsect: Io.Reader = .fixed(subsects.take(subsect_hdr.length) catch return null);
846845 if (subsect_hdr.kind == .inlinee_lines) {
847 const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little)
848 catch return error.InvalidDebugInfo;
846 const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little) catch return error.InvalidDebugInfo;
849847 const has_extra_files = switch (inlinee_source_line_signature) {
850848 .normal => false,
851849 .ex => true,
......@@ -855,8 +853,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
855853 if (has_extra_files) {
856854 const file_count = subsect.takeInt(u32, .little) catch
857855 return error.InvalidDebugInfo;
858 const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32))
859 catch return error.InvalidDebugInfo;
856 const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32)) catch return error.InvalidDebugInfo;
860857 subsect.discardAll(file_bytes) catch
861858 return error.InvalidDebugInfo;
862859 }
......@@ -868,7 +865,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
868865 }
869866 }
870867 }
871
868
872869 std.mem.sort(InlineeSourceLine, inlinee_source_lines.items, {}, InlineeSourceLine.lessThan);
873870 break :b try inlinee_source_lines.toOwnedSlice(gpa);
874871 };
lib/std/debug/SelfInfo/MachO.zig-14
......@@ -22,20 +22,6 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
2222 si.modules.deinit(gpa);
2323}
2424
25pub const SymbolIterator = struct {
26 curr: ?Error!std.debug.Symbol,
27
28 pub fn deinit(self: *SymbolIterator, _: Io) void {
29 self.* = undefined;
30 }
31
32 pub fn next(self: *SymbolIterator) ?Error!std.debug.Symbol {
33 const result = self.curr;
34 self.curr = null;
35 return result;
36 }
37};
38
3925pub fn getSymbols(si: *SelfInfo, io: Io, address: usize, resolve_inline_callers: bool) Error![]std.debug.Symbol {
4026 _ = resolve_inline_callers;
4127
lib/std/pdb.zig+1-6
......@@ -616,11 +616,7 @@ pub const InlineSiteSym2 = extern struct {
616616 invocations: u32,
617617};
618618
619pub const InlineeSourceLineSignature = enum(u32) {
620 normal = 0,
621 ex = 1,
622 _
623};
619pub const InlineeSourceLineSignature = enum(u32) { normal = 0, ex = 1, _ };
624620
625621pub const InlineeSourceLine = extern struct {
626622 inlinee: u32,
......@@ -651,4 +647,3 @@ pub const BinaryAnnotationOpcode = enum(u8) {
651647 change_code_length_and_code_offset = 12,
652648 change_column_end = 13,
653649};
654
lib/std/testing/FailingAllocator.zig+2-2
......@@ -138,8 +138,8 @@ pub fn getStackTrace(self: *FailingAllocator) std.debug.StackTrace {
138138 len += 1;
139139 }
140140 return .{
141 .return_addresses = &self.stack_addresses,
142 .index = len,
141 .return_addresses = self.stack_addresses[0..len],
142 .skipped = if (len == self.stack_addresses.len) .unknown else .none,
143143 };
144144}
145145
test/cases/disable_stack_tracing.zig+1-1
......@@ -9,7 +9,7 @@ pub fn main() !void {
99
1010 const captured_st = try foo(&stdout.interface, &st_buf);
1111 try std.debug.writeStackTrace(&captured_st, .{ .writer = &stdout.interface, .mode = .no_color });
12 try stdout.interface.print("stack trace index: {d}\n", .{captured_st.index});
12 try stdout.interface.print("stack trace index: {d}\n", .{captured_st.return_addresses.len});
1313
1414 try stdout.interface.flush();
1515}
test/error_traces.zig+1-2
......@@ -466,8 +466,7 @@ pub fn addCases(cases: *@import("tests.zig").ErrorTracesContext, os: std.Target.
466466 \\}
467467 ,
468468 .expect_error = "ThisIsSoSad",
469 .expect_trace =
470 switch (os) {
469 .expect_trace = switch (os) {
471470 // LLVM doesn't emit column info in the binary annotations for inlinee callees in PDBs,
472471 // so our expected result is slightly different for Windows than on other operating
473472 // systems.
test/src/convert-stack-trace.zig+10-9
......@@ -52,23 +52,24 @@ pub fn main(init: std.process.Init) !void {
5252 continue;
5353 }
5454
55 // If both the row and column are present, this it he column end. Otherwise it's the line end.
5655 const src_pos_end = std.mem.indexOf(u8, in_line, ": 0x") orelse {
5756 try w.writeAll(in_line);
5857 continue;
5958 };
60 const src_row_or_path_end = std.mem.lastIndexOfScalar(u8, in_line[0..src_pos_end], ':') orelse {
61 try w.writeAll(in_line);
62 continue;
59 const src_pos_start = b: {
60 const postfix = ".zig:";
61 const postfix_index = std.mem.lastIndexOf(u8, in_line[0..src_pos_end], postfix) orelse {
62 try w.writeAll(in_line);
63 continue;
64 };
65 break :b postfix_index + postfix.len;
6366 };
64 const src_path_end = std.mem.lastIndexOfScalar(u8, in_line[0..src_row_or_path_end], ':')
65 orelse src_row_or_path_end;
6667
67 const addr_end = std.mem.indexOfPos(u8, in_line, src_pos_end, " in ") orelse {
68 const addr_end = std.mem.findPos(u8, in_line, src_pos_end, " in ") orelse {
6869 try w.writeAll(in_line);
6970 continue;
7071 };
71 const symbol_end = std.mem.indexOfPos(u8, in_line, addr_end, " (") orelse {
72 const symbol_end = std.mem.findPos(u8, in_line, addr_end, " (") orelse {
7273 try w.writeAll(in_line);
7374 continue;
7475 };
......@@ -87,7 +88,7 @@ pub fn main(init: std.process.Init) !void {
8788 //
8889 // ...with that first '_' being replaced by its basename.
8990
90 const src_path = in_line[0..src_path_end];
91 const src_path = in_line[0..src_pos_start];
9192 const basename_start = if (std.mem.lastIndexOfAny(u8, src_path, "/\\")) |i| i + 1 else 0;
9293 const symbol_start = addr_end + " in ".len;
9394 try w.writeAll(in_line[basename_start..src_pos_end]);
test/standalone/coff_dwarf/main.zig+2-2
......@@ -12,13 +12,13 @@ pub fn main(init: std.process.Init) void {
1212 var add_addr: usize = undefined;
1313 _ = add(1, 2, &add_addr);
1414
15 const symbols = di.getSymbols(io, add_addr) catch |err| fatal("failed to get symbol: {t}", .{err});
15 const symbols = di.getSymbols(io, add_addr, false) catch |err| fatal("failed to get symbol: {t}", .{err});
1616 const debug_gpa = std.debug.getDebugInfoAllocator();
1717 defer for (symbols) |symbol| {
1818 if (symbol.source_location) |sl| {
1919 debug_gpa.free(sl.file_name);
2020 }
21 }
21 };
2222
2323 if (symbols.len != 1) fatal("expected 1 symbol, found {}", .{symbols.len});
2424 const symbol = symbols[0];
test/tests.zig+1-2
......@@ -2168,7 +2168,6 @@ pub fn addErrorTraceTests(
21682168 error_traces.addCases(darling_cases, .macos);
21692169 }
21702170
2171
21722171 return step;
21732172}
21742173
......@@ -2291,7 +2290,7 @@ pub fn addCliTests(b: *std.Build) *Step {
22912290 \\ return num * num;
22922291 \\}
22932292 \\extern fn zig_panic() noreturn;
2294 \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("builtin").StackTrace, _: ?usize) noreturn {
2293 \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace, _: ?usize) noreturn {
22952294 \\ _ = msg;
22962295 \\ _ = error_return_trace;
22972296 \\ zig_panic();