ERR/E3.0 (slice 3a): embedded Frame trace resolution
Return-trace frames now resolve to real `func at file:line:col`
in-process — no DWARF, no symbolizer.
- New niladic, span-stamped `.trace_frame` IR op (mirrors is_comptime):
carries no operands; each backend derives the frame from context.
lower.zig's placeholderTraceFrame emits it; the existing
sx_trace_push call consumes it.
- emit_llvm: resolve the op's span + current function to
{file(basename), line, col, func}, build an interned Frame global
({string,i32,i32,string}, strings cached by content), push its
address (ptrtoint).
- interp: pack (func_id << 32 | span.start) for the comptime resolver
(slice 3b); never a pointer.
- sx_trace.c report_unhandled derefs SxFrame; trace.sx gains the Frame
struct, frame_at -> *Frame, and field-reading to_string. Layout
mirrored in 3 places with cross-ref comments.
Verified JIT + AOT. Snapshots 243/244/247 regenerated (placeholder ->
func at file:line:col). Gates: zig build, zig build test,
run_examples.sh -> 290 passed.
This commit is contained in:
@@ -11,22 +11,30 @@
|
||||
// `catch` handler (the clear fires when the handler completes, so the body
|
||||
// still sees the chain) or the (future) failable-`main` wrapper.
|
||||
//
|
||||
// Frame resolution: a frame is an opaque u64. Resolving it to `file:line:col`
|
||||
// needs DWARF line-info (ERR E3.0), which sx does not emit yet — so for now
|
||||
// each frame prints as "<location pending DWARF>". The frame COUNT, ordering,
|
||||
// and overflow note are already meaningful; once E3.0 lands, only the
|
||||
// per-frame location string changes. (The comptime path — resolving a packed
|
||||
// `(func_id, ir_offset)` via the interpreter's IR tables — also lands with the
|
||||
// resolver in E3.0/E3.3-full.)
|
||||
// Frame resolution (ERR E3.0 slice 3a): in compiled code a frame is a pointer
|
||||
// to an interned `Frame` the compiler stamped in at the push site, so the
|
||||
// location resolves in-process with no DWARF and no symbolizer. (The comptime
|
||||
// path — a packed `(func_id, ir_offset)` resolved via the interpreter's IR
|
||||
// tables — lands with slice 3b.)
|
||||
// =====================================================================
|
||||
|
||||
libc :: #library "c";
|
||||
|
||||
// The compiled return-trace frame. Layout MUST match `getFrameStructType` in
|
||||
// src/ir/emit_llvm.zig and `SxFrame` in library/vendors/sx_trace_runtime/sx_trace.c.
|
||||
Frame :: struct {
|
||||
file: string;
|
||||
line: s32;
|
||||
col: s32;
|
||||
func: string;
|
||||
}
|
||||
|
||||
// The error-trace buffer C API (library/vendors/sx_trace_runtime/sx_trace.c),
|
||||
// linked in for the JIT and auto-injected for AOT when traces are used.
|
||||
// `frame_at` hands back the stamped `*Frame` (the compiler stored its address).
|
||||
sx_trace_len :: () -> u32 #foreign;
|
||||
sx_trace_truncated :: () -> u32 #foreign;
|
||||
sx_trace_frame_at :: (i: u32) -> u64 #foreign;
|
||||
sx_trace_frame_at :: (i: u32) -> *Frame #foreign;
|
||||
|
||||
write :: (fd: s32, buf: [*]u8, count: usize) -> isize #foreign libc;
|
||||
|
||||
@@ -43,10 +51,8 @@ to_string :: () -> string {
|
||||
|
||||
i : u32 = 0;
|
||||
while i < n {
|
||||
frame := sx_trace_frame_at(i);
|
||||
// DWARF (E3.0) will resolve `frame` to file:line:col + function name.
|
||||
// Until then the raw frame value is shown (a placeholder, not a PC yet).
|
||||
line := format(" frame {}: <location pending DWARF> (raw {})\n", i, xx frame);
|
||||
f := sx_trace_frame_at(i);
|
||||
line := format(" {} at {}:{}:{}\n", f.func, f.file, f.line, f.col);
|
||||
result = concat(result, line);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user