diff options
Diffstat (limited to 'src/trace/Debugger.zig')
| -rw-r--r-- | src/trace/Debugger.zig | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/trace/Debugger.zig b/src/trace/Debugger.zig index 55f9cd1..08d3b30 100644 --- a/src/trace/Debugger.zig +++ b/src/trace/Debugger.zig @@ -77,6 +77,8 @@ asan_shadow: ?u64 = null, /// glibc's heap, recorded at every stop as `heap.zig` reads it (`--heap`): null for not at all. heap: ?@import("heap.zig").Watch = null, breakpoints: std.ArrayList(Breakpoint) = .empty, +/// Stop-state capture only; excludes waiting for the target and flushing a recorder. +capture_ns: u64 = 0, /// The current thread's registers at its last stop. regs: Regs = .{}, /// The target has exited. @@ -534,9 +536,11 @@ fn emit(d: *Debugger, ev: Event, payload: []const u8) !void { /// the watched memory that changed, then the stop. fn report(d: *Debugger, stop: Stop) !Stop { if (d.sink == null) return stop; + const started = std.Io.Clock.awake.now(d.syms.io); + defer d.capture_ns = @intCast(started.durationTo(std.Io.Clock.awake.now(d.syms.io)).toNanoseconds()); if (!d.done) { - // Code loaded or JIT-compiled while running without syscall stops. - if (d.syms.mappingAt(d.regs.rip) == null) try d.refreshMaps(); + // Every stop owns its mapping snapshot, including data mapped while PC stayed in known code. + try d.refreshMaps(); try d.emitLine(); if (d.asan and d.asan_shadow == null) try d.findShadow(); // With the 128 bytes under the stack pointer: the red zone, a leaf's locals. @@ -653,6 +657,14 @@ pub fn inspectCode(d: *Debugger, addr: u64, count: usize) !void { } } +pub fn mapSource(d: *Debugger, from: []const u8, to: []const u8) !void { + try d.syms.mapSource(from, to); + d.file_ids.clearRetainingCapacity(); + d.code_len.clearRetainingCapacity(); + try d.emitLine(); + try d.emitCode(); +} + pub fn loadJit(d: *Debugger, path: []const u8) !void { try d.refreshMaps(); try d.syms.loadJit(path); @@ -983,11 +995,7 @@ pub fn decode(d: *Debugger, nr: u16) ![]const u8 { /// The string id of a line's file: its path, recorded the first time. 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/...). - 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 path = try d.syms.sourcePath(l); const named = d.files.getOrPut(d.gpa, path) catch |err| { d.gpa.free(path); return err; |
