zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit df2413cf69a834253bf36a45242a92da6fa8ecae (tree)
parent 312ef9558b68898b5402796a94f4bc97a05b308d
Author: Mason Remaley <mason@gamesbymason.com>
Date:   Sat, 11 Apr 2026 23:28:45 -0700

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

Diffstat:
Mlib/std/debug.zig | 1-
Mlib/std/debug/Pdb.zig | 63++++++++++++++++++++++++++++++---------------------------------
Mlib/std/debug/SelfInfo/MachO.zig | 14--------------
Mlib/std/pdb.zig | 7+------
Mlib/std/testing/FailingAllocator.zig | 4++--
Mtest/cases/disable_stack_tracing.zig | 2+-
Mtest/error_traces.zig | 3+--
Mtest/src/convert-stack-trace.zig | 19++++++++++---------
Mtest/standalone/coff_dwarf/main.zig | 4++--
Mtest/tests.zig | 3+--
10 files changed, 48 insertions(+), 72 deletions(-)

diff --git a/lib/std/debug.zig b/lib/std/debug.zig @@ -622,7 +622,6 @@ pub const StackTrace = struct { return_addresses: []usize, /// Indicates whether any stack frames were omitted from `return_addresses`. skipped: SkippedAddresses, - }; /// Indicates how many addresses were skipped in a trace. diff --git a/lib/std/debug/Pdb.zig b/lib/std/debug/Pdb.zig @@ -285,7 +285,7 @@ pub const InlineSiteSymIterator = struct { .inlinesite, .inlinesite2, => return @ptrCast(inline_prefix), - else => {} + else => {}, } } @@ -332,9 +332,9 @@ pub const BinaryAnnotation = union(enum) { .file_id = self.file_id, .code_offset = self.code_offset, .code_length = b: { - if (self.code_length) |l| break :b l; - const end = next_code_offset orelse return null; - break :b end - self.code_offset; + if (self.code_length) |l| break :b l; + const end = next_code_offset orelse return null; + break :b end - self.code_offset; }, }; } @@ -345,7 +345,7 @@ pub const BinaryAnnotation = union(enum) { .annotations = annotations, .curr = .{ .line_offset = 0, - .file_id = null, + .file_id = null, .code_offset = 0, .code_length = null, }, @@ -395,22 +395,22 @@ pub const BinaryAnnotation = union(enum) { }, // Not emitted by LLVM at the time of writing, and we don't want to add support - // without a test csae. Safe to ignore since we don't use this info right now. + // without a test case. Safe to ignore since we don't use this info right now. .change_line_end_delta, .change_column_start, .change_column_end_delta, .change_column_end, - => {}, + => {}, - // Not emitted by LLVM at the time of writing. Various sources conflict on how - // these opcodes should be interpreted, so we make no attempt to handle them. + // Not emitted by LLVM at the time of writing. Various sources conflict on how + // these opcodes should be interpreted, so we make no attempt to handle them. .code_offset, .change_code_offset_base, .change_range_kind, => { - self.annotations = .empty; - self.prev = null; - return null; + self.annotations = .empty; + self.prev = null; + return null; }, } @@ -457,8 +457,8 @@ pub const BinaryAnnotation = union(enum) { switch (op) { // Microsoft's docs say that invalid is used as padding, though it is left ambiguous // whether padding is allowed internally or only after all instructions are complete. - // Empircally, the latter appears to be the case, at lest with the output from LLVM that - // I've tested. + // Empirically, the latter appears to be the case, at least with the output from LLVM + // that I've tested. .invalid => return error.EndOfStream, .code_offset => return .{ .code_offset = try expect(takePackedU32(reader)), @@ -547,7 +547,7 @@ pub const BinaryAnnotation = union(enum) { } } - fn expect(value: anytype) error { ReadFailed }!@typeInfo(@TypeOf(value)).error_union.payload { + fn expect(value: anytype) error{ReadFailed}!@typeInfo(@TypeOf(value)).error_union.payload { comptime assert(@typeInfo(@TypeOf(value)).error_union.error_set == Io.Reader.Error); return value catch error.ReadFailed; } @@ -661,16 +661,16 @@ pub fn getSymbolName(self: *Pdb, proc_sym: *align(1) const pdb.ProcSym) []const } pub const InlineeSourceLine = struct { - signature: pdb.InlineeSourceLineSignature, - info: *align(1) const pdb.InlineeSourceLine, + signature: pdb.InlineeSourceLineSignature, + info: *align(1) const pdb.InlineeSourceLine, - fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool { - return lhs.info.inlinee < rhs.info.inlinee; - } + fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool { + return lhs.info.inlinee < rhs.info.inlinee; + } - fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order { - return std.math.order(inlinee, self.info.inlinee); - } + fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order { + return std.math.order(inlinee, self.info.inlinee); + } }; /// Returns all `InlineeSourceLine`s for a given module with the given inlinee. Ideally there would @@ -694,7 +694,7 @@ pub fn getInlineeSourceLines( // Linearly scan to the first match const begin = b: { - var begin = any; + var begin = any; while (begin > 0) { const prev = begin - 1; if (mod.inlinee_source_lines[prev].info.inlinee != inlinee) break; @@ -706,10 +706,9 @@ pub fn getInlineeSourceLines( // Linearly scan to the last match const end = b: { var end = any + 1; - while ( - end < mod.inlinee_source_lines.len and - mod.inlinee_source_lines[end].info.inlinee == inlinee - ) : (end += 1) {} + while (end < mod.inlinee_source_lines.len and + mod.inlinee_source_lines[end].info.inlinee == inlinee) : (end += 1) + {} break :b end; }; @@ -844,8 +843,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module { while (subsects.takeStructPointer(pdb.DebugSubsectionHeader) catch null) |subsect_hdr| { var subsect: Io.Reader = .fixed(subsects.take(subsect_hdr.length) catch return null); if (subsect_hdr.kind == .inlinee_lines) { - const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little) - catch return error.InvalidDebugInfo; + const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little) catch return error.InvalidDebugInfo; const has_extra_files = switch (inlinee_source_line_signature) { .normal => false, .ex => true, @@ -855,8 +853,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module { if (has_extra_files) { const file_count = subsect.takeInt(u32, .little) catch return error.InvalidDebugInfo; - const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32)) - catch return error.InvalidDebugInfo; + const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32)) catch return error.InvalidDebugInfo; subsect.discardAll(file_bytes) catch return error.InvalidDebugInfo; } @@ -868,7 +865,7 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module { } } } - + std.mem.sort(InlineeSourceLine, inlinee_source_lines.items, {}, InlineeSourceLine.lessThan); break :b try inlinee_source_lines.toOwnedSlice(gpa); }; diff --git a/lib/std/debug/SelfInfo/MachO.zig b/lib/std/debug/SelfInfo/MachO.zig @@ -22,20 +22,6 @@ pub fn deinit(si: *SelfInfo, io: Io) void { si.modules.deinit(gpa); } -pub const SymbolIterator = struct { - curr: ?Error!std.debug.Symbol, - - pub fn deinit(self: *SymbolIterator, _: Io) void { - self.* = undefined; - } - - pub fn next(self: *SymbolIterator) ?Error!std.debug.Symbol { - const result = self.curr; - self.curr = null; - return result; - } -}; - pub fn getSymbols(si: *SelfInfo, io: Io, address: usize, resolve_inline_callers: bool) Error![]std.debug.Symbol { _ = resolve_inline_callers; diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig @@ -616,11 +616,7 @@ pub const InlineSiteSym2 = extern struct { invocations: u32, }; -pub const InlineeSourceLineSignature = enum(u32) { - normal = 0, - ex = 1, - _ -}; +pub const InlineeSourceLineSignature = enum(u32) { normal = 0, ex = 1, _ }; pub const InlineeSourceLine = extern struct { inlinee: u32, @@ -651,4 +647,3 @@ pub const BinaryAnnotationOpcode = enum(u8) { change_code_length_and_code_offset = 12, change_column_end = 13, }; - diff --git a/lib/std/testing/FailingAllocator.zig b/lib/std/testing/FailingAllocator.zig @@ -138,8 +138,8 @@ pub fn getStackTrace(self: *FailingAllocator) std.debug.StackTrace { len += 1; } return .{ - .return_addresses = &self.stack_addresses, - .index = len, + .return_addresses = self.stack_addresses[0..len], + .skipped = if (len == self.stack_addresses.len) .unknown else .none, }; } diff --git a/test/cases/disable_stack_tracing.zig b/test/cases/disable_stack_tracing.zig @@ -9,7 +9,7 @@ pub fn main() !void { const captured_st = try foo(&stdout.interface, &st_buf); try std.debug.writeStackTrace(&captured_st, .{ .writer = &stdout.interface, .mode = .no_color }); - try stdout.interface.print("stack trace index: {d}\n", .{captured_st.index}); + try stdout.interface.print("stack trace index: {d}\n", .{captured_st.return_addresses.len}); try stdout.interface.flush(); } diff --git a/test/error_traces.zig b/test/error_traces.zig @@ -466,8 +466,7 @@ pub fn addCases(cases: *@import("tests.zig").ErrorTracesContext, os: std.Target. \\} , .expect_error = "ThisIsSoSad", - .expect_trace = - switch (os) { + .expect_trace = switch (os) { // LLVM doesn't emit column info in the binary annotations for inlinee callees in PDBs, // so our expected result is slightly different for Windows than on other operating // systems. diff --git a/test/src/convert-stack-trace.zig b/test/src/convert-stack-trace.zig @@ -52,23 +52,24 @@ pub fn main(init: std.process.Init) !void { continue; } - // If both the row and column are present, this it he column end. Otherwise it's the line end. const src_pos_end = std.mem.indexOf(u8, in_line, ": 0x") orelse { try w.writeAll(in_line); continue; }; - const src_row_or_path_end = std.mem.lastIndexOfScalar(u8, in_line[0..src_pos_end], ':') orelse { - try w.writeAll(in_line); - continue; + const src_pos_start = b: { + const postfix = ".zig:"; + const postfix_index = std.mem.lastIndexOf(u8, in_line[0..src_pos_end], postfix) orelse { + try w.writeAll(in_line); + continue; + }; + break :b postfix_index + postfix.len; }; - const src_path_end = std.mem.lastIndexOfScalar(u8, in_line[0..src_row_or_path_end], ':') - orelse src_row_or_path_end; - const addr_end = std.mem.indexOfPos(u8, in_line, src_pos_end, " in ") orelse { + const addr_end = std.mem.findPos(u8, in_line, src_pos_end, " in ") orelse { try w.writeAll(in_line); continue; }; - const symbol_end = std.mem.indexOfPos(u8, in_line, addr_end, " (") orelse { + const symbol_end = std.mem.findPos(u8, in_line, addr_end, " (") orelse { try w.writeAll(in_line); continue; }; @@ -87,7 +88,7 @@ pub fn main(init: std.process.Init) !void { // // ...with that first '_' being replaced by its basename. - const src_path = in_line[0..src_path_end]; + const src_path = in_line[0..src_pos_start]; const basename_start = if (std.mem.lastIndexOfAny(u8, src_path, "/\\")) |i| i + 1 else 0; const symbol_start = addr_end + " in ".len; try w.writeAll(in_line[basename_start..src_pos_end]); diff --git a/test/standalone/coff_dwarf/main.zig b/test/standalone/coff_dwarf/main.zig @@ -12,13 +12,13 @@ pub fn main(init: std.process.Init) void { var add_addr: usize = undefined; _ = add(1, 2, &add_addr); - const symbols = di.getSymbols(io, add_addr) catch |err| fatal("failed to get symbol: {t}", .{err}); + const symbols = di.getSymbols(io, add_addr, false) catch |err| fatal("failed to get symbol: {t}", .{err}); const debug_gpa = std.debug.getDebugInfoAllocator(); defer for (symbols) |symbol| { if (symbol.source_location) |sl| { debug_gpa.free(sl.file_name); } - } + }; if (symbols.len != 1) fatal("expected 1 symbol, found {}", .{symbols.len}); const symbol = symbols[0]; diff --git a/test/tests.zig b/test/tests.zig @@ -2168,7 +2168,6 @@ pub fn addErrorTraceTests( error_traces.addCases(darling_cases, .macos); } - return step; } @@ -2291,7 +2290,7 @@ pub fn addCliTests(b: *std.Build) *Step { \\ return num * num; \\} \\extern fn zig_panic() noreturn; - \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("builtin").StackTrace, _: ?usize) noreturn { + \\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace, _: ?usize) noreturn { \\ _ = msg; \\ _ = error_return_trace; \\ zig_panic();