diff options
Diffstat (limited to 'anim')
| -rw-r--r-- | anim/README.md | 104 | ||||
| -rw-r--r-- | anim/build.zig | 13 | ||||
| -rw-r--r-- | anim/scenes/intro_code.zig | 124 | ||||
| -rw-r--r-- | anim/scenes/intro_memory.zig | 26 | ||||
| -rw-r--r-- | anim/scenes/intro_stack.zig | 141 | ||||
| -rw-r--r-- | anim/src/aligned.zig | 154 | ||||
| -rw-r--r-- | anim/src/aside.zig | 73 | ||||
| -rw-r--r-- | anim/src/context.zig | 56 | ||||
| -rw-r--r-- | anim/src/descent.zig | 44 | ||||
| -rw-r--r-- | anim/src/regroup.zig | 52 | ||||
| -rw-r--r-- | anim/src/root.zig | 2 | ||||
| -rw-r--r-- | anim/src/segments.zig | 21 |
12 files changed, 596 insertions, 214 deletions
diff --git a/anim/README.md b/anim/README.md index bfc4f95..14e39cf 100644 --- a/anim/README.md +++ b/anim/README.md @@ -182,9 +182,9 @@ canim.descent.step(cur, s, .moment); | `gallery` | every block in its states, a page or a state each 3 s; at 21 s the `blocks` lens (sort's rings at rest, `leave` mid-way, a `turn` landing with its ring's count struck; libc's `open` in `layers` at its `syscall`, what it has not reached folded), at 24 s the moves of a first time (sort's first swap `reach`ed, its pill filling; `open` stepped past its `syscall`, its fold mid-`unfold`; sort in `layers` panned to the pc; the fold open, at rest). Its context pages fold the registers its one step does not change | all three, `blocks` | `gallery`, and for the graph pages `test/gallery/sort.ztrace` and `hello.ztrace` (the second page's picture keeps the old name `graph-map.png`) | | `column` | the text column (design/motion.md, "A scene in the column"): `syscalls`' story on the same recording and steps, beat by beat as the storyboard's table C1 to C12 has it, its texts as it cuts them (C4's 57 characters): the opening `below` (the working frame whole, its caption); the arguments beside the source and the disassembly over the registers; the call and the stub's jmp beside the descent over a stack of twenty words (the touch from the call row down the gutter to the free word, rsp's pin climbing); the wrapper at a run over a source of two lines, the text level with open's head; its last three beside the registers; the crossing beside a descent of twenty-four rows, the text level with the kernel's floor; back up, the text at main's call row; `read`, `close`, `write` stepped over, the bytes over the source, each text beside its call row; the close `below`. Every other pane on the shelf, the registers' strikes on their tag | the column (`column.zig`), the working frame `beside` at the opening and the close | `hello` | | `column_sort` | the column's wide placements on sort's first trip: the opening `below`, then the rings across both columns twice their size, the others on the shelf (`sort.c line 12`, `disassembly jne …`), a text `on` the drawing in the corner the rings leave free with its stem round the drawing's top to the pc's block; then a text `above` it; then the working frame again | `blocks`, then the drawing across both columns (`Stage.zoom`) | `sort` | -| `intro_memory` | the introduction's first chapter (design/motion.md, "A scene: the introduction", I1 to I10): the 128 bytes at the top of the stack under the camera at x2; `regroup`, sixteen a row to eight (the return address walked, the rest at a run); three words that hold addresses framed; into the column, the dump folded to a tag; the address space to scale (`segments`: a slim bar, then `enlarge` a cluster at a time, the stack, the libraries, the tracer's 64 MiB ring in a box of its own, the program by segment, start, end and size on every band), texts beside; back to the working frame: the dump's `tie` and `link` onto the stack's box, a visit at x4, `ink`, three chains | the working frame (`below`), the column for I4 to I6 | `list`, moment 77 (reverse's first `call`) | -| `intro_stack` | chapter II, from I's last picture: the words become the stack panel; the call's push walked as the tied stack walks it; `main+50` framed and the offsets counted; rbp's pin and the panel's tag; the registers built row by row; texts beside on the left, in the program column | the working frame without a backtrace, texts on the left | `list`, 77 to 78 | -| `intro_code` | chapter III: the code's bytes as a dump row in code's ink, an instruction's four framed; `decode` into `aligned` (`interleaved`, mock 33), the neighbours at a run; `align` to `columns` (mock 36); the working frame with the list's nodes, the camera at x1.5 and back; `surface` to the map | `aligned`, texts above; then `subject`, `nodes`; the map | `list`, moment 582 (the load on line 21) | +| `intro_memory` | the introduction's first chapter (design/motion.md, "A scene: the introduction", I1 to I10): the 128 bytes at the top of the stack under the camera at x2; `regroup`, sixteen a row to eight (the return address walked: the top row, so its bytes fly under it and its offsets stand over it; the rest at a run); three words that hold addresses framed; into the column, the dump folded to a tag; the address space to scale (`segments`, mock 34: a slim bar, then `enlarge` a cluster at a time, the stack, the libraries, the program by segment, start, end and size on every band), texts beside; back to the working frame: the dump's `tie` and `link` onto the stack's box (mock 30), a visit at x4, `ink`, three chains | the working frame (`below`), the column for I4 to I6 | `intro`, reverse's first instruction (`push rbp`) | +| `intro_stack` | chapter II (II1 to II4, mock 31), from I's last picture: the words glide into the stack panel's rows (sixteen and two `free` over rsp) and become it; rsp's row arrives over the stack, its pin on the top word; `push rbp` walked (the touch, the word, rsp's pin climbing); the way back framed, main's three rows round its call arriving in the program column and the word aimed at the row it returns to (`aim`, this beat only), the offsets a `column`; rbp's row and pin, `mov rbp, rsp` and `sub rsp` walked, the roles and the spans a `column` each, the panel's tag last (`frame up`); the registers built row by row, their tag last; texts beside on the left, in the program column | the working frame without a backtrace, texts on the left | `intro`, reverse's first three instructions | +| `intro_code` | chapter III (III1 to III5, mocks 32, 33, 36), from II's last picture (it gives way): the code's bytes as a dump row in code's ink, an instruction's four framed; `decode` into `aligned` (`interleaved`, mock 33: lines and addresses in one column, a rule over every group, the load's row annotated), the neighbours at a run; `align` to `columns` (mock 36); `stack` to the working frame (the lines glide to the source panel's rows, the instructions down and into the disassembly's, the panels come in under them); the list's nodes from the heap's bytes; each pane's minimap last; `surface` to the map, its text on it | `aligned`, texts above; then `subject`, `nodes`; the map | `intro`, the load on line 21 | | `asan` | plain against AddressSanitizer on `overflow.c` (design/motion.md, "A scene: ASan against a plain build", A1 to A16): a `pair` (A1 to A9, A14 to A16: the shared source, each run's disassembly, registers and frame as bytes eight a row with ASan's shadow byte beside each row, `only here` and `differs` bars, the parting framed `attention`, ASan's stderr in place of its registers once stopped) and the column for A10 to A13 (ASan folded to one shelf tag, its report's first line on it; plain's disassembly a descent, main's window over fill's whole; plain's frame the column's rest; each text level with the field the letter lands in; `aim = .standing`: the return address aims at main's row after the call, glides to `fill+1` at i = 24 and frays at i = 25); i = 27 held 4.9 s (mock 38, the poster); the fault at `ret` (SIGSEGV, rip stays) | `pair.split`, then the column | `overflow`, `overflow_asan`, `overflow_report` | ## The blocks @@ -213,10 +213,11 @@ every state the code has in the `gallery` scene. | 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 map's drawing is the `blocks` lens's (`graph.Blocks` at its size, 880 by 344, over the source: `split`'s band is the working frame's), the disassembly linear beside it with its blocks ruled. 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. `unroll` and `roll` (`Map.unroll`, `.roll`, `map.Unroll`, added over everything by `Context.ties`): the panes veiled and the strip's window framed bright (18 f), the pane's whole column growing out of its strip (36 f, `glide`) to as many rows as the stage holds (24 a row at most; right on the strip's edge, the window's rows level with the pane's where the stage allows), its scale on the logarithm from the strip's, the window's outline riding from the strip to the pane's rows in it; held as the scene says; `roll` the reverse (36 f), the veil lifting (18 f). A far jump in the same column at a walk (the source's window farther than its height to lines the map's column of the file holds too, `source.unrolling`, `inColumn`: no step said faster in a hurry) is `unroll`, the window travelling along the column (24 f, `glide`, the mark lighting gold at its new line as the window gets there, the tag's note changing then), `roll` (96 f: `Cursor.travel`), the pane going into the column and coming out of it at its new place, never a fade. Out of the column (another function, a long file) the map's column goes over as the advance starts, so the strip (6 to 11 f behind, a 6 f crossfade) shows where the pane goes before the pane fades through (`over`, `far` on the map at half its height); a window going farther than the column holds keeps its place on the strip until the column goes over (`spanOf2`); the tag's line range changes with the pane's fade; the map's disassembly is measured by the moment the pane shows (a continue repacks the map as the pane gets there), and a recording of breakpoints has its deepest chain read at every stop (`deepest`: the backtrace's box packed once) | | | `stage` and `relayout` | `src/stage.zig` | splits `none`, `beside`, `subject`, `blocks` (`theme.layout.split`, layout A: the disassembly under the source in every split; the source 14, 8, 8 and 6 lines, the disassembly 17, 17, 11 and 11 rows; `blocks` a drawing of 880 by 344 over the program column and no view, the state column the registers' and the stack's from the top), each for a registers panel of eleven rows; `layout.fit` gives the scene's registers their rows and the stack the rest above the backtrace, whole slots, any rest above it (`Stage.registers_rows`: every split a `relayout` goes to keeps them); 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; `glide` (a column's moves: no fit, no fade), `column` (the clock under the text column), `zoom` (the band's drawing drawn larger, its tag not: `graph.Blocks`) | | | `column` | `src/column.zig` (`Column`, `canim.column`, `beat`) | the shelf (y 48: each folded pane's tag in the frame's order, its note: the scene's, or computed for the registers (those the step changed, the first's value struck as on its row, crossfading with the strike), the source (`line 12`) and the disassembly (`jne 4011af`), crossfading with the advance); the panes from 84 to 1032, 12 apart; texts: `beside` (Go 40 on 54, at most 40 characters a line, 16 of padding, on `raised` while newest, dimming to `dim` without paper, three at most, level with their row, riding it until the panes change or the row goes, an older one gliding above the newest's place or under it), `below` (the caption band), `above` (a band over the drawing), `on` (where the scene puts it, its stem round the drawing's top lane); the change between beats (`change`: fade 6 f, fold where it stands and the tag to the shelf 18 f, glide 24 f (a pane crossing to the other column going down its own first, then across, 24 f each), unfold 18 f, fade in 6 f; a pane that changes its height keeps its rows: `Stage.resizing`, the descent's two layouts glided between, the source's window glided); a stem about a folded pane to its tag; `Beat.held`, and a bubble read past its beat flagged on stderr | -| | `segments` | `src/segments.zig` (`read`, `Segments`, `Place`) | the address space to true scale from the recording's mappings (permissions, file offsets): a slim bar the column's height, its ends' addresses and its size; clusters split at gaps of 16 MiB or more, and a band eight times the rest of its cluster in a box of its own; `enlarge` a box at a time (its bands with start, end and size, leaders to the bar), 108 wide; kept above y 888 under the camera (`clipStage`) | -| | the introduction's dump | `src/regroup.zig` (`Words`) | 128 bytes sixteen a row, no ink, the addresses faint; `regroup` to eight a row (bytes become words, low byte last), `ink`, `extend`, `become` (the words into the stack panel's rows) | -| | `aligned` | `src/aligned.zig` | the source and its instructions in one panel, each line level with its code: `interleaved` and `columns`; `decode` (an instruction's bytes to its row) and `align` (one form to the other) | -| | a text standing alone | `src/aside.zig` (`Aside`, `Asides`) | a column's bubble where no `Column` stands (the introduction's texts beside); `shortcut:` it repeats `column.zig`'s bubble drawing | +| | `segments` | `src/segments.zig` (`read`, `Segments`, `Place`) | the address space to true scale from the recording's mappings (permissions, file offsets), the tracer's own (its ring, its preloaded agent and the agent's bss) left out: a slim bar the column's height, its ends' addresses and its size; clusters split at gaps of 16 MiB or more, and a band eight times the rest of its cluster in a box of its own; `enlarge` a box at a time (its bands with start, end and size, leaders to the bar), 108 wide; an edge's address in the ink of the band that starts there; a file name past the column's edge cut with `…`; kept above y 888 under the camera (`clipStage`) | +| | the introduction's dump | `src/regroup.zig` (`Words`) | 128 bytes sixteen a row, no ink, the addresses faint; `regroup` to eight a row (bytes become words, low byte last; a word in the top four rows has no room over it at x2, so its bytes fly under it, over the veiled rows, and its offsets and labels stand over it, the header veiled with the rest), `ink`, `extend`, `become` (the bytes go, then the words and addresses glide into the stack panel's rows); with no heap word in the bytes, the first other address is framed | +| | `aligned` | `src/aligned.zig` | the source and its instructions in one panel, each line level with its code: `interleaved` and `columns`; the lines without their indent; the mnemonics after the longest instruction's bytes; the pc's row annotated (what it reads, its chain); `decode` (an instruction's bytes to its row), `align` (one form to the other: the bytes go first, then the columns glide) and `stack` (to the working frame: the heads' paper, rules and tag out 12 f, the lines to the source panel's rows 36 f, the instructions down their column 24 f and into the disassembly's rows 24 f, those its window does not show fading past its edge; the scene fades the panels in under them) | +| | a text standing alone | `src/aside.zig` (`Aside`, `Asides`) | a column's bubble where no `Column` stands (the introduction's texts beside, and the one on the map); a newline breaks where the author says; one the new text would stand on leaves first, then a gap; `shortcut:` it repeats `column.zig`'s bubble drawing | +| | a caller's rows alone, a stack built a column at a time | `src/descent.zig` (`Caller`), `src/context.zig` (`Stack.reveal`) | `Caller`: a descent's head row over a call, the row it returns to and the next, each a `row` place for an `aim` (chapter II's main); `reveal`: the stack's offsets, roles and spans each under the page until the scene's clock lets them in top down (`column`, 2 f apart, 12 f each) | | | `pair` | `src/pair.zig` (`split`, `Frame`, `Report`, `Marks`, `Clock`, `Shelf`) | two runs on either side of the seam (design/README.md, `pair`): `split` each side's stage; `Frame` a frame as bytes eight a row read by its fields (`hexdump` `eight`: fields live from a moment, the letters keeping a string's ink in a pointer's field, the shadow byte of each row beside it, tall in the column, its words said as values for the relations); `Report` a stopped run's stderr in place of its registers; `Marks` `only here`, `differs`, `attention` and the `fault` (hazard bands round an ink plaque, SIGSEGV); `Clock` one rule and each run's moment; `Shelf` a folded side's tag | | | `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`; `unroll` and `roll` (`Map.unroll`, `Map.roll`, above); `reach` and `unfold` (`graph`, above); `leave` and `turn` (`graph.leave`, from a block's last row, `graph.toEnd` to get there, along the curves of `rings` or `layers`: 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, its point the way it goes) along the edge 42 to 42 + 12 f and 2 f a 100 units of the drawing's edge (42 f at most), round the ring's foot for a turn; landing, the advance; the target's count armed and struck 6 f after (a ring's turns at its centre armed as the mark leaves the latch, struck 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 | @@ -278,6 +279,7 @@ before. The source panel follows the pc into any file it has | `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), 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 | +| `intro` | `list.c` again, as `list` is built | every instruction, `--from list.c:41` (main's call of reverse), `--until list.c:22` (past the load); run as `./list` | 588 (70 of them the loader's and the agent's syscalls before main), 187 KB | as `list`: `--alloc --preload`, `--ring` | | `overflow` | `overflow.c` (design/mock/overflow.c: a loop writing 32 bytes into `char buf[16]`), the system's clang `-O0 -g -fno-omit-frame-pointer -no-pie -fno-stack-protector`, glibc | every instruction, `--from main`, to the fault | 298, 60 KB | the recorder says `exit 139`; the SIGSEGV on the moment after `ret`, rip unchanged | | `overflow_asan` | the same with `-fsanitize=address`, `ASAN_OPTIONS=detect_leaks=0` | every instruction, `--from main`, `--steps 582` (to `__asan_report_store1`'s first instruction) | 785, 257 KB | `--asan` (the shadow); the fake frame's header parsed by the scene from memory | | `overflow_report` | the same run | `--by syscall --stack 0 --telescope 0 -s 4096` | 707, 401 KB | the report: its `write(2, …)`s, shown from their capture; `exit 1` | @@ -350,30 +352,47 @@ 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. -| | fib | list | sort | syscalls | musl | zoom | sqlite | heap | gallery | title | column | column_sort | asan | -| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| POP, before / after | 10 / 3 | 13 / 10 | 3 / 4 | 21 / 14 | 16 / 7 | 5 / 2 | 7 / 6 | 17 / 15 | 9 / 9 | 0 / 0 | 9 / 4 | 6 / 6 | – / 29 | -| of them the strips', before / after | 1 / 1 | 4 / 4 | 2 / 3 | 8 / 9 | 1 / 1 | 2 / 1 | 0 / 0 | 6 / 5 | 3 / 3 | 0 / 0 | 4 / 2 | 3 / 3 | – / 0 | -| POP exempt, before / after | | – / keyframe 1 | | | | | | | cut 5 / cut 5 | | | | | -| CROWD, before / after | 3 / 3 | 8 / 7 | 6 / 8 | 4 / 4 | 8 / 6 | 4 / 3 | 2 / 2 | 18 / 17 | 6 / 5 | 0 / 0 | 0 / 0 | 0 / 0 | – / 15 | -| METRONOME, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 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 | 1 / 0 | 2 / 0 | 1 / 0 | 0 / 0 | 0 / 0 | 1 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | 0 / 0 | 1 / 1 | – / 1 | -| CAPTION under its reading time, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | | not checked | not checked | not checked | -| 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 / 0 | | not checked | 1 / 1 | not checked | -| AIR, before / after | 0 / 0 | 0 / 0 | 1 / 1 | 0 / 0 | 0 / 0 | 1 / 1 | 1 / 1 | 0 / 0 | 1 / 1 | 1 / 1 | 1 / 0 | 0 / 0 | – / 1 | -| seconds, before / after | 50.2 / 48.2 | 88.0 / 83.9 | 72.9 / 74.5 | 85.4 / 85.4 | 77.5 / 66.8 | 38.0 / 34.9 | 62.9 / 62.9 | 80.2 / 80.2 | 27.0 / 27.0 | 12.3 / 12.3 | 104.8 / 95.3 | 30.6 / 29.5 | – / 120.0 | +| | fib | list | sort | syscalls | musl | zoom | sqlite | heap | gallery | title | column | column_sort | asan | intro_memory | intro_stack | intro_code | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| POP, before / after | 10 / 3 | 13 / 10 | 3 / 4 | 21 / 14 | 16 / 7 | 5 / 2 | 7 / 6 | 17 / 15 | 9 / 9 | 0 / 0 | 9 / 4 | 6 / 6 | – / 29 | – / 1 | – / 0 | – / 0 | +| of them the strips', before / after | 1 / 1 | 4 / 4 | 2 / 3 | 8 / 9 | 1 / 1 | 2 / 1 | 0 / 0 | 6 / 5 | 3 / 3 | 0 / 0 | 4 / 2 | 3 / 3 | – / 0 | – | – | – | +| POP exempt, before / after | | – / keyframe 1 | | | | | | | cut 5 / cut 5 | | | | | | | | +| CROWD, before / after | 3 / 3 | 8 / 7 | 6 / 8 | 4 / 4 | 8 / 6 | 4 / 3 | 2 / 2 | 18 / 17 | 6 / 5 | 0 / 0 | 0 / 0 | 0 / 0 | – / 15 | – / 0 | – / 0 | – / 0 | +| METRONOME, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 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 | 1 / 0 | 2 / 0 | 1 / 0 | 0 / 0 | 0 / 0 | 1 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | 0 / 0 | 1 / 1 | – / 1 | – / 1 | – / 0 | – / 0 | +| CAPTION under its reading time, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | | not checked | not checked | not checked | not checked | not checked | not checked | +| 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 / 0 | | not checked | 1 / 1 | not checked | – / 1 | – / 0 | – / 1 | +| AIR, before / after | 0 / 0 | 0 / 0 | 1 / 1 | 0 / 0 | 0 / 0 | 1 / 1 | 1 / 1 | 0 / 0 | 1 / 1 | 1 / 1 | 1 / 0 | 0 / 0 | – / 1 | – / 0 | – / 1 | – / 1 | +| seconds, before / after | 50.2 / 48.2 | 88.0 / 83.9 | 72.9 / 74.5 | 85.4 / 85.4 | 77.5 / 66.8 | 38.0 / 34.9 | 62.9 / 62.9 | 80.2 / 80.2 | 27.0 / 27.0 | 12.3 / 12.3 | 104.8 / 95.3 | 30.6 / 29.5 | – / 120.0 | – / 67.2 | – / 31.8 | – / 40.8 | "Before" is the last pass's "after" (its gallery and title were the pass before's: this pass exports every scene again). `asan` is new; the introduction's three scenes (`intro_memory`, `intro_stack`, `intro_code`) -are built and tested but not exported (the round's order moved them to the -next). The column's, column_sort's and asan's "caption" regions are not a +are this pass's, exported alone (the other scenes' columns are the last +pass's). The column's, column_sort's and asan's "caption" regions are not a caption's (the text column, a drawing's band), so their CAPTION lines are not a caption's; the column's own check is the renderer's (`column: bubble N is still read …`): C2's bubble (74 characters) 1.8 s past its three steps. +The introduction's texts beside are not in the caption band either: in +`intro_memory` the band is empty for the column part (21.7 to 43.4 s), which +the instrument reads as one caption up 22 s with the picture moving; in +`intro_code` the caption leaving before `surface` (33.1 s) is read as one +arriving; the reading times are the scenes' own (`Narrator`, `Asides`: each +text waits until the last is read). `intro_memory`'s POP (31.20) is the +first `enlarge`'s line framed bright, 2 units over its 6 f (looked at, frame +by frame: it comes in over the 6 f; the instrument counts 75 pixels, then +36). The two AIRs are the chapters' last pictures, II4's and III5's texts +read and the 2 s before the cut. -What this pass changed, a kind of one-frame change at a time, each at its -block (the catalogue's rule: nothing changes in one frame): +This pass (the introduction) changed, outside its three scenes: a pin +joining another's row in front of its names (`mov rbp, rsp`: rbp onto rsp) +lets its own head go as it lands, not in the advance's frame (`Stack`); the +pc's triangle on `aligned`'s plaque is drawn where it is (it was transformed +twice, off the stage); `segments` leaves the tracer's own mappings out, +inks an edge by the band that starts there and cuts a long file name; the +build records `intro` (`Recording.until`, `.program`). The last pass +changed, a kind of one-frame change at a time, each at its block (the +catalogue's rule: nothing changes in one frame): - An instruction's in-step annotation (`lea`'s `= 402004 ← "note"`, a register's first value, a compare's flags, the canary's word, `rbp = @@ -500,21 +519,30 @@ What fires still (the finals; located where it says so): 582`), which moves with the compiler; the fake frame's header is parsed by the scene from memory, plain's fields from the instructions' rbp offsets, and the two runs' stops are matched by pc. -- The introduction (`intro_memory`, `intro_stack`, `intro_code`): built and - tested before the round's order moved it to the next round; not exported, - and its chapters II and III not looked at again after their last texts - were cut. Chapter I follows its storyboard (68 s against 66): the bytes - under the camera, `regroup`, `segments` and `enlarge` (with a box of its - own for the tracer's 64 MiB ring, which the recording's mappings hold), - the tie, the visit, `ink`, the chains. II has no touch line (no - disassembly row on screen), its roles and spans come with the rows, its - stack shows 23 words (16 asked), its registers are canim's folded layout - (not mock 31's seventeen rows). III has no annotation column (mock 33's - chain) and no keyword ink in its source, `stack` is a crossfade (not a - morph), the minimaps do not draw themselves last, and the map's text is a - caption, not `on` the map. All three use `list` (moment 77; 582 for III): - `--from reverse` stops past the prologue, so the `push rbp` the storyboard - names is the call's push of its return address. +- The introduction (`intro_memory`, `intro_stack`, `intro_code`), exported: + where it differs from its storyboard and mocks. The recording is `intro` + (main's call of reverse to past the load), so the push II walks is + reverse's own `push rbp` and I's 128 bytes are at rsp at that push (the + return address the top word); the return address is `main+50` + (`402412`), not the storyboard's `main+80`. I (67 s against 66): the + walked word is the top row, with no room over it at x2, so its bytes fly + under it (mock 37 flies them over); a library's file name past the + column's edge is cut (`ld-linux-x86-64…`; mock 34 says `ld.so`); the + instrument's one POP (31.2 s) is the first `enlarge`'s line framed + bright, 2 units over 6 f, looked at. II (32 s against 26.5): `mov rbp, + rsp` and `sub rsp` are walked too, so rbp's pin and the frame's span come + from the recording, not drawn on; its registers are canim's folded + layout at x1 (mock 31: seventeen rows at x1.25), so the stack keeps its + eighteen rows; main's rows fade at III's opening rather than staying + under III's disassembly (III's code is reverse's). III (41 s against + 30.3): it opens on II's last picture, which gives way (the held corners + of II's last step are not on it); `columns` (mock 36) is a beat of its + own after `interleaved`; no camera (at x1.5 the band's nodes and its + dump do not both fit, and the storyboard's "out to x1" has no "in"); the + minimaps draw themselves 48 f apart (the long text would stand still + over 3 s); the map's text is a bubble on the map's empty middle foot. + The caption checks cannot pair the texts beside with the caption band, + so their reading times are the scenes' own (`Asides`, `Narrator`). - The relations: arcs within a panel (the stack's, a dump's, a loupe's) are still each panel's own (`rows.Arcs`, lanes per panel), not rows of the frame's tables; the column's stems are drawn by the column, their diff --git a/anim/build.zig b/anim/build.zig index 9c7d63e..63d962e 100644 --- a/anim/build.zig +++ b/anim/build.zig @@ -107,6 +107,10 @@ pub fn build(b: *std.Build) void { glibc: bool = false, /// Stops after `from` before the recording ends: main's return, not the exit's. steps: ?[]const u8 = null, + /// Ends the recording at the first stop here (`--until`). + until: ?[]const u8 = null, + /// The name it runs by (argv[0], its mapping), where not the recording's. + program: ?[]const u8 = null, /// Also glibc's heap at every stop (`--heap`), and memory watched (`-w`). heap: bool = false, watch: []const []const u8 = &.{}, @@ -130,6 +134,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 }, + // The introduction's: the same program from main's call of reverse + // (its push of the way back, reverse's prologue) to line 22, past the load. + .{ .name = "intro", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "list.c:41", .until = "list.c:22", .alloc = true, .program = "list" }, // `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" }, @@ -164,7 +171,8 @@ pub fn build(b: *std.Build) void { // environment: the strings on its stack (its name, its variables) // end up on screen, and should say nothing of the machine it was made on. const where = b.addWriteFiles(); - _ = where.addCopyFile(program, r.name); + const runs_as = r.program orelse r.name; + _ = where.addCopyFile(program, runs_as); 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, @@ -196,6 +204,7 @@ pub fn build(b: *std.Build) void { run.addArgs(&.{ "--by", r.by, "--stack", r.stack, "--around", "256", "--disasm", "69", "-s", "64" }); if (r.from) |place| run.addArgs(&.{ "--from", place }); if (r.steps) |n| run.addArgs(&.{ "--steps", n }); + if (r.until) |place| run.addArgs(&.{ "--until", place }); if (r.heap) run.addArg("--heap"); for (r.watch) |what| run.addArgs(&.{ "-w", what }); // What an instrumented program tells of itself comes through a ring. @@ -206,7 +215,7 @@ pub fn build(b: *std.Build) void { } run.addArg("-o"); const trace = run.addOutputFileArg(b.fmt("{s}.ztrace", .{r.name})); - run.addArgs(&.{ "--", b.fmt("./{s}", .{r.name}) }); + run.addArgs(&.{ "--", b.fmt("./{s}", .{runs_as}) }); run.setCwd(where.getDirectory()); run.expectExitCode(0); run.expectStdErrMatch("exit 0"); diff --git a/anim/scenes/intro_code.zig b/anim/scenes/intro_code.zig index a5660ed..b50c971 100644 --- a/anim/scenes/intro_code.zig +++ b/anim/scenes/intro_code.zig @@ -1,14 +1,16 @@ //! The introduction, chapter III: code and meaning (design/motion.md, "A //! scene: the introduction", III1 to III5; mocks 32, 33, 36). On the -//! `list` recording at the load in `reverse` (line 21, `node *next = +//! `intro` recording at the load in `reverse` (line 21, `node *next = //! cur->next;`, the instruction that reads `cur->next`): the code's bytes //! as a dump row, that instruction's four framed; `decode`d into its row //! of `aligned` (`interleaved`), its neighbours at a run, each line level //! with its run; then `align` to `columns`; then the working frame with the -//! nodes drawn from the heap's bytes; then the map (`surface`). The texts -//! `above` the aligned panel, then below the working frame. +//! nodes drawn from the heap's bytes, each pane's minimap drawing itself +//! last; then the map (`surface`). The texts `above` the aligned panel, +//! then below the working frame, and the last one on the map. const std = @import("std"); const anim = @import("anim"); +const sk = @import("sketch"); const canim = @import("canim"); const recordings = @import("recordings"); @@ -33,11 +35,60 @@ fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 { return from; } +/// The page over a part not drawn yet (a pane's minimap until III4). +const Page = struct { + box: canim.Rect, + pub fn draw(c: *const Page, fr: *sk.Frame, placed: anim.Placed) void { + (canim.ui.Ui{ .f = fr, .at = placed }).fill(c.box, canim.theme.color.page); + } +}; + +/// Chapter II's last picture (scenes/intro_stack.zig, its layout and texts +/// as there): its registers and stack, a context of their own at II's last +/// moment; main's rows, faint; II3's text dimmed and II4's. +fn lastOfTwo(s: *anim.Frame, rec: *canim.Recording) struct { panels: [3]anim.Obj, texts: [2]anim.Obj } { + const enter = rec.call("reverse", 0).enter; + const last = enter + 3; + const row = canim.theme.metric.context.row; + const head = canim.theme.metric.context.tag + canim.theme.metric.context.pad; + var at = canim.cursor(s, rec, enter); + at.journey(.moment, last); + at.levels = .{ .fire = .disasm, .source_rows = 14 }; + at.jump(s, last); + var split = canim.layout.split.none; + split.backtrace.h = 0; + const ctx = canim.context(s, at, .{ .split = split }); + const rb = ctx.stage.first.registers; + ctx.stage.first.stack.h = canim.layout.panelH(18); + ctx.stage.first.stack.y = rb.y + rb.h + canim.theme.canvas.row_gap; + const top = ctx.stage.first.stack.y + head; + const rsp = rec.register(enter, "rsp"); + const window = rec.register(last, "rsp") - 16; + const rowY = struct { + fn y(t0: f32, from: u64, addr: u64) f32 { + return t0 + row * @as(f32, @floatFromInt(@as(i64, @bitCast(addr -% from)) >> 3)); + } + }.y; + const stack = canim.add(s, canim.Stack{ .cursor = ctx.cursor, .stage = ctx.stage }); + const back_y = rowY(top, rsp - 8 - 16, rsp); + // (Placed at the origin: it draws at its own box.) + const caller = s.custom(s.new(canim.descent.Caller{ .rec = rec, .at = enter, .call = rec.register(enter - 1, "rip"), .box = .{ .x = canim.theme.layout.program.x, .y = back_y + row / 2 + 176, .w = canim.theme.layout.program.w, .h = 4 * row }, .in = s.value(999), .faint = s.value(1) }), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); + const left = canim.theme.canvas.margin_x; + const said = [2]canim.Aside{ + .{ .text = "A function's words are its frame: the saved rbp, its locals, the way back.", .x = left, .level = (rowY(top, window, window + 16) + rowY(top, window, rsp + 8)) / 2, .dim = s.value(1) }, + .{ .text = "The registers are the other place values live: seventeen of them.", .x = left, .level = rb.y + head + row * 2.5, .dim = s.value(0) }, + }; + var texts: [2]anim.Obj = undefined; + for (said, &texts) |a, *o| o.* = s.custom(s.new(a), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); + for ([_]anim.Obj{ ctx.registers, stack, caller, texts[0], texts[1] }) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 }); + return .{ .panels = .{ ctx.registers, stack, caller }, .texts = texts }; +} + /// The variables whose tags the nodes carry, as the list scene's. const tracked = [_][]const u8{ "prev", "cur", "next", "head" }; fn frame(s: *anim.Frame) void { - const rec = canim.open(recordings.list); + const rec = canim.open(recordings.intro); const reverse = rec.call("reverse", 0); // The load: `cur->next` read, line 21's second instruction. const moment = on(rec, rec.lineMoment(21, reverse.enter), "[rax + 8]"); @@ -52,6 +103,10 @@ fn frame(s: *anim.Frame) void { for (code[0..insn.len], 0..) |b, k| hex.print(s.arena, "{s}{x:0>2}", .{ if (k > 0) " " else "", b }) catch {}; const text = std.mem.replaceOwned(u8, s.arena, insn.text, "qword ptr ", "") catch insn.text; + // Chapter II's last picture, which this chapter opens on (II's own + // context at II's last moment, laid out as II has it, under this one's). + const opening = lastOfTwo(s, rec); + var at = canim.cursor(s, rec, moment); at.journey(.moment, moment + 1); at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 8 }; @@ -60,6 +115,13 @@ fn frame(s: *anim.Frame) void { ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &tracked }); const joins = ctx.ties(s); + // Each pane's minimap under the page until III4, where they draw themselves last, top down + // (over the panels, under the aligned rows landing on them; on from the panels' first frame). + const first = ctx.stage.first; + var strips: [4]anim.Obj = undefined; + for ([_]canim.Rect{ first.view, first.source, first.stack, first.disasm }, &strips) |b, *o| + o.* = s.custom(s.new(Page{ .box = .{ .x = b.x + b.w - canim.theme.strip.cost, .y = b.y + canim.theme.metric.context.tag, .w = canim.theme.strip.cost - canim.theme.stroke.rule, .h = b.h - canim.theme.metric.context.tag - canim.theme.stroke.rule } }), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); + const al = s.new(canim.Aligned.init(s, rec, moment)); const panel = s.custom(al, .{ .x = -640, .y = -360, .scale = canim.ui.scale }); s.play(.{panel.fadeIn()}, .{ .seconds = 0 }); @@ -67,8 +129,14 @@ fn frame(s: *anim.Frame) void { const left = canim.theme.canvas.margin_x; const above = canim.theme.canvas.stage.y + 40; + // From II's last picture: it gives way (its texts 12 f, the rest 18 f), the stage clear for the code. + s.wait(t.beat); + s.play(.{ opening.texts[0].fadeOut(), opening.texts[1].fadeOut() }, .{ .seconds = t.caption_out, .ease = canim.ease.exit }); + s.cursor -= t.caption_out; + s.play(.{ opening.panels[0].fadeOut(), opening.panels[1].fadeOut(), opening.panels[2].fadeOut() }, .{ .seconds = f(18), .ease = anim.ease.linear }); + s.wait(t.beat); + // III1: the code's bytes, one instruction's framed. - s.wait(1.0); asides.say(s, std.fmt.allocPrint(s.arena, "Code is bytes too: `{s}` is one instruction.", .{hex.items}) catch "", left, above); s.wait(t.caption_lead); run(s, al.bytes, 12 + 2 * 15 + 12 + 6); @@ -83,28 +151,46 @@ fn frame(s: *anim.Frame) void { // III2, the other form: two columns, each line level with the first of its instructions. asides.say(s, "Two columns: each line level with its first instruction.", left, above); - run(s, al.form, 72); + run(s, al.form, 80); s.wait(t.beat); - // Into the working frame: the texts above leave, the panel goes, the frame comes in. + // Into the working frame: the texts above leave; `stack`: the lines glide to + // the source panel's rows, the instructions to the disassembly's (60 f); those + // panels come in under them as the aligned rows go (12 f): the same rows; then + // the band and the state column (`establish`). asides.leave(s); - s.play(.{panel.fadeOut()}, .{ .seconds = f(12), .ease = anim.ease.linear }); + al.to = .{ .source = ctx.stage.first.source, .disasm = ctx.stage.first.disasm }; + run(s, al.stack, 60); + s.play(.{ strips[0].fadeIn(), strips[1].fadeIn(), strips[2].fadeIn(), strips[3].fadeIn() }, .{ .seconds = 0 }); + s.play(.{ ctx.source.fadeIn(), ctx.disasm.fadeIn(), panel.fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear }); var says: canim.Narrator = .{}; - var cam: canim.Camera = .{}; - canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, joins }); + canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, joins }); // III3: the node it reads, as bytes and drawn: the band comes in, its - // elements rising from their bytes, and the camera nearer on it (x1.5). + // elements rising from their bytes. No camera: at x1.5 the drawing's + // nodes and its bytes do not both fit the frame, and the band is whole at x1. says.line(s, "`rax` points at a list node on the heap:\nits bytes, and drawn, the node."); - ctx.establish(s, .{list}, 3); - cam.go(s, .{ .x = 512, .y = 48, .w = 896, .h = 296 }, 1.5, .{}); + // The heap's dump first, in the band's right half (18 f); then the nodes drawn from it, rising (`establish`). + s.play(.{ctx.stage.drawing.to(0)}, .{ .seconds = 0 }); + s.play(.{list.fadeIn()}, .{ .seconds = f(18), .ease = anim.ease.linear }); + s.wait(f(30)); + s.play(.{ctx.stage.drawing.to(1)}, .{ .seconds = f(12), .ease = anim.ease.linear }); + s.cursor -= f(12); + ctx.establish(s, .{}, 3); s.wait(t.beat); - // III4: the whole frame: the camera back to x1. + // III4: the whole frame; each pane's minimap draws itself, last, top down (24 f, 48 f apart). says.line(s, "This is the whole frame.\nEvery view in it is these same bytes."); - cam.back(s, .{}); + const strips_from = s.cursor; + for (strips, 0..) |o, k| { + s.cursor = strips_from + f(48 * @as(f32, @floatFromInt(k))); + s.play(.{o.fadeOut()}, .{ .seconds = f(24), .ease = anim.ease.linear }); + } s.wait(t.beat); - // III5: the map. - says.line(s, "And all of it at once: the map."); + // III5: the map, and its text on it, in the key's corner (the middle column's foot, empty on this map). + s.wait(@max(says.read_by - s.cursor, 0)); + s.play(.{says.current.?.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit }); + s.wait(t.caption_gap); ctx.map.surface(s); - says.close(s); - cam.apply(s); + asides.say(s, "And all of it at once:\nthe map.", 528, 720); + s.wait(@max(asides.read_by - s.cursor, 0)); + s.wait(t.before_cut); } diff --git a/anim/scenes/intro_memory.zig b/anim/scenes/intro_memory.zig index 07e694a..7aec267 100644 --- a/anim/scenes/intro_memory.zig +++ b/anim/scenes/intro_memory.zig @@ -1,8 +1,8 @@ //! The introduction, chapter I: memory (design/motion.md, "A scene: the //! introduction", I1 to I10; mocks 29, 30, 34, 37). The frame built from -//! its bytes up, on the `list` recording stopped in `reverse`'s prologue, -//! at its first call (line 17: the push chapter II walks; the 128 bytes at -//! rsp then are the load's but for `prev`, not yet stored), each part in +//! its bytes up, on the `intro` recording (the list program from main's +//! call of `reverse`) at reverse's first instruction, its `push rbp` (the +//! push chapter II walks; rsp holds the way back to main), each part in //! the place it keeps: the 128 bytes at the top //! of the stack where the stack panel will stand, under the camera at x2; //! made words (`regroup`); three of them addresses; then the address space @@ -36,22 +36,10 @@ fn start(s: *anim.Frame, v: anim.Value, frames: f32) void { s.cursor = at; } -/// The first moment from `from` whose instruction reads `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.indexOf(u8, here.text, text) != null) return i; - return from; -} - fn frame(s: *anim.Frame) void { - const rec = canim.open(recordings.list); - const reverse = rec.call("reverse", 0); - // reverse's first call (line 17, the tracer's `__zt_var` for its first - // local): the push chapter II walks. The recording begins after - // reverse's own `push rbp` (`--from` breaks past the prologue), so it is - // the first push of reverse's that the recording has. - const moment = on(rec, reverse.enter, "call"); + const rec = canim.open(recordings.intro); + // reverse's first instruction (its call's first moment): its `push rbp`, which chapter II walks. + const moment = rec.call("reverse", 0).enter; const ui = canim.ui; const at = canim.regroup.at; @@ -121,7 +109,7 @@ fn frame(s: *anim.Frame) void { const clusters = @min(l.space.clusters.len, 6); var top_end: usize = 0; while (top_end < clusters and l.space.clusters[top_end].lo > canim.segments.user_end / 2) top_end += 1; - asides.say(s, "Enlarged, the top end: the stack, the libraries and the tracer's ring, each band with its addresses and size.", column_x, l.boxes[0].y + 12); + asides.say(s, "Enlarged, the top end: the stack, then the libraries, each band with its addresses and size.", column_x, l.boxes[0].y + 12); for (0..top_end) |i| { start(s, space.rides[i], 6 + 72 + 90 + 2 * 12 + 12); s.wait(f(78)); diff --git a/anim/scenes/intro_stack.zig b/anim/scenes/intro_stack.zig index e504ffc..49162e6 100644 --- a/anim/scenes/intro_stack.zig +++ b/anim/scenes/intro_stack.zig @@ -1,17 +1,22 @@ //! The introduction, chapter II: the stack (design/motion.md, "A scene: the //! introduction", II1 to II4; mock 31). It opens on chapter I's last -//! picture, at the same moment of the `list` recording (reverse's first -//! call, line 17): the address space and the dump's link fade, the words -//! glide into the stack panel's rows where it stands in the working frame -//! and become it; a push walked from the recording (that call's: the -//! address to come back to, rsp's pin climbing onto it); the return -//! address main left, and the offsets; rbp's pin and the panel's tag last; -//! then the registers built over it a row at a time, their tag last. The -//! text stands beside on the left, in the program column, empty until -//! chapter III. +//! picture, at the same moment of the `intro` recording (reverse's first +//! instruction, its `push rbp`): the address space and the dump's link +//! fade, the words glide into the stack panel's rows where it stands in the +//! working frame (sixteen of them and two `free` over rsp) and become it. +//! rsp's row arrives over the stack and its pin lands on the top word; the +//! push walked from the recording (rsp's pin climbing onto the saved rbp). +//! The way back main left framed, main's three rows round its call arriving +//! in the program column, the word aimed at the row it returns to (`aim`, +//! this beat only), the offsets a `column`. rbp's row and pin, `mov rbp, +//! rsp` and `sub rsp` walked: the frame; its roles and spans, a `column` +//! each, the panel's tag last (`frame up`). Then the registers built over +//! it a row at a time, their tag last. The text stands beside on the left, +//! in the program column, empty until chapter III but for main's rows. //! -//! What a beat has not reached yet is under the page (`Cover`), lifted as -//! the beat says it: the context's panels draw every column at once. +//! What a beat has not reached yet is under the page (`Cover`, and the +//! stack's own `reveal`), lifted as the beat says it: the context's panels +//! draw every column at once. const std = @import("std"); const anim = @import("anim"); const sk = @import("sketch"); @@ -80,59 +85,62 @@ fn lift(s: *anim.Frame, covers: []const ?anim.Obj, apart: f32, each: f32) void { s.cursor = end; } -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.indexOf(u8, here.text, text) != null) return i; - return from; -} - /// A value at once, from the cursor. fn set(s: *anim.Frame, v: anim.Value, to: f32) void { s.play(.{v.to(to)}, .{ .seconds = 0 }); } +/// Clock `v` from 0 to `frames`, linear, from the cursor; the cursor after it. +fn run(s: *anim.Frame, v: anim.Value, frames: f32) void { + s.play(.{v.to(0)}, .{ .seconds = 0 }); + s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear }); +} + fn frame(s: *anim.Frame) void { - const rec = canim.open(recordings.list); + const rec = canim.open(recordings.intro); const reverse = rec.call("reverse", 0); - // Chapter I's moment: reverse's first call, whose push is walked here. - const moment = on(rec, reverse.enter, "call"); + // Chapter I's moment: reverse's first instruction, `push rbp`; then `mov rbp, rsp` and `sub rsp, 0x20`. + const moment = reverse.enter; + const framed = moment + 3; var at = canim.cursor(s, rec, moment); - at.journey(.moment, moment + 1); + at.journey(.moment, framed); at.levels = .{ .fire = .disasm, .source_rows = 14 }; - // The working frame with no backtrace: the stack goes to the stage's foot under the registers. var split = canim.layout.split.none; split.backtrace.h = 0; const ctx = canim.context(s, at, .{ .split = split }); - const sb = ctx.stage.first.stack; + // Sixteen slots and the headroom under the registers' box (the words + // become them where they stand), not the column's rest. const rb = ctx.stage.first.registers; + ctx.stage.first.stack.h = canim.layout.panelH(18); + ctx.stage.first.stack.y = rb.y + rb.h + canim.theme.canvas.row_gap; + const sb = ctx.stage.first.stack; const rsp = rec.register(moment, "rsp"); - const rsp_after = rec.register(moment + 1, "rsp"); // The window has two `free` words over rsp; rows from the panel's tag and padding. const first = rsp - 16; const top = sb.y + tag + pad; const slots = canim.layout.rowsIn(sb.h); const rowY = struct { fn y(t0: f32, from: u64, addr: u64) f32 { - return t0 + row * @as(f32, @floatFromInt((addr - from) / 8)); + return t0 + row * @as(f32, @floatFromInt(@as(i64, @bitCast(addr -% from)) >> 3)); } }.y; - // What has not been said yet, under the page: the stack's offsets, the - // pins' lane under rsp's row, its tag, rules and strip; the registers' rows, tag and rules. - var offsets: [32]?anim.Obj = @splat(null); - var lane: [32]?anim.Obj = @splat(null); - const rsp_row = (rsp - first) / 8; - for (0..@min(slots, 32)) |k| { - const y = top + row * @as(f32, @floatFromInt(k)); - offsets[k] = cover(s, .{ .x = sb.x + 92, .y = y, .w = 84, .h = row }); - if (k > rsp_row) lane[k] = cover(s, .{ .x = sb.x + 2, .y = y, .w = 88, .h = row }); - } - const stack_chrome = chrome(s, sb, true); + // The panels and the page over what they have not said yet, first: chapter I's + // picture, the words gliding into the stack among them, draws over them. + // The stack, its offsets, roles and spans under the page until their beats. + const reveal: canim.Stack.Reveal = .{ .offsets = s.value(-1), .roles = s.value(-1), .spans = s.value(-1) }; + const stack = canim.add(s, canim.Stack{ .cursor = ctx.cursor, .stage = ctx.stage, .reveal = reveal }); + // The registers, under the page: rbp's and rsp's rows (the scene's two, the first two), the rest, the chrome. + s.play(.{ctx.registers.fadeIn()}, .{ .seconds = 0 }); var regs_rows: [16]?anim.Obj = @splat(null); for (0..@min(canim.layout.rowsIn(rb.h), 16)) |k| - regs_rows[k] = cover(s, .{ .x = rb.x + 2, .y = rb.y + tag + pad + row * @as(f32, @floatFromInt(k)), .w = rb.w - 4, .h = row }); + // (From the third row on 2 higher: the rule over the folded rows goes with them.) + regs_rows[k] = cover(s, .{ .x = rb.x + 2, .y = rb.y + tag + pad + row * @as(f32, @floatFromInt(k)) - @as(f32, if (k >= 2) 2 else 0), .w = rb.w - 4, .h = row + @as(f32, if (k >= 2) 2 else 0) }); const regs_chrome = chrome(s, rb, false); + // The pins' lane under the free words: rsp's row's lifted with rsp, the rest with rbp. + var lane: [32]?anim.Obj = @splat(null); + for (2..@min(slots, 32)) |k| lane[k] = cover(s, .{ .x = sb.x + 2, .y = top + row * @as(f32, @floatFromInt(k)), .w = 116, .h = row }); + const stack_chrome = chrome(s, sb, true); // Chapter I's last picture: the address space, the words with their chains, the link standing. const space = s.new(canim.Segments.init(s, rec, moment)); @@ -148,33 +156,57 @@ fn frame(s: *anim.Frame) void { set(s, dump.left, 24); const objs = .{ place(s, space), place(s, dump), place(s, tie) }; inline for (objs) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 }); - const main_word: canim.Rect = .{ .x = sb.x + canim.theme.metric.slot.address + 12 * 12 + canim.theme.metric.context.arrow_w, .y = rowY(top, rsp_after - 16, rsp + 8 * dump.walked), .w = 6 * 12, .h = row }; - const framed = place(s, s.new(Read{ .box = main_word })); + + // main's rows, in the program column under II2's text; the aim joins them to the word. + const rsp_after = rec.register(moment + 1, "rsp"); + const back_y = rowY(top, rsp_after - 16, rsp); + const main_rows = s.new(canim.descent.Caller{ .rec = rec, .at = moment, .call = rec.register(moment - 1, "rip"), .box = .{ .x = canim.theme.layout.program.x, .y = back_y + row / 2 + 176, .w = canim.theme.layout.program.w, .h = 4 * row }, .in = s.value(-1), .faint = s.value(0) }); + s.play(.{place(s, main_rows).fadeIn()}, .{ .seconds = 0 }); + const main_word: canim.Rect = .{ .x = sb.x + canim.theme.metric.slot.address + 12 * 12 + canim.theme.metric.context.arrow_w, .y = back_y, .w = @as(f32, @floatFromInt(canim.ui.digits(rec.register(moment - 1, "rip") + 5))) * 12, .h = row }; + const word_frame = place(s, s.new(Read{ .box = main_word })); + const joins = ctx.ties(s); + s.play(.{joins.fadeIn()}, .{ .seconds = 0 }); var asides: canim.Asides = .{}; const left = canim.theme.canvas.margin_x; // II1: the address space and the link fade (18 f); the words glide into - // the stack's rows (36 f) and become the panel (12 f); then the push. + // the stack's rows (36 f) and become the panel (12 f). s.wait(t.beat); s.play(.{ objs[0].fadeOut(), objs[2].fadeOut() }, .{ .seconds = f(18), .ease = anim.ease.linear }); s.play(.{dump.become.to(1)}, .{ .seconds = f(36), .ease = anim.ease.linear }); - s.play(.{ ctx.stack.fadeIn(), objs[1].fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear }); - asides.say(s, "`rsp` holds the address of the stack's top; a push moves it down a word.", left, rowY(top, first, rsp) + row / 2); + s.play(.{ stack.fadeIn(), objs[1].fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear }); + asides.say(s, "`rsp` holds the address of the top of the stack. A push moves it down a word.", left, rowY(top, first, rsp) + row / 2); + // rsp's row arrives over the stack (12 f), then its pin lands on the top word (12 f). + lift(s, &.{regs_rows[1]}, 0, 12); + lift(s, &.{lane[2]}, 0, 12); + s.wait(f(18)); at.walk(s, .moment, moment + 1); s.wait(t.beat); - // II2: the address the call pushed, and main's under it; the offsets, a column. - asides.say(s, "Each call pushes where to come back to: `main+50` is main's.", left, main_word.y + row / 2); - s.play(.{framed.fadeIn()}, .{ .seconds = f(6), .ease = anim.ease.linear }); - s.wait(f(24)); - lift(s, &offsets, 2, 12); + // II2: the way back main left, framed; main's rows; the aim; the offsets, a column. + asides.say(s, "A call pushes the address to come back to: here, `main+50`.", left, back_y + row / 2); + s.play(.{word_frame.fadeIn()}, .{ .seconds = f(6), .ease = anim.ease.linear }); + s.wait(f(12)); + run(s, main_rows.in, 12 + 2 * 2 + 12); + s.wait(f(6)); + at.aim(s, .standing); + s.wait(f(30)); + run(s, reveal.offsets, 2 * @as(f32, @floatFromInt(slots)) + 12); s.wait(t.beat); - // II3: a function's frame: rbp's pin, and the panel's tag, last. - asides.say(s, "A function's words are its frame: saved rbp, locals, the way back.", left, rowY(top, rsp_after - 16, rec.register(moment + 1, "rbp")) + row / 2); - s.play(.{framed.fadeOut()}, .{ .seconds = f(18), .ease = anim.ease.linear }); - s.cursor -= f(18); - lift(s, &lane, 2, 12); + // II3: rbp's row and its pin; the frame made (`mov rbp, rsp`, `sub rsp`); its roles, spans, and the tag last. + const rsp_framed = rec.register(framed, "rsp"); + const span_y = (rowY(top, rsp_framed - 16, rsp_framed) + rowY(top, rsp_framed - 16, rsp + 8)) / 2; + asides.say(s, "A function's words are its frame: the saved rbp, its locals, the way back.", left, span_y); + at.aim(s, .off); + s.play(.{ word_frame.fadeOut(), main_rows.faint.to(1) }, .{ .seconds = f(18), .ease = anim.ease.linear }); + lift(s, &.{regs_rows[0]}, 0, 12); + lift(s, lane[3..], 2, 12); + s.wait(f(12)); + at.walk(s, .moment, moment + 2); + at.walk(s, .moment, framed); + run(s, reveal.roles, 2 * @as(f32, @floatFromInt(slots)) + 12); + run(s, reveal.spans, 2 * 4 + 12); s.wait(t.beat); // `frame up`: its rules (12 f), then its tag and strip (12 f). lift(s, stack_chrome[1..4], 0, 12); @@ -183,8 +215,7 @@ fn frame(s: *anim.Frame) void { // II4: the registers built over the stack, a row at a time, their tag last. asides.say(s, "The registers are the other place values live: seventeen of them.", left, rb.y + tag + pad + row * 2.5); - s.play(.{ctx.registers.fadeIn()}, .{ .seconds = 0 }); - lift(s, ®s_rows, 12, 12); + lift(s, regs_rows[2..], 12, 12); lift(s, regs_chrome[1..4], 0, 12); lift(s, &.{regs_chrome[0]}, 0, 12); // The chapter's last picture. diff --git a/anim/src/aligned.zig b/anim/src/aligned.zig index a7c225d..ce2f5a0 100644 --- a/anim/src/aligned.zig +++ b/anim/src/aligned.zig @@ -19,15 +19,19 @@ //! first row of its run; a line with no code of its own in source order //! after the line before it, faint, `no code of their own`. //! -//! `align` between them (6. Verbs): the addresses and instructions glide -//! right into the instruction column (24 f, the bytes going), then every +//! `align` between them (6. Verbs): the bytes go (8 f), the addresses and +//! instructions glide right into the instruction column (24 f), then every //! row glides to its height (36 f: the verb's 24 read too quick for rows //! crossing a column), then the lines with no code fade in (12 f). +//! +//! The lines as the mocks set them, without their indentation; the pc's +//! row says what it reads (its address and chain, mock 33's annotation). const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); const ui = @import("ui.zig"); const disasm = @import("disasm.zig"); +const rows = @import("rows.zig"); const Recording = @import("Recording.zig"); const theme = ui.theme; const Rect = ui.Rect; @@ -47,6 +51,9 @@ const col = struct { const mnemonic = 360; const seam_after = 48; const instr = 156; + /// The pc's row's annotation, from its mnemonic: interleaved, columns (mocks 32, 36). + const note = 540; + const note_columns = 360; }; /// The dump row's first byte (`bytes`: at 132 at least). @@ -83,15 +90,25 @@ pub const Aligned = struct { rows_in: anim.Value, chrome: anim.Value, form: anim.Value, + /// `stack` (6. Verbs, `align` backwards), frames: the heads' paper and + /// rules, the seam and the tag out (12 f), then each line glides to its + /// row of the source panel (36 f, `glide`) and each instruction to its + /// row of the disassembly, down its column first (24 f), then left into + /// the panel (24 f): an instruction never passes over a line. Those the + /// working frame's windows do not show go on past their edge, fading. + /// 60 f in all; the scene then brings the panels in under them and lets this go. + stack: anim.Value, + /// Where they stack to: the working frame's source and disassembly boxes. + to: struct { source: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, disasm: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 } } = .{}, pub fn init(s: *anim.Frame, rec: *const Recording, moment: u64) Aligned { - return .{ .rec = rec, .at = moment, .bytes = s.value(-1), .decode = s.value(-1), .rows_in = s.value(-1), .chrome = s.value(-1), .form = s.value(0) }; + return .{ .rec = rec, .at = moment, .bytes = s.value(-1), .decode = s.value(-1), .rows_in = s.value(-1), .chrome = s.value(-1), .form = s.value(0), .stack = s.value(-1) }; } fn sourceLine(a: *const Aligned, n: u32) []const u8 { var it = std.mem.splitScalar(u8, a.rec.source, '\n'); var k: u32 = 1; - while (it.next()) |l| : (k += 1) if (k == n) return std.mem.trimEnd(u8, l, " \r"); + while (it.next()) |l| : (k += 1) if (k == n) return std.mem.trim(u8, l, " \t\r"); return ""; } @@ -177,14 +194,32 @@ pub const Aligned = struct { if (built.rows.len == 0) return; const m = a.rec.moment(a.at); const form = placed.value(a.form); - const across = glide(form / 24); - const down = glide((form - 24) / 36); - const bare = clamp01((form - 60) / 12); - const seam = col.text + built.longest + col.seam_after; + // The bytes first (interleaved alone has them), then the columns glide: never over them. + const bytes_go = clamp01(form / 8); + const across = glide((form - 8) / 24); + const down = glide((form - 32) / 36); + const bare = clamp01((form - 68) / 12); + // The seam 48 after the longest line, or after a second run's line and its note; the + // mnemonics after the longest instruction's bytes (mock 32's 360 holds five). + var seam = col.text + built.longest + col.seam_after; + var most: usize = 0; + for (built.rows) |r| { + if (r.kind == .head and r.again) seam = @max(seam, col.text + lineWidth(a, r.line) + again_gap + u.width(.sans, theme.size.sans.micro, again_note) + 24); + if (r.insn) |insn| most = @max(most, insn.len); + } + const mnemonic = @max(col.mnemonic, col.bytes + @as(f32, @floatFromInt(3 * most)) * adv + 12); const rows_in = placed.value(a.rows_in); - const chrome = clamp01(placed.value(a.chrome) / 12); - const tag_in = clamp01((placed.value(a.chrome) - 12) / 12); + const st = placed.value(a.stack); + const kept = 1 - clamp01(st / 12); + const going = glide((st - 12) / 36); + const down_first = glide((st - 12) / 24); + const then_left = glide((st - 36) / 24); + const chrome = clamp01(placed.value(a.chrome) / 12) * kept; + const tag_in = clamp01((placed.value(a.chrome) - 12) / 12) * kept; const v = u.moved(a.box.x, a.box.y); + // Nothing under the stage (y 888): rows `stack` takes past the disassembly's foot fade there, not over the caption. + v.clip(.{ .x = -a.box.x, .y = -a.box.y, .w = theme.canvas.width, .h = theme.canvas.stage.y + theme.canvas.stage.h }); + defer v.unclip(); const body = tag + pad; var counts = [2]f32{ 0, 0 }; for (built.rows) |r| counts = .{ @max(counts[0], r.at[0] + 1), @max(counts[1], r.at[1] + 1) }; @@ -200,22 +235,53 @@ pub const Aligned = struct { } if (chrome > 0) v.faded(chrome).frame(.{ .x = 0, .y = 0, .w = a.box.w, .h = h }, theme.color.rule, theme.stroke.rule); // The seam, with the columns. - if (down > 0) v.faded(down).fill(.{ .x = seam, .y = tag, .w = theme.stroke.rule, .h = h - tag }, theme.color.rule); + if (down > 0) v.faded(down * kept).fill(.{ .x = seam, .y = tag, .w = theme.stroke.rule, .h = h - tag }, theme.color.rule); + // Where `stack` takes them: the source's window and the disassembly's, as those panels have them. + const src_first: f32 = @floatFromInt(a.rec.shownFirst(@intCast(theme.layout.rowsIn(a.to.source.h)), a.rec.shown[a.at])); + const dis_room = theme.layout.rowsIn(a.to.disasm.h); + // The panels' columns right of the line numbers move by as much as the widest file's numbers need. + const widen = rows.numberRoom(a.rec.most_lines); + const dis_rows = if (st >= 0) disasm.listingAt(u, a.rec, a.at, a.rec.register(a.at, "rip"), dis_room, (dis_room -| 1) / 2).rows else &.{}; for (built.rows, 0..) |r, k| { - const y = body + pitch * std.math.lerp(r.at[0], r.at[1], down); + var y = body + pitch * std.math.lerp(r.at[0], r.at[1], down); const order: f32 = @floatFromInt(k); // At a run: rows top down, 2 f apart, 8 f each; the pc's row is the decoded one. // The pc's row is the decoded one, once it has travelled to its place (48). var shows: f32 = if (k == built.pc) @as(f32, if (placed.value(a.decode) >= 48) 1 else 0) else clamp01((rows_in - 2 * order) / 8); if (r.kind == .bare_line) shows = @min(shows, bare); + // `stack`: its row in the working frame's panel (box-relative), and whether that window shows it. + var to_x: f32 = 0; + var to_y: f32 = 0; + if (st >= 0) { + var inside = true; + if (r.kind == .insn) { + var n: ?usize = null; + for (dis_rows, 0..) |d, i| if (d.addr == r.insn.?.addr) { + n = i; + }; + // Past the window: where it would be, going on from its last row. + const at_row: f32 = if (n) |i| @floatFromInt(i) else @as(f32, @floatFromInt(dis_rows.len)) + order - @as(f32, @floatFromInt(built.pc)); + inside = n != null; + to_x = a.to.disasm.x - a.box.x; + to_y = a.to.disasm.y - a.box.y + body + pitch * at_row; + } else { + const at_row = @as(f32, @floatFromInt(r.line)) - src_first; + inside = !r.again and at_row >= 0 and at_row < @as(f32, @floatFromInt(theme.layout.rowsIn(a.to.source.h))); + to_x = a.to.source.x - a.box.x; + to_y = a.to.source.y - a.box.y + body + pitch * at_row; + } + if (!inside) shows *= 1 - (if (r.kind == .insn) then_left else going); + } if (shows <= 0) continue; const rv = v.faded(shows); + if (r.kind == .insn and st >= 0) y = std.math.lerp(y, to_y, down_first); const base = theme.baseline(y, pitch, size); switch (r.kind) { .head, .bare_line => { // Interleaved: a head across the panel; columns: the line in its cell, level with its run. - const head_y = if (r.kind == .head) y else body + pitch * r.at[1]; + var head_y = if (r.kind == .head) y else body + pitch * r.at[1]; + if (st >= 0) head_y = std.math.lerp(head_y, to_y, going); const hb = theme.baseline(head_y, pitch, size); const paper_w = std.math.lerp(a.box.w - 4, seam - 2, down); if (r.kind == .head and !r.again and chrome > 0) rv.faded(chrome).fill(.{ .x = 2, .y = head_y, .w = paper_w, .h = pitch }, theme.color.raised); @@ -223,36 +289,47 @@ pub const Aligned = struct { const faint = r.again or r.kind == .bare_line; const number = rv.print("{d}", .{r.line}); const is_pc = !r.again and built.rows[built.pc].line == r.line and r.kind == .head; - if (is_pc) rv.fill(.{ .x = col.place_end - @as(f32, @floatFromInt(number.len)) * adv - 4, .y = head_y + 1, .w = @as(f32, @floatFromInt(number.len)) * adv + 6, .h = pitch - 2 }, theme.mark(.current).solid); - rv.text(.mono, size, col.place_end - @as(f32, @floatFromInt(number.len)) * adv, hb, number, if (is_pc) t.ink else t.faint); - rv.text(.mono, size, col.text, hb, a.sourceLine(r.line), if (faint) t.faint else t.primary); - if (r.again) rv.text(.sans, theme.size.sans.micro, std.math.lerp(col.mnemonic + 4, col.text + built.longest - 140, down), hb, "again: its second run", t.dim); - if (r.kind == .bare_line and r.first) rv.text(.sans, theme.size.sans.micro, seam + col.instr, hb, "no code of their own", t.dim); + // `stack`: the number to the source's number column, the text to its text column at its indent. + const n_end = std.math.lerp(col.place_end, to_x + theme.metric.context.line_number_end + widen, going); + const t_x = std.math.lerp(col.text, to_x + theme.metric.context.line_text + widen + @as(f32, @floatFromInt(indentOf(a, r.line))) * adv, going); + if (is_pc) rv.fill(.{ .x = n_end - @as(f32, @floatFromInt(number.len)) * adv - 4, .y = head_y + 1, .w = @as(f32, @floatFromInt(number.len)) * adv + 6, .h = pitch - 2 }, theme.mark(.current).solid); + rv.text(.mono, size, n_end - @as(f32, @floatFromInt(number.len)) * adv, hb, number, if (is_pc) t.ink else t.faint); + rv.text(.mono, size, t_x, hb, a.sourceLine(r.line), if (faint) t.faint else t.primary); + if (r.again) rv.faded(kept).text(.sans, theme.size.sans.micro, std.math.lerp(mnemonic + 4, col.text + lineWidth(a, r.line) + again_gap, down), hb, again_note, t.dim); + if (r.kind == .bare_line and r.first) rv.faded(kept).text(.sans, theme.size.sans.micro, seam + col.instr, hb, "no code of their own", t.dim); }, .insn => { const insn = r.insn.?; - const ix = std.math.lerp(0, seam, across); + // `stack`: the row's left edge to the disassembly's. + const ix = std.math.lerp(std.math.lerp(0, seam, across), to_x, then_left); + const right = std.math.lerp(a.box.w, to_x + a.to.disasm.w, then_left); if (k == built.pc) { const wash = rv.faded(clamp01((placed.value(a.decode) - 48) / 12)); - wash.current(.{ .x = ix + 2, .y = y, .w = a.box.w - ix - 4, .h = pitch }, theme.metric.plaque.pc, 0); - sk.draw.polygon(f, &.{ wash.at.xf.apply(.{ ix + 20, y + pitch / 2 }), wash.at.xf.apply(.{ ix + 10, y + 6 }), wash.at.xf.apply(.{ ix + 10, y + pitch - 6 }) }, wash.at.pen(.{ .fill = ui.rgb(theme.mark(.current).on_solid) })); + wash.current(.{ .x = ix + 2, .y = y, .w = right - ix - 4, .h = pitch }, theme.metric.plaque.pc, 0); + sk.draw.polygon(f, &.{ .{ ix + 20, y + pitch / 2 }, .{ ix + 10, y + 6 }, .{ ix + 10, y + pitch - 6 } }, wash.at.pen(.{ .fill = ui.rgb(theme.mark(.current).on_solid) })); } const digits: f32 = @floatFromInt(ui.digits(insn.addr)); - _ = rv.address(ix + col.place_end - digits * adv, base, insn.addr, .{ .ink = ui.rgb(theme.color.region.code_) }); + // (`stack`: ranged right in its column to the disassembly's address column, from 40.) + _ = rv.address(std.math.lerp(std.math.lerp(0, seam, across) + col.place_end - digits * adv, to_x + theme.metric.insn.address, then_left), base, insn.addr, .{ .ink = ui.rgb(theme.color.region.code_) }); // Its bytes, as the recording read them: interleaved only. - if (across < 1) rv.faded(1 - across).text(.mono, size, col.bytes, base, hexBytes(rv, m, insn), t.dim); - disasm.bareRow(rv.moved(std.math.lerp(col.mnemonic - theme.metric.insn.mnemonic, seam + col.instr + 24 - theme.metric.insn.mnemonic, across), 0), insn, y); + if (bytes_go < 1) rv.faded(1 - bytes_go).text(.mono, size, col.bytes, base, hexBytes(rv, m, insn), t.dim); + const mx = std.math.lerp(std.math.lerp(mnemonic, seam + col.instr + 24, across), to_x + theme.metric.insn.mnemonic + widen, then_left); + disasm.bareRow(rv.moved(mx - theme.metric.insn.mnemonic, 0), insn, y); + // The pc's row: what it reads, its address and the chain from it, once decoded. + if (k == built.pc) if (a.rec.insn_touches[a.at][0]) |touch| { + _ = rows.chain(rv.faded(clamp01((placed.value(a.decode) - 48) / 12) * kept), mx + std.math.lerp(col.note, col.note_columns, across), y, m, touch.addr, a.box.w - 24, .{}); + }; }, } } - a.drawBytesRow(v, m, placed, built); + a.drawBytesRow(v, m, placed, built, mnemonic); } /// III1 and the decode (III2): the code's sixteen bytes as a dump row, /// in code's ink 2 f apart; the pc's instruction's bytes framed; then /// they gather, its text fades in beside them, and the row travels to /// its place in the panel. - fn drawBytesRow(a: *const Aligned, v: ui.Ui, m: Recording.Moment, placed: anim.Placed, built: anytype) void { + fn drawBytesRow(a: *const Aligned, v: ui.Ui, m: Recording.Moment, placed: anim.Placed, built: anytype, mnemonic: f32) void { const clock = placed.value(a.bytes); if (clock < 0) return; const d = placed.value(a.decode); @@ -300,10 +377,33 @@ pub const Aligned = struct { if (framed > 0) rv.read(.{ .x = bx(first), .y = y, .w = bx(first + insn.len - 1) - bx(first) + 2 * adv, .h = pitch }, framed); // Its text beside the bytes, at the panel's columns from them (12 f). const text_in = clamp01((d - 12) / 12); - if (text_in > 0) disasm.bareRow(rv.faded(text_in).moved(target_x - col.bytes + col.mnemonic - theme.metric.insn.mnemonic, 0), insn, y); + if (text_in > 0) disasm.bareRow(rv.faded(text_in).moved(target_x - col.bytes + mnemonic - theme.metric.insn.mnemonic, 0), insn, y); } }; +const again_note = "again: its second run"; +const again_gap = 36; + +/// How far line `n` is indented in the file (its leading spaces; a tab as four). +fn indentOf(a: *const Aligned, n: u32) usize { + var it = std.mem.splitScalar(u8, a.rec.source, '\n'); + var k: u32 = 1; + while (it.next()) |l| : (k += 1) if (k == n) { + var w: usize = 0; + for (l) |ch| switch (ch) { + ' ' => w += 1, + '\t' => w += 4, + else => break, + }; + return w; + }; + return 0; +} + +fn lineWidth(a: *const Aligned, n: u32) f32 { + return @as(f32, @floatFromInt(a.sourceLine(n).len)) * adv; +} + fn hexBytes(u: ui.Ui, m: Recording.Moment, insn: disasm.Insn) []const u8 { var bytes: [16]u8 = undefined; var known: [16]bool = undefined; diff --git a/anim/src/aside.zig b/anim/src/aside.zig index 7cf6867..5400da5 100644 --- a/anim/src/aside.zig +++ b/anim/src/aside.zig @@ -46,7 +46,8 @@ pub const Aside = struct { /// A scene's texts beside their parts, said one after another: each waits /// until the last has been read, arrives (18 f, `enter`), and is followed /// by its lead (60 f); the one before it dims (18 f), or leaves (12 f, -/// `exit`) where the new one would stand on it. `leave`: all go together. +/// `exit`, then the caption's gap) where the new one would stand on it. +/// `leave`: all go together. pub const Asides = struct { shown: [8]?anim.Obj = @splat(null), dims: [8]anim.Value = undefined, @@ -61,15 +62,18 @@ pub const Asides = struct { const obj = s.custom(made, .{ .x = -640, .y = -360, .scale = ui.scale }); const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text) - 1)) * line_pitch }; const at = s.cursor; + var in_the_way = false; for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n]) |*o, d, other| { s.cursor = at; if (o.* == null) continue; if (other[0] < span[1] + 12 and span[0] < other[1] + 12) { s.play(.{o.*.?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit }); o.* = null; + in_the_way = true; } else s.play(.{d.to(1)}, .{ .seconds = 18.0 / 60.0, .ease = easeGlide }); } - s.cursor = at; + // One it would stand on is gone first, then a gap: never two texts over each other. + s.cursor = if (in_the_way) at + time.caption_out + time.caption_gap else at; s.play(.{obj.fadeIn()}, .{ .seconds = time.caption_in, .ease = easeEnter }); a.shown[a.n] = obj; a.dims[a.n] = dim; @@ -100,19 +104,23 @@ fn easeGlide(x: f32) f32 { return theme.ease(.glide, x); } -/// How many lines `wrap` makes of `text`. +/// How many lines `wrap` makes of `text` (a newline breaks one where the author says). fn lines(text: []const u8) usize { - var it = std.mem.splitScalar(u8, text, ' '); - var n: usize = 0; - var count: usize = 1; - while (it.next()) |word| { - const seen = (std.unicode.utf8CountCodepoints(word) catch word.len) - std.mem.count(u8, word, "`"); - if (n > 0 and n + 1 + seen > chars) { - count += 1; - n = 0; + var count: usize = 0; + var paragraphs = std.mem.splitScalar(u8, text, '\n'); + while (paragraphs.next()) |paragraph| { + var it = std.mem.splitScalar(u8, paragraph, ' '); + var n: usize = 0; + count += 1; + while (it.next()) |word| { + const seen = (std.unicode.utf8CountCodepoints(word) catch word.len) - std.mem.count(u8, word, "`"); + if (n > 0 and n + 1 + seen > chars) { + count += 1; + n = 0; + } + if (n > 0) n += 1; + n += seen; } - if (n > 0) n += 1; - n += seen; } return count; } @@ -129,25 +137,28 @@ fn width(u: ui.Ui, line: []const u8) f32 { /// run keeps its backticks on each line it spans. fn wrap(u: ui.Ui, text: []const u8) []const []const u8 { var out: std.ArrayList([]const u8) = .empty; - var it = std.mem.splitScalar(u8, text, ' '); - var line: std.ArrayList(u8) = .empty; - var n: usize = 0; - while (it.next()) |word| { - const seen = std.unicode.utf8CountCodepoints(word) catch word.len; - const ticks = std.mem.count(u8, word, "`"); - if (n > 0 and n + 1 + seen - ticks > chars) { - out.append(u.f.scratch, line.items) catch break; - line = .empty; - n = 0; + var paragraphs = std.mem.splitScalar(u8, text, '\n'); + while (paragraphs.next()) |paragraph| { + var it = std.mem.splitScalar(u8, paragraph, ' '); + var line: std.ArrayList(u8) = .empty; + var n: usize = 0; + while (it.next()) |word| { + const seen = std.unicode.utf8CountCodepoints(word) catch word.len; + const ticks = std.mem.count(u8, word, "`"); + if (n > 0 and n + 1 + seen - ticks > chars) { + out.append(u.f.scratch, line.items) catch break; + line = .empty; + n = 0; + } + if (n > 0) { + line.append(u.f.scratch, ' ') catch break; + n += 1; + } + line.appendSlice(u.f.scratch, word) catch break; + n += seen - ticks; } - if (n > 0) { - line.append(u.f.scratch, ' ') catch break; - n += 1; - } - line.appendSlice(u.f.scratch, word) catch break; - n += seen - ticks; + out.append(u.f.scratch, line.items) catch {}; } - if (line.items.len > 0) out.append(u.f.scratch, line.items) catch {}; if (out.items.len == 0) out.append(u.f.scratch, "") catch {}; return out.items; } @@ -157,4 +168,6 @@ test "lines of at most forty characters, backticks not counted" { try std.testing.expectEqual(@as(usize, 2), lines("Its address space, 128 TiB, to scale: mapped only at each end.")); // Four code runs of nine: 39 shown, 47 with their backticks. try std.testing.expectEqual(@as(usize, 1), lines("`012345678` `012345678` `012345678` `012345678`")); + // A newline breaks where the author says. + try std.testing.expectEqual(@as(usize, 2), lines("And all of it at once:\nthe map.")); } diff --git a/anim/src/context.zig b/anim/src/context.zig index 9b466da..8e0156d 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -465,6 +465,23 @@ pub const Stack = struct { above: i32 = 0, /// Which box of its stage it is in: the map's `more` holds the stack continued. part: @import("stage.zig").Part = .stack, + /// The introduction's: its offsets, roles and spans come in a `column` at a time. + reveal: ?Reveal = null, + + /// The stack built a `column` at a time (design/README.md, 6. Verbs: + /// `column`; motion.md, chapter II): each part a clock the scene plays + /// (frames, negative before it begins), its rows coming in top down as + /// shown, 2 f apart, 12 f each; until then under the page. + pub const Reveal = struct { + offsets: anim.Value, + roles: anim.Value, + spans: anim.Value, + + /// How much of row (or span) `k`'s part is still under the page, its clock at `clock`. + fn hidden(clock: f32, k: f32) f32 { + return 1 - std.math.clamp((clock - 2 * @max(k, 0)) / 12, 0, 1); + } + }; pub fn draw(k: *const Stack, f: *sk.Frame, placed: anim.Placed) void { const box = k.stage.box(placed, k.part); @@ -710,6 +727,13 @@ pub const Stack = struct { const y = top + (@as(f32, @floatFromInt(n)) + slide) * m.row; if (y + m.row < body.y or y > box.h) continue; const addr = window[0] +% @as(u64, @bitCast(n * 8)); + // Not come in yet (`reveal`): the offset under the page (from past the pins to 172), the role with its row. + const hide_offset = if (k.reveal) |rv| Reveal.hidden(placed.value(rv.offsets), (y - top) / m.row) else 0; + const hide_role = if (k.reveal) |rv| Reveal.hidden(placed.value(rv.roles), (y - top) / m.row) else 0; + // The page laid over them is opaque whatever the panel's own fade (a faded page over faded text leaves some). + var page_u = u; + page_u.at.pose.opacity = 1; + defer if (hide_offset > 0) page_u.faded(hide_offset).fill(.{ .x = 120, .y = y, .w = theme.metric.slot.offset + 4 - 120, .h = m.row }, theme.color.page); // Who points here: a pin in the lane, landing with its link. const names = pins(u, now, is, was, addr, travel); var marks: rows.Marks = .{ .lead = lead, .first = now.writtenWatched(addr, 8, .memory, 0, watched_from, watched_to) }; @@ -779,6 +803,11 @@ pub const Stack = struct { const fades = ran < 1 and !std.meta.eql(word_was, word_is); if (fades) _ = rows.slot(vs.faded(1 - ran), y, room_w, now.before(), addr, below_rsp, &.{}, 0, marks, role.name, role.local, role_was); const hops = rows.slot(if (fades) vs.faded(ran) else vs, y, room_w, if (fades) now.moment() else now.shownAt(addr, 8), addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local, role_was); + if (hide_role > 0) { + // The role drawn, and the one it crossfades from while it does. + const role_w = @max(if (role_was.going < 1) u.width(.mono, size, role_at[0].name) else 0, u.width(.mono, size, role.name)); + if (role_w > 0) page_u.faded(hide_role).fill(.{ .x = room_w - theme.metric.slot.room - role_w - 2, .y = y, .w = role_w + 4, .h = m.row }, theme.color.page); + } // An arc's ends are rows on show (the row above the window, there for a slide, is not). if (y + m.row > top + 1 and y < box.h - m.pad - 1) at_rows.append(u.f.scratch, .{ .addr = addr, .y = y }) catch {}; const what_was: zt.telescope.Role = if (k_role < roles[0].len) roles[0][k_role].role else .none; @@ -843,12 +872,25 @@ pub const Stack = struct { pinAmount(u, x, top + place * m.row, names_, if (is.rsp < was.rsp) u.print("-{x}", .{bytes}) else u.print("+{x}", .{bytes}), amount_shows); // The rows it crossed, a 3-unit vermilion bracket in the outer arc lane. if (crossed > 0.05) u.faded(amount_shows).bracket(theme.metric.arc.lanes[0], top + @min(place, old) * m.row + 2, top + @max(place, old) * m.row - 2, theme.mark(.write).solid, theme.metric.bracket.tie, 1, false); + } else if (lone != null and joinsBefore(pins(u, now, is, was, is.named(name) orelse 0, travel).names, name)) { + // Joining a pin in front of a name there (rbp onto rsp's row): its own head goes as it lands + // (the joined pin has one head, after the last name), never in the advance's frame. + const y_pin = top + place * m.row; + u.text(.mono_bold, size, x, theme.baseline(y_pin, m.row, size), name, t.primary); + const head = theme.metric.pin; + const hx = x + u.width(.mono, size, name) + head.row_gap; + const mid = y_pin + m.row / 2; + const v_head = u.faded(1 - goes(now, was, is, name)); + sk.draw.polygon(u.f, &.{ .{ hx + head.row_head[0], mid }, .{ hx, mid - head.row_head[1] / 2 }, .{ hx, mid + head.row_head[1] / 2 } }, v_head.at.pen(.{ .fill = ui.rgb(theme.color.region.stack) })); } else u.pinRow(x, top + place * m.row, names_, theme.color.region.stack); } - for (spans[0..n_spans]) |sp| if (sp.shows > 0) if (sp.was) |was_name| { - 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.faded(sp.shows), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); + for (spans[0..n_spans], 0..) |sp, i| if (sp.shows > 0) { + const sv = if (k.reveal) |rv| v.faded(1 - Reveal.hidden(placed.value(rv.spans), @floatFromInt(i))) else v; + if (sp.was) |was_name| { + rows.span(sv.faded(1 - renamed), map.content(box.w), sp.y0, sp.y1, was_name, sp.newest, sp.open); + rows.span(sv.faded(renamed), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); + } else rows.span(sv.faded(sp.shows), 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); } @@ -896,6 +938,12 @@ pub const Stack = struct { } /// Where `name` goes in a row pin of `others` and it, in the registers' order. + /// Whether `name` joining the pin of `others` comes before one of them (pwndbg's order). + fn joinsBefore(others: []const []const u8, name: []const u8) bool { + for (others) |o| if (index(o).? > index(name).?) return true; + return false; + } + fn pinPlace(u: ui.Ui, others: []const []const u8, name: []const u8) f32 { const size = theme.size.mono.context; var x: f32 = theme.metric.slot.lane; diff --git a/anim/src/descent.zig b/anim/src/descent.zig index ad3a5c5..96f6f2d 100644 --- a/anim/src/descent.zig +++ b/anim/src/descent.zig @@ -71,6 +71,50 @@ pub fn step(cur: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void { cur.step(s, to, plan, plan.total); } +/// A caller's window standing alone (the introduction, motion.md II2: the +/// first code on screen): a descent's head row (the function, its file +/// ranged right) over its call, the row the call returns to and the next, +/// each said as a place (`row`) for an aim, a call's callee named where the +/// annotation goes. `in` (frames): the head, then the rows 2 f apart, 12 f +/// each; `faint` (0 to 1): to half, as it stays under what follows. +pub const Caller = struct { + rec: *const Recording, + at: u64, + /// The call instruction's address. + call: u64, + box: Rect, + in: anim.Value, + faint: anim.Value, + + pub fn draw(r: *const Caller, fr: *sk.Frame, placed: anim.Placed) void { + const clock = placed.value(r.in); + if (clock < 0) return; + const u = (ui.Ui{ .f = fr, .at = placed }).moved(r.box.x, r.box.y).faded(1 - 0.5 * std.math.clamp(placed.value(r.faint), 0, 1)); + const moment = r.rec.moment(r.at); + var name_buf: [128]u8 = undefined; + const head = u.faded(std.math.clamp(clock / 12, 0, 1)); + const name = (moment.string(r.call, &name_buf) catch null) orelse ""; + head.fill(.{ .x = theme.stroke.rule, .y = 0, .w = r.box.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); + head.text(.sans_medium, theme.size.sans.micro, c.address, 18, u.print("{s}", .{name[0 .. std.mem.indexOfScalar(u8, name, '+') orelse name.len]}), t.primary); + head.text(.sans, theme.size.sans.micro, r.box.w - 12 - head.width(.sans, theme.size.sans.micro, r.rec.file), 18, r.rec.file, t.faint); + var addr = r.call; + var buf: [256]u8 = undefined; + for (0..3) |n| { + const insn = r.rec.instruction(r.at, addr, &buf) orelse return; + const y = m.row * @as(f32, @floatFromInt(n + 1)); + const rv = u.faded(std.math.clamp((clock - 12 - 2 * @as(f32, @floatFromInt(n))) / 12, 0, 1)); + _ = rv.address(c.address, rows.baseline(y), addr, .{ .ink = ui.rgb(theme.color.region.code_) }); + const row: Insn = .{ .addr = addr, .len = insn.len, .text = insn.text, .line = insn.line }; + disasm.bareRow(rv, row, y); + if (disasm.target(row)) |to| if (std.mem.startsWith(u8, insn.text, "call")) { + if (moment.string(to, &name_buf) catch null) |callee| rv.text(.mono, size, c.annotation, rows.baseline(y), ui.symbol(rv, callee[0 .. std.mem.indexOfScalar(u8, callee, '+') orelse callee.len]), t.primary); + }; + ties.anchor(u, .{ .row = addr }, .{ .x = 0, .y = y, .w = r.box.w, .h = m.row }); + addr += insn.len; + } + } +}; + /// The key of the head row over function `name`'s window (a `ties.Place.row`). pub fn headKey(name: []const u8) u64 { return std.hash.Wyhash.hash(0, name) | 1 << 63; diff --git a/anim/src/regroup.zig b/anim/src/regroup.zig index 431abd8..c9f618a 100644 --- a/anim/src/regroup.zig +++ b/anim/src/regroup.zig @@ -92,7 +92,8 @@ pub const Words = struct { } /// The return address the newest frame has, and the first word that - /// points into the heap, into the stack, and the return address, top down. + /// points into the heap (or, with none, the first other address), into + /// the stack, and the return address, top down. pub fn pick(rec: *const Recording, moment: u64) struct { walked: usize, three: [3]usize } { const m = rec.moment(moment); const rsp = rec.register(moment, "rsp"); @@ -109,12 +110,17 @@ pub const Words = struct { const values = read(rec, moment); var heap: ?usize = null; var stack: ?usize = null; + var other: ?usize = null; for (values.words, 0..) |v, i| switch (rows.regionOf(m, v)) { .heap => heap = heap orelse i, .stack => stack = stack orelse i, - else => {}, + .none => {}, + else => if (i != walked) { + other = other orelse i; + }, }; - var three = [3]usize{ heap orelse 0, stack orelse 1, walked }; + // With no heap word in the 128 bytes, the first other address that is not the walked one. + var three = [3]usize{ heap orelse other orelse 1, stack orelse 2, walked }; std.mem.sort(usize, &three, {}, std.sort.asc(usize)); return .{ .walked = walked, .three = three }; } @@ -162,11 +168,11 @@ pub const Words = struct { const data = read(w.rec, w.at); const m = w.rec.moment(w.at); // The header (mock 29), with the first row; gone as the dump is tied to its place. - const header = clamp01(in / 18) * (1 - placed.value(w.placed)); + // The veil over every row but the walked one, while it is walked (the header too). + const veil = clamp01((r - 48) / 18) - clamp01((r - 270) / 18); + const header = clamp01(in / 18) * (1 - placed.value(w.placed)) * (1 - veil); if (header > 0) v.faded(header).text(.sans, theme.size.sans.micro, at.address, at.top - 12, "128 bytes, from where rsp points", t.faint); - // The veil over every row but the walked one, while it is walked. - const veil = clamp01((r - 48) / 18) - clamp01((r - 270) / 18); const address_ink = ui.mix(t.faint, theme.color.region.stack, placed.value(w.placed)); const become = placed.value(w.become); const g = glide(become); @@ -178,9 +184,10 @@ pub const Words = struct { const slot: f32 = @floatFromInt(@as(i64, @bitCast(data.base + 8 * i -% w.panel.first)) >> 3); const y = std.math.lerp(p.y, w.panel.top + pitch * slot, g); const base = theme.baseline(y, pitch, size); - const ax = std.math.lerp(at.address, w.panel.x + theme.metric.slot.address, g); + // The bytes go first (9 f), then the addresses travel right to the slots' column: never over them. + const ax = std.math.lerp(at.address, w.panel.x + theme.metric.slot.address, glide((become - 0.25) / 0.75)); if (p.address > 0) _ = row.faded(p.address).address(ax, base, data.base + 8 * i, .{ .ink = address_ink }); - w.drawBytes(row.faded(1 - clamp01(become * 2)), data, i, p.x, base, r, placed); + w.drawBytes(row.faded(1 - clamp01(become * 4)), data, i, p.x, base, r, placed); w.drawWord(row, m, data.words[i], i, y, r, placed); } if (r >= 0) w.walk(v, data, r); @@ -258,7 +265,13 @@ pub const Words = struct { // A code address's chain is its name: it comes in as a hop does (6 f). const end = v.address(rect.x, base, value, .{ .ink = ink, .rwx = kind == .rwx }); var name_buf: [128]u8 = undefined; - if (m.string(value, &name_buf) catch null) |name| v.faded(clamp01(since * 10)).text(.mono, size, end + 10, base, ui.symbol(u, name), t.primary); + if (m.string(value, &name_buf) catch null) |name| { + // Cut with `…` at the state column's edge, as the stack's rows cut theirs. + const sym = ui.symbol(u, name); + const fits: usize = @intFromFloat(@max((theme.layout.state.x + theme.layout.state.w - end - 10) / adv, 2)); + const shown = if (sym.len > fits) u.print("{s}\u{2026}", .{sym[0 .. fits - 1]}) else sym; + v.faded(clamp01(since * 10)).text(.mono, size, end + 10, base, shown, t.primary); + } return; } if (since >= 0) { @@ -277,13 +290,20 @@ pub const Words = struct { const y = at.top + pitch * @as(f32, @floatFromInt(w.walked)); const base = theme.baseline(y, pitch, size); const value = data.words[w.walked]; - // Under the row, its offsets and labels on the page (the veiled rows under them give way). + // A row near the dump's top has no room over it for the arcs at x2 (the camera's frame + // begins two rows over the header): there the bytes fly under the row, over the veiled + // rows, and the offsets and labels stand over it, the header's place (veiled with the rest). + const flip = w.walked < 4; + const dir: f32 = if (flip) -1 else 1; + // Under the row (over it, flipped), its offsets and labels on the page (the veiled rows there give way). // They go as the gaps close (192), not after: closed, their pairs are 24 apart and they would touch. const labels = clamp01((r - 84) / 12) * (1 - clamp01((r - 192) / 12)); const offsets = clamp01((r - 66) / 12) * (1 - clamp01((r - 192) / 12)); const zeros_mark = clamp01((r - 204) / 12) * (1 - clamp01((r - 228) / 12)); - const under = @max(offsets, zeros_mark); - if (under > 0) u.faded(under).fill(.{ .x = at.bytes - 12, .y = y + pitch, .w = at.field_end - at.bytes + 24, .h = 2 * pitch + 6 }, theme.color.page); + const page_x = at.bytes - 12; + const page_w = at.field_end - at.bytes + 24; + if (offsets > 0) u.faded(offsets).fill(.{ .x = page_x, .y = if (flip) y - 2 * pitch - 6 else y + pitch, .w = page_w, .h = 2 * pitch + 6 }, theme.color.page); + if (zeros_mark > 0) u.faded(zeros_mark).fill(.{ .x = page_x, .y = y + pitch, .w = page_w, .h = 2 * pitch + 6 }, theme.color.page); const close = glide((r - 192) / 12); for (0..8) |k| { const kf: f32 = @floatFromInt(k); @@ -294,7 +314,7 @@ pub const Words = struct { const long = to - from; const high = std.math.clamp(long / 4, theme.time.flight.arc_min, theme.time.flight.arc_max); const x = std.math.lerp(from, to, theme.ease(.glide, s)); - const lift = high * @sin(std.math.pi * s); + const lift = dir * high * @sin(std.math.pi * s); // The byte itself: bright and bold in the air (from 108 the walk draws it, not the row). if (r >= 108) { const air = s > 0 and s < 1; @@ -310,13 +330,13 @@ pub const Words = struct { } // Its offset under it, going with it. const off = offsets * clamp01((r - 66 - 2 * kf) / 12); - if (off > 0 and s > 0 and s < 1) u.faded(off).fill(.{ .x = x - 3, .y = base + pitch - lift - 18, .w = 2 * adv + 6, .h = 24 }, theme.color.page); - if (off > 0) u.faded(off).text(.mono, size, x, base + pitch - lift, u.print("+{d}", .{k}), t.dim); + if (off > 0 and s > 0 and s < 1) u.faded(off).fill(.{ .x = x - 3, .y = base + dir * pitch - lift - 18, .w = 2 * adv + 6, .h = 24 }, theme.color.page); + if (off > 0) u.faded(off).text(.mono, size, x, base + dir * pitch - lift, u.print("+{d}", .{k}), t.dim); // `low byte` from its byte's left, `high byte` to its byte's right: under the bytes, never the addresses. if (k == 0 or k == 7) if (labels > 0) { const label = if (k == 0) "low byte" else "high byte"; const lw = u.width(.sans, theme.size.sans.tag, label); - u.faded(labels).text(.sans, theme.size.sans.tag, if (k == 0) x else x + 2 * adv - lw, base + 2 * pitch + 2 - lift, label, t.dim); + u.faded(labels).text(.sans, theme.size.sans.tag, if (k == 0) x else x + 2 * adv - lw, base + dir * 2 * pitch + 2 - lift, label, t.dim); }; } // The zeros in front, bracketed (motion.md: 204 to 228). diff --git a/anim/src/root.zig b/anim/src/root.zig index 596ac57..5482285 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -52,6 +52,8 @@ const tying = @import("ties.zig"); pub const relations = @import("relations.zig"); pub const Ties = tying.Ties; pub const Place = tying.Place; +/// Says where a place is this frame, for a scene's own component the ties should find. +pub const anchor = tying.anchor; pub const Array = @import("array.zig").Array; pub const Loupe = @import("loupe.zig").Loupe; pub const syscalls = @import("syscalls.zig"); diff --git a/anim/src/segments.zig b/anim/src/segments.zig index d28d2dd..db9d28f 100644 --- a/anim/src/segments.zig +++ b/anim/src/segments.zig @@ -69,11 +69,18 @@ pub fn read(rec: *const Recording, at: u64, arena: std.mem.Allocator) Space { const maps = mo.mappings(arena) catch &.{}; var bands: std.ArrayList(Band) = .empty; var path_buf: [512]u8 = undefined; + // The tracer's own (its ring, its preloaded agent, and an agent's bss + // after it) are not the program's: left out, as mock 34 has them. + var tracers_end: u64 = 0; for (maps) |mp| { if (mp.addr >= user_end) continue; var path: []const u8 = ""; _ = mo.mapping(mp.addr, &path, &path_buf) catch null; const name = arena.dupe(u8, nameOf(path)) catch ""; + if (std.mem.indexOf(u8, name, "ztrace") != null or (name.len == 0 and mp.addr == tracers_end)) { + tracers_end = mp.addr + mp.len; + continue; + } if (bands.items.len > 0) { const last = &bands.items[bands.items.len - 1]; if (last.hi == mp.addr and last.prot == mp.prot and (std.mem.eql(u8, last.name, name) or (name.len == 0 and last.name.len > 0 and last.name[0] != '['))) { @@ -163,6 +170,12 @@ pub fn size(buf: []u8, bytes: u64) []const u8 { return std.fmt.bufPrint(buf, "{d} {s}", .{ @as(u64, @intFromFloat(@round(v))), units[u] }) catch ""; } +/// `name` cut with `…` to fit `room` (a library's long file name in the program column). +fn cut(u: ui.Ui, name: []const u8, room: f32) []const u8 { + const most: usize = @intFromFloat(@max(room / ui.advance(m.mono), 2)); + return if (name.len > most) u.print("{s}\u{2026}", .{name[0 .. most - 1]}) else name; +} + fn perms(prot: u64) [3]u8 { return .{ if (prot & 1 != 0) 'r' else '-', if (prot & 2 != 0) 'w' else '-', if (prot & 4 != 0) 'x' else '-' }; } @@ -433,9 +446,9 @@ pub const Segments = struct { out.append(arena, .{ .kind = .unit, .addr = un.lo, .unit = k, .target = std.math.clamp((yh + yl) / 2, box.y, box.y + box.h), .ink = un.ink }) catch {}; out.append(arena, .{ .kind = .edge, .addr = un.lo, .unit = k, .target = yl, .ink = un.ink }) catch {}; } - // An edge two units share takes the ink of the one that starts there. - for (out.items, 0..) |*r, j| if (r.kind == .edge and j + 1 < out.items.len and out.items[j + 1].kind == .unit) { - r.ink = l.space.units[out.items[j + 1].unit].ink; + // An edge two units share takes the ink of the one that starts there (its lowest address). + for (out.items) |*r| if (r.kind == .edge) for (l.space.units[c.units[0]..c.units[1]]) |un| if (un.lo == r.addr) { + r.ink = un.ink; }; return out.items; } @@ -484,7 +497,7 @@ pub const Segments = struct { if (un.program) { if (first_program == null) first_program = k; last_program = k; - } else v.text(.mono, m.mono, g.x + m.name, y + 7.2, un.name, t.primary); + } else v.text(.mono, m.mono, g.x + m.name, y + 7.2, cut(v, un.name, theme.layout.program.w - 12 - m.name), t.primary); // A file whose permissions differ: each part's written inside its band, where it is 28 tall. if (un.prot == null) g.insides(v, l, i, un, scale); }, |
