trace.odin 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package debug_trace
  2. import "base:intrinsics"
  3. import "base:runtime"
  4. Frame :: distinct uintptr
  5. Frame_Location :: struct {
  6. using loc: runtime.Source_Code_Location,
  7. allocator: runtime.Allocator,
  8. }
  9. delete_frame_location :: proc(fl: Frame_Location) -> runtime.Allocator_Error {
  10. allocator := fl.allocator
  11. delete(fl.loc.procedure, allocator) or_return
  12. delete(fl.loc.file_path, allocator) or_return
  13. return nil
  14. }
  15. Context :: struct {
  16. in_resolve: bool, // atomic
  17. impl: _Context,
  18. }
  19. init :: proc(ctx: ^Context) -> bool {
  20. return _init(ctx)
  21. }
  22. destroy :: proc(ctx: ^Context) -> bool {
  23. return _destroy(ctx)
  24. }
  25. @(require_results)
  26. frames :: proc(ctx: ^Context, skip: uint, frames_buffer: []Frame) -> []Frame {
  27. return _frames(ctx, skip, frames_buffer)
  28. }
  29. @(require_results)
  30. resolve :: proc(ctx: ^Context, frame: Frame, allocator: runtime.Allocator) -> (result: Frame_Location) {
  31. return _resolve(ctx, frame, allocator)
  32. }
  33. @(require_results)
  34. in_resolve :: proc "contextless" (ctx: ^Context) -> bool {
  35. return intrinsics.atomic_load(&ctx.in_resolve)
  36. }