From: Brendan Hansen Date: Sat, 10 Jun 2023 02:19:57 +0000 (-0500) Subject: added: stack trace logging to logging allocator X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=42c263f012a58fdf84f9e566775408c21d0ea611;p=onyx.git added: stack trace logging to logging allocator --- diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index 2b62d417..f952a7fb 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -5,6 +5,7 @@ package core.alloc.log // allocator. use core +use runtime #local Allocation_Action_Strings := str.[ @@ -24,6 +25,12 @@ logging_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: log(.Info, "Core", msg); + trace := runtime.info.get_stack_trace(); + defer if trace do delete(&trace); + for trace { + log(.Info, "Core", tprintf("in {} ({}:{})", it.func_name, it.file, it.line)); + } + return res; } diff --git a/core/runtime/info/stack_trace.onyx b/core/runtime/info/stack_trace.onyx index 95c929df..fa6032b8 100644 --- a/core/runtime/info/stack_trace.onyx +++ b/core/runtime/info/stack_trace.onyx @@ -1,5 +1,16 @@ package runtime.info + use runtime +use core {alloc} // These can included because this file is only included in non-custom runtimes. + +// +// This file contains the code for working with runtime stack traces. +// The only function in this file is `get_stack_trace`, which returns +// an array of stack nodes, allocated from the threads temporary allocator. +// This is not the `context.temp_allocator`, because certain builtin in +// allocators use `get_stack_trace`, and can accidentally cause infinite +// recursion. +// Stack_Node :: struct { file: str; @@ -15,8 +26,8 @@ Stack_Trace :: struct { #if runtime.Stack_Trace_Enabled { -get_stack_trace :: () -> [] &Stack_Node { - trace: [..] &Stack_Node; +get_stack_trace :: () -> [..] &Stack_Node { + trace := make([..] &Stack_Node, 8, alloc.temp_allocator); walker := __stack_trace.prev; while walker {