doc.odin 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. A debug stack trace library. Only works when debug symbols are enabled `-debug`.
  3. Example:
  4. import "base:runtime"
  5. import "core:debug/trace"
  6. import "core:fmt"
  7. global_trace_ctx: trace.Context
  8. debug_trace_assertion_failure_proc :: proc(prefix, message: string, loc := #caller_location) -> ! {
  9. runtime.print_caller_location(loc)
  10. runtime.print_string(" ")
  11. runtime.print_string(prefix)
  12. if len(message) > 0 {
  13. runtime.print_string(": ")
  14. runtime.print_string(message)
  15. }
  16. runtime.print_byte('\n')
  17. ctx := &trace_ctx
  18. if !trace.in_resolve(ctx) {
  19. buf: [64]trace.Frame
  20. runtime.print_string("Debug Trace:\n")
  21. frames := trace.frames(ctx, 1, buf[:])
  22. for f, i in frames {
  23. fl := trace.resolve(ctx, f, context.temp_allocator)
  24. if fl.loc.file_path == "" && fl.loc.line == 0 {
  25. continue
  26. }
  27. runtime.print_caller_location(fl.loc)
  28. runtime.print_string(" - frame ")
  29. runtime.print_int(i)
  30. runtime.print_byte('\n')
  31. }
  32. }
  33. runtime.trap()
  34. }
  35. main :: proc() {
  36. trace.init(&global_trace_ctx)
  37. defer trace.destroy(&global_trace_ctx)
  38. context.assertion_failure_proc = debug_trace_assertion_failure_proc
  39. ...
  40. }
  41. */
  42. package debug_trace