diff options
| author | gingerBill <bill@gingerbill.org> | 2024-04-28 13:05:19 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-04-28 13:05:19 +0100 |
| commit | c0b7dd7da60c4b7557e494049937af630bc25c33 (patch) | |
| tree | 7f31c532860de9dc1c07364f55531f074682dffa /core/debug | |
| parent | be09584ea5a61ac83c8ddc96eba1c7bccbe51472 (diff) | |
Remove need for allocator and MAX_FRAMES in `trace.frames`
Diffstat (limited to 'core/debug')
| -rw-r--r-- | core/debug/trace/trace.odin | 5 | ||||
| -rw-r--r-- | core/debug/trace/trace_linux.odin | 17 | ||||
| -rw-r--r-- | core/debug/trace/trace_windows.odin | 12 |
3 files changed, 16 insertions, 18 deletions
diff --git a/core/debug/trace/trace.odin b/core/debug/trace/trace.odin index 243232ddc..134609b05 100644 --- a/core/debug/trace/trace.odin +++ b/core/debug/trace/trace.odin @@ -4,7 +4,6 @@ import "base:intrinsics" import "base:runtime" Frame :: distinct uintptr -MAX_FRAMES :: 512 Frame_Location :: struct { using loc: runtime.Source_Code_Location, @@ -32,8 +31,8 @@ destroy :: proc(ctx: ^Context) -> bool { } @(require_results) -frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> []Frame { - return _frames(ctx, skip, allocator) +frames :: proc(ctx: ^Context, skip: uint, frames_buffer: []Frame) -> []Frame { + return _frames(ctx, skip, frames_buffer) } @(require_results) diff --git a/core/debug/trace/trace_linux.odin b/core/debug/trace/trace_linux.odin index c65a165f9..211c379ca 100644 --- a/core/debug/trace/trace_linux.odin +++ b/core/debug/trace/trace_linux.odin @@ -2,6 +2,7 @@ //+build linux package debug_trace +import "base:intrinsics" import "base:runtime" import "core:strings" import "core:fmt" @@ -92,17 +93,16 @@ _destroy :: proc(ctx: ^Context) -> bool { } @(private="package") -_frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> (frames: []Frame) { +_frames :: proc "contextless" (ctx: ^Context, skip: uint, frames_buffer: []Frame) -> (frames: []Frame) { Backtrace_Context :: struct { ctx: ^Context, - rt_ctx: runtime.Context, - frames: [MAX_FRAMES]Frame, + frames: []Frame, frame_count: int, } btc := &Backtrace_Context{ ctx = ctx, - rt_ctx = context, + frames = frames_buffer, } backtrace_simple( ctx.impl.state, @@ -113,6 +113,9 @@ _frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> (fra if address == 0 { return 1 } + if btc.frame_count == len(btc.frames) { + return 1 + } btc.frames[btc.frame_count] = address btc.frame_count += 1 return 0 @@ -121,10 +124,8 @@ _frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> (fra btc, ) - res := btc.frames[:btc.frame_count] - if len(res) > 0 { - frames = make([]Frame, btc.frame_count, allocator) - copy(frames, res) + if btc.frame_count > 0 { + frames = btc.frames[:btc.frame_count] } return } diff --git a/core/debug/trace/trace_windows.odin b/core/debug/trace/trace_windows.odin index c7b4eeaa1..5535c09f5 100644 --- a/core/debug/trace/trace_windows.odin +++ b/core/debug/trace/trace_windows.odin @@ -28,16 +28,14 @@ _destroy :: proc "contextless" (ctx: ^Context) -> bool { return true } -_frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> []Frame { - buffer: [MAX_FRAMES]rawptr - frame_count := win32.RtlCaptureStackBackTrace(u32(skip) + 2, len(buffer), &buffer[0], nil) - frames := make([]Frame, frame_count, allocator) - for &f, i in frames { +_frames :: proc "contextless" (ctx: ^Context, skip: uint, frames_buffer: []Frame) -> []Frame { + frame_count := win32.RtlCaptureStackBackTrace(u32(skip) + 2, len(frames_buffer), &frames_buffer[0], nil) + for i in 0..<frame_count { // NOTE: Return address is one after the call instruction so subtract a byte to // end up back inside the call instruction which is needed for SymFromAddr. - f = Frame(buffer[i]) - 1 + frames_buffer[i] -= 1 } - return frames + return frames_buffer[:frame_count] } |