From 2ec39484dcb51662a4c2da257bb674ddb45c6710 Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 4 Jun 2023 02:00:31 +0000 Subject: [PATCH] Add more detail to memory leak traces --- source/ona/heap.zig | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/source/ona/heap.zig b/source/ona/heap.zig index 2c6cecf..755b0b0 100644 --- a/source/ona/heap.zig +++ b/source/ona/heap.zig @@ -9,22 +9,22 @@ const std = @import("std"); /// const stack_trace_frame_size = if (std.debug.sys_can_stack_trace) 16 else 0; +/// +/// +/// +const AllocationInfo = struct { + stack_frames: [stack_trace_frame_size]usize, + stack_trace: std.builtin.StackTrace, + next_info: ?*AllocationInfo, + size: usize, +}; + /// /// /// const Context = struct { allocation_info_head: ?*AllocationInfo = null, - /// - /// - /// - const AllocationInfo = struct { - stack_frames: [stack_trace_frame_size]usize, - stack_trace: std.builtin.StackTrace, - next_info: ?*AllocationInfo, - size: usize, - }; - /// /// /// @@ -167,7 +167,10 @@ pub fn trace_allocations() void { var current_allocation_info = context.allocation_info_head; while (current_allocation_info) |allocation_info| : (current_allocation_info = allocation_info.next_info) { - std.debug.print("{d} byte leak detected", .{allocation_info.size}); - std.debug.dumpStackTrace(allocation_info.stack_trace); + std.debug.print("{d} byte leak at 0x{x} detected: {}", .{ + allocation_info.size, + @ptrToInt(allocation_info) + @sizeOf(AllocationInfo), + allocation_info.stack_trace + }); } }