diff --git a/core/debug/trace/trace.odin b/core/debug/trace/trace.odin index 134609b05..79c10b67f 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) +} + +_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]) } \ No newline at end of file diff --git a/core/debug/trace/trace_cpp.odin b/core/debug/trace/trace_cpp.odin index 8ef377cef..49a5a9055 100644 --- a/core/debug/trace/trace_cpp.odin +++ b/core/debug/trace/trace_cpp.odin @@ -164,7 +164,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) + fl.procedure = _format_missing_proc(address, 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..d4f5d08cc 100644 --- a/core/debug/trace/trace_windows.odin +++ b/core/debug/trace/trace_windows.odin @@ -6,7 +6,7 @@ import "base:intrinsics" import "base:runtime" import win32 "core:sys/windows" -import "core:fmt" +import "core:strconv" _Context :: struct { hProcess: win32.HANDLE, @@ -56,7 +56,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