authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-31 20:57:27-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-31 20:57:27-07:00
log96daca7b3b6f02033e68ac91776bf6e8d2b67409
tree785d872334a63422cad75dffaa7efa8e59090b7e
parent69e304bd510e3fed2d51582edc6f11127824d7e6
parent4adb10df4722a020e4db5140c0fd30962a526813
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21173 from mrjbq7/writeStackTrace

std.debug: remove allocator from std.debug.writeStackTrace()

3 files changed, 4 insertions(+), 9 deletions(-)

lib/std/Build/Step.zig+1-2
......@@ -295,10 +295,9 @@ pub fn dump(step: *Step, file: std.fs.File) void {
295295 }) catch {};
296296 return;
297297 };
298 const ally = debug_info.allocator;
299298 if (step.getStackTrace()) |stack_trace| {
300299 w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};
301 std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {
300 std.debug.writeStackTrace(stack_trace, w, debug_info, tty_config) catch |err| {
302301 w.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};
303302 return;
304303 };
lib/std/builtin.zig+1-3
......@@ -48,14 +48,12 @@ pub const StackTrace = struct {
4848 if (builtin.os.tag == .freestanding) return;
4949
5050 _ = options;
51 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
52 defer arena.deinit();
5351 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
5452 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
5553 };
5654 const tty_config = std.io.tty.detectConfig(std.io.getStdErr());
5755 try writer.writeAll("\n");
58 std.debug.writeStackTrace(self, writer, arena.allocator(), debug_info, tty_config) catch |err| {
56 std.debug.writeStackTrace(self, writer, debug_info, tty_config) catch |err| {
5957 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});
6058 };
6159 }
lib/std/debug.zig+2-4
......@@ -377,7 +377,7 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
377377 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
378378 return;
379379 };
380 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, io.tty.detectConfig(io.getStdErr())) catch |err| {
380 writeStackTrace(stack_trace, stderr, debug_info, io.tty.detectConfig(io.getStdErr())) catch |err| {
381381 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
382382 return;
383383 };
......@@ -520,11 +520,9 @@ fn waitForOtherThreadToFinishPanicking() void {
520520pub fn writeStackTrace(
521521 stack_trace: std.builtin.StackTrace,
522522 out_stream: anytype,
523 allocator: mem.Allocator,
524523 debug_info: *SelfInfo,
525524 tty_config: io.tty.Config,
526525) !void {
527 _ = allocator;
528526 if (builtin.strip_debug_info) return error.MissingDebugInfo;
529527 var frame_index: usize = 0;
530528 var frames_left: usize = @min(stack_trace.index, stack_trace.instruction_addresses.len);
......@@ -1452,7 +1450,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
14521450 .index = frames.len,
14531451 .instruction_addresses = frames,
14541452 };
1455 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, tty_config) catch continue;
1453 writeStackTrace(stack_trace, stderr, debug_info, tty_config) catch continue;
14561454 }
14571455 if (t.index > end) {
14581456 stderr.print("{d} more traces not shown; consider increasing trace size\n", .{