mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std: fixes
This commit is contained in:
parent
f1215adeda
commit
202aeacc05
6 changed files with 19 additions and 37 deletions
|
|
@ -275,18 +275,6 @@ pub fn dependOn(step: *Step, other: *Step) void {
|
||||||
step.dependencies.append(other) catch @panic("OOM");
|
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 {
|
fn makeNoOp(step: *Step, options: MakeOptions) anyerror!void {
|
||||||
_ = options;
|
_ = options;
|
||||||
|
|
||||||
|
|
@ -308,9 +296,9 @@ pub fn cast(step: *Step, comptime T: type) ?*T {
|
||||||
|
|
||||||
/// For debugging purposes, prints identifying information about this Step.
|
/// 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 {
|
pub fn dump(step: *Step, w: *std.Io.Writer, tty_config: std.Io.tty.Config) void {
|
||||||
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 {};
|
w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};
|
||||||
std.debug.writeStackTrace(stack_trace, w, tty_config) catch {};
|
std.debug.writeStackTrace(&step.debug_stack_trace, w, tty_config) catch {};
|
||||||
} else {
|
} else {
|
||||||
const field = "debug_stack_frames_count";
|
const field = "debug_stack_frames_count";
|
||||||
comptime assert(@hasField(Build, field));
|
comptime assert(@hasField(Build, field));
|
||||||
|
|
|
||||||
|
|
@ -1098,15 +1098,9 @@ const MachODumper = struct {
|
||||||
for (ctx.symtab.items) |sym| {
|
for (ctx.symtab.items) |sym| {
|
||||||
const sym_name = ctx.getString(sym.n_strx);
|
const sym_name = ctx.getString(sym.n_strx);
|
||||||
if (sym.n_type.bits.is_stab != 0) {
|
if (sym.n_type.bits.is_stab != 0) {
|
||||||
const tt = switch (sym.n_type) {
|
const tt = switch (sym.n_type.stab) {
|
||||||
macho.N_SO => "SO",
|
_ => "UNKNOWN STAB",
|
||||||
macho.N_OSO => "OSO",
|
else => @tagName(sym.n_type.stab),
|
||||||
macho.N_BNSYM => "BNSYM",
|
|
||||||
macho.N_ENSYM => "ENSYM",
|
|
||||||
macho.N_FUN => "FUN",
|
|
||||||
macho.N_GSYM => "GSYM",
|
|
||||||
macho.N_STSYM => "STSYM",
|
|
||||||
else => "UNKNOWN STAB",
|
|
||||||
};
|
};
|
||||||
try writer.print("{x}", .{sym.n_value});
|
try writer.print("{x}", .{sym.n_value});
|
||||||
if (sym.n_sect > 0) {
|
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},{s})", .{ sect.segName(), sect.sectName() });
|
||||||
}
|
}
|
||||||
try writer.print(" {s} (stab) {s}\n", .{ tt, sym_name });
|
try writer.print(" {s} (stab) {s}\n", .{ tt, sym_name });
|
||||||
} else if (sym.n_type.type == .sect) {
|
} else if (sym.n_type.bits.type == .sect) {
|
||||||
const sect = ctx.sections.items[sym.n_sect - 1];
|
const sect = ctx.sections.items[sym.n_sect - 1];
|
||||||
try writer.print("{x} ({s},{s})", .{
|
try writer.print("{x} ({s},{s})", .{
|
||||||
sym.n_value,
|
sym.n_value,
|
||||||
sect.segName(),
|
sect.segName(),
|
||||||
sect.sectName(),
|
sect.sectName(),
|
||||||
});
|
});
|
||||||
if (sym.n_desc & macho.REFERENCED_DYNAMICALLY != 0) try writer.writeAll(" [referenced dynamically]");
|
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_def_or_ref_to_weak) try writer.writeAll(" weak");
|
||||||
if (sym.n_desc.weak_ref) try writer.writeAll(" weakref");
|
if (sym.n_desc.weak_ref) try writer.writeAll(" weakref");
|
||||||
if (sym.ext()) {
|
if (sym.n_type.bits.ext) {
|
||||||
if (sym.pext()) try writer.writeAll(" private");
|
if (sym.n_type.bits.pext) try writer.writeAll(" private");
|
||||||
try writer.writeAll(" external");
|
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});
|
try writer.print(" {s}\n", .{sym_name});
|
||||||
} else if (sym.tentative()) {
|
} 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 });
|
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});
|
try writer.print(" {s}\n", .{sym_name});
|
||||||
} else if (sym.n_type.type == .undf) {
|
} else if (sym.n_type.bits.type == .undf) {
|
||||||
const ordinal = @divFloor(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER);
|
const ordinal = @divFloor(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER);
|
||||||
const import_name = blk: {
|
const import_name = blk: {
|
||||||
if (ordinal <= 0) {
|
if (ordinal <= 0) {
|
||||||
|
|
@ -1154,7 +1148,7 @@ const MachODumper = struct {
|
||||||
};
|
};
|
||||||
try writer.writeAll("(undefined)");
|
try writer.writeAll("(undefined)");
|
||||||
if (sym.n_desc.weak_ref) try writer.writeAll(" weakref");
|
if (sym.n_desc.weak_ref) try writer.writeAll(" weakref");
|
||||||
if (sym.ext()) try writer.writeAll(" external");
|
if (sym.n_type.bits.ext) try writer.writeAll(" external");
|
||||||
try writer.print(" {s} (from {s})\n", .{
|
try writer.print(" {s} (from {s})\n", .{
|
||||||
sym_name,
|
sym_name,
|
||||||
import_name,
|
import_name,
|
||||||
|
|
|
||||||
|
|
@ -530,7 +530,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
|
||||||
@call(.auto, f, args) catch |err| {
|
@call(.auto, f, args) catch |err| {
|
||||||
std.debug.print("error: {s}\n", .{@errorName(err)});
|
std.debug.print("error: {s}\n", .{@errorName(err)});
|
||||||
if (@errorReturnTrace()) |trace| {
|
if (@errorReturnTrace()) |trace| {
|
||||||
std.debug.dumpStackTrace(trace.*);
|
std.debug.dumpStackTrace(trace);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1443,7 +1443,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
|
||||||
.index = frames.len,
|
.index = frames.len,
|
||||||
.instruction_addresses = frames,
|
.instruction_addresses = frames,
|
||||||
};
|
};
|
||||||
writeStackTrace(stack_trace, stderr, tty_config) catch return;
|
writeStackTrace(&stack_trace, stderr, tty_config) catch return;
|
||||||
}
|
}
|
||||||
if (t.index > end) {
|
if (t.index > end) {
|
||||||
stderr.print("{d} more traces not shown; consider increasing trace size\n", .{
|
stderr.print("{d} more traces not shown; consider increasing trace size\n", .{
|
||||||
|
|
|
||||||
|
|
@ -892,7 +892,7 @@ pub const nlist_64 = extern struct {
|
||||||
n_desc: packed struct(u16) {
|
n_desc: packed struct(u16) {
|
||||||
_pad0: u3 = 0,
|
_pad0: u3 = 0,
|
||||||
arm_thumb_def: bool,
|
arm_thumb_def: bool,
|
||||||
_pad1: u1 = 0,
|
referenced_dynamically: bool,
|
||||||
/// The meaning of this bit is contextual.
|
/// The meaning of this bit is contextual.
|
||||||
/// See `N_DESC_DISCARDED` and `N_NO_DEAD_STRIP`.
|
/// See `N_DESC_DISCARDED` and `N_NO_DEAD_STRIP`.
|
||||||
discarded_or_no_dead_strip: bool,
|
discarded_or_no_dead_strip: bool,
|
||||||
|
|
@ -907,7 +907,7 @@ pub const nlist_64 = extern struct {
|
||||||
n_value: u64,
|
n_value: u64,
|
||||||
|
|
||||||
pub fn tentative(sym: nlist_64) bool {
|
pub fn tentative(sym: nlist_64) bool {
|
||||||
return sym.n_type.type == .undf and sym.n_value != 0;
|
return sym.n_type.bits.type == .undf and sym.n_value != 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -636,7 +636,7 @@ pub inline fn callMain() u8 {
|
||||||
}
|
}
|
||||||
std.log.err("{s}", .{@errorName(err)});
|
std.log.err("{s}", .{@errorName(err)});
|
||||||
if (@errorReturnTrace()) |trace| {
|
if (@errorReturnTrace()) |trace| {
|
||||||
std.debug.dumpStackTrace(trace.*);
|
std.debug.dumpStackTrace(trace);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue