remove core:fmt dependency from core:debug/trace

This commit is contained in:
jakubtomsu
2026-02-10 19:19:30 +01:00
parent 53cb56cc21
commit 874ffa0385
3 changed files with 33 additions and 3 deletions

View File

@@ -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])
}

View File

@@ -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

View File

@@ -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