From 8b5d0340c9f9b3168c67f04e57cfa03712ac992c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 22:02:01 -0300 Subject: canim: a continue is a wave; what arrives after a fade is plain; a pin only where its register points From the designer's review of the SQLite scene. Between far stops the changed registers strike two frames apart in pwndbg's order, and links and pins set off with memory. A stack window or a dump that fades in carries no marks of changes the viewer did not see. At rest a moved register kept a pin at its old place as well, in every scene: gone. The kernel's answer is filled before the return arrow leaves, and rax strikes as it lands. Every dump has one reading, by type (a char quoted, a bool by name); line numbers are as wide as the program's largest; pins' names keep the side they came to. Names and measures follow the catalogue (.loose, theme.metric.calls, time.pin, time.continue_wave). Co-Authored-By: Claude Fable 5.2 --- anim/README.md | 125 ++++++++++++--------- anim/scenes/gallery.zig | 19 +++- anim/scenes/sqlite.zig | 25 ++--- anim/src/Recording.zig | 6 + anim/src/array.zig | 5 +- anim/src/calls.zig | 21 +--- anim/src/context.zig | 76 ++++++++++--- anim/src/cursor.zig | 68 +++++++++--- anim/src/disasm.zig | 8 +- anim/src/hexdump.zig | 251 ++++++++++++++++++++++++++---------------- anim/src/nodes.zig | 52 ++++++++- anim/src/root.zig | 6 +- anim/src/rows.zig | 22 ++-- anim/src/source.zig | 18 +-- anim/src/stage.zig | 4 +- anim/src/syscalls.zig | 43 ++++---- anim/src/theme.zig | 43 +++++++- anim/src/ties.zig | 22 +++- anim/test/gallery/atoms.png | Bin 99949 -> 104376 bytes anim/test/gallery/none.png | Bin 223173 -> 223316 bytes anim/test/gallery/rest.png | Bin 230803 -> 230773 bytes anim/test/gallery/rows.png | Bin 106864 -> 113603 bytes anim/test/gallery/step.png | Bin 230313 -> 230367 bytes anim/test/gallery/subject.png | Bin 204289 -> 204673 bytes 24 files changed, 532 insertions(+), 282 deletions(-) diff --git a/anim/README.md b/anim/README.md index 5801c74..bf2100a 100644 --- a/anim/README.md +++ b/anim/README.md @@ -75,7 +75,12 @@ projection from its return address does, 36 f after); the writes of one step str mark advances last; a rest. `walk` plays steps in full, `hurry` ramps the pace down and up again (each step 0.6 of the one before) to a run (0.30 s a step) or a sprint, `step` takes an explicit `Plan` (`Array.swap`, -`syscalls.step`). Components read it through `Cursor.now(at)`. +`syscalls.step`), and `continue` goes to a stop far from this one (a +breakpoint): the line it leaves fires, the registers it changed strike in +a wave 2 f apart in pwndbg's order (fill 6 f, no arm, no pulse), then +memory and the idea, a 36 f hold, the mark out and in (6 f each, the +source fading through first if far), a 24 f rest. Components read it +through `Cursor.now(at)`. ## The scenes @@ -87,7 +92,7 @@ step) or a sprint, `step` takes an explicit `Plan` (`Array.swap`, | `sort` | insertion sort: compares and swaps | `subject`, `array` | `sort` | | `syscalls` | open, read, close, write: the kernel's side | `subject`, `syscalls` | `hello` | | `zoom` | one line of C as its instructions, the call's bytes | `none`, the camera at x2 | `steps` | -| `sqlite` | a row's way to disk in SQLite: from `sqlite3_step` to `sqlite3BtreeInsert` (three continues, the row's struct on the stack), the commit's `unixWrite` nine calls under `main`, `pwrite64` of page 2 into the kernel, and the page read as a B-tree leaf | `subject` with the backtrace in the drawing's place, then `syscalls`; its view a `hexdump.Dump` | `sqlite` | +| `sqlite` | a row's way to disk in SQLite: from `sqlite3_step` to `sqlite3BtreeInsert` (three continues, the row's struct on the stack), the commit's `unixWrite` nine calls under `main`, `pwrite64` of page 2 into the kernel, and the page read as a B-tree leaf | `subject`, `backtrace` (`Context.Options.backtrace`), then `syscalls`; its view a `hexdump.Dump` | `sqlite` | | `gallery` | every block in its states | all three | `gallery` | ## The blocks @@ -97,20 +102,20 @@ every state the code has in the `gallery` scene. | Layer | Block | Where | Notes | | --- | --- | --- | --- | -| 0 tokens | grid, colour, type, the splits | `src/theme.zig` | per "Token changes"; JetBrains Mono NL (`.code*` faces) for all mono, Medium under 30 | +| 0 tokens | grid, colour, type, the splits | `src/theme.zig` | per "Token changes" (`metric.calls`, `time.pin`, `time.continue_wave`, `time.relayout_fade` there; the insn's character counts gone); JetBrains Mono NL (`.code*` faces) for all mono, Medium under 30 | | 1 atom | `address` (`lead`, `name`, `rwx`), `value` (and `Ui.typed`: `fd`, `bool`, `char`), `arrow` (`points`, `holds`, `more`), `mark`s, `plaque` (`chip`), `pin` (`row`, `under`), `bracket` (`quiet`, `tie`, `thread`), `tag` | `src/ui.zig` (`Ui.address`, `.value`, `.arrow`, `.written`, `.read`, `.cellWritten`, `.cellRead`, `.current`, `.trail`, `.unknown`, `.chip`, `.pinRow`, `.pinUnder`, `.bracket`, `.panel`) | marks in the context: `armed`, `struck`, `held` (a tick), `read`; in a lens's cell the same with a bar | -| | `byte` | `src/rows.zig` `bytes` | `number`, `pointer`, `text` (a string's ink), `allocator` (also bytes that are no field of what a dump is about), `unread`; `pad`; `bytesAt` moves the bytes right of a long (stack) address | +| | `byte` | `src/rows.zig` `bytes` | `number`, `pointer`, `text` (a string's ink), `loose` (a byte of no field: the allocator's, padding, past what a dump is of), `unread`; `pad`; `bytesAt` moves the bytes right of a long (stack) address, by the dump's widest | | 2 row | `chain`, `reg` (and `rip` with the flags), `slot`, `line`, `bytes`, `call` (`span`, `callRow`) | `src/rows.zig` | `chain` follows `zt.telescope.chase`; cut at its far end, `more` | | | `insn` | `src/disasm.zig` | columns at 2, 31, 40, 134, 180, 264, 564; operands whole, the annotation from 564 or a character after them; then a size word goes, then the operands give way, never inside `[]`; `current`, `ran` (every instruction of the last three steps), `ahead`, `outside`; the jump lane from the jump just before the pc's moment | -| 3 panel | `registers`, `stack`, `backtrace` | `src/context.zig` | the stack's window on `[rsp, rbp+16)` keeping the touched word in view, rsp and rbp's pins travelling (keeping their place among the names they leave and join); a window that moves more than 16 words fades out and in round memory's strike; a frame's name longer than the spans' room shortens the chains beside it; `call` spans and the backtrace (`#n`, name, arguments at 384, file and line) from `zt.telescope.frames`, the frames two stops share sliding to their new depth | -| | `source` | `src/source.zig` | the whole file in a window, its middle third; numbers as wide as the window needs (SQLite's have five digits), the text moved right by as much; a window more than two windows away fades out and in | -| | `disasm` | `src/disasm.zig` | 17 rows (9 as subject), fewer above near a function's start | -| | `hexdump` | `src/hexdump.zig` | a lens's view (`hexdump.panel`): `bytes` rows and their reading, veiled at a sprint; `Dump`, a view of a region by the fields a scene gives it (`Field`: where, how long, read as a number, big-endian or not, a pointer, text, or left to the eye), the rows that hold a field and a `more` row for those left out, marks the scene plays, the bytes a syscall was given as the kernel took them, and only what the debugger read at the stop (`seen`) | -| | lenses: `nodes`, `array`, `calls`, `syscalls` | `src/nodes.zig`, `src/array.zig`, `src/calls.zig` (`Tree`), `src/syscalls.zig` (`Crossing`) | the drawing in `band` (over the program column), its view in `view` (over the state column): `nodes` and `array` a dump (`hexdump.panel`), `calls` the backtrace with arguments, `syscalls` the bytes the call is given or fills | +| 3 panel | `registers`, `stack`, `backtrace` | `src/context.zig` | the stack's window on `[rsp, rbp+16)` keeping the touched word in view, its tag the first and last word shown (`rsp+20 to rsp+48`), rsp and rbp's pins travelling 18 f after rsp's strike (`time.pin`, keeping their place among the names they leave and join), at rest only where the register points; a window that moves farther than its own height (six or eight slots) fades out and in round memory's strike, and what it brings, and what changed before it, is plain; a frame's name longer than the spans' room shortens the chains beside it; `call` spans and the backtrace (`#n`, name, arguments at 384, file and line) from `zt.telescope.frames`, the frames two stops share sliding to their new depth; the backtrace as a lens's drawing with `Context.Options.backtrace` | +| | `source` | `src/source.zig` | the whole file in a window, its middle third; numbers as wide as the program's largest line (SQLite's six digits), the text moved right by as much; a window going farther than its own height fades out and in | +| | `disasm` | `src/disasm.zig` | 17 rows (9 as subject), fewer above near a function's start; the line column as wide as the source's; two windows that overlap scroll, others fade out and in | +| | `hexdump` | `src/hexdump.zig` | a lens's view (`hexdump.panel`): `bytes` rows and their reading, veiled at a sprint; one reading for every dump (`hexdump.reading`), a list a character apart, a typed number as its type reads (`char` quoted, `bool` by name); the address room once a dump, by its widest; `Dump`, a view of a region by the fields a scene gives it (`Field`: where, how long, read as a number, big-endian or not, a pointer, text, or left to the eye), the rows that hold a field and a `more` row for each stretch left out, and where those rows outnumber the window, a window kept round the first row a mark or the step is on, the rest folded into `more` rows; marks the scene plays, and the step's only from the stop it came in at (`since`); the bytes a syscall was given as the kernel took them (`given`), and only what the debugger read at the stop (`seen`) | +| | lenses: `nodes`, `array`, `calls`, `syscalls`, `backtrace` | `src/nodes.zig`, `src/array.zig`, `src/calls.zig` (`Tree`), `src/syscalls.zig` (`Crossing`), `src/context.zig` (`Backtrace`, `lens`) | the drawing in `band` (over the program column), its view in `view` (over the state column): `nodes` and `array` a dump (`hexdump.panel`), `calls` the backtrace with arguments, `syscalls` the bytes the call is given or fills, `backtrace` (eleven rows as subject, five beside) a `Dump` the scene gives; an `under` pin's names in the order they came, the first left | | 4 tie | `thread`, `link` (and its `pin`), `projection`, `echo` | `src/ties.zig` | panels publish places (`anchor`); `Ties`, added last, draws in the channels: a link climbs to a node by the gutter's left lane and goes down to a slot by the right, its name riding its head, a target past the stack's window a stub and a row count; a projection from the view's bytes, or from a frame's return address to its call's node | | 5 frame | `stage` and `relayout` | `src/stage.zig` | splits `none`, `beside`, `subject` (`theme.layout.split`): the band is `band` (the drawing) and `view`; `relayout` fades the drawing round its move; `holdStack` holds the stack's window for the camera, with `free` slots | | | `clock`, `caption`, `veil`, `card` | `src/words.zig`, `src/root.zig` (`Narrator`, `Camera`) | the clock still while a step plays, its piece fading in once the mark lands; a caption stays its reading time; the title card is `scenes/title.zig` | -| 6 verb | `fire`, `arm`, `strike`, `cool`, `read`, `extend`, `link`, `project`, `travel` (pins), `advance`, `cascade`, `run`, `sprint`, `establish` (`Context.establish`: a drawing's elements fade in rising, no lines), `scroll`, `relayout`, `visit`, `say` | `src/cursor.zig` (the timetable), the blocks (each draws its state at the instant) | tokens in `theme.time`; a level gives up its slot when nothing it touched is drawn (`Recording.drawn`) | +| 6 verb | `fire`, `arm`, `strike`, `cool`, `read`, `extend`, `link`, `project`, `travel` (pins), `advance`, `cascade`, `continue` (`Cursor.continue`, `Plan.wave`), `run`, `sprint`, `establish` (`Context.establish`: a drawing's elements fade in rising, no lines), `scroll`, `relayout`, `visit`, `say` | `src/cursor.zig` (the timetable), the blocks (each draws its state at the instant) | tokens in `theme.time`; a level gives up its slot when nothing it touched is drawn (`Recording.drawn`) | `Recording` (`src/Recording.zig`) is the index every block reads: lines, calls, syscalls, allocations, which registers and bytes each moment changed @@ -141,8 +146,8 @@ and no canary stepped through that the source does not say. A recording that begins inside a call (`--from`) has that call open from its first stop (`Recording.index`, from the frame chain). Writes are the bytes whose value changed, to the element the instruction stored (its -`touch`); a store of the same value is kept apart (`store_spans`) and -counts as assigning a local. A register's change over a step is net: a +`touch`); a store of the same value is kept apart (`storedSame`) and +counts as assigning a local (and as a name coming to a node's pin). A register's change over a step is net: a call's rsp put back is not struck. The vDSO's `clock_gettime` is stepped through under the runtime and the agent: its retry loop makes the counts vary a little from one recording to the next. An address no symbol @@ -153,59 +158,80 @@ holds is named from its module's first mapping (`list+2c89`). `tools/chart.py chart` on the 1080p exports in `out/` (the designer's five checks; its regions follow the two-panel band now). Encoded with `-g 600`: x264's keyframe at 10, 20, 30 s is a one-frame fade the instrument sees. +"Before" is the exports this pass started from (10 November, evening); +"after" the ones it made: the continue's wave, plain windows and dumps +after a fade, the crossing's order, pins at rest only where their +register points, `time.pin`, the compact reading, names by arrival. | | fib | list | sort | syscalls | zoom | sqlite | | --- | --- | --- | --- | --- | --- | --- | -| POP, round 2 / 3 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | -| CROWD, round 2 / 3 | 7 / 2 | 2 / 7 | 10 / 6 | 5 / 1 | 4 / 3 | – / 1 | -| RUSH, round 2 / 3 | 0 / 0 | 0 / 2 | 2 / 0 | 1 / 2 | 0 / 0 | – / 1 | -| AIR, round 3 | 0 | 0 | 0 | 0 | 1 | 4 | -| seconds, round 3 | 41.5 | 60.5 | 42.0 | 38.5 | 32.0 | 64.6 | - -(sort as the coordinator re-exported it without the camera; syscalls and -sqlite after the crossing's changes: a register carries a call only while -it holds the argument at the stop shown, `rax` is struck after the -kernel's `returns` row; fib, list and zoom are the round-3 exports, made -before the stack's and backtrace's motions below.) +| POP, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | +| CROWD, before / after | 2 / 2 | 7 / 7 | 5 / 5 | 1 / 1 | 4 / 4 | 1 / 0 | +| RUSH, before / after | 0 / 0 | 2 / 2 | 0 / 0 | 2 / 1 | 0 / 0 | 1 / 1 | +| AIR, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 1 / 1 | 4 / 5 | +| seconds, after | 41.5 | 60.5 | 42.0 | 37.9 | 32.0 | 64.6 | What fires, and why it is left: -- CROWD: fib 12.05 and 27.20, list 30.62 and 32.18, sort 17.58 are the +- CROWD: fib 12.05 and 27.20, list 30.62 and 32.18, sort 17.60 are the veil coming over the registers, stack and disassembly at the first shortened step (one veil over three panels); zoom 9.65 and 21.55 the camera (the regions are fixed on the screen); zoom 11.75 the stack's window scrolling to its hold under the camera (the stack fills every - region there). The rest (list 15.92, 19.32 and the others like them, - sort 11.68, 27.12, 29.42 and the others, syscalls 35.35, sqlite 43.40) - are an `advance`: the thread, the plaques and rip move as one mark, the + region there); sort 30.00 is x264's keyframe on a step's first frame. + The rest (list 15.92, 19.32 and the others like them, sort 11.68, + 29.42 and 36.13, syscalls 34.75, zoom 3.62) are an + `advance`: the thread, the plaques and rip move as one mark, the source and the disassembly scroll with it, and a link or projection - goes back into its pin, all on the catalogue's one frame. -- RUSH: list 29.20 and 29.55, syscalls 29.37 and 29.72, sqlite 9.10: a - caption arrives, and the next change the instrument sees is the - keyframe at 30.00 (10.00) (a fade of every region over one frame, - 0.00% at its peak). + goes back into its pin, all on the catalogue's one frame. (sqlite's, + the crossing's advance at 43.40, no longer starts with another panel.) +- RUSH: list 29.20 and 29.55, syscalls 29.32, sqlite 9.10: a caption + arrives, and the next change the instrument sees is the keyframe at + 30.00 (10.00) (a fade of every region over one frame, 0.00% at its + peak). - AIR: a caption's reading time on a still picture: the last one's and - the 2 s on the finished picture (zoom 26.88, 3.1 s; sqlite 60.02, - 4.6 s), and in sqlite three more, each a dense caption over a stop - (11.38, 7.2 s: the arguments; 32.72, 3.5 s: the commit's backtrace; - 50.03, 4.9 s: the page's header), its fields framed as it names them. + the 2 s on the finished picture (zoom 26.88, 3.1 s; sqlite 60.03, + 4.6 s), and in sqlite four more, each a dense caption over a stop + (11.38, 7.2 s: the arguments; 24.57, 3.2 s: the two more rows, now + that a continue is a wave and a 36 f hold and not a cascade's longest + hold; 32.95, 3.2 s: the commit's backtrace; 50.03, 4.9 s: the page's + header), its fields framed as it names them. ## What is not done - Back pointers between nodes still run under the nodes: a page keyline round each pin's stub and head shows them passing behind it (there is no lane for them in `beside`). -- Names keep their side when one of two leaves a pin and when a pin's - name travels; a name that arrives where another already is takes the - right, and once it has landed the pin's own order (variables, then - registers) may put it on the other side. (In the stack's lane, rsp or - rbp travelling alone keeps its place among the names it leaves and - joins; both travelling to rows with other names is not handled.) -- The hexdump's reading of a `char` or `bool` field (the lens's values - and cells read them by type; the dump's reading column does not). +- An `under` pin's names are in the order they came to the node (the + recording read back from the stop shown), so a name that lands where + another is stays on the right it travelled on; but one left alone + where it was on the right keeps that side only for the step in which + the other left, and takes the left at the next. A third name coming to + a pin whose two sides are taken is counted (`+1`), unless it is a + variable the scene names and a register holds the right, which it then + takes; on its way it is drawn over the right-hand name (list, 7.5 s). + A pin's count (`+1`) can run into the left-hand name of the next + node's pin (list, 26 to 57 s). + (In the stack's lane, + rsp or rbp travelling alone keeps its place among the names it leaves + and joins; both travelling to rows with other names is not handled.) +- Pins travel with `time.pin`'s times, but on `standard`, not the + catalogue's `glide`, in the stack's lane and the array; a pin in a + drawing sets off when the idea strikes (the projection's arrival), + not 18 f after its word's strike. +- The disassembly scrolls or fades over the mark's advance: 24 f where + the source's window moves too, 12 f where the mark only jumps. +- Whether the stack's window faded at a step is judged by the slots it + shows now: after a relayout to fewer, a step that scrolled may lose + its ticks. +- A frame's name on a `call` span is never cut (`metric.span.name_max`, + 300 units, is not built); the calls tree's small and folded sizes are + not built. - A link to a slot past the stack's window ends in its stub and row count: drawn in the sqlite scene only (rsi to the struct on the caller's - stack, `23 rows`, 4.2 s). + stack, `23 rows`, 5.0 s; in a continue a link sets off with memory's + strike, when the window is at its new place). One to a slot above the + window would put its count over the panel's tag. - The calls tree's leaf spacing holds for fib(5); past about ten leaves nodes and badges collide (the catalogue's known case). - `heap` and `pages` lenses are not in the band (`Timeline` is the old @@ -222,11 +248,10 @@ What fires, and why it is left: - A program's frame arguments are in the backtrace only for calls the recording tells (an instrumented program's); at a breakpoint the callee's are in its registers, which the scene's captions name. -- The sqlite scene changes what is over the band (the backtrace, then the - kernel's side) and its view (the SQL at rbx, the row, the page) by a - fade, not by a verb of the catalogue; the backtrace in the band's - drawing is a split the catalogue does not have (`subject` with the - backtrace where the drawing goes: eleven rows). +- The sqlite scene changes what is over the band (the backtrace lens, + then the kernel's side) and its view (the SQL at rbx, the row, the + page) by fades scripted in the scene (12 f out, then 12 f in); the + kernel's side does not bring its elements in as at `establish`. - `zig build test` prints "failed command" for each scripted scene: that is the run echoing its stderr (the Vulkan headless warning), not a failure; the summary line is the verdict. diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index 2cc3d9f..fce9d43 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -98,16 +98,18 @@ fn atoms(u: ui.Ui, p: *const Pages) void { _ = u.address(350, rows.baseline(y), 0x407030, .{ .ink = ui.rgb(region.heap) }); // byte - y = 344; + y = 330; title(u, 64, y, "byte"); - note(u, 200, y, "number, pointer, allocator, unread; pad"); + note(u, 200, y, "number, pointer, text, loose, unread; pad"); y += 12; { var values: [16]u8 = .{ 9, 0, 0, 0, 0, 0, 0, 0, 0x30, 0x70, 0x40, 0, 0, 0, 0, 0 }; var known: [16]bool = @splat(true); rows.bytes(u, y, 0x407050, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer } }, region.heap, 4, true, m); values = .{ 0, 0, 0, 0, 0, 0, 0, 0, 0x21, 0, 0, 0, 0, 0, 0, 0 }; - rows.bytes(u, y + row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .allocator } }, region.heap, 4, false, m); + rows.bytes(u, y + row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .loose } }, region.heap, 4, false, m); + values = .{ '.', '/', 'l', 'i', 's', 't', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + rows.bytes(u, y + 2 * row, 0x407070, &values, &known, &.{ .{ .first = 0, .len = 7, .kind = .text }, .{ .first = 7, .len = 9, .kind = .loose } }, region.heap, 4, true, m); } // mark, in the context and in a lens's cell @@ -264,7 +266,7 @@ fn rowsPage(u: ui.Ui, p: *const Pages) void { y = 750; title(u, 64, y, "bytes"); - note(u, 160, y, "runs from the types; marks per run: struck, read, held"); + note(u, 160, y, "runs from the types; marks per run: struck, read, held; read as their types: a char, a bool, an int, a pointer"); y += 12; panel = u.moved(976, y); var values: [16]u8 = .{ 12, 0, 0, 0, 0, 0, 0, 0, 0x10, 0x70, 0x40, 0, 0, 0, 0, 0 }; @@ -274,6 +276,15 @@ fn rowsPage(u: ui.Ui, p: *const Pages) void { rows.bytes(panel, row, 0x407050, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer, .heat = .ember } }, region.heap, 4, true, m); known = @splat(false); rows.bytes(panel, 2 * row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .unread } }, region.heap, 4, false, m); + // A struct of a char, a bool, padding, an int and a pointer: each read as its type says. + values = .{ 'A', 1, 0, 0, 0xfd, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 }; + known = @splat(true); + const types = canim.Recording.types; + const char: types.Type = .{ .scalar = .{ .kind = .char, .bits = 8 } }; + const boolean: types.Type = .{ .scalar = .{ .kind = .bool, .bits = 8 } }; + const int: types.Type = .{ .scalar = .{ .kind = .int, .bits = 32 } }; + rows.bytes(panel, 3 * row, 0x407080, &values, &known, &.{ .{ .first = 0, .len = 1, .kind = .number }, .{ .first = 1, .len = 1, .kind = .number }, .{ .first = 2, .len = 2, .kind = .loose }, .{ .first = 4, .len = 4, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer } }, region.heap, 4, true, m); + _ = canim.hexdump.reading(panel, 3 * row, 0, m, &values, &known, &.{ .{ .at = 0, .len = 1, .type = char }, .{ .at = 1, .len = 1, .type = boolean }, .{ .at = 4, .len = 4, .type = int }, .{ .at = 8, .len = 8, .reads = .pointer } }); } fn frame(s: *anim.Frame) void { diff --git a/anim/scenes/sqlite.zig b/anim/scenes/sqlite.zig index f145da6..e7d103e 100644 --- a/anim/scenes/sqlite.zig +++ b/anim/scenes/sqlite.zig @@ -103,18 +103,17 @@ fn frame(s: *anim.Frame) void { var at = canim.cursor(s, rec, start); at.levels = .{ .source_rows = 10 }; at.journey(.moment, back); - // The lens is the subject: the call chain, eleven rows, over the + // The lens is the subject: the backtrace, eleven rows, over the // program column (where the kernel's side comes later), and over the // state column the bytes the newest call is handed. - var split = canim.layout.split.subject; - split.backtrace = split.band; - const ctx = canim.context(s, at, .{ .split = split, .syscalls = true }); + const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject, .syscalls = true, .backtrace = true }); const kernel = canim.crossing(s, .{ .cursor = at, .stage = ctx.stage, .view = false }); // What the opening stop's rbx points at: the SQL sqlite3_exec is running. const sql = canim.add(s, canim.hexdump.Dump{ .cursor = at, .stage = ctx.stage, .about = "the SQL being run, at rbx", + .since = start, .of = .{ .base = rec.register(start, "rbx"), .len = 32, .fields = &.{.{ .at = 0, .len = 32, .reads = .text }}, .region = region.rodata }, }); // The row, as sqlite3BtreeInsert is handed it: rsi. @@ -126,6 +125,7 @@ fn frame(s: *anim.Frame) void { .about = "pX, the row: a BtreePayload, at rsi", .of = .{ .base = rec.register(first, "rsi"), .len = 48, .fields = &payload, .region = region.stack }, .marks = row_marks, + .since = first, }); // The page, as unixWrite is handed it: rsi. At that stop the debugger // has read 32 bytes of it (where rsi leads); the kernel takes it whole. @@ -140,6 +140,7 @@ fn frame(s: *anim.Frame) void { .about = "pBuf: page 2 of t.db, at rsi", .of = .{ .base = write.args[1], .len = 4096, .fields = leaf(s.arena, bytes), .region = region.heap, .seen = .{ .addr = write.args[1], .len = 32 } }, .marks = page_marks, + .since = handed, }); const joins = ctx.ties(s); var says: canim.Narrator = .{}; @@ -165,19 +166,11 @@ fn frame(s: *anim.Frame) void { } } }; - // A continue: straight to the next stop, timed by what it changed. - const walk = struct { - fn to(c: canim.Cursor, f: *anim.Frame, moment: u64) void { - const plan = c.reading(c.moment(f), moment); - c.step(f, moment, plan, plan.total); - } - }.to; - canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, sql, ctx.backtrace, joins }); says.line(s, "SQLite at a breakpoint in `sqlite3_step`, which runs\n`INSERT INTO t VALUES ('alpha')`. Continue:"); // What rbx showed was this stop's: it goes before the program moves on. fade.out(s, sql); - walk(at, s, first); + at.@"continue"(s, first); s.wait(t.beat); // The row it was handed: a struct on its caller's stack. fade.in(s, row); @@ -190,13 +183,13 @@ fn frame(s: *anim.Frame) void { says.line(s, "Two more continues, the same call: rowid 2, then 3, records\nof 6 and 7 bytes. The rows are in memory, not yet on disk."); mark.out(s, row_marks); - walk(at, s, second); + at.@"continue"(s, second); s.wait(t.beat); - walk(at, s, third); + at.@"continue"(s, third); says.line(s, "`COMMIT`: `unixWrite`, nine calls under `main`, is handed\npage 2 of the file: 4096 bytes, for offset 4096."); fade.out(s, row); - walk(at, s, handed); + at.@"continue"(s, handed); s.wait(t.beat); fade.in(s, page); diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig index 41619aa..833d17b 100644 --- a/anim/src/Recording.zig +++ b/anim/src/Recording.zig @@ -772,6 +772,12 @@ pub fn written(r: *const Recording, from: u64, to: u64) []const Span { return r.write_spans.of(from, to); } +/// The bytes they stored with the value already there (a local +/// assigned what its slot held before): no change, but an assignment. +pub fn storedSame(r: *const Recording, from: u64, to: u64) []const Span { + return r.store_spans.of(from, to); +} + /// The bytes they read. pub fn read(r: *const Recording, from: u64, to: u64) []const Span { return r.read_spans.of(from, to); diff --git a/anim/src/array.zig b/anim/src/array.zig index 9adc132..d9216c3 100644 --- a/anim/src/array.zig +++ b/anim/src/array.zig @@ -80,7 +80,7 @@ pub const Array = struct { const first = v.addr & ~@as(u64, 15); const dump = hexdump.panel(f, at, g.stage, u.print("{x} to {x}, an element a run", .{ v.addr, v.addr + v.size - 1 }), &.{}); const rows_n = @min(dump.rows, (v.addr + v.size - first + 15) / 16); - if (rows_n > 0) hexdump.draw(dump.u, now, 0, m.tag + m.pad, first, rows_n, .{ .array = .{ .addr = v.addr, .len = v.size, .elem = @intCast(elem) }, .region = context.ink(context.regionOf(moment, v.addr)) }); + if (rows_n > 0) hexdump.draw(dump.u, now, 0, m.tag + m.pad, first, rows_n, .{ .array = .{ .addr = v.addr, .len = v.size, .elem = @intCast(elem), .type = elem_type }, .region = context.ink(context.regionOf(moment, v.addr)) }); dump.veil(now); u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); } @@ -223,7 +223,8 @@ pub const Array = struct { } if (names.items.len == 0) continue; var x = cx; - if (slide[k]) |from| x = std.math.lerp(left + (from + 0.5) * cell[0], x, cursors.standard(now.moving(.idea, 0, time.move))); + // A pin's travel (`time.pin`): to the next cell, or farther. + if (slide[k]) |from| x = std.math.lerp(left + (from + 0.5) * cell[0], x, cursors.standard(now.moving(.idea, 0, if (@abs(from - @as(f32, @floatFromInt(k))) <= 1) time.pin.node else time.pin.nodes))); // An index lives on the stack: its name in stack's ink; a register's primary. var inks: [8]u24 = @splat(t.primary); for (inks[0..@min(indices, inks.len)]) |*i_ink| i_ink.* = theme.color.region.stack; diff --git a/anim/src/calls.zig b/anim/src/calls.zig index 0765ce4..5eef946 100644 --- a/anim/src/calls.zig +++ b/anim/src/calls.zig @@ -20,10 +20,6 @@ const time = theme.time; const Rect = ui.Rect; const t = theme.color.text; -/// A return's follow-through: its frame leaves the backtrace as the idea -/// strikes, and the tree's badge is struck this long after. -const badge_after = 0.20; - pub const Tree = struct { cursor: Cursor, stage: *const Stage, @@ -54,7 +50,7 @@ pub const Tree = struct { const top = body.y + m.root; const since = now.since(.idea, 0); const returned = now.walking() and rec.depths[now.stops[0]] < rec.depths[now.stops[1]]; - const moment = if (now.plan.gait == .sprint or since >= (if (returned) @as(f32, badge_after) else 0)) now.stops[0] else now.stops[1]; + const moment = if (now.plan.gait == .sprint or since >= (if (returned) @as(f32, time.badge_after) else 0)) now.stops[0] else now.stops[1]; const edge = cursors.standard(now.moving(.idea, time.quick, time.quick)); const appears = now.moving(.idea, 0, time.snap); const at_of = struct { @@ -124,7 +120,7 @@ pub const Tree = struct { if (active) continue; // Done: what it returned, on its shoulder; struck as it lands. const badge: Rect = .{ .x = c[0] + m.badge_at[0], .y = c[1] - m.badge_at[1], .w = m.badge, .h = m.badge }; - const heat: ui.Heat = if (n.call.exit.? > now.stops[1]) now.heat(0, null, since - badge_after) else .none; + const heat: ui.Heat = if (n.call.exit.? > now.stops[1]) now.heat(0, null, since - time.badge_after) else .none; const ink = u.cellWritten(badge, heat, theme.color.page); if (heat.level < 1) u.frame(badge, t.faint, theme.stroke.rule); u.label(ink.face, size, badge, .center, u.print("{d}", .{@as(i64, @bitCast(n.call.result))}), if (heat.level >= 1) ink.ink else ui.rgb(t.primary)); @@ -173,17 +169,8 @@ pub fn arguments(u: ui.Ui, rec: *const Recording, c: Recording.Call) []const u8 return u.print("{s}={d}", .{ name, @as(i64, @bitCast(arg)) }); } -/// The tree's measures (design/README.md, `calls`): a disc 48 across, -/// levels 46 apart, the root 48 under the tag; the result's square of 30 -/// on the shoulder, 12 right of the centre and 42 up; the caller's box. -const metric = struct { - const radius = 24; - const level = 46; - const root = 48; - const badge = 30; - const badge_at = [2]f32{ 12, 42 }; - const caller = [2]f32{ 64, 28 }; -}; +/// The tree's measures (design/README.md, `calls`): full size. +const metric = theme.metric.calls; pub const Node = struct { call: Recording.Call, diff --git a/anim/src/context.zig b/anim/src/context.zig index 7740792..9874cd7 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -106,8 +106,10 @@ pub const Registers = struct { fn rip(r: *const Registers, u: ui.Ui, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { const rec = r.cursor.rec; const moment = now.marks[if (now.advancing() >= 0.5) 1 else 0]; - // The flags' ticks are secondary: 6 f after the registers strike, not with them. - const landed = now.landed(.cpu, cursors.write_apart); + // The flags' ticks are secondary: 6 f after the registers strike, + // not with them; in a continue's wave, in its place after r15. + const delay = if (now.plan.wave) ties.strikeDelay(now, index("eflags").?) else cursors.write_apart; + const landed = now.landed(.cpu, delay); const flags = (if (landed) is else was).regs.eflags; // The flags a step changed are ticked, for three steps. const eflags_index = comptime index("eflags").?; @@ -115,7 +117,7 @@ pub const Registers = struct { const age = if (landed) now.registerAge(eflags_index) else now.registerAgeFrom(eflags_index, 1); var changed: u64 = 0; if (age) |a| changed = rec.register(now.stops[a], "eflags") ^ rec.register(now.stops[a + 1], "eflags"); - const held = if (r.quiet) 0 else now.register(eflags_index, cursors.write_apart).level; + const held = if (r.quiet) 0 else now.register(eflags_index, delay).level; rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0); } @@ -300,12 +302,12 @@ pub const Stack = struct { const held = hold >= 0; const held_at: u64 = if (held) rec.register(@intFromFloat(hold), "rsp") -% 8 * @as(u64, @intFromFloat(placed.value(k.stage.hold_free))) else 0; var window = if (held) [2]u64{ held_at, held_at } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) }; - // A window that goes further than its rows can slide (a continue - // to a stop deeper or shallower than a call is): the old rows fade - // out before memory strikes and the new ones in after, each with - // the memory of its own stop. + // A window that goes farther than its own height (a continue to a + // stop deeper or shallower than a call is) does not scroll: the old + // rows fade out before memory strikes and the new ones in after, + // each with the memory of its own stop. const landed = now.landed(.memory, 0); - const jumped = @abs(@as(f32, @floatFromInt(@as(i64, @bitCast(window[0] -% window[1])))) / 8) > 16; + const jumped = far(window[0], window[1], slots); const since_memory = now.since(.memory, 0); const jump_shows: f32 = if (!jumped or now.resting()) 1 else if (!landed) 1 - std.math.clamp((since_memory + time.quick) / time.quick, 0, 1) else std.math.clamp((since_memory - time.strike.in / 2.0) / time.quick, 0, 1); if (jumped) window = if (landed) .{ window[0], window[0] } else .{ window[1], window[1] }; @@ -328,11 +330,12 @@ pub const Stack = struct { 8 => "eight", else => u.print("{d}", .{slots}), }; - const range = if (from_rsp == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, from_rsp), offset(u, from_rsp + 8 * @as(i64, @intCast(slots))) }); + // The first word shown and the last. + const range = if (from_rsp == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, from_rsp), offset(u, from_rsp + 8 * (@as(i64, @intCast(slots)) - 1)) }); const body = u.panel(box.w, box.h, "stack", .{ .focus = k.focus, .note = u.print("{s} \u{00b7} the frames they belong to", .{range}) }); const p = cursors.glide(now.moving(.memory, 0, time.move)); const moved = @as(f32, @floatFromInt(@as(i64, @bitCast(window[0] -% window[1])))) / 8; - const slide: f32 = (if (@abs(moved) > 16) 0 else moved * (1 - p)) + hold_scroll; + const slide: f32 = (if (jumped) 0 else moved * (1 - p)) + hold_scroll; const top = body.y + m.pad; clipBody(u, box); defer u.unclip(); @@ -341,6 +344,11 @@ pub const Stack = struct { const shown_at = if (landed) window[0] else window[1]; const lead = ui.shared(&.{ shown_at, shown_at + 8 * @as(u64, slots) }); const memory = now.shown(.memory); + // Marks only for what the viewer saw change: the steps since the + // window last faded to its place (none on a window that has just + // faded in; the ticks it had on its way out). + const watched_from: usize = if (jumped and !landed) 1 else 0; + const watched_to = if (held) now.stops.len else watched(now, slots, watched_from); // rsp and rbp, moved by the step with no link to land: their tags // travel down the lane from the old word to the new, with the slide. var travel_buf: [2][]const u8 = undefined; @@ -381,8 +389,19 @@ pub const Stack = struct { n_spans += 1; } // rsp or rbp travelling alone keeps its place in the pin it leaves and - // the one it joins: room there, closing and opening as it goes. - const going = cursors.standard(if (now.resting()) 1 else std.math.clamp(now.since(.cpu, ties.strikeDelay(now, index("rsp").?)) / time.move, 0, 1)); + // the one it joins: room there, closing and opening as it goes. It + // sets off 18 f after rsp's strike (`time.pin`): 24 f to the next + // row, 2 f a further row, 36 f at most. + const goes = struct { + fn of(n: cursors.Now, a: zt.Regs, b: zt.Regs, name: []const u8) f32 { + if (n.resting()) return 1; + const pin = time.pin; + const rows_far: f32 = @floatFromInt(@abs(@as(i64, @bitCast((b.named(name) orelse 0) -% (a.named(name) orelse 0)))) / 8); + const takes = @min(pin.row + pin.step_per_row * @max(rows_far - 1, 0), pin.row_max); + // rsp's strike sets both off: rbp, struck first, goes with it. + return cursors.standard(std.math.clamp((n.since(.cpu, ties.strikeDelay(n, index("rsp").?)) - pin.after) / takes, 0, 1)); + } + }.of; const size = theme.size.mono.context; const lone: ?[]const u8 = if (travel.len == 1) travel[0] else null; var n: i64 = @as(i64, @intFromFloat(@floor(-slide))) - 1; @@ -392,8 +411,8 @@ pub const Stack = struct { const addr = window[0] +% @as(u64, @bitCast(n * 8)); // Who points here: a pin in the lane, landing with its link. const names = pins(u, now, is, was, addr, travel); - var marks: rows.Marks = .{ .lead = lead, .first = now.written(addr, 8, .memory, 0) }; - if (now.wasRead(addr, 8) and now.writeAge(addr, 8) != 0) { + var marks: rows.Marks = .{ .lead = lead, .first = now.writtenWatched(addr, 8, .memory, 0, watched_from, watched_to) }; + if (watched_from == 0 and watched_to > 0 and now.wasRead(addr, 8) and now.writeAge(addr, 8) != 0) { marks.read = 0; marks.read_shows = now.reading(.memory, 0); } @@ -410,6 +429,7 @@ pub const Stack = struct { } var gap: f32 = 0; if (lone) |name| { + const going = goes(now, was, is, name); const share: f32 = if (was.named(name) == addr) 1 - going else if (is.named(name) == addr) going else 0; gap = share * (u.width(.mono, size, name) + ui.advance(size)); } @@ -431,14 +451,14 @@ pub const Stack = struct { for (travel, places[0..travel.len]) |name, *place| { const at_old = @as(f32, @floatFromInt(@as(i64, @bitCast((was.named(name) orelse 0) -% window[0])))) / 8 + slide; const at_new = @as(f32, @floatFromInt(@as(i64, @bitCast((is.named(name) orelse 0) -% window[0])))) / 8 + slide; - place.* = std.math.lerp(at_old, at_new, going); + place.* = std.math.lerp(at_old, at_new, goes(now, was, is, name)); } for (travel, places[0..travel.len], 0..) |name, place, i| { if (i == 1 and @abs(places[0] - place) < 0.05) continue; if (place < -0.5 or place > @as(f32, @floatFromInt(slots)) - 0.5) continue; const both = i == 0 and travel.len == 2 and @abs(places[1] - place) < 0.05; // Alone, from its place among the names it leaves to its place among those it joins. - const x = if (lone != null) std.math.lerp(pinPlace(u, pins(u, now, is, was, was.named(name) orelse 0, travel).names, name), pinPlace(u, pins(u, now, is, was, is.named(name) orelse 0, travel).names, name), going) else theme.metric.slot.lane; + const x = if (lone != null) std.math.lerp(pinPlace(u, pins(u, now, is, was, was.named(name) orelse 0, travel).names, name), pinPlace(u, pins(u, now, is, was, is.named(name) orelse 0, travel).names, name), goes(now, was, is, name)) else theme.metric.slot.lane; u.pinRow(x, top + place * m.row, if (both) &.{ "rsp", "rbp" } else &.{name}, theme.color.region.stack); } for (spans[0..n_spans]) |sp| rows.span(v, box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); @@ -475,6 +495,24 @@ pub const Stack = struct { sk.draw.polygon(u.f, &.{ .{ hx + p.row_head[0], mid }, .{ hx, mid - p.row_head[1] / 2 }, .{ hx, mid + p.row_head[1] / 2 } }, u.at.pen(.{ .fill = ui.rgb(theme.color.region.stack) })); } + /// Whether a window of `slots` going from word `a` to word `b` goes + /// farther than its own height: it fades, and does not scroll. + fn far(a: u64, b: u64, slots: usize) bool { + return @abs(@as(i64, @bitCast(a -% b))) > 8 * @as(u64, slots); + } + + /// The first step, from `age` steps ago back, in which the window faded + /// to a new place (as many as the cursor remembers when none did). + fn watched(now: cursors.Now, slots: usize, age: usize) usize { + const rec = now.rec; + for (age..now.stops.len - 1) |a| { + const to = (rec.moment(now.stops[a]).regs(rec.tid) catch null) orelse return a; + const from = (rec.moment(now.stops[a + 1]).regs(rec.tid) catch null) orelse return a; + if (far(windowAt(now, to, slots, a), windowAt(now, from, slots, a + 1), slots)) return a; + } + return now.stops.len; + } + /// The first word a window of `slots` shows, `skip` steps back: rsp, /// or within [rsp, rbp+16) (the frame, with its saved rbp and its way /// back) so that the word the newest of the last three steps wrote or @@ -531,11 +569,13 @@ pub const Backtrace = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + /// The `backtrace` lens: in the band, as its drawing. + lens: bool = false, pub fn draw(b: *const Backtrace, f: *sk.Frame, placed: anim.Placed) void { - const box = b.stage.box(placed, .backtrace); + const box = b.stage.box(placed, if (b.lens) .band else .backtrace); if (box.h < m.tag) return; - const u = at(f, placed, box); + const u = if (b.lens) at(f, placed, box).faded(placed.value(b.stage.drawing)) else at(f, placed, box); const now = b.cursor.now(placed); const rec = b.cursor.rec; // A frame is its words on the stack: the chain changes with memory. diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index ec05ec0..f196fab 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -78,6 +78,8 @@ pub const Plan = struct { travel: f32 = time.step, /// The whole step: the advance, then a rest in which the next line is read. total: f32 = time.fire + time.step + time.rest, + /// A `continue`: the registers strike in a wave, no arm and no pulse. + wave: bool = false, /// Once the pattern is known: the levels a stagger apart from the /// first frame, the mark after them, in `seconds`. @@ -106,7 +108,7 @@ pub const Cursor = struct { /// 0 to 1 through the step it is taking; 1 at rest. phase: anim.Value, /// The step's `Plan`, a value a field. - plan: [7]anim.Value, + plan: [8]anim.Value, /// The moment the current mark was on, and the one it is on (or going to). marks: [2]anim.Value, /// 1 while steps are hurried (the head counts them), and while what @@ -132,7 +134,7 @@ pub const Cursor = struct { .rec = rec, .stops = undefined, .phase = s.value(1), - .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total) }, + .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0) }, .marks = .{ s.value(here), s.value(here) }, .hurried = s.value(0), .veil = s.value(0), @@ -172,16 +174,16 @@ pub const Cursor = struct { /// sentence said faster). pub fn step(c: Cursor, s: *anim.Frame, to: u64, plan: Plan, seconds: f32) void { const from = c.moment(s); - var set: [history + 11]anim.Animation = undefined; + var set: [history + 12]anim.Animation = undefined; for (1..history) |i| set[i] = c.stops[i].to(settled(s, c.stops[i - 1])); set[0] = c.stops[0].to(@floatFromInt(to)); - for (c.plan, [_]f32{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total }, history..) |value, is, n| set[n] = value.to(is); + for (c.plan, [_]f32{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)) }, history..) |value, is, n| set[n] = value.to(is); // At a sprint the mark is seen only where a phrase ends. const was = settled(s, c.marks[1]); - set[history + 7] = c.marks[0].to(was); - set[history + 8] = c.marks[1].to(if (plan.gait == .sprint and !c.phraseEnds(from, to)) was else @floatFromInt(to)); - set[history + 9] = c.phase.to(0); - set[history + 10] = c.count.to(settled(s, c.count) + 1); + set[history + 8] = c.marks[0].to(was); + set[history + 9] = c.marks[1].to(if (plan.gait == .sprint and !c.phraseEnds(from, to)) was else @floatFromInt(to)); + set[history + 10] = c.phase.to(0); + set[history + 11] = c.count.to(settled(s, c.count) + 1); s.play(set, .{ .seconds = 0 }); s.play(.{c.phase.to(1)}, .{ .seconds = seconds, .ease = anim.ease.linear }); } @@ -207,6 +209,24 @@ pub const Cursor = struct { /// advance; a rest. A line and no more comes to 0.8 s, one value to /// 1.5, a register and memory to 2.0, a call through three levels 2.5. pub fn reading(c: Cursor, from: u64, to: u64) Plan { + return c.timetable(from, to, false); + } + + /// `continue`: straight to a stop far from this one (a breakpoint, not + /// a step). The line it leaves fires; the registers it changed strike + /// in a wave, 2 f apart in pwndbg's order, the fill in over 6 f, no arm + /// and no pulse (a dozen arms at once are a crowd, a dozen pulses a + /// flash); memory 18 f after the last of them (the stack's window + /// scrolls or fades to its place, the backtrace's frames leave, slide + /// and arrive), then the idea; a hold of 36 f after the last strike; + /// the advance, the mark out and in (6 f each), the source fading + /// through first if it goes farther than its window; a rest. + pub fn @"continue"(c: Cursor, s: *anim.Frame, to: u64) void { + const plan = c.timetable(c.moment(s), to, true); + c.step(s, to, plan, plan.total); + } + + fn timetable(c: Cursor, from: u64, to: u64, wave: bool) Plan { const rec = c.rec; const regs: f32 = @floatFromInt(@popCount(rec.registersChanged(from, to) & ~quiet)); // Memory gives up its slot when nothing it touched is drawn. @@ -227,7 +247,7 @@ pub const Cursor = struct { .data => touched, }, }; - var plan: Plan = .{ .travel = c.travel(from, to) }; + var plan: Plan = .{ .travel = c.travel(from, to, wave), .wave = wave }; var slot: f32 = 0; for (levels, &plan.at, 0..) |is, *strikes, level| { // A drawing made of the bytes reacts when the projection from @@ -236,6 +256,8 @@ pub const Cursor = struct { const projected = level == 2 and is and levels[1] and (c.levels.idea == .data or deeper); if (projected) slot += time.project.bracket + @as(f32, if (c.levels.idea == .data) time.project.draw else time.project.far) + @as(f32, if (wrote > 0 and c.levels.idea == .data) time.strike.arm else 0) else if (is) slot += time.cascade; strikes.* = @max(slot, time.cascade); + // A wave's last register strikes 2 f a register after its first: the next level is 18 f after that. + if (wave and level == 0 and is) slot += (regs - 1) * time.continue_wave; } // The writes of one step strike 6 f apart: the last is later. if (levels[1]) slot += @min(@max(wrote - 1, 0), 3) * write_apart; @@ -251,19 +273,21 @@ pub const Cursor = struct { .calls => if (back) time.returning else time.snap, .data => c.levels.follow, }; - plan.advance = slot + follow + @min(time.read_value + time.read_more * (values - 1), time.read_most); + // A continue's hold is 36 f: what it changed is too much to read value by value. + plan.advance = slot + follow + if (wave) time.read_value else @min(time.read_value + time.read_more * (values - 1), time.read_most); } plan.total = plan.advance + plan.travel + time.rest; return plan; } /// How long the mark takes to the next line: a slide by how far, or a - /// jump (out, then in) into or out of a call, or further than a few rows. - fn travel(c: Cursor, from: u64, to: u64) f32 { + /// jump (out, then in) into or out of a call, further than a few rows, + /// or at the end of a continue (`wave`). + fn travel(c: Cursor, from: u64, to: u64, wave: bool) f32 { const rec = c.rec; // The source's window moves with it: by whole lines, and never a cut. if (rec.viewFirst(c.levels.source_rows, rec.own[from]) != rec.viewFirst(c.levels.source_rows, rec.own[to])) return time.move; - if (jumps(rec, from, to)) return 2 * time.current_jump; + if (wave or jumps(rec, from, to)) return 2 * time.current_jump; const rows: f32 = @floatFromInt(@max(rec.own[from], rec.own[to]) - @min(rec.own[from], rec.own[to])); return @min(time.step + time.step_per_row * @max(rows - 1, 0), time.step_max); } @@ -346,6 +370,7 @@ pub const Cursor = struct { .advance = placed.value(c.plan[4]), .travel = placed.value(c.plan[5]), .total = placed.value(c.plan[6]), + .wave = placed.value(c.plan[7]) >= 0.5, }, .marks = .{ whole(rec, placed.value(c.marks[0])), whole(rec, placed.value(c.marks[1])) }, .hurried = placed.value(c.hurried), @@ -587,6 +612,14 @@ pub const Now = struct { return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay + n.writeDelay(addr, size))); } + /// `written`, on a thing the viewer has watched only through the steps + /// `lo` to `hi` ago (a window that faded to its place, a view that came + /// in after its step): what changed in any other step is plain. + pub fn writtenWatched(n: Now, addr: u64, size: u64, level: Level, delay: f32, lo: usize, hi: usize) ui.Heat { + const age = n.writeAge(addr, size) orelse return .none; + return if (age >= lo and age < hi) n.written(addr, size, level, delay) else .none; + } + /// How far after this step's first write the one of `addr .. addr + size` is. pub fn writeDelay(n: Now, addr: u64, size: u64) f32 { var order: f32 = 0; @@ -600,9 +633,14 @@ pub const Now = struct { return 0; } - /// The mark of a register: the CPU's level. + /// The mark of a register: the CPU's level. In a continue's wave, no arm and no pulse. pub fn register(n: Now, reg: usize, delay: f32) ui.Heat { - return n.heat(n.registerAge(reg), n.registerAgeFrom(reg, 1), n.since(.cpu, delay)); + var h = n.heat(n.registerAge(reg), n.registerAgeFrom(reg, 1), n.since(.cpu, delay)); + if (n.plan.wave) { + h.arm = 0; + h.out = 0; + } + return h; } /// How much (0 to 1) the frame round a thing this step read shows: in diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 6faaade..6c28516 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -158,11 +158,9 @@ pub const Disasm = struct { }; var last_line: ?u32 = null; - // A source of many lines (SQLite's) has wider numbers: what is - // right of them moves right by as much. - var widest: u32 = 0; - for (merged) |row| widest = @max(widest, row.line orelse 0); - const widen = rows.numberRoom(widest); + // A source of many lines (SQLite's) has wider numbers, as wide as + // its largest: what is right of them moves right by as much. + const widen = rows.numberRoom(rec.line_count); // The thread's runs: of the line the mark leaves and of the one it // goes to, each a span of rows; published sliding from the one to // the other with the advance (`threadRuns`). diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index b98d9bd..fba212d 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -1,11 +1,12 @@ //! `hexdump` (design/README.md, "3. Panels"): memory as `bytes` rows, //! sixteen a row, the right half of a lens: the pane its drawing is a view //! of. A window of the region kept round the rows the step touches (five -//! beside, nine as the subject), in address order; a gap in the addresses +//! beside, seven as the subject), in address order; a gap in the addresses //! is one row of `more`'s dots and the count left out. Each row's runs //! come from the types of what the program's pointers reach: a field's -//! bytes on raised paper in its ink, the allocator's dim, never read two -//! dots; and its reading at 640: what the runs read as, little-endian. +//! bytes on raised paper in its ink, `loose` ones (the allocator's, a +//! struct's padding) dim, never read two dots; and its reading at 640: +//! what the runs read as, a list a character apart. //! Bytes a step wrote are struck here before the drawing reacts. //! Reads `Moment.read`, `Moment.allocation`, and the recording's types. const std = @import("std"); @@ -23,22 +24,23 @@ const b = theme.metric.bytes; const adv = theme.size.mono.context * 3 / 5; /// What a word of the region is. -pub const Kind = enum { number, pointer, allocator, unread }; +pub const Kind = enum { number, pointer, loose, unread }; -/// The kind of the word at `addr`: a field of a struct the program's -/// pointers reach (by its type), other allocated bytes, the allocator's -/// own between allocations, or never observed. -pub fn kindOf(things: []const objects.Object, moment: Recording.Moment, addr: u64) Kind { +/// The kind of the word at `addr`, and its type where a field's is known: +/// a field of a struct the program's pointers reach (by its type), other +/// allocated bytes, `loose` (the allocator's own between allocations), or +/// never observed. +pub fn kindOf(things: []const objects.Object, moment: Recording.Moment, addr: u64) struct { Kind, ?Recording.types.Type } { for (things) |o| { if (!o.holds(addr)) continue; - for (o.type.record.fields) |field| if (o.addr + field.offset == addr) return if (field.type == .pointer) .pointer else .number; - return .number; + for (o.type.record.fields) |field| if (o.addr + field.offset == addr) return .{ if (field.type == .pointer) .pointer else .number, field.type }; + return .{ .number, null }; } var bytes: [8]u8 = undefined; var known: [8]bool = undefined; - moment.read(addr, &bytes, &known) catch return .unread; - if (std.mem.indexOfScalar(bool, &known, true) == null) return .unread; - return if ((moment.allocation(addr) catch null) != null) .number else .allocator; + moment.read(addr, &bytes, &known) catch return .{ .unread, null }; + if (std.mem.indexOfScalar(bool, &known, true) == null) return .{ .unread, null }; + return .{ if ((moment.allocation(addr) catch null) != null) .number else .loose, null }; } /// The rows of a region (`lo .. hi`, sixteen-aligned) a dump of `count` @@ -57,10 +59,11 @@ pub fn window(now: cursors.Now, lo: u64, hi: u64, count: usize) u64 { } /// What a dump is of: the structs a drawing beside it draws, or an array -/// of numbers (an element a run), and the ink of the memory it is in. +/// of numbers (an element a run, read as its type), and the ink of the +/// memory it is in. pub const Of = struct { things: []const objects.Object = &.{}, - array: ?struct { addr: u64, len: u64, elem: u8 } = null, + array: ?struct { addr: u64, len: u64, elem: u8, type: ?Recording.types.Type = null } = null, region: u24 = theme.color.region.heap, }; @@ -93,6 +96,9 @@ pub const Dump = struct { legend: []const ui.Legend = &.{}, of: Fields, marks: []const @import("anim").Value = &.{}, + /// The stop it comes in at: what changed before then, the viewer did + /// not see change, and it is plain. + since: u64 = 0, pub fn draw(d: *const Dump, f: *@import("sketch").Frame, placed: @import("anim").Placed) void { const v = panel(f, placed, d.stage, d.about, d.legend); @@ -100,6 +106,8 @@ pub const Dump = struct { if (v.rows == 0) return; const now = d.cursor.now(placed); var of = d.of; + of.watched = 0; + while (of.watched + 1 < now.stops.len and now.stops[of.watched + 1] >= d.since) of.watched += 1; var shows: [8]f32 = @splat(0); const marked = @min(d.marks.len, shows.len); for (d.marks[0..marked], shows[0..marked]) |mark, *value| value.* = placed.value(mark); @@ -144,6 +152,8 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize const v = u.moved(x, 0); const moment = now.shown(.memory); const lead = ui.shared(&.{ first, first + 16 * @as(u64, count -| 1) }); + // Room for the addresses, once for the dump: by its widest. + const shift = rows.addressRoom(first + 16 * @as(u64, count -| 1)); for (0..count) |i| { const addr = first + 16 * i; const ry = y + @as(f32, @floatFromInt(i)) * m.row; @@ -151,15 +161,18 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize var known: [16]bool = undefined; moment.read(addr, &values, &known) catch return; var runs: [16]rows.Run = undefined; + var readings: [16]Field = undefined; var n: usize = 0; var holds_drawn = false; var at: u64 = 0; while (at < 16) { const here = addr + at; var run: rows.Run = .{ .first = @intCast(at), .len = 8, .kind = .unread }; + var kind: ?Recording.types.Type = null; if (of.array) |arr| if (here >= arr.addr and here < arr.addr + arr.len) { run.len = arr.elem; run.kind = .number; + kind = arr.type; holds_drawn = true; }; if (run.kind == .unread) { @@ -168,10 +181,11 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize if (of.array) |arr| if (here < arr.addr and arr.addr < here + run.len) { run.len = @intCast(arr.addr - here); }; - run.kind = switch (kindOf(of.things, moment, here)) { + const word, kind = kindOf(of.things, moment, here); + run.kind = switch (word) { .number => .number, .pointer => .pointer, - .allocator => .allocator, + .loose => .loose, .unread => .unread, }; for (of.things) |o| if (o.holds(here)) { @@ -180,51 +194,23 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize } run.heat = now.written(here, run.len, .memory, 0); if (now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) run.read = now.reading(.memory, 0); - if (run.kind == .number or run.kind == .pointer) ties.anchor(v, .{ .dump_run = here }, .{ .x = rows.byteX(run.first) - 4, .y = ry, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row }); + if (run.kind == .number or run.kind == .pointer) ties.anchor(v, .{ .dump_run = here }, .{ .x = shift + rows.byteX(run.first) - 4, .y = ry, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row }); + readings[n] = .{ .at = run.first, .len = run.len, .reads = switch (run.kind) { + .number => .number, + .pointer => .pointer, + else => .bytes, + }, .type = kind }; runs[n] = run; n += 1; at += run.len; } - rows.bytes(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment); - reading(v, ry, addr, moment, &values, &known, runs[0..n]); - } -} - -/// The reading: what the runs read as, little-endian. A number ranged -/// right in three characters; a pointer as `points` and its address; -/// `NULL` dim; an allocator's run as a note, faint. -fn reading(u: ui.Ui, y: f32, addr: u64, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, runs: []const rows.Run) void { - const size = theme.size.mono.context; - const base = rows.baseline(y); - var x: f32 = b.reading; - for (runs) |run| { - var bytes: [8]u8 = @splat(0); - @memcpy(bytes[0..run.len], values[run.first..][0..run.len]); - const word = std.mem.readInt(u64, &bytes, .little); - const whole = std.mem.indexOfScalar(bool, known[run.first..][0..run.len], false) == null; - if (!whole) continue; - switch (run.kind) { - .number => { - // A field typed a number reads as its decimal. - const shift: u6 = @intCast(64 - 8 * @as(u32, @min(run.len, 8))); - const digits = u.print("{d}", .{@as(i64, @bitCast(word << shift)) >> shift}); - const w = @as(f32, @floatFromInt(digits.len)) * adv; - u.text(.mono, size, x + @max(3 * adv - w, 0), base, digits, t.primary); - x += @max(3 * adv, w) + 8; - }, - .pointer => if (word == 0) { - u.text(.mono, size, x + theme.metric.context.arrow_w, base, "NULL", t.dim); - x += theme.metric.context.arrow_w + 4 * adv + 8; - } else { - x = u.arrow(x, y + m.row / 2, .points); - x = u.address(x, base, word, .{ .ink = ui.rgb(rows.ink(rows.regionOf(moment, word))) }) + 8; - }, - .allocator => if (run.first == 8 and run.len == 8 and chunkAfter(moment, addr + 8)) { - // The size word of the chunk after: malloc's. - u.text(.sans, theme.size.sans.micro, x, base - 1, u.print("malloc's: a chunk of {d}", .{word & ~@as(u64, 7)}), t.faint); - return; - }, - .text, .unread => {}, + rows.bytesAt(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment, shift); + const end = reading(v, ry, shift, moment, &values, &known, readings[0..n]); + // The size word of the chunk after: malloc's, a note after the reading. + const last = runs[n - 1]; + if (last.kind == .loose and last.first == 8 and last.len == 8 and std.mem.indexOfScalar(bool, known[8..], false) == null and chunkAfter(moment, addr + 8)) { + const size = std.mem.readInt(u64, values[8..16], .little) & ~@as(u64, 7); + v.text(.sans, theme.size.sans.micro, end, rows.baseline(ry) - 1, v.print("malloc's: a chunk of {d}", .{size}), t.faint); } } } @@ -251,6 +237,9 @@ pub const Field = struct { big: bool = false, /// Which of the view's marks frames it as read (`Fields.marks`). mark: ?u8 = null, + /// A number's type, where the debug info gives it: read as the lens's + /// values are (`objects.reading`: a `char` quoted, a `bool` by name). + type: ?Recording.types.Type = null, }; /// What a dump of fields is of, and how it is marked now. @@ -272,46 +261,108 @@ pub const Fields = struct { /// pointer leads, 32 bytes at a stop; elsewhere its last seen bytes may /// be long out of date, and are drawn as not seen. seen: ?Recording.Span = null, + /// How many of the newest steps it has been on screen through: only + /// their changes are marked. + watched: usize = std.math.maxInt(usize), }; /// The region's rows in view `v`, from `y`, sixteen bytes a row from its /// first byte: those that hold a field (all of them, where they fit), and /// for a stretch left out one row of `more`'s dots and how many rows it -/// stands for. A field is a run, cut where a row ends; a byte that is no -/// field is drawn as the allocator's (dim, no paper) and reads as nothing. +/// stands for. More rows of fields than the window: it is kept round the +/// first row a mark or the step is on, and the others are `more` rows too. +/// A field is a run, cut where a row ends; a byte that is no field is +/// `loose` (dim, no paper) and reads as nothing. pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { const u = v.u; const moment = now.shown(.memory); const total = (of.len + 15) / 16; - var shown: [16]u64 = undefined; - var n: usize = 0; - for (0..total) |r| { - const lo = of.base + 16 * r; - const holds = for (of.fields) |field| { - if (of.base + field.at < lo + 16 and of.base + field.at + field.len > lo) break true; - } else false; - if ((holds or total <= v.rows) and n < shown.len) { - shown[n] = r; - n += 1; - } - } + var held: std.ArrayList(u64) = .empty; + for (0..total) |r| if (total <= v.rows or holdsField(of, r)) held.append(u.f.scratch, r) catch return; + const all = held.items; + if (all.len == 0) return; + const range = keep(all, focus(now, of, all), v.rows, total - 1); + const shown = all[range[0]..range[1]]; const lead = ui.shared(&.{ of.base, of.base + 16 * (total -| 1) }); + // Room for the addresses, once for the dump: by the widest it shows. + const shift = rows.addressRoom(of.base + 16 * shown[shown.len - 1]); + const more = struct { + fn row(at: ui.Ui, ry: f32, count: u64) void { + const after = at.arrow(b.address, ry + m.row / 2, .more); + at.text(.mono, theme.size.mono.context, after + adv, rows.baseline(ry), at.print("{d} rows", .{count}), t.faint); + } + }.row; var ry = y; var last: ?u64 = null; - for (shown[0..n]) |r| { - if (last) |l| if (r > l + 1) { - // A stretch left out: one row, three dots and a count. - const after = u.arrow(b.address, ry + m.row / 2, .more); - u.text(.mono, theme.size.mono.context, after + adv, rows.baseline(ry), u.print("{d} rows", .{r - l - 1}), t.faint); + for (shown) |r| { + // A stretch left out: one row, three dots and a count. + const gap = if (last) |l| r - l - 1 else r; + if (gap > 0) { + more(u, ry, gap); ry += m.row; - }; + } last = r; - fieldRow(u, now, ry, of.base + 16 * r, moment, of, lead); + fieldRow(u, now, ry, of.base + 16 * r, moment, of, lead, shift); ry += m.row; } + if (shown[shown.len - 1] < total - 1) more(u, ry, total - 1 - shown[shown.len - 1]); +} + +/// Which of `rs` (rows of fields, the region's last row `last`) a window +/// of `room` rows shows: as many as fit round `rs[focus_at]`, each row a +/// line and each stretch left out (before, between, after) a `more` line. +fn keep(rs: []const u64, focus_at: usize, room: usize, last: u64) [2]usize { + const lines = struct { + fn count(all: []const u64, lo: usize, hi: usize, end: u64) usize { + var n = hi - lo + @intFromBool(all[lo] > 0) + @intFromBool(all[hi - 1] < end); + for (all[lo .. hi - 1], all[lo + 1 .. hi]) |a, b2| n += @intFromBool(b2 > a + 1); + return n; + } + }.count; + var lo = focus_at; + var hi = lo + 1; + while (true) { + const before = hi - lo; + if (hi < rs.len and lines(rs, lo, hi + 1, last) <= room) hi += 1; + if (lo > 0 and lines(rs, lo - 1, hi, last) <= room) lo -= 1; + if (hi - lo == before) break; + } + return .{ lo, hi }; +} + +test "a dump of more rows of fields than its window keeps those round its focus" { + // A page's header row, then two cells at its end: all fit in seven. + try std.testing.expectEqual([2]usize{ 0, 3 }, keep(&.{ 0, 254, 255 }, 0, 7, 255)); + // Ten rows with gaps, a window of five round the sixth: two rows, a `more` before, between and after. + const spread = [_]u64{ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 }; + try std.testing.expectEqual([2]usize{ 5, 7 }, keep(&spread, 5, 5, 18)); + // Rows next to each other, the window of five round the last: four rows and a `more` before. + const run = [_]u64{ 0, 1, 2, 3, 4, 5, 6, 7 }; + try std.testing.expectEqual([2]usize{ 4, 8 }, keep(&run, 7, 5, 7)); } -fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Moment, of: Fields, lead: usize) void { +/// Whether row `r` of the region holds a field. +fn holdsField(of: Fields, r: u64) bool { + const lo = of.base + 16 * r; + for (of.fields) |field| if (of.base + field.at < lo + 16 and of.base + field.at + field.len > lo) return true; + return false; +} + +/// Which of `rs` (rows of fields) the window is kept round: the first a +/// mark shows on, else the first the step wrote or read, else the first. +fn focus(now: cursors.Now, of: Fields, rs: []const u64) usize { + for (rs, 0..) |r, k| for (of.fields) |field| { + if (field.at >= 16 * r + 16 or field.at + field.len <= 16 * r) continue; + if (field.mark) |i| if (i < of.marks.len and of.marks[i] > 0) return k; + }; + for (rs, 0..) |r, k| { + const span: Recording.Span = .{ .addr = of.base + 16 * r, .len = 16 }; + if (Recording.touches(now.rec.written(now.stops[1], now.stops[0]), span.addr, span.len) or Recording.touches(now.rec.read(now.stops[1], now.stops[0]), span.addr, span.len)) return k; + } + return 0; +} + +fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Moment, of: Fields, lead: usize, shift: f32) void { var values: [16]u8 = undefined; var known: [16]bool = undefined; moment.read(addr, &values, &known) catch return; @@ -336,7 +387,6 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom given_from = @min(given_from, @as(u8, @intCast(i))); given_to = @max(given_to, @as(u8, @intCast(i))); }; - const shift = rows.addressRoom(addr); var runs: [16]rows.Run = undefined; var readings: [16]Field = undefined; var n: usize = 0; @@ -346,7 +396,7 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom const field = for (of.fields) |field| { if (of.base + field.at <= here and here < of.base + field.at + field.len) break field; } else null; - var run: rows.Run = .{ .first = at, .len = 1, .kind = .allocator }; + var run: rows.Run = .{ .first = at, .len = 1, .kind = .loose }; if (field) |fl| { run.len = @intCast(@min(of.base + fl.at + fl.len - here, 16 - @as(u64, at))); run.kind = switch (fl.reads) { @@ -354,14 +404,14 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom .pointer => .pointer, .text => .text, }; - run.heat = now.written(here, run.len, .memory, 0); + run.heat = now.writtenWatched(here, run.len, .memory, 0, 0, of.watched); var framed: f32 = 0; if (fl.mark) |k| if (k < of.marks.len) { framed = of.marks[k]; }; - if (now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) framed = @max(framed, now.reading(.memory, 0)); + if (of.watched > 0 and now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) framed = @max(framed, now.reading(.memory, 0)); run.read = framed; - readings[n] = .{ .at = at, .len = run.len, .reads = fl.reads, .big = fl.big }; + readings[n] = .{ .at = at, .len = run.len, .reads = fl.reads, .big = fl.big, .type = fl.type }; ties.anchor(u, .{ .dump_run = here }, .{ .x = shift + rows.byteX(run.first) - 4, .y = y, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row }); } else { // Up to the next field, or the row's end. @@ -382,33 +432,41 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom if (gives and shows > 0) { if (shows < 1) rows.bytesAt(u.faded(1 - shows), y, addr, &values, &known, runs[0..n], of.region, lead, true, moment, shift); rows.bytesAt(u.faded(shows), y, addr, &given_values, &given_known, runs[0..n], of.region, lead, true, moment, shift); - fieldReading(u.faded(shows), y, shift, moment, &given_values, &given_known, readings[0..n]); + _ = reading(u.faded(shows), y, shift, moment, &given_values, &given_known, readings[0..n]); } else { rows.bytesAt(u, y, addr, &values, &known, runs[0..n], of.region, lead, true, moment, shift); - fieldReading(u, y, shift, moment, &values, &known, readings[0..n]); + _ = reading(u, y, shift, moment, &values, &known, readings[0..n]); } } -/// The reading of a row of fields, left to right, a character apart: a -/// number in decimal, a pointer as `points` and its address, text in -/// quotes; bytes left to the eye read as nothing. Cut where the panel -/// ends, with `…`. -fn fieldReading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field) void { +/// `bytes`'s reading, for every dump: what a row's runs (`fields`, from +/// the row's first byte) read as, left to right, a character apart, from +/// 508 after the first byte (`shift` right of 640): a number in decimal, +/// in its byte order, or as its type says (`objects.reading`: a `char` +/// quoted, a `bool` by name); a pointer as `points` and its address, +/// `NULL` dim; text in quotes, C's escapes; bytes left to the eye, or +/// `loose`, as nothing. Cut where the panel ends, with `…`. Returns where +/// it ends. +pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field) f32 { const size = theme.size.mono.context; const base = rows.baseline(y); const room = theme.layout.state.w - theme.metric.context.side; var x: f32 = b.reading + shift; for (fields) |fl| { const first: usize = @intCast(fl.at); - const len: usize = @intCast(fl.len); - if (fl.reads == .bytes) continue; + // A typed number is as wide as its type (an `int` in a word: 4 bytes). + const len: usize = @intCast(if (fl.type) |ty| @min(fl.len, ty.size() orelse fl.len) else fl.len); + if (fl.reads == .bytes or len == 0) continue; if (std.mem.indexOfScalar(bool, known[first..][0..len], false) != null) continue; const bytes = values[first..][0..len]; const words: []const u8 = switch (fl.reads) { .number => blk: { var word: u64 = 0; for (0..@min(len, 8)) |k| word |= @as(u64, bytes[if (fl.big) len - 1 - k else k]) << @intCast(8 * k); - break :blk u.print("{d}", .{word}); + const ty = fl.type orelse break :blk u.print("{d}", .{word}); + const shift_bits: u6 = @intCast(64 - 8 * @as(u64, @min(len, 8))); + const signed = ty == .scalar and ty.scalar.kind == .int; + break :blk objects.reading(u.f.scratch, if (signed) @as(i64, @bitCast(word << shift_bits)) >> shift_bits else @bitCast(word), ty); }, .pointer => blk: { var word: u64 = 0; @@ -427,9 +485,10 @@ fn fieldReading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: const shown = if (fits) words else rows.fitted(u, words, room - x); const ink = if (fl.reads == .text) theme.color.string else if (std.mem.eql(u8, words, "NULL")) t.dim else t.primary; u.text(.mono, size, x, base, shown, ink); - if (!fits) return; + if (!fits) return room; x += w + adv; } + return x; } /// Bytes as C text, in quotes: the printable as they are, the rest by C's diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig index 1f8acec..d5c7613 100644 --- a/anim/src/nodes.zig +++ b/anim/src/nodes.zig @@ -223,8 +223,8 @@ pub const Nodes = struct { } /// Where variable `name`'s tag is: it travels from node to node in the - /// drawing's slot, after its word has been struck (`glide`, 30 f to the - /// next node, 36 f further); it does not jump. + /// drawing's slot, as the idea strikes, after its word has been struck + /// (`glide`, `time.pin`: 30 f to the next node, 36 f further); it does not jump. fn tagOf(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) Tag { const rec = g.cursor.rec; const at = struct { @@ -237,7 +237,7 @@ pub const Nodes = struct { const to = at.value(rec, u.f.scratch, now.moment(), name); const from = at.value(rec, u.f.scratch, now.before(), name); if (from == to or now.resting()) return .{ .from = from, .to = to, .p = 1 }; - const far: f32 = if (from != 0 and to != 0 and @abs(@as(i64, @bitCast(to -% from))) > 0x30) time.flight.mid else time.flight.near; + const far: f32 = if (from != 0 and to != 0 and @abs(@as(i64, @bitCast(to -% from))) > 0x30) time.pin.nodes else time.pin.node; const p = switch (now.plan.gait) { .walk => std.math.clamp(now.since(.idea, 0) / far, 0, 1), .run => now.moving(.idea, 0, time.run_ease), @@ -269,10 +269,10 @@ pub const Nodes = struct { const x = std.math.lerp(a.?.x + a.?.w / 2, b.?.x + b.?.w / 2, cursors.glide(tag.p)); u.pinUnderInked(x, a.?.y + a.?.h, names, inks, heap, label); } else if (b) |r| { - const p = std.math.clamp(tag.p / (time.quick / time.flight.near), 0, 1); + const p = std.math.clamp(tag.p / (time.pin.in / time.pin.node), 0, 1); u.faded(p).pinUnderInked(r.x + r.w / 2, r.y + r.h + (1 - p) * theme.time.caption_rise, names, inks, heap, label); } else if (a) |r| { - u.faded(1 - std.math.clamp(tag.p / (time.quick / time.flight.near), 0, 1)).pinUnderInked(r.x + r.w / 2, r.y + r.h, names, inks, heap, label); + u.faded(1 - std.math.clamp(tag.p / (time.pin.out / time.pin.node), 0, 1)).pinUnderInked(r.x + r.w / 2, r.y + r.h, names, inks, heap, label); } } } @@ -312,7 +312,30 @@ pub const Nodes = struct { inks.append(u.f.scratch, t.primary) catch break; shows = @max(shows, this); }; - // Names keep their side: one left alone where it was on the right stays there. + // Names keep their side: the first to come is on the left, the next + // on the right, and a name that lands where another is stays on the + // right it travelled on; one left alone where it was on the right stays there. + const came = u.f.scratch.alloc(u64, out.items.len) catch return .{ .names = out.items, .inks = inks.items, .shows = shows }; + for (out.items, came) |name, *at| at.* = g.arrival(u, now, name, addr); + for (1..@max(out.items.len, 1)) |i| { + var k = i; + while (k > 0 and came[k - 1] > came[k]) : (k -= 1) { + std.mem.swap(u64, &came[k - 1], &came[k]); + std.mem.swap([]const u8, &out.items[k - 1], &out.items[k]); + std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]); + } + } + // Both sides taken: a variable the scene names (what the narration + // follows) takes the right from a register, which is counted. + if (out.items.len > 2 and context.index(out.items[1]) != null) for (out.items[2..], 2..) |name, j| { + if (context.index(name) != null) continue; + var k = j; + while (k > 1) : (k -= 1) { + std.mem.swap([]const u8, &out.items[k - 1], &out.items[k]); + std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]); + } + break; + }; if (out.items.len == 1) { const first_before = g.firstBefore(u, now, addr, was); if (first_before != null and !std.mem.eql(u8, first_before.?, out.items[0])) { @@ -323,6 +346,23 @@ pub const Nodes = struct { return .{ .names = out.items, .inks = inks.items, .shows = shows }; } + /// When `name` came to point at `addr`: the moment its value last + /// became it (a variable's, its last assignment), as of the stop shown + /// (or the one before, for a name that is leaving). + fn arrival(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8, addr: u64) u64 { + const rec = g.cursor.rec; + if (context.index(name)) |_| { + var i = if (rec.registers[now.stops[0]].named(name) == addr) now.stops[0] else now.stops[1]; + while (i > 0 and rec.registers[i - 1].named(name) == addr) i -= 1; + return i; + } + const v = rec.variable(u.f.scratch, now.moment(), name) orelse return now.stops[0]; + var i = if ((Recording.word(now.moment(), v.addr, 8) catch null) == addr) now.stops[0] else now.stops[1]; + // Its assignment: a store, of a new value or of the one its slot held. + while (i > 0 and !Recording.touches(rec.written(i - 1, i), v.addr, 8) and !Recording.touches(rec.storedSame(i - 1, i), v.addr, 8)) i -= 1; + return i; + } + /// The first name on `addr`'s pin before this step, if another name was beside it. fn firstBefore(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64, was: zt.Regs) ?[]const u8 { const names = g.namesBefore(u, now, addr, was); diff --git a/anim/src/root.zig b/anim/src/root.zig index 2f59420..d68b99c 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -225,6 +225,10 @@ pub const Context = struct { syscalls: bool = false, /// An instrumented program: see `Registers.quiet`. quiet: bool = false, + /// The `backtrace` lens: the call chain as the band's drawing + /// (eleven rows as subject, five beside), when how the program came + /// to be here is the story; the scene adds the drawing's view. + backtrace: bool = false, }; /// The ties between the panes, drawn over everything added before. @@ -263,7 +267,7 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex .disasm = add(s, Disasm{ .cursor = at, .stage = stage }), .registers = add(s, Registers{ .cursor = at, .stage = stage, .syscalls = options.syscalls, .quiet = options.quiet }), .stack = add(s, Stack{ .cursor = at, .stage = stage }), - .backtrace = add(s, Backtrace{ .cursor = at, .stage = stage }), + .backtrace = add(s, Backtrace{ .cursor = at, .stage = stage, .lens = options.backtrace }), .clock = add(s, Clock{ .cursor = at }), }; } diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 9e5bbba..8446b52 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -270,8 +270,8 @@ pub fn fitted(u: ui.Ui, text: []const u8, width: f32) []const u8 { /// then a faint `…`. `current`: a gold plaque 50 wide on the number (its /// edges out `fire`), ember across; `marked`: the number as on the plaque, /// which its panel draws where the mark is (it slides). `trail`: the bar -/// (0 newest). `widen`: how much more room the numbers of the window take -/// than three characters (`numberRoom`); the text moves right by as much. +/// (0 newest). `widen`: how much more room the program's line numbers +/// take than three characters (`numberRoom`); the text moves right by as much. pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, widen: f32, text: []const u8, styles: []const u8, state: union(enum) { plain, current: f32, marked, trail: usize }) void { const gold = theme.mark(.current); switch (state) { @@ -327,7 +327,7 @@ fn codeFace(class: u8) ui.Face { pub const Run = struct { first: u8, len: u8, - kind: enum { number, pointer, text, allocator, unread }, + kind: enum { number, pointer, text, loose, unread }, /// Its mark: struck (heat), read (shows), held is in the heat. heat: ui.Heat = .none, read: f32 = 0, @@ -338,17 +338,17 @@ pub const Run = struct { /// region ink with `lead` at 18 (at 60% on a row that holds no drawn /// thing), the bytes from 132 on a pitch of 30, 12 more after the /// eighth; a field's bytes on raised paper in their ink (a pointer's in -/// the region it points into, text's in a string's), an allocator's (and -/// any that are no field of what the dump is about) dim with no paper, never -/// read two dots a byte; a word's padding bytes faint. `reading` is drawn -/// by the caller at 640. +/// the region it points into, text's in a string's), `loose` ones (of no +/// field: the allocator's, a struct's padding, past what the dump is of) +/// dim with no paper, never read two dots a byte; a word's padding bytes +/// faint. Its reading is `hexdump.reading`, at 640. pub fn bytes(u: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *const [16]bool, runs: []const Run, region: u24, lead: usize, holds_drawn: bool, moment: Recording.Moment) void { bytesAt(u, y, addr, values, known, runs, region, lead, holds_drawn, moment, 0); } -/// How far right of their column a row's bytes (and its reading) go to -/// leave its address room: none for one of eight digits, 42 for a stack -/// address's twelve. +/// How far right of their column a dump's bytes (and its reading) go to +/// leave its widest address room: none for one of eight digits, 42 for a +/// stack address's twelve. A dump sets it once, so its rows keep one column. pub fn addressRoom(addr: u64) f32 { const b = theme.metric.bytes; return @max(b.address + @as(f32, @floatFromInt(ui.digits(addr))) * adv + adv - b.first, 0); @@ -394,7 +394,7 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons .number => ui.rgb(t.primary), .pointer => ui.rgb(if (run.len == 8) ink(regionOf(moment, word)) else t.primary), .text => ui.rgb(theme.color.string), - .allocator => ui.rgb(t.dim), + .loose => ui.rgb(t.dim), .unread => ui.rgb(t.faint), }; for (0..run.len) |j| { diff --git a/anim/src/source.zig b/anim/src/source.zig index 6b693a4..301e8cd 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -42,10 +42,10 @@ pub const Source = struct { // moves on) gliding to where the next one does. It never cuts. const going = now.advancing(); const windows = [2]f32{ @floatFromInt(rec.viewFirst(fit, was)), @floatFromInt(rec.viewFirst(fit, here)) }; - // Further than two windows (a large file, another function far - // off): what leaves has left before what replaces it arrives; a - // scroll through thousands of lines would be a blur, and say nothing. - const far = @abs(windows[1] - windows[0]) > 2 * @as(f32, @floatFromInt(fit)); + // Farther than its own height (another function far off): what + // leaves has left before what replaces it arrives; a scroll of more + // lines than the window shows would be a blur, and say nothing. + const far = @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)); const first = if (far) windows[if (going >= 0.5) 1 else 0] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); const lit = if (far and going < 1) u.faded(@abs(2 * going - 1)) else u; const from: u32 = @intFromFloat(@floor(first)); @@ -61,14 +61,14 @@ pub const Source = struct { var mark_at: f32 = @floatFromInt(here); var shows: f32 = 1; if (going < 1) { - if (!cursors.jumps(rec, now.marks[0], now.marks[1])) { + if (!now.plan.wave and !cursors.jumps(rec, now.marks[0], now.marks[1])) { // A line near by: it slides, off promptly and settling on // the next. The step's follow-through. mark_at = std.math.lerp(@as(f32, @floatFromInt(was)), mark_at, cursors.standard(going)); if (@abs(mark_at - @as(f32, @floatFromInt(was))) < 0.5) mark_line = was; } else { - // A call, a return, a line far off: a jump. Out there, then - // in here; it does not cross the lines between. + // A call, a return, a line far off, a continue: a jump. Out + // there, then in here; it does not cross the lines between. const half = @min(theme.time.current_jump, travel / 2); if (moved < travel - half) { mark_line = was; @@ -78,8 +78,8 @@ pub const Source = struct { } } const mark_y = top + (mark_at - first) * m.row; - // The numbers of the two windows, as wide as the widest needs. - const widen = rows.numberRoom(@min(@as(u32, @intFromFloat(@max(windows[0], windows[1]))) + @as(u32, @intCast(context.rowsOf(box))), rec.line_count)); + // The numbers as wide as the program's largest: a scroll does not shift the text. + const widen = rows.numberRoom(rec.line_count); context.clipBody(u, box); defer u.unclip(); // The plaque over the number. Fire: on the line about to run its diff --git a/anim/src/stage.zig b/anim/src/stage.zig index 595b9f5..e650906 100644 --- a/anim/src/stage.zig +++ b/anim/src/stage.zig @@ -48,9 +48,9 @@ pub const Stage = struct { st.moves[st.count] = .{ .from = st.last(), .to = to, .p = p }; st.count += 1; // The drawing fades out (12 f), the panels move, it fades in at its new size. - s.play(.{st.drawing.to(0)}, .{ .seconds = theme.time.quick, .ease = anim.ease.linear }); + s.play(.{st.drawing.to(0)}, .{ .seconds = theme.time.relayout_fade, .ease = anim.ease.linear }); s.play(.{p.to(1)}, .{ .seconds = theme.time.relayout, .ease = anim.ease.linear }); - s.play(.{st.drawing.to(1)}, .{ .seconds = theme.time.quick, .ease = anim.ease.linear }); + s.play(.{st.drawing.to(1)}, .{ .seconds = theme.time.relayout_fade, .ease = anim.ease.linear }); } /// Holds the stack's window still as it is at moment `at`, with `free` diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index b3e080d..e184990 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -28,9 +28,9 @@ const k = theme.color.on_kernel; /// one by one; the arrow goes down through the line; only then does the /// kernel's side change, the last call giving way to this one, its name, /// its rows, its card; the work is done a byte at a time (a call with -/// none skips it); the arrow comes back, and what came back strikes rax. -/// So a call is as long as what it does: `close` 4.1 s, a `read` of -/// fifteen bytes 5.2. +/// none skips it); the kernel's rows say what it returns, the arrow comes +/// back with it, and it strikes rax as the arrow lands. So a call is as +/// long as what it does: `close` 3.9 s, a `read` of fifteen bytes 5.0. pub const Plan = struct { registers: f32 = time.cascade, enters: f32 = 0.80, @@ -45,16 +45,18 @@ pub const Plan = struct { work: f32 = 2.00, fills: f32 = 2.40, bytes: f32 = 0, - /// The arrow back sets off; as it lands the `returns` row takes the - /// value; then rax is armed, and struck (nothing is marked as come - /// back before it has); the program stores what came back (memory, - /// after its cause); the mark moves on. + /// The `returns` row takes the value 6 f before the arrow back sets + /// off (the kernel answers before the answer travels); rax is armed + /// while the arrow travels and struck as it lands (nothing is marked as + /// come back before it has); everything else the step changed waits + /// for rax; the program stores what came back (memory, after its + /// cause); the mark moves on. + returns: f32 = 1.90, back: f32 = 2.00, - returns: f32 = 2.40, - struck: f32 = 2.60, - stored: f32 = 2.90, - advance: f32 = 3.50, - total: f32 = 4.10, + struck: f32 = 2.40, + stored: f32 = 2.70, + advance: f32 = 3.30, + total: f32 = 3.90, pub const cross = 0.40; pub const row = 0.10; @@ -67,8 +69,8 @@ pub const Plan = struct { const up: u64 = if (fills(call)) |span| span.len else 0; p.bytes = @floatFromInt(@max(down, @min(up, 32))); if (p.bytes > 0) p.back = p.fills + p.bytes * byte + 10.0 / 60.0; - p.returns = p.back + cross; - p.struck = p.returns + time.strike.arm; + p.returns = p.back - 6.0 / 60.0; + p.struck = p.back + cross; p.stored = p.struck + time.cascade; p.advance = p.stored + time.read_value; p.total = p.advance + time.step + time.rest; @@ -338,7 +340,7 @@ pub const Crossing = struct { const reach = 64; // Off promptly, and settling in the kernel. const up = cursors.standard(std.math.clamp((t - p.enters) / Plan.cross, 0, 1)); - const gone = std.math.clamp((t - p.returns - theme.time.quick) / theme.time.read.out, 0, 1); + const gone = std.math.clamp((t - p.struck - theme.time.quick) / theme.time.read.out, 0, 1); const v = u.faded(1 - gone); if (t < p.back) along(v, x, bottom, bottom - up * reach); if (made.exit != null and t > p.back) along(v, x + 40, bottom - reach, bottom - reach + cursors.standard(std.math.clamp((t - p.back) / Plan.cross, 0, 1)) * reach); @@ -451,12 +453,13 @@ pub const Timeline = struct { }; test "a crossing is as long as what the call does" { - // A call with no work: 4.1 s. Fifteen bytes copied up: 5.2. - try std.testing.expectApproxEqAbs(@as(f32, 4.10), Plan.of(.{ .nr = 3, .args = @splat(0), .enter = 0 }).total, 1e-3); + // A call with no work: 3.9 s. Fifteen bytes copied up: 5.0. + try std.testing.expectApproxEqAbs(@as(f32, 3.90), Plan.of(.{ .nr = 3, .args = @splat(0), .enter = 0 }).total, 1e-3); const read = Plan.of(.{ .nr = 0, .args = .{ 3, 0x1000, 32, 0, 0, 0 }, .enter = 0, .exit = 0, .result = 15 }); - try std.testing.expectApproxEqAbs(@as(f32, 5.17), read.total, 1e-2); - // What came back is read in the kernel's rows, then struck in rax, then stored. - try std.testing.expect(read.struck >= read.returns + theme.time.strike.arm and read.stored > read.struck); + try std.testing.expectApproxEqAbs(@as(f32, 4.97), read.total, 1e-2); + // What came back is in the kernel's rows before the arrow back leaves, + // struck in rax as it lands (armed on its way), then stored. + try std.testing.expect(read.returns < read.back and read.struck == read.back + Plan.cross and read.struck - time.strike.arm > read.back and read.stored > read.struck); // Nothing on the kernel's side before the arrow is through the line. try std.testing.expect(read.leaves >= read.enters and read.name >= read.enters + Plan.cross); try std.testing.expect(read.fills > read.name and read.returns > read.fills + 15 * Plan.byte); diff --git a/anim/src/theme.zig b/anim/src/theme.zig index a96d79c..846014f 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -497,8 +497,6 @@ pub const metric = struct { pub const mnemonic = 180; pub const operands = 264; pub const annotation = 564; - pub const operand_chars = 24; - pub const annotation_chars = 25; }; /// `bytes`: a hexdump row, from its panel's left edge (the band's right half). @@ -563,6 +561,18 @@ pub const metric = struct { pub const arrow_head = [2]f32{ 12, 10 }; }; + /// `calls`, full size: a disc 48 across, levels 46 apart, the root's + /// centre 48 under the tag; the result's square of 30 on the shoulder, + /// 12 right of the centre and 42 up; the caller's box 64 by 28. + pub const calls = struct { + pub const radius = 24; + pub const level = 46; + pub const root = 48; + pub const badge = 30; + pub const badge_at = [2]f32{ 12, 42 }; + pub const caller = [2]f32{ 64, 28 }; + }; + /// A lens's lanes: projections 4 under its tag, links 8 above its bottom edge. pub const lens = struct { pub const top_lane = 4; @@ -749,6 +759,9 @@ pub const time = struct { /// A flow's arrow outlives the landing by this. pub const linger = 1.0; }; + /// A `continue`'s registers strike in a wave, this far apart in + /// pwndbg's order (the fill in over `strike.in`, no arm, no pulse). + pub const continue_wave = 2.0 / 60.0; /// The veil that dims everything but the subject. pub const veil = 0.30; /// A telescope extends: the links after one that changed are followed @@ -778,10 +791,32 @@ pub const time = struct { pub const far = 0.50; pub const out = 0.30; }; + /// `travel`, for a pin: it sets off `after` the strike that moved it; + /// in a drawing it takes `node` to the next node or cell, `nodes` to + /// one farther; in the stack's lane `row` to the next row and + /// `step_per_row` a further row, `row_max` at most. One that comes + /// fades in (`in`, rising 8), one that goes fades out (`out`); a name + /// joining or leaving a pin cross-fades (`names`). + pub const pin = struct { + pub const after = 0.30; + pub const node = 0.50; + pub const nodes = 0.60; + pub const row = 0.40; + pub const step_per_row = 2.0 / 60.0; + pub const row_max = 0.60; + pub const in = 0.20; + pub const out = 0.20; + pub const names = 0.20; + }; + /// A return in the calls tree: its frame leaves the backtrace as the + /// idea strikes, and the result on the node's shoulder this long after. + pub const badge_after = 0.20; /// `establish`, for a lens: its elements come in from this far into the opening. pub const establish_rise = 0.50; - /// `relayout`: a change of split. + /// `relayout`: a change of split; the drawing fades out before the + /// move (`relayout_fade`) and in after it. pub const relayout = 0.80; + pub const relayout_fade = 0.20; /// A caption leaves, then nothing, then the next arrives rising this /// many units; never typed out, never crossfaded. The stage stays /// still `caption_lead` after it (`caption_lead_first` after a scene's @@ -949,7 +984,7 @@ test "easing runs from 0 to 1 without turning back" { test "durations are whole frames" { const t = time; - for ([_]f32{ t.snap, t.quick, t.step, t.step_per_row, t.step_max, t.move, t.travel, t.layout, t.camera, t.camera_far, t.fire, t.cascade, t.read_value, t.read_more, t.rest, t.strike.arm, t.strike.in, t.strike.pulse, t.strike.hold, t.strike.cool, t.strike.out, t.read.out, t.current_jump, t.flight.lift, t.flight.near, t.flight.second, t.veil, t.link.after, t.link.pin_out, t.link.in, t.link.in_far, t.link.settle, t.link.out, t.project.bracket, t.project.draw, t.project.out, t.establish_rise, t.relayout, t.caption_in, t.caption_out, t.caption_gap, t.walk, t.run, t.sprint, t.phrase_rest, t.before_cut }) |d| { + for ([_]f32{ t.snap, t.quick, t.step, t.step_per_row, t.step_max, t.move, t.travel, t.layout, t.camera, t.camera_far, t.fire, t.cascade, t.read_value, t.read_more, t.rest, t.strike.arm, t.strike.in, t.strike.pulse, t.strike.hold, t.strike.cool, t.strike.out, t.read.out, t.current_jump, t.flight.lift, t.flight.near, t.flight.second, t.veil, t.link.after, t.link.pin_out, t.link.in, t.link.in_far, t.link.settle, t.link.out, t.project.bracket, t.project.draw, t.project.out, t.establish_rise, t.relayout, t.relayout_fade, t.continue_wave, t.badge_after, t.pin.after, t.pin.node, t.pin.nodes, t.pin.row, t.pin.step_per_row, t.pin.row_max, t.pin.in, t.pin.out, t.pin.names, t.caption_in, t.caption_out, t.caption_gap, t.walk, t.run, t.sprint, t.phrase_rest, t.before_cut }) |d| { const frames = d * t.fps; try expect(@abs(frames - @round(frames)) < 1e-3); } diff --git a/anim/src/ties.zig b/anim/src/ties.zig index 1f2532d..0df8e34 100644 --- a/anim/src/ties.zig +++ b/anim/src/ties.zig @@ -100,7 +100,8 @@ fn find(place: Place) ?[4]f32 { /// When register `i` strikes in this step: the registers one step wrote /// strike 6 f apart, in the registers' order; from the fourth on with the /// third, within the CPU's slot of the cascade; in a crossing, once the -/// call is back. Its pin and its link go with it. +/// call is back; in a continue, a wave, 2 f after the one above it. Its +/// pin and its link go with it. pub fn strikeDelay(now: cursors.Now, i: usize) f32 { var before: f32 = 0; for (theme.metric.all_registers[0..16]) |name| { @@ -108,9 +109,17 @@ pub fn strikeDelay(now: cursors.Now, i: usize) f32 { if (k == i) break; if (now.registerAge(k) == 0) before += 1; } + if (now.plan.wave) return before * time.continue_wave; return @min(before * cursors.write_apart, time.cascade) + @import("syscalls.zig").crossingDelay(now); } +/// Seconds since register `i`'s link (and its pin) set off: its strike; +/// in a continue, memory's, when the stack's window is at its new place +/// (a tie arrives at what is on screen, not at a window about to go). +fn linkSince(now: cursors.Now, i: usize) f32 { + return if (now.plan.wave) now.since(.memory, 0) else now.since(.cpu, strikeDelay(now, i)); +} + /// How long a link draws: to a slot near by, or across to the lens. pub fn linkTime(target: enum { slot, node }) f32 { return if (target == .slot) time.link.in else time.link.in_far; @@ -120,11 +129,12 @@ pub fn linkTime(target: enum { slot, node }) f32 { /// before this step (`old`) and at the one it points at now (`new`): /// 6 f after its strike the old pin fades (12 f); the new lands with /// its link's head and settles (12 f). At a run or a sprint it moves -/// with its level; at rest, and for a register the step did not write, -/// both are 1. +/// with its level; at rest it is where the register points, and only +/// there; for a register the step did not write, the two are one place. pub fn pinShows(now: cursors.Now, i: usize, target: enum { slot, node }) struct { old: f32, new: f32 } { - if (now.resting() or now.registerAge(i) != 0) return .{ .old = 1, .new = 1 }; - const since = now.since(.cpu, strikeDelay(now, i)); + if (now.registerAge(i) != 0) return .{ .old = 1, .new = 1 }; + if (now.resting()) return .{ .old = 0, .new = 1 }; + const since = linkSince(now, i); if (!now.walking()) return if (since >= 0) .{ .old = 0, .new = 1 } else .{ .old = 1, .new = 0 }; const l = time.link; const arrives = l.after + linkTime(if (target == .slot) .slot else .node); @@ -221,7 +231,7 @@ pub const Ties = struct { const y = if (words < 0) w.top else w.top + @as(f32, @floatFromInt(w.slots - 1)) * w.row; break :edge [4]f32{ w.x, y, w.x + 10 * k, y + w.row }; }; - const since = now.since(.cpu, strikeDelay(now, i)); + const since = linkSince(now, i); const l = time.link; const drawn = cursors.standard(std.math.clamp((since - l.after) / linkTime(if (node != null) .node else .slot), 0, 1)); const back = std.math.clamp((now.time - now.plan.advance) / l.out, 0, 1); diff --git a/anim/test/gallery/atoms.png b/anim/test/gallery/atoms.png index 025176c..819bc91 100644 Binary files a/anim/test/gallery/atoms.png and b/anim/test/gallery/atoms.png differ diff --git a/anim/test/gallery/none.png b/anim/test/gallery/none.png index e4e3cb4..3e8eb0a 100644 Binary files a/anim/test/gallery/none.png and b/anim/test/gallery/none.png differ diff --git a/anim/test/gallery/rest.png b/anim/test/gallery/rest.png index 92c50ab..25c982e 100644 Binary files a/anim/test/gallery/rest.png and b/anim/test/gallery/rest.png differ diff --git a/anim/test/gallery/rows.png b/anim/test/gallery/rows.png index 9f6c095..cd2cb3e 100644 Binary files a/anim/test/gallery/rows.png and b/anim/test/gallery/rows.png differ diff --git a/anim/test/gallery/step.png b/anim/test/gallery/step.png index 1ca6f8a..682a317 100644 Binary files a/anim/test/gallery/step.png and b/anim/test/gallery/step.png differ diff --git a/anim/test/gallery/subject.png b/anim/test/gallery/subject.png index b579083..6f3230b 100644 Binary files a/anim/test/gallery/subject.png and b/anim/test/gallery/subject.png differ -- cgit v1.3