diff options
33 files changed, 1646 insertions, 564 deletions
diff --git a/anim/README.md b/anim/README.md index 1401ad7..c6e55bc 100644 --- a/anim/README.md +++ b/anim/README.md @@ -9,6 +9,7 @@ a block of the catalogue is a function or a component of the same name here. ```sh zig build record # the recordings, into zig-out/recordings +zig build sources # fetch the library sources their lines name (the only step that uses the network) zig build run -Dscene=fib # a scene in a window, hot reload (zig build lib --watch) zig build export -Dscene=fib -- DIR --fps 60 --size 1920x1080 # frames as PNGs (or - for raw RGBA) zig build videos -Doptimize=ReleaseFast # every scene: out/NAME-1080.mp4 and out/NAME-2160.mp4 (x264, 60 fps, aq-mode=0) @@ -21,7 +22,8 @@ CANIM_MAP=1 zig build export -Dscene=fib -- DIR --size 3840x2160 # every frame t ``` Needs what sketchbook and ztrace need, and `setarch`, `clang` (the pass -plugin), `ffmpeg` (videos), python with numpy and Pillow (charts). The +plugin), `ffmpeg` (videos), python with numpy and Pillow (charts), `curl` +(`zig build sources` alone). The `sqlite` scene also needs SQLite's amalgamation (`-Dsqlite=DIR`, the directory of `sqlite3.c` and `sqlite3.h`; by default `~/05-genizah/sqlite/sqlite-amalgamation-3500400`) and `objdump`; where @@ -86,10 +88,11 @@ 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 minimap reads the same values 6 f behind and -five more mirrors a frame apart (`Cursor.lags`, `time.minimap_lag`, +through `Cursor.now(at)`; each pane's minimap (its strip) reads the same +values 6 f behind and five more mirrors a frame apart, with the panes' +windows as they were as long ago (`Cursor.lags`, `time.minimap_lag`, `time.minimap_fade`: its drawings are averaged), so nothing on it starts -on a primary onset's frame and nothing on it changes in one. +on a primary onset's frame and nothing on it moves a pixel in one. ## The scenes @@ -99,11 +102,12 @@ on a primary onset's frame and nothing on it changes in one. | `fib` | recursion: each call a frame and a node | `subject`, `calls` | `steps` | | `list` | a list reversed: each `next` turned; it opens on the map and dives into the frame; after the first load the pointer loaded opens in a loupe, and the `next` in it one deeper | `subject`, `nodes` | `list` | | `sort` | insertion sort as its blocks: one trip of the inner loop walked a block at a time (each block's rows a cascade onto its last, then `leave` along the edge it takes: the compare's chips framed, the edge drawn gold, the mark along it, the target's count struck; `turn` up the inner loop's lane), the next trip at a run, the long middle a sprint on the map (`surface`, the gold going block to block, the counts growing, `dive`), the last value's trip walked again, the way out run | `blocks` (`graph.Blocks`; the disassembly its view over the state column, the source alone in the program column); on the map the graph with its rows (`Context.Options.graph`) | `sort` | -| `syscalls` | glibc's `hello`, by instruction from main: `open` followed down (main's call ringed, the PLT's stub passed, libc's wrapper run to its last three instructions and those walked, the kernel's window at the floor with the call in C's form and `returns`, and back up), then `read`, `close`, `write` stepped over, each in three parts: the instructions before the call a cascade onto the call row, the crossing from that row with the kernel's window opening under it (the rows after it making room), the stores after it 18 f after rax | `beside`, `syscalls` (the calls so far, as strace writes them); the disassembly a `descent` (`Context.Options.descent`) | `hello` | +| `syscalls` | glibc's `hello`, by instruction from main: `open` followed down (main's call ringed, the PLT's stub passed, libc's wrapper run to its last three instructions and those walked, its source beside it where the build has it (open64.c, and sysdep-cancel.h where the pc is in what that header's macro made; `zig build sources`), the kernel's window at the floor with the call in C's form and `returns`, and back up), then `read`, `close`, `write` stepped over, each in three parts: the instructions before the call a cascade onto the call row, the crossing from that row with the kernel's window opening under it (the rows after it making room), the stores after it 18 f after rax | `beside`, `syscalls` (the calls so far, as strace writes them); the disassembly a `descent` (`Context.Options.descent`) | `hello` | +| `musl` | the same `hello` built by Zig against musl, static: `open` followed down with no PLT and no GOT, the source panel following the pc through musl's own files (open.c, `__syscall_cp.c`, the one line of `syscall_arch.h` that is the `syscall`), the kernel's window, and back up to `main` | `beside`, `syscalls`; the disassembly a `descent` | `musl` | | `heap` | glibc's malloc under a list of three: three pushes, two pops, a push, told by motion.md's storyboard (nine captions; pushes 2 and 3 at a run; each `free` and the `malloc` that takes the head back walked; what the storyboard does not narrate runs: the calls into push and pop with their prologues, the returns to main but the one under the second free's long caption); the chunks by fields (`size`, `protected`, `key`), the program's list over the tcache's free list with its `bin` (a chunk in neither list drawn in the program's row, unarrowed), the tcache in a loupe over the stack, its stem down the gutter from its chunk's row, opened in each step that changes the tcache and closed at its advance | `subject`, the scene's own drawing (`nodes` in two rows) and view, both on its map too | `heap` | | `zoom` | one line of C as its instructions, the call's bytes | `none`, the camera at x1.16 on the instructions and the stack in one view, cause and effect (the stack's window set before the move and held); the map's drawing the calls of `fib` (`Map.drawing`) | `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`, `backtrace` (`Context.Options.backtrace`), then `syscalls`; its view a `hexdump.Dump`; as the caption names them, rdi's `BtCursor` opened in a loupe, then rsi linked to its row in the view (`Context.tiesWith`); the page's fields named a group at a time, 2 s apart; the backtrace lens drawn on its map | `sqlite` | -| `gallery` | every block in its states, a page or a state each 3 s; at 21 s the `blocks` lens (at rest, `leave` mid-way, `turn` landing, libc's `open` folded), at 24 s the graph with its rows as the map draws it, at half size (sort's panned to its loop; `open` at its `syscall`, the blocks never reached folded) | all three, `blocks` | `gallery`, and for the graph pages `test/gallery/sort.ztrace` and `hello.ztrace` | +| `gallery` | every block in its states, a page or a state each 3 s; at 21 s the `blocks` lens (at rest, `leave` mid-way, `turn` landing, libc's `open` folded), at 24 s the graph with its rows as the map draws it, at half size (sort's panned to its loop; `open` at its `syscall`, the blocks not reached folded) | all three, `blocks` | `gallery`, and for the graph pages `test/gallery/sort.ztrace` and `hello.ztrace` | ## The blocks @@ -115,20 +119,20 @@ every state the code has in the `gallery` scene. | 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`; and at a view's row's end, `Ui.pinEnd`), `bracket` (`quiet`, `tie`, `thread`), `tag` | `src/ui.zig` (`Ui.address`, `.value`, `.arrow`, `.written`, `.corner`, `.read`, `.cellWritten`, `.cellRead`, `.current`, `.trail`, `.unknown`, `.chip`, `.pinRow`, `.pinUnder`, `.bracket`, `.panel`) | marks as mock 15's column B: `current` the white wash (`color.wash`) and the gold plaque; `struck` the softened paper (`color.struck`) with bold bright digits; `held` a turned corner (9; 12 on a lens's cell), in over the cool's last 6 f (`Heat.corner`, `time.strike.corner`); `armed`, `read` | | | `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; a write's arm, strike and held corner cover the bytes whose value changed, first to last (`Run.changed`, `Now.changedBytes`), struck a byte a frame from the low address (what a read fills, 2 f apart); until its strike lands (s+3) a run keeps its old bytes and their reading, through the arm, read by its old field where the step retypes it (`hexdump.keepOld`, `Fields.was`) | -| 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`; a register's reads memory as the panels show it, the step's bytes from their strike (s+3): its later hops fade out from the strike and are followed again 4 f after the bytes land (`Now.following`, `Marks.hops`). `slot`: pins from 16, the offset from rsp ranged right to 172, the address at 184, the chain, its role ranged right where the room ends, from `zt.telescope.slots` (`saved rbx`, a local's name in primary, `n, high half` for a narrower local in the word's top four bytes, `argc`, `argv[0]`, `argv end`, `envp end`, `auxv`; nothing for a return address or `.none`). `bytes`: the bracket at 24, the address at 34, the bytes 12 after it and at 132 at least | +| 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`; a register's reads memory as the panels show it, the step's bytes from their strike (s+3): its later hops fade out from the strike and are followed again 4 f after the bytes land (`Now.following`, `Marks.hops`). `slot`: pins from 16, the offset from rsp ranged right to 172, the address at 184, the chain, its role ranged right where the room ends (48 sooner in a pane: its strip), from `zt.telescope.slots` (`saved rbx`, a local's name in primary, `n, high half` for a narrower local in the word's top four bytes, `argc`, `argv[0]`, `argv end`, `envp end`, `auxv`; nothing for a return address or `.none`). `bytes`: the bracket at 24, the address at 34, the bytes 12 after it and at 132 at least | | | `arc` | `src/rows.zig` (`Arcs`), `src/hexdump.zig` (`pointerArcs`) | a pointer to a row of its own panel: lanes at 4, 10, 16 in a dump or a loupe, 4 and 10 on the stack; longest outermost, a chain in one lane; standing at 60% toward the page, full in the step that writes or reads it and always in a loupe; rewritten: the old dashed with the arm, fading from 6 f after the strike as the new draws (12 f), quieting with the cool; a lane change glides while the arc that causes it draws or fades (`Arcs.assign`, with and without the arcs on their way); a stub to the rule for a target in the region past the window, only in its step; a saved rbp's only in its step, going with its advance (18 f); a dump withholds the arcs an open loupe carries | -| | `insn` | `src/disasm.zig` | columns at 2, 31, 40, 134, 180, 264, 564; size words dropped from every operand, a `width` of byte cells (`metric.width`) after the `]` where no register outside the brackets has the access's size and the mnemonic does not fix it; `nop` and `endbr64` faint; a PLT target named (`401070 open@plt`); the annotation from 564 or a character after the operands, then the operands give way, never inside `[]`; `current`, `ran` (every instruction of the last three steps), `ahead`, `outside`, `waiting`, `pass`; the jump lane from the jump just before the pc's moment. The row's detail, every value the recording's at that moment: a compare's two values and the flags it leaves as chips (those the conditional after it reads; CF ZF SF OF when none); a conditional's `taken`/`not taken · reads` and its flags, `→ target` when it leaves the window, and while it runs the setting row's chips and rip's framed as read (an echo); `lea`'s `= value`; a call through memory or a register `→ target name · read from open@got, 403fd8` (out of room the slot goes, then the digits); a call through a PLT stub by the function it reaches (`the resolver` while its slot is lazy); `fs:[0x28]` as the stack's canary (`canary` where the row has no room); a `rep`'s count and step; `syscall` with its name and number, its arguments under it by register, typed (`-100 AT_FDCWD`, `O_RDONLY`), the rows they hang over giving up their own annotation; a call that has run in C's form with its result (`read(3, …) = 15`: out of room the arguments go from the right, the result stays); a memory access narrower than a word read at its width (`rows.narrow`: `7fffffffecc4 ◂ 15`) | -| | `descent` | `src/descent.zig` (`Descent`, `step`) | the disassembly a call deep: the root's window on top (main), each callee's under the row that called it (that row `waiting`, ringed, its annotation the call in C's form), a PLT stub gone through kept as its `jmp`, `pass`; a head row over each window (the name at 40, Go Medium 18; what it is ranged right: `libc.so.6 · no source`, `the PLT · its jmp reads open@got, 403fd8`, `the PLT, jumped through`); the call lane at x 14; the nearest caller takes the rows the deepest does not use, all above its call row (one row after it, the return row, the callee's head directly under that), and where its function starts first the rest go back to the deepest window; three code windows at most, the rest one `more` row; each window's addresses its own width; the tag the deepest function and its module (`open · libc.so.6`); at a `syscall` (and the stop after it) the floor's three rows are the kernel's: in a crossing the lane down from the plaque (3, vellum), the window filling down, `the kernel` and `openat, system call 257`, the call in C's form, `returns` struck, `rcx, r11: clobbered`, the answer climbing the lane (24 f, `glide`), the window drawing back at the advance. A crossing stepped over opens the same window under the call row, past the arguments hanging under it, the rows after them making room (18 f) and closing up with the window. Every row keyed (an address, a head), so a step is the rows both stops have gliding and the rest leaving or arriving on its verb's timetable, in two moves, never at once: `descend` (2.9 s: the given-up rows fade 66–78, the kept ones glide 78–96, ring 84–96, lane 96–114, head 108–120, rows 114–138), on through a stub's `jmp` (2.2 s), `ascend` (2.5 s: the window closes 48–72, lane back 72–84, the kept rows glide 84–102, the given-up ones fade in 102–114), `cross` (`syscalls.step`); a row whose state the verb changes (the call row to `waiting` with its hanging arguments, a jmp to `pass`, a waiting call taking its result) crossfades; with it the source's line `waiting` (ringed, the tag `main waits at line 6 · the pc is in libc's open`, crossfading over the 12 f before the advance, as a stack span's name does) and the thread waiting (primary, 2) | +| | `insn` | `src/disasm.zig` | columns at 2, 31, 40, 134, 180, 264, 564 (540 in a pane, whose strip takes 48 of the row; `map.content`); size words dropped from every operand, a `width` of byte cells (`metric.width`) after the `]` where no register outside the brackets has the access's size and the mnemonic does not fix it; `nop` and `endbr64` faint; a PLT target named (`401070 open@plt`); the annotation from 564 or a character after the operands, then the operands give way, never inside `[]`; `current`, `ran` (every instruction of the last three steps), `ahead`, `outside`, `waiting`, `pass`; the jump lane from the jump just before the pc's moment. The row's detail, every value the recording's at that moment: a compare's two values and the flags it leaves as chips (those the conditional after it reads; CF ZF SF OF when none); a conditional's `taken`/`not taken · reads` and its flags, `→ target` when it leaves the window, and while it runs the setting row's chips and rip's framed as read (an echo); `lea`'s `= value`; a call through memory or a register `→ target name · read from open@got, 403fd8` (out of room the slot goes, then the digits); a call through a PLT stub by the function it reaches (`the resolver` while its slot is lazy); `fs:[0x28]` as the stack's canary (`canary` where the row has no room); a `rep`'s count and step; `syscall` with its name and number, its arguments under it by register, typed (`-100 AT_FDCWD`, `O_RDONLY`), the rows they hang over giving up their own annotation; a call that has run in C's form with its result (`read(3, …) = 15`: out of room the arguments go from the right, the result stays); a memory access narrower than a word read at its width (`rows.narrow`: `7fffffffecc4 ◂ 15`) | +| | `descent` | `src/descent.zig` (`Descent`, `step`) | the disassembly a call deep: the root's window on top (main), each callee's under the row that called it (that row `waiting`, ringed, its annotation the call in C's form), a PLT stub gone through kept as its `jmp`, `pass`; a head row over each window (the name at 40, Go Medium 18; what it is ranged right: `libc.so.6 · open64.c` (the file of its function's entry, where the build has the source), `libc.so.6 · no source`, `the PLT · its jmp reads open@got, 403fd8`, `the PLT, jumped through`); the call lane at x 14; the nearest caller takes the rows the deepest does not use, all above its call row (one row after it, the return row, the callee's head directly under that), and where its function starts first the rest go back to the deepest window; three code windows at most, the rest one `more` row; each window's addresses its own width; the tag the deepest function and its module (`open · libc.so.6`); at a `syscall` (and the stop after it) the floor's three rows are the kernel's: in a crossing the lane down from the plaque (3, vellum), the window filling down, `the kernel` and `openat, system call 257`, the call in C's form, `returns` struck, `rcx, r11: clobbered`, the answer climbing the lane (24 f, `glide`), the window drawing back at the advance. A crossing stepped over opens the same window under the call row, past the arguments hanging under it, the rows after them making room (18 f) and closing up with the window. Every row keyed (an address, a head), so a step is the rows both stops have gliding and the rest leaving or arriving on its verb's timetable, in two moves, never at once: `descend` (2.9 s: the given-up rows fade 66–78, the kept ones glide 78–96, ring 84–96, lane 96–114, head 108–120, rows 114–138), on through a stub's `jmp` (2.2 s), `ascend` (2.5 s: the window closes 48–72, lane back 72–84, the kept rows glide 84–102, the given-up ones fade in 102–114), `cross` (`syscalls.step`); a row whose state the verb changes (the call row to `waiting` with its hanging arguments, a jmp to `pass`, a waiting call taking its result) crossfades; with it the source's line `waiting` where the pc is in code without source (ringed, the tag `main waits at line 6 · the pc is in libc's open`, crossfading over the 12 f before the advance, as a stack span's name does) and the thread waiting (primary, 2); where the build has the library's source the panel goes on with the pc into it. Its strip is the deepest window's function's linear column (a `Disasm` drawn for the strip alone, `Map.In.strips`), that window framed on it; going down or up it fades through as the mark lands (`map.through`) | | 3 panel | `registers`, `stack`, `backtrace` | `src/context.zig` | rip's value crossfading over the advance, a flag set or cleared over the 6 f it lands in (`rows.RipWas`); the backtrace newest at the bottom, `#0` last, the oldest dropped from the top (`newest at the bottom · 2 more above`), as a panel, the calls lens's view, the backtrace lens and on the map, all one block (`backtraceRows`: frames leave, slide and arrive; what a kept row says that changes, its depth, its pc's offset, its line, and the tag's count, crossfades, 12 f before the advance); 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`), a word's role and offset, and the tag, crossfading (12 f from memory's strike) where the step changes them, 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 (12 f each; at a run half its step each), and what it brings, and what changed before it, is plain; while rows slide they keep their roles (those of both windows are read), and a word becoming a saved rbp, or no longer one, has its arc go or come with its role; 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; the trail's bars crossfading with the advance; 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; its tag's function (a descent's tag too) crossfading with the advance; a 2-unit `rule` across over each block's first row (not its function's), and the block's visits by the moment shown ranged right, faint (`×3`), where the row's annotation leaves room, crossfading with the advance (`graph.Rules`, a descent's windows too); the rows clipped above the panel's padding (a row scrolling out takes its rule with it) | -| | `graph` | `src/graph.zig` (`read`, `fold`, `place`, `layout`, `Blocks`, `Map`, `Rules`) | the function's blocks from the recording (`zt.telescope.blocks`; a block of `nop` padding nothing goes to left out), their edges by how each ends, and the run over them by the moment shown: each block's visits, each edge's count, the last three edges taken, the pc's block; counted where one stop in the function follows another across an edge, and only for a recording that stops at every instruction (`exact`; by line, visits only, every edge `rule`). Laid out (`place`, pure, by the whole recording's counts, so it never moves as they grow): back edges by a walk from the entry in address order, layers by the longest forward path, the blocks that return last; in a layer a block under the predecessor that reached it most often, then under the one it falls from, a taken target never taken right of it, the more travelled first where two want one column; columns a pitch apart (the map's as wide as the pc's block with its annotation, 928; the lens's 300); a forward edge out of the bottom on its target's side (40 in, 16 in the lens; the middle when straight below), along the gap's middle, into the target's top (arrivals 48 apart), through the right channel (32 out) where it would cross a block; a back edge down 14, out to its loop's lane (16 apart from 24, the outermost farthest), up, into its header's head. Too tall for its place (`layout`), in the catalogue's order: each run of blocks the whole recording never reached (neighbours in address order joined by an edge; split where folding would make a loop the code does not have) one dashed box, `+5b to +b9 · 5 blocks never reached`; then blocks over 16 rows to four, `more`, four (not the pc's); then it pans, whole layers, to the largest loop the pc's block is in that fits, else the pc's block in the middle. The static part kept per function and form (`memo`), the moment's counts counted again each frame. `Blocks`: the lens's drawing, boxes 24 high, 60 and 10 a row wide (132 at least), the offset, the visits (`dim`), reached `raised`, not yet on the page, a fold dashed, the pc's framed gold 3; the edges never taken `rule`, taken `dim`, the trail's golds (the newest 3), a loop's turns on its lane (Go 18). `Map`: on the map two columns wide beside the source, each block a head (its address, `lines a to b`, `×n` primary) over `insn`'s rows moved 52 left, the offset where the address was (ranged right at 72); the annotation only in the pc's block (and its rows that ran in the last three steps, with their trail bars), which widens to its column, its rows' annotations kept inside it; a conditional's counts by its ports; a direct call's hook out of the block's side and back a row down, the callee named (`swap`); under a return the way out (stub 14, bar 28), a tail call's stub and name, an indirect jump's `targets not known` | +| | `source` | `src/source.zig` | the file the pc is on a line of, of the recording's sources (`Recording.sources`, `shown`: the program's own, or a library's the build gave; else the last such line, a frame up, where the pc waits), whole in a window, its middle third; its lines cut at 63 characters in a pane (67 on the map); the trail's bars (of that file's lines) crossfading with the advance; numbers as wide as the widest file's largest line (SQLite's six digits), the text moved right by as much; another file: the panel fades through (12 f out, 12 f in), its tag's title and note crossfading with it, its strip with it (`map.through`); a window going farther than its own height in one file: the advance is 48 f, the window gliding on the strip for the first 24 (the gold lit on its new row there), then the pane out and in | +| | `disasm` | `src/disasm.zig` | 17 rows (9 as subject), fewer above near a function's start; on the map 69 from the function's start where the pc is in its first three quarters (a strip's column stays still while the pc walks it), else round the pc; the line column as wide as the source's, a row's number where its line is of the file the source panel shows (libc's rows open64.c's while it shows open64.c, main's none then); two windows that overlap scroll, others fade out and in; its tag's function (a descent's tag too) crossfading with the advance; a 2-unit `rule` across over each block's first row (not its function's), and the block's visits by the moment shown ranged right, faint (`×3`), where the row's annotation leaves room, crossfading with the advance (`graph.Rules`, a descent's windows too); the rows clipped above the panel's padding (a row scrolling out takes its rule with it) | +| | `graph` | `src/graph.zig` (`read`, `fold`, `place`, `layout`, `Blocks`, `Map`, `Rules`) | the function's blocks from the recording (`zt.telescope.blocks`; a block of `nop` padding nothing goes to left out), their edges by how each ends, and the run over them by the moment shown: each block's visits, each edge's count, the last three edges taken, the pc's block; counted where one stop in the function follows another across an edge, and only for a recording that stops at every instruction (`exact`; by line, visits only, every edge `rule`). Laid out (`place`, pure, by the whole recording's counts, so it never moves as they grow): back edges by a walk from the entry in address order, layers by the longest forward path, the blocks that return last; in a layer a block under the predecessor that reached it most often, then under the one it falls from, a taken target never taken right of it, the more travelled first where two want one column; columns a pitch apart (the map's as wide as the pc's block with its annotation, 928; the lens's 300); a forward edge out of the bottom on its target's side (40 in, 16 in the lens; the middle when straight below), along the gap's middle, into the target's top (arrivals 48 apart), through the right channel (32 out) where it would cross a block; a back edge down 14, out to its loop's lane (16 apart from 24, the outermost farthest), up, into its header's head. Too tall for its place (`layout`), in the catalogue's order: each run of blocks the whole recording never reached (neighbours in address order joined by an edge; split where folding would make a loop the code does not have) one dashed box, `+5b to +b9 · 5 blocks not reached` (said of the run so far: a graph says only what has happened by the moment shown, never what will not; which blocks fold, and where each block is placed, are still chosen by the whole recording); then blocks over 16 rows to four, `more`, four (not the pc's); then it pans, whole layers, to the largest loop the pc's block is in that fits, else the pc's block in the middle. The static part kept per function and form (`memo`), the moment's counts counted again each frame. `Blocks`: the lens's drawing, boxes 24 high, 60 and 10 a row wide (132 at least), the offset, the visits (`dim`), reached `raised`, not yet on the page, a fold dashed, the pc's framed gold 3; the edges never taken `rule`, taken `dim`, the trail's golds (the newest 3), a loop's turns on its lane (Go 18). `Map`: on the map two columns wide beside the source, each block a head (its address, `lines a to b`, `×n` primary) over `insn`'s rows moved 52 left, the offset where the address was (ranged right at 72); the annotation only in the pc's block (and its rows that ran in the last three steps, with their trail bars), which widens to its column, its rows' annotations kept inside it; a conditional's counts by its ports; a direct call's hook out of the block's side and back a row down, the callee named (`swap`); under a return the way out (stub 14, bar 28), a tail call's stub and name, an indirect jump's `targets not known` | | | `blocks` lens | `src/graph.zig` (`Blocks`), `theme.layout.split.blocks` | its drawing the graph as shapes over the program column (296 high), which then holds the source alone (twenty lines); its view the disassembly itself, seven rows over the state column; the registers over six words; no thread (the disassembly is not under the source: it fades with the distance between them) | | | `hexdump` | `src/hexdump.zig` | malloc's words: a field read as `size` (`0x20 a m P`, the bits as rip's flags) or `protected` (`→ 405050 ^ 405`, `NULL ^ 405`, its arc to the pointer it protects), and a field's `note` (Go 18 faint: `key`, `top`, `slots left`); a lens's view (`hexdump.panel`): `bytes` rows and their reading, veiled at a sprint; a row whose bytes the step changed where the recording saw no write (memory nothing watches, read anew at a stop), or that became known, crossfading over 12 f (`rowPasses`); 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`) | | | `loupe` | `src/loupe.zig` (`canim.loupe`, `Loupe.open`, `.close`) | from a register, a loupe's field, or a dump's row read by the scene's fields (`.row`: malloc's tcache, `num_slots[0]` and `entries[0]`, the rest `more`); five rows round a pointer's target, lifted (`color.lift`, `lift_tag`, `shade` 12 and 16; 20 and 26 deeper), hanging from its pointer (its tag on the row's foot, 92 left of the digits, clamped to the stage), a 4-high bracket under the digits its stem, the target's fields framed bright; one opened from the band's view lies over the stack, never the registers, its stem down the gutter's right lane (x 962), its fields struck once it has opened (6 f after, 6 f apart: `Fields.struck`); a deeper one with no room to the right hangs under the one it opens from, its stem down to its tag; a note that does not fit is cut at a word with `…`; `open` 36 f (read 6, stem and rise 18 with the shadow, the frame 6 f after), `close` 12 f; it opens again after a close | -| | 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 calls so far as strace writes them (oldest on top, the newest coming in once it is back, held; the rows make room for it, a full log scrolling a row, 24 f, `glide`, the count above crossfading; out of room a row gives up its faint names first, then its arguments from the right, and keeps what it returned; a path by its string, the kernel's capture where the stop did not read it) over the bytes the call crossing in the step is given or fills (in with the argument framing, 12 f out and 12 f in; what a read fills landing a byte every 2 f, struck, the stack's words with them; a write's buffer framed as read while the kernel takes it; cleared with the log's new row: between crossings `no call crossing now`), `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, faded out through the middle of a register's joining or leaving (`Pins.text`); a call node's look (gold, ringed, done) crossfading as the tree's moment changes (6 f), and at a sprint a new node coming in over its step; a left child's result on its left shoulder, off its parent; a view's row a register points into carries the register's `pin` at the row's end (`hexdump` `rowPin`), the reading ending before it; at a sprint the array's pins hold and move where a phrase ends | +| | 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 calls so far as strace writes them (oldest on top, the newest coming in once it is back, held; the rows make room for it, a full log scrolling a row, 24 f, `glide`, the count above crossfading; out of room a row gives up its faint names first, then its arguments from the right, and keeps what it returned; a path by its string, the kernel's capture where the stop did not read it) over the bytes the call crossing in the step is given or fills (in with the argument framing, 12 f out and 12 f in; what a read fills landing a byte every 2 f, struck, the stack's words with them; a write's buffer framed as read while the kernel takes it; cleared with the log's new row: between crossings `no call crossing now`), `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, faded out through the middle of a register's joining or leaving (`Pins.text`); a call node's look (gold, ringed, done) crossfading as the tree's moment changes (6 f), and at a sprint a new node coming in over its step; a left child's result on its left shoulder, off its parent; a view's row a register points into carries the register's `pin` at the row's end (`hexdump` `rowPin`; 48 to the left in a pane, its strip at the right), the reading ending before it; at a sprint the array's pins hold and move where a phrase ends | | 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; to a view's row (`dump_pin`) by the left lane, into the row's edge; on a beat the narration names (`Context.tiesWith`, `ties.Beat`): the register framed as read, then its link, held, drawn back with the frame; a projection from the view's bytes, or from a frame's return address to its call's node | -| 5 frame | `map`, `minimap`, `dive`, `surface` | `src/map.zig` (`Map`, `split`, `minimap`), `Context.map` | the working frame's panels bound to a stage of 3840 by 2160 (`map.split`, packed by content: each box as long as the most rows its panel has wanted, `measure`, the backtrace's as long as the deepest call chain of the scene's way, so that it is packed once; the drawing, the source and under it the backtrace; the disassembly; the view (none where nothing draws one), the registers, and in the column's rest the stack going on, `stack, continued`; the stack from 16 words above rsp; and the first two columns' rest (`Split.spare`) given, in the catalogue's order, to `map.Spare`: a five-row dump round each place the registers (pwndbg's order, not rsp or rbp) and the 64 words up from rsp point at outside the stack and the code, none within another's rows, then the loupes open (`Map.loupes`, lifted, nine rows), then the key (the recording and the moment, the marks as drawn, the inks); only then page); its rows published while `ui.mapping` (the dumps' too); the working windows outlined (2 `dim`, 4 out), each window published with where its step took it from and how far its scroll has gone, so its outline glides; the thread across the gutter (x 1008), gold; a scene without a band can put a drawing on its map (`Map.drawing`); with `Context.Options.graph` the disassembly is the function's graph (`graph.Map`), two columns wide beside the source, the registers over the stack in the last column, no band (the lens's window on it is the graph whole, the disassembly's the box round the rows it shows), no thread line (the gold line number is the thread); the minimap the same at a twentieth under the clock (a graph's blocks outlined, its edges a pixel, the pc's block framed gold) (text as 1-unit strokes at 45% toward the page, marks as blocks; `ui.strokes`), drawn six times into the host's images, each from the cursor's mirror a frame later (6 to 11 f behind: `Cursor.lagInto`, `time.minimap_fade`) and averaged, so that every change on it fades in over 6 f and nothing on it changes in a frame; its outlines on whole pixels at rest and between them only as they glide; a mark no working window shows (a word struck or read on the stack or in a dump the map draws) flashing on it (a ring 8 to 14 in the mark's colour, 12 f), the count ranged right at 1648; `Map.show`, `.dive` (outlines bright 6 f, veil to 24, each panel from its window to its place 60 f, 6 f apart, a panel drawn over another setting off first (drawing, view, disassembly, stack, source, registers) so that none in its place is crossed by one on its way, opaque on the way, its rows on the window's rows, its tag and rules in at the end; the map falls into the minimap's corner over 72 f, its scale on the logarithm, its corner going toward the minimap's as the scale does, small it is drawn over the panels with its edge, and crossfades into the minimap's drawing at 90–96; 120 f and 30 f still), `.surface` (the dive back, 84 f, then 30 f still); per-panel transforms through `context.at` (`context.zoomed`) | +| 5 frame | `map`, `minimap`, `dive`, `surface` | `src/map.zig` (`Map`, `split`, `strip`, `Map.strips`), `Context.map` | the working frame's panels bound to a stage of 3840 by 2160 (`map.split`, packed by content: each box as long as the most rows its panel has wanted, `measure`, the backtrace's as long as the deepest call chain of the scene's way, so that it is packed once; the drawing, the source and under it the backtrace; the disassembly; the view (none where nothing draws one), the registers, and in the column's rest the stack going on, `stack, continued`; the stack from 16 words above rsp; and the first two columns' rest (`Split.spare`) given, in the catalogue's order, to `map.Spare`: a five-row dump round each place the registers (pwndbg's order, not rsp or rbp) and the 64 words up from rsp point at outside the stack and the code, none within another's rows, then the loupes open (`Map.loupes`, lifted, nine rows), then the key (the recording and the moment, the marks as drawn, the inks); only then page); its rows published while `ui.mapping` (the dumps' too); the working windows outlined (2 `dim`, 4 out), each window published with where its step took it from and how far its scroll has gone, so its outline glides; the thread across the gutter (x 1008), gold; a scene without a band can put a drawing on its map (`Map.drawing`); with `Context.Options.graph` the disassembly is the function's graph (`graph.Map`), two columns wide beside the source, the registers over the stack in the last column, no band (the lens's window on it is the graph whole, the disassembly's the box round the rows it shows), no thread line (the gold line number is the thread). Each pane's minimap (`map.strip`): a strip 40 wide inside its frame at its right, under the tag, on `well` (`theme.strip`), drawn from its column of the map (the source's boxes, the stack's with `stack, continued`, the view's dump; the disassembly's the linear rows round the pc, drawn for the strips alone where the map has a graph or a descent: `Map.In.strips`) at 4 units a row and 36 of 880 across, from what the map drawn for it collects (`ui.strokes`, `ui.collected`: each run of text a stroke 3 high in its ink 65% from the page, the marks 4 by 4 at a row's left in the catalogue's order, an arc with an end off the window a 2-unit line down the left edge, a block's first row ticked); a column longer than the strip the rows round its window, the window in the middle, clamped to the ends, three faint dots where it goes on (fading in over its first row's scroll); the window framed 2 in primary; a mark no working window shows (a word struck or read on the stack or in the view's dump) flashing on its row (a ring 8 to 14 in the mark's colour, 12 f). The strips are one image a frame (`Map.strips`): the map drawn for them six times, each from the cursor's mirror a frame later (6 to 11 f behind: `Cursor.lagInto`) with the panes' windows as long ago (`past`), every strip drawn as it shows (its rows, dots and window in place) and the six averaged, so that every change on a strip fades in over 6 f from 6 f after its onset and nothing on it moves a pixel in a frame; the panes blit their part (source, disassembly and its descent and the `blocks` lens's view, stack, a dump's view: not the registers, a drawing, a loupe, the backtrace, the `syscalls` lens's log). A pane with a strip has 48 less for its rows (`map.content`). `Map.show`, `.dive` (outlines bright 6 f, veil to 24, each panel from its window to its place 60 f, 6 f apart, a panel drawn over another setting off first (drawing, view, disassembly, stack, source, registers) so that none in its place is crossed by one on its way, opaque on the way, its rows on the window's rows, its tag and rules in from 84 f; with each, the rest of its column (the rows its strip shows) squeezing from its place on the map into the strip, its width and height each on its logarithm (to 36 of 880, 4 of 24 a row), its window's outline riding on it, gone into the strip's own drawing over the 12 f before its pane lands (`Map.squeeze`, `stripShows`); the map's other parts fading where they are, 24 to 72; 120 f and 30 f still), `.surface` (the dive back, 84 f, then 30 f still); per-panel transforms through `context.at` (`context.zoomed`); the clock's count ranged right at 1856 | | | `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`, `continue` (`Cursor.continue`, `Plan.wave`), `run`, `sprint`, `establish` (`Context.establish`: a drawing's elements fade in rising, no lines), `scroll`, `relayout`, `visit`, `say`; `leave` and `turn` (`graph.leave`, from a block's last row, `graph.toEnd` to get there: fire 0–12; the compare's chips framed as read from 18 (the CPU's slot, the jump's echo), held while the edge draws gold, head first, 24–42; the mark (a gold plaque, half size in the lens) along the edge 42 to 42 + 12 f and 2 f a 100 units of the lens's edge (30 f at most), up the lane for a turn; landing, the advance; the target's count armed and struck 6 f after (a turn's lane count as it lands), cooled to nothing by the step's end; the trail recoloured over 18 f from the landing; a rest of 42 f from the landing); over a graph at a walk of several blocks, a run or a sprint the trail, the counts and the gold crossfade with the advance (8 f at a run, the step at a sprint), the pan gliding with it | `src/cursor.zig` (the timetable), `src/graph.zig` (`leave`, `instant`), 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`); a label that changes in place with a step crossfades over the 12 f before the advance, or from the step's start where that is sooner (`Now.renaming`); at a run what marked a value goes with the run's ease (8 f) and a pin changes over it; at a sprint an ember and what grows come in over the step (4 f), never in a frame | @@ -140,7 +144,7 @@ and read (a debugger's `touch` reads count), each moment's `touch` and ## The recordings -`build.zig` records five programs of `tools/` under `ztrace record` (the +`build.zig` records six programs of `tools/` under `ztrace record` (the debugger: registers, the stack, what they point at, the instructions round the pc with their lines and callees' parameter counts, what each stack word is (`zt.telescope.slots`), at every stop: `--stack 1024 --around 256 @@ -152,15 +156,53 @@ the clock's retry loops it steps through). The instrumented ones are built `-no-pie -fno-stack-protector -Wl,-z,now`: short addresses, no resolver and no canary stepped through that the source does not say. +A dynamic program's libraries (glibc, the loader) are named by their own +debug info where the debuginfod client's cache has the file of their build +id (`$DEBUGINFOD_CACHE_PATH`, else `$XDG_CACHE_HOME/debuginfod_client`, +else `~/.cache/debuginfod_client`): their frames carry names and lines. +The recorder finds it by `DEBUGINFOD_CACHE_PATH`, which the program +inherits and keeps in its environment, so it is `debuginfod`, a link +beside the program to the cache: the program's environment says +`DEBUGINFOD_CACHE_PATH=debuginfod` (rdx at main's start points at it), +nothing of the machine. A static musl program's are its own (Zig builds +musl from its sources with it). + +**Sources.** A recording's lines name files other than the program's own +(libc's `open64.c`, musl's `open.c`). The build gives each scene those it +has (`tools/sources.zig embed`, every build, no network: the recording's +`<name>-sources` module, `Program.sources`, path and text): musl's from +Zig's lib directory (`zig env`), the rest from the debuginfod client's +cache, `<cache>/<build id>/source/<path as the debug info names it>` (a +directory of canim's own beside elfutils' entries there: elfutils' own +source layout is not documented on this machine, and gdb does not share +it). `zig build sources` fetches into it what it lacks, of the modules +named by a separate debug file (a distribution's library, never the +program's own), from the first server of `$DEBUGINFOD_URLS` or +`/etc/debuginfod/*.urls`: `curl <server>/buildid/<build id>/source<path>`, +which sends the build id and the path and curl's defaults. Without the +cache (or before the step) a scene shows a library without source, as +before. The source panel follows the pc into any file it has +(`Recording.shown`). + | Name | Program | Stops | Moments, bytes | Also | | --- | --- | --- | --- | --- | -| `steps` | `fib.c`, static musl, `-O0` | every instruction | 1999, 431 KB (336 KB before) | | -| `hello` | `hello.c`, the system's clang and glibc, dynamic: `-O0 -g -no-pie -fstack-protector-strong -Wl,-z,now` (a PLT bound at load, no resolver; the canary) | every instruction, `--from main`, `--steps 132` (to main's return) | 166 (30 of them the loader's syscalls before main), 83 KB (233, 126 KB: static musl by line) | reads `tools/note`; PLT stubs and GOT slots named (`open@plt`, `open@got`) | -| `heap` | `heap.c` (design/mock/heap.c), the system's clang and glibc, dynamic, as `hello` | every line, `--from main`, and pop's `call free@plt` (`break_call`: a breakpoint objdump finds, which a line-stepping recorder now stops at) | 77, 59 KB | `--heap` (`ztrace.heap.glibc`: chunks, the tcache, bins, the arena); `-w 0x405000,1024` (the chunks' bodies) and `-w head` (the global the list hangs from: unwatched, a recording keeps a global as last seen) | -| `sort` | `sort.c`, `ztrace cc --instr vars --only sort,a` | every instruction, `--from main` | 4396, 751 KB (5154, 799 KB at `--stack 256`) | `--ring`: the variables' names and types; each `__zt_var` call is stepped (4 of them) | -| `list` | `list.c`, `ztrace cc --instr vars --only push,reverse,head` | every instruction, `--from reverse` | 2920, 743 KB (2913 the pass before: the count differs by a few moments from one recording to the next, not looked into; 3369, 782 KB at `--stack 256`) | `--alloc --preload` the agent: allocator headers are read; the pushes (the agent's and the runtime's first calls) run through | +| `steps` | `fib.c`, static musl, `-O0` | every instruction | 1999, 601 KB | | +| `hello` | `hello.c`, the system's clang and glibc, dynamic: `-O0 -g -no-pie -fstack-protector-strong -Wl,-z,now` (a PLT bound at load, no resolver; the canary) | every instruction, `--from main`, `--steps 132` (to main's return) | 166 (30 of them the loader's syscalls before main), 110 KB (83 KB before libc was named) | reads `tools/note`; PLT stubs and GOT slots named (`open@plt`, `open@got`) | +| `heap` | `heap.c` (design/mock/heap.c), the system's clang and glibc, dynamic, as `hello` | every line, `--from main`, `--steps 46` (to main's return: libc's lines, named now, would take it on through `exit`), and pop's `call free@plt` (`break_call`: a breakpoint objdump finds, which a line-stepping recorder now stops at) | 78, 74 KB | `--heap` (`ztrace.heap.glibc`: chunks, the tcache, bins, the arena); `-w 0x405000,1024` (the chunks' bodies) and `-w head` (the global the list hangs from: unwatched, a recording keeps a global as last seen) | +| `sort` | `sort.c`, `ztrace cc --instr vars --only sort,a` | every instruction, `--from main` | 4446, 984 KB (4396, 751 KB before libc was named) | `--ring`: the variables' names and types; each `__zt_var` call is stepped (4 of them) | +| `list` | `list.c`, `ztrace cc --instr vars --only push,reverse,head` | every instruction, `--from reverse` | 2913, 1035 KB (2920, 743 KB before libc was named: the count differs by a few moments from one recording to the next, not looked into) | `--alloc --preload` the agent: allocator headers are read; the pushes (the agent's and the runtime's first calls) run through | +| `musl` | `hello.c` again, built by Zig for `x86_64-linux-musl`, static, `-O0 -g` (musl compiled from its sources with it: no PLT, its lines its own) | every instruction, `--from main`, `--steps 166` (to main's return) | 173, 55 KB | reads `tools/note` | | `gallery` | the old `list` by line, kept in `test/gallery/list.ztrace`; for the graph pages `sort` and `hello` as recorded on 11 November (with blocks), kept in `test/gallery/sort.ztrace` and `hello.ztrace` (`gallery_sort`, `gallery_hello`) | | 134, 88 KB; 776 KB; 87 KB | the gallery's pictures depend on the drawing only | -| `sqlite` | `sqlite.c` (three rows into a table, committed) with SQLite 3.50.4's amalgamation, system clang `-O2 -g -fno-omit-frame-pointer -no-pie -fno-stack-protector -Wl,-z,now`, glibc | `--by break`: `sqlite3_step`, `sqlite3BtreeInsert`, `unixWrite`, and the instruction after its `pwrite64` (found by objdump); every syscall recorded, `-s 4096` | 181 (42 stops, 138 syscalls), 233 KB (139 KB) | made only with `-Dsqlite=DIR` (default `~/05-genizah/sqlite/sqlite-amalgamation-3500400`), in a new temporary directory each time; `sqlite3.c` is embedded as the source | +| `sqlite` | `sqlite.c` (three rows into a table, committed) with SQLite 3.50.4's amalgamation, system clang `-O2 -g -fno-omit-frame-pointer -no-pie -fno-stack-protector -Wl,-z,now`, glibc | `--by break`: `sqlite3_step`, `sqlite3BtreeInsert`, `unixWrite`, and the instruction after its `pwrite64` (found by objdump); every syscall recorded, `-s 4096` | 181 (42 stops, 138 syscalls), 494 KB | made only with `-Dsqlite=DIR` (default `~/05-genizah/sqlite/sqlite-amalgamation-3500400`), in a new temporary directory each time; `sqlite3.c` is embedded as the source | + +What builds each program: `fib.c` (`steps`) and `hello.c` for `musl`, +Zig's build (`addExecutable`, musl, static); `hello.c` for `hello`, +`heap.c` and `sqlite.c`, the system's clang against the system's glibc, +dynamically (`hello`'s PLT and GOT are the scene, as a C programmer's +build lays them; the heap scene is glibc's own allocator; `sqlite` is +built as the bench builds it, and its scene is glibc's `pwrite64`); +`list.c` and `sort.c`, `ztrace cc`, the system's clang with the +instrumentation pass, a plugin of that clang's LLVM. Every recording the build makes carries each function's blocks (`zt.telescope.blocks`, at the first stop in it) and a `branch` event at @@ -181,11 +223,16 @@ holds is named from its module's first mapping (`list+2c89`). `tools/chart.py chart` on the 1080p exports (the designer's `design/motion/motion.py`, its checks and its regions told where canim's panels are (sort's the `blocks` split's: the drawing, the view that is -the disassembly, the source alone, the registers and the stack); the -clock, ranged right at 1648, its own region, whose count -changing in a frame is no POP; the caption's box from 940, under the -clock's count and a run's step counter; the minimap its own region, -secondary action, and its one-frame changes POPs). POP: any region still +the disassembly, the source alone, the registers and the stack), each +pane's strip a region of its own (`source strip`, `disasm strip`, +`stack strip`, and `view strip` where the view is a dump: `motion.strips`, +the pane's region stopping 42 short of its right edge), secondary action +like the words (no CROWD), its one-frame changes POPs; the clock, its +count ranged right at 1856, its own region, whose count changing in a +frame is no POP; the caption's box from 940, under the clock's count and a +run's step counter). `design/motion/motion.py` itself has the strips' +regions by split too (`--regions none|beside|subject|blocks`, and the +default frame's columns less their strips). POP: any region still for 12 f that changes in one frame and is still again. A one-frame change that is right is counted apart by name (`POP exempt`), never dropped: `keyframe`, x264's I frame (`-g 600`: 10, 20, 30 s) re-quantizing a still @@ -202,78 +249,91 @@ fib's first 600 frames have no such column). CAPTION: up over 720 f, up under `says.line` strings as shown; where the video's arrivals and the scene's captions do not pair up it says so and checks no reading time), or the picture moving within 60 f of its arrival; chart.py does not count the -list's dive (150 to 300 f) as a caption's change: the falling map passes -under the caption, which does not change. +list's dive (150 to 300 f) as a caption's change. -| | fib | list | sort | syscalls | zoom | sqlite | heap | gallery | -| --- | --- | --- | --- | --- | --- | --- | --- | --- | -| POP, before / after | 11 / 12 | 13 / 13 | 6 / 3 | 25 / 25 | 11 / 12 | 8 / 8 | 17 / 19 | 8 / 9 | -| of them the minimap's, before / after | 5 / 5 | 6 / 6 | 1 / 2 | 17 / 17 | 6 / 6 | 3 / 3 | 8 / 10 | 4 / 4 | -| POP exempt, before / after | | | | | | | | cut 3 / cut 5, keyframe 1 | -| CROWD, before / after | 4 / 3 | 9 / 8 | 7 / 10 | 3 / 3 | 1 / 1 | 1 / 1 | 16 / 16 | 4 / 5 | -| METRONOME, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | -| CAPTION up over 720 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | -| CAPTION under its reading time, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | -| CAPTION picture moving within 60 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | -| AIR, before / after | 0 / 0 | 0 / 0 | 1 / 1 | 0 / 0 | 1 / 1 | 2 / 2 | 0 / 0 | 1 / 1 | -| seconds, before / after | 42.0 / 42.0 | 81.7 / 81.7 | 42.2 / 63.8 | 83.8 / 83.8 | 33.5 / 33.5 | 62.9 / 62.9 | 78.6 / 78.6 | 21.0 / 27.0 | +| | fib | list | sort | syscalls | musl | zoom | sqlite | heap | gallery | title | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| POP, before / after | 12 / 7 | 13 / 8 | 3 / 6 | 25 / 7 | – / 12 | 12 / 6 | 8 / 5 | 19 / 16 | 9 / 11 | – / 0 | +| of them the corner minimap's / the strips' | 5 / 1 | 6 / 1 | 2 / 5 | 17 / 1 | – / 1 | 6 / 1 | 3 / 0 | 10 / 6 | 4 / 4 | – / 0 | +| POP exempt, before / after | | | | | | | | | cut 5 / cut 5, keyframe 1 / keyframe 1 | | +| CROWD, before / after | 3 / 4 | 8 / 8 | 10 / 10 | 3 / 4 | – / 2 | 1 / 1 | 1 / 1 | 16 / 16 | 5 / 5 | – / 0 | +| METRONOME, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | +| CAPTION up over 720 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | +| CAPTION under its reading time, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | | +| CAPTION picture moving within 60 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | +| AIR, before / after | 0 / 0 | 0 / 0 | 1 / 1 | 0 / 0 | – / 0 | 1 / 1 | 2 / 1 | 0 / 0 | 1 / 1 | – / 1 | +| seconds, before / after | 42.0 / 42.0 | 81.7 / 81.7 | 63.8 / 63.8 | 83.8 / 83.8 | – / 68.9 | 33.5 / 33.5 | 62.9 / 62.9 | 78.6 / 78.6 | 27.0 / 27.0 | – / 12.3 | -"Before" is the last pass's "after". The sort scene is new (the `blocks` -lens and the map's graph, against the array scene's 42.2 s), and the -gallery has two pages more; the other scenes changed only by the linear -rows' block rules, and their counts are within one of the last pass's: -fib's 27.53 (the ran rows' annotations as the sprint begins), zoom's 19.25 -and 21.85 and syscalls' 28.23 are in the last pass's exports at the same -frames, counted now; the heap's minimap has two more. +"Before" is the last pass's "after". The musl scene is new; the title's +export is the last pass's size to the byte (it was not in that table). The +corner minimap is gone and its fires with it (a repack landing in one +frame for all six drawings; its windows' outlines drawn from the frame's +own scroll): syscalls' 17 were most of its 25, in the run through `open`. +The strips that replace it are each the average of six drawings a frame +apart, their windows too (`past`), so a change on a strip fades over 6 f. +sqlite's AIR at 32.95 is gone. Sort's and heap's strips' counts are +mostly not the strips': see below. -What this pass built (`graph`, design/README.md's "graph" and motion.md's -"A block left"), and what it fixed at the block on the way: +What this pass built (design/README.md's "The map and the minimap", +mocks 10, 11, 20 and 39; the source following the pc): -- The graph: its layout (`graph.place`, unit-tested on sort's, reverse's - and libc's `open` recordings in `test/recordings.zig`), the `blocks` - lens, the graph with its rows on the map and its blocks on the minimap, - the block rules on every scene's linear rows, `leave` and `turn`, the - run and the sprint over it (the gold, the trail and the counts - crossfading with each step's advance), and the gallery's two pages. -- `Stack.watched` read each stop's registers from the trace file, ten - reads a stack drawn and seven stacks a frame with the minimap's: most of - a frame's time once the scene had run a while (sort's draft 57 ms a frame, - about 20 after). It reads the recording's index. -- The disassembly's rows were clipped at the panel's rule, not above its - padding: a row scrolling out showed in the padding (a block's rule there - came and went in a frame). They are clipped above it. -- `surface` did nothing in a scene that had not opened on the map: the - map's object was never shown. It shows it. +- Each pane's strip (`map.strips`, `map.strip`, `map.through`): its + column of the map at 4 units a row, the window framed, the gold, strikes + and reads, an arc's end off the window down its edge, a flash where a + word changes outside it; the corner minimap removed, the clock's count + ranged right at 1856. `dive` squeezes each pane's column into its strip; + `surface` the reverse. The strips' regions in `tools/chart.py` and + `design/motion/motion.py`. +- The source panel follows the pc into any file the build has the source + of (`Recording.sources`, `tools/sources.zig`, `zig build sources`); the + `musl` scene; libraries' frames named by file and line in the backtrace. +- On the way: `rows.fitted` clamps an infinite width (a Debug panic, + `integer part of floating point value out of bounds`, in musl); the + sketchbook's text cache holds 4096 entries and 128 MB, not 512 and 16 + (the map's text drawn six times a frame thrashed it: the list's dive + 0.46 s a frame, about 47 ms after); the heap's recording stops at 46 + steps (libc's lines carried it on through `exit`: 519 moments); the + graph's counts, ink, trail and lane counts are by the moment shown. Right in one frame, and exempted by name: the encoder's keyframes and the gallery's cuts (above). -What fires still, by kind (located on this pass's exports): +What fires still, by kind (located on this pass's exports; those not +looked at this pass say so): -- The minimap (about half of every scene's): a repack of the map (a panel - that wants more rows, a frame behind) lands in one frame for all six - drawings; and a working window's outline, drawn from the frame's own - scroll and not averaged, moving a pixel with a pause where its glide's - sub-pixel steps round alike (syscalls' run through `open`). +- The strips' regions: fib 30.37, list 3.87 (in the dive), syscalls + 5.10, musl 63.23, zoom 23.18, 12 to 24 pixels each. Sort's 31.63, + 32.18, 33.93 and 35.25 are the map's own panels under the source + strip's region while the sprint plays on the map (as the view's 32.25); + 52.50 is 14 pixels. Heap's six (12 to 98 pixels) are in the stack + strip's region: 65.07 is a loupe passing over it at a step's first + frame, the rest not looked at. The gallery's 12.22, 18.15 and 20.82 are + at a state's first frame, as its view's re-windowing. - The stack: a few pixels in the arcs' lanes and the pins (fib 8.20, - 19.50, 24.90, 39.13; syscalls 29.13, 57.72, 70.17; sqlite 20.43, 31.75). + 19.50, 24.90, 39.13; syscalls 29.13, 57.72, 70.17; sqlite 20.43, + 31.75); musl's five, list's 7.30, zoom's 19.25 and heap's 55.23 not + looked at. - Registers: a held corner, a few pixels at a value's top left (fib 21.10, - syscalls 44.32, sqlite 38.67). -- The source and the disassembly: syscalls 17.92 and 55.62, the line - going `waiting` and back with the descent's rows; zoom 18.10 and 19.60, - an annotation taking its value in place under the camera. + syscalls 44.32, sqlite 38.67); zoom's 12.80 and 16.40, list's 59.45 and + 70.45, musl's 62.57, heap's 13.68 and the gallery's 22.38 not looked at. +- The source and the disassembly: syscalls 17.92, the line going + `waiting` and back with the descent's rows; zoom 18.10 and 19.60, an + annotation taking its value in place under the camera; musl's five in + the disassembly (31.33 to 66.35), the descent's rows, a library + address's leading digits changing in a frame; heap 13.50, a scroll's + first whole-pixel step from rest. - The view: syscalls 64.77, the read's first byte landing over the - buffer's dots; the gallery's view re-windowing at a state's first frame. -- The drawing: fib 33.63 the calls tree's badge corner; the heap's runs - (its 16 CROWDs too: the calls and returns it does not narrate); the - gallery's 22.38, a struck count's digits going to their ordinary face at - the middle of its cool (the catalogue's `cool`). -- The map filling the frame: sort 32.25, at the sprint on it, a few pixels - of the map's panels changing in place at the sprint's pace. + buffer's dots; the gallery's view re-windowing at a state's first frame; + sqlite 55.83 (15 pixels) not looked at. +- The drawing: fib 33.63, the calls tree's badge corner; the heap's runs + (its 16 CROWDs too: the calls and returns it does not narrate); sqlite + 42.47, the system calls' log scrolling a line up from rest by whole + pixels (1 every other frame at first); list's 13.12, 40.82, 67.65 and + 68.85 (120 to 277 pixels) not looked at. - AIR: sort's and zoom's last picture (the last caption read, then held); - sqlite 32.95, after the continue to `unixWrite`, and 46.02, where the - chart misses the read frame on one byte (`0d`) at 47.5 s: the picture is - still 1.5 s and then 2 s; the gallery's atoms page, 3 s by design. + sqlite 46.02, where the chart misses the read frame on one byte (`0d`) + at 47.5 s; the gallery's atoms page, 3 s by design; the title's card, + held by design. - CROWD: the advance (thread, plaques and rip as one mark, the source and the disassembly scrolling with it), the veil over three panels at a run's first step; sort's `surface` and `dive`, every panel at once by @@ -281,6 +341,15 @@ What fires still, by kind (located on this pass's exports): ## What is not done +- The graph's truth: what it shows is the run's by the moment shown (each + block's visits and `seen` paper, each edge's count and ink, the trail, + a loop's turns: `countBy` counts to the moment), and a fold of blocks no + longer says `never reached` but `not reached`. What is still the whole + recording's: where each block is placed (`place`, by the whole run's + edge counts: the hot path straight down, so the picture does not move as + the counts grow) and which blocks fold (the runs it never reached): both + say something of the future to one who reads the layout. Left for the + designer's revision of the graph. - The graph (`graph`): the map draws the disassembly as its graph only where the scene asks (`Context.Options.graph`: sort); the catalogue has it whenever the recording has the function's blocks. Not built for the @@ -317,10 +386,10 @@ What fires still, by kind (located on this pass's exports): a step later. The fold past three windows (`2 calls: fib fib`), a lazy PLT's resolver row and the vDSO's window are written but no recording shows them; on the map the descent's box is as long as the rows it has - wanted, so opening a callee's window there repacks the map (the most of - syscalls' remaining minimap POPs). At a run the windows do not open and close in 8 f with no lane + wanted (the map draws the descent only where it is shown: the strip's + column is the linear rows round the pc). At a run the windows do not open and close in 8 f with no lane (the syscalls scene walks every step of the descent). -- `open("note", O_RDONLY) = 3` does not fit 880 from 564 (27 +- `open("note", O_RDONLY) = 3` does not fit 832 from 540 (27 characters): the arguments go from the right, `open("note", …) = 3`. A call's arguments come from as many as the source's call writes, typed by the system call of the function's name (`open`, `read`): a libc @@ -353,19 +422,60 @@ What fires still, by kind (located on this pass's exports): the scene's deepest chain, so its box can be taller than the frames of the moment). The sqlite map draws the backtrace lens, not the calls so far it changes to, and no view. -- The minimap is the average of six drawings a frame apart (6 to 11 f - behind): every change on it fades over 6 f, at the cost of drawing the - map six times a frame while anything moves (once at rest). Its images - are a process-wide cache of the host's. A repack of the map (a panel - that wants more rows, a frame behind) is averaged like any change but - still lands in one frame for all six drawings: the remaining minimap - POPs are those and the windows of panels that publish them after the - clock. The scene's focus is not set on it. -- `dive`: every panel travels 60 f (the catalogue's 72 f is the map's - fall), so that seven of them 6 f apart land by 120 f; the drawing does +- The strips are the average of six drawings a frame apart (6 to 11 f + behind), the panes' windows in them as long ago (`past`, kept by frame + number: after a seek the first eleven frames draw the windows as they + are): every change on a strip fades over 6 f, at the cost of drawing + the map six times a frame while anything moves (once at rest), text + collected but not shaped. Their images are a process-wide cache of the + host's. Native shapes are not antialiased and images are sampled + nearest, so a window gliding moves a pixel at a time: averaged, each + pixel step fades over 6 f. The map's disassembly is the function from + its start where it fits (so a strip's column stays still in a + function); a jump to another function scrolls the map's rows, and on + the strip that slide is averaged into a 6 f blur, under the pane's fade + through (`map.through`). The drawing for the strips draws every part of + the map but the registers, the backtrace and the spare dumps. +- A pane's content is 48 narrower in the working frame + (`map.content`), the map's not: the gallery's rows and any panel drawn + outside a context too. The `syscalls` lens's view (the log over the + bytes crossing) has no strip but its reading is still cut 48 sooner. A + conditional jump's annotation (`taken · reads zf sf`) is not cut by its + room: with a library's 12-digit addresses it runs under the strip by a + few characters (syscalls' hurried run through `open`, sort's view). +- A far jump in one file (the source's window farther than its own + height) takes 48 f: the window glides on the strip for the first 24, + then the pane fades out and in. A far jump of the disassembly alone (no + source window far) fades through over the advance with its window + gliding on the strip over the same frames. A file change (another + source) fades the panel and its strip through over 24 f; at a run over + the run's 8 f advance (syscalls' hurry through open64.c and + sysdep-cancel.h flips the file several times, each a fade). The far + jumps seen in the finals are sqlite's, in its 262 899-line sqlite3.c, + whose strip (the map's source panel, round the line the pc goes to) + cannot hold both places: at a continue the strip goes over to the new + place as the continue sets off (a 6 f fade, the gold lit there at once) + and shows no window until the pane's lands there, about 2 s later; the + step back from `pwrite64` (43.3 s) plays on the crossing's plan, whose + travel is shorter, so the pane fades through in about 6 f, before the + strip (6 to 11 f behind) shows it. The tag's note names the new lines + over the 12 f before the advance, before the pane shows them. +- The heap scene never stops inside malloc or free (they are run + through, by the PLT, at a line a stop): there is no frame of theirs to + name, and no line column of theirs to show. Their lines are in the + recordings as names only where a frame is (sqlite's, list's and sort's + `__libc_start_call_main`, `libc_start_call_main.h:59`). +- `dive`: every panel travels 60 f (the catalogue's 72 f), so that + seven of them 6 f apart land by 120 f; each pane's column squeezes with + it, its rows the strip will show (the column's rows past them fade with + the map, where they are), and goes into the strip's own drawing over + the 12 f before its pane lands (the catalogue: 84 to 96 for all), the + text drawn real all the way (no strokes until the strip's); a graph's + disassembly (sort) has no linear column on the map: its strip comes in + as its pane lands, from nothing; the drawing does not crossfade between sizes (the list's are the same, subject on both). - Only the list opens on the map; no scene surfaces, and no sprint or far - continue plays on the map. + Only the list opens on the map; only sort surfaces (its sprint plays on + the map), and no far continue plays on the map. - A loupe hung from a register keeps to the stage but does not yet move past the current marks or a changed row; on the 1920 stage a deeper one hangs under the first, not 120 to its right. The catalogue's stem is 3 @@ -428,19 +538,16 @@ What fires still, by kind (located on this pass's exports): x1.16; at x1.5 the stack's chains (`fib+42`) and roles (`saved rbp`, `n`) the captions name fall off its right edge, or the mnemonics off its left; the stack's call spans are off its right edge at x1.16. -- A working window's outline on the minimap is drawn from the frame's own - scroll, not averaged with the six drawings: a one-pixel scroll there - moves over a few frames with a pause where the glide's sub-pixel steps - round alike (most of syscalls' minimap POPs, in the run through `open`). - Bytes the recorder merged into one written span (a free's link and key, stored by two instructions next to each other) strike as one. - The `pages` lens is not in the band (`Timeline` is the old far view). -- The map's and minimap's drawing flags (`ui.mapping`, `ui.strokes`, - `ui.chrome`), a dive's per-panel transforms (`context.zoomed`), the - map's measured rows (`map.held`), the ties' table and the thread's +- The map's drawing flags (`ui.mapping`, `ui.strokes`, `ui.collected`, + `ui.bound`, `ui.chrome`), a dive's per-panel transforms (`context.zoomed`), the + map's measured rows (`map.held`), the strips' images and the windows + they keep (`map.atlas`, `map.past`, `map.current`), the ties' table and the thread's waiting are still process-wide globals, set and read in one frame's drawing (the measured rows a frame behind); two players at once would - want them on the frame. Only the minimap's lag is passed down now: its + want them on the frame. Only the strips' lag is passed down now: their drawings get the frame's values with the cursor's replaced by a lagging mirror's (`Cursor.lagInto`), and `Cursor.now` no longer reads `ui.strokes`. The rest is read by components the frame reaches only @@ -452,9 +559,12 @@ What fires still, by kind (located on this pass's exports): pointer leads (32 bytes), so a view of it says what the stop read (`hexdump.Fields.seen`); a syscall's buffer is shown as the kernel took it, from its capture. The recorder should say what it read at each stop. -- A frame's file and line are known only where the recording stopped in - it: return addresses are recorded with names, not lines, so a deep - backtrace's older rows have none. +- A backtrace row's `file:line` is its call's, where the recording has the + instruction before its return address (the debugger records the + instructions at a frame's return address, their lines with them): a + library's too where its debug info was found (glibc's + `libc_start_call_main.h:59` and `libc-start.c:372`, musl's + `__libc_start_main.c:95`), else none. - 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. diff --git a/anim/build.zig b/anim/build.zig index 4a2ec76..24ce5e1 100644 --- a/anim/build.zig +++ b/anim/build.zig @@ -16,7 +16,7 @@ const std = @import("std"); const sketchbook = @import("sketchbook"); -const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "zoom", "heap", "gallery" }; +const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "musl", "zoom", "heap", "gallery" }; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); @@ -53,6 +53,29 @@ pub fn build(b: *std.Build) void { const agent = tools.namedLazyPath("ztrace-agent"); const musl = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }); + // The debuginfod client's cache, where elfutils and Zig's std look: a + // distribution's library's debug info of the same build id, that the + // recorder names its code and lines by; and where `sources` keeps the + // source files those lines name (<cache>/<build id>/source/<path>). + // Found when a step runs, from its environment (`$DEBUGINFOD_CACHE_PATH`, + // else `$XDG_CACHE_HOME/debuginfod_client`, else `~/.cache/debuginfod_client`), + // never at configure time, whose result zig caches. + const debuginfod_cache = "${DEBUGINFOD_CACHE_PATH:-${XDG_CACHE_HOME:-$HOME/.cache}/debuginfod_client}"; + // The sources a recording's lines name, other than the program's own: + // embedded from the cache and Zig's lib directory (`embed`, every build), + // fetched into the cache (`fetch`, `zig build sources`). + const sources_tool = b.addExecutable(.{ .name = "sources", .root_module = b.createModule(.{ + .root_source_file = b.path("tools/sources.zig"), + .target = b.graph.host, + .optimize = .ReleaseFast, + .imports = &.{.{ .name = "ztrace", .module = tools.module("ztrace") }}, + }) }); + const fetch = b.addRunArtifact(sources_tool); + fetch.addArg("fetch"); + fetch.has_side_effects = true; + b.step("sources", "Fetch the library sources the recordings' lines name into the debuginfod cache (the only step that uses the network)").dependOn(&fetch.step); + var source_modules: std.ArrayList(std.Build.Module.Import) = .empty; + const Recording = struct { name: []const u8, source: []const u8, @@ -97,8 +120,9 @@ pub fn build(b: *std.Build) void { // By instruction from main, through the PLT and libc's wrappers to // the kernel and back: the descent; to main's return. .{ .name = "hello", .source = "hello.c", .by = "insn", .from = "main", .steps = "132", .glibc = true, .reads = "note" }, - // A line a stop, malloc and free run through; glibc's heap at each. - .{ .name = "heap", .source = "heap.c", .by = "line", .from = "main", .glibc = true, .heap = true, .watch = &.{ "0x405000,1024", "head" }, .break_call = .{ "pop", "free" } }, + // A line a stop, malloc and free run through (through the PLT); glibc's heap at each; + // to main's return (libc's lines, named now, would take it on through `exit`). + .{ .name = "heap", .source = "heap.c", .by = "line", .from = "main", .steps = "46", .glibc = true, .heap = true, .watch = &.{ "0x405000,1024", "head" }, .break_call = .{ "pop", "free" } }, // By instruction, as `steps` is: the registers are the program's // own, so they strike and link. Only the variables the scenes name // are told by the instrumentation (each a call into its runtime, @@ -106,6 +130,9 @@ pub fn build(b: *std.Build) void { // (the agent's and the runtime's first calls) run through. .{ .name = "sort", .source = "sort.c", .by = "insn", .instr = "vars", .only = "sort,a", .from = "main" }, .{ .name = "list", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "reverse", .alloc = true }, + // `hello` again, built by Zig against musl, static: no PLT; musl's + // own source (`open.c`, `syscall_cp`) on the way down to the kernel. + .{ .name = "musl", .source = "hello.c", .by = "insn", .from = "main", .steps = "166", .reads = "note" }, }) |r| { const source = b.path(b.fmt("tools/{s}", .{r.source})); var program: std.Build.LazyPath = undefined; @@ -139,16 +166,26 @@ pub fn build(b: *std.Build) void { const where = b.addWriteFiles(); _ = where.addCopyFile(program, r.name); if (r.reads) |name| _ = where.addCopyFile(b.path(b.fmt("tools/{s}", .{name})), name); + // A dynamic program's libraries are named by their debug info in + // the debuginfod cache: the recorder finds it by DEBUGINFOD_CACHE_PATH, + // which the program inherits, so it is a link beside the program + // (`debuginfod`), a name that says nothing of the machine. + const dynamic = r.glibc or r.instr != null; const run = if (r.break_call) |call| blk: { // The call's address, from the program as built, then the recorder with a breakpoint there. const sh = b.addSystemCommand(&.{ "sh", "-c", b.fmt( \\p=$0 z=$1; shift + \\c={s} \\at=$(objdump -d --no-show-raw-insn "$p" | awk '/<{s}>:/ {{ f = 1 }} f && /call.*<{s}@plt>/ {{ sub(":", "", $1); print "0x" $1; exit }}') \\[ -n "$at" ] || {{ echo "no call of {s} in {s}" >&2; exit 1; }} - \\exec env -i setarch -R "$z" record -b "*$at" "$@" - , .{ call[0], call[1], call[1], call[0] }) }); + \\ln -sfn "$c" debuginfod + \\exec env -i DEBUGINFOD_CACHE_PATH=debuginfod setarch -R "$z" record -b "*$at" "$@" + , .{ debuginfod_cache, call[0], call[1], call[1], call[0] }) }); sh.addFileArg(program); break :blk sh; + } else if (dynamic) blk: { + const sh = b.addSystemCommand(&.{ "sh", "-c", "ln -sfn \"" ++ debuginfod_cache ++ "\" debuginfod && exec env -i DEBUGINFOD_CACHE_PATH=debuginfod setarch -R \"$0\" \"$@\"" }); + break :blk sh; } else b.addSystemCommand(&.{ "env", "-i", "setarch", "-R" }); run.addArtifactArg(ztrace); // More round each stop than the working frame shows: the map of @@ -174,12 +211,16 @@ pub fn build(b: *std.Build) void { run.expectExitCode(0); run.expectStdErrMatch("exit 0"); - // Into the scene's own binary: the recording's bytes and the source it ran. + // Into the scene's own binary: the recording's bytes, the source it + // ran, and the other sources its lines name that the build has. const file = b.fmt("{s}.ztrace", .{r.name}); record_step.dependOn(&b.addInstallFile(trace, b.fmt("recordings/{s}", .{file})).step); _ = embedded.addCopyFile(trace, file); _ = embedded.addCopyFile(source, r.source); - table.print(b.allocator, "pub const {s}: Program = .{{ .trace = @embedFile(\"{s}\"), .file = \"{s}\", .source = @embedFile(\"{s}\") }};\n", .{ r.name, file, r.source, r.source }) catch @panic("OOM"); + fetch.addFileArg(trace); + const sources = embedSources(b, sources_tool, r.name, trace, r.source); + source_modules.append(b.allocator, .{ .name = b.fmt("{s}-sources", .{r.name}), .module = sources }) catch @panic("OOM"); + table.print(b.allocator, "pub const {s}: Program = .{{ .trace = @embedFile(\"{s}\"), .file = \"{s}\", .source = @embedFile(\"{s}\"), .sources = &@import(\"{s}-sources\").list }};\n", .{ r.name, file, r.source, r.source, r.name }) catch @panic("OOM"); } // SQLite, the next rung: its amalgamation is not ours to copy, so the // scene is made only where it is. Built as the bench builds it (-O2, @@ -211,7 +252,8 @@ pub fn build(b: *std.Build) void { \\trap 'rm -rf "$d"' EXIT \\cp "$program" "$d/sqlite" \\cd "$d" - \\env -i setarch -R "$ztrace" record --by break -b sqlite3_step -b sqlite3BtreeInsert -b unixWrite -b "*$back" --stack 1024 --around 256 --disasm 69 -s 4096 -o "$out" -- ./sqlite + \\ln -s "${DEBUGINFOD_CACHE_PATH:-${XDG_CACHE_HOME:-$HOME/.cache}/debuginfod_client}" debuginfod + \\env -i DEBUGINFOD_CACHE_PATH=debuginfod setarch -R "$ztrace" record --by break -b sqlite3_step -b sqlite3BtreeInsert -b unixWrite -b "*$back" --stack 1024 --around 256 --disasm 69 -s 4096 -o "$out" -- ./sqlite }); run.addArtifactArg(ztrace); run.addFileArg(program); @@ -220,7 +262,9 @@ pub fn build(b: *std.Build) void { record_step.dependOn(&b.addInstallFile(trace, "recordings/sqlite.ztrace").step); _ = embedded.addCopyFile(trace, "sqlite.ztrace"); _ = embedded.addCopyFile(.{ .cwd_relative = sqlite_c }, "sqlite3.c"); - table.print(b.allocator, "pub const sqlite: Program = .{{ .trace = @embedFile(\"sqlite.ztrace\"), .file = \"sqlite3.c\", .source = @embedFile(\"sqlite3.c\") }};\n", .{}) catch @panic("OOM"); + fetch.addFileArg(trace); + source_modules.append(b.allocator, .{ .name = "sqlite-sources", .module = embedSources(b, sources_tool, "sqlite", trace, "sqlite3.c") }) catch @panic("OOM"); + table.print(b.allocator, "pub const sqlite: Program = .{{ .trace = @embedFile(\"sqlite.ztrace\"), .file = \"sqlite3.c\", .source = @embedFile(\"sqlite3.c\"), .sources = &@import(\"sqlite-sources\").list }};\n", .{}) catch @panic("OOM"); } // The gallery's own: a recording of the list kept in test/gallery, so its @@ -233,10 +277,10 @@ pub fn build(b: *std.Build) void { table.print(b.allocator, "pub const gallery_{s}: Program = .{{ .trace = @embedFile(\"gallery-{s}.ztrace\"), .file = \"{s}\", .source = @embedFile(\"{s}\") }};\n", .{ kept[0], kept[0], kept[1], kept[1] }) catch @panic("OOM"); } const recordings = b.createModule(.{ .root_source_file = embedded.add("recordings.zig", b.fmt( - \\//! Generated by canim's build.zig: the recordings and the sources they ran. - \\pub const Program = struct {{ trace: []const u8, file: []const u8, source: []const u8 }}; + \\//! Generated by canim's build.zig: the recordings, the sources they ran, and the other sources their lines name that the build found (path, text). + \\pub const Program = struct {{ trace: []const u8, file: []const u8, source: []const u8, sources: []const [2][]const u8 = &.{{}} }}; \\{s} - , .{table.items})) }); + , .{table.items})), .imports = source_modules.items }); // ---- Tests: the library's own, then on the real recordings. const test_step = b.step("test", "Unit tests and the scripted runs"); @@ -329,3 +373,16 @@ pub fn build(b: *std.Build) void { } } } + +/// The sources the lines of recording `name` (`trace`) name (but `own`, the program's +/// file) that this machine has, as a module: `list`, each path and text. +/// It reads the debuginfod cache, which the build does not track: run every build. +fn embedSources(b: *std.Build, tool: *std.Build.Step.Compile, name: []const u8, trace: std.Build.LazyPath, own: []const u8) *std.Build.Module { + const run = b.addRunArtifact(tool); + run.addArg("embed"); + run.addFileArg(trace); + run.addArgs(&.{ own, b.graph.zig_exe }); + const dir = run.addOutputDirectoryArg(b.fmt("{s}-sources", .{name})); + run.has_side_effects = true; + return b.createModule(.{ .root_source_file = dir.path(b, "sources.zig") }); +} diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index 48fba99..f8964bd 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -14,7 +14,7 @@ //! an edge never taken), `leave` mid-way, `turn` landing, folds //! 24 s the graph with its rows, as the map draws it (here at half size): //! sort's (panned to its loop, the pc's block annotated) and libc's -//! `open` at its syscall (the blocks never reached folded) +//! `open` at its syscall (the blocks not reached folded) const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -319,7 +319,7 @@ const GraphPages = struct { const u: ui.Ui = .{ .f = f, .at = at }; if (at.t >= 21 and at.t < 24) { title(u, 64, 40, "graph: the blocks lens"); - for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, never taken", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks never reached" }) |p, words| note(u, p[0], p[1], words); + for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, not taken so far", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks not reached" }) |p, words| note(u, p[0], p[1], words); } else if (at.t >= 24 and at.t < 27) { title(u, 64, 40, "graph: with its rows, as on the map (half size)"); } diff --git a/anim/scenes/musl.zig b/anim/scenes/musl.zig new file mode 100644 index 0000000..3112a27 --- /dev/null +++ b/anim/scenes/musl.zig @@ -0,0 +1,84 @@ +//! The `syscalls` scene's `open`, built by Zig against musl, static: no +//! PLT and no GOT, and musl compiled from its source with the program, so +//! the source panel follows the pc all the way down: `main`'s line, musl's +//! `open.c`, `__syscall_cp.c`, and the one line of `syscall_arch.h` that +//! is the `syscall`; the kernel's window at the floor, and back up. +//! +//! How it moves: as `syscalls` (design/motion.md, "A call followed down", +//! "A system call"); each window opened by `descend`, the source fading +//! through to each file it comes to. +const std = @import("std"); +const anim = @import("anim"); +const canim = @import("canim"); +const recordings = @import("recordings"); + +pub const background = canim.background; +pub const scene = anim.Live(frame, struct {}); + +/// The first moment from `from` whose instruction is `text`. +fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 { + var buf: [256]u8 = undefined; + var i = from; + while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.startsWith(u8, here.text, text)) return i; + return rec.end(); +} + +/// The first moment from `from` on line `line` of a file not the program's own. +fn libLine(rec: *canim.Recording, from: u64, line: u32) u64 { + var i = from; + while (i < rec.end()) : (i += 1) if (rec.shown[i].here and rec.shown[i].src != 0 and rec.shown[i].line == line) return i; + return rec.end(); +} + +fn frame(s: *anim.Frame) void { + const rec = canim.open(recordings.musl); + const main = rec.call("main", 0); + var cur = canim.cursor(s, rec, main.enter); + const call_open = on(rec, main.enter, "call"); + const call_cp = on(rec, call_open + 1, "call"); + const jump = on(rec, call_cp, "jmp"); + const crossing = on(rec, jump, "syscall"); + const ret_cp = on(rec, crossing, "ret"); + const ret_open = on(rec, ret_cp + 1, "ret"); + const done = ret_open + 1; + cur.journey(.moment, done); + cur.levels = .{ .source_rows = 8, .fire = .disasm }; + const ctx = canim.context(s, cur, .{ .split = canim.layout.split.beside, .syscalls = true, .descent = true }); + const log = canim.crossing(s, .{ .cursor = cur, .stage = ctx.stage, .focus = true }); + ctx.map.add(s, canim.Crossing{ .cursor = cur, .stage = ctx.map.stage }); + var says: canim.Narrator = .{}; + const t = canim.theme.time; + const joins = ctx.ties(s); + canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, log, joins }); + + says.line(s, "The same `hello`, built by Zig against musl, static."); + cur.walk(s, .line, rec.lineMoment(6, main.enter)); + says.line(s, "`main` calls `open` itself: no PLT stub, no GOT.\nmusl is compiled from its source with the program."); + cur.walk(s, .moment, call_open); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "musl's `open` is open.c: the source follows it."); + cur.hurry(s, .moment, libLine(rec, call_open, 9), .{}); + says.line(s, "Its line 16 calls `__syscall_cp`,\nin __syscall_cp.c."); + cur.hurry(s, .moment, call_cp, .{}); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "Which jumps on to `__syscall_cp_c`, in the same file."); + // __syscall_cp's few rows, and its jump on. + while (cur.moment(s) <= jump) canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "The `syscall` is one line of C, in syscall_arch.h:\nrax holds 2, open's number, and rdi the path."); + cur.hurry(s, .moment, crossing - 2, .{}); + cur.walk(s, .moment, crossing); + says.line(s, "The kernel opens the file and answers in rax: 3."); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + cur.hurry(s, .moment, ret_cp, .{}); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "Back in open.c, which returns the 3 to `main`."); + cur.hurry(s, .moment, ret_open, .{}); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.close(s); +} diff --git a/anim/scenes/syscalls.zig b/anim/scenes/syscalls.zig index e9f0ae5..b795116 100644 --- a/anim/scenes/syscalls.zig +++ b/anim/scenes/syscalls.zig @@ -1,7 +1,8 @@ //! A program that needs the kernel four times: open, read, close, write. //! glibc's `hello`, by instruction from main: `open` followed down (the //! disassembly a `descent`: main's call, the PLT's stub, libc's wrapper, -//! the kernel's window at the floor, and back up), then the other three +//! its source, open64.c, beside it where the build has it (`zig build +//! sources`), the kernel's window at the floor, and back up), then the other three //! stepped over, each crossing under its call. The band is the calls so //! far, as strace writes them. //! @@ -66,7 +67,7 @@ fn frame(s: *anim.Frame) void { canim.descent.step(cur, s, .moment); s.wait(t.phrase_rest); // The wrapper at a run, veiled; its last three instructions walked, named as they run. - says.line(s, "libc's `open` is a wrapper: no source, its own code,\nup to the instruction that calls the kernel."); + says.line(s, "libc's `open` is a wrapper: a few lines of C, open64.c,\nup to the instruction that calls the kernel."); cur.hurry(s, .moment, crossing - 3, .{}); says.line(s, "Its last three set r8 to 0, rdi to AT_FDCWD (-100)\nand rax to 257: openat's number."); cur.walk(s, .moment, crossing); diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig index a6e940c..359305c 100644 --- a/anim/src/Recording.zig +++ b/anim/src/Recording.zig @@ -101,6 +101,15 @@ source: []const u8, /// Its functions, as pardes outlines them, and how many lines it has. functions: []const Function = &.{}, line_count: u32 = 0, +/// Every file the source panel can show: the program's own first (`file`, +/// `source`), then those the build gave it (a library's, by the path its +/// debug info names); and the most lines any of them has. +sources: []const Source = &.{}, +most_lines: u32 = 0, +/// Where the source panel stands after each moment: the line the pc is on +/// where its file is one of `sources`, else the last such line (the +/// deepest frame that has source, a frame up). +shown: []Shown = &.{}, /// The thread shown: the first to make an event. tid: u32 = 0, /// The source line `tid` is on after each moment (line 0: none yet), in @@ -142,17 +151,39 @@ const gpa = std.heap.smp_allocator; /// `frame` runs every frame and asks again. var opened: std.ArrayList(*Recording) = .empty; +/// A file the source panel can show: its path as the debug info names it +/// (the program's own, its bare name), its text and how many lines. +pub const Source = struct { + path: []const u8, + text: []const u8, + lines: u32, + + /// What its tag says: the file's name. + pub fn name(s: Source) []const u8 { + return std.fs.path.basename(s.path); + } +}; + +/// A line of `sources[src]`; `here`: the pc is on it (else a frame up is). +pub const Shown = struct { src: u16 = 0, line: u32 = 0, here: bool = false }; + /// A recording as the build embeds it in `recordings`: a `.ztrace` file's -/// bytes (`trace`), the source it ran (`source`) and its name (`file`). -/// Opened and indexed the first time. +/// bytes (`trace`), the source it ran (`source`) and its name (`file`), +/// and the other sources its lines name that the build found (`sources`: +/// path and text). Opened and indexed the first time. pub fn open(program: anytype) *Recording { for (opened.items) |r| if (r.key == program.trace.ptr) return r; - const r = load(program.trace, program.file, program.source) catch |err| std.debug.panic("canim: cannot open the recording of {s}: {t}", .{ program.file, err }); + const more: []const [2][]const u8 = if (@hasField(@TypeOf(program), "sources")) program.sources else &.{}; + const r = load(program.trace, program.file, program.source, more) catch |err| std.debug.panic("canim: cannot open the recording of {s}: {t}", .{ program.file, err }); opened.append(gpa, r) catch @panic("canim: out of memory"); return r; } -fn load(bytes: []const u8, file: []const u8, source: []const u8) !*Recording { +fn lineCount(text: []const u8) u32 { + return @intCast(std.mem.count(u8, text, "\n") + @intFromBool(text.len > 0 and text[text.len - 1] != '\n')); +} + +fn load(bytes: []const u8, file: []const u8, source: []const u8, more: []const [2][]const u8) !*Recording { // The trace reads a file: give it one in memory. const linux = std.os.linux; const rc = linux.memfd_create("canim", linux.MFD.CLOEXEC); @@ -173,7 +204,12 @@ fn load(bytes: []const u8, file: []const u8, source: []const u8) !*Recording { r.* = .{ .trace = try .open(gpa, std.Io.Threaded.global_single_threaded.io(), path), .key = bytes.ptr, .file = file, .source = source, .arena = .init(gpa) }; if (r.trace.len == 0) return error.EmptyRecording; r.functions = try outline(r.arena.allocator(), source, file); - r.line_count = @intCast(std.mem.count(u8, source, "\n") + @intFromBool(source.len > 0 and source[source.len - 1] != '\n')); + r.line_count = lineCount(source); + const sources = try r.arena.allocator().alloc(Source, 1 + more.len); + sources[0] = .{ .path = file, .text = source, .lines = r.line_count }; + for (more, sources[1..]) |pair, *s| s.* = .{ .path = pair[0], .text = pair[1], .lines = lineCount(pair[1]) }; + r.sources = sources; + for (sources) |s| r.most_lines = @max(r.most_lines, s.lines); try r.index(); return r; } @@ -184,13 +220,32 @@ fn load(bytes: []const u8, file: []const u8, source: []const u8) !*Recording { /// its function is (0: not known); `line`, the line of the program's own /// source it was compiled from (null: another file's, or not known); /// `params`, a direct call's callee's parameter count. -pub fn instruction(r: *const Recording, i: u64, addr: u64, buf: []u8) ?struct { len: u8, back: u8, text: []const u8, line: ?u32, params: ?u8 } { +pub fn instruction(r: *const Recording, i: u64, addr: u64, buf: []u8) ?struct { len: u8, back: u8, text: []const u8, line: ?u32, src: u16 = 0, params: ?u8 } { const found = (zt.telescope.instruction(r.moment(i), addr, buf) catch return null) orelse return null; - var line: ?u32 = null; - if (found.line) |l| if (std.mem.eql(u8, std.fs.path.basename(r.name(l.file)), r.file)) { - line = l.line; - }; - return .{ .len = found.len, .back = found.back, .text = found.text, .line = line orelse r.lineOf(addr), .params = found.params }; + if (found.line) |l| if (r.sourceOf(l.file)) |k| return .{ .len = found.len, .back = found.back, .text = found.text, .line = l.line, .src = k, .params = found.params }; + return .{ .len = found.len, .back = found.back, .text = found.text, .line = r.lineOf(addr), .params = found.params }; +} + +/// The source a line's file (a string id) is, of `sources`: null where the recording has none. +pub fn sourceOf(r: *const Recording, file: u64) ?u16 { + const path = r.name(file); + if (std.mem.eql(u8, std.fs.path.basename(path), r.file)) return 0; + for (r.sources, 0..) |s, k| if (k > 0 and std.mem.eql(u8, s.path, path)) return @intCast(k); + return null; +} + +/// Where the code at `addr` is, as the debug info has it at moment `i`: +/// its file's name and line, whatever the file (a library's too, its +/// source in hand or not); at moment `i`'s own pc, the moment's line. +pub fn where(r: *const Recording, i: u64, addr: u64) ?struct { file: []const u8, line: u32 } { + var buf: [256]u8 = undefined; + if (addr == r.register(i, "rip")) { + const l = r.lines[@min(i, r.end())]; + if (l.line != 0) return .{ .file = std.fs.path.basename(r.name(l.file)), .line = l.line }; + } + const found = (zt.telescope.instruction(r.moment(i), addr, &buf) catch null) orelse return null; + if (found.line) |l| return .{ .file = std.fs.path.basename(r.name(l.file)), .line = l.line }; + return if (r.lineOf(addr)) |l| .{ .file = r.file, .line = l } else null; } /// The source line the instruction at `addr` was compiled from, for a @@ -218,8 +273,9 @@ pub fn ownLine(r: *const Recording, i: u64) ?u32 { return l.line; } -/// Whether the pc at moment `i` is in the program's own source: not in a -/// library's code, a PLT stub, the vDSO (where `own` keeps the last line). +/// Whether the pc at moment `i` is on a line the source panel can show (the +/// program's own, or a library's whose source the build gave): not in a +/// PLT stub, the vDSO, a library without source (where `shown` keeps the last line). pub fn sourced(r: *const Recording, i: u64) bool { var buf: [256]u8 = undefined; const here = r.instruction(i, r.register(i, "rip"), &buf) orelse return r.ownLine(i) != null; @@ -227,14 +283,20 @@ pub fn sourced(r: *const Recording, i: u64) bool { } /// The first line a source panel of `fit` lines shows when the program is -/// on `line`: the whole file when it fits; else a window that has the line -/// in its middle third, and is the same window for every line of that -/// third, so that the text moves only when the program has moved on. -pub fn viewFirst(r: *const Recording, fit: u32, line: u32) u32 { - if (r.line_count <= fit or fit < 3) return 1; +/// on `line` of a file of `lines`: the whole file when it fits; else a +/// window that has the line in its middle third, and is the same window +/// for every line of that third, so that the text moves only when the +/// program has moved on. +pub fn viewFirst(fit: u32, lines: u32, line: u32) u32 { + if (lines <= fit or fit < 3) return 1; const third = fit / 3; const band = (@max(line, 1) - 1) / third; - return std.math.clamp(@as(u32, @intCast(@max(@as(i64, band) - 1, 0))) * third + 1, 1, r.line_count - fit + 1); + return std.math.clamp(@as(u32, @intCast(@max(@as(i64, band) - 1, 0))) * third + 1, 1, lines - fit + 1); +} + +/// The first line of `shown`'s file a source panel of `fit` lines shows. +pub fn shownFirst(r: *const Recording, fit: u32, shown: Shown) u32 { + return viewFirst(fit, r.sources[shown.src].lines, shown.line); } /// Runs of bytes, a list for each moment. @@ -257,6 +319,7 @@ fn index(r: *Recording) !void { const arena = r.arena.allocator(); var lines: std.ArrayList(store.Line) = .empty; var own: std.ArrayList(u32) = .empty; + var shown: std.ArrayList(Shown) = .empty; var reached: std.ArrayList(bool) = .empty; var depths: std.ArrayList(u32) = .empty; var calls: std.ArrayList(Call) = .empty; @@ -429,6 +492,8 @@ fn index(r: *Recording) !void { try lines.append(arena, line); const ours = line.line != 0 and std.mem.eql(u8, std.fs.path.basename(r.name(line.file)), r.file); try own.append(arena, if (ours) line.line else if (own.items.len > 0) own.items[own.items.len - 1] else 0); + const src = if (line.line != 0) r.sourceOf(line.file) else null; + try shown.append(arena, if (src) |k| .{ .src = k, .line = line.line, .here = true } else if (shown.items.len > 0) .{ .src = shown.items[shown.items.len - 1].src, .line = shown.items[shown.items.len - 1].line } else .{}); try reached.append(arena, ours and line_file != null); try touch_list.append(arena, touched); pending = touched; @@ -509,6 +574,7 @@ fn index(r: *Recording) !void { }; r.lines = lines.items; r.own = own.items; + r.shown = shown.items; r.reached = reached.items; r.depths = depths.items; r.calls = calls.items; diff --git a/anim/src/context.zig b/anim/src/context.zig index 55ff9d6..15ece55 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -298,17 +298,17 @@ pub fn callArguments(u: ui.Ui, rec: *const Recording, open: []const Recording.Ca /// not); an older one on its call's line, or where the recording only /// knows a line near its return address, that one. pub fn frameWhere(u: ui.Ui, rec: *const Recording, moment: u64, i: usize, pc: u64) []const u8 { - const line = if (i == 0) rec.ownLine(moment) else callLine(rec, moment, pc) orelse rec.lineOf(pc); - return if (line) |l| u.print("{s}:{d}", .{ rec.file, l }) else ""; + const place = if (i == 0) rec.where(moment, pc) else rec.where(moment, callOf(rec, moment, pc) orelse pc); + return if (place) |l| u.print("{s}:{d}", .{ l.file, l.line }) else ""; } -/// The line of the call that returns to `ret`, where the recording has it: -/// an outer frame is on its call's line, not on the one it returns to. -fn callLine(rec: *const Recording, moment: u64, ret: u64) ?u32 { +/// The call that returns to `ret`, where the recording has it: an outer +/// frame is on its call's line, not on the one it returns to. +fn callOf(rec: *const Recording, moment: u64, ret: u64) ?u64 { var buf: [256]u8 = undefined; const after = rec.instruction(moment, ret, &buf) orelse return null; if (after.back == 0) return null; - return (rec.instruction(moment, ret - after.back, &buf) orelse return null).line; + return ret - after.back; } /// A frame's name: its function's (no offset), or its module's and offset where there is no symbol. @@ -529,10 +529,10 @@ pub const Stack = struct { if (slot_shows <= 0) continue; const vs = v.faded(slot_shows); // A frame's name beside this row: the chain ends a character before it. - var room_w = box.w; + var room_w = map.content(box.w); for (spans[0..n_spans]) |sp| { const mid = (sp.y0 + sp.y1) / 2; - if (mid + m.row / 2 > y and mid - m.row / 2 < y + m.row) room_w = @min(room_w, rows.spanNameX(u, box.w, sp.name) - ui.advance(theme.size.mono.context) + theme.metric.slot.room); + if (mid + m.row / 2 > y and mid - m.row / 2 < y + m.row) room_w = @min(room_w, rows.spanNameX(u, map.content(box.w), sp.name) - ui.advance(theme.size.mono.context) + theme.metric.slot.room); } var gap: f32 = 0; if (lone) |name| { @@ -605,10 +605,11 @@ pub const Stack = struct { u.pinRow(x, top + place * m.row, if (both) &.{ "rsp", "rbp" } else &.{name}, theme.color.region.stack); } for (spans[0..n_spans]) |sp| if (sp.was) |was_name| { - rows.span(v.faded(1 - renamed), box.w, sp.y0, sp.y1, was_name, sp.newest, sp.open); - rows.span(v.faded(renamed), box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); - } else rows.span(v, box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); + rows.span(v.faded(1 - renamed), map.content(box.w), sp.y0, sp.y1, was_name, sp.newest, sp.open); + rows.span(v.faded(renamed), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); + } else rows.span(v, map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); veiled(u, box, now.veil); + if (k.part == .stack) map.strip(.stack, u, box); } /// A slot's role as the catalogue writes it: `saved rbx` (dim); a diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index f0f90ff..9de02c1 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -394,10 +394,19 @@ pub const Cursor = struct { /// 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; + const a = rec.shown[from]; + const b = rec.shown[to]; + // Another file: the source fades through (12 f out, 12 f in). + if (a.src != b.src) return time.move; + // The source's window moves with it: by whole lines, and never a cut; + // farther than its own height, its strip shows where it goes first + // (the window gliding there, 24 f), then the pane fades through. + const fit = c.levels.source_rows; + const windows = [2]u32{ rec.shownFirst(fit, a), rec.shownFirst(fit, b) }; + if (@max(windows[0], windows[1]) - @min(windows[0], windows[1]) > fit) return 2 * time.move; + if (windows[0] != windows[1]) return time.move; 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])); + const rows: f32 = @floatFromInt(@max(a.line, b.line) - @min(a.line, b.line)); return @min(time.step + time.step_per_row * @max(rows - 1, 0), time.step_max); } @@ -540,8 +549,10 @@ fn settled(s: *const anim.Frame, v: anim.Value) f32 { /// (fades out there and in here) and does not slide: a call is not a /// journey across the lines between. pub fn jumps(rec: *const Recording, from: u64, to: u64) bool { - const rows = @max(rec.own[from], rec.own[to]) - @min(rec.own[from], rec.own[to]); - return rec.depths[from] != rec.depths[to] or rows > time.current_jump_rows; + const a = rec.shown[from]; + const b = rec.shown[to]; + const rows = @max(a.line, b.line) - @min(a.line, b.line); + return a.src != b.src or rec.depths[from] != rec.depths[to] or rows > time.current_jump_rows; } /// The cursor at one instant. diff --git a/anim/src/descent.zig b/anim/src/descent.zig index 53d46c5..5dd156c 100644 --- a/anim/src/descent.zig +++ b/anim/src/descent.zig @@ -247,8 +247,10 @@ pub const Descent = struct { // Which rows ran in the last three steps: the trail. const ran = recentRows(a, now, if (going >= 0.5) 0 else 1); - const current_line = rec.own[marked]; - const widen0 = rows.numberRoom(rec.line_count); + // The line the source panel is on, in the file it shows: rows of that file carry their numbers. + const current = rec.shown[marked]; + const current_line = current.line; + const widen0 = rows.numberRoom(rec.most_lines); var covered: usize = 0; var covered_before: usize = 0; var runs: disasm.Runs = .{}; @@ -268,7 +270,7 @@ pub const Descent = struct { .head => |h| { v.fill(.{ .x = theme.stroke.rule, .y = y, .w = box.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); v.text(.sans_medium, theme.size.sans.micro, c.address, y + 18, h.name, t.primary); - v.text(.sans, theme.size.sans.micro, box.w - m.side - v.width(.sans, theme.size.sans.micro, h.note), y + 18, h.note, t.faint); + v.text(.sans, theme.size.sans.micro, map.content(box.w) - m.side - v.width(.sans, theme.size.sans.micro, h.note), y + 18, h.note, t.faint); covered -|= 1; }, .more => |words| { @@ -286,7 +288,7 @@ pub const Descent = struct { }; const lead = ui.shared(addrs[0..n]); const wide = @as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv; - const line = if (row.outside) null else row.line; + const line = if (row.outside or row.src != current.src) null else row.line; const state: disasm.Disasm.State = switch (p.item.state) { // The row the plaque has not reached yet is ahead. .current => if (p.old == null or p.old.?.state != .current) (if (going >= 0.5) .current else .ahead) else if (p.new == null or p.new.?.state != .current) (if (going < 0.5) .current else .ahead) else .current, @@ -309,10 +311,10 @@ pub const Descent = struct { runs.add(line != null and line.? == current_line, y, y + m.row); // A row drawn twice (crossfading) counts once for the arguments that hang over the rows under it. const covers = if (p.twin) covered_before > 0 else covered > 0; - const hangs = dd.insn(v, now, row, y, box.w, widen0 + wide, line, line != last_line, current_line, lead, state, base, covers, .{ addrs[0], addrs[n -| 1] }, null); + const hangs = dd.insn(v, now, row, y, map.content(box.w), widen0 + wide, line, line != last_line, current_line, lead, state, base, covers, .{ addrs[0], addrs[n -| 1] }, null); const w = @min(p.item.window, rules.len - 1); if (rules[w] == null) rules[w] = graph.Rules.init(u.f.scratch, rec, now.marks, .{ row.addr, row.addr }, going); - rules[w].?.draw(v, row.addr, y, box.w, !covers and !row.outside and !dd.noted(v, now, row, y, state, base, .{ addrs[0], addrs[n -| 1] }, null)); + rules[w].?.draw(v, row.addr, y, map.content(box.w), !covers and !row.outside and !dd.noted(v, now, row, y, state, base, .{ addrs[0], addrs[n -| 1] }, null)); if (!p.twin) covered_before = covered; covered = if (p.twin) @max(covered, hangs) else @max(covered -| 1, hangs); last_line = line; @@ -343,10 +345,13 @@ pub const Descent = struct { const yb = p.y + m.row / 2; u.route(&.{ .{ 14, ya }, .{ 14, yb }, .{ c.address - 4, yb } }, t.primary, .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4, .progress = cursors.standard(drawn) }); } - map.window(.disasm, .{ first(after), last(after) }, .{ first(before), last(before) }, cursors.glide(going)); + // Its strip is the deepest window's function's column, that window framed on it. + map.window(.disasm, deepest(after), deepest(before), cursors.glide(going)); if (pc_y[1] orelse pc_y[0]) |y| ties.anchor(u, .pc, .{ .x = 0, .y = y, .w = theme.metric.plaque.pc, .h = m.row }); kernel(u, now, box, under orelse top + @as(f32, @floatFromInt(room -| 3)) * m.row, pc_y[0] orelse pc_y[1]); context.veiled(u, box, now.veil); + // Going down or up, the strip is another function's column: it fades through as the mark lands (24 f). + map.strip(.disasm, if (kind == .same) u else u.faded(map.through(now, now.plan.travel + f(12))), box); } }; @@ -380,15 +385,15 @@ fn windowOf(items: anytype, window: u8) @TypeOf(items) { return if (lo < hi) items[lo..hi] else items[0..0]; } -fn first(l: Layout) u64 { - for (l.items) |it| if (it.what == .insn) return it.key; - return 0; -} - -fn last(l: Layout) u64 { - var out: u64 = 0; +/// The first and last instruction of the deepest window of code. +fn deepest(l: Layout) [2]u64 { + var window: u8 = 0; for (l.items) |it| if (it.what == .insn) { - out = it.key; + window = @max(window, it.window); + }; + var out = [2]u64{ std.math.maxInt(u64), 0 }; + for (l.items) |it| if (it.what == .insn and it.window == window) { + out = .{ @min(out[0], it.key), @max(out[1], it.key) }; }; return out; } @@ -600,7 +605,9 @@ fn headNote(u: ui.Ui, rec: *const Recording, i: u64, l: Level) []const u8 { const module = moduleOf(u, rec, i, l.at); if (std.mem.eql(u8, module, "[vdso]")) return "vdso \u{00b7} the kernel's code, run here"; var buf: [256]u8 = undefined; - if ((@import("ztrace").telescope.instruction(rec.moment(i), l.at, &buf) catch null)) |here| if (here.line != null) return rec.file; + // Its source, where the build gave it: the program's own file, or the library's (its entry's: not the header a line of it is inlined from). + const entry = if (@import("ztrace").telescope.function(rec.moment(i), l.at)) |fun| fun.start else l.at; + if (rec.instruction(i, entry, &buf)) |here| if (here.line != null) return if (here.src == 0) rec.file else u.print("{s} \u{00b7} {s}", .{ module, rec.sources[here.src].name() }); return u.print("{s} \u{00b7} no source", .{module}); } diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 282c66e..be3452f 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -37,8 +37,9 @@ pub const Insn = struct { text: []const u8, /// Past the function's end. outside: bool = false, - /// The line of the program's source it was compiled from. + /// The line it was compiled from, of `src` (`Recording.sources`). line: ?u32 = null, + src: u16 = 0, /// A direct call's callee's parameter count. params: ?u8 = null, /// A graph's row: its block's head carries the address, the row its offset. @@ -72,6 +73,8 @@ pub const Disasm = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + /// On the map its box is as long as what it shows (not where it is a strip's column alone). + measures: bool = true, pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void { const box = d.stage.box(placed, .disasm); @@ -79,13 +82,12 @@ pub const Disasm = struct { const now = d.cursor.now(placed); const rec = d.cursor.rec; const room = theme.layout.rowsIn(box.h); - const above = (room -| 1) / 2; // The mark: it moves last, with the source's and rip. const going = now.advancing(); - const from = listing(u, rec, now.marks[0], room, above); - const to = listing(u, rec, now.marks[1], room, above); + const from = listing(u, rec, now.marks[0], room); + const to = listing(u, rec, now.marks[1], room); // On the map its box is as long as the instructions the recording has round the pc. - if (ui.mapping) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows, (theme.map.disasm_rows - 1) / 2).rows.len); + if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows).rows.len); const pc = [2]u64{ rec.register(now.marks[0], "rip"), rec.register(now.marks[1], "rip") }; // The function's name: one that changes with the advance crossfades over it. @@ -111,6 +113,7 @@ pub const Disasm = struct { var merged: []const Insn = to.rows; var offsets = [2]f32{ 0, 0 }; var fade: f32 = 1; + var faded_through = false; var shown = to; if (pc[0] != pc[1] and going < 1) { if (merge(u, from.rows, to.rows)) |both| { @@ -120,6 +123,7 @@ pub const Disasm = struct { merged = if (going < 0.5) from.rows else to.rows; shown = if (going < 0.5) from else to; fade = @abs(2 * going - 1); + faded_through = true; } } const scroll = std.math.lerp(offsets[0], offsets[1], cursors.glide(going)); @@ -137,7 +141,9 @@ pub const Disasm = struct { // Which moment the current mark stands for, and the three steps before it. const base: usize = if (going >= 0.5) 0 else 1; - const current_line = rec.own[now.marks[if (going >= 0.5) 1 else 0]]; + // The line the source panel is on, in the file it shows: rows of that file carry their numbers. + const current = rec.shown[now.marks[if (going >= 0.5) 1 else 0]]; + const current_line = current.line; // The addresses' shared digits, of the window the mark is in: they // change with the advance, not before it. const lead = blk: { @@ -190,12 +196,12 @@ pub const Disasm = struct { var last_line: ?u32 = null; // 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); + const widen = rows.numberRoom(rec.most_lines); // 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`). var runs: [2]Runs = .{ .{}, .{} }; - const lines_of = [2]u32{ rec.own[now.marks[0]], rec.own[now.marks[1]] }; + const lines_of = [2]Recording.Shown{ rec.shown[now.marks[0]], rec.shown[now.marks[1]] }; var lanes: [2]?f32 = .{ null, null }; // A call's arguments hang in the annotation column of the rows under it. var covered: usize = 0; @@ -206,9 +212,9 @@ pub const Disasm = struct { const rules = graph.Rules.init(u.f.scratch, rec, now.marks, pc, going); for (merged, 0..) |row, j| { const y = top + (@as(f32, @floatFromInt(j)) - scroll) * m.row; - const line = if (row.outside) null else row.line; + const line = if (row.outside or row.src != current.src) null else row.line; // The thread: the current line's runs of instructions. - for (&runs, lines_of) |*r, of| r.add(line != null and line.? == of and mark_shows >= 1, @max(y, top), @min(y, box.h - m.pad)); + for (&runs, lines_of) |*r, of| r.add(!row.outside and row.line != null and row.line.? == of.line and row.src == of.src and mark_shows >= 1, @max(y, top), @min(y, box.h - m.pad)); // A row wholly above the body (the window it scrolls from or to) // does not take the line number from the first row shown. const above_body = y + m.row <= top + 0.5; @@ -222,8 +228,8 @@ pub const Disasm = struct { const was = if (is_pc) null else ran[j]; if (was) |r| lit.trail(c.mark, y, r.k); const state: State = if (is_pc) .current else if (was) |r| .{ .ran = r } else .ahead; - const hangs = d.insn(lit, now, row, y, box.w, widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); - rules.draw(lit, row.addr, y, box.w, covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); + const hangs = d.insn(lit, now, row, y, map.content(box.w), widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); + rules.draw(lit, row.addr, y, map.content(box.w), covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); covered = @max(covered -| 1, hangs); last_line = if (above_body) null else line; if (jumped == row.addr and !is_pc) lanes[0] = y; @@ -231,13 +237,16 @@ pub const Disasm = struct { } const end_y = @min(top + (@as(f32, @floatFromInt(merged.len)) - scroll) * m.row, box.h - m.pad); for (&runs) |*r| r.add(false, end_y, end_y); - threadRuns(u, box.w, runs, if (lines_of[0] == lines_of[1]) 1 else cursors.standard(going)); + threadRuns(u, box.w, runs, if (std.meta.eql(lines_of[0], lines_of[1])) 1 else cursors.standard(going)); if (lanes[0] != null and lanes[1] != null and lanes[0].? != lanes[1].?) { const ya = lanes[0].? + m.row / 2; const yb = lanes[1].? + m.row / 2; lit.route(&.{ .{ 38, ya }, .{ c.jump_lane, ya }, .{ c.jump_lane, yb }, .{ 39, yb } }, theme.color.trail[0], .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4 }); } context.veiled(u, box, now.veil); + // A window going to another column (another function) fades through, and its strip with it. + const column_changes = faded_through and (from.rows.len == 0 or to.rows.len == 0 or !(map.inColumn(.disasm, .{ from.rows[0].addr, from.rows[from.rows.len - 1].addr }) and map.inColumn(.disasm, .{ to.rows[0].addr, to.rows[to.rows.len - 1].addr }))); + map.strip(.disasm, if (column_changes) u.faded(map.through(now, now.plan.travel)) else u, box); } pub const State = union(enum) { @@ -272,7 +281,7 @@ pub const Disasm = struct { const name = if (rec.strings.get(row.addr)) |n| n[0 .. std.mem.lastIndexOfScalar(u8, n, '+') orelse n.len] else ""; const ops = shorn(u, row); const x = if (name.len > 0) annotationX(operandsWidth(u, row, ops, ""), room, @as(f32, @floatFromInt(name.len)) * adv) else room + gap; - operands(u, row, ops, "", base_y, (if (covered) c.annotation else x) - gap - c.operands, t.faint); + operands(u, row, ops, "", base_y, (if (covered) annotationColumn() else x) - gap - c.operands, t.faint); u.text(.mono, size, x, base_y, name, t.faint); return 0; } @@ -286,21 +295,21 @@ pub const Disasm = struct { const pad = row.padding(); u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); // How wide the annotation is, drawn where nothing shows; then where it goes. - const need = d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo); + const need = d.annotation(u.faded(0), now, row, y, annotationColumn(), std.math.inf(f32), state, base, window, echo); // When the operands and the annotation do not both fit: the // annotation moves left (never past its column), then the operands give way. const ops = shorn(u, row); const stub = if (target(row)) |to| pltName(u, rec, to) else ""; var x = room + gap; - if (need.drawn) x = annotationX(operandsWidth(u, row, ops, stub), room, need.end - c.annotation); - operands(u, row, ops, stub, base_y, (if (covered) @min(x, c.annotation) else x) - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + if (need.drawn) x = annotationX(operandsWidth(u, row, ops, stub), room, need.end - annotationColumn()); + operands(u, row, ops, stub, base_y, (if (covered) @min(x, annotationColumn()) else x) - gap - c.operands, if (pad) t.faint else theme.color.code.plain); // Its annotation column holds the arguments of a call above: its own gives way. return if (need.drawn and !covered) d.annotation(u, now, row, y, x, room, state, base, window, echo).hangs else 0; } /// Whether `row` has an annotation: where it has none, its block's visits may be ranged right. pub fn noted(d: *const Disasm, u: ui.Ui, now: cursors.Now, row: Insn, y: f32, state: State, base: usize, window: [2]u64, echo: ?Echo) bool { - return d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo).drawn; + return d.annotation(u.faded(0), now, row, y, annotationColumn(), std.math.inf(f32), state, base, window, echo).drawn; } const Note = struct { drawn: bool = false, end: f32 = 0, hangs: usize = 0 }; @@ -809,6 +818,11 @@ pub fn readsFlags(rec: *const Recording, i: u64) u16 { return flagsRead((Insn{ .addr = pc, .len = here.len, .text = here.text }).mnemonic()); } +/// Where an annotation starts: 564 on the map, 540 in a pane with a strip. +fn annotationColumn() f32 { + return if (ui.mapping) c.annotation else c.annotation - theme.strip.cost / 2; +} + /// The gap between the operands and the annotation: a character. const gap = adv; @@ -853,7 +867,7 @@ pub fn threadRuns(u: ui.Ui, w: f32, runs: [2]Runs, p: f32) void { /// after operands `width` wide: at its column, or a character after the /// operands, or (when both do not fit) where it just fits. fn annotationX(width: f32, room: f32, need: f32) f32 { - return @max(c.annotation, @min(c.operands + width + gap, room - need)); + return @max(annotationColumn(), @min(c.operands + width + gap, room - need)); } /// The row in `rows` (in address order) of the instruction at `addr`. @@ -899,7 +913,7 @@ pub fn bareRow(u: ui.Ui, row: Insn, y: f32) void { const base_y = rows.baseline(y); const pad = row.padding(); u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); - operands(u, row, shorn(u, row), "", base_y, c.annotation - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + operands(u, row, shorn(u, row), "", base_y, annotationColumn() - gap - c.operands, if (pad) t.faint else theme.color.code.plain); } /// Operands as canim draws them (design/README.md, `insn` and `width`): @@ -1056,15 +1070,24 @@ fn full(name: []const u8) ?[]const u8 { /// The window at moment `i`: up to `above` of the function's own /// instructions over the pc (fewer near its start), the pc's, and as many /// after it as fill `room`; past the function's end, `outside`. -fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize, above: usize) Listing { - return listingAt(u, rec, i, rec.register(i, "rip"), room, above); +/// `room` rows round the pc at moment `i`: in a pane, as many above as +/// below; on the map, the function from its start where the pc is in its +/// first three quarters of the rows (a strip's column stays still while +/// the pc walks it), else round the pc. +fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize) Listing { + const pc = rec.register(i, "rip"); + if (ui.mapping) { + const whole = listingAt(u, rec, i, pc, room, room * 3 / 4); + if (whole.pc < room * 3 / 4) return whole; + } + return listingAt(u, rec, i, pc, room, (room -| 1) / 2); } /// The same round the instruction at `pc` (in the window, `Listing.pc`). pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, above: usize) Listing { const out = u.f.scratch.alloc(Insn, room) catch return .{ .rows = &.{}, .pc = 0 }; var buf: [256]u8 = undefined; - var up: [16]Insn = undefined; + var up: [theme.map.disasm_rows]Insn = undefined; var n_up: usize = 0; var addr = pc; while (n_up < @min(above, up.len)) { @@ -1072,7 +1095,7 @@ pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, if (here.back == 0) break; addr -= here.back; const one = rec.instruction(i, addr, &buf) orelse break; - up[n_up] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .line = one.line, .params = one.params }; + up[n_up] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .line = one.line, .src = one.src, .params = one.params }; n_up += 1; } var n: usize = 0; @@ -1083,7 +1106,7 @@ pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, while (n < room) : (n += 1) { const one = rec.instruction(i, addr, &buf) orelse break; if (n > pc_row and one.back == 0) outside = true; - out[n] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .outside = outside, .line = one.line, .params = one.params }; + out[n] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .outside = outside, .line = one.line, .src = one.src, .params = one.params }; addr += one.len; } return .{ .rows = out[0..n], .pc = pc_row }; diff --git a/anim/src/graph.zig b/anim/src/graph.zig index f4e61ea..fa91adb 100644 --- a/anim/src/graph.zig +++ b/anim/src/graph.zig @@ -499,6 +499,8 @@ pub const Rules = struct { v.* = g.nodes[k].visits; }; if (visits[0] == null and visits[1] == null) return; + // For a strip: a tick at the row's top. + if (ui.strokes) return ui.collectMark(u, 0, y, .tick, 1); u.fill(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); if (!free) return; const size = theme.size.mono.context; @@ -1210,7 +1212,7 @@ pub const Map = struct { const module: []const u8 = if (std.mem.indexOfScalar(u8, full, '!')) |bang| full[0..bang] else ""; const folded = g.foldedBlocks(); const title = if (module.len > 0) u.print("disassembly \u{00b7} {s} \u{00b7} {s}", .{ name, module }) else u.print("disassembly \u{00b7} {s}", .{name}); - const note = if (folded > 0) u.print("{s}{d} blocks \u{00b7} folded: {d} never reached", .{ if (rec.sourced(now.stops[0])) "" else "no source \u{00b7} ", g.blocks, folded }) else if (g.exact) "its blocks \u{00b7} visits so far \u{00b7} the edges the run took" else "its blocks \u{00b7} visits so far"; + const note = if (folded > 0) u.print("{s}{d} blocks \u{00b7} folded: {d} not reached", .{ if (rec.sourced(now.stops[0])) "" else "no source \u{00b7} ", g.blocks, folded }) else if (g.exact) "its blocks \u{00b7} visits so far \u{00b7} the edges the run took" else "its blocks \u{00b7} visits so far"; _ = u.panel(box.w, box.h, title, .{ .note = note }); u.clip(.{ .x = theme.stroke.rule, .y = m.tag, .w = box.w - 2 * theme.stroke.rule, .h = room }); defer u.unclip(); @@ -1242,11 +1244,12 @@ pub const Map = struct { const gold = golden(v, k); o.fill(r, theme.color.page); if (n.folded > 0) { - // Blocks the whole recording never reached: one dashed box, its offsets and its count. + // Blocks the whole recording never reached: one dashed box, its offsets and its count, + // said of the run so far (a graph says what has happened by the moment shown, never what will not). o.dashedFrame(r, theme.color.rule, theme.stroke.rule); const last = n.start + n.len - 1; o.text(.mono, size, n.x + m.side, rows.baseline(n.y), o.print("+{x} to +{x}", .{ n.start - g.start, last - g.start }), t.faint); - const words = if (n.folded > 1) o.print("{d} blocks never reached", .{n.folded}) else "never reached"; + const words = if (n.folded > 1) o.print("{d} blocks not reached", .{n.folded}) else "not reached"; const micro = theme.size.sans.micro; o.text(.sans, micro, n.x + w - m.side - o.width(.sans, micro, words), n.y + m.tag - 6, words, t.faint); return; diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index 21db91f..a35f091 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -142,9 +142,12 @@ pub const View = struct { rows: usize, box: Rect, - /// What a sprint cannot show: veiled, over its rows. + /// What a sprint cannot show: veiled, over its rows; then, a dump's, + /// its minimap: its window (published as it drew, `map.window`) on its + /// column of the map, a strip of its own (`map.strip`). pub fn veil(v: View, now: cursors.Now) void { @import("context.zig").veiled(v.u, v.box, now.sprint_veil); + @import("map.zig").strip(.view, v.u, v.box); } }; @@ -281,20 +284,20 @@ fn rowPasses(now: cursors.Now, addr: u64) Passes { fn rowPin(u: ui.Ui, now: cursors.Now, addr: u64, y: f32) f32 { ties.anchor(u, .{ .dump_pin = addr }, .{ .x = 0, .y = y, .w = b.bracket, .h = m.row }); const at = pinned(u, now, addr); - if (at.names.len == 0 or at.shows <= 0) return full_room; - const x = u.faded(at.shows).pinEnd(full_room, y, at.names, rows.ink(rows.regionOf(now.moment(), addr))); + if (at.names.len == 0 or at.shows <= 0) return viewRoom(); + const x = u.faded(at.shows).pinEnd(viewRoom(), y, at.names, rows.ink(rows.regionOf(now.moment(), addr))); return x - adv; } /// Where the reading of a row must end for its pin (`rowPin`), not drawing it. fn rowPinRoom(u: ui.Ui, now: cursors.Now, addr: u64) f32 { const at = pinned(u, now, addr); - if (at.names.len == 0 or at.shows <= 0) return full_room; + if (at.names.len == 0 or at.shows <= 0) return viewRoom(); const p = theme.metric.pin; var shown: []const u8 = ""; for (at.names[0..@min(at.names.len, 3)], 0..) |name, i| shown = if (i == 0) name else u.print("{s} {s}", .{ shown, name }); if (at.names.len > 3) shown = u.print("{s} +{d}", .{ shown, at.names.len - 3 }); - return full_room - u.width(.mono, theme.size.mono.context, shown) - p.row_gap - p.row_head[0] - adv; + return viewRoom() - u.width(.mono, theme.size.mono.context, shown) - p.row_gap - p.row_head[0] - adv; } fn pinned(u: ui.Ui, now: cursors.Now, addr: u64) struct { names: []const []const u8, shows: f32 } { @@ -527,6 +530,7 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { for (at_rows.items) |r| if (addr >= r.addr and addr < r.addr + 16) pointerArcs(&arcs, now, addr, r.y, at_rows.items, 16, .{ y - m.pad, ry + m.pad }, false, field.reads == .protected); }; arcs.draw(u, theme.metric.arc.lanes.len); + if (of.pins) @import("map.zig").window(.view, .{ of.base + 16 * shown[0], of.base + 16 * shown[shown.len - 1] }, .{ of.base + 16 * shown[0], of.base + 16 * shown[shown.len - 1] }, 1); } /// Which of `rs` (rows of fields, the region's last row `last`) a window @@ -699,6 +703,11 @@ pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: * /// The panel's width less its side: where a reading ends with no pin at its row's end. const full_room = theme.layout.state.w - theme.metric.context.side; +/// A view's: less its strip, in the working frame. +fn viewRoom() f32 { + return @import("map.zig").content(full_room); +} + /// `reading`, ending at `room` (a pin at the row's end takes the rest). pub fn readingIn(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field, room: f32) f32 { const size = theme.size.mono.context; diff --git a/anim/src/map.zig b/anim/src/map.zig index 108bafd..ee1d2a1 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -1,11 +1,12 @@ -//! The `map` and the `minimap` (design/README.md, "The map and the +//! The `map` and the panes' minimaps (design/README.md, "The map and the //! minimap"): the working frame unfolded, every panel at its full length on -//! a stage of 3840 by 2160 at the context's type size, and the same at a -//! twentieth in the caption band's right end. Its panels are the working -//! frame's components bound to a stage of their own (`split`), drawn with -//! `ui.mapping` set: then they publish their rows (`row`), and in the -//! working frame their windows (`window`); the map outlines each working -//! window round the rows of its own that it shows. +//! a stage of 3840 by 2160 at the context's type size; and each pane's +//! column of it, small, in a `strip` inside the pane's frame at its right. +//! Its panels are the working frame's components bound to a stage of their +//! own (`split`), drawn with `ui.mapping` set: then they publish their rows +//! (`row`), and in the working frame their windows (`window`); the map +//! outlines each working window round the rows of its own that it shows, +//! and a strip frames it. const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -18,17 +19,25 @@ const Split = theme.layout.Split; pub const Panel = enum { band, view, source, disasm, registers, stack, backtrace }; +/// The panes with a strip, in the order of their places in the strips' images. +pub const stripped = [_]Panel{ .source, .disasm, .stack, .view }; + +fn slotOf(panel: Panel) ?usize { + return std.mem.indexOfScalar(Panel, &stripped, panel); +} + /// `dive`'s frames: the windows bright by `bright`, the rest veiled by /// `move`, when the panels set off (each `apart` after the one before, for -/// `travel`); the veil lifts from `lift` as the map lands at `land`; then -/// `still`. `surface` takes `surface` back. +/// `travel`), each pane's column squeezing into its strip with it; the +/// rest of the map gone by `gone`; the strips and the tags in from `lift`; +/// then `still` from `land`. `surface` takes `surface` back. pub const diving = struct { pub const bright = 6; pub const move = 24; pub const apart = 6; - /// A panel's way, and the map's. + /// A panel's way, and its column's. pub const travel = 60; - pub const fall = 72; + pub const gone = 72; pub const lift = 84; /// The last of seven panels in place: 24 + 6 * 6 + 60. pub const land = 120; @@ -41,14 +50,6 @@ pub fn looking(f: *sk.Frame) bool { return f.host.env("CANIM_MAP") != null; } -/// The dive's frames over which the falling map crossfades into the minimap's drawing. -pub const minimap_lands = [2]f32{ 90, 96 }; - -/// How much of the minimap shows at dive frame `t`: none while the map falls, crossfading in as it lands. -pub fn minimapShows(t: f32) f32 { - return std.math.clamp((t - minimap_lands[0]) / (minimap_lands[1] - minimap_lands[0]), 0, 1); -} - /// Where each working window is on the map this frame, in canvas pixels. var window_px: [7]?[4]f32 = @splat(null); @@ -72,8 +73,8 @@ pub fn measure(panel: Panel, n: usize) void { } /// A working panel shows the rows of keys `now` (first and last), going -/// there from `was`, `p` of the way (eased): its outline on the minimap -/// glides with its scroll, and never jumps. +/// there from `was`, `p` of the way (eased): its outline on the map and +/// its window on its strip glide with its scroll, and never jump. pub fn window(panel: Panel, now: [2]u64, was: [2]u64, p: f32) void { if (!ui.mapping) windows[@intFromEnum(panel)] = .{ .now = now, .was = was, .p = p }; } @@ -89,6 +90,28 @@ pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void { counts[i] += 1; } +/// How much of a pane's strip shows as the pane fades through to another +/// column (another file, another function) over the advance's `travel` +/// seconds: out and in as the pane does, as late as the strip's own +/// drawing is (`time.minimap_lag` and half its fade), so that the column it +/// changes to comes in while the strip is out. +pub fn through(now: @import("cursor.zig").Now, travel: f32) f32 { + if (now.resting() or travel <= 0) return 1; + const lag = theme.time.minimap_lag + @as(f32, theme.time.minimap_fade) / 2.0 / 60.0; + return @abs(2 * std.math.clamp((now.time - now.plan.advance - lag) / travel, 0, 1) - 1); +} + +/// Whether `panel`'s column on its strip has the rows of keys `keys[0]` to `keys[1]`. +pub fn inColumn(panel: Panel, keys: [2]u64) bool { + const col = &atlas.columns[slotOf(panel) orelse return false]; + return col.span(.{ keys[0], keys[0] }) != null and col.span(.{ keys[1], keys[1] }) != null; +} + +/// The width a pane's rows have: its box's, less its strip's in the working frame. +pub fn content(w: f32) f32 { + return if (ui.mapping) w else w - theme.strip.cost; +} + /// The map's boxes for a recording, packed by content: each panel as long /// as its rows (`measure`), the next under it 12 apart (design/README.md, /// "The map and the minimap"). The drawing and the source in the first @@ -113,7 +136,7 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split const source_y = if (lens) band.y + band.h + gap else st.y; // The backtrace as long as the call chain gets over the scene's way: packed once, never repacked under the eye. const bt_rows = @max(want(.backtrace, 0), deepest(rec, way)); - const source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y - gap - panelH(bt_rows)))); + const source_rows: f32 = @floatFromInt(@min(rec.most_lines, theme.layout.rowsIn(foot - source_y - gap - panelH(bt_rows)))); const source: Rect = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) }; const bt_y = source.y + source.h + gap; // The view as long as what draws there has wanted: none where nothing does (a lens drawn alone). @@ -125,7 +148,7 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split const disasm: Rect = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(@min(want(.disasm, theme.map.disasm_rows), theme.map.disasm_rows)) }; // The source longer than its column (69 lines round the current line, or the file whole if shorter) // goes on at the top of the next column's free space, under its tag, `continued`. - const lines_left: f32 = @as(f32, @floatFromInt(@min(rec.line_count, theme.map.disasm_rows))) - source_rows; + const lines_left: f32 = @as(f32, @floatFromInt(@min(rec.most_lines, theme.map.disasm_rows))) - source_rows; const under_disasm = disasm.y + disasm.h + gap; const more_rows = @min(lines_left, @as(f32, @floatFromInt(theme.layout.rowsIn(foot - under_disasm)))); const source_more: Rect = .{ .x = c[1], .y = under_disasm, .w = w, .h = if (more_rows >= 3) panelH(more_rows) else 0 }; @@ -141,7 +164,7 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split if (graph) { const regs: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = panelH(17) }; const nothing: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = 0 }; - const src: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = panelH(@floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - st.y - gap - panelH(bt_rows))))) }; + const src: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = panelH(@floatFromInt(@min(rec.most_lines, theme.layout.rowsIn(foot - st.y - gap - panelH(bt_rows))))) }; const bt: Rect = .{ .x = c[0], .y = src.y + src.h + gap, .w = w, .h = @min(panelH(bt_rows), foot - (src.y + src.h + gap)) }; return .{ .band = .{ .x = c[0], .y = st.y, .w = w, .h = 0 }, @@ -326,18 +349,16 @@ pub const Spare = struct { /// frame's component bound to that stage. pub const Map = struct { stage: *Stage, - parts: [12]Part = undefined, + parts: [14]Part = undefined, n: usize = 0, - /// The panel the narration is in: its window bright on the minimap. - focus: ?Panel = null, /// The working frame, whose panels dive out of their windows. frame: *const Stage, /// Frames into a `dive` (0: the map fills the frame; `diving.land` and - /// on: the working frame, the map its minimap). + /// on: the working frame, each pane's column in its strip). t: anim.Value, /// The map as an object of the scene, under the panels: it shows from `show`. obj: anim.Obj = undefined, - /// Where the program is: for the thread across the gutter, and the minimap's flashes. + /// Where the program is: for the thread across the gutter, and the strips' flashes. cursor: ?@import("cursor.zig").Cursor = null, /// The scene's loupes: open, each is a panel of its own on the map (`Spare`). loupes: [2]?*const @import("loupe.zig").Loupe = .{ null, null }, @@ -345,18 +366,31 @@ pub const Map = struct { /// no line crosses the lanes; the band's window is the whole graph; the /// disassembly's, the rows it shows. graph: bool = false, + /// With `graph`: the stage of the linear disassembly the strip is a + /// column of (the map draws the graph, which is its own whole). + linear: ?*Stage = null, - const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void }; + /// Which drawings a part is in: the map's, the strips' (what they are + /// drawn from: a pane's column, as the linear disassembly the map draws + /// as a graph or a descent), or both. + pub const In = enum { both, map, strips }; + /// `panel`: the box it draws in (null: a lens's, its drawing and its view), for a column squeezing in a dive. + const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void, in: In, panel: ?Panel }; - /// Puts `component` (bound to `m.stage`) on the map, drawn in the order added. + /// Puts `component` (bound to `m.stage`; a lens, unless `addIn` says + /// which panel it is) on the map, drawn in the order added. pub fn add(m: *Map, s: *anim.Frame, component: anytype) void { + m.addIn(s, component, .both, null); + } + + pub fn addIn(m: *Map, s: *anim.Frame, component: anytype, in: In, panel: ?Panel) void { const T = @TypeOf(component); const kept = s.new(component); m.parts[m.n] = .{ .ctx = kept, .draw = struct { fn draw(ctx: *const anyopaque, f: *sk.Frame, at: anim.Placed) void { @as(*const T, @ptrCast(@alignCast(ctx))).draw(f, at); } - }.draw }; + }.draw, .in = in, .panel = panel }; m.n += 1; } @@ -367,7 +401,7 @@ pub const Map = struct { m.add(s, component); } - /// Whether the working frame is in place (the minimap is the map). + /// Whether the working frame is in place. pub fn settled(m: *const Map, at: anim.Placed) bool { return at.value(m.t) >= diving.land; } @@ -385,8 +419,8 @@ pub const Map = struct { /// `dive`: the windows go bright, the rest of the map is veiled; each /// window travels to its panel's place, growing from the map's size to /// the frame's on a logarithm (`glide`, 6 f apart in reading order), - /// as the map falls to the minimap's place; the veil lifts as it lands; - /// then the frame is still. + /// each pane's column squeezing into its strip with it; the rest of + /// the map fades where it is; then the frame is still. pub fn dive(m: *const Map, s: *anim.Frame) void { s.play(.{m.t.to(diving.land + diving.still)}, .{ .seconds = @as(f32, diving.land + diving.still) / 60.0, .ease = anim.ease.linear }); } @@ -400,22 +434,34 @@ pub const Map = struct { s.wait(@as(f32, diving.still) / 60.0); } - /// The map while it is shown or travelling (the scene's first object): - /// filling the frame at half its size, or on its way to the minimap. - /// It sets where each working panel is drawn on the way (`context.zoomed`). + /// The map while it is shown or a dive plays (the scene's first + /// object): filling the frame at half its size, the rest of it fading + /// where it is as each pane's column squeezes into its strip. It sets + /// where each working panel is drawn on the way (`context.zoomed`). pub fn draw(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { const context = @import("context.zig"); context.zoomed = @splat(null); const t = placed.value(m.t); context.thread_shows = std.math.clamp((t - diving.land) / 12, 0, 1); if (t >= diving.land) return; + // The columns' rows, where the strips have them. + m.strips(f, placed); const fixed = @import("words.zig").fixed(f, placed, 0); - const at = m.falling(f, placed, t); - // Large, it is under the panels diving out of it; small (`falling`), over them, into the corner. - if (at.scale >= small * fixed.at.scale) m.copy(f, at, fixed, t) else fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + const at = half(fixed.at); + // The rest of the map veiled from 6 to 24 f, then gone where it is by 72. + var rest = at; + rest.pose.opacity *= 1 - std.math.clamp((t - diving.move) / (diving.gone - diving.move), 0, 1); + m.drawParts(f, rest); + const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1); + (ui.Ui{ .f = f, .at = rest }).veil(theme.map.stage, veil); + // The windows bright from 0 to 6 f, over the veil: a pane's with a strip rides on its column. + const bright = std.math.clamp(t / diving.bright, 0, 1); + m.outline(f, rest, bright, true); // Each working panel: from its window on the map at the start to its place, 6 f after the one before. const back = at.xf.invert(); const working = m.frame.now(placed); + var ways: [7]f32 = @splat(0); // In the frame's reading order, except that a panel drawn over another // sets off first: a panel in its place is never crossed by one still // on its way (the disassembly over the source's foot, the stack over @@ -433,22 +479,117 @@ pub const Map = struct { const lead = (if (whole) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0; const from: Rect = .{ .x = a[0] / 2, .y = a[1] / 2 - lead, .w = box.w * s0, .h = box.h * s0 }; const p = theme.ease(.glide, std.math.clamp((t - diving.move - @as(f32, @floatFromInt(order)) * diving.apart) / diving.travel, 0, 1)); + ways[i] = p; const scale = std.math.pow(f32, s0, 1 - p); const x = std.math.lerp(from.x, box.x, p); const y = std.math.lerp(from.y, box.y, p); - // The tags, rules and lanes come in as the map lands. + // The tags, rules and lanes, and the strips, come in as the map lands. const chrome = std.math.clamp((t - diving.lift) / 12, 0, 1); // Out of a graph the rows and the lens are another form of what the map shows there: they come in on their way. const other = m.graph and (i == @intFromEnum(Panel.disasm) or i == @intFromEnum(Panel.band)); context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .shows = if (other) p else 1 }; }; } + // Each pane's column squeezing into its strip: their places on the map give way first, then they go. + for ([_]bool{ true, false }) |masking| for (stripped) |panel| { + const box = switch (panel) { + inline else => |tag| @field(working, @tagName(tag)), + }; + const gone = 1 - stripShows(panel, t); + // The graph's linear column is not on the map: its strip comes in with the tags. + if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null and !(m.graph and panel == .disasm)) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright }); + }; + } + + /// How much of a pane's strip shows at dive frame `t`: it comes in as + /// its pane lands (12 f), its column going into it. + fn stripShows(panel: Panel, t: f32) f32 { + // The panels' order setting off (`draw`). + const order: f32 = switch (panel) { + .band => 0, + .view => 1, + .disasm => 2, + .stack => 3, + .source => 4, + .registers => 5, + .backtrace => 6, + }; + const lands = diving.move + order * diving.apart + diving.travel; + return std.math.clamp((t - lands + 12) / 12, 0, 1); } - /// Frames into the dive now; 0 (the map filling the frame, as a scene - /// that opens on it shows it) with `CANIM_MAP` in the environment. - fn diveAt(m: *const Map, f: *sk.Frame, placed: anim.Placed) f32 { - return if (looking(f)) 0 else placed.value(m.t); + /// The map filling the frame: half its units. + fn half(at: anim.Placed) anim.Placed { + var out = at; + out.xf = at.xf.mul(.scale(0.5, 0.5)); + out.scale = at.scale * 0.5; + return out; + } + + const Squeeze = struct { masking: bool, shows: f32, veil: f32, bright: f32 }; + + /// A pane's column in a dive, `p` of its way (eased) from its place on + /// the map (`at`: filling the frame) into the pane's strip: the rows the + /// strip shows, its width and its height each on its logarithm (to 36 + /// of 880; to 4 of 24 a row), the text thinning as it lands, the + /// window's outline riding on it. With `masking`, only its place on the + /// map given up (the page over it: the column goes from there). + fn squeeze(m: *const Map, f: *sk.Frame, fixed: ui.Ui, at: anim.Placed, panel: Panel, box: Rect, p: f32, how: Squeeze) void { + const col = &atlas.columns[slotOf(panel).?]; + if (col.n == 0) return; + const st = theme.strip; + const cm = theme.metric.context; + const r = stripRect(box); + const cap = (r.h - st.top - st.foot) / st.pitch; + const win = windowOn(panel, col) orelse return; + const first = firstShown(col, win, cap); + const k = [2]f32{ std.math.pow(f32, 0.5, 1 - p) * std.math.pow(f32, st.across, p), std.math.pow(f32, 0.5, 1 - p) * std.math.pow(f32, @as(f32, st.pitch) / cm.row, p) }; + var offset: f32 = 0; + for (m.column(at, panel)) |b| { + if (b.h <= 0) continue; + const n: f32 = @floatFromInt(theme.layout.rowsIn(b.h)); + defer offset += n; + const lo = @max(first, offset); + const hi = @min(first + cap, @min(offset + n, col.rows)); + if (hi <= lo) continue; + const body = b.y + cm.tag + cm.pad; + const rows_rect: Rect = .{ .x = b.x, .y = body + (lo - offset) * cm.row, .w = b.w, .h = (hi - lo) * cm.row }; + if (how.masking) { + (ui.Ui{ .f = f, .at = at }).fill(.{ .x = rows_rect.x, .y = rows_rect.y - cm.pad, .w = rows_rect.w, .h = rows_rect.h + 2 * cm.pad }, theme.color.page); + continue; + } + // Its first row: where it is on the map, and where it goes in the strip. + const from = [2]f32{ rows_rect.x / 2, rows_rect.y / 2 }; + const to = [2]f32{ r.x + st.left, r.y + st.top + (lo - first) * st.pitch }; + var moved = fixed.at; + moved.xf = fixed.at.xf.mul(.translate(std.math.lerp(from[0], to[0], p), std.math.lerp(from[1], to[1], p))).mul(.scale(k[0], k[1])).mul(.translate(-rows_rect.x, -rows_rect.y)); + moved.scale = fixed.at.scale * k[1]; + moved.pose.opacity *= how.shows; + const u: ui.Ui = .{ .f = f, .at = moved }; + // Its parts clip to their boxes inside it. + u.clip(rows_rect); + const a0 = moved.xf.apply(.{ rows_rect.x, rows_rect.y }); + const a1 = moved.xf.apply(.{ rows_rect.x + rows_rect.w, rows_rect.y + rows_rect.h }); + ui.bound = .{ .x = @round(a0[0]), .y = @round(a0[1]), .w = @round(a1[0]) - @round(a0[0]), .h = @round(a1[1]) - @round(a0[1]) }; + m.drawPanel(f, moved, panel); + // Veiled with the map until it leaves. + u.veil(rows_rect, how.veil * (1 - p)); + ui.bound = null; + u.unclip(); + // The window's outline, where its rows are in this box: from the map's (dim, 2 and 4 out) to the strip's (primary, 2). + const w0 = @max(win[0], lo); + const w1 = @min(win[1] + 1, hi); + if (w1 > w0) { + const a = moved.xf.apply(.{ rows_rect.x, body + (w0 - offset) * cm.row }); + const c = moved.xf.apply(.{ rows_rect.x + rows_rect.w, body + (w1 - offset) * cm.row }); + const line = std.math.lerp(theme.map.outline / 2.0, st.window, p) * fixed.at.scale; + const out = std.math.lerp(theme.map.outline_out / 2.0, 0, p) * fixed.at.scale; + const ink = ui.mix(ui.mix(theme.color.text.dim, theme.color.text.bright, how.bright), theme.color.text.primary, p); + var raw: ui.Ui = .{ .f = f, .at = moved }; + raw.at.xf = .identity; + raw.frame(.{ .x = a[0] - out - line, .y = a[1] - out - line, .w = c[0] - a[0] + 2 * (out + line), .h = c[1] - a[1] + 2 * (out + line) }, ink, line); + } + } } /// With `CANIM_MAP` in the environment every frame is the map filling @@ -457,130 +598,44 @@ pub const Map = struct { /// any scene's map at 1:1 in a 4K export. pub fn wholeMap(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { const fixed = @import("words.zig").fixed(f, placed, 0); - m.copy(f, m.falling(f, placed, 0), fixed, 0); - } - - /// Below this scale (of the frame's) the falling map is drawn over the - /// panels, on its way into the corner, and not under them. - const small = 0.12; - - /// Where the map is at dive frame `t`: from filling the frame (half - /// its units) to the minimap's rect (a twentieth), its scale on the - /// logarithm, its corner going toward the minimap's as the scale does, - /// so that it falls into the corner. - fn falling(m: *const Map, f: *sk.Frame, placed: anim.Placed, t: f32) anim.Placed { - _ = m; - const fixed = @import("words.zig").fixed(f, placed, 0); - const q = theme.ease(.glide, std.math.clamp((t - diving.move) / diving.fall, 0, 1)); - const mini = theme.minimap.box; - const k = std.math.pow(f32, 0.5, 1 - q) * std.math.pow(f32, theme.minimap.scale, q); - const toward = (0.5 - k) / (0.5 - theme.minimap.scale); - var at = fixed.at; - at.xf = at.xf.mul(.translate(toward * mini.x, toward * mini.y)).mul(.scale(k, k)); - at.scale = fixed.at.scale * k; - return at; - } - - /// The falling map, veiled, its windows outlined, and its edge as the - /// minimap's; it crossfades into the minimap's own drawing as it lands. - fn copy(m: *const Map, f: *sk.Frame, at: anim.Placed, fixed: ui.Ui, t: f32) void { - const shows = 1 - minimapShows(t); - if (shows <= 0) return; - const mini = at.scale < small * fixed.at.scale; - if (!mini) fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); - var faded = at; - faded.pose.opacity *= shows; - m.drawAt(f, faded, mini); - // The rest of the map veiled from 6 f to 24 f, lifting as it lands. - const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1) * (1 - std.math.clamp((t - diving.lift) / (minimap_lands[1] - diving.lift), 0, 1)); - (ui.Ui{ .f = f, .at = faded }).veil(theme.map.stage, veil); - // The windows bright from 0 to 6 f, over the veil. - m.outline(f, faded, mini, std.math.clamp(t / diving.bright, 0, 1)); - var edge: ui.Ui = .{ .f = f, .at = faded }; - edge.at.xf = .identity; - const a = at.xf.apply(.{ 0, 0 }); - const b = at.xf.apply(.{ 2 * theme.canvas.width, 2 * theme.canvas.height }); - const q = std.math.clamp((0.5 * fixed.at.scale - at.scale) / ((0.5 - theme.minimap.scale) * fixed.at.scale), 0, 1); - edge.faded(q).frame(.{ .x = a[0] - 1, .y = a[1] - 1, .w = b[0] - a[0] + 2, .h = b[1] - a[1] + 2 }, theme.color.rule, @max(1, fixed.at.scale)); + fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + m.drawAt(f, half(fixed.at)); } - /// Small, the falling map over the working panels (the minimap's drawer calls it). - pub fn fallingOver(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { - const t = placed.value(m.t); - if (t >= minimap_lands[1]) return; - const fixed = @import("words.zig").fixed(f, placed, 0); - const at = m.falling(f, placed, t); - if (at.scale >= small * fixed.at.scale) return; - // Its ground, so that it reads over what it passes. - var ground: ui.Ui = .{ .f = f, .at = at }; - ground.at.pose.opacity *= 1 - minimapShows(t); - ground.fill(.{ .x = 0, .y = 0, .w = 2 * theme.canvas.width, .h = 2 * theme.canvas.height }, theme.color.page); - m.copy(f, at, fixed, t); + /// The map in `at`'s transform (the map's units), and the working + /// frame's windows outlined on it: a 2-unit `dim` frame 4 out. + pub fn drawAt(m: *const Map, f: *sk.Frame, at: anim.Placed) void { + m.drawParts(f, at); + m.outline(f, at, 0, false); } - /// The map in `at`'s transform (the map's units), and the working - /// frame's windows outlined on it: a 2-unit `dim` frame 4 out; on the - /// minimap (`mini`) a pixel of primary, the focused one 1.5. - pub fn drawAt(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool) void { - m.drawParts(f, at, mini); - m.outline(f, at, mini, 0); + /// The parts that draw `panel` (a dump: the lens's), as the map draws them. + fn drawPanel(m: *const Map, f: *sk.Frame, at: anim.Placed, panel: Panel) void { + ui.mapping = true; + defer ui.mapping = false; + for (m.parts[0..m.n]) |p| if (p.in != .strips and (p.panel == panel or (p.panel == null and panel == .view))) p.draw(p.ctx, f, at); } - fn drawParts(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool) void { + fn drawParts(m: *const Map, f: *sk.Frame, at: anim.Placed) void { ui.mapping = true; - ui.strokes = mini; counts = @splat(0); - for (m.parts[0..m.n]) |p| p.draw(p.ctx, f, at); - if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at), mini); + for (m.parts[0..m.n]) |p| if (p.in != .strips) p.draw(p.ctx, f, at); + if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at)); ui.mapping = false; - ui.strokes = false; } /// The thread on the map: the current line and the pc's row, joined - /// across the gutter between source and disassembly (x 1008), gold; on - /// the minimap a stroke a pixel wide. And there, a mark no working - /// window shows `flash`es: a ring 8 across drawing out to 14 and gone - /// (12 f), with the strike (the minimap's own time, 6 f behind). - fn thread(m: *const Map, f: *sk.Frame, at: anim.Placed, now: @import("cursor.zig").Now, mini: bool) void { + /// across the gutter between source and disassembly (x 1008), gold. + fn thread(m: *const Map, f: *sk.Frame, at: anim.Placed, now: @import("cursor.zig").Now) void { _ = m; const rec = now.rec; - const k = at.scale; var raw: ui.Ui = .{ .f = f, .at = at }; raw.at.xf = .identity; const marked = now.marked(); - const line = rows_of(.source, rec.own[marked]); - const pc = rows_of(.disasm, rec.register(marked, "rip")); - if (line != null and pc != null) { - const a = line.?; - const b = pc.?; - const lane = at.xf.apply(.{ 1008, 0 })[0]; - const w = if (mini) @max(1, k / theme.minimap.scale) else theme.stroke.line * k; - const gold = theme.mark(.current).solid; - raw.route(&.{ .{ a[2], (a[1] + a[3]) / 2 }, .{ lane, (a[1] + a[3]) / 2 }, .{ lane, (b[1] + b[3]) / 2 }, .{ b[0], (b[1] + b[3]) / 2 } }, gold, .{ .width = w, .head = null, .radius = 0 }); - } - if (!mini or !now.walking()) return; - // A mark no working window shows: a word struck or read, on the - // stack (its own column or continued) or in memory the map draws - // (the view's dump, the dumps round the pointers), flashes where the - // map has it, in the mark's colour. - const since = now.since(.memory, 0); - const p = since / (12.0 / 60.0); - if (p < 0 or p > 1) return; - const marks = [2]struct { spans: []const Recording.Span, ink: u24 }{ - .{ .spans = rec.written(now.stops[1], now.stops[0]), .ink = theme.color.struck }, - .{ .spans = rec.read(now.stops[1], now.stops[0]), .ink = theme.mark(.read).solid }, - }; - for (marks) |mark| for (mark.spans) |span| { - // Where the map has it: the stack's word, or the 16 bytes of a dump's row. - const word = span.addr & ~@as(u64, 7); - const sixteen = span.addr & ~@as(u64, 15); - const panel: Panel, const key: u64 = if (rows_of(.stack, word) != null) .{ .stack, word } else .{ .view, sixteen }; - const box = rows_of(panel, key) orelse continue; - if (windows[@intFromEnum(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue; - const c = ui.Vec{ (box[0] + box[2]) / 2, (box[1] + box[3]) / 2 }; - const r = std.math.lerp(@as(f32, 4), 7, p) * k / theme.minimap.scale; - raw.faded(1 - p).disc(c, r, null, ui.rgb(mark.ink), @max(1, k / theme.minimap.scale)); - }; + const line = rows_of(.source, rec.shown[marked].line) orelse return; + const pc = rows_of(.disasm, rec.register(marked, "rip")) orelse return; + const lane = at.xf.apply(.{ 1008, 0 })[0]; + raw.route(&.{ .{ line[2], (line[1] + line[3]) / 2 }, .{ lane, (line[1] + line[3]) / 2 }, .{ lane, (pc[1] + pc[3]) / 2 }, .{ pc[0], (pc[1] + pc[3]) / 2 } }, theme.mark(.current).solid, .{ .width = theme.stroke.line * at.scale, .head = null, .radius = 0 }); } /// The top and bottom of the map's rows of panel `i` with keys from `keys[0]` to `keys[1]`, in canvas pixels. @@ -606,8 +661,9 @@ pub const Map = struct { } /// The working windows' outlines on the map in `at`, `bright` of the way - /// from `dim` to bright; where they are is kept (`window_px`). - fn outline(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool, bright: f32) void { + /// from `dim` to bright; where they are is kept (`window_px`). With + /// `riding`, a pane's with a strip is not drawn: it rides on its column (`squeeze`). + fn outline(m: *const Map, f: *sk.Frame, at: anim.Placed, bright: f32, riding: bool) void { var raw: ui.Ui = .{ .f = f, .at = at }; raw.at.xf = .identity; const k = at.scale; @@ -628,116 +684,439 @@ pub const Map = struct { const was = spanOf(i, win.was) orelse is; if (is orelse was) |to| { const from = was orelse to; - // On the minimap each end on whole pixels: crisp at rest, between them only while it glides. - const snap = struct { - fn of(v: f32, on: bool) f32 { - return if (on) @round(v) else v; - } - }.of; - r[1] = std.math.lerp(snap(from[0], mini), snap(to[0], mini), win.p); - r[3] = std.math.lerp(snap(from[1], mini), snap(to[1], mini), win.p); + r[1] = std.math.lerp(from[0], to[0], win.p); + r[3] = std.math.lerp(from[1], to[1], win.p); shown = true; // In a graph the rows a window shows are in blocks: round them, not the panel's width. if (m.graph and panel == .disasm) if (boxOf(i, win.now)) |round| { const was_box = boxOf(i, win.was) orelse round; - r[0] = std.math.lerp(snap(was_box[0], mini), snap(round[0], mini), win.p); - r[2] = std.math.lerp(snap(was_box[2], mini), snap(round[2], mini), win.p); + r[0] = std.math.lerp(was_box[0], round[0], win.p); + r[2] = std.math.lerp(was_box[2], round[2], win.p); }; } } - // On the minimap on whole pixels (a window's ends already are, at rest). - if (mini) { - r[0] = @round(r[0]); - r[2] = @round(r[2]); - if (windows[i] == null) { - r[1] = @round(r[1]); - r[3] = @round(r[3]); - } - } window_px[i] = if (shown) r else null; - if (shown) { - const focus = m.focus == panel; - // On the minimap a pixel of the frame: `k` is the canvas's pixels to a map unit. - const w = if (mini) @as(f32, if (focus) 1.5 else 1) * k / theme.minimap.scale else theme.map.outline * k; - const out = if (mini) w else theme.map.outline_out * k; + const rides = riding and slotOf(panel) != null and !(m.graph and panel == .disasm); + if (shown and !rides) { + const w = theme.map.outline * k; + const out = theme.map.outline_out * k; const ring: Rect = .{ .x = r[0] - out, .y = r[1] - out, .w = r[2] - r[0] + 2 * out, .h = r[3] - r[1] + 2 * out }; - const ink = ui.mix(if (mini) theme.color.text.primary else theme.color.text.dim, theme.color.text.bright, bright); - // On the minimap not snapped to pixels: a window that glides moves a pixel over many frames, not in one. - if (mini) { - const pen = raw.at.pen(.{ .fill = ink }); - for ([4]sk.math.Rect{ .{ .x = ring.x, .y = ring.y, .w = ring.w, .h = w }, .{ .x = ring.x, .y = ring.y + ring.h - w, .w = ring.w, .h = w }, .{ .x = ring.x, .y = ring.y + w, .w = w, .h = ring.h - 2 * w }, .{ .x = ring.x + ring.w - w, .y = ring.y + w, .w = w, .h = ring.h - 2 * w } }) |edge| sk.draw.rect(f, edge, pen); - } else raw.frame(ring, ink, if (bright > 0) w * 1.5 else w); + raw.frame(ring, ui.mix(theme.color.text.dim, theme.color.text.bright, bright), if (bright > 0) w * 1.5 else w); } } } } -}; -/// The minimap's drawings, a frame apart, and what they are averaged into: -/// the host's images, made once for a size. -/// shortcut: a process-wide cache of host images, for one player at a time; two at once want it in their Session. -var fades: struct { w: u32 = 0, h: u32 = 0, images: [theme.time.minimap_fade + 1]sk.Image = undefined } = .{}; + /// The boxes on the map of `panel`'s column, in order: the second where + /// it goes on (`continued`), or none. + fn column(m: *const Map, at: anim.Placed, panel: Panel) [2]Rect { + const sp = m.stage.now(at); + const none: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; + return switch (panel) { + .source => .{ sp.source, sp.source_more }, + .disasm => .{ if (m.linear) |l| l.now(at).disasm else sp.disasm, none }, + .stack => .{ sp.stack, sp.more }, + .view => .{ sp.view, none }, + else => .{ none, none }, + }; + } + + /// The strips, drawn once a frame: the map drawn for them (`collect`) + /// six times, each from the cursor's mirror a frame later (6 to 11 f + /// behind: `Cursor.lagInto`) and with the panes' windows as they were + /// as long ago (`past`), each into an image of every strip as it shows + /// (its rows round its window, the window framed), and those averaged: + /// every change on a strip, a window gliding or its column scrolling + /// too, fades in over 6 f from 6 f after its onset, and nothing on it + /// moves a pixel in a frame. + fn strips(m: *const Map, f: *sk.Frame, at: anim.Placed) void { + if (atlas.frame == f.in.frame and atlas.map == m) return; + atlas.frame = f.in.frame; + atlas.map = m; + f.clip(null); + const st = theme.strip; + const k = @import("words.zig").fixed(f, at, 0).at.scale; + const w: u32 = @intFromFloat(@ceil(@as(f32, stripped.len * st.w) * k)); + const h: u32 = @intFromFloat(@ceil(theme.canvas.stage.h * k)); + if (atlas.w != w or atlas.h != h) { + if (atlas.w != 0) for (atlas.images) |img| f.host.freeImage(img); + for (&atlas.images) |*img| img.* = f.host.newImage(w, h); + atlas.w = w; + atlas.h = h; + } + if (atlas.scrap == null) atlas.scrap = f.host.newImage(4, 4); + atlas.k = k; + // After a seek the windows kept are of another time. + if (f.in.jumped) past = @splat(.{}); + past[f.in.frame % past.len] = .{ .frame = f.in.frame, .windows = windows }; + // Each pane's strip as high as its box has it now (a relayout moves them). + const working = m.frame.now(at); + var heights: [stripped.len]f32 = undefined; + for (stripped, &heights) |panel, *sh| sh.* = switch (panel) { + inline else => |tag| stripRect(@field(working, @tagName(tag))).h, + }; + const values = f.scratch.dupe(f32, at.values) catch return; + var placed = at; + placed.values = values; + placed.xf = .identity; + placed.scale = 1; + placed.pose.opacity = 1; + const n = theme.time.minimap_fade; + var weights: [n]f32 = @splat(0); + var made: usize = 0; + const chrome = ui.chrome; + defer ui.chrome = chrome; + var cols: [stripped.len]Column = undefined; + for (0..n) |lag| { + const then = pastWindows(f.in.frame, @as(u64, @intFromFloat(theme.time.minimap_lag * 60)) + lag); + // A mirror the same as the one before draws the same (its windows too): its drawing counts twice. + const moved = lag > 0 and !std.meta.eql(then, pastWindows(f.in.frame, @as(u64, @intFromFloat(theme.time.minimap_lag * 60)) + lag - 1)); + const differs = (if (m.cursor) |c| c.lagInto(values, lag) else lag == 0) or moved; + if (differs) { + m.collect(f, placed); + m.columns(placed, &cols); + if (made == 0) atlas.columns = cols; + f.target(atlas.images[made]); + f.clear(ui.rgb(theme.color.well)); + m.render(f, placed, k, &cols, then, heights); + made += 1; + } + weights[made - 1] += 1; + } + // Averaged: each drawing over those before it at its share of the drawings so far. + const whole: sk.Rect = .{ .x = 0, .y = 0, .w = @floatFromInt(w), .h = @floatFromInt(h) }; + f.target(atlas.images[n]); + var so_far: f32 = 0; + for (atlas.images[0..made], weights[0..made]) |img, weight| { + so_far += weight; + f.image(img, whole, .{ .tint = sk.Color.white.alphaFloat(weight / so_far) }); + } + f.target(.none); + } + + /// The map drawn for the strips, into nothing that shows: its parts + /// publish their rows and the text, marks and arcs they draw are + /// collected (`ui.collected`), with the flashes of the moment. + fn collect(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { + f.target(atlas.scrap.?); + ui.mapping = true; + ui.strokes = true; + counts = @splat(0); + ui.collected.reset(); + for (m.parts[0..m.n]) |p| if (p.in != .map) p.draw(p.ctx, f, placed); + f.clip(null); + n_flashes = 0; + if (m.cursor) |c| flash(c.now(placed)); + ui.mapping = false; + ui.strokes = false; + } -/// The minimap: `m` at a twentieth in the caption band's right end, still -/// while the camera moves; the page under it, framed a pixel in `rule`. -/// Every change on it fades in over `time.minimap_fade` frames from -/// `time.minimap_lag` after its onset: it is the average of that many -/// drawings, each from the cursor's mirror a frame later (`Cursor.lagInto`), -/// so a stroke that changes, a mark that comes and the gold that moves on -/// all fade, and a window's glide is smoothed, never stepped. -pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void { - var shown = at; - shown.pose.opacity *= minimapShows(m.diveAt(f, at)); - if (shown.pose.opacity <= 0) return; - const fixed = @import("words.zig").fixed(f, shown, 0); - const box = theme.minimap.box; - const a = fixed.at.xf.apply(.{ box.x, box.y }); - const b = fixed.at.xf.apply(.{ box.x + box.w, box.y + box.h }); - const px: sk.Rect = .{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) }; - const w: u32 = @intFromFloat(@max(px.w, 1)); - const h: u32 = @intFromFloat(@max(px.h, 1)); - if (fades.w != w or fades.h != h) { - if (fades.w != 0) for (fades.images) |img| f.host.freeImage(img); - for (&fades.images) |*img| img.* = f.host.newImage(w, h); - fades.w = w; - fades.h = h; + /// Each strip's column, from the map just collected: its rows' keys and places. + fn columns(m: *const Map, at: anim.Placed, out: *[stripped.len]Column) void { + for (stripped, out) |panel, *c| { + c.* = .{}; + const boxes = m.column(at, panel); + const i = @intFromEnum(panel); + for (rows[i][0..counts[i]]) |rw| { + if (c.n == c.keys.len) break; + const place = spotIn(boxes, rw.box[0] + 1, rw.box[1], false) orelse continue; + c.keys[c.n] = rw.key; + c.at[c.n] = place.r; + c.n += 1; + c.rows = @max(c.rows, @round(place.r) + 1); + } + } } - // Each drawing in an image of its own, the page under it, in the image's pixels. - var placed = fixed.at; - placed.pose.opacity = 1; - placed.xf = sk.math.Affine.translate(-px.x, -px.y).mul(fixed.at.xf).mul(.translate(box.x, box.y)).mul(.scale(theme.minimap.scale, theme.minimap.scale)); - placed.scale = fixed.at.scale * theme.minimap.scale; - const values = f.scratch.dupe(f32, at.values) catch return; - placed.values = values; - // Its drawings outline the windows in their images' pixels: where the - // falling map has them (a dive's panels set off from there) is kept. - const falling_px = window_px; - defer window_px = falling_px; - const n = theme.time.minimap_fade; - var weights: [n]f32 = @splat(0); - var made: usize = 0; - for (0..n) |k| { - // A mirror the same as the one before draws the same: its drawing counts twice. - const differs = if (m.cursor) |c| c.lagInto(values, k) else k == 0; - if (differs) { - f.target(fades.images[made]); - f.clear(ui.rgb(theme.color.page)); - m.drawAt(f, placed, true); - made += 1; + + /// Every strip, as it shows, into the image in hand, a strip's width + /// each (`heights`: as high as each is): its column's rows round its + /// window (`then`: the panes' windows as long ago as the drawing is), + /// each run of text a stroke from where it starts, as long as it is, in + /// its ink 65% of the way from the page; at a row's left its marks (the + /// current row gold, a strike vermilion, a read in read's colour, held + /// a vermilion 2 by 2); an arc with an end off its pane's window a + /// 2-unit line in its ink down the left edge; a block's first row a + /// tick; a flash's ring; three faint dots at an end where the column + /// goes on; the window framed 2 in primary. + fn render(m: *const Map, f: *sk.Frame, at: anim.Placed, k: f32, cols: *const [stripped.len]Column, then: [7]?Window, heights: [stripped.len]f32) void { + const st = theme.strip; + var boxes: [stripped.len][2]Rect = undefined; + for (stripped, &boxes) |panel, *b| b.* = m.column(at, panel); + // Each strip's window and the first row it shows. + var wins: [stripped.len]?[2]f32 = undefined; + var firsts: [stripped.len]f32 = undefined; + var caps: [stripped.len]f32 = undefined; + for (stripped, cols, &wins, &firsts, &caps, heights) |panel, *col, *win, *first, *cap, sh| { + cap.* = (sh - st.top - st.foot) / st.pitch; + win.* = spanOf2(then[@intFromEnum(panel)], col); + // Whole rows at rest: its strokes on the image's pixels. + first.* = firstShown(col, win.* orelse .{ 0, 0 }, @floor(cap.*)); } - weights[made - 1] += 1; + // Where row `r` of strip `slot` is drawn, and whether it shows. + const Row = struct { + fn y(fs: [stripped.len]f32, slot: usize, r: f32) f32 { + return st.top + (r - fs[slot]) * st.pitch; + } + fn shows(fs: [stripped.len]f32, cs: [stripped.len]f32, slot: usize, r: f32) bool { + return r > fs[slot] - 0.75 and r < fs[slot] + cs[slot] - 0.25; + } + }; + const c = &ui.collected; + const page = ui.rgb(theme.color.page); + for (c.runs[0..c.n_runs]) |run| for (boxes, 0..) |pair, slot| { + const spot = spotIn(pair, run.x0, run.y, true) orelse continue; + if (Row.shows(firsts, caps, slot, spot.r)) { + const ink = ui.mix(page, run.ink.alphaFloat(1), st.ink).alphaFloat(@as(f32, @floatFromInt(run.ink.a)) / 255); + pixels(f, k, slot, st.left + spot.x * st.across, Row.y(firsts, slot, spot.r), (run.x1 - run.x0) * st.across, st.stroke, ink); + } + break; + }; + // The marks of each row: the most of each kind it has, side by side in the catalogue's order. + var shows: [stripped.len][atlas_rows][4]f32 = @splat(@splat(@splat(0))); + var place: [stripped.len][atlas_rows]f32 = undefined; + for (c.marks[0..c.n_marks]) |mk| for (boxes, 0..) |pair, slot| { + const spot = spotIn(pair, mk.x, mk.y, mk.kind != .tick) orelse continue; + if (!Row.shows(firsts, caps, slot, spot.r)) break; + if (mk.kind == .tick) { + pixels(f, k, slot, 0, Row.y(firsts, slot, spot.r) - 1, st.left + st.mark, 2, ui.rgb(theme.color.rule).alphaFloat(mk.shows)); + break; + } + const near = @round(spot.r); + if (near < 0 or near >= atlas_rows) break; + const i: usize = @intFromFloat(near); + shows[slot][i][@intFromEnum(mk.kind)] = @max(shows[slot][i][@intFromEnum(mk.kind)], @min(mk.shows, 1)); + place[slot][i] = spot.r; + break; + }; + for (shows, place, 0..) |of_slot, places, slot| for (of_slot, places) |kinds, r| { + var x: f32 = st.left; + const y = Row.y(firsts, slot, r); + const write = ui.rgb(theme.mark(.write).solid); + if (kinds[0] > 0) { + pixels(f, k, slot, x, y, st.mark, st.mark, ui.rgb(theme.mark(.current).solid).alphaFloat(kinds[0])); + x += st.mark_apart; + } + if (kinds[1] > 0) { + pixels(f, k, slot, x, y, st.mark, st.mark, write.alphaFloat(kinds[1])); + x += st.mark_apart; + } else if (kinds[3] > 0) { + pixels(f, k, slot, x + 1, y + 1, st.held, st.held, write.alphaFloat(kinds[3])); + x += st.mark_apart; + } + if (kinds[2] > 0) pixels(f, k, slot, x, y, st.mark, st.mark, ui.rgb(theme.mark(.read).solid).alphaFloat(kinds[2])); + }; + for (c.arcs[0..c.n_arcs]) |arc| for (boxes, 0..) |pair, slot| { + const a = spotIn(pair, arc.x, arc.from, true) orelse continue; + const b = spotIn(pair, arc.x, arc.to, true) orelse break; + // An arc with both ends in its pane's window is there: only one with an end off it is here. + const win = wins[slot] orelse break; + const in = struct { + fn of(r: f32, w: [2]f32) bool { + return r > w[0] - 0.5 and r < w[1] + 0.5; + } + }.of; + if (in(a.r, win) and in(b.r, win)) break; + const y0 = @max(Row.y(firsts, slot, @min(a.r, b.r)) + 1, st.top); + const y1 = @min(Row.y(firsts, slot, @max(a.r, b.r)) + 2, st.top + caps[slot] * st.pitch); + if (y1 > y0) pixels(f, k, slot, 0, y0, 2, y1 - y0, arc.ink); + break; + }; + // A flash: a ring 8 across drawing out to 14, and gone. + var scaled = at; + scaled.xf = sk.math.Affine.scale(k, k); + scaled.scale = k; + const u: ui.Ui = .{ .f = f, .at = scaled }; + for (flashes[0..n_flashes]) |fl| { + const slot = slotOf(fl.panel).?; + const r = (cols[slot].span(.{ fl.key, fl.key }) orelse continue)[0]; + if (!Row.shows(firsts, caps, slot, r)) continue; + u.faded(1 - fl.p).disc(.{ @as(f32, @floatFromInt(slot)) * st.w + st.left + 7, Row.y(firsts, slot, r) + 1.5 }, std.math.lerp(@as(f32, 4), 7, fl.p), null, ui.rgb(fl.ink), 2); + } + for (cols, firsts, caps, wins, 0..) |*col, first, cap, win, slot| { + const left = @as(f32, @floatFromInt(slot)) * st.w; + // Where it goes on: three faint dots, 2 by 2, 6 apart, coming as the column's end leaves (over a row). + const shown = @min(cap, col.rows - first); + for ([2]f32{ std.math.clamp(first, 0, 1), std.math.clamp(col.rows - first - shown, 0, 1) }, [2]f32{ 0, st.top + cap * st.pitch + 1 }) |q, y| if (q > 0) { + for (0..3) |i| pixels(f, k, slot, 13 + 6 * @as(f32, @floatFromInt(i)), y, 2, 2, ui.rgb(theme.color.text.faint).alphaFloat(q)); + }; + // Its window: the brightest thing on it. + if (win) |w| { + const top = st.top + (w[0] - first) * st.pitch - st.window; + const bottom = st.top + (w[1] - first + 1) * st.pitch + 1; + u.frame(.{ .x = left, .y = top, .w = st.w, .h = bottom - top }, theme.color.text.primary, st.window); + } + } + } +}; + +/// The most rows a column has in the strips' images. +const atlas_rows = 160; + +/// A pane's column of the map as its strip draws it: each of its rows' +/// key and place (rows from the column's top, continuous where the map's +/// panel scrolls), and how many rows the column has. +const Column = struct { + n: usize = 0, + keys: [atlas_rows]u64 = undefined, + at: [atlas_rows]f32 = undefined, + rows: f32 = 0, + + /// The first and last place of its rows with keys `keys[0]` to `keys[1]`. + fn span(c: *const Column, keys: [2]u64) ?[2]f32 { + var lo = std.math.inf(f32); + var hi = -std.math.inf(f32); + for (c.keys[0..c.n], c.at[0..c.n]) |key, at| if (key >= keys[0] and key <= keys[1]) { + lo = @min(lo, at); + hi = @max(hi, at); + }; + return if (lo <= hi) .{ lo, hi } else null; } - // Averaged: each drawing over those before it at its share of the drawings so far. - const whole: sk.Rect = .{ .x = 0, .y = 0, .w = px.w, .h = px.h }; - f.target(fades.images[n]); - var so_far: f32 = 0; - for (fades.images[0..made], weights[0..made]) |img, weight| { - so_far += weight; - f.image(img, whole, .{ .tint = sk.Color.white.alphaFloat(weight / so_far) }); +}; + +/// The strips' images: one for each lagging drawing of the map +/// (`time.minimap_fade`) and their average, last; each strip a column of +/// them, its column whole from its top. +/// shortcut: a process-wide cache of host images, for one player at a time; two at once want it in their Session. +var atlas: struct { + w: u32 = 0, + h: u32 = 0, + images: [theme.time.minimap_fade + 1]sk.Image = undefined, + /// What a collecting drawing draws into: nothing of it shows. + scrap: ?sk.Image = null, + /// The frame they were made for, and of which map. + frame: u64 = std.math.maxInt(u64), + map: ?*const Map = null, + /// Pixels a unit. + k: f32 = 1, + columns: [stripped.len]Column = @splat(.{}), +} = .{}; + +/// The panes' windows in the frames before, for the strips' lagging drawings (`Map.strips`). +var past: [16]struct { frame: u64 = std.math.maxInt(u64), windows: [7]?Window = @splat(null) } = @splat(.{}); + +/// The panes' windows `back` frames before frame `now` (where they were not kept, as they are). +fn pastWindows(now: u64, back: u64) [7]?Window { + const e = past[(now -% back) % past.len]; + return if (e.frame == now -% back) e.windows else windows; +} + +/// Where a window is on a column: its first and last row, between where it +/// was and where it is, as far as its scroll had gone. +fn spanOf2(maybe: ?Window, col: *const Column) ?[2]f32 { + const win = maybe orelse return null; + const is = col.span(win.now) orelse return null; + const was = col.span(win.was) orelse is; + return .{ std.math.lerp(was[0], is[0], win.p), std.math.lerp(was[1], is[1], win.p) }; +} + +/// The map whose columns the strips are (`context` sets it). +/// shortcut: process-wide, as the drawing flags are: one scene drawn at a time. +pub var current: ?*const Map = null; + +/// A mark no working window shows, `flash`ing on its pane's strip. +const Flash = struct { panel: Panel, key: u64, ink: u24, p: f32 }; +var flashes: [16]Flash = undefined; +var n_flashes: usize = 0; + +/// The flashes of the step, in the strips' time (6 f behind): a word +/// struck or read on the stack or in the view's dump that its pane's +/// window does not show; `p` of its 12 f. +fn flash(now: @import("cursor.zig").Now) void { + if (!now.walking()) return; + const p = now.since(.memory, 0) / (12.0 / 60.0); + if (p < 0 or p > 1) return; + const rec = now.rec; + const marks = [2]struct { spans: []const Recording.Span, ink: u24 }{ + .{ .spans = rec.written(now.stops[1], now.stops[0]), .ink = theme.color.struck }, + .{ .spans = rec.read(now.stops[1], now.stops[0]), .ink = theme.mark(.read).solid }, + }; + for (marks) |mark| for (mark.spans) |span| { + // Where the map has it: the stack's word, or the 16 bytes of a dump's row. + const word = span.addr & ~@as(u64, 7); + const sixteen = span.addr & ~@as(u64, 15); + const panel: Panel, const key: u64 = if (Map.rows_of(.stack, word) != null) .{ .stack, word } else .{ .view, sixteen }; + if (Map.rows_of(panel, key) == null) continue; + if (windows[@intFromEnum(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue; + if (n_flashes == flashes.len) return; + flashes[n_flashes] = .{ .panel = panel, .key = key, .ink = mark.ink, .p = p }; + n_flashes += 1; + }; +} + +const Spot = struct { r: f32, x: f32 }; + +/// Where a point of the map is in a column of `boxes`: its row, counted +/// from the column's top (continuous: `middle`, a point on a row's middle, +/// else on its top), and how far across its box. +fn spotIn(boxes: [2]Rect, x: f32, y: f32, middle: bool) ?Spot { + const cm = theme.metric.context; + var offset: f32 = 0; + for (boxes) |b| { + if (b.h <= 0) continue; + const body = b.y + cm.tag + cm.pad; + const n: f32 = @floatFromInt(theme.layout.rowsIn(b.h)); + if (x >= b.x - 1 and x <= b.x + b.w + 1 and y >= body - 1 and y <= body + n * cm.row + 1) + return .{ .r = offset + (y - body - @as(f32, if (middle) cm.row / 2 else 0)) / cm.row, .x = x - b.x }; + offset += n; } - f.target(.none); - f.image(fades.images[n], px, .{ .tint = sk.Color.white.alphaFloat(shown.pose.opacity) }); - fixed.frame(.{ .x = box.x - 1, .y = box.y - 1, .w = box.w + 2, .h = box.h + 2 }, theme.color.rule, 1); + return null; +} + +/// A rect of a strip's column, in strip units from its slot's corner, in the image's pixels (one at least). +fn pixels(f: *sk.Frame, k: f32, slot: usize, x: f32, y: f32, w: f32, h: f32, color: sk.Color) void { + const left = @as(f32, @floatFromInt(slot)) * theme.strip.w; + const x0 = @round((left + x) * k); + const y0 = @round(y * k); + const x1 = @max(@round((left + x + w) * k), x0 + 1); + const y1 = @max(@round((y + h) * k), y0 + 1); + f.fill(sk.Rect{ .x = x0, .y = y0, .w = x1 - x0, .h = y1 - y0 }, color); +} + +/// Where a pane's window is on its column now: its first and last row, +/// between where it was and where it is, as far as its scroll has gone. +fn windowOn(panel: Panel, col: *const Column) ?[2]f32 { + return spanOf2(windows[@intFromEnum(panel)], col); +} + +/// The first row a strip of `cap` rows shows: the column's top, or where +/// it is longer, the window in the middle, clamped to the column's ends. +fn firstShown(col: *const Column, win: [2]f32, cap: f32) f32 { + if (col.rows <= cap) return 0; + return std.math.clamp((win[0] + win[1] + 1) / 2 - cap / 2, 0, col.rows - cap); +} + +/// A pane's strip, in the pane's units (`box` its box). +fn stripRect(box: Rect) Rect { + const st = theme.strip; + return .{ .x = box.x + box.w - st.inset - st.w, .y = box.y + theme.metric.context.tag, .w = st.w, .h = box.h - theme.metric.context.tag - st.inset }; +} + +/// A pane's minimap (design/README.md, "The map and the minimap"): its +/// column of the map in a strip inside its frame at its right; where the +/// column is longer than the strip, the rows round its window, with three +/// faint dots at an end where it goes on; its window framed in primary, +/// gliding with its scroll. `u` is the pane's `Ui` at its box's corner (a +/// pane fading through passes its faded one); drawn last, over its rows. +pub fn strip(panel: Panel, u: ui.Ui, box: Rect) void { + if (ui.mapping) return; + const m = current orelse return; + const f = u.f; + if (looking(f)) return; + const slot = slotOf(panel) orelse return; + // In a dive it comes in as its pane lands. + const v = u.faded(Map.stripShows(panel, u.at.value(m.t))); + if (v.at.pose.opacity <= 0) return; + m.strips(f, u.at); + const col = &atlas.columns[slot]; + if (col.n == 0) return; + const st = theme.strip; + const r = stripRect(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); + if (r.h <= st.top + st.foot + st.pitch) return; + // The strip as its drawings have it, its rows, dots and window in place. + const k = atlas.k; + const a = v.at.xf.apply(.{ r.x, r.y }); + const b = v.at.xf.apply(.{ r.x + r.w, r.y + r.h }); + f.image(atlas.images[theme.time.minimap_fade], sk.Rect{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] }, .{ .src = sk.Rect{ .x = @as(f32, @floatFromInt(slot)) * st.w * k, .y = 0, .w = st.w * k, .h = r.h * k }, .tint = sk.Color.white.alphaFloat(v.at.pose.opacity) }); } test "the map's columns hold their panels" { @@ -745,3 +1124,14 @@ test "the map's columns hold their panels" { const st = theme.map.stage; try std.testing.expectEqual(@as(f32, 3840), st.x + st.w + st.x); } + +test "a point of the map is placed in its column, the second box going on from the first" { + const cm = theme.metric.context; + const boxes = [2]Rect{ .{ .x = 0, .y = 0, .w = 880, .h = theme.layout.panelH(10) }, .{ .x = 900, .y = 100, .w = 880, .h = theme.layout.panelH(5) } }; + const first = spotIn(boxes, 40, cm.tag + cm.pad + 3 * cm.row + cm.row / 2, true).?; + try std.testing.expectEqual(@as(f32, 3), first.r); + const second = spotIn(boxes, 940, 100 + cm.tag + cm.pad + cm.row, false).?; + try std.testing.expectEqual(@as(f32, 11), second.r); + try std.testing.expectEqual(@as(f32, 40), second.x); + try std.testing.expect(spotIn(boxes, 2000, 50, true) == null); +} diff --git a/anim/src/root.zig b/anim/src/root.zig index b7be9b4..78da9dc 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -220,7 +220,7 @@ pub const map = @import("map.zig"); pub const Context = struct { stage: *Stage, /// The working frame unfolded (`map.Map`): its panels, on a stage of its - /// own; drawn small as the minimap. A lens adds its drawing with `map.add`. + /// own; each pane's column of it is the pane's strip. A lens adds its drawing with `map.add`. map: *map.Map, clock: anim.Obj, source: anim.Obj, @@ -288,18 +288,29 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex const stage = Stage.init(s, options.split); var at = cursor_; at.levels.crossings = options.syscalls; - // The map first: while it fills the frame or falls to the minimap it is under the panels diving out of it. + // The map first: while it fills the frame it is under the panels diving out of it. const whole = s.new(map.Map{ .stage = Stage.init(s, map.split(at.rec, options.split.band.h > 0, .{ at.first, at.last }, options.graph)), .frame = stage, .t = s.value(map.diving.land + map.diving.still), .cursor = at, .graph = options.graph }); whole.obj = s.custom(whole, .{ .x = -640, .y = -360, .scale = ui.scale }); - whole.add(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent }); - whole.add(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent, .part = .source_more }); - if (options.graph) whole.add(s, graph.Map{ .cursor = at, .stage = whole.stage }) else if (options.descent) whole.add(s, Descent{ .cursor = at, .stage = whole.stage }) else whole.add(s, Disasm{ .cursor = at, .stage = whole.stage }); - whole.add(s, Registers{ .cursor = at, .stage = whole.stage, .syscalls = options.syscalls, .quiet = options.quiet }); - whole.add(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above }); + whole.addIn(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent }, .both, .source); + whole.addIn(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent, .part = .source_more }, .both, .source); + // The disassembly's strip is its linear column: where the map draws a + // graph or a descent, the rows round the pc are drawn for the strip alone. + if (options.graph) { + whole.linear = Stage.init(s, map.split(at.rec, options.split.band.h > 0, .{ at.first, at.last }, false)); + whole.addIn(s, graph.Map{ .cursor = at, .stage = whole.stage }, .map, .disasm); + whole.addIn(s, Disasm{ .cursor = at, .stage = whole.linear.?, .measures = false }, .strips, .disasm); + } else if (options.descent) { + whole.addIn(s, Descent{ .cursor = at, .stage = whole.stage }, .map, .disasm); + whole.addIn(s, Disasm{ .cursor = at, .stage = whole.stage, .measures = false }, .strips, .disasm); + } else whole.addIn(s, Disasm{ .cursor = at, .stage = whole.stage }, .both, .disasm); + whole.addIn(s, Registers{ .cursor = at, .stage = whole.stage, .syscalls = options.syscalls, .quiet = options.quiet }, .map, .registers); + whole.addIn(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above }, .both, .stack); // The stack goes on in the rest of the memory's column, from where its own column ends. - whole.add(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above - @as(i32, @intCast(theme.layout.rowsIn(whole.stage.first.stack.h))), .part = .more }); - whole.add(s, Backtrace{ .cursor = at, .stage = whole.stage }); - whole.add(s, map.Spare{ .cursor = at, .stage = whole.stage, .map = whole }); + whole.addIn(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above - @as(i32, @intCast(theme.layout.rowsIn(whole.stage.first.stack.h))), .part = .more }, .both, .stack); + whole.addIn(s, Backtrace{ .cursor = at, .stage = whole.stage }, .map, .backtrace); + // The rest of the first two columns: no pane's. + whole.addIn(s, map.Spare{ .cursor = at, .stage = whole.stage, .map = whole }, .map, .backtrace); + map.current = whole; return .{ .stage = stage, .map = whole, diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 95400be..f82bb81 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -356,7 +356,8 @@ pub fn callLabels(u: ui.Ui, y: f32, w: f32, n: usize, name: []const u8, args: [] /// `text` in `width` units of mono 20: whole, or cut at its far end with `…`. pub fn fitted(u: ui.Ui, text: []const u8, width: f32) []const u8 { - const chars: usize = @intFromFloat(@max(width / adv, 1)); + // (A width measured without a room is infinite: whole.) + const chars: usize = @intFromFloat(std.math.clamp(width / adv, 1, 1 << 16)); if (text.len <= chars) return text; return u.print("{s}\u{2026}", .{text[0 .. chars - 1]}); } @@ -378,7 +379,9 @@ pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, widen: f32, text: []const u8, const on = state == .current or state == .marked; const num = u.print("{d}", .{number}); u.text(if (on) .mono_bold else .mono, size, m.line_number_end + widen - @as(f32, @floatFromInt(num.len)) * adv, baseline(y), num, if (on) gold.on_solid else t.faint); - const limit: usize = m.source_chars - @as(usize, @intFromFloat(widen / adv)); + // Cut as much sooner as the row is narrower than its column (a pane's strip takes 48: four characters). + const cut: usize = @intFromFloat(@max(theme.layout.program.w - w, 0) / adv); + const limit: usize = m.source_chars - @as(usize, @intFromFloat(widen / adv)) - cut; const end = @min(text.len, limit); var i: usize = 0; while (i < end) { @@ -490,6 +493,10 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons u.fill(.{ .x = bx0, .y = r.y - h.out, .w = bx1 - bx0, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); }; u.corner(s0, y + 2, m.corner, h.level * h.corner); + if (ui.strokes) { + if (h.level >= 1 and h.solid * h.in > 0) ui.collectMark(u, s0, y + row_h / 2, .struck, h.solid * h.in) else ui.collectMark(u, s0, y + row_h / 2, .held, h.level * h.corner); + ui.collectMark(u, x0, y + row_h / 2, .read, run.read); + } if (run.read > 0) u.faded(run.read).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.read).solid, 2); // A little-endian word: the bytes above its highest non-zero one are its padding. var top: usize = 0; @@ -564,6 +571,17 @@ pub const Arcs = struct { /// without it to those they have with it, as far as it has drawn or shows. pub fn draw(a: *Arcs, u: ui.Ui, lanes: usize) void { const k = theme.metric.arc; + // For a strip: each arc's rows, the middles of its pointer's and its target's. + if (ui.strokes) { + const c = &ui.collected; + for (a.items[0..a.n]) |arc| if (!arc.stub and c.n_arcs < c.arcs.len) { + const p = u.at.xf.apply(.{ 0, arc.from + row_h / 2 }); + const q = u.at.xf.apply(.{ 0, arc.to + row_h / 2 }); + c.arcs[c.n_arcs] = .{ .x = p[0], .from = p[1], .to = q[1], .ink = u.faded(arc.shows).at.faded(ui.rgb(arc.ink)) }; + c.n_arcs += 1; + }; + return; + } var spans: [32]Span = undefined; for (a.items[0..a.n], spans[0..a.n], 0..) |arc, *sp, i| { const up = arc.to < arc.from; diff --git a/anim/src/source.zig b/anim/src/source.zig index 0705f5b..5a5f1cd 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -41,41 +41,59 @@ pub const Source = struct { const u = context.at(f, placed, box); const rec = p.cursor.rec; const now = p.cursor.now(placed); - const text = prepared(rec.source, rec.file) orelse return; // Its window, and on the map the lines of both its boxes (`continued`): this one from `skip` lines in. const head = theme.layout.rowsIn(p.stage.box(placed, .source).h); const tail = theme.layout.rowsIn(p.stage.box(placed, .source_more).h); const fit: u32 = @intCast(theme.layout.rowsIn(box.h)); const span_fit: u32 = @intCast(head + tail); const skip: f32 = if (p.part == .source_more) @floatFromInt(head) else 0; - // The mark: leaving the line of one moment for that of the next. - const was = rec.own[now.marks[0]]; - const here = rec.own[now.marks[1]]; + // The mark: leaving the line of one moment for that of the next, in + // whichever file the pc is on a line of (a library's, where the + // build gave its source), else where it waits a frame up. + const at = [2]Recording.Shown{ rec.shown[now.marks[0]], rec.shown[now.marks[1]] }; + const was = at[0].line; + const here = at[1].line; // The window: where the line it is on has it, and (as the mark // moves on) gliding to where the next one does. It never cuts. const going = now.advancing(); - const windows = [2]f32{ @as(f32, @floatFromInt(rec.viewFirst(span_fit, was))) + skip, @as(f32, @floatFromInt(rec.viewFirst(span_fit, here))) + skip }; - // 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 windows = [2]f32{ @as(f32, @floatFromInt(rec.shownFirst(span_fit, at[0]))) + skip, @as(f32, @floatFromInt(rec.shownFirst(span_fit, at[1]))) + skip }; + // Another file: the panel fades through (12 f out, 12 f in), its tag + // naming the file it comes to. Farther than its own height in one + // file (another function far off): its strip shows where it goes + // first (24 f), then 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 turn = at[0].src != at[1].src and going < 1; + const far = !turn and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)) and going < 1; + const side: usize = if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(going >= 0.75) else @intFromBool(going >= 0.5); + const file = rec.sources[at[side].src]; + const text = prepared(file.text, file.path) orelse return; + const first = if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); + const fade: f32 = if (turn) @abs(2 * going - 1) else if (far) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; + const lit = u.faded(fade); const from: u32 = @intFromFloat(@floor(first)); - const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), rec.line_count); - const shown_first: u32 = @intFromFloat(windows[if (going >= 0.5) 1 else 0]); - // Waiting: the pc is in code with no source, under this line's call. - const waits = p.descent and !rec.sourced(now.marked()) and rec.own[now.marked()] != 0; - const lines_note = if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}); + const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), file.lines); + // Waiting: the pc is in code with no source (a PLT stub, a library without it), under this line's call. + const waits = p.descent and !at[side].here and at[side].line != 0; + var lines_notes: [2][]const u8 = undefined; + for (at, windows, &lines_notes) |a, w, *note| { + const lines = rec.sources[a.src].lines; + const shown_first: u32 = @intFromFloat(w - skip); + note.* = if (lines > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, lines), lines }) else u.print("{d} lines", .{lines}); + } // Where the pc is, said where it waits: a change of it (on through a // stub) crossfades over the 12 f before the advance, never in a frame. var notes: [2][]const u8 = undefined; - for (now.marks, ¬es) |mk, *note| note.* = if (p.descent and !rec.sourced(mk) and rec.own[mk] != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, mk), "rip")), rec.own[mk], whereIs(u, rec, mk) }) else lines_note; - const swap = !std.mem.eql(u8, notes[0], notes[1]) and (notes[0].ptr != lines_note.ptr or notes[1].ptr != lines_note.ptr) and now.walking(); - const body = u.panel(box.w, box.h, if (p.part == .source_more) u.print("{s}, continued", .{rec.file}) else rec.file, .{ .focus = p.focus, .note = if (swap) "" else if (waits) notes[if (going >= 0.5) 1 else 0] else lines_note }); + for (now.marks, at, ¬es, lines_notes) |mk, a, *note, lines_note| note.* = if (p.descent and !a.here and a.line != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(lastShown(rec, mk), "rip")), a.line, whereIs(u, rec, mk) }) else lines_note; + const swap = !std.mem.eql(u8, notes[0], notes[1]) and now.walking(); + const titles = [2][]const u8{ rec.sources[at[0].src].name(), rec.sources[at[1].src].name() }; + const title = if (p.part == .source_more) u.print("{s}, continued", .{file.name()}) else file.name(); + const body = u.panel(box.w, box.h, if (turn) "" else title, .{ .focus = p.focus, .note = if (swap) "" else notes[side] }); + // Its tag's file and note change with the fade through it; a note otherwise over the 12 f before the advance. + if (turn) for (titles, [2]f32{ 1 - 2 * going, 2 * going - 1 }) |t, shows| u.faded(shows).tagTitle(t, p.focus); if (swap) { - const c = now.renaming(); - u.faded(1 - c).tagNote(box.w, notes[0]); + const c = if (turn) std.math.clamp(2 * going - 1, 0, 1) else now.renaming(); + u.faded(if (turn) 1 - 2 * going else 1 - c).tagNote(box.w, notes[0]); u.faded(c).tagNote(box.w, notes[1]); } const top = body.y + m.pad; @@ -86,7 +104,18 @@ pub const Source = struct { var mark_line = here; var mark_at: f32 = @floatFromInt(here); var shows: f32 = 1; - if (going < 1) { + if (turn or far) { + // It goes with the fade: out with the old window, in with the new. + mark_line = at[side].line; + mark_at = @floatFromInt(mark_line); + shows = fade; + // On the map, for the strip, it lights on its new line at once: the strip shows where the pane goes before it fades. + if (ui.mapping and far and going > 0) { + mark_line = here; + mark_at = @floatFromInt(here); + shows = 1; + } + } else if (going < 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. @@ -104,10 +133,9 @@ pub const Source = struct { } } const mark_y = top + (mark_at - first) * m.row; - // The numbers as wide as the program's largest: a scroll does not shift the text. - const widen = rows.numberRoom(rec.line_count); + // The numbers as wide as the widest file's largest: a scroll or another file does not shift the text. + const widen = rows.numberRoom(rec.most_lines); context.clipBody(u, box); - defer u.unclip(); // The plaque over the number. Fire: on the line about to run its // edges go out and come back, once, and nothing else moves. if (waits) { @@ -117,29 +145,35 @@ pub const Source = struct { } else if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source)); if (shows >= 1 and mark_y >= body.y and mark_y + m.row <= box.h) ties.anchor(u, .source, .{ .x = 0, .y = mark_y, .w = box.w, .h = m.row }); - // The trail: the last three other lines it was on, as the mark left - // them and as it finds them: a bar that moves crossfades with the advance. + // The trail: the last three other lines of its file it was on, as + // the mark left them and as it finds them: a bar that moves crossfades with the advance. var trails: [2][3]u32 = @splat(@splat(0)); var founds = [2]usize{ 0, 0 }; for (now.marks, &trails, &founds) |mk, *trail, *found| { - const on_line = rec.own[mk]; + const on = rec.shown[mk]; var back = mk; while (back > 0 and found.* < trail.len) { back -= 1; - const l = rec.own[back]; - if (l == 0 or l == on_line or std.mem.indexOfScalar(u32, trail[0..found.*], l) != null) continue; - trail[found.*] = l; + const l = rec.shown[back]; + if (l.line == 0 or l.src != on.src or l.line == on.line or std.mem.indexOfScalar(u32, trail[0..found.*], l.line) != null) continue; + trail[found.*] = l.line; found.* += 1; } } + if (turn) { + // Another file's trail is not this one's. + trails[1 - side] = @splat(0); + founds[1 - side] = 0; + } const lines_of = struct { - fn of(at: f32, n: u32, lines: u32) [2]u64 { - const a: u32 = @intFromFloat(at); - return .{ a, @min(a + n - 1, lines) }; + fn of(a: f32, n: u32, lines: u32) [2]u64 { + const l: u32 = @intFromFloat(a); + return .{ l, @min(l + n - 1, lines) }; } }.of; - map.window(.source, lines_of(windows[1], fit, rec.line_count), lines_of(windows[0], fit, rec.line_count), cursors.glide(going)); + // On the strip the window glides there; a window fading through goes before the fade, so the strip shows where it went first. + map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); var line = @max(from, 1); while (line <= last) : (line += 1) { const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row; @@ -149,18 +183,21 @@ pub const Source = struct { const k = if (going >= 0.5) ks[1] else ks[0]; const on = shows >= 0.5 and line == mark_line; const fading = !std.meta.eql(ks[0], ks[1]) and going > 0 and going < 1; - rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain); + rows.line(lit, y, map.content(box.w), line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain); if (fading and !(on and !waits)) for (ks, [2]f32{ 1 - going, going }) |kk, amount| if (kk) |n| lit.faded(amount).trail(theme.stroke.rule, y, n); } // The source is read at a run; at a sprint it is veiled too. context.veiled(u, box, now.sprint_veil); + u.unclip(); + // Another file is another column: its strip fades through as the pane does. + map.strip(.source, if (turn) u.faded(map.through(now, travel)) else u, box); } }; -/// The last moment at or before `i` whose pc was on a line of the program's source. -fn firstOwn(rec: *const Recording, i: u64) u64 { +/// The last moment at or before `i` whose pc was on a line the panel can show. +fn lastShown(rec: *const Recording, i: u64) u64 { var at = i; - while (at > 0 and !rec.sourced(at)) at -= 1; + while (at > 0 and !rec.shown[at].here) at -= 1; return at; } diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index b568612..3788fe3 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -425,7 +425,8 @@ pub const Crossing = struct { .read = if (bufferRead(given) != null) now.held(p.work) else 0, .pins = true, }); - v.veil(now); + // The log is whole: no strip. + context.veiled(v.u, v.box, now.sprint_veil); } }; diff --git a/anim/src/theme.zig b/anim/src/theme.zig index 7d505d7..156088c 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -47,8 +47,7 @@ pub const canvas = struct { /// The map (design/README.md, "The map and the minimap"): the working /// frame unfolded on a stage of 3840 by 2160 at the context's type size, /// four columns of 880; the working frame's windows outlined on it (2 in -/// `dim`, 4 out). The minimap: the map at a twentieth in the caption -/// band's right end, under the clock's, whose count moves left of it. +/// `dim`, 4 out). Each pane's minimap is a `strip` of its own column. pub const map = struct { pub const width = 3840; pub const height = 2160; @@ -62,11 +61,29 @@ pub const map = struct { pub const disasm_rows = 69; pub const memory_rows = 32; }; -pub const minimap = struct { - pub const box: Rect = .{ .x = 1664, .y = 912, .w = 192, .h = 108 }; - pub const scale = 1.0 / 20.0; - /// The clock's count, ranged right here. - pub const count_end = 1648; +/// A pane's minimap: its column of the map in a strip 40 wide inside its +/// frame at its right (inside the 2-unit rule), under the tag, on `well`; +/// a row of the map 4 units (a stroke 3 high), its 880 across 36, from 2 +/// in; the window framed 2 in primary; marks 4 by 4 at a row's left, 5 +/// apart. The pane's content keeps 8 from it: the strip costs it 48, and +/// the disassembly's annotation column 24 (564 to 540). +pub const strip = struct { + pub const w = 40; + pub const inset = 2; + pub const cost = 48; + pub const pitch = 4; + pub const stroke = 3; + pub const across = 36.0 / 880.0; + pub const left = 2; + pub const mark = 4; + pub const mark_apart = 5; + pub const held = 2; + pub const window = 2; + /// Above the first row; under the last, the dots where the column goes on. + pub const top = 2; + pub const foot = 4; + /// A row's text 65% of the way from the page to its ink. + pub const ink = 0.65; }; /// Left edge of column `i` (0 to 11). diff --git a/anim/src/ui.zig b/anim/src/ui.zig index bcefff3..589bfb6 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -17,17 +17,49 @@ pub const Vec = sk.math.Vec; pub const scale = 1280.0 / @as(comptime_float, theme.canvas.width); /// While the map's panels draw (`map.zig`): they publish their rows, not -/// their windows and places. `strokes`: the minimap, a twentieth of the -/// map, where text is a stroke a pixel high in its ink at 45% toward the -/// page and the marks are blocks a few pixels across. +/// their windows and places. `strokes`: the map drawn for the panes' +/// strips (`map.strip`), where nothing shows and what a strip draws is +/// collected (`collected`): each run of text, the marks, the arcs, the +/// blocks' first rows. /// shortcut: process-wide, for one scene drawn at a time; two players at once want it on the frame. pub var mapping = false; pub var strokes = false; /// How much of a panel's tag and rules shows: less while it dives out of /// its window on the map (`context.at` sets it for the panel it hands out). pub var chrome: f32 = 1; -/// The minimap's pixel, in the map's units. -const px = 20; +/// A clip every other stays inside, in canvas pixels: a map column squeezing into its strip. +pub var bound: ?sk.Rect = null; + +/// What a map drawn for the strips holds, in its own units (`map.strip` +/// draws it in no transform but its own): text runs by their middle, the +/// marks by their row's middle, the arcs by their rows' tops. +pub const Collected = struct { + pub const Run = struct { x0: f32, x1: f32, y: f32, ink: Color }; + pub const Kind = enum { current, struck, read, held, tick }; + pub const Mark = struct { x: f32, y: f32, kind: Kind, shows: f32 }; + pub const Arc = struct { x: f32, from: f32, to: f32, ink: Color }; + runs: [12288]Run = undefined, + n_runs: usize = 0, + marks: [1024]Mark = undefined, + n_marks: usize = 0, + arcs: [96]Arc = undefined, + n_arcs: usize = 0, + + pub fn reset(c: *Collected) void { + c.n_runs = 0; + c.n_marks = 0; + c.n_arcs = 0; + } +}; +pub var collected: Collected = .{}; + +/// A mark on the row whose middle is `y` (in `u`), for the strips; `shows` of it. +pub fn collectMark(u: Ui, x: f32, y: f32, kind: Collected.Kind, shows: f32) void { + if (!strokes or shows <= 0 or collected.n_marks == collected.marks.len) return; + const p = u.point(x, y); + collected.marks[collected.n_marks] = .{ .x = p[0], .y = p[1], .kind = kind, .shows = shows * u.at.pose.opacity }; + collected.n_marks += 1; +} /// Adds `data` (a component: something with `draw(f, at)`) to the scene, /// its origin at design `x, y` and its units the design's. Like any @@ -158,9 +190,8 @@ pub const Ui = struct { u.f.fill(sk.Rect{ .x = x, .y = y, .w = @round(b[0]) - x, .h = @round(b[1]) - y }, u.at.faded(rgb(c))); } - /// A stroke `w` wide, wholly inside `r` (on the minimap, a pixel at least). - pub fn frame(u: Ui, r: Rect, c: anytype, w_: f32) void { - const w = if (strokes) @max(w_, px) else w_; + /// A stroke `w` wide, wholly inside `r`. + pub fn frame(u: Ui, r: Rect, c: anytype, w: f32) void { u.fill(.{ .x = r.x, .y = r.y, .w = r.w, .h = w }, c); u.fill(.{ .x = r.x, .y = r.y + r.h - w, .w = r.w, .h = w }, c); u.fill(.{ .x = r.x, .y = r.y + w, .w = w, .h = r.h - 2 * w }, c); @@ -179,9 +210,14 @@ pub const Ui = struct { pub fn text(u: Ui, face: Face, size: f32, x: f32, baseline: f32, bytes: []const u8, c: anytype) void { if (bytes.len == 0) return; if (strokes) { - // A run of text: a stroke as long as it is, through its capitals' middle. - if (std.mem.indexOfNone(u8, bytes, " ") == null) return; - return u.fill(.{ .x = x, .y = baseline - 0.36 * size - px / 2, .w = u.width(face, size, bytes), .h = px }, mix(c, theme.color.page, 0.45)); + // A run of text, for a strip: where it starts and ends, through its capitals' middle, and its ink. + if (std.mem.indexOfNone(u8, bytes, " ") == null or collected.n_runs == collected.runs.len) return; + const lead = std.mem.indexOfNone(u8, bytes, " ").?; + const a = u.point(x + u.width(face, size, bytes[0..lead]), baseline - 0.36 * size); + const b = u.point(x + u.width(face, size, std.mem.trimEnd(u8, bytes, " ")), baseline); + collected.runs[collected.n_runs] = .{ .x0 = a[0], .x1 = b[0], .y = a[1], .ink = u.at.faded(rgb(c)) }; + collected.n_runs += 1; + return; } // Go's ascent is 0.945 em; JetBrains Mono's, which every monospace is set in, 1.02. const at = u.point(x, baseline - @as(f32, if (set(face, size) == face) 0.945 else 1.02) * size); @@ -254,6 +290,11 @@ pub const Ui = struct { u.text(.sans, micro, w - 10 - u.width(.sans, micro, note), theme.metric.context.tag - 6, note, theme.color.text.faint); } + /// A tag's title drawn apart from its panel: for one that crossfades with another. + pub fn tagTitle(u: Ui, title: []const u8, focus: bool) void { + u.text(.sans_medium, theme.size.sans.tag, 28, theme.metric.context.tag - 6, title, if (focus) theme.color.text.primary else theme.color.text.dim); + } + fn panelChrome(u: Ui, w: f32, h: f32, title: []const u8, focus: bool, note: []const u8, legend: []const Legend) Rect { const options = .{ .focus = focus, .note = note, .legend = legend }; const m = theme.metric.context; @@ -383,11 +424,8 @@ pub const Ui = struct { const w = theme.mark(.write); const m = theme.metric.context; if (strokes) { - // On the minimap: a strike a block 3 pixels across at the value's start; held, a pixel. - const mid = r.y + r.h / 2; - if (h.level >= 1 and h.solid * h.in > 0) { - u.faded(h.solid * h.in).fill(.{ .x = r.x, .y = mid - 1.5 * px, .w = 3 * px, .h = 3 * px }, w.solid); - } else if (h.level * h.corner > 0) u.faded(h.level * h.corner).fill(.{ .x = r.x, .y = mid - px / 2, .w = px, .h = px }, w.solid); + // For a strip: a strike, or held. + if (h.level >= 1 and h.solid * h.in > 0) collectMark(u, r.x, r.y + r.h / 2, .struck, h.solid * h.in) else collectMark(u, r.x, r.y + r.h / 2, .held, h.level * h.corner); return null; } if (h.arm > 0) u.faded(h.arm).frame(.{ .x = r.x - 6, .y = r.y, .w = r.w + 12, .h = r.h }, w.solid, m.read_frame); @@ -411,10 +449,7 @@ pub const Ui = struct { /// `read` in the context: a 2-unit frame in read's colour, 6 out at /// the sides, no fill; `shows` of it (0 to 1: it fades in and out). pub fn read(u: Ui, r: Rect, shows: f32) void { - if (strokes) { - if (shows > 0) u.faded(shows).frame(.{ .x = r.x, .y = r.y + r.h / 2 - 1.5 * px, .w = 3 * px, .h = 3 * px }, theme.mark(.read).solid, px); - return; - } + if (strokes) return collectMark(u, r.x, r.y + r.h / 2, .read, shows); if (shows > 0) u.faded(shows).frame(.{ .x = r.x - 6, .y = r.y, .w = r.w + 12, .h = r.h }, theme.mark(.read).solid, theme.metric.context.read_frame); } @@ -450,8 +485,7 @@ pub const Ui = struct { /// `w` wide at its left, its edges out `out` units (the fire). pub fn current(u: Ui, r: Rect, w: f32, out: f32) void { const gold = theme.mark(.current); - // On the minimap: a gold stroke across the column, 2 pixels high. - if (strokes) return u.fill(.{ .x = r.x, .y = r.y + r.h / 2 - px, .w = r.w, .h = 2 * px }, gold.solid); + if (strokes) return collectMark(u, r.x, r.y + r.h / 2, .current, 1); u.fill(r, gold.ember); u.fill(.{ .x = r.x - out, .y = r.y - out, .w = w + 2 * out, .h = r.h + 2 * out }, gold.solid); } @@ -566,11 +600,17 @@ pub const Ui = struct { pub fn clip(u: Ui, r: Rect) void { const a = u.point(r.x, r.y); const b = u.point(r.x + r.w, r.y + r.h); - u.f.clip(sk.Rect{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) }); + var c: sk.Rect = .{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) }; + if (bound) |o| { + const x0 = @max(c.x, o.x); + const y0 = @max(c.y, o.y); + c = .{ .x = x0, .y = y0, .w = @max(@min(c.x + c.w, o.x + o.w) - x0, 0), .h = @max(@min(c.y + c.h, o.y + o.h) - y0, 0) }; + } + u.f.clip(c); } pub fn unclip(u: Ui) void { - u.f.clip(null); + if (bound) |b| u.f.clip(b) else u.f.clip(null); } /// A path through `points` with corners of radius `radius`, `progress` diff --git a/anim/src/words.zig b/anim/src/words.zig index f66f6d2..5411385 100644 --- a/anim/src/words.zig +++ b/anim/src/words.zig @@ -22,7 +22,7 @@ const t = theme.color.text; pub const Clock = struct { cursor: Cursor, box: Rect = .{ .x = theme.canvas.stage.x, .y = theme.canvas.clock_y - 12, .w = theme.canvas.stage.w, .h = 24 }, - /// The map, drawn small under the clock's right end: the minimap. + /// The map: with `CANIM_MAP`, drawn over everything (`Map.wholeMap`). map: ?*const @import("map.zig").Map = null, pub fn draw(k: *const Clock, f: *sk.Frame, at: anim.Placed) void { @@ -60,19 +60,15 @@ pub const Clock = struct { const size = theme.size.mono.context; const base = c.clock_y + 28; const count = u.print("moment {d} of {d}", .{ counted -| now.way[0], now.way[1] -| now.way[0] }); - // Ranged right left of the minimap. - const count_x = (if (k.map != null) theme.minimap.count_end else stage.x + stage.w) - u.width(.mono, size, count); + // Ranged right at the stage's right edge, 1856. + const count_x = stage.x + stage.w - u.width(.mono, size, count); u.text(.mono, size, count_x, base, count, t.faint); // Secondary action: the pace, said quietly. It only fades. if (now.hurried > 0) { const steps = if (now.of > 0) u.print("step {d} of {d}", .{ now.count, now.of }) else u.print("step {d}", .{now.count}); u.faded(now.hurried).text(.mono, size, count_x - u.width(.mono, size, steps) - 3 * ui.advance(size), base, steps, t.dim); } - if (k.map) |m| { - if (@import("map.zig").looking(f)) return m.wholeMap(f, at); - m.fallingOver(f, at); - @import("map.zig").minimap(m, f, at); - } + if (k.map) |m| if (@import("map.zig").looking(f)) m.wholeMap(f, at); } }; diff --git a/anim/test/gallery/atoms.png b/anim/test/gallery/atoms.png Binary files differindex 8da5c01..acd54a8 100644 --- a/anim/test/gallery/atoms.png +++ b/anim/test/gallery/atoms.png diff --git a/anim/test/gallery/graph-map.png b/anim/test/gallery/graph-map.png Binary files differindex b16caf6..951d4af 100644 --- a/anim/test/gallery/graph-map.png +++ b/anim/test/gallery/graph-map.png diff --git a/anim/test/gallery/graph.png b/anim/test/gallery/graph.png Binary files differindex ea9695e..d43db42 100644 --- a/anim/test/gallery/graph.png +++ b/anim/test/gallery/graph.png diff --git a/anim/test/gallery/loupe.png b/anim/test/gallery/loupe.png Binary files differindex 7f07d94..52bc89a 100644 --- a/anim/test/gallery/loupe.png +++ b/anim/test/gallery/loupe.png diff --git a/anim/test/gallery/none.png b/anim/test/gallery/none.png Binary files differindex bac000d..4e4d5b1 100644 --- a/anim/test/gallery/none.png +++ b/anim/test/gallery/none.png diff --git a/anim/test/gallery/rest.png b/anim/test/gallery/rest.png Binary files differindex c368a30..205fc0d 100644 --- a/anim/test/gallery/rest.png +++ b/anim/test/gallery/rest.png diff --git a/anim/test/gallery/rows.png b/anim/test/gallery/rows.png Binary files differindex dd85690..4d936ab 100644 --- a/anim/test/gallery/rows.png +++ b/anim/test/gallery/rows.png diff --git a/anim/test/gallery/step.png b/anim/test/gallery/step.png Binary files differindex 19ffc00..5ccb082 100644 --- a/anim/test/gallery/step.png +++ b/anim/test/gallery/step.png diff --git a/anim/test/gallery/subject.png b/anim/test/gallery/subject.png Binary files differindex 182f8ba..9e36a1d 100644 --- a/anim/test/gallery/subject.png +++ b/anim/test/gallery/subject.png diff --git a/anim/test/musl.script b/anim/test/musl.script new file mode 100644 index 0000000..742770b --- /dev/null +++ b/anim/test/musl.script @@ -0,0 +1,9 @@ +# The musl scene, headless: it runs to three instants of its timeline without failing. +frames 2 +console set playing false +console set t 5 +screenshot .zig-cache/canim/musl-early.png +console set t 14 +screenshot .zig-cache/canim/musl-mid.png +console set t 999 +screenshot .zig-cache/canim/musl-end.png diff --git a/anim/test/recordings.zig b/anim/test/recordings.zig index ce5a9db..e3af983 100644 --- a/anim/test/recordings.zig +++ b/anim/test/recordings.zig @@ -210,3 +210,21 @@ test "libc's open at its syscall: the blocks never reached folded, no loop made const here = g.nodes[g.here.?]; try expect(here.y >= off and here.y + here.h <= off + room and g.w <= 1792); } + +test "the source follows the pc into musl's own files and back to main's line" { + // musl is built from Zig's sources with the program: its files are always the build's to give. + const rec = canim.open(recordings.musl); + const main = rec.call("main", 0); + try std.testing.expectEqualStrings("hello.c", rec.sources[rec.shown[main.enter].src].name()); + var files: [3]bool = @splat(false); + var back = false; + for (rec.shown[main.enter..], main.enter..) |s, i| { + const name = rec.sources[s.src].name(); + for ([_][]const u8{ "open.c", "__syscall_cp.c", "syscall_arch.h" }, &files) |want, *seen| seen.* = seen.* or (s.here and std.mem.eql(u8, name, want)); + // Where it is on a line of musl's, the panel shows it: never main's held over. + if (s.here) try expect(rec.sourced(i)); + back = back or (files[0] and s.here and std.mem.eql(u8, name, "hello.c") and s.line == 6); + } + for (files) |seen| try expect(seen); + try expect(back); +} diff --git a/anim/tools/chart.py b/anim/tools/chart.py index 7cc0925..290c59e 100644 --- a/anim/tools/chart.py +++ b/anim/tools/chart.py @@ -39,27 +39,36 @@ def split(drawing, view, source, disasm, slots, backtrace=0): out["backtrace"] = (976, right + ph(17) + 12 + ph(slots) + 12, 880, ph(backtrace)) return out -# The words that are not panels (motion.WORDS): the clock (its count, ranged right at 1648, -# changes in a frame by design), the caption (its 1400 from the margin), and the minimap at -# the caption band's right end, secondary action. The caption's box starts under the clock's count -# and the run's step counter (912 to 934). -words = {"clock": (0, 888, 1656, 46), "caption": (0, 940, 1464, 140), "minimap": (1664, 912, 192, 108)} +# The words that are not panels (motion.WORDS): the clock (its count, ranged right at 1856, +# changes in a frame by design) and the caption (its 1400 from the margin). The caption's box +# starts under the clock's count and the run's step counter (912 to 934). +words = {"clock": (0, 888, 1920, 46), "caption": (0, 940, 1464, 140)} none, beside, subject = split(0, 0, 14, 17, 8, 4), split(152, 152, 8, 17, 8), split(296, 200, 10, 9, 6) # The `blocks` lens: the graph over the program column, the source alone under it; the disassembly # (its view) over the state column, seven rows, the registers and six words under it. blocks = {**subject, "view": (976, 48, 880, ph(7)), "source": (64, 356, 880, ph(20))} del blocks["disasm"] +# Each pane's minimap a region of its own (motion.strips), secondary action: the source's, the +# disassembly's, the stack's, and the view's where it is a dump (not the calls lens's backtrace, +# not the syscalls lens's log). +def strips(panes, view): + out = motion.strips(panes) + if not view and "view strip" in out: + del out["view strip"] + out["view"] = panes["view"] + return out motion.REGIONS.update({ - "fib": {**subject, **words}, - "sort": {**blocks, **words}, + "fib": {**strips(subject, False), **words}, + "sort": {**strips(blocks, True), **words}, # The band is the calls so far; the disassembly a descent. - "syscalls": {**beside, **words}, - "heap": {**subject, **words}, - "list": {**subject, **words}, - # The band's drawing is the backtrace, then the kernel's side. - "sqlite": {**subject, **words}, - "zoom": {**none, **words}, - "gallery": {**beside, **words}, + "syscalls": {**strips(beside, False), **words}, + "musl": {**strips(beside, False), **words}, + "heap": {**strips(subject, True), **words}, + "list": {**strips(subject, True), **words}, + # The band's drawing is the backtrace, then the kernel's side; its view a dump. + "sqlite": {**strips(subject, True), **words}, + "zoom": {**strips(none, False), **words}, + "gallery": {**strips(beside, True), **words}, }) # `cut`: the gallery is the catalogue's pages, cut from one to the next (scenes/gallery.zig: 3, 6, 9.6, 13, 16, # 19.8, 21 and 24 s), not a scene: a page's first frame changes everything at once by design. @@ -92,8 +101,8 @@ def shown(text): text = re.sub(r"\\(.)", r"\1", text.replace("\\n", "")) return len(text.replace("`", "")) -# A scene that opens on the map dives (scenes/list.zig: at 2.5 s, 150 f): the falling map passes under the -# caption, which does not change. Its frames are no caption's arrival or leaving. +# A scene that opens on the map dives (scenes/list.zig: at 2.5 s, 150 f): the map's columns go into their +# strips over the caption, which does not change. Its frames are no caption's arrival or leaving. DIVES = {"list": (150, 300)} _lint = motion.lint diff --git a/anim/tools/sources.zig b/anim/tools/sources.zig new file mode 100644 index 0000000..8c8026e --- /dev/null +++ b/anim/tools/sources.zig @@ -0,0 +1,164 @@ +//! The sources a recording's lines name, other than the program's own, for +//! the source panel to follow the pc into (`Recording.sources`): +//! +//! sources embed TRACE OWN ZIG OUT every build, no network +//! sources fetch TRACE... `zig build sources` +//! +//! `embed` copies those it can read into OUT, a file each, and writes +//! OUT/sources.zig (`list`: each path, as the debug info names it, and its +//! text) for the scene to embed: Zig's musl from the lib directory of ZIG +//! (`zig env`: a static musl build's lines name it there), the rest +//! from the debuginfod client's cache by the build id of the module the pc +//! was in: <cache>/<build id>/source/<path> (the cache: `$DEBUGINFOD_CACHE_PATH`, +//! else `$XDG_CACHE_HOME/debuginfod_client`, else `~/.cache/debuginfod_client`). What is in neither is left out: the +//! panel then waits a frame up, as it did before there were sources. +//! `fetch` asks the debuginfod server (the first of `$DEBUGINFOD_URLS`, +//! else of `/etc/debuginfod/*.urls`) for those the cache lacks, of +//! the modules whose names came from a separate debug file (a +//! distribution's library: never the program's own): `URL/buildid/<build +//! id>/source<path>`, with curl, which sends nothing but its defaults. +//! The only step that uses the network. +const std = @import("std"); +const zt = @import("ztrace"); + +/// A file a moment's line names; the build id (hex) of the module the pc +/// was in, and whether that module's names came from a separate debug file. +const Named = struct { path: []const u8, id: []const u8, separate: bool }; + +/// Each file the recording's lines name, but the program's own (`own`, its bare name). +fn named(a: std.mem.Allocator, io: std.Io, trace_path: []const u8, own: []const u8) ![]Named { + var trace = try zt.Trace.open(a, io, trace_path); + defer trace.close(); + var out: std.ArrayList(Named) = .empty; + var tid: u32 = 0; + for (0..trace.len) |i| { + const m = try trace.moment(i); + if (tid == 0) { + const threads = try m.threads(a); + if (threads.len == 0) continue; + tid = threads[0]; + } + const line = (try m.line(tid)) orelse continue; + if (line.line == 0) continue; + const path = trace.strings.get(line.file) orelse continue; + if (std.mem.eql(u8, std.fs.path.basename(path), own)) continue; + if (for (out.items) |n| { + if (std.mem.eql(u8, n.path, path)) break true; + } else false) continue; + const regs = (try m.regs(tid)) orelse continue; + var module: []const u8 = ""; + var buf: [4096]u8 = undefined; + _ = try m.mapping(regs.rip, &module, &buf); + const mod = zt.telescope.module(m, module); + try out.append(a, .{ + .path = try a.dupe(u8, path), + .id = if (mod) |it| try std.fmt.allocPrint(a, "{x}", .{it.build_id}) else "", + .separate = if (mod) |it| it.debug == .separate else false, + }); + } + return out.items; +} + +/// Where a file of musl's is in Zig's lib directory, by its path from `libc/musl/`. +fn musl(a: std.mem.Allocator, path: []const u8, zig_lib: []const u8) !?[]const u8 { + const k = std.mem.indexOf(u8, path, "/libc/musl/") orelse return null; + return try std.fs.path.join(a, &.{ zig_lib, path[k + 1 ..] }); +} + +/// Where the cache keeps a module's source file: `<cache>/<build id>/source/<path>`. +fn cached(a: std.mem.Allocator, cache: []const u8, n: Named) ![]const u8 { + return std.fs.path.join(a, &.{ cache, n.id, "source", n.path }); +} + +/// Zig's lib directory, as `zig env` says it. +fn zigLib(a: std.mem.Allocator, io: std.Io, zig: []const u8) ![]const u8 { + const env = try std.process.run(a, io, .{ .argv = &.{ zig, "env" } }); + const key = ".lib_dir = \""; + const at = (std.mem.indexOf(u8, env.stdout, key) orelse return error.NoLibDir) + key.len; + return env.stdout[at .. std.mem.indexOfScalarPos(u8, env.stdout, at, '"') orelse return error.NoLibDir]; +} + +fn embed(a: std.mem.Allocator, io: std.Io, trace: []const u8, own: []const u8, zig: []const u8, cache: []const u8, out_dir: []const u8) !void { + const cwd = std.Io.Dir.cwd(); + const zig_lib = try zigLib(a, io, zig); + var dir = try cwd.createDirPathOpen(io, out_dir, .{}); + defer dir.close(io); + var list: std.ArrayList(u8) = .empty; + try list.appendSlice(a, "//! Generated by tools/sources.zig: the files the recording's lines name that the build found.\npub const list = [_][2][]const u8{\n"); + var k: usize = 0; + for (try named(a, io, trace, own)) |n| { + const from = (try musl(a, n.path, zig_lib)) orelse if (n.id.len > 0) try cached(a, cache, n) else continue; + const text = cwd.readFileAlloc(io, from, a, .limited(1 << 22)) catch continue; + // A path a Zig string literal holds as it is: nothing to escape. + if (std.mem.indexOfAny(u8, n.path, "\"\\\n") != null) continue; + const name = try std.fmt.allocPrint(a, "{d}", .{k}); + try dir.writeFile(io, .{ .sub_path = name, .data = text }); + try list.print(a, " .{{ \"{s}\", @embedFile(\"{s}\") }},\n", .{ n.path, name }); + k += 1; + } + try list.appendSlice(a, "};\n"); + try dir.writeFile(io, .{ .sub_path = "sources.zig", .data = list.items }); +} + +fn fetch(a: std.mem.Allocator, io: std.Io, url: []const u8, cache: []const u8, traces: []const []const u8) !void { + const cwd = std.Io.Dir.cwd(); + const base = std.mem.trimEnd(u8, url, "/"); + for (traces) |trace| for (try named(a, io, trace, "")) |n| { + if (!n.separate or n.id.len == 0 or !std.fs.path.isAbsolute(n.path)) continue; + const to = try cached(a, cache, n); + if (cwd.access(io, to, .{})) |_| continue else |_| {} + const part = try std.fmt.allocPrint(a, "{s}.part", .{to}); + const from = try std.fmt.allocPrint(a, "{s}/buildid/{s}/source{s}", .{ base, n.id, n.path }); + const got = try std.process.run(a, io, .{ .argv = &.{ "curl", "-fsS", "--create-dirs", "-o", part, from } }); + if (got.term == .exited and got.term.exited == 0) { + try cwd.rename(part, cwd, to, io); + std.debug.print("sources: {s} {s}\n", .{ n.id, n.path }); + } else { + cwd.deleteFile(io, part) catch {}; + std.debug.print("sources: not served: {s} {s}: {s}", .{ n.id, n.path, got.stderr }); + } + }; +} + +/// The debuginfod client's cache, as elfutils and Zig's std find it. +fn cacheDir(a: std.mem.Allocator, env: *const std.process.Environ.Map) ![]const u8 { + if (env.get("DEBUGINFOD_CACHE_PATH")) |p| return p; + if (env.get("XDG_CACHE_HOME")) |x| return std.fs.path.join(a, &.{ x, "debuginfod_client" }); + return std.fs.path.join(a, &.{ env.get("HOME") orelse "/", ".cache", "debuginfod_client" }); +} + +/// The debuginfod server: the first of `$DEBUGINFOD_URLS`, else of `/etc/debuginfod/*.urls`. +fn server(a: std.mem.Allocator, io: std.Io, env: *const std.process.Environ.Map) ?[]const u8 { + const first = struct { + fn of(text: []const u8) ?[]const u8 { + var words = std.mem.tokenizeAny(u8, text, " \t\n"); + return words.next(); + } + }.of; + if (env.get("DEBUGINFOD_URLS")) |urls| if (first(urls)) |url| return url; + var dir = std.Io.Dir.openDirAbsolute(io, "/etc/debuginfod", .{ .iterate = true }) catch return null; + defer dir.close(io); + var it = dir.iterate(); + while (it.next(io) catch null) |entry| { + if (!std.mem.endsWith(u8, entry.name, ".urls")) continue; + const text = dir.readFileAlloc(io, entry.name, a, .limited(1 << 16)) catch continue; + if (first(text)) |url| return url; + } + return null; +} + +pub fn main(init: std.process.Init) !void { + const a = init.arena.allocator(); + const args = try init.minimal.args.toSlice(a); + const cache = try cacheDir(a, init.environ_map); + if (args.len >= 6 and std.mem.eql(u8, args[1], "embed")) return embed(a, init.io, args[2], args[3], args[4], cache, args[5]); + if (args.len >= 2 and std.mem.eql(u8, args[1], "fetch")) { + const url = server(a, init.io, init.environ_map) orelse { + std.debug.print("sources: no debuginfod server: set DEBUGINFOD_URLS or /etc/debuginfod/*.urls\n", .{}); + return error.NoServer; + }; + return fetch(a, init.io, url, cache, args[2..]); + } + std.debug.print("usage: sources embed TRACE OWN ZIG OUT | sources fetch TRACE...\n", .{}); + return error.Usage; +} |
