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 {...@@ -295,10 +295,9 @@ pub fn dump(step: *Step, file: std.fs.File) void {
295 }) catch {};295 }) catch {};
296 return;296 return;
297 };297 };
298 const ally = debug_info.allocator;
299 if (step.getStackTrace()) |stack_trace| {298 if (step.getStackTrace()) |stack_trace| {
300 w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};299 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| {
302 w.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};301 w.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};
303 return;302 return;
304 };303 };
lib/std/builtin.zig+1-3
...@@ -48,14 +48,12 @@ pub const StackTrace = struct {...@@ -48,14 +48,12 @@ pub const StackTrace = struct {
48 if (builtin.os.tag == .freestanding) return;48 if (builtin.os.tag == .freestanding) return;
4949
50 _ = options;50 _ = options;
51 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
52 defer arena.deinit();
53 const debug_info = std.debug.getSelfDebugInfo() catch |err| {51 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
54 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});52 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
55 };53 };
56 const tty_config = std.io.tty.detectConfig(std.io.getStdErr());54 const tty_config = std.io.tty.detectConfig(std.io.getStdErr());
57 try writer.writeAll("\n");55 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| {
59 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});57 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});
60 };58 };
61 }59 }
lib/std/debug.zig+2-4
...@@ -377,7 +377,7 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {...@@ -377,7 +377,7 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
377 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;377 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
378 return;378 return;
379 };379 };
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| {
381 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;381 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
382 return;382 return;
383 };383 };
...@@ -520,11 +520,9 @@ fn waitForOtherThreadToFinishPanicking() void {...@@ -520,11 +520,9 @@ fn waitForOtherThreadToFinishPanicking() void {
520pub fn writeStackTrace(520pub fn writeStackTrace(
521 stack_trace: std.builtin.StackTrace,521 stack_trace: std.builtin.StackTrace,
522 out_stream: anytype,522 out_stream: anytype,
523 allocator: mem.Allocator,
524 debug_info: *SelfInfo,523 debug_info: *SelfInfo,
525 tty_config: io.tty.Config,524 tty_config: io.tty.Config,
526) !void {525) !void {
527 _ = allocator;
528 if (builtin.strip_debug_info) return error.MissingDebugInfo;526 if (builtin.strip_debug_info) return error.MissingDebugInfo;
529 var frame_index: usize = 0;527 var frame_index: usize = 0;
530 var frames_left: usize = @min(stack_trace.index, stack_trace.instruction_addresses.len);528 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...@@ -1452,7 +1450,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
1452 .index = frames.len,1450 .index = frames.len,
1453 .instruction_addresses = frames,1451 .instruction_addresses = frames,
1454 };1452 };
1455 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, tty_config) catch continue;1453 writeStackTrace(stack_trace, stderr, debug_info, tty_config) catch continue;
1456 }1454 }
1457 if (t.index > end) {1455 if (t.index > end) {
1458 stderr.print("{d} more traces not shown; consider increasing trace size\n", .{1456 stderr.print("{d} more traces not shown; consider increasing trace size\n", .{