diff options
Diffstat (limited to 'anim/src/context.zig')
| -rw-r--r-- | anim/src/context.zig | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig index e5a226a..6123d26 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -140,7 +140,9 @@ pub const Registers = struct { if (age) |a| changed = rec.register(now.stops[a], "eflags") ^ rec.register(now.stops[a + 1], "eflags"); const heat = now.register(eflags_index, delay); const held = if (r.quiet) 0 else heat.level * heat.corner; - rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0); + // While a conditional jump runs, the flags it reads are framed (an echo of the row that set them). + const reads: u64 = if (now.resting() or now.advancing() >= 0.5) 0 else @import("disasm.zig").readsFlags(rec, now.stops[1]); + rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0, reads, now.reading(.cpu, 0)); } fn row(r: *const Registers, u: ui.Ui, now: cursors.Now, line_is: Shown, line_was: Shown, name: []const u8, y: f32, w: f32) void { @@ -288,8 +290,10 @@ fn callLine(rec: *const Recording, moment: u64, ret: u64) ?u32 { /// A frame's name: its function's (no offset), or its module's and offset where there is no symbol. pub fn frameName(u: ui.Ui, rec: *const Recording, pc: u64) []const u8 { const name = rec.strings.get(pc) orelse return u.print("{x}", .{pc}); - if (std.mem.indexOfScalar(u8, name, '!') != null) return ui.symbol(u, name); - return name[0 .. std.mem.lastIndexOfScalar(u8, name, '+') orelse name.len]; + const shown = ui.symbol(u, name); + // A library's symbol (`libc.so.6!open+0`) by its name alone; one with none, `libc+27781`. + if (std.mem.indexOfScalar(u8, name, '!') != null and shown.ptr != name.ptr + std.mem.indexOfScalar(u8, name, '!').? + 1) return shown; + return shown[0 .. std.mem.lastIndexOfScalar(u8, shown, '+') orelse shown.len]; } /// The registers (of the sixteen) that hold `addr` in `regs`. @@ -489,7 +493,7 @@ pub const Stack = struct { for (pointers.items) |p_| { const word, const saved = p_; if (saved and !(now.writeAge(word.addr, 8) == 0 or now.wasRead(word.addr, 8))) continue; - hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false); + hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false, false); } arcs.draw(v, theme.metric.arc.stack_lanes); // Where the window is, for a link to a word outside it. @@ -659,30 +663,33 @@ pub const Backtrace = struct { const arrive = std.math.clamp((since - time.quick / 2.0 - time.move) / time.quick, 0, 1); const room = rowsOf(box); const total = chains[if (slide >= 0.5) 1 else 0].len; - const body = u.panel(box.w, box.h, "backtrace", .{ .focus = b.focus, .note = if (total > room) u.print("newest on top \u{00b7} {d} more", .{total - room}) else "newest on top" }); + const body = u.panel(box.w, box.h, "backtrace", .{ .focus = b.focus, .note = newestAtBottom(u, total, room) }); clipBody(u, box); defer u.unclip(); const opens = [2][]const Recording.Call{ rec.stack(u.f.scratch, now.stops[1]), rec.stack(u.f.scratch, now.stops[0]) }; const top = body.y + m.pad; + // Newest at the bottom, `#0` last: a frame's row is its place from + // the oldest, less the oldest that do not fit (dropped from the top). + const dropped = [2]usize{ chains[0].len -| room, chains[1].len -| room }; for (chains, 0..) |chain, side| { const shows = if (side == 0) 1 - leave else arrive; - for (chain[0..@min(chain.len, room + shared)], 0..) |frame, i| { + for (chain, 0..) |frame, i| { const from_end = chain.len - 1 - i; const kept = from_end < shared; // A frame both have is drawn once, from the old chain to its place in the new. if (kept and side == 1) continue; - var at_row: f32 = @floatFromInt(i); + var at_row = @as(f32, @floatFromInt(from_end)) - @as(f32, @floatFromInt(dropped[side])); var depth = i; var which = side; if (kept) { const to = chains[1].len - 1 - from_end; - at_row = std.math.lerp(at_row, @as(f32, @floatFromInt(to)), slide); + at_row = std.math.lerp(at_row, @as(f32, @floatFromInt(from_end)) - @as(f32, @floatFromInt(dropped[1])), slide); if (slide >= 0.5) { depth = to; which = 1; } } else if (shows <= 0) continue; - if (at_row >= @as(f32, @floatFromInt(room))) continue; + if (at_row <= -1 or at_row >= @as(f32, @floatFromInt(room))) continue; const v = if (kept) u else u.faded(shows); const name = ui.symbol(u, rec.strings.get(frame.pc) orelse u.print("{x}", .{frame.pc})); rows.callRow(v, top + at_row * m.row, box.w, depth, name, callArguments(u, rec, opens[which], depth, frame.pc), frameWhere(u, rec, if (which == 1) now.marks[1] else now.marks[0], depth, frame.pc), depth == 0); @@ -692,6 +699,12 @@ pub const Backtrace = struct { } }; +/// A backtrace's tag note: `newest at the bottom`, and how many of the +/// oldest a panel of `room` rows leaves out above. +pub fn newestAtBottom(u: ui.Ui, total: usize, room: usize) []const u8 { + return if (total > room) u.print("newest at the bottom \u{00b7} {d} more above", .{total - room}) else "newest at the bottom"; +} + test "the flags' bits" { try std.testing.expectEqual(@as(?usize, 17), index("eflags")); } |
