diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-09-30 20:24:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-30 20:24:58 +0100 |
| commit | b64535e3c8770db9bf314fc14d1b2b276b864f72 (patch) | |
| tree | 4a6f90029d8feff983889a133326fbe2a4e3465d /lib/std/Build | |
| parent | 7adb15892eada307b43a6a7844d3e51720f8992d (diff) | |
| parent | 1120546f72405ac263dce7414eb71ca4e6c96fc8 (diff) | |
| download | zig-b64535e3c8770db9bf314fc14d1b2b276b864f72.tar.gz zig-b64535e3c8770db9bf314fc14d1b2b276b864f72.zip | |
Merge pull request #25227 from mlugg/capture-stack
The Great `std.debug` Refactor
Diffstat (limited to 'lib/std/Build')
| -rw-r--r-- | lib/std/Build/Step.zig | 38 | ||||
| -rw-r--r-- | lib/std/Build/Step/CheckObject.zig | 38 |
2 files changed, 21 insertions, 55 deletions
diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index 3002db628f..8e9e12248a 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -60,7 +60,7 @@ test_results: TestResults, /// The return address associated with creation of this step that can be useful /// to print along with debugging messages. -debug_stack_trace: []usize, +debug_stack_trace: std.builtin.StackTrace, pub const TestResults = struct { fail_count: u32 = 0, @@ -220,16 +220,9 @@ pub fn init(options: StepOptions) Step { .state = .precheck_unstarted, .max_rss = options.max_rss, .debug_stack_trace = blk: { - if (!std.debug.sys_can_stack_trace) break :blk &.{}; - const addresses = arena.alloc(usize, options.owner.debug_stack_frames_count) catch @panic("OOM"); - @memset(addresses, 0); + const addr_buf = arena.alloc(usize, options.owner.debug_stack_frames_count) catch @panic("OOM"); const first_ret_addr = options.first_ret_addr orelse @returnAddress(); - var stack_trace = std.builtin.StackTrace{ - .instruction_addresses = addresses, - .index = 0, - }; - std.debug.captureStackTrace(first_ret_addr, &stack_trace); - break :blk addresses; + break :blk std.debug.captureCurrentStackTrace(.{ .first_address = first_ret_addr }, addr_buf); }, .result_error_msgs = .{}, .result_error_bundle = std.zig.ErrorBundle.empty, @@ -282,18 +275,6 @@ pub fn dependOn(step: *Step, other: *Step) void { step.dependencies.append(other) catch @panic("OOM"); } -pub fn getStackTrace(s: *Step) ?std.builtin.StackTrace { - var len: usize = 0; - while (len < s.debug_stack_trace.len and s.debug_stack_trace[len] != 0) { - len += 1; - } - - return if (len == 0) null else .{ - .instruction_addresses = s.debug_stack_trace, - .index = len, - }; -} - fn makeNoOp(step: *Step, options: MakeOptions) anyerror!void { _ = options; @@ -315,18 +296,9 @@ pub fn cast(step: *Step, comptime T: type) ?*T { /// For debugging purposes, prints identifying information about this Step. pub fn dump(step: *Step, w: *std.Io.Writer, tty_config: std.Io.tty.Config) void { - const debug_info = std.debug.getSelfDebugInfo() catch |err| { - w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{ - @errorName(err), - }) catch {}; - return; - }; - if (step.getStackTrace()) |stack_trace| { + if (step.debug_stack_trace.instruction_addresses.len > 0) { w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {}; - std.debug.writeStackTrace(stack_trace, w, debug_info, tty_config) catch |err| { - w.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {}; - return; - }; + std.debug.writeStackTrace(&step.debug_stack_trace, w, tty_config) catch {}; } else { const field = "debug_stack_frames_count"; comptime assert(@hasField(Build, field)); diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index 2b5994cc34..56be318a84 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -1097,16 +1097,10 @@ const MachODumper = struct { for (ctx.symtab.items) |sym| { const sym_name = ctx.getString(sym.n_strx); - if (sym.stab()) { - const tt = switch (sym.n_type) { - macho.N_SO => "SO", - macho.N_OSO => "OSO", - macho.N_BNSYM => "BNSYM", - macho.N_ENSYM => "ENSYM", - macho.N_FUN => "FUN", - macho.N_GSYM => "GSYM", - macho.N_STSYM => "STSYM", - else => "UNKNOWN STAB", + if (sym.n_type.bits.is_stab != 0) { + const tt = switch (sym.n_type.stab) { + _ => "UNKNOWN STAB", + else => @tagName(sym.n_type.stab), }; try writer.print("{x}", .{sym.n_value}); if (sym.n_sect > 0) { @@ -1114,27 +1108,27 @@ const MachODumper = struct { try writer.print(" ({s},{s})", .{ sect.segName(), sect.sectName() }); } try writer.print(" {s} (stab) {s}\n", .{ tt, sym_name }); - } else if (sym.sect()) { + } else if (sym.n_type.bits.type == .sect) { const sect = ctx.sections.items[sym.n_sect - 1]; try writer.print("{x} ({s},{s})", .{ sym.n_value, sect.segName(), sect.sectName(), }); - if (sym.n_desc & macho.REFERENCED_DYNAMICALLY != 0) try writer.writeAll(" [referenced dynamically]"); - if (sym.weakDef()) try writer.writeAll(" weak"); - if (sym.weakRef()) try writer.writeAll(" weakref"); - if (sym.ext()) { - if (sym.pext()) try writer.writeAll(" private"); + if (sym.n_desc.referenced_dynamically) try writer.writeAll(" [referenced dynamically]"); + if (sym.n_desc.weak_def_or_ref_to_weak) try writer.writeAll(" weak"); + if (sym.n_desc.weak_ref) try writer.writeAll(" weakref"); + if (sym.n_type.bits.ext) { + if (sym.n_type.bits.pext) try writer.writeAll(" private"); try writer.writeAll(" external"); - } else if (sym.pext()) try writer.writeAll(" (was private external)"); + } else if (sym.n_type.bits.pext) try writer.writeAll(" (was private external)"); try writer.print(" {s}\n", .{sym_name}); } else if (sym.tentative()) { - const alignment = (sym.n_desc >> 8) & 0x0F; + const alignment = (@as(u16, @bitCast(sym.n_desc)) >> 8) & 0x0F; try writer.print(" 0x{x:0>16} (common) (alignment 2^{d})", .{ sym.n_value, alignment }); - if (sym.ext()) try writer.writeAll(" external"); + if (sym.n_type.bits.ext) try writer.writeAll(" external"); try writer.print(" {s}\n", .{sym_name}); - } else if (sym.undf()) { + } else if (sym.n_type.bits.type == .undf) { const ordinal = @divFloor(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER); const import_name = blk: { if (ordinal <= 0) { @@ -1153,8 +1147,8 @@ const MachODumper = struct { break :blk basename[0..ext]; }; try writer.writeAll("(undefined)"); - if (sym.weakRef()) try writer.writeAll(" weakref"); - if (sym.ext()) try writer.writeAll(" external"); + if (sym.n_desc.weak_ref) try writer.writeAll(" weakref"); + if (sym.n_type.bits.ext) try writer.writeAll(" external"); try writer.print(" {s} (from {s})\n", .{ sym_name, import_name, |
