mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Remove need for allocator and MAX_FRAMES in trace.frames
This commit is contained in:
@@ -4,7 +4,6 @@ import "base:intrinsics"
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
Frame :: distinct uintptr
|
Frame :: distinct uintptr
|
||||||
MAX_FRAMES :: 512
|
|
||||||
|
|
||||||
Frame_Location :: struct {
|
Frame_Location :: struct {
|
||||||
using loc: runtime.Source_Code_Location,
|
using loc: runtime.Source_Code_Location,
|
||||||
@@ -32,8 +31,8 @@ destroy :: proc(ctx: ^Context) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> []Frame {
|
frames :: proc(ctx: ^Context, skip: uint, frames_buffer: []Frame) -> []Frame {
|
||||||
return _frames(ctx, skip, allocator)
|
return _frames(ctx, skip, frames_buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
//+build linux
|
//+build linux
|
||||||
package debug_trace
|
package debug_trace
|
||||||
|
|
||||||
|
import "base:intrinsics"
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
@@ -92,17 +93,16 @@ _destroy :: proc(ctx: ^Context) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(private="package")
|
@(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 {
|
Backtrace_Context :: struct {
|
||||||
ctx: ^Context,
|
ctx: ^Context,
|
||||||
rt_ctx: runtime.Context,
|
frames: []Frame,
|
||||||
frames: [MAX_FRAMES]Frame,
|
|
||||||
frame_count: int,
|
frame_count: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
btc := &Backtrace_Context{
|
btc := &Backtrace_Context{
|
||||||
ctx = ctx,
|
ctx = ctx,
|
||||||
rt_ctx = context,
|
frames = frames_buffer,
|
||||||
}
|
}
|
||||||
backtrace_simple(
|
backtrace_simple(
|
||||||
ctx.impl.state,
|
ctx.impl.state,
|
||||||
@@ -113,6 +113,9 @@ _frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> (fra
|
|||||||
if address == 0 {
|
if address == 0 {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
if btc.frame_count == len(btc.frames) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
btc.frames[btc.frame_count] = address
|
btc.frames[btc.frame_count] = address
|
||||||
btc.frame_count += 1
|
btc.frame_count += 1
|
||||||
return 0
|
return 0
|
||||||
@@ -121,10 +124,8 @@ _frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> (fra
|
|||||||
btc,
|
btc,
|
||||||
)
|
)
|
||||||
|
|
||||||
res := btc.frames[:btc.frame_count]
|
if btc.frame_count > 0 {
|
||||||
if len(res) > 0 {
|
frames = btc.frames[:btc.frame_count]
|
||||||
frames = make([]Frame, btc.frame_count, allocator)
|
|
||||||
copy(frames, res)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,16 +28,14 @@ _destroy :: proc "contextless" (ctx: ^Context) -> bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_frames :: proc(ctx: ^Context, skip: uint, allocator: runtime.Allocator) -> []Frame {
|
_frames :: proc "contextless" (ctx: ^Context, skip: uint, frames_buffer: []Frame) -> []Frame {
|
||||||
buffer: [MAX_FRAMES]rawptr
|
frame_count := win32.RtlCaptureStackBackTrace(u32(skip) + 2, len(frames_buffer), &frames_buffer[0], nil)
|
||||||
frame_count := win32.RtlCaptureStackBackTrace(u32(skip) + 2, len(buffer), &buffer[0], nil)
|
for i in 0..<frame_count {
|
||||||
frames := make([]Frame, frame_count, allocator)
|
|
||||||
for &f, i in frames {
|
|
||||||
// NOTE: Return address is one after the call instruction so subtract a byte to
|
// 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.
|
// 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]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user