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 {...@@ -622,7 +622,6 @@ pub const StackTrace = struct {
622 return_addresses: []usize,622 return_addresses: []usize,
623 /// Indicates whether any stack frames were omitted from `return_addresses`.623 /// Indicates whether any stack frames were omitted from `return_addresses`.
624 skipped: SkippedAddresses,624 skipped: SkippedAddresses,
625
626};625};
627626
628/// Indicates how many addresses were skipped in a trace.627/// Indicates how many addresses were skipped in a trace.
lib/std/debug/Pdb.zig+30-33
...@@ -285,7 +285,7 @@ pub const InlineSiteSymIterator = struct {...@@ -285,7 +285,7 @@ pub const InlineSiteSymIterator = struct {
285 .inlinesite,285 .inlinesite,
286 .inlinesite2,286 .inlinesite2,
287 => return @ptrCast(inline_prefix),287 => return @ptrCast(inline_prefix),
288 else => {}288 else => {},
289 }289 }
290 }290 }
291291
...@@ -332,9 +332,9 @@ pub const BinaryAnnotation = union(enum) {...@@ -332,9 +332,9 @@ pub const BinaryAnnotation = union(enum) {
332 .file_id = self.file_id,332 .file_id = self.file_id,
333 .code_offset = self.code_offset,333 .code_offset = self.code_offset,
334 .code_length = b: {334 .code_length = b: {
335 if (self.code_length) |l| break :b l; 335 if (self.code_length) |l| break :b l;
336 const end = next_code_offset orelse return null;336 const end = next_code_offset orelse return null;
337 break :b end - self.code_offset;337 break :b end - self.code_offset;
338 },338 },
339 };339 };
340 }340 }
...@@ -345,7 +345,7 @@ pub const BinaryAnnotation = union(enum) {...@@ -345,7 +345,7 @@ pub const BinaryAnnotation = union(enum) {
345 .annotations = annotations,345 .annotations = annotations,
346 .curr = .{346 .curr = .{
347 .line_offset = 0,347 .line_offset = 0,
348 .file_id = null,348 .file_id = null,
349 .code_offset = 0,349 .code_offset = 0,
350 .code_length = null,350 .code_length = null,
351 },351 },
...@@ -395,22 +395,22 @@ pub const BinaryAnnotation = union(enum) {...@@ -395,22 +395,22 @@ pub const BinaryAnnotation = union(enum) {
395 },395 },
396396
397 // Not emitted by LLVM at the time of writing, and we don't want to add support397 // 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.
399 .change_line_end_delta,399 .change_line_end_delta,
400 .change_column_start,400 .change_column_start,
401 .change_column_end_delta,401 .change_column_end_delta,
402 .change_column_end,402 .change_column_end,
403 => {},403 => {},
404404
405 // Not emitted by LLVM at the time of writing. Various sources conflict on how405 // 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.406 // these opcodes should be interpreted, so we make no attempt to handle them.
407 .code_offset,407 .code_offset,
408 .change_code_offset_base,408 .change_code_offset_base,
409 .change_range_kind,409 .change_range_kind,
410 => {410 => {
411 self.annotations = .empty; 411 self.annotations = .empty;
412 self.prev = null;412 self.prev = null;
413 return null;413 return null;
414 },414 },
415 }415 }
416416
...@@ -457,8 +457,8 @@ pub const BinaryAnnotation = union(enum) {...@@ -457,8 +457,8 @@ pub const BinaryAnnotation = union(enum) {
457 switch (op) {457 switch (op) {
458 // Microsoft's docs say that invalid is used as padding, though it is left ambiguous458 // Microsoft's docs say that invalid is used as padding, though it is left ambiguous
459 // whether padding is allowed internally or only after all instructions are complete.459 // 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 that460 // Empirically, the latter appears to be the case, at least with the output from LLVM
461 // I've tested.461 // that I've tested.
462 .invalid => return error.EndOfStream,462 .invalid => return error.EndOfStream,
463 .code_offset => return .{463 .code_offset => return .{
464 .code_offset = try expect(takePackedU32(reader)),464 .code_offset = try expect(takePackedU32(reader)),
...@@ -547,7 +547,7 @@ pub const BinaryAnnotation = union(enum) {...@@ -547,7 +547,7 @@ pub const BinaryAnnotation = union(enum) {
547 }547 }
548 }548 }
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 {
551 comptime assert(@typeInfo(@TypeOf(value)).error_union.error_set == Io.Reader.Error);551 comptime assert(@typeInfo(@TypeOf(value)).error_union.error_set == Io.Reader.Error);
552 return value catch error.ReadFailed;552 return value catch error.ReadFailed;
553 }553 }
...@@ -661,16 +661,16 @@ pub fn getSymbolName(self: *Pdb, proc_sym: *align(1) const pdb.ProcSym) []const...@@ -661,16 +661,16 @@ pub fn getSymbolName(self: *Pdb, proc_sym: *align(1) const pdb.ProcSym) []const
661}661}
662662
663pub const InlineeSourceLine = struct {663pub const InlineeSourceLine = struct {
664 signature: pdb.InlineeSourceLineSignature,664 signature: pdb.InlineeSourceLineSignature,
665 info: *align(1) const pdb.InlineeSourceLine, 665 info: *align(1) const pdb.InlineeSourceLine,
666666
667 fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool {667 fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool {
668 return lhs.info.inlinee < rhs.info.inlinee;668 return lhs.info.inlinee < rhs.info.inlinee;
669 }669 }
670670
671 fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order {671 fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order {
672 return std.math.order(inlinee, self.info.inlinee);672 return std.math.order(inlinee, self.info.inlinee);
673 }673 }
674};674};
675675
676/// Returns all `InlineeSourceLine`s for a given module with the given inlinee. Ideally there would676/// Returns all `InlineeSourceLine`s for a given module with the given inlinee. Ideally there would
...@@ -694,7 +694,7 @@ pub fn getInlineeSourceLines(...@@ -694,7 +694,7 @@ pub fn getInlineeSourceLines(
694694
695 // Linearly scan to the first match695 // Linearly scan to the first match
696 const begin = b: {696 const begin = b: {
697 var begin = any; 697 var begin = any;
698 while (begin > 0) {698 while (begin > 0) {
699 const prev = begin - 1;699 const prev = begin - 1;
700 if (mod.inlinee_source_lines[prev].info.inlinee != inlinee) break;700 if (mod.inlinee_source_lines[prev].info.inlinee != inlinee) break;
...@@ -706,10 +706,9 @@ pub fn getInlineeSourceLines(...@@ -706,10 +706,9 @@ pub fn getInlineeSourceLines(
706 // Linearly scan to the last match706 // Linearly scan to the last match
707 const end = b: {707 const end = b: {
708 var end = any + 1;708 var end = any + 1;
709 while (709 while (end < mod.inlinee_source_lines.len and
710 end < mod.inlinee_source_lines.len and710 mod.inlinee_source_lines[end].info.inlinee == inlinee) : (end += 1)
711 mod.inlinee_source_lines[end].info.inlinee == inlinee711 {}
712 ) : (end += 1) {}
713 break :b end;712 break :b end;
714 };713 };
715714
...@@ -844,8 +843,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {...@@ -844,8 +843,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
844 while (subsects.takeStructPointer(pdb.DebugSubsectionHeader) catch null) |subsect_hdr| {843 while (subsects.takeStructPointer(pdb.DebugSubsectionHeader) catch null) |subsect_hdr| {
845 var subsect: Io.Reader = .fixed(subsects.take(subsect_hdr.length) catch return null);844 var subsect: Io.Reader = .fixed(subsects.take(subsect_hdr.length) catch return null);
846 if (subsect_hdr.kind == .inlinee_lines) {845 if (subsect_hdr.kind == .inlinee_lines) {
847 const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little)846 const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little) catch return error.InvalidDebugInfo;
848 catch return error.InvalidDebugInfo;
849 const has_extra_files = switch (inlinee_source_line_signature) {847 const has_extra_files = switch (inlinee_source_line_signature) {
850 .normal => false,848 .normal => false,
851 .ex => true,849 .ex => true,
...@@ -855,8 +853,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {...@@ -855,8 +853,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
855 if (has_extra_files) {853 if (has_extra_files) {
856 const file_count = subsect.takeInt(u32, .little) catch854 const file_count = subsect.takeInt(u32, .little) catch
857 return error.InvalidDebugInfo;855 return error.InvalidDebugInfo;
858 const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32))856 const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32)) catch return error.InvalidDebugInfo;
859 catch return error.InvalidDebugInfo;
860 subsect.discardAll(file_bytes) catch857 subsect.discardAll(file_bytes) catch
861 return error.InvalidDebugInfo;858 return error.InvalidDebugInfo;
862 }859 }
...@@ -868,7 +865,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {...@@ -868,7 +865,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
868 }865 }
869 }866 }
870 }867 }
871 868
872 std.mem.sort(InlineeSourceLine, inlinee_source_lines.items, {}, InlineeSourceLine.lessThan);869 std.mem.sort(InlineeSourceLine, inlinee_source_lines.items, {}, InlineeSourceLine.lessThan);
873 break :b try inlinee_source_lines.toOwnedSlice(gpa);870 break :b try inlinee_source_lines.toOwnedSlice(gpa);
874 };871 };
lib/std/debug/SelfInfo/MachO.zig-14
...@@ -22,20 +22,6 @@ pub fn deinit(si: *SelfInfo, io: Io) void {...@@ -22,20 +22,6 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
22 si.modules.deinit(gpa);22 si.modules.deinit(gpa);
23}23}
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
39pub fn getSymbols(si: *SelfInfo, io: Io, address: usize, resolve_inline_callers: bool) Error![]std.debug.Symbol {25pub fn getSymbols(si: *SelfInfo, io: Io, address: usize, resolve_inline_callers: bool) Error![]std.debug.Symbol {
40 _ = resolve_inline_callers;26 _ = resolve_inline_callers;
4127
lib/std/pdb.zig+1-6
...@@ -616,11 +616,7 @@ pub const InlineSiteSym2 = extern struct {...@@ -616,11 +616,7 @@ pub const InlineSiteSym2 = extern struct {
616 invocations: u32,616 invocations: u32,
617};617};
618618
619pub const InlineeSourceLineSignature = enum(u32) {619pub const InlineeSourceLineSignature = enum(u32) { normal = 0, ex = 1, _ };
620 normal = 0,
621 ex = 1,
622 _
623};
624620
625pub const InlineeSourceLine = extern struct {621pub const InlineeSourceLine = extern struct {
626 inlinee: u32,622 inlinee: u32,
...@@ -651,4 +647,3 @@ pub const BinaryAnnotationOpcode = enum(u8) {...@@ -651,4 +647,3 @@ pub const BinaryAnnotationOpcode = enum(u8) {
651 change_code_length_and_code_offset = 12,647 change_code_length_and_code_offset = 12,
652 change_column_end = 13,648 change_column_end = 13,
653};649};
654
lib/std/testing/FailingAllocator.zig+2-2
...@@ -138,8 +138,8 @@ pub fn getStackTrace(self: *FailingAllocator) std.debug.StackTrace {...@@ -138,8 +138,8 @@ pub fn getStackTrace(self: *FailingAllocator) std.debug.StackTrace {
138 len += 1;138 len += 1;
139 }139 }
140 return .{140 return .{
141 .return_addresses = &self.stack_addresses,141 .return_addresses = self.stack_addresses[0..len],
142 .index = len,142 .skipped = if (len == self.stack_addresses.len) .unknown else .none,
143 };143 };
144}144}
145145
test/cases/disable_stack_tracing.zig+1-1
...@@ -9,7 +9,7 @@ pub fn main() !void {...@@ -9,7 +9,7 @@ pub fn main() !void {
99
10 const captured_st = try foo(&stdout.interface, &st_buf);10 const captured_st = try foo(&stdout.interface, &st_buf);
11 try std.debug.writeStackTrace(&captured_st, .{ .writer = &stdout.interface, .mode = .no_color });11 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
14 try stdout.interface.flush();14 try stdout.interface.flush();
15}15}
test/error_traces.zig+1-2
...@@ -466,8 +466,7 @@ pub fn addCases(cases: *@import("tests.zig").ErrorTracesContext, os: std.Target....@@ -466,8 +466,7 @@ pub fn addCases(cases: *@import("tests.zig").ErrorTracesContext, os: std.Target.
466 \\}466 \\}
467 ,467 ,
468 .expect_error = "ThisIsSoSad",468 .expect_error = "ThisIsSoSad",
469 .expect_trace =469 .expect_trace = switch (os) {
470 switch (os) {
471 // LLVM doesn't emit column info in the binary annotations for inlinee callees in PDBs,470 // LLVM doesn't emit column info in the binary annotations for inlinee callees in PDBs,
472 // so our expected result is slightly different for Windows than on other operating471 // so our expected result is slightly different for Windows than on other operating
473 // systems.472 // systems.
test/src/convert-stack-trace.zig+10-9
...@@ -52,23 +52,24 @@ pub fn main(init: std.process.Init) !void {...@@ -52,23 +52,24 @@ pub fn main(init: std.process.Init) !void {
52 continue;52 continue;
53 }53 }
5454
55 // If both the row and column are present, this it he column end. Otherwise it's the line end.
56 const src_pos_end = std.mem.indexOf(u8, in_line, ": 0x") orelse {55 const src_pos_end = std.mem.indexOf(u8, in_line, ": 0x") orelse {
57 try w.writeAll(in_line);56 try w.writeAll(in_line);
58 continue;57 continue;
59 };58 };
60 const src_row_or_path_end = std.mem.lastIndexOfScalar(u8, in_line[0..src_pos_end], ':') orelse {59 const src_pos_start = b: {
61 try w.writeAll(in_line);60 const postfix = ".zig:";
62 continue;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;
63 };66 };
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 {
68 try w.writeAll(in_line);69 try w.writeAll(in_line);
69 continue;70 continue;
70 };71 };
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 {
72 try w.writeAll(in_line);73 try w.writeAll(in_line);
73 continue;74 continue;
74 };75 };
...@@ -87,7 +88,7 @@ pub fn main(init: std.process.Init) !void {...@@ -87,7 +88,7 @@ pub fn main(init: std.process.Init) !void {
87 //88 //
88 // ...with that first '_' being replaced by its basename.89 // ...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];
91 const basename_start = if (std.mem.lastIndexOfAny(u8, src_path, "/\\")) |i| i + 1 else 0;92 const basename_start = if (std.mem.lastIndexOfAny(u8, src_path, "/\\")) |i| i + 1 else 0;
92 const symbol_start = addr_end + " in ".len;93 const symbol_start = addr_end + " in ".len;
93 try w.writeAll(in_line[basename_start..src_pos_end]);94 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 {...@@ -12,13 +12,13 @@ pub fn main(init: std.process.Init) void {
12 var add_addr: usize = undefined;12 var add_addr: usize = undefined;
13 _ = add(1, 2, &add_addr);13 _ = 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});
16 const debug_gpa = std.debug.getDebugInfoAllocator();16 const debug_gpa = std.debug.getDebugInfoAllocator();
17 defer for (symbols) |symbol| {17 defer for (symbols) |symbol| {
18 if (symbol.source_location) |sl| {18 if (symbol.source_location) |sl| {
19 debug_gpa.free(sl.file_name);19 debug_gpa.free(sl.file_name);
20 }20 }
21 }21 };
2222
23 if (symbols.len != 1) fatal("expected 1 symbol, found {}", .{symbols.len});23 if (symbols.len != 1) fatal("expected 1 symbol, found {}", .{symbols.len});
24 const symbol = symbols[0];24 const symbol = symbols[0];
test/tests.zig+1-2
...@@ -2168,7 +2168,6 @@ pub fn addErrorTraceTests(...@@ -2168,7 +2168,6 @@ pub fn addErrorTraceTests(
2168 error_traces.addCases(darling_cases, .macos);2168 error_traces.addCases(darling_cases, .macos);
2169 }2169 }
21702170
2171
2172 return step;2171 return step;
2173}2172}
21742173
...@@ -2291,7 +2290,7 @@ pub fn addCliTests(b: *std.Build) *Step {...@@ -2291,7 +2290,7 @@ pub fn addCliTests(b: *std.Build) *Step {
2291 \\ return num * num;2290 \\ return num * num;
2292 \\}2291 \\}
2293 \\extern fn zig_panic() noreturn;2292 \\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 {
2295 \\ _ = msg;2294 \\ _ = msg;
2296 \\ _ = error_return_trace;2295 \\ _ = error_return_trace;
2297 \\ zig_panic();2296 \\ zig_panic();