From 874ffa0385046efdab5b03f2bfc04bb735968400 Mon Sep 17 00:00:00 2001 From: jakubtomsu <66876057+jakubtomsu@users.noreply.github.com> Date: Tue, 10 Feb 2026 19:19:30 +0100 Subject: remove core:fmt dependency from core:debug/trace --- core/debug/trace/trace.odin | 30 ++++++++++++++++++++++++++++++ core/debug/trace/trace_cpp.odin | 2 +- core/debug/trace/trace_windows.odin | 4 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) (limited to 'core/debug') 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 -- cgit v1.2.3 From 0e2f5b7d7007df27f4a9f4a7eaa4b1166dd45f3a Mon Sep 17 00:00:00 2001 From: jakubtomsu <66876057+jakubtomsu@users.noreply.github.com> Date: Tue, 10 Feb 2026 19:45:18 +0100 Subject: remove strconv --- core/debug/trace/trace_windows.odin | 1 - 1 file changed, 1 deletion(-) (limited to 'core/debug') diff --git a/core/debug/trace/trace_windows.odin b/core/debug/trace/trace_windows.odin index d4f5d08cc..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:strconv" _Context :: struct { hProcess: win32.HANDLE, -- cgit v1.2.3 From 77be6a1f1837253c66eaaec2e5009ec9e52a23e3 Mon Sep 17 00:00:00 2001 From: jakubtomsu <66876057+jakubtomsu@users.noreply.github.com> Date: Tue, 10 Feb 2026 19:46:51 +0100 Subject: fix tabs --- core/debug/trace/trace.odin | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/debug') diff --git a/core/debug/trace/trace.odin b/core/debug/trace/trace.odin index 79c10b67f..8561d72c2 100644 --- a/core/debug/trace/trace.odin +++ b/core/debug/trace/trace.odin @@ -49,15 +49,15 @@ in_resolve :: proc "contextless" (ctx: ^Context) -> bool { _format_hex :: proc(buf: []byte, val: uintptr, allocator: runtime.Allocator) -> int { _digits := "0123456789abcdef" - shift := (size_of(uintptr) * 8) - 4 + shift := (size_of(uintptr) * 8) - 4 offs := 0 - for shift >= 0 { - d := (val >> uint(shift)) & 0xf + for shift >= 0 { + d := (val >> uint(shift)) & 0xf buf[offs] = _digits[d] - shift -= 4 + shift -= 4 offs += 1 - } + } return offs } -- cgit v1.2.3 From edd960905a043ad08bb6bc3cfcc6234f9c9baa3c Mon Sep 17 00:00:00 2001 From: jakubtomsu <66876057+jakubtomsu@users.noreply.github.com> Date: Tue, 10 Feb 2026 19:48:12 +0100 Subject: fix typo in the trace cpp backend --- core/debug/trace/trace.odin | 2 +- core/debug/trace/trace_cpp.odin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core/debug') diff --git a/core/debug/trace/trace.odin b/core/debug/trace/trace.odin index 8561d72c2..6a9ba9dab 100644 --- a/core/debug/trace/trace.odin +++ b/core/debug/trace/trace.odin @@ -74,4 +74,4 @@ _format_missing_proc :: proc(addr: uintptr, allocator: runtime.Allocator) -> str 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 49a5a9055..5c2c381d2 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 { - fl.procedure = _format_missing_proc(address, allocator) + frame.procedure = _format_missing_proc(address, allocator) } frame.line = i32(line) return 0 -- cgit v1.2.3 From 26e4af28adbdfef1d751bae22c847568b602ebb3 Mon Sep 17 00:00:00 2001 From: jakubtomsu <66876057+jakubtomsu@users.noreply.github.com> Date: Tue, 10 Feb 2026 19:55:50 +0100 Subject: remove the actual fmt import from trace_cpp --- core/debug/trace/trace_cpp.odin | 1 - 1 file changed, 1 deletion(-) (limited to 'core/debug') diff --git a/core/debug/trace/trace_cpp.odin b/core/debug/trace/trace_cpp.odin index 5c2c381d2..afa065474 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 and becomes ABI and that can be used -- cgit v1.2.3 From 83489c07f1123e1994e40a08a32206d8d78414a9 Mon Sep 17 00:00:00 2001 From: jakubtomsu <66876057+jakubtomsu@users.noreply.github.com> Date: Tue, 10 Feb 2026 19:56:49 +0100 Subject: fix allocator error --- core/debug/trace/trace_cpp.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/debug') diff --git a/core/debug/trace/trace_cpp.odin b/core/debug/trace/trace_cpp.odin index afa065474..1a96ee112 100644 --- a/core/debug/trace/trace_cpp.odin +++ b/core/debug/trace/trace_cpp.odin @@ -163,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 = _format_missing_proc(address, allocator) + frame.procedure = _format_missing_proc(address, btc.allocator) } frame.line = i32(line) return 0 -- cgit v1.2.3