diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2026-02-10 20:19:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-10 20:19:26 +0100 |
| commit | 855bc31350a9a6aa23193c0b4e13f17e6e6f68ea (patch) | |
| tree | 549a3e3a3b8527e070363548aaf4c8f439274ac1 /core/debug/trace | |
| parent | 132e4e470f9662f308bba86e09199ec4bc400d60 (diff) | |
| parent | 83489c07f1123e1994e40a08a32206d8d78414a9 (diff) | |
Merge pull request #6254 from jakubtomsu/more-import-cleanup
More import cleanup
Diffstat (limited to 'core/debug/trace')
| -rw-r--r-- | core/debug/trace/trace.odin | 32 | ||||
| -rw-r--r-- | core/debug/trace/trace_cpp.odin | 3 | ||||
| -rw-r--r-- | core/debug/trace/trace_windows.odin | 3 |
3 files changed, 33 insertions, 5 deletions
diff --git a/core/debug/trace/trace.odin b/core/debug/trace/trace.odin index 134609b05..6a9ba9dab 100644 --- a/core/debug/trace/trace.odin +++ b/core/debug/trace/trace.odin @@ -44,4 +44,34 @@ resolve :: proc(ctx: ^Context, frame: Frame, allocator: runtime.Allocator) -> (r @(require_results) in_resolve :: proc "contextless" (ctx: ^Context) -> bool { return intrinsics.atomic_load(&ctx.in_resolve) -}
\ No newline at end of file +} + +_format_hex :: proc(buf: []byte, val: uintptr, allocator: runtime.Allocator) -> int { + _digits := "0123456789abcdef" + + shift := (size_of(uintptr) * 8) - 4 + offs := 0 + + for shift >= 0 { + d := (val >> uint(shift)) & 0xf + buf[offs] = _digits[d] + shift -= 4 + offs += 1 + } + + return offs +} + +_format_missing_proc :: proc(addr: uintptr, allocator: runtime.Allocator) -> string { + PREFIX :: "proc:0x" + buf, buf_err := make([]byte, len(PREFIX) + 16, allocator) + copy(buf, PREFIX) + + if buf_err != nil { + return "OUT_OF_MEMORY" + } + + offs := len(PREFIX) + offs += _format_hex(buf[offs:], uintptr(addr), allocator) + return string(buf[:offs]) +} diff --git a/core/debug/trace/trace_cpp.odin b/core/debug/trace/trace_cpp.odin index 8ef377cef..1a96ee112 100644 --- a/core/debug/trace/trace_cpp.odin +++ b/core/debug/trace/trace_cpp.odin @@ -5,7 +5,6 @@ package debug_trace import "base:intrinsics" import "base:runtime" import "core:strings" -import "core:fmt" import "core:c" // NOTE: Relies on C++23 which adds <stacktrace> and becomes ABI and that can be used @@ -164,7 +163,7 @@ _resolve :: proc(ctx: ^Context, frame: Frame, allocator: runtime.Allocator) -> F } else if info: Dl_info; dladdr(rawptr(address), &info) != 0 && info.dli_sname != "" { frame.procedure = strings.clone_from_cstring(info.dli_sname, btc.allocator) } else { - frame.procedure = fmt.aprintf("(procedure: 0x%x)", allocator=btc.allocator) + frame.procedure = _format_missing_proc(address, btc.allocator) } frame.line = i32(line) return 0 diff --git a/core/debug/trace/trace_windows.odin b/core/debug/trace/trace_windows.odin index 04e92f125..b27b0ee29 100644 --- a/core/debug/trace/trace_windows.odin +++ b/core/debug/trace/trace_windows.odin @@ -6,7 +6,6 @@ import "base:intrinsics" import "base:runtime" import win32 "core:sys/windows" -import "core:fmt" _Context :: struct { hProcess: win32.HANDLE, @@ -56,7 +55,7 @@ _resolve :: proc(ctx: ^Context, frame: Frame, allocator: runtime.Allocator) -> ( if win32.SymFromAddrW(ctx.impl.hProcess, win32.DWORD64(frame), &{}, symbol) { fl.procedure, _ = win32.wstring_to_utf8(cstring16(&symbol.Name[0]), -1, allocator) } else { - fl.procedure = fmt.aprintf("(procedure: 0x%x)", frame, allocator=allocator) + fl.procedure = _format_missing_proc(uintptr(frame), allocator) } line: win32.IMAGEHLP_LINE64 |