diff options
Diffstat (limited to 'anim/src/source.zig')
| -rw-r--r-- | anim/src/source.zig | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/anim/src/source.zig b/anim/src/source.zig index 58b9df0..bbc985e 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -17,6 +17,7 @@ const ties = @import("ties.zig"); const map = @import("map.zig"); const cursors = @import("cursor.zig"); const Stage = @import("stage.zig").Stage; +const Recording = @import("Recording.zig"); const Cursor = cursors.Cursor; const theme = ui.theme; const Rect = ui.Rect; @@ -28,6 +29,9 @@ pub const Source = struct { cursor: Cursor, stage: *const Stage, focus: bool = false, + /// In a `descent`: while the pc is in code without source, the line it + /// called from waits, ringed, and the tag says where the pc is. + descent: bool = false, pub fn draw(p: *const Source, f: *sk.Frame, placed: anim.Placed) void { const box = p.stage.box(placed, .source); @@ -52,7 +56,10 @@ pub const Source = struct { const from: u32 = @intFromFloat(@floor(first)); const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), rec.line_count); const shown_first: u32 = @intFromFloat(windows[if (going >= 0.5) 1 else 0]); - const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}) }); + // Waiting: the pc is in code with no source, under this line's call. + const waits = p.descent and !rec.sourced(now.marked()) and rec.own[now.marked()] != 0; + const note = if (waits) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, now.marked()), "rip")), rec.own[now.marked()], whereIs(u, rec, now.marked()) }) else if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}); + const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = note }); const top = body.y + m.pad; // Where the mark is, and how much of it. @@ -85,7 +92,11 @@ pub const Source = struct { defer u.unclip(); // The plaque over the number. Fire: on the line about to run its // edges go out and come back, once, and nothing else moves. - if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source)); + if (waits) { + // The number ringed: a 2-unit primary frame where the plaque would be, no wash. + u.faded(shows).frame(.{ .x = theme.stroke.rule + 1, .y = mark_y + 1, .w = theme.metric.plaque.line + widen - 2, .h = m.row - 2 }, theme.color.text.primary, theme.stroke.rule); + if (!ui.mapping) ties.thread_waits = true; + } else if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source)); if (shows >= 1 and mark_y >= body.y and mark_y + m.row <= box.h) ties.anchor(u, .source, .{ .x = 0, .y = mark_y, .w = box.w, .h = m.row }); // The trail: the last three other lines it was on. It shifts without animation. @@ -109,13 +120,33 @@ pub const Source = struct { const span = text.lines[line - 1]; const k = std.mem.indexOfScalar(u32, trail[0..found], line); const on = shows >= 0.5 and line == mark_line; - rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on) .marked else if (k) |n| .{ .trail = n } else .plain); + rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (k) |n| .{ .trail = n } else .plain); } // The source is read at a run; at a sprint it is veiled too. context.veiled(u, box, now.sprint_veil); } }; +/// The last moment at or before `i` whose pc was on a line of the program's source. +fn firstOwn(rec: *const Recording, i: u64) u64 { + var at = i; + while (at > 0 and !rec.sourced(at)) at -= 1; + return at; +} + +/// Where the pc is at moment `i`, for the waiting line's tag: `the PLT`, +/// `libc's open`, `the vdso`. +fn whereIs(u: ui.Ui, rec: *const Recording, i: u64) []const u8 { + const name = context.frameName(u, rec, rec.register(i, "rip")); + if (std.mem.endsWith(u8, name, "@plt")) return "the PLT"; + var module: []const u8 = ""; + var buf: [256]u8 = undefined; + _ = (rec.moment(i).mapping(rec.register(i, "rip"), &module, &buf) catch null); + const base = std.fs.path.basename(module); + const short = base[0 .. std.mem.indexOfScalar(u8, base, '.') orelse base.len]; + return u.print("{s}'s {s}", .{ short, name }); +} + /// A source ready to draw: a class for each byte, and where each line is. const Text = struct { bytes: []const u8, |
