From: Brendan Hansen Date: Wed, 14 Jun 2023 16:48:30 +0000 (-0500) Subject: added: current_line to Stack_Frame X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=247c7006f63be73481e5648a1d705311e0a78a25;p=onyx.git added: current_line to Stack_Frame --- diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index 028e76fc..ea9f9459 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -2191,6 +2191,10 @@ EMIT_FUNC(call, AstCall* call) { if (cc == CC_Return_Stack) reserve_size += return_size; if (context.options->stack_trace_enabled) { + emit_stack_address(mod, &code, mod->stack_trace_idx, NULL); + WIL(NULL, WI_I32_CONST, call->token->pos.line); + emit_store_instruction(mod, &code, &basic_types[Basic_Kind_U32], 8); + u64 stack_trace_pass_global = bh_imap_get(&mod->index_map, (u64) &builtin_stack_trace); emit_stack_address(mod, &code, mod->stack_trace_idx, NULL); WIL(NULL, WI_GLOBAL_SET, stack_trace_pass_global); diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index c9508f29..bc2c887e 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -201,7 +201,7 @@ get_freed_size :: () => { #if Enable_Stack_Trace { trace := runtime.info.get_stack_trace(); for trace { - log(.Error, "Core", core.tprintf("in {} ({}:{})", it.func_name, it.file, it.line)); + log(.Error, "Core", core.tprintf("in {} ({}:{})", it.info.func_name, it.info.file, it.current.line)); } } } diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index f952a7fb..786b43b2 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -28,7 +28,7 @@ logging_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: 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)); + log(.Info, "Core", tprintf("in {} ({}:{})", it.info.func_name, it.info.file, it.current_line)); } return res; diff --git a/core/runtime/common.onyx b/core/runtime/common.onyx index 0f36e8b6..498fdb9a 100644 --- a/core/runtime/common.onyx +++ b/core/runtime/common.onyx @@ -9,6 +9,18 @@ use runtime.platform { __output_string } // Every platform should define this, even if is it just '() {}'. #export "_start" platform.__start +#local +__output_uint :: (n: u64) { + buf: [128] u8; + i := 127; + while n > 0 && i >= 0 { + buf[i] = ~~('0' + n % 10); + i -= 1; + n /= 10; + } + + __output_string(buf[i .. 128]); +} // The default assert handler. This assumes that __output_string // and __exit are defined in the 'runtime' package. @@ -22,9 +34,11 @@ __assert_handler :: (msg: str, site: CallSite) { trace := info.get_stack_trace(); for trace[1..trace.length] { __output_string(" in "); - __output_string(it.func_name); + __output_string(it.info.func_name); __output_string(" ("); - __output_string(it.file); + __output_string(it.info.file); + __output_string(":"); + __output_uint(~~it.current_line); __output_string(")\n"); } @@ -104,4 +118,4 @@ __thread_initialize :: () { raw_free(alloc.heap_allocator, __tls_base); core.thread.__exited(id); } -} \ No newline at end of file +} diff --git a/core/runtime/info/stack_trace.onyx b/core/runtime/info/stack_trace.onyx index fa6032b8..8b2e0041 100644 --- a/core/runtime/info/stack_trace.onyx +++ b/core/runtime/info/stack_trace.onyx @@ -22,16 +22,22 @@ Stack_Node :: struct { Stack_Trace :: struct { prev: &Stack_Trace; data: &Stack_Node; + current_line: u32; +} + +Stack_Frame :: struct { + info: &Stack_Node; + current_line: u32; } #if runtime.Stack_Trace_Enabled { -get_stack_trace :: () -> [..] &Stack_Node { - trace := make([..] &Stack_Node, 8, alloc.temp_allocator); +get_stack_trace :: () -> [..] Stack_Frame { + trace := make([..] Stack_Frame, 8, alloc.temp_allocator); walker := __stack_trace.prev; while walker { - trace << walker.data; + trace << .{ walker.data, walker.current_line }; walker = walker.prev; } @@ -40,7 +46,7 @@ get_stack_trace :: () -> [..] &Stack_Node { } else { -get_stack_trace :: () -> [] &Stack_Node { +get_stack_trace :: () -> [] Stack_Frame { return .[]; }