summaryrefslogtreecommitdiff
path: root/src/trace/Debugger.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-13 01:24:16 -0300
committerGabriel Schneider <[email protected]>2026-11-13 01:34:46 -0300
commit5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (patch)
tree5fdffebd75ed3fbac1eae5dec0a3f2d491450342 /src/trace/Debugger.zig
parent4b4113a0217ee27c78e7efddb66ff5a455d49083 (diff)
downloadcomputeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.tar.gz
computeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.zip
debugger: align source and add rich Vim-style navigation
Diffstat (limited to 'src/trace/Debugger.zig')
-rw-r--r--src/trace/Debugger.zig31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/trace/Debugger.zig b/src/trace/Debugger.zig
index 9368a42..55f9cd1 100644
--- a/src/trace/Debugger.zig
+++ b/src/trace/Debugger.zig
@@ -639,6 +639,31 @@ fn emitCode(d: *Debugger) !void {
}
}
+/// Capture code for a viewer without executing it or changing the selected registers.
+pub fn inspectCode(d: *Debugger, addr: u64, count: usize) !void {
+ if (count == 0 or count > 256) return error.InvalidCount;
+ const decode_insn = d.disasm orelse return error.NoDisassembler;
+ if (d.syms.mappingAt(addr) == null) try d.refreshMaps();
+ var pc = addr;
+ var back: u8 = 0;
+ for (0..count) |_| {
+ back = (try d.emitInstruction(decode_insn, pc, back)) orelse break;
+ try d.nameAddress(pc);
+ pc +|= back;
+ }
+}
+
+pub fn loadJit(d: *Debugger, path: []const u8) !void {
+ try d.refreshMaps();
+ try d.syms.loadJit(path);
+ const module = d.syms.modules.items[d.syms.modules.items.len - 1];
+ // Existing decoded rows must acquire the newly imported source locations.
+ var addr = module.start;
+ while (addr < module.end) : (addr += 1) _ = d.code_len.remove(addr);
+ try d.emitLine();
+ try d.emitCode();
+}
+
/// Records the instruction at `addr` as a string (`event.codeId`), once: a
/// byte for its length, a byte for the length of the one before it (0:
/// not known), then its text; and when either is known, a zero, its source
@@ -841,7 +866,7 @@ fn emitModule(d: *Debugger, m: *const Symbols.Module) !void {
const id = event.moduleId(m.path);
if ((try d.described.getOrPut(d.gpa, id)).found_existing) return;
var text: [1 + 64]u8 = undefined;
- text[0] = @intFromEnum(m.debug);
+ text[0] = @backingInt(m.debug);
const n = @min(m.build_id.len, 64);
@memcpy(text[1..][0..n], m.build_id[0..n]);
try d.emit(.{ .kind = .string, .a = .{ id, 0, 0, 0, 0, 0 } }, text[0 .. 1 + n]);
@@ -960,7 +985,9 @@ fn fileId(d: *Debugger, l: Symbols.Line) !u64 {
if (d.file_ids.get(l.key)) |id| return id;
// As the compilation saw it: its directory, the file's, its name, each
// relative to the one before (glibc's: /usr/src/debug/glibc/glibc/csu/../sysdeps/...).
- const path = try std.fs.path.resolveAlloc(d.gpa, &.{ l.base, l.dir, l.name });
+ var cwd: [4096]u8 = undefined;
+ const cwd_len = if (std.fs.path.isAbsolute(l.base) or std.fs.path.isAbsolute(l.dir) or std.fs.path.isAbsolute(l.name)) 0 else try std.Io.Dir.cwd().realPath(d.syms.io, &cwd);
+ const path = try std.fs.path.resolveAlloc(d.gpa, &.{ cwd[0..cwd_len], l.base, l.dir, l.name });
const named = d.files.getOrPut(d.gpa, path) catch |err| {
d.gpa.free(path);
return err;