From bbabc78dcfd00a98abb5ececae6761bccc496eb8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 22:16:50 -0300 Subject: design: four times the context on a 4K stage; the loupe; quieter marks From the user, after the second videos. The stage is 3840 by 2160 at the same type size: four columns (source, disassembly, state, stack), 69 lines, rows and slots with no lens, 43 with a lens as subject, dumps of 32 rows. Code reads at 1440p and up; the caption, the clock and a lens's drawing are doubled, and the camera at x2 is the old frame. The stack's rows carry their offset from rsp and a role. A loupe is the telescope as a floating panel: the memory round what a pointer leads to, lifted over the context, a pointer inside it opening the next. The current row is a white wash, a strike a softened vermilion, held a turned corner; sheet 15 sets the alternatives side by side. Co-Authored-By: Claude Fable 5.2 --- design/mock/09-context-480.png | Bin 36556 -> 36505 bytes design/mock/09-context.png | Bin 242644 -> 242320 bytes design/mock/09-context.svg | 30 +- design/mock/10-context-step-480.png | Bin 38234 -> 38234 bytes design/mock/10-context-step.png | Bin 247333 -> 246875 bytes design/mock/10-context-step.svg | 32 +- design/mock/11-context-lens-480.png | Bin 38429 -> 38599 bytes design/mock/11-context-lens.png | Bin 236071 -> 235747 bytes design/mock/11-context-lens.svg | 32 +- design/mock/12-calls-subject-480.png | Bin 32964 -> 32952 bytes design/mock/12-calls-subject.png | Bin 197962 -> 197829 bytes design/mock/12-calls-subject.svg | 34 +- design/mock/13-sqlite-row-480.png | Bin 32674 -> 33001 bytes design/mock/13-sqlite-row.png | Bin 229211 -> 229299 bytes design/mock/13-sqlite-row.svg | 56 +- design/mock/14-sqlite-page-480.png | Bin 37842 -> 37787 bytes design/mock/14-sqlite-page.png | Bin 234953 -> 235073 bytes design/mock/14-sqlite-page.svg | 58 +- design/mock/15-marks-480.png | Bin 0 -> 18542 bytes design/mock/15-marks.png | Bin 0 -> 264805 bytes design/mock/15-marks.svg | 1027 +++++++++++++++++ design/mock/16-none-480.png | Bin 0 -> 33091 bytes design/mock/16-none.png | Bin 0 -> 750420 bytes design/mock/16-none.svg | 1641 ++++++++++++++++++++++++++ design/mock/17-subject-480.png | Bin 0 -> 35404 bytes design/mock/17-subject.png | Bin 0 -> 714590 bytes design/mock/17-subject.svg | 1562 +++++++++++++++++++++++++ design/mock/18-loupes-480.png | Bin 0 -> 37782 bytes design/mock/18-loupes.png | Bin 0 -> 780782 bytes design/mock/18-loupes.svg | 2110 ++++++++++++++++++++++++++++++++++ design/mock/context.py | 218 ++-- design/mock/dense.py | 441 +++++++ design/mock/list-dbg.txt | 178 +++ design/mock/list.dis | 263 +++++ 34 files changed, 7495 insertions(+), 187 deletions(-) create mode 100644 design/mock/15-marks-480.png create mode 100644 design/mock/15-marks.png create mode 100644 design/mock/15-marks.svg create mode 100644 design/mock/16-none-480.png create mode 100644 design/mock/16-none.png create mode 100644 design/mock/16-none.svg create mode 100644 design/mock/17-subject-480.png create mode 100644 design/mock/17-subject.png create mode 100644 design/mock/17-subject.svg create mode 100644 design/mock/18-loupes-480.png create mode 100644 design/mock/18-loupes.png create mode 100644 design/mock/18-loupes.svg create mode 100644 design/mock/dense.py create mode 100644 design/mock/list-dbg.txt create mode 100644 design/mock/list.dis (limited to 'design/mock') diff --git a/design/mock/09-context-480.png b/design/mock/09-context-480.png index 3d4975a..099116b 100644 Binary files a/design/mock/09-context-480.png and b/design/mock/09-context-480.png differ diff --git a/design/mock/09-context.png b/design/mock/09-context.png index 6be6c29..b1f6003 100644 Binary files a/design/mock/09-context.png and b/design/mock/09-context.png differ diff --git a/design/mock/09-context.svg b/design/mock/09-context.svg index a175fcc..828a9ce 100644 --- a/design/mock/09-context.svg +++ b/design/mock/09-context.svg @@ -21,7 +21,7 @@ head ) { - + 21 struct @@ -109,7 +109,7 @@ 4 - + 10019 @@ -180,7 +180,7 @@ read-only rax - + 28b41090 @@ -188,7 +188,7 @@ rbx 0 rcx - + 28b410b0 @@ -201,7 +201,7 @@ 0 rdi - + 28b41090 @@ -276,22 +276,22 @@ 1 - + rip 1001926 reverse+22 -cf +cf PF -af - -zf -sf +af + +zf +sf IF -df -of +df +of @@ -514,7 +514,7 @@ 00 00 - + 00 00 00 @@ -532,7 +532,7 @@ 1 - + diff --git a/design/mock/10-context-step-480.png b/design/mock/10-context-step-480.png index 7bbfa65..4a9c7e1 100644 Binary files a/design/mock/10-context-step-480.png and b/design/mock/10-context-step-480.png differ diff --git a/design/mock/10-context-step.png b/design/mock/10-context-step.png index fa9086b..244c65b 100644 Binary files a/design/mock/10-context-step.png and b/design/mock/10-context-step.png differ diff --git a/design/mock/10-context-step.svg b/design/mock/10-context-step.svg index 3cd8c76..09baba3 100644 --- a/design/mock/10-context-step.svg +++ b/design/mock/10-context-step.svg @@ -21,7 +21,7 @@ head ) { - + 21 struct @@ -109,7 +109,7 @@ 4 - + 10019 @@ -181,7 +181,7 @@ read-only rax - + 28b41090 @@ -189,7 +189,7 @@ rbx 0 rcx - + 28b410b0 @@ -202,8 +202,8 @@ 0 rdi - -28b41070 + +28b41070 9 @@ -277,22 +277,22 @@ 1 - + rip 1001926 reverse+22 -cf +cf PF -af - -zf -sf +af + +zf +sf IF -df -of +df +of @@ -513,7 +513,7 @@ 00 00 - + 00 00 00 @@ -531,7 +531,7 @@ 1 - + diff --git a/design/mock/11-context-lens-480.png b/design/mock/11-context-lens-480.png index 318735d..9e76b53 100644 Binary files a/design/mock/11-context-lens-480.png and b/design/mock/11-context-lens-480.png differ diff --git a/design/mock/11-context-lens.png b/design/mock/11-context-lens.png index 78d0779..6e5e6fe 100644 Binary files a/design/mock/11-context-lens.png and b/design/mock/11-context-lens.png differ diff --git a/design/mock/11-context-lens.svg b/design/mock/11-context-lens.svg index f5582e3..a7dcea0 100644 --- a/design/mock/11-context-lens.svg +++ b/design/mock/11-context-lens.svg @@ -37,7 +37,7 @@ head ) { - + 21 struct @@ -111,7 +111,7 @@ 4 - + 10019 @@ -168,7 +168,7 @@ read-only rax - + 28b41090 @@ -176,7 +176,7 @@ rbx 0 rcx - + 28b410b0 @@ -189,8 +189,8 @@ 0 rdi - -28b41070 + +28b41070 9 @@ -264,22 +264,22 @@ 1 - + rip 1001926 reverse+22 -cf +cf PF -af - -zf -sf +af + +zf +sf IF -df -of +df +of @@ -534,7 +534,7 @@ 00 00 - + 00 00 00 @@ -552,7 +552,7 @@ 1 - + diff --git a/design/mock/12-calls-subject-480.png b/design/mock/12-calls-subject-480.png index d53389e..0cde337 100644 Binary files a/design/mock/12-calls-subject-480.png and b/design/mock/12-calls-subject-480.png differ diff --git a/design/mock/12-calls-subject.png b/design/mock/12-calls-subject.png index 5ce57a1..7ab5d52 100644 Binary files a/design/mock/12-calls-subject.png and b/design/mock/12-calls-subject.png differ diff --git a/design/mock/12-calls-subject.svg b/design/mock/12-calls-subject.svg index 36d11c1..6dd15d6 100644 --- a/design/mock/12-calls-subject.svg +++ b/design/mock/12-calls-subject.svg @@ -27,7 +27,7 @@ return n ; - + 6 return @@ -109,7 +109,7 @@ rdi, 2 rdi 2 - + 10133 @@ -180,7 +180,7 @@ "./steps" rdi 2 - + rbp 7fffffffeda0 @@ -196,8 +196,8 @@ 0 rsp - -7fffffffed78 + +7fffffffed78 10133ab @@ -223,20 +223,20 @@ main+0 r15 1 - + rip 10133a6 fib+54 -cf -pf -af -zf -sf +cf +pf +af +zf +sf IF -df -of +df +of @@ -248,8 +248,8 @@ 78 - -10133ab + +10133ab fib+59 7fffffffed 80 @@ -260,7 +260,7 @@ 88 - + 2 7fffffffed 90 @@ -300,7 +300,7 @@ backtrace the calls waiting · newest on top - + #0 fib+0 diff --git a/design/mock/13-sqlite-row-480.png b/design/mock/13-sqlite-row-480.png index 33f2486..db957cc 100644 Binary files a/design/mock/13-sqlite-row-480.png and b/design/mock/13-sqlite-row-480.png differ diff --git a/design/mock/13-sqlite-row.png b/design/mock/13-sqlite-row.png index 4d6a377..e372f2f 100644 Binary files a/design/mock/13-sqlite-row.png and b/design/mock/13-sqlite-row.png differ diff --git a/design/mock/13-sqlite-row.svg b/design/mock/13-sqlite-row.svg index 7161b31..92d1ec0 100644 --- a/design/mock/13-sqlite-row.svg +++ b/design/mock/13-sqlite-row.svg @@ -37,7 +37,7 @@ seekResult /* Result of prior IndexMoveto … - + 80895 ) @@ -78,7 +78,7 @@ 81 mov rbp, rsp - + 448d @@ -121,35 +121,35 @@ read-only rax - + 5226d0 0 rbx 1 - + rcx 0 - + rdx 8 - + rsi - + 7fffffffea60 0 rdi - + 521978 0x101 257 rbp - + 7fffffffe980 @@ -166,7 +166,7 @@ rsp - + 7fffffffe980 @@ -185,49 +185,49 @@ r8 0x38 56 - + r9 0 - + r10 7 - + r11 0xffffffff - + r12 0 r13 - + 5222d0 0x39fb80 r14 - + 5218f8 0x40100010000 r15 0 - - + + rip 448d84 sqlite3BtreeInsert+4 -cf - -pf -af - -zf -sf +cf + +pf +af + +zf +sf IF -df -of +df +of @@ -314,7 +314,7 @@ backtrace newest on top - + #0 sqlite3BtreeInsert+4 diff --git a/design/mock/14-sqlite-page-480.png b/design/mock/14-sqlite-page-480.png index 9024f82..35a7d2f 100644 Binary files a/design/mock/14-sqlite-page-480.png and b/design/mock/14-sqlite-page-480.png differ diff --git a/design/mock/14-sqlite-page.png b/design/mock/14-sqlite-page.png index c014899..695138d 100644 Binary files a/design/mock/14-sqlite-page.png and b/design/mock/14-sqlite-page.png differ diff --git a/design/mock/14-sqlite-page.svg b/design/mock/14-sqlite-page.svg index 7bcee25..d67cbac 100644 --- a/design/mock/14-sqlite-page.svg +++ b/design/mock/14-sqlite-page.svg @@ -22,7 +22,7 @@ ( USE_PREAD ) - + 42290 do @@ -125,7 +125,7 @@ 4b call qword ptr [rip + 0xf1567] - + 4220 @@ -162,29 +162,29 @@ rax 0x1000 4096 - + rbx 3 - + rcx - + 7ffff7cf1a7d __pwrite64+173 rdx 0x1000 4096 - + rsi - + 538b28 0xe60f030000000d rdi 3 - + rbp - + 7fffffffe7e0 @@ -201,30 +201,30 @@ rsp - + 7fffffffe7a0 0 r8 0 - + r9 0 r10 0x1000 4096 - + r11 0x246 582 - + r12 0x1000 4096 - + r13 - + 538b28 @@ -232,31 +232,31 @@ r14 0x1000 4096 - + r15 - + 538b28 0xe60f030000000d - + rip 422051 unixWrite+65 - + CF - + PF -af -zf -sf +af +zf +sf IF -df -of +df +of @@ -266,13 +266,13 @@ c0 - + 0 7fffffffe7 c8 - + 538b28 @@ -281,7 +281,7 @@ d0 - + 517e38 @@ -293,7 +293,7 @@ d8 - + 2 rbp diff --git a/design/mock/15-marks-480.png b/design/mock/15-marks-480.png new file mode 100644 index 0000000..ad7f92c Binary files /dev/null and b/design/mock/15-marks-480.png differ diff --git a/design/mock/15-marks.png b/design/mock/15-marks.png new file mode 100644 index 0000000..a295ec1 Binary files /dev/null and b/design/mock/15-marks.png differ diff --git a/design/mock/15-marks.svg b/design/mock/15-marks.svg new file mode 100644 index 0000000..32d55db --- /dev/null +++ b/design/mock/15-marks.svg @@ -0,0 +1,1027 @@ + + + +current, struck, held +Rows of targets/list at the load in reverse (moment 3) and the store after it (moment 4), at the 4K stage's density: mono 20, rows of 24. Look at it at full size. +A +the first videos: gold band, solid vermilion, a tick + + + +list.c +lines 18 to 23 of 42 +18 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +reverse +( +struct +node +… +19 +struct +node +* +prev += +NULL +; + +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; +22 +head +- +> +next += +prev +; +23 +prev += +head +; + + + +disassembly +reverse +10019 +19 +20 +xor +eax, eax +10019 +1b +nop +dword ptr [rax + rax] +10019 +20 +mov +rcx, rax + +10019 +23 +mov +rax, rdi + + + +10019 +26 +21 +mov +rdi, qword ptr [rdi + 8] + +1004098 + + +1004070 + + +9 +10019 +2a +22 +mov +qword ptr [rax + 8], rcx +10019 +2e +20 +test +rdi, rdi + + + +registers +rax + +1004090 + + +4 +rcx + +10040b0 + + +1 +rsi +10040c0 + + +0 +rdi + +1004070 + + +9 +rbp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 + + +rip +1001926 +reverse+22 + + + +its bytes +moment 4: the store, struck; 10040b8, held + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + +b0 +40 +00 +01 +00 +00 +00 +00 + + +10040b0 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + +b0 + +in a lens's cell, twice the size + + + +4 + +held + + + +4 + +struck +the same, 1.35 times + + + + +list.c +lines 19 to 21 of 42 +19 +struct +node +* +prev += +NULL +; + +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; + + + +registers +rax + +1004090 + + +4 +rdi + +1004070 + + +9 + + +rip +1001926 +reverse+22 +rcx + +10040b0 + + +1 + +B +recommended: a white wash, a softened strike, a turned corner + + + +list.c +lines 18 to 23 of 42 +18 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +reverse +( +struct +node +… +19 +struct +node +* +prev += +NULL +; + +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; +22 +head +- +> +next += +prev +; +23 +prev += +head +; + + + +disassembly +reverse +10019 +19 +20 +xor +eax, eax +10019 +1b +nop +dword ptr [rax + rax] +10019 +20 +mov +rcx, rax + +10019 +23 +mov +rax, rdi + + + +10019 +26 +21 +mov +rdi, qword ptr [rdi + 8] + +1004098 + + +1004070 + + +9 +10019 +2a +22 +mov +qword ptr [rax + 8], rcx +10019 +2e +20 +test +rdi, rdi + + + +registers +rax + +1004090 + + +4 +rcx + +10040b0 + + +1 +rsi +10040c0 + + +0 +rdi + +1004070 + + +9 +rbp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 + + +rip +1001926 +reverse+22 + + + +its bytes +moment 4: the store, struck; 10040b8, held + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + +b0 +40 +00 +01 +00 +00 +00 +00 + + +10040b0 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + +b0 + +in a lens's cell, twice the size + + + +4 + +held + + + +4 + +struck +the same, 1.35 times + + + + +list.c +lines 19 to 21 of 42 +19 +struct +node +* +prev += +NULL +; + +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; + + + +registers +rax + +1004090 + + +4 +rdi + +1004070 + + +9 + + +rip +1001926 +reverse+22 +rcx + +10040b0 + + +1 + +C +white: a white plaque, a white strike framed in vermilion, a bar under + + + +list.c +lines 18 to 23 of 42 +18 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +reverse +( +struct +node +… +19 +struct +node +* +prev += +NULL +; + +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; +22 +head +- +> +next += +prev +; +23 +prev += +head +; + + + +disassembly +reverse +10019 +19 +20 +xor +eax, eax +10019 +1b +nop +dword ptr [rax + rax] +10019 +20 +mov +rcx, rax + +10019 +23 +mov +rax, rdi + + + +10019 +26 +21 +mov +rdi, qword ptr [rdi + 8] + +1004098 + + +1004070 + + +9 +10019 +2a +22 +mov +qword ptr [rax + 8], rcx +10019 +2e +20 +test +rdi, rdi + + + +registers +rax + +1004090 + + +4 +rcx + +10040b0 + + +1 +rsi +10040c0 + + +0 +rdi + + +1004070 + + +9 +rbp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 + + +rip +1001926 +reverse+22 + + + +its bytes +moment 4: the store, struck; 10040b8, held + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + +b0 +40 +00 +01 +00 +00 +00 +00 + + +10040b0 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + +b0 + +in a lens's cell, twice the size + + + +4 + +held + + + + +4 + +struck +the same, 1.35 times + + + + +list.c +lines 19 to 21 of 42 +19 +struct +node +* +prev += +NULL +; + +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; + + + +registers +rax + +1004090 + + +4 +rdi + + +1004070 + + +9 + + +rip +1001926 +reverse+22 +rcx + +10040b0 + + +1 + + diff --git a/design/mock/16-none-480.png b/design/mock/16-none-480.png new file mode 100644 index 0000000..e85cc62 Binary files /dev/null and b/design/mock/16-none-480.png differ diff --git a/design/mock/16-none.png b/design/mock/16-none.png new file mode 100644 index 0000000..68b7049 Binary files /dev/null and b/design/mock/16-none.png differ diff --git a/design/mock/16-none.svg b/design/mock/16-none.svg new file mode 100644 index 0000000..4b89733 --- /dev/null +++ b/design/mock/16-none.svg @@ -0,0 +1,1641 @@ + + + + + + +list.c +lines 1 to 42 of 42 +1 +// A linked list on the heap: built, reversed, summed. `list_done` +2 +// finished list, the place for a tracer to look at it. +3 +#include +<stdio.h> +4 +#include +<stdlib.h> +5 +6 +struct +node +{ +7 +long +value +; +8 +struct +node +* +next +; +9 +} +; +10 +11 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +push +( +struct +node +* +he +… +12 +struct +node +* +n += +malloc +( +sizeof +* +n +) +; +13 +n +- +> +value += +value +; +14 +n +- +> +next += +head +; +15 +return +n +; +16 +} +17 +18 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +reverse +( +struct +node +… +19 +struct +node +* +prev += +NULL +; +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; +22 +head +- +> +next += +prev +; +23 +prev += +head +; +24 +head += +next +; +25 +} +26 +return +prev +; +27 +} +28 +29 +__attribute__ +( +( +noinline +) +) +long +list_done +( +struct +node +* +head +) +{ +30 +long +sum += +0 +; +31 +for +( +; +head +; +head += +head +- +> +next +) +sum ++ += +head +- +> +value +; +32 +return +sum +; +33 +} +34 +35 +int +main +( +int +argc +, +char +* +* +argv +) +{ +36 +int +n += +argc +> +1 +? +atoi +( +argv +[ +1 +] +) +: +6 +; +37 +struct +node +* +head += +NULL +; +38 +for +( +int +i += +n +; +i +> += +1 +; +i +- +- +) +head += +push +( +head +, +i +* +i +) +; +39 +head += +reverse +( +head +) +; +40 +printf +( +"sum = %ld\n" +, +list_done +( +head +) +) +; +41 +return +0 +; +42 +} +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 + + + +disassembly +reverse + +1001 +8a8 +39 +mov +rdi, rax +main +1001 +8ab +call +1001910 +1001 +8b0 +40 +mov +rdi, rax +1001 +8b3 +call +1001830 +1001 +8b8 +lea +rdi, [rip - 0x12cb] +1001 +8bf +mov +rsi, rax +1001 +8c2 +xor +eax, eax +1001 +8c4 +call +1001990 +printf +1001 +8c9 +41 +xor +eax, eax +1001 +8cb +add +rsp, 8 +1001 +8cf +pop +rbx +1001 +8d0 +pop +rbp +1001 +8d1 +ret +1001 +8d2 +nop +word ptr cs:[rax + rax] + +1001 +8e0 +11 +push +rbp +push +1001 +8e1 +mov +rbp, rsp +1001 +8e4 +push +r14 +1001 +8e6 +push +rbx +1001 +8e7 +mov +rbx, rsi +1001 +8ea +mov +r14, rdi +1001 +8ed +12 +mov +edi, 0x10 +1001 +8f2 +call +10019a0 +malloc +1001 +8f7 +13 +mov +qword ptr [rax], rbx +1001 +8fa +14 +mov +qword ptr [rax + 8], r14 +1001 +8fe +15 +pop +rbx +1001 +8ff +pop +r14 +1001 +901 +pop +rbp +1001 +902 +ret +1001 +903 +nop +word ptr cs:[rax + rax] +1001 +910 +20 +test +rdi, rdi +1001 +913 +je +1001935 +1001 +915 +push +rbp +1001 +916 +mov +rbp, rsp +1001 +919 +xor +eax, eax +1001 +91b +nop +dword ptr [rax + rax] +1001 +920 +mov +rcx, rax +1001 +923 +mov +rax, rdi + + + +1001 +926 +21 +mov +rdi, qword ptr [rdi + 8] +1004098 + + +1004070 + + +9 +1001 +92a +22 +mov +qword ptr [rax + 8], rcx +1001 +92e +20 +test +rdi, rdi +1001 +931 +jne +1001920 +1001 +933 +pop +rbp +1001 +934 +26 +ret +1001 +935 +xor +eax, eax +1001 +937 +ret + +1001 +938 +endbr64 +_init +1001 +93c +sub +rsp, 8 +1001 +940 +mov +rax, qword ptr [rip + 0x1231] +1001 +947 +test +rax, rax +1001 +94a +je +100194e +1001 +94c +call +rax +1001 +94e +add +rsp, 8 +1001 +952 +ret + +1001 +954 +endbr64 +_fini +1001 +958 +sub +rsp, 8 +1001 +95c +add +rsp, 8 +1001 +960 +ret + +1001 +970 +push +qword ptr [rip + 0x1222] +strtol@plt-0x10 +1001 +976 +jmp +qword ptr [rip + 0x1224] +1001 +97c +nop +dword ptr [rax] + +1001 +980 +jmp +qword ptr [rip + 0x1222] +strtol@plt +1001 +986 +push +0 +1001 +98b +jmp +1001970 + +1001 +990 +jmp +qword ptr [rip + 0x121a] +printf@plt +1001 +996 +push +1 +1001 +99b +jmp +1001970 + +1001 +9a0 +jmp +qword ptr [rip + 0x1212] +malloc@plt +1001 +9a6 +push +2 +1001 +9ab +jmp +1001970 + + + + + + + + + + + + +registers +stack +heap +code +data +rwx + +read-only +rax + +1004090 + + +4 +rbx +0 +rcx + +10040b0 + + +1 +rdx +0 +rsi +10040c0 + + +0 +rdi + +1004090 + + +4 +rbp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +rsp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +r8 +7ffff7e19ac0 +r9 +0x20 +32 +r10 +0x10 +16 +r11 +7ffff7e19ac8 +r12 +7fffffffee38 + + +7fffffffefea + + +"./list" +r13 +1 +r14 +7ffff7ffd000 + + +7ffff7ffe3c0 + + +0 +r15 +10029c0 + + +1 + + +rip +1001926 +reverse+22 +cf + +PF +af +zf +sf + +IF +df +of + + + +backtrace +newest on top + + +#0 +reverse+22 +list.c:21 +#1 +main+80 +list.c:40 +#2 +libc+27781 +#3 +__libc_start_main+137 +#4 +_start+37 + + + +memory +the heap, round what the step reads + + + +10040 +00 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +10 + +24 +00 +00 +00 +00 +00 +00 +00 +36 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +20 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +30 + +19 +00 +00 +00 +00 +00 +00 +00 +25 + +10 +40 +00 +01 +00 +00 +00 +00 + + +1004010 + + + +10040 +40 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +50 + +10 +00 +00 +00 +00 +00 +00 +00 +16 + +30 +40 +00 +01 +00 +00 +00 +00 + + +1004030 + + + +10040 +60 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +70 + +09 +00 +00 +00 +00 +00 +00 +00 +9 + +50 +40 +00 +01 +00 +00 +00 +00 + + +1004050 + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + +70 +40 +00 +01 +00 +00 +00 +00 + + +1004070 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +c0 +00 +00 +00 +00 +00 +00 +00 +00 +41 +0f +02 +00 +00 +00 +00 +00 +malloc's: the top chunk + + + + + +19 rows + + + +stack +69 words from rsp · the frames they belong to +rbp rsp + ++0 +saved rbp +7fffffffe +ce0 + + +7fffffffed00 + + + + + ++8 +7fffffffe +ce8 + + +10018b0 +main+80 ++10 +7fffffffe +cf0 + + +7ffff7e20de8 ++18 +saved rbx +7fffffffe +cf8 + + +0 ++20 +saved rbp +7fffffffe +d00 + + +7fffffffedb0 + + + + + ++28 +7fffffffe +d08 + + +7ffff7c27781 +libc+27781 ++30 +7fffffffe +d10 + + +7ffff7fe0c60 +ld.so+22c60 ++38 +7fffffffe +d18 + + +7fffffffee38 + + +7fffffffefea + + +".… ++40 +7fffffffe +d20 + + +0x1f7fbe000 ++48 +7fffffffe +d28 + + +1001860 +main+0 ++50 +7fffffffe +d30 + + +7fffffffed70 + + + + + ++58 +7fffffffe +d38 + + + + + ++60 +7fffffffe +d40 + + +0 ++68 +7fffffffe +d48 + + +0x1fe335fc95a5781c ++70 +7fffffffe +d50 + + +7fffffffee38 + + +7fffffffefea + + +".… ++78 +7fffffffe +d58 + + +1 ++80 +7fffffffe +d60 + + +7ffff7ffd000 ++88 +7fffffffe +d68 + + +10029c0 ++90 +7fffffffe +d70 + + +0x1fe335fc94e5781c ++98 +7fffffffe +d78 + + +0x1fe32587a0af781c ++a0 +7fffffffe +d80 + + +0x7fff00000000 ++a8 +7fffffffe +d88 + + +0 ++b0 +7fffffffe +d90 + + +0 ++b8 +7fffffffe +d98 + + +0 ++c0 +7fffffffe +da0 + + +7fffffffee38 + + +7fffffffefea + + +".… ++c8 +7fffffffe +da8 + + +0x15f6f7c6b8dafb00 ++d0 +saved rbp +7fffffffe +db0 + + +7fffffffee10 + + +0 ++d8 +7fffffffe +db8 + + + + + ++e0 +7fffffffe +dc0 + + +7fffffffee48 + + +0 ++e8 +7fffffffe +dc8 + + +10029c0 ++f0 +7fffffffe +dd0 + + +1001860 +main+0 ++f8 +7fffffffe +dd8 + + +7fffffffee48 + + +0 ++100 +7fffffffe +de0 + + +0 ++108 +7fffffffe +de8 + + +0 ++110 +7fffffffe +df0 + + +1001730 +_start+0 ++118 +7fffffffe +df8 + + +7fffffffee30 + + +1 ++120 +7fffffffe +e00 + + +0 ++128 +7fffffffe +e08 + + +0 ++130 +saved rbp +7fffffffe +e10 + + +0 ++138 +7fffffffe +e18 + + +1001755 +_start+37 ++140 +7fffffffe +e20 + + +7fffffffee28 + + +0x38 +56 ++148 +7fffffffe +e28 + + +0x38 +56 ++150 +argc +7fffffffe +e30 + + +1 ++158 +argv[0] +7fffffffe +e38 + + +7fffffffefea + + +"./list" ++160 +argv end +7fffffffe +e40 + + +0 ++168 +envp end +7fffffffe +e48 + + +0 ++170 +auxv +7fffffffe +e50 + + +0x21 +33 ++178 +7fffffffe +e58 + + +7ffff7fbc000 +vdso+0 ++180 +7fffffffe +e60 + + +0x33 +51 ++188 +7fffffffe +e68 + + +0xe30 +3632 ++190 +7fffffffe +e70 + + +0x10 +16 ++198 +7fffffffe +e78 + + +0xbfebfbff ++1a0 +7fffffffe +e80 + + +6 ++1a8 +7fffffffe +e88 + + +0x1000 +4096 ++1b0 +7fffffffe +e90 + + +0x11 +17 ++1b8 +7fffffffe +e98 + + +0x64 +100 ++1c0 +7fffffffe +ea0 + + +3 ++1c8 +7fffffffe +ea8 + + +1000040 ++1d0 +7fffffffe +eb0 + + +4 ++1d8 +7fffffffe +eb8 + + +0x38 +56 ++1e0 +7fffffffe +ec0 + + +5 ++1e8 +7fffffffe +ec8 + + +0xb +11 ++1f0 +7fffffffe +ed0 + + +7 ++1f8 +7fffffffe +ed8 + + +0x7ffff7fbe000 ++200 +7fffffffe +ee0 + + +8 ++208 +7fffffffe +ee8 + + +0 ++210 +7fffffffe +ef0 + + +9 ++218 +7fffffffe +ef8 + + +1001730 +_start+0 ++220 +7fffffffe +f00 + + +0xb +11 + + + +reverse + + + +main + + + +libc+27781 + + + +__libc_start_main + + +_start + + +moment 2 of 4 +Stopped in reverse, about to load head->next. +rdi points at a node; the word after its value is the next node. + diff --git a/design/mock/17-subject-480.png b/design/mock/17-subject-480.png new file mode 100644 index 0000000..daca488 Binary files /dev/null and b/design/mock/17-subject-480.png differ diff --git a/design/mock/17-subject.png b/design/mock/17-subject.png new file mode 100644 index 0000000..d1bb0cc Binary files /dev/null and b/design/mock/17-subject.png differ diff --git a/design/mock/17-subject.svg b/design/mock/17-subject.svg new file mode 100644 index 0000000..fd9459e --- /dev/null +++ b/design/mock/17-subject.svg @@ -0,0 +1,1562 @@ + + + + + + +its bytes +the heap, 1004000 to 10041ff + + + +10040 +00 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +10 + +24 +00 +00 +00 +00 +00 +00 +00 +36 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +20 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +30 + +19 +00 +00 +00 +00 +00 +00 +00 +25 + +10 +40 +00 +01 +00 +00 +00 +00 + + +1004010 + + + +10040 +40 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +50 + +10 +00 +00 +00 +00 +00 +00 +00 +16 + +30 +40 +00 +01 +00 +00 +00 +00 + + +1004030 + + + +10040 +60 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +70 + +09 +00 +00 +00 +00 +00 +00 +00 +9 + +50 +40 +00 +01 +00 +00 +00 +00 + + +1004050 + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + + +70 +40 +00 +01 +00 +00 +00 +00 + + +1004070 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +c0 +00 +00 +00 +00 +00 +00 +00 +00 +41 +0f +02 +00 +00 +00 +00 +00 +malloc's: the top chunk + + + + + +19 rows + + + +registers +stack +heap +code +data +rwx + +read-only +rax + +1004090 + + +4 +rbx +0 +rcx + +10040b0 + + +1 +rdx +0 +rsi +10040c0 + + +0 +rdi + +1004070 + + +9 +rbp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +rsp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +r8 +7ffff7e19ac0 +r9 +0x20 +32 +r10 +0x10 +16 +r11 +7ffff7e19ac8 +r12 +7fffffffee38 + + +7fffffffefea + + +"./list" +r13 +1 +r14 +7ffff7ffd000 + + +7ffff7ffe3c0 + + +0 +r15 +10029c0 + + +1 + + +rip +1001926 +reverse+22 +cf + +PF +af +zf +sf + +IF +df +of + + + +backtrace +newest on top + + +#0 +reverse+22 +list.c:21 +#1 +main+80 +list.c:40 +#2 +libc+27781 +#3 +__libc_start_main+137 +#4 +_start+37 + + + +the list +10040b0 + +1 + + + + + +rcx +1004090 + +4 + + + + + + + +rax +1004070 + +9 + + + + + + +rdi +1004050 + +16 + + + + +1004030 + +25 + + + + +1004010 + +36 + + + + + + + + + + + + +list.c +lines 1 to 42 of 42 +1 +// A linked list on the heap: built, reversed, summed. `list_done` +2 +// finished list, the place for a tracer to look at it. +3 +#include +<stdio.h> +4 +#include +<stdlib.h> +5 +6 +struct +node +{ +7 +long +value +; +8 +struct +node +* +next +; +9 +} +; +10 +11 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +push +( +struct +node +* +he +… +12 +struct +node +* +n += +malloc +( +sizeof +* +n +) +; +13 +n +- +> +value += +value +; +14 +n +- +> +next += +head +; +15 +return +n +; +16 +} +17 +18 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +reverse +( +struct +node +… +19 +struct +node +* +prev += +NULL +; +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; +22 +head +- +> +next += +prev +; +23 +prev += +head +; +24 +head += +next +; +25 +} +26 +return +prev +; +27 +} +28 +29 +__attribute__ +( +( +noinline +) +) +long +list_done +( +struct +node +* +head +) +{ +30 +long +sum += +0 +; +31 +for +( +; +head +; +head += +head +- +> +next +) +sum ++ += +head +- +> +value +; +32 +return +sum +; +33 +} +34 +35 +int +main +( +int +argc +, +char +* +* +argv +) +{ +36 +int +n += +argc +> +1 +? +atoi +( +argv +[ +1 +] +) +: +6 +; +37 +struct +node +* +head += +NULL +; +38 +for +( +int +i += +n +; +i +> += +1 +; +i +- +- +) +head += +push +( +head +, +i +* +i +) +; +39 +head += +reverse +( +head +) +; +40 +printf +( +"sum = %ld\n" +, +list_done +( +head +) +) +; +41 +return +0 +; +42 +} +43 + + + +disassembly +reverse + +1001 +8e4 +11 +push +r14 +push +1001 +8e6 +push +rbx +1001 +8e7 +mov +rbx, rsi +1001 +8ea +mov +r14, rdi +1001 +8ed +12 +mov +edi, 0x10 +1001 +8f2 +call +10019a0 +malloc +1001 +8f7 +13 +mov +qword ptr [rax], rbx +1001 +8fa +14 +mov +qword ptr [rax + 8], r14 +1001 +8fe +15 +pop +rbx +1001 +8ff +pop +r14 +1001 +901 +pop +rbp +1001 +902 +ret +1001 +903 +nop +word ptr cs:[rax + rax] +1001 +910 +20 +test +rdi, rdi +1001 +913 +je +1001935 +1001 +915 +push +rbp +1001 +916 +mov +rbp, rsp +1001 +919 +xor +eax, eax +1001 +91b +nop +dword ptr [rax + rax] +1001 +920 +mov +rcx, rax +1001 +923 +mov +rax, rdi + + + +1001 +926 +21 +mov +rdi, qword ptr [rdi + 8] + +1004098 + + +1004070 + + +9 +1001 +92a +22 +mov +qword ptr [rax + 8], rcx +1001 +92e +20 +test +rdi, rdi +1001 +931 +jne +1001920 +1001 +933 +pop +rbp +1001 +934 +26 +ret +1001 +935 +xor +eax, eax +1001 +937 +ret + +1001 +938 +endbr64 +_init +1001 +93c +sub +rsp, 8 +1001 +940 +mov +rax, qword ptr [rip + 0x1231] +1001 +947 +test +rax, rax +1001 +94a +je +100194e +1001 +94c +call +rax +1001 +94e +add +rsp, 8 +1001 +952 +ret + +1001 +954 +endbr64 +_fini +1001 +958 +sub +rsp, 8 +1001 +95c +add +rsp, 8 +1001 +960 +ret + +1001 +970 +push +qword ptr [rip + 0x1222] +strtol@plt-0x10 +1001 +976 +jmp +qword ptr [rip + 0x1224] + + + + + + + + + + + + +stack +69 words from rsp · the frames they belong to +rbp rsp + ++0 +saved rbp +7fffffffe +ce0 + + +7fffffffed00 + + + + + ++8 +7fffffffe +ce8 + + +10018b0 +main+80 ++10 +7fffffffe +cf0 + + +7ffff7e20de8 ++18 +saved rbx +7fffffffe +cf8 + + +0 ++20 +saved rbp +7fffffffe +d00 + + +7fffffffedb0 + + + + + ++28 +7fffffffe +d08 + + +7ffff7c27781 +libc+27781 ++30 +7fffffffe +d10 + + +7ffff7fe0c60 +ld.so+22c60 ++38 +7fffffffe +d18 + + +7fffffffee38 + + +7fffffffefea + + +".… ++40 +7fffffffe +d20 + + +0x1f7fbe000 ++48 +7fffffffe +d28 + + +1001860 +main+0 ++50 +7fffffffe +d30 + + +7fffffffed70 + + + + + ++58 +7fffffffe +d38 + + + + + ++60 +7fffffffe +d40 + + +0 ++68 +7fffffffe +d48 + + +0x1fe335fc95a5781c ++70 +7fffffffe +d50 + + +7fffffffee38 + + +7fffffffefea + + +".… ++78 +7fffffffe +d58 + + +1 ++80 +7fffffffe +d60 + + +7ffff7ffd000 ++88 +7fffffffe +d68 + + +10029c0 ++90 +7fffffffe +d70 + + +0x1fe335fc94e5781c ++98 +7fffffffe +d78 + + +0x1fe32587a0af781c ++a0 +7fffffffe +d80 + + +0x7fff00000000 ++a8 +7fffffffe +d88 + + +0 ++b0 +7fffffffe +d90 + + +0 ++b8 +7fffffffe +d98 + + +0 ++c0 +7fffffffe +da0 + + +7fffffffee38 + + +7fffffffefea + + +".… ++c8 +7fffffffe +da8 + + +0x15f6f7c6b8dafb00 ++d0 +saved rbp +7fffffffe +db0 + + +7fffffffee10 + + +0 ++d8 +7fffffffe +db8 + + + + + ++e0 +7fffffffe +dc0 + + +7fffffffee48 + + +0 ++e8 +7fffffffe +dc8 + + +10029c0 ++f0 +7fffffffe +dd0 + + +1001860 +main+0 ++f8 +7fffffffe +dd8 + + +7fffffffee48 + + +0 ++100 +7fffffffe +de0 + + +0 ++108 +7fffffffe +de8 + + +0 ++110 +7fffffffe +df0 + + +1001730 +_start+0 ++118 +7fffffffe +df8 + + +7fffffffee30 + + +1 ++120 +7fffffffe +e00 + + +0 ++128 +7fffffffe +e08 + + +0 ++130 +saved rbp +7fffffffe +e10 + + +0 ++138 +7fffffffe +e18 + + +1001755 +_start+37 ++140 +7fffffffe +e20 + + +7fffffffee28 + + +0x38 +56 ++148 +7fffffffe +e28 + + +0x38 +56 ++150 +argc +7fffffffe +e30 + + +1 ++158 +argv[0] +7fffffffe +e38 + + +7fffffffefea + + +"./list" ++160 +argv end +7fffffffe +e40 + + +0 ++168 +envp end +7fffffffe +e48 + + +0 ++170 +auxv +7fffffffe +e50 + + +0x21 +33 ++178 +7fffffffe +e58 + + +7ffff7fbc000 +vdso+0 ++180 +7fffffffe +e60 + + +0x33 +51 ++188 +7fffffffe +e68 + + +0xe30 +3632 ++190 +7fffffffe +e70 + + +0x10 +16 ++198 +7fffffffe +e78 + + +0xbfebfbff ++1a0 +7fffffffe +e80 + + +6 ++1a8 +7fffffffe +e88 + + +0x1000 +4096 ++1b0 +7fffffffe +e90 + + +0x11 +17 ++1b8 +7fffffffe +e98 + + +0x64 +100 ++1c0 +7fffffffe +ea0 + + +3 ++1c8 +7fffffffe +ea8 + + +1000040 ++1d0 +7fffffffe +eb0 + + +4 ++1d8 +7fffffffe +eb8 + + +0x38 +56 ++1e0 +7fffffffe +ec0 + + +5 ++1e8 +7fffffffe +ec8 + + +0xb +11 ++1f0 +7fffffffe +ed0 + + +7 ++1f8 +7fffffffe +ed8 + + +0x7ffff7fbe000 ++200 +7fffffffe +ee0 + + +8 ++208 +7fffffffe +ee8 + + +0 ++210 +7fffffffe +ef0 + + +9 ++218 +7fffffffe +ef8 + + +1001730 +_start+0 ++220 +7fffffffe +f00 + + +0xb +11 + + + +reverse + + + +main + + + +libc+27781 + + + +__libc_start_main + + +_start + + +moment 2 of 4 +The load read the word at 1004098: the address of the next node. +rdi holds it now, and points at the node whose value is 9. + diff --git a/design/mock/18-loupes-480.png b/design/mock/18-loupes-480.png new file mode 100644 index 0000000..c7b8332 Binary files /dev/null and b/design/mock/18-loupes-480.png differ diff --git a/design/mock/18-loupes.png b/design/mock/18-loupes.png new file mode 100644 index 0000000..cafd759 Binary files /dev/null and b/design/mock/18-loupes.png differ diff --git a/design/mock/18-loupes.svg b/design/mock/18-loupes.svg new file mode 100644 index 0000000..02bff4f --- /dev/null +++ b/design/mock/18-loupes.svg @@ -0,0 +1,2110 @@ + + + + + + +list.c +lines 1 to 42 of 42 +1 +// A linked list on the heap: built, reversed, summed. `list_done` +2 +// finished list, the place for a tracer to look at it. +3 +#include +<stdio.h> +4 +#include +<stdlib.h> +5 +6 +struct +node +{ +7 +long +value +; +8 +struct +node +* +next +; +9 +} +; +10 +11 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +push +( +struct +node +* +he +… +12 +struct +node +* +n += +malloc +( +sizeof +* +n +) +; +13 +n +- +> +value += +value +; +14 +n +- +> +next += +head +; +15 +return +n +; +16 +} +17 +18 +__attribute__ +( +( +noinline +) +) +static +struct +node +* +reverse +( +struct +node +… +19 +struct +node +* +prev += +NULL +; +20 +while +( +head +) +{ + + +21 +struct +node +* +next += +head +- +> +next +; +22 +head +- +> +next += +prev +; +23 +prev += +head +; +24 +head += +next +; +25 +} +26 +return +prev +; +27 +} +28 +29 +__attribute__ +( +( +noinline +) +) +long +list_done +( +struct +node +* +head +) +{ +30 +long +sum += +0 +; +31 +for +( +; +head +; +head += +head +- +> +next +) +sum ++ += +head +- +> +value +; +32 +return +sum +; +33 +} +34 +35 +int +main +( +int +argc +, +char +* +* +argv +) +{ +36 +int +n += +argc +> +1 +? +atoi +( +argv +[ +1 +] +) +: +6 +; +37 +struct +node +* +head += +NULL +; +38 +for +( +int +i += +n +; +i +> += +1 +; +i +- +- +) +head += +push +( +head +, +i +* +i +) +; +39 +head += +reverse +( +head +) +; +40 +printf +( +"sum = %ld\n" +, +list_done +( +head +) +) +; +41 +return +0 +; +42 +} +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 + + + +disassembly +reverse + +1001 +8a8 +39 +mov +rdi, rax +main +1001 +8ab +call +1001910 +1001 +8b0 +40 +mov +rdi, rax +1001 +8b3 +call +1001830 +1001 +8b8 +lea +rdi, [rip - 0x12cb] +1001 +8bf +mov +rsi, rax +1001 +8c2 +xor +eax, eax +1001 +8c4 +call +1001990 +printf +1001 +8c9 +41 +xor +eax, eax +1001 +8cb +add +rsp, 8 +1001 +8cf +pop +rbx +1001 +8d0 +pop +rbp +1001 +8d1 +ret +1001 +8d2 +nop +word ptr cs:[rax + rax] + +1001 +8e0 +11 +push +rbp +push +1001 +8e1 +mov +rbp, rsp +1001 +8e4 +push +r14 +1001 +8e6 +push +rbx +1001 +8e7 +mov +rbx, rsi +1001 +8ea +mov +r14, rdi +1001 +8ed +12 +mov +edi, 0x10 +1001 +8f2 +call +10019a0 +malloc +1001 +8f7 +13 +mov +qword ptr [rax], rbx +1001 +8fa +14 +mov +qword ptr [rax + 8], r14 +1001 +8fe +15 +pop +rbx +1001 +8ff +pop +r14 +1001 +901 +pop +rbp +1001 +902 +ret +1001 +903 +nop +word ptr cs:[rax + rax] +1001 +910 +20 +test +rdi, rdi +1001 +913 +je +1001935 +1001 +915 +push +rbp +1001 +916 +mov +rbp, rsp +1001 +919 +xor +eax, eax +1001 +91b +nop +dword ptr [rax + rax] +1001 +920 +mov +rcx, rax +1001 +923 +mov +rax, rdi + + + +1001 +926 +21 +mov +rdi, qword ptr [rdi + 8] + +1004098 + + +1004070 + + +9 +1001 +92a +22 +mov +qword ptr [rax + 8], rcx +1001 +92e +20 +test +rdi, rdi +1001 +931 +jne +1001920 +1001 +933 +pop +rbp +1001 +934 +26 +ret +1001 +935 +xor +eax, eax +1001 +937 +ret + +1001 +938 +endbr64 +_init +1001 +93c +sub +rsp, 8 +1001 +940 +mov +rax, qword ptr [rip + 0x1231] +1001 +947 +test +rax, rax +1001 +94a +je +100194e +1001 +94c +call +rax +1001 +94e +add +rsp, 8 +1001 +952 +ret + +1001 +954 +endbr64 +_fini +1001 +958 +sub +rsp, 8 +1001 +95c +add +rsp, 8 +1001 +960 +ret + +1001 +970 +push +qword ptr [rip + 0x1222] +strtol@plt-0x10 +1001 +976 +jmp +qword ptr [rip + 0x1224] +1001 +97c +nop +dword ptr [rax] + +1001 +980 +jmp +qword ptr [rip + 0x1222] +strtol@plt +1001 +986 +push +0 +1001 +98b +jmp +1001970 + +1001 +990 +jmp +qword ptr [rip + 0x121a] +printf@plt +1001 +996 +push +1 +1001 +99b +jmp +1001970 + +1001 +9a0 +jmp +qword ptr [rip + 0x1212] +malloc@plt +1001 +9a6 +push +2 +1001 +9ab +jmp +1001970 + + + + + + + + + + + + +registers +stack +heap +code +data +rwx + +read-only +rax + +1004090 + + +4 +rbx +0 +rcx + +10040b0 + + +1 +rdx +0 +rsi +10040c0 + + +0 +rdi + +1004070 + + +9 +rbp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +rsp +7fffffffece0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +r8 +7ffff7e19ac0 +r9 +0x20 +32 +r10 +0x10 +16 +r11 +7ffff7e19ac8 +r12 +7fffffffee38 + + +7fffffffefea + + +"./list" +r13 +1 +r14 +7ffff7ffd000 + + +7ffff7ffe3c0 + + +0 +r15 +10029c0 + + +1 + + +rip +1001926 +reverse+22 +cf + +PF +af +zf +sf + +IF +df +of + + + +backtrace +newest on top + + +#0 +reverse+22 +list.c:21 +#1 +main+80 +list.c:40 +#2 +libc+27781 +#3 +__libc_start_main+137 +#4 +_start+37 + + + +memory +the heap, round what the step reads + + + +10040 +00 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +10 + +24 +00 +00 +00 +00 +00 +00 +00 +36 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +20 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +30 + +19 +00 +00 +00 +00 +00 +00 +00 +25 + +10 +40 +00 +01 +00 +00 +00 +00 + + +1004010 + + + +10040 +40 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +50 + +10 +00 +00 +00 +00 +00 +00 +00 +16 + +30 +40 +00 +01 +00 +00 +00 +00 + + +1004030 + + + +10040 +60 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +70 + +09 +00 +00 +00 +00 +00 +00 +00 +9 + +50 +40 +00 +01 +00 +00 +00 +00 + + +1004050 + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + + +70 +40 +00 +01 +00 +00 +00 +00 + + +1004070 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +c0 +00 +00 +00 +00 +00 +00 +00 +00 +41 +0f +02 +00 +00 +00 +00 +00 +malloc's: the top chunk + + + + + +19 rows + + + +stack +69 words from rsp · the frames they belong to +rbp rsp + ++0 +saved rbp +7fffffffe +ce0 + + +7fffffffed00 + + + + + ++8 +7fffffffe +ce8 + + +10018b0 +main+80 ++10 +7fffffffe +cf0 + + +7ffff7e20de8 ++18 +saved rbx +7fffffffe +cf8 + + +0 ++20 +saved rbp +7fffffffe +d00 + + +7fffffffedb0 + + + + + ++28 +7fffffffe +d08 + + +7ffff7c27781 +libc+27781 ++30 +7fffffffe +d10 + + +7ffff7fe0c60 +ld.so+22c60 ++38 +7fffffffe +d18 + + +7fffffffee38 + + +7fffffffefea + + +".… ++40 +7fffffffe +d20 + + +0x1f7fbe000 ++48 +7fffffffe +d28 + + +1001860 +main+0 ++50 +7fffffffe +d30 + + +7fffffffed70 + + + + + ++58 +7fffffffe +d38 + + + + + ++60 +7fffffffe +d40 + + +0 ++68 +7fffffffe +d48 + + +0x1fe335fc95a5781c ++70 +7fffffffe +d50 + + +7fffffffee38 + + +7fffffffefea + + +".… ++78 +7fffffffe +d58 + + +1 ++80 +7fffffffe +d60 + + +7ffff7ffd000 ++88 +7fffffffe +d68 + + +10029c0 ++90 +7fffffffe +d70 + + +0x1fe335fc94e5781c ++98 +7fffffffe +d78 + + +0x1fe32587a0af781c ++a0 +7fffffffe +d80 + + +0x7fff00000000 ++a8 +7fffffffe +d88 + + +0 ++b0 +7fffffffe +d90 + + +0 ++b8 +7fffffffe +d98 + + +0 ++c0 +7fffffffe +da0 + + +7fffffffee38 + + +7fffffffefea + + +".… ++c8 +7fffffffe +da8 + + +0x15f6f7c6b8dafb00 ++d0 +saved rbp +7fffffffe +db0 + + +7fffffffee10 + + +0 ++d8 +7fffffffe +db8 + + + + + ++e0 +7fffffffe +dc0 + + +7fffffffee48 + + +0 ++e8 +7fffffffe +dc8 + + +10029c0 ++f0 +7fffffffe +dd0 + + +1001860 +main+0 ++f8 +7fffffffe +dd8 + + +7fffffffee48 + + +0 ++100 +7fffffffe +de0 + + +0 ++108 +7fffffffe +de8 + + +0 ++110 +7fffffffe +df0 + + +1001730 +_start+0 ++118 +7fffffffe +df8 + + +7fffffffee30 + + +1 ++120 +7fffffffe +e00 + + +0 ++128 +7fffffffe +e08 + + +0 ++130 +saved rbp +7fffffffe +e10 + + +0 ++138 +7fffffffe +e18 + + +1001755 +_start+37 ++140 +7fffffffe +e20 + + +7fffffffee28 + + +0x38 +56 ++148 +7fffffffe +e28 + + +0x38 +56 ++150 +argc +7fffffffe +e30 + + +1 ++158 +argv[0] +7fffffffe +e38 + + +7fffffffefea + + +"./list" ++160 +argv end +7fffffffe +e40 + + +0 ++168 +envp end +7fffffffe +e48 + + +0 ++170 +auxv +7fffffffe +e50 + + +0x21 +33 ++178 +7fffffffe +e58 + + +7ffff7fbc000 +vdso+0 ++180 +7fffffffe +e60 + + +0x33 +51 ++188 +7fffffffe +e68 + + +0xe30 +3632 ++190 +7fffffffe +e70 + + +0x10 +16 ++198 +7fffffffe +e78 + + +0xbfebfbff ++1a0 +7fffffffe +e80 + + +6 ++1a8 +7fffffffe +e88 + + +0x1000 +4096 ++1b0 +7fffffffe +e90 + + +0x11 +17 ++1b8 +7fffffffe +e98 + + +0x64 +100 ++1c0 +7fffffffe +ea0 + + +3 ++1c8 +7fffffffe +ea8 + + +1000040 ++1d0 +7fffffffe +eb0 + + +4 ++1d8 +7fffffffe +eb8 + + +0x38 +56 ++1e0 +7fffffffe +ec0 + + +5 ++1e8 +7fffffffe +ec8 + + +0xb +11 ++1f0 +7fffffffe +ed0 + + +7 ++1f8 +7fffffffe +ed8 + + +0x7ffff7fbe000 ++200 +7fffffffe +ee0 + + +8 ++208 +7fffffffe +ee8 + + +0 ++210 +7fffffffe +ef0 + + +9 ++218 +7fffffffe +ef8 + + +1001730 +_start+0 ++220 +7fffffffe +f00 + + +0xb +11 + + + +reverse + + + +main + + + +libc+27781 + + + +__libc_start_main + + +_start + + + + +rdi + → +1004070 +heap · struct node, 16 bytes + + + +10040 +30 + +19 +00 +00 +00 +00 +00 +00 +00 +25 + +10 +40 +00 +01 +00 +00 +00 +00 + + +1004010 + + + +10040 +40 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +50 + +10 +00 +00 +00 +00 +00 +00 +00 +16 + +30 +40 +00 +01 +00 +00 +00 +00 + + +1004030 + + + +10040 +60 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +70 + + +09 +00 +00 +00 +00 +00 +00 +00 +9 + + +50 +40 +00 +01 +00 +00 +00 +00 + + +1004050 + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + +70 +40 +00 +01 +00 +00 +00 +00 + + +1004070 + + + +10040 +a0 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +b0 + +01 +00 +00 +00 +00 +00 +00 +00 +1 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + + + + + +1004078 + → +1004050 +heap · struct node, 16 bytes + + + +10040 +10 + +24 +00 +00 +00 +00 +00 +00 +00 +36 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +10040 +20 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +30 + +19 +00 +00 +00 +00 +00 +00 +00 +25 + +10 +40 +00 +01 +00 +00 +00 +00 + + +1004010 + + + +10040 +40 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +50 + + +10 +00 +00 +00 +00 +00 +00 +00 +16 + + +30 +40 +00 +01 +00 +00 +00 +00 + + +1004030 + + + +10040 +60 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +70 + +09 +00 +00 +00 +00 +00 +00 +00 +9 + +50 +40 +00 +01 +00 +00 +00 +00 + + +1004050 + + + +10040 +80 +00 +00 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +malloc's: a chunk of 32 + + + +10040 +90 + +04 +00 +00 +00 +00 +00 +00 +00 +4 + +70 +40 +00 +01 +00 +00 +00 +00 + + +1004070 + + + + +moment 3 of 4 +The load is done: rdi holds 1004070, and beside it the heap round it opens. +Its next word opens the node after it, one deeper. + diff --git a/design/mock/context.py b/design/mock/context.py index 64603a2..303c7c1 100644 --- a/design/mock/context.py +++ b/design/mock/context.py @@ -43,6 +43,61 @@ def ph(rows): return TAG + 2 * PAD + rows * ROW +# ---- marks: the forms of `current`, `struck` and `held`. A is the first videos'; B the catalogue's now; C the +# other readings of "white, with less opacity" (mock 15 sets them side by side). +STYLE = {"current": "B", "struck": "B", "held": "B"} +WASH = mix(BRIGHT, PAGE, 0.10) # the current row: a white wash, opaque, a tenth of the way to bright +SOFT = mix(VERM, PAGE, 0.70) # a strike's paper, B + + +def band(): + """The paper across the current row.""" + return EMBER[GOLD] if STYLE["current"] == "A" else WASH + + +def current_row(g, x, y, w, plaque): + """The current mark on a row: the band across it and the plaque on its label. Returns the plaque's letters' ink.""" + g.rect(x, y, w, ROW, band()) + g.rect(x, y, plaque, ROW, BRIGHT if STYLE["current"] == "C" else GOLD) + return INK + + +def struck(g, x, y, w, h=ROW): + """A struck value's paper (x, w: the value's, 5 out each side). Returns its digits' ink.""" + st = STYLE["struck"] + if st == "A": + g.rect(x, y + 1, w, h - 2, VERM) + return INK + if st == "B": + g.rect(x, y + 1, w, h - 2, SOFT) + return BRIGHT + g.rect(x, y + 1, w, h - 2, mix(BRIGHT, PAGE, 0.18)) + g.frame(x, y + 1, w, h - 2, VERM, 2) + return BRIGHT + + +def held(g, x, y, w, h=ROW): + """Changed within three steps, at the value whose left is x (w wide) on the row at y.""" + st = STYLE["held"] + if st == "A": + g.rect(x - 9, y + 3, 4, h - 6, VERM) + elif st == "B": # a dog-ear: the corner of the value turned down + g.path(f"M{x - 4},{y + 2} h9 l-9,9 Z", fill=VERM) + else: # a bar under it, half strength + g.rect(x - 2, y + h - 4, w + 4, 2, mix(VERM, PAGE, 0.6)) + + +def held_cell(g, x, y, w, h, k=1): + """`held` on a lens's cell (k: the drawing's scale).""" + st = STYLE["held"] + if st == "A": + g.rect(x, y + h - 4 * k, w, 4 * k, VERM) + elif st == "B": + g.path(f"M{x},{y} h{12 * k} l{-12 * k},{12 * k} Z", fill=VERM) + else: + g.rect(x, y + h - 3 * k, w, 3 * k, mix(VERM, PAGE, 0.6)) + + def tag(g, x, y, w, h, title, focus=False, note=None): """A panel's frame and its one-row tag. note: a string, or runs (text, ink, underlined) for a legend.""" g.rect(x, y, w, TAG, RAISED) @@ -146,11 +201,10 @@ def chain(g, x, y, links, end, marks=None, room=None, lead=0): x = link_arrow(g, x, y) m = marks.get(i) if m == "strike": - g.rect(x - 5, y + 1, w + 10, ROW - 2, VERM) - addr(g, x, y, n, INK, BOLD) + addr(g, x, y, n, struck(g, x - 5, y, w + 10), BOLD) else: if m == "tick": - g.rect(x - 9, y + 3, 4, ROW - 6, VERM) + held(g, x, y, w) if m == "read": g.frame(x - 6, y, w + 12, ROW, READ, 2) addr(g, x, y, n, ink, lead=lead if i == 0 else 0) @@ -166,7 +220,7 @@ def chain(g, x, y, links, end, marks=None, room=None, lead=0): return where x = value_arrow(g, x, y) if links else x if marks.get("end") == "tick": # the value it holds changed within three steps - g.rect(x - 7, y + 3, 4, ROW - 6, VERM) + held(g, x + 2, y, len(str(end[1])) * A if end[0] == "int" else 3 * A) if end[0] == "int": integer(g, x, y, end[1]) else: @@ -186,11 +240,11 @@ def pin(g, x, y, names, ink): g.path(f"M{x + 9},{y + 12} l-9,-6 v12 Z", fill=ink) -def pin_up(g, cx, y, names, ink, size, link=None): +def pin_up(g, cx, y, names, ink, size, link=None, sw=3): """A register's name under what it points at: a stub with its head on the thing, the names either side. link: the points the stub is the end of, when this is the step that set the register.""" rise = size + 10 - gen.arrow(g, (link or []) + [(cx, y + rise), (cx, y + 1)], ink, 3, r=8, hl=10, hw=10) + gen.arrow(g, (link or []) + [(cx, y + rise), (cx, y + 1)], ink, sw, r=8, hl=10 + 2 * (sw - 3), hw=10 + 2 * (sw - 3)) face = BOLD by = y + 8 + size * 0.86 if names and names[0]: # names keep their side: None holds a side that was left @@ -215,37 +269,41 @@ def registers(g, y, regs, flags, marks): for i, (name, links, end) in enumerate(regs): yy = y0 + i * ROW if name == "rip": - g.rect(RX + 2, yy, CW - 4, ROW, EMBER[GOLD]) - g.rect(RX + 2, yy, 54, ROW, GOLD) - g.t(RX + 12, b(yy), name, S, INK, BOLD) + g.t(RX + 12, b(yy), name, S, current_row(g, RX + 2, yy, CW - 4, 54), BOLD) else: g.t(RX + 12, b(yy), name, S, DIM, MONO) where[name] = yy if links: chain(g, RX + 72, yy, links, end, marks.get(name), room=RX + CW - 12) else: + if marks.get(name, {}).get(0) == "strike": + s_ = ("0x%x" % end[1]) if end[1] >= 10 else str(end[1]) + g.t(RX + 72, b(yy), s_, S, struck(g, RX + 67, yy, len(s_) * A + 10), BOLD) + continue integer(g, RX + 72, yy, end[1]) if marks.get(name, {}).get(0) == "tick": - g.rect(RX + 63, yy + 3, 4, ROW - 6, VERM) + held(g, RX + 72, yy, len(str(end[1])) * A) # the flags, in rip's row: where the machine is, and the condition it is in x = RX + CW - 12 - len(flags) * 42 + 10 for name, on, changed in flags: if changed: - g.rect(x - 7, yy + 3, 4, ROW - 6, VERM) + held(g, x + 4, yy, 2 * A) if on: g.rect(x, yy + 2, 2 * A + 8, 20, RAISED) g.t(x + 4, b(yy), name, S, BRIGHT, BOLD) else: - g.t(x + 4, b(yy), name.lower(), S, mix(DIM, EMBER[GOLD], 0.8), MONO) + g.t(x + 4, b(yy), name.lower(), S, mix(DIM, band(), 0.8), MONO) x += 42 return where -def stack(g, y, rows, frames, note=None): +def stack(g, y, rows, frames, note=None, rsp=None, roles=None): """rows: (slot, pins, links, end[, marks]). frames: (name, first row, last row), newest first: the backtrace, drawn on the words that are each frame; a first row under 0 runs above the window. The window is the newest frame's. A frame's name is never cut for a chain: the chains on the rows it sits on end 12 - before it. Returns each row's y.""" + before it. rsp: the slots' offsets from it are drawn (pwndbg's column). roles: {row: (what the slot is, ink)}: + a local's name, `saved rbp`, `return`, ranged right where the chain's room ends; the chain ends 12 before it. + Returns each row's y.""" y0 = panel(g, RX, y, CW, len(rows), "stack", note=(note or "%s words from rsp" % {6: "six", 8: "eight"}[len(rows)]) + " · the frames they belong to") lead = shared([r[0] for r in rows]) @@ -264,13 +322,22 @@ def stack(g, y, rows, frames, note=None): room[r] = min(room.get(r, RX + CW - 136), nx - 12) spans.append((i, name, x, ya, yb, ny, open_top, open_)) ys = [] + roles = roles or {} + first = RX + (184 if rsp is not None else 122) for i, (slot, pins, links, end, *marks) in enumerate(rows): yy = y0 + i * ROW ys.append(yy) if pins: pin(g, RX + 10, yy, pins, STACK) - chain(g, RX + 122, yy, [(slot, STACK)] + links, end, marks[0] if marks else None, - room=room.get(i, RX + CW - 136), lead=lead) + if rsp is not None: # the offset from rsp, pwndbg's way: +18 + off = slot - rsp + g.t(RX + 172, b(yy), ("+%x" % off) if off >= 0 else ("-%x" % -off), S, FAINT, MONO, "end") + end_x = room.get(i, RX + CW - 136) + if i in roles: + text, ink = roles[i] + g.t(end_x, b(yy), text, S, ink, MONO, "end") + end_x -= len(text) * A + 12 + chain(g, first, yy, [(slot, STACK)] + links, end, marks[0] if marks else None, room=end_x, lead=lead) for i, name, x, ya, yb, ny, open_top, open_ in spans: ink = GOLD if i == 0 else RULE g.rect(x - 1, ya, 2, yb - ya, ink) @@ -319,14 +386,12 @@ def wide(total): def source(g, y, rows, lines, first, cur, trail, name, total): """Returns the y of the current line's row. Numbers as wide as the file's last: the text moves by the extra.""" w = wide(total) - y0 = panel(g, LX, y, CW, rows, name, note=f"lines {first} to {first + rows - 1} of {total}") + y0 = panel(g, LX, y, CW, rows, name, note=f"lines {first} to {min(first + rows - 1, total)} of {total}") for i in range(rows): n = first + i yy = y0 + i * ROW if n == cur: - g.rect(LX + 2, yy, CW - 4, ROW, EMBER[GOLD]) - g.rect(LX + 2, yy, 50 + w, ROW, GOLD) - g.t(LX + 46 + w, b(yy), str(n), S, INK, BOLD, "end") + g.t(LX + 46 + w, b(yy), str(n), S, current_row(g, LX + 2, yy, CW - 4, 50 + w), BOLD, "end") else: if n in trail: g.rect(LX + 2, yy + 1, 4, ROW - 2, TRAIL[min(trail.index(n), 2)]) @@ -352,16 +417,14 @@ def disasm(g, y, rows, func, cur_line, jump=None, w=0): yy = y0 + i * ROW where[a] = yy dim = st == "out" - if dim: # the function ends: a rule, and the next one's name + if dim or st == "other_first": # a function ends: a rule, and the next one's name g.rect(LX + 2, yy, CW - 4, 2, RULE) if st == "cur": - g.rect(LX + 2, yy, CW - 4, ROW, EMBER[GOLD]) - g.rect(LX + 2, yy, 24, ROW, GOLD) - g.path(f"M{LX + 20},{yy + 12} l-10,-6 v12 Z", fill=INK) + g.path(f"M{LX + 20},{yy + 12} l-10,-6 v12 Z", fill=current_row(g, LX + 2, yy, CW - 4, 24)) elif st and st.startswith("trail"): g.rect(LX + 2, yy + 1, 4, ROW - 2, TRAIL[int(st[-1])]) addr(g, LX + DX_ADDR, yy, a, mix(CODE, PAGE, 0.6) if dim else CODE, lead=0 if dim else lead) - if line != last_line and not dim: # the line this run of instructions was compiled from + if line is not None and line != last_line and not dim: # the line this run was compiled from on = line == cur_line g.t(LX + DX_LINE + 3 * A + w, b(yy), str(line), S, GOLD if on else FAINT, BOLD if on else MONO, "end") last_line = line @@ -400,30 +463,38 @@ def thread(g, ys, spans): # ---- the lens: a list, and beside it the bytes it is drawn from ------------------------- -def fields(g, y, h, about, base, length, flist, mem, region, region_of, marks=()): +def fields(g, y, h, about, base, length, flist, mem, region, region_of, marks=(), title="its bytes", x=None, + framed=(), bare=False, rows_shown=None): """`hexdump` by `fields`: the region a scene names, read by the fields it gives it, in the band's view. flist: (at, len, reads, big, mark) with reads in number | pointer | text | bytes. mem: {address: byte} of what the stop shown saw (or the kernel took); a byte not in it is unread. marks: the field marks framed as read. - Rows that hold no field are one `more` row and their count. The bytes begin 12 after the widest address.""" - tag(g, RX, y, CW, h, "its bytes") - g.t(RX + 28 + tw("its bytes", 20, "sansm") + 12, y + 18, about, 18, FAINT, "sans") + Rows that hold no field are one `more` row and their count. The bytes begin 12 after the widest address. + reads `malloc`: the allocator's size word, loose, read as a note. framed: (at, len) drawn with `attention`'s + bright frame (a loupe's target). bare: no tag (a loupe draws its own). rows_shown: the rows to show, when the + window is not every row that holds a field. Returns {row address: y}.""" + X = RX if x is None else x + if not bare: + tag(g, X, y, CW, h, title) + g.t(X + 28 + tw(title, 20, "sansm") + 12, y + 18, about, 18, FAINT, "sans") total = (length + 15) // 16 holds = lambda r: any(base + at < base + 16 * (r + 1) and base + at + n > base + 16 * r for at, n, *_ in flist) - shown = [r for r in range(total) if holds(r) or total <= (h - TAG - 2 * PAD) // ROW] + shown = rows_shown if rows_shown is not None else [r for r in range(total) if holds(r)] + ys = {} digits = max(len("%x" % (base + 16 * r)) for r in shown) shift = max(18 + digits * A + 12 - 132, 0) - bx = lambda i: RX + 132 + shift + i * 30 + (12 if i >= 8 else 0) + bx = lambda i: X + 132 + shift + i * 30 + (12 if i >= 8 else 0) lead = shared([base + 16 * r for r in shown]) if len(shown) > 1 else 0 yy, last = y + TAG + PAD, None for r in shown: if last is not None and r > last + 1: # the rows left out: one row, and how many - more(g, RX + 18 - 6, yy) - g.t(RX + 18 + 30 + 36, b(yy), "%d rows" % (r - last - 1), S, FAINT, MONO) + more(g, X + 18 - 6, yy) + g.t(X + 18 + 30 + 36, b(yy), "%d rows" % (r - last - 1), S, FAINT, MONO) yy += ROW last = r a0 = base + 16 * r - bracket(g, RX + 7, yy + 3, yy + ROW - 3, mix(region, PAGE, 0.6)) - addr(g, RX + 18, yy, a0, region, lead=lead) + ys[a0] = yy + bracket(g, X + 7, yy + 3, yy + ROW - 3, mix(region, PAGE, 0.6)) + addr(g, X + 18, yy, a0, region, lead=lead) runs, i = [], 0 while i < 16 and a0 + i < base + length: f = next((f for f in flist if base + f[0] <= a0 + i < base + f[0] + f[1]), None) @@ -433,12 +504,12 @@ def fields(g, y, h, about, base, length, flist, mem, region, region_of, marks=() n = min([base + o[0] - a0 for o in flist if a0 + i < base + o[0] < a0 + 16] + [16, base + length - a0]) - i runs.append((i, n, f)) i += n - x = RX + 640 + shift # the reading: a list, a character apart + x = X + 640 + shift # the reading: a list, a character apart for i0, n, f in runs: vals = [mem.get(a0 + k) for k in range(i0, i0 + n)] reads = f[2] if f else "loose" x0, x1 = bx(i0) - 4, bx(i0 + n - 1) + 28 - if f: + if f and reads != "malloc": g.rect(x0, yy + 1, x1 - x0, ROW - 2, RAISED) if f[4] is not None and f[4] in marks: g.frame(x0 - 3, yy - 1, x1 - x0 + 6, ROW + 2, READ, 2) @@ -448,8 +519,11 @@ def fields(g, y, h, about, base, length, flist, mem, region, region_of, marks=() order = vals[::-1] if not (f and f[3]) else vals for v in order: word = word << 8 | v - ink = {"number": VELLUM, "bytes": VELLUM, "text": LIT, "loose": DIM, - "pointer": region_of(word) if known else VELLUM}[reads] + for fa, fl in framed: # the target: framed bright, as attention + if base + fa < a0 + i0 + n and base + fa + fl > a0 + i0: + g.frame(x0 - 3, yy - 1, x1 - x0 + 6, ROW + 2, BRIGHT, 2) + ink = {"number": VELLUM, "bytes": VELLUM, "text": LIT, "loose": DIM, "malloc": DIM, + "pointer": (region_of(word) or VELLUM) if known else VELLUM}[reads] nz = [k for k, v in enumerate(vals) if v] for k, v in enumerate(vals): xx = bx(i0 + k) @@ -461,21 +535,30 @@ def fields(g, y, h, about, base, length, flist, mem, region, region_of, marks=() g.t(xx, b(yy), "%02x" % v, S, mix(ink, PAGE, 0.45) if padded else ink, MONO) if not known or reads in ("bytes", "loose"): continue + if reads == "malloc": # the allocator's own: the size word of the chunk after it + note = "malloc's: a chunk of %d" % (word & ~7) if word < 0x10000 else "malloc's: the top chunk" + g.t(x, b(yy) - 1, note, 18, FAINT, "sans") + x += tw(note, 18, "sans") + A + continue if reads == "pointer": if word == 0: s_, sink = "NULL", DIM else: - x = addr(g, link_arrow(g, x, yy), yy, word, region_of(word)) + A + x = addr(g, link_arrow(g, x, yy), yy, word, region_of(word) or VELLUM) + A continue elif reads == "number": s_, sink = str(word), VELLUM else: s_, sink = '"' + bytes(vals).split(b"\0")[0].decode("latin1") + '"', LIT - if x + len(s_) * A > RX + CW - 12: - s_ = s_[:max(int((RX + CW - 12 - x) // A) - 1, 0)] + "…" + if x + len(s_) * A > X + CW - 12: + s_ = s_[:max(int((X + CW - 12 - x) // A) - 1, 0)] + "…" g.t(x, b(yy), s_, S, sink, MONO) x += (len(s_) + 1) * A yy += ROW + if shown and shown[-1] < total - 1: # the rows after the last field: one row, and how many + more(g, X + 18 - 6, yy) + g.t(X + 18 + 30 + 36, b(yy), "%d rows" % (total - 1 - shown[-1]), S, FAINT, MONO) + return ys def kernel(g, y, h, calls, name, nr, rows, given): @@ -524,7 +607,7 @@ def dump_row(g, y, a, runs, lead, mark=None, node=False): if mark.get("read") == k: g.frame(x0 - 3, y - 1, x1 - x0 + 6, ROW + 2, READ, 2) if mark.get("tick") == k: - g.rect(x0 - 7, y + 3, 4, ROW - 6, VERM) + held(g, x0 + 4, y, x1 - x0 - 8) ink = {"value": VELLUM, "next": HEAP, "malloc": DIM, "unread": FAINT}[kind] top = max((j for j in range(n) if (v or 0) >> (8 * j) & 0xff), default=0) for j in range(n): @@ -548,26 +631,30 @@ def dump_row(g, y, a, runs, lead, mark=None, node=False): g.t(x + 3 * A + 8 + 30, b(y), "NULL", S, DIM, MONO) -def lens(g, y, h, hv, nodes, pins, marks, first, nrows, link_from=None, subject=False): +def lens(g, y, h, hv, nodes, pins, marks, first, nrows, link_from=None, subject=False, dw=None, k=1, view_rows=None): """The band: the list drawn, over the program column, and the heap bytes it is drawn from, over the state column; two panels, h and hv high, the gutter between them the ties'. nodes: (address, value, next address or 0), in the list's order. pins: {address: [registers]}. marks: {"read": address of a word, "tick": [addresses of words]}. link_from: the y of the register row the step's link comes from, and the register. - As the subject the drawing is a size up; the dump stays on the context's grid and shows more rows.""" - tag(g, LX, y, CW, h, "the list", focus=True) + As the subject the drawing is a size up; the dump stays on the context's grid and shows more rows. + On the 4K stage the drawing is dw wide and drawn k times the size (2), and the view is drawn by `fields`, whose + rows (view_rows: {row address: y}) the projection starts from.""" + dw = dw or CW + tag(g, LX, y, dw, h, "the list", focus=True) last = first + (nrows - 1) * 16 - tag(g, RX, y, CW, hv, "its bytes", - note=[("value", VELLUM, False), ("next", HEAP, False), ("malloc's", DIM, False), ("never read", FAINT, False)]) - g.t(RX + 28 + tw("its bytes", 20, "sansm") + 12, y + 18, "the heap, %x to %x" % (first, last + 15), 18, FAINT, - "sans") + rows = view_rows or {} + if view_rows is None: + tag(g, RX, y, CW, hv, "its bytes", + note=[("value", VELLUM, False), ("next", HEAP, False), ("malloc's", DIM, False), ("never read", FAINT, False)]) + g.t(RX + 28 + tw("its bytes", 20, "sansm") + 12, y + 18, "the heap, %x to %x" % (first, last + 15), 18, FAINT, + "sans") # the dump y0 = y + TAG + PAD by_addr = {a: (v, nx) for a, v, nx in nodes} lead = shared([first, last]) - rows = {} - for i in range(nrows): + for i in range(nrows if view_rows is None else 0): a, yy = first + i * 16, y0 + i * ROW rows[a] = yy if a in by_addr: @@ -584,12 +671,13 @@ def lens(g, y, h, hv, nodes, pins, marks, first, nrows, link_from=None, subject= dump_row(g, yy, a, [(0, 8, "unread", None), (8, 8, "malloc", 0x21)], lead) # the drawing, centred between its lanes - NW, NH, GAP, VS, LS = (124, 72, 22, 45, 25) if subject else (116, 44, 28, 25, 20) - VW = NW - 48 # the value's half; the pointer's is 48 - x0 = LX + (CW - len(nodes) * NW - (len(nodes) - 1) * GAP) / 2 + NW, NH, GAP, VS, LS = [v * k for v in ((124, 72, 22, 45, 25) if subject else (116, 44, 28, 25, 20))] + VW = NW - 48 * k # the value's half; the pointer's is 48 + tie_w = (3, 2) if k == 1 else (4, 3) # a link, a projection: on the 4K stage, 2 and 1.5 pixels at 1080p + x0 = LX + (dw - len(nodes) * NW - (len(nodes) - 1) * GAP) / 2 lane_top, lane_bot = y + TAG + 4, y + h - 8 block = LS * 1.2 + 4 + NH + LS + 10 + 8 # address, node, the pins' stub and names - ly = y + TAG + (16 if not subject else round((h - TAG - block) / 2)) # the row of addresses over the nodes + ly = y + TAG + (16 * k if not subject else round((h - TAG - block) / 2)) # the row of addresses over the nodes ny = ly + LS * 1.2 + 4 xs = {a: x0 + i * (NW + GAP) for i, (a, v, nx) in enumerate(nodes)} for a, v, nx in nodes: @@ -599,22 +687,22 @@ def lens(g, y, h, hv, nodes, pins, marks, first, nrows, link_from=None, subject= g.t(x + VW / 2 - 1, ny + NH / 2 + 0.36 * VS, str(v), VS, VELLUM, MONO if VS < 30 else "mono", "middle") g.rect(x + VW, ny, NW - VW, NH, WELL) if marks.get("read") == a + 8: - g.frame(x + VW - 2, ny - 2, NW - VW + 4, NH + 4, READ, 2) + g.frame(x + VW - 2 * k, ny - 2 * k, NW - VW + 4 * k, NH + 4 * k, READ, 2 * k) if a + 8 in marks.get("tick", ()): - g.rect(x + VW, ny + NH - 4, NW - VW, 4, VERM) + held_cell(g, x + VW, ny, NW - VW, NH, k) cx, cy = x + VW + (NW - VW) / 2, ny + NH / 2 if nx: - g.rect(cx - 5, cy - 5, 10, 10, HEAP) - gen.arrow(g, [(cx + 8, cy), (xs[nx] - 3, cy)], HEAP, 3, hl=12, hw=10) + g.rect(cx - 5 * k, cy - 5 * k, 10 * k, 10 * k, HEAP) + gen.arrow(g, [(cx + 8 * k, cy), (xs[nx] - 3 * k, cy)], HEAP, 3 * k, hl=12 * k, hw=10 * k) else: - g.path(f"M{x + VW + 10},{ny + NH - 8} L{x + NW - 10},{ny + 8}", DIM, 2) + g.path(f"M{x + VW + 10 * k},{ny + NH - 8 * k} L{x + NW - 10 * k},{ny + 8 * k}", DIM, 2 * k) names = pins.get(a) if names: via = None if link_from and link_from[1] in names: # the step's link ends in this pin via = [(RX + 2, link_from[0] + 12), (LANE_LINK, link_from[0] + 12), (LANE_LINK, lane_bot), (x + NW / 2, lane_bot)] - pin_up(g, x + NW / 2, ny + NH, names, HEAP, LS, via) + pin_up(g, x + NW / 2, ny + NH, names, HEAP, LS, via, sw=tie_w[0]) # the projection: the bytes a step read, and the part of the drawing that is those bytes if marks.get("read"): @@ -623,7 +711,7 @@ def lens(g, y, h, hv, nodes, pins, marks, first, nrows, link_from=None, subject= bracket(g, RX + 7, yy + 2, yy + ROW - 2, READ, 3, 6) g.path(f"M{RX + 6},{yy + 12} H{LANE_VIEW + 6} Q{LANE_VIEW},{yy + 12} {LANE_VIEW},{yy + 6} V{lane_top + 6} " f"Q{LANE_VIEW},{lane_top} {LANE_VIEW - 6},{lane_top} H{x + NW / 2 + 6} " - f"Q{x + NW / 2},{lane_top} {x + NW / 2},{lane_top + 6} V{ly - 4}", READ, 2) + f"Q{x + NW / 2},{lane_top} {x + NW / 2},{lane_top + 6} V{ly - 4}", READ, tie_w[1]) g.rect(x, ly - 5, NW, 3, READ) g.rect(x, ly - 5, 3, 8, READ) g.rect(x + NW - 3, ly - 5, 3, 8, READ) @@ -848,9 +936,7 @@ def backtrace(g, y, h, frames, x=RX, note="the calls waiting · newest on top", for i, (name, args, file, line) in enumerate(frames[:rows]): yy = y0 + i * ROW if i == 0: - g.rect(x + 2, yy, CW - 4, ROW, EMBER[GOLD]) - g.rect(x + 2, yy, 40, ROW, GOLD) - g.t(x + 12, b(yy), "#0", S, INK, BOLD) + g.t(x + 12, b(yy), "#0", S, current_row(g, x + 2, yy, CW - 4, 40), BOLD) else: g.t(x + 12, b(yy), "#%d" % i, S, FAINT, MONO) g.t(x + 60, b(yy), name, S, VELLUM, MONO) diff --git a/design/mock/dense.py b/design/mock/dense.py new file mode 100644 index 0000000..cb047ac --- /dev/null +++ b/design/mock/dense.py @@ -0,0 +1,441 @@ +#!/usr/bin/env python3 +"""The frame on the 4K stage: four columns of 880, the context at mono 20, four times what 1080 held. + + python3 -B dense.py # writes 15-marks.svg, 16-none.svg, 17-subject.svg, 18-loupes.svg + +The blocks are context.py's, placed on the 4K stage's columns; what is new here is the stage, the thread across +the gutter, the `loupe`, and the marks sheet. The moment is real: a fresh recording of the same `targets/list`, +`ztrace dbg --stack 1024` with a breakpoint at `reverse+22` (the load at line 21), its second stop and the +instruction after (`list-dbg.txt`, kept beside this file), and the program's disassembly with its lines +(`objdump -dl`, `list.dis`). +""" +import re + +import gen +gen.W, gen.H = 3840, 2160 # the Svg's canvas: the 4K stage, in units +import context as C +from context import (PAGE, RAISED, VELLUM, BRIGHT, DIM, FAINT, INK, GOLD, VERM, READ, HEAP, STACK, A, S, ROW, + TAG, PAD, MONO, BOLD, b, ph, tw, mix, bracket, chain, Svg, S_, H_, C_, D_, P) + +W4, H4 = 3840, 2160 +COL = [112, 1024, 1936, 2848] # four columns of 880, gutters of 32 +CW = 880 +TOP4, BOT4 = 96, 1784 # the stage: 1688, a single panel of 69 rows +C.W = W4 +C.TOP, C.BOTTOM = TOP4, BOT4 +C.LANE_LINK, C.LANE_VIEW = 1912, 1924 # the gutter between the program's columns and the state's +THREAD_X = 1008 # the gutter between the source and the disassembly +LIFT, LIFT_TAG, SHADE = "#121c52", "#22317a", "#02061a" # a loupe's surface, its tag, its shadow + + +def put(x): + """Place the next block in the column at x.""" + C.LX = C.RX = x + + +# ---- the recording ---------------------------------------------------------------------------------- +DBG = open(__file__.replace("dense.py", "list-dbg.txt")).read() +MEM = {} +for line in DBG.split("\n"): + m = re.match(r"^([0-9a-f]{12}) ((?:[0-9a-f?]{2} ){16})", line) + if m and "??" not in m.group(2): + for i, v in enumerate(m.group(2).split()): + MEM[int(m.group(1), 16) + i] = int(v, 16) +NAMES = {0x1001730: "_start", 0x1001830: "list_done", 0x1001860: "main", 0x10018e0: "push", 0x1001910: "reverse", + 0x1001938: "_init", 0x1001954: "_fini"} +LIBNAMES = {0x7ffff7c27781: "libc+27781", 0x7ffff7c278b9: "__libc_start_main+137", 0x7ffff7fe0c60: "ld.so+22c60", + 0x7ffff7fbc000: "vdso+0"} + + +def region(v): + """The ink of what v points into, by the run's mappings (None: no mapping).""" + for lo, hi, ink in [(0x7ffffffde000, 0x7ffffffff000, S_), (0x1004000, 0x1025000, H_), (0x1001000, 0x1002000, C_), + (0x1000000, 0x1001000, VELLUM), (0x1002000, 0x1003000, VELLUM), (0x1003000, 0x1004000, D_), + (0x7ffff7c24000, 0x7ffff7d9f000, C_), (0x7ffff7c00000, 0x7ffff7c24000, VELLUM), + (0x7ffff7e15000, 0x7ffff7e23000, D_), (0x7ffff7fbc000, 0x7ffff7fbe000, C_), + (0x7ffff7fbf000, 0x7ffff7fec000, C_), (0x7ffff7ffb000, 0x7ffff7fff000, D_)]: + if lo <= v < hi: + return ink + return None + + +def name(v): + if v in LIBNAMES: + return LIBNAMES[v] + f = max((a for a in NAMES if a <= v), default=None) + return "%s+%d" % (NAMES[f], v - f) if f is not None else "%x" % v + + +def word(a): + if all(a + i in MEM for i in range(8)): + return sum(MEM[a + i] << (8 * i) for i in range(8)) + return None + + +def text(a): + """The C string at a, if there is one of two characters or more.""" + out = [] + while a + len(out) in MEM and MEM[a + len(out)] and 32 <= MEM[a + len(out)] < 127: + out.append(chr(MEM[a + len(out)])) + return "".join(out) if len(out) >= 2 and MEM.get(a + len(out)) == 0 else None + + +def follow(v, depth=5): + """A chain from the address v, as far as the recording holds the memory: (links, end) for context.chain.""" + links = [] + while True: + ink = region(v) + if ink == C_: + return links + [(v, C_, name(v))], None + links.append((v, ink)) + s = text(v) + if s: + return links, ("str", s) + w = word(v) + if w is None or len(links) > depth: + return links, None + if w and region(w): + v = w + continue + return links, ("int", w) + + +def value(v): + return follow(v) if v and region(v) else ([], ("int", v)) + + +RSP = 0x7fffffffece0 +FRAMES = [("reverse", 0, 1), ("main", 2, 5), ("libc+27781", 6, 27), ("__libc_start_main", 28, 39), ("_start", 40, 99)] +# What a slot is, where the recording can know it: a saved register (the frame-pointer chain; the prologue's pushes, +# from the call frame information), the process's start (argc, argv, envp, auxv, from the first stack pointer). A +# return address needs no word: its chain is code, named, and its frame's bracket ends on it. +ROLES = {0: "saved rbp", 3: "saved rbx", 4: "saved rbp", 26: "saved rbp", 38: "saved rbp", 42: "argc", 43: "argv[0]", + 44: "argv end", 45: "envp end", 46: "auxv"} + + +def stack_rows(n, rbp_rsp=True): + rows = [] + for i in range(n): + a = RSP + 8 * i + links, end = value(word(a)) + rows.append((a, (["rbp", "rsp"] if i == 0 and rbp_rsp else []), links, end)) + return rows + + +def roles(n): + return {i: (t, DIM) for i, t in ROLES.items() if i < n} + + +def regs(step): + rdi = 0x1004070 if step else 0x1004090 + out = [] + for r, v in [("rax", 0x1004090), ("rbx", 0), ("rcx", 0x10040b0), ("rdx", 0), ("rsi", 0x10040c0), ("rdi", rdi), + ("rbp", RSP), ("rsp", RSP), ("r8", 0x7ffff7e19ac0), ("r9", 0x20), ("r10", 0x10), ("r11", 0x7ffff7e19ac8), + ("r12", 0x7fffffffee38), ("r13", 1), ("r14", 0x7ffff7ffd000), ("r15", 0x10029c0)]: + links, end = value(v) + if r == "r14": # ld.so's data: the recording followed it (ztrace's own telescope) + links, end = [(0x7ffff7ffd000, D_), (0x7ffff7ffe3c0, D_)], ("int", 0) + if r == "r15": + links, end = [(0x10029c0, VELLUM)], ("int", 1) + out.append((r, links, end)) + out.append(("rip", [(0x1001926, C_, "reverse+22")], None)) + return out + + +FLAGS = [("CF", 0, 0), ("PF", 1, 0), ("AF", 0, 0), ("ZF", 0, 0), ("SF", 0, 0), ("IF", 1, 0), ("DF", 0, 0), ("OF", 0, 0)] +BT = [("reverse+22", "", "list.c", 21), ("main+80", "", "list.c", 40), ("libc+27781", "", None, 0), + ("__libc_start_main+137", "", None, 0), ("_start+37", "", None, 0)] +NODES = [(0x10040b0, 1, 0), (0x1004090, 4, 0x1004070), (0x1004070, 9, 0x1004050), (0x1004050, 16, 0x1004030), + (0x1004030, 25, 0x1004010), (0x1004010, 36, 0)] +SRC = C.SRC[:42] + [""] * 40 + + +def heap_fields(base, length, read_at=None): + """The heap's words by what the program and malloc made of them: each node a value and a next, each chunk's + size word malloc's, the top chunk's size word, and the rest loose. The word at read_at carries mark 9.""" + out = [] + for a, _, _ in NODES: + out += [(a - base, 8, "number", False, None), (a + 8 - base, 8, "pointer", False, 9 if a + 8 == read_at else None), + (a - 8 - base, 8, "malloc", False, None)] + out.append((0x10040c8 - base, 8, "malloc", False, None)) + return [f for f in out if 0 <= f[0] < length] + + +def conv(mn, ops): + """objdump's Intel syntax as the recording's disassembler writes it.""" + if mn.startswith("data16") or mn == "cs": + return "nop", "word ptr cs:[rax + rax]" + ops = ops.lower().replace(",", ", ") + ops = re.sub(r"\[(.*?)\]", lambda m: "[" + re.sub(r"([+*-])", r" \1 ", m.group(1)).replace(" * ", "*") + "]", ops) + ops = ops.replace("*1 + 0x0", "").replace(" + 0x0]", "]") + + def num(m): + v = int(m.group(1), 16) + return str(v) if v < 10 else "0x%x" % v + ops = re.sub(r"rip \+ 0x(f{8}[0-9a-f]+)", lambda m: "rip - 0x%x" % ((1 << 64) - int(m.group(1), 16)), ops) + ops = re.sub(r"(?:", l) + if m: + func = m.group(2) + continue + m = re.match(r"^targets/list\.c:(\d+)", l) + if m: + line = int(m.group(1)) + continue + m = re.match(r"^\s+([0-9a-f]+):\s+(\S+)\s*(.*)$", l) + if m: + ops = re.sub(r"\s*<[^>]+>", "", re.sub(r"\s+#.*", "", m.group(3))).strip() + mn, ops = conv(m.group(2), ops) + own = func in ("main", "push", "reverse", "list_done") + rows.append((int(m.group(1), 16), func, line if own else None, mn, ops)) + return rows + + +CALLEES = {0x1001990: "printf", 0x10019a0: "malloc", 0x1001980: "strtol"} + + +def window(n, step): + """n instructions round the pc: the function's and its neighbours', each neighbour under a rule and its name.""" + rows = disasm_rows() + i = [r[0] for r in rows].index(0x1001926) + lo = max(0, min(i - n // 2, len(rows) - n)) + out, last_func = [], None + for a, func, line, mn, ops in rows[lo:lo + n]: + target = re.fullmatch(r"([0-9a-f]{6,})", ops) + parts = [(int(ops, 16), C_)] if target else ([(ops, P)] if ops else []) + st = "cur" if a == 0x1001926 else None + note = None + if func != "reverse": + st = "other_first" if func != last_func else "other" + if func != last_func: + note = ("text", func, DIM) + if mn == "call" and target and int(ops, 16) in CALLEES: + note = ("text", CALLEES[int(ops, 16)], VELLUM) + if a == 0x1001926: + note = ("chain", [(0x1004098, H_), (0x1004070, H_)], ("int", 9), {0: "read"} if step else None) + out.append((a, line, mn, parts, st, note)) + last_func = func + return out + + +# ---- the stage's blocks ------------------------------------------------------------------------------- +def thread_across(g, ys, spans): + """The thread on the 4K stage: the source and the disassembly side by side, the gutter between them its + channel. A bracket on the line at the source's right edge, one on each run at the disassembly's left, a + line down the gutter between.""" + x0, x1 = COL[0] + CW + 6, COL[1] - 6 + bracket(g, x0, ys + 2, ys + ROW - 2, GOLD, 4, 7, side=-1) + tops = [ys + 12] + for ya, yb in spans: + bracket(g, x1, ya + 2, yb - 2, GOLD, 4, 7) + tops.append((ya + yb) / 2) + g.rect(THREAD_X, (ya + yb) / 2 - 2, x1 - THREAD_X, 4, GOLD) + g.rect(x0, ys + 10, THREAD_X - x0, 4, GOLD) + g.rect(THREAD_X - 2, min(tops) - 2, 4, max(tops) - min(tops) + 4, GOLD) + + +def clock4(g, moment, total): + g.rect(COL[0], 1798, 3616, 4, C.RULE) + g.rect(COL[0], 1796, 3616 * moment / total, 8, GOLD) + g.t(COL[3] + CW, 1852, "moment %d of %d" % (moment, total), 40, FAINT, "mono", "end") + + +def caption4(g, lines): + """The caption, twice the 1080 frame's: Go 80 on 108, code mono 70; so it reads the same at 1080p.""" + y = 1824 + (104 if len(lines) == 2 else 156) + for parts in lines: + g.rich(COL[0], y, [(p[0], VELLUM) + tuple(p[1:]) for p in parts], 80) + y += 108 + + +def loupe(g, x, y, title, note, base, flist, framed, depth): + """`loupe`: the memory round a pointer's target, floating over the context, tied to the pointer it opens + from. Nine rows, the target's in the middle; the target framed bright. Lifted: its own surface, a shadow + under it, deeper for a loupe opened from another. Returns its rows' y.""" + h = ph(9) + sx, sy = (12, 16) if depth == 1 else (20, 26) + g.rect(x + sx, y + sy, CW, h, SHADE) + g.rect(x, y, CW, h, LIFT) + g.rect(x, y, CW, TAG, LIFT_TAG) + g.frame(x, y, CW, h, DIM, 2) + xx = x + 12 + for s_, ink in title: + g.t(xx, y + 18, s_, S, ink, MONO) + xx += len(s_) * A + g.t(x + CW - 10, y + 18, note, 18, DIM, "sans", "end") + return C.fields(g, y, h, "", base, 144, flist, MEM, HEAP, region, framed=framed, bare=True, x=x) + + +def stem(g, pts): + """The tie from a pointer to its loupe: a link, in the ink of what it points into, head on the loupe.""" + gen.arrow(g, pts, HEAP, 4, r=8, hl=12, hw=12) + + +# ---- the frames ---------------------------------------------------------------------------------------- +def frame_none(name, step, loupes=False): + """`none` on the 4K stage: source | disassembly | registers, backtrace, memory | stack.""" + g = Svg() + put(COL[0]) + ys = C.source(g, TOP4, 69, SRC, 1, 21, [], "list.c", 42) + put(COL[1]) + at = C.disasm(g, TOP4, window(69, step), "reverse", 21) + thread_across(g, ys, [(at[0x1001926], at[0x1001926] + ROW)]) + put(COL[2]) + marks = {"rax": {0: "tick"}, "rcx": {0: "tick"}, "rdi": {0: "strike" if step else "tick"}} + where = C.registers(g, TOP4, regs(step), FLAGS, marks) + C.backtrace(g, 548, 416, BT, x=COL[2], note="newest on top") + C.fields(g, 976, 808, "the heap, round what the step reads", 0x1004000, 512, + heap_fields(0x1004000, 512, 0x1004098), MEM, HEAP, region, marks=(9,) if step else (), title="memory") + put(COL[3]) + C.stack(g, TOP4, stack_rows(69), FRAMES, note="69 words from rsp", rsp=RSP, roles=roles(69)) + if loupes: + ry = where["rdi"] + x1, y1 = 2728, ry + r1 = loupe(g, x1, y1, [("rdi", DIM), (" → ", FAINT), ("1004070", HEAP)], "heap · struct node, 16 bytes", + 0x1004030, heap_fields(0x1004030, 144), [(0x1004070 - 0x1004030, 16)], 1) + stem(g, [(COL[2] + 72 + 7 * A + 30 + A + 16, ry + 12), (x1, ry + 12)]) # from the end of rdi's chain + # the next word in it opens the next: the field's bytes bracketed, a stem down into the deeper loupe + fy = r1[0x1004070] + bx0 = x1 + 132 + 8 * 30 + 12 - 4 + bx1 = x1 + 132 + 15 * 30 + 12 + 28 + g.rect(bx0, fy + ROW + 1, bx1 - bx0, 3, HEAP) + x2, y2 = x1 + 120, fy + ROW + 34 + loupe(g, x2, y2, [("1004078", HEAP), (" → ", FAINT), ("1004050", HEAP)], "heap · struct node, 16 bytes", + 0x1004010, heap_fields(0x1004010, 144), [(0x1004050 - 0x1004010, 16)], 2) + stem(g, [((bx0 + bx1) / 2, fy + ROW + 4), ((bx0 + bx1) / 2, y2)]) + clock4(g, 3 if step else 2, 4) + if loupes: + caption4(g, [[("The load is done: ",), ("rdi", "mono"), (" holds ",), ("1004070", "mono"), + (", and beside it the heap round it opens.",)], + [("Its ",), ("next", "mono"), (" word opens the node after it, one deeper.",)]]) + else: + caption4(g, [[("Stopped in ",), ("reverse", "mono"), (", about to load ",), ("head->next", "mono"), (".",)], + [("rdi", "mono"), (" points at a node; the word after its value is the next node.",)]]) + g.save(name) + + +def frame_subject(name): + """`subject` on the 4K stage, mid-step: the list drawn twice the size over the program's two columns, its + bytes over the third, the context under and beside them.""" + g = Svg() + band = 604 + put(COL[2]) + view = C.fields(g, TOP4, 800, "the heap, 1004000 to 10041ff", 0x1004000, 512, + heap_fields(0x1004000, 512, 0x1004098), MEM, HEAP, region, marks=(9,)) + where = C.registers(g, 908, regs(True), FLAGS, {"rax": {0: "tick"}, "rcx": {0: "tick"}, "rdi": {0: "strike"}}) + C.backtrace(g, 1360, 424, BT, x=COL[2], note="newest on top") + put(COL[0]) + pins = {0x10040b0: ["rcx"], 0x1004090: ["rax"], 0x1004070: ["rdi"]} + C.RX = COL[2] # the link leaves the registers, the projection the view + C.lens(g, TOP4, band, 800, NODES, pins, {"tick": [0x10040b8], "read": 0x1004098}, 0x1004000, 32, + link_from=(where["rdi"], "rdi"), subject=True, dw=2 * CW + 32, k=2, view_rows=view) + put(COL[0]) + ys = C.source(g, TOP4 + band + 12, 43, SRC, 1, 21, [], "list.c", 42) + put(COL[1]) + at = C.disasm(g, TOP4 + band + 12, window(43, True), "reverse", 21) + thread_across(g, ys, [(at[0x1001926], at[0x1001926] + ROW)]) + put(COL[3]) + C.stack(g, TOP4, stack_rows(69), FRAMES, note="69 words from rsp", rsp=RSP, roles=roles(69)) + clock4(g, 2, 4) + caption4(g, [[("The load read the word at ",), ("1004098", "mono"), (": the address of the next node.",)], + [("rdi", "mono"), (" holds it now, and points at the node whose value is 9.",)]]) + g.save(name) + + +def frame_marks(name): + """Mock 15: current, struck and held, as the first videos drew them (A), as the catalogue now does (B), and + the other reading of "white, with less opacity" (C), on real rows of the same moment and the one after.""" + g = Svg() + xs = [112, 1376, 2640] + titles = [("A", "the first videos: gold band, solid vermilion, a tick"), + ("B", "recommended: a white wash, a softened strike, a turned corner"), + ("C", "white: a white plaque, a white strike framed in vermilion, a bar under")] + g.t(112, 120, "current, struck, held", 40, BRIGHT, "sansm") + g.t(112, 164, "Rows of targets/list at the load in reverse (moment 3) and the store after it (moment 4), at the " + "4K stage's density: mono 20, rows of 24. Look at it at full size.", 24, DIM, "sans") + for (key, label), x in zip(titles, xs): + C.STYLE.update(current=key, struck=key, held=key) + g.t(x, 244, key, 56, GOLD if key == "B" else BRIGHT, "sansb") + g.t(x + 56, 236, label, 22, DIM, "sans") + put(x) + y = 280 + ys = C.source(g, y, 6, SRC, 18, 21, [20], "list.c", 42) + y += ph(6) + 24 + rows = [r for r in window(69, True) if 0x1001919 <= r[0] <= 0x100192e] + rows = [(a, ln, mn, ops, "trail0" if a == 0x1001923 else st, note) for a, ln, mn, ops, st, note in rows] + C.disasm(g, y, rows, "reverse", 21) + y += ph(len(rows)) + 24 + reg = [r for r in regs(True) if r[0] in ("rax", "rcx", "rsi", "rdi", "rbp")] + [regs(True)[-1]] + y0 = C.panel(g, x, y, CW, len(reg), "registers") + for i, (r, links, end) in enumerate(reg): + yy = y0 + i * ROW + if r == "rip": + g.t(x + 12, b(yy), r, S, C.current_row(g, x + 2, yy, CW - 4, 54), BOLD) + else: + g.t(x + 12, b(yy), r, S, DIM, MONO) + m = {"rax": {0: "tick"}, "rcx": {0: "tick"}, "rdi": {0: "strike"}}.get(r) + chain(g, x + 72, yy, links, end, m, room=x + CW - 12) + y += ph(len(reg)) + 24 + mem4 = dict(MEM) # moment 4: the store wrote 10040b0 into the word at 1004098 + for i, v in enumerate((0x10040b0).to_bytes(8, "little")): + mem4[0x1004098 + i] = v + flist = heap_fields(0x1004080, 64) + flist = [(a, n, r, bg, 7 if a == 0x18 else m) for a, n, r, bg, m in flist] + yr = C.fields(g, y, ph(4), "moment 4: the store, struck; 10040b8, held", 0x1004080, 64, flist, mem4, HEAP, + region, marks=()) + # struck on the run the store wrote, held on the one iteration 1 wrote (its own row, 10040b0's next) + r_y = yr[0x1004090] + x0 = x + 132 + 8 * 30 + 12 - 4 + ink = C.struck(g, x0, r_y, 30) # only the byte that changed: 70 to b0; 40 00 01 kept their value + g.t(x + 132 + 8 * 30 + 12, b(r_y), "b0", S, ink, BOLD) + C.held(g, x + 132 + 8 * 30 + 12, yr[0x10040b0], 8 * 30 - 6) + y += ph(4) + 36 + # a lens's cells, at the drawing's scale on this stage (2): a node held, a node struck + g.t(x, y, "in a lens's cell, twice the size", 20, DIM, "sansm") + y += 16 + for j, (lab, mark) in enumerate([("4", "held"), ("4", "struck")]): + cx = x + j * 300 + g.rect(cx, y, 152, 88, RAISED) + g.rect(cx + 152, y, 96, 88, C.WELL) + if mark == "struck": + ink = C.struck(g, cx, y - 1, 152, 90) + else: + ink = VELLUM + C.held_cell(g, cx + 152, y, 96, 88, 2) + g.t(cx + 76, y + 44 + 18, lab, 50, ink, "mono", "middle") + g.rect(cx + 190, y + 34, 20, 20, HEAP) + g.t(cx + 124, y + 118, mark, 20, DIM, "sansm", "middle") + # the same rows, closer: 1.4 times, for judging on a screen smaller than 4K + g.t(x, 1236, "the same, 1.35 times", 20, DIM, "sansm") + g.o.append('' % (x, 1256)) + put(0) + C.source(g, 0, 3, SRC, 19, 21, [20], "list.c", 42) + y0 = C.panel(g, 0, ph(3) + 16, CW, 4, "registers") + for i, r in enumerate([r for r in regs(True) if r[0] in ("rax", "rdi")] + [regs(True)[-1]]): + yy = y0 + i * ROW + nm, links, end = r + if nm == "rip": + g.t(12, b(yy), nm, S, C.current_row(g, 2, yy, CW - 4, 54), BOLD) + else: + g.t(12, b(yy), nm, S, DIM, MONO) + chain(g, 72, yy, links, end, {"rax": {0: "tick"}, "rdi": {0: "strike"}}.get(nm), room=CW - 12) + yy = y0 + 3 * ROW + g.t(12, b(yy), "rcx", S, DIM, MONO) + chain(g, 72, yy, [(0x10040b0, H_)], ("int", 1), {0: "tick"}, room=CW - 12) + g.o.append("") + put(x) + C.STYLE.update(current="B", struck="B", held="B") + g.save(name) + + +if __name__ == "__main__": + frame_marks("15-marks") + frame_none("16-none", False) + frame_subject("17-subject") + frame_none("18-loupes", True, loupes=True) diff --git a/design/mock/list-dbg.txt b/design/mock/list-dbg.txt new file mode 100644 index 0000000..14e8196 --- /dev/null +++ b/design/mock/list-dbg.txt @@ -0,0 +1,178 @@ +# ztrace dbg -o list.ztrace --stack 1024 -- ./list (env -i setarch -R), break at *0x1001926, the second stop; then si. +# moment 2 (stop) and moment 3 (after the load): registers, the stack from rsp, the heap from 0x1004000. +(ztrace) ctx +moment 2 of 3, 49 events so far + +thread 1131036 targets/list.c:21:35 + rax 1004090 + rbx 0 + rcx 10040b0 + rdx 0 + rsi 10040c0 + rdi 1004090 + rbp 7fffffffece0 —▸ 7fffffffed00 —▸ 7fffffffedb0 —▸ 7fffffffee10 ◂— 0 + rsp 7fffffffece0 —▸ 7fffffffed00 —▸ 7fffffffedb0 —▸ 7fffffffee10 ◂— 0 + r8 7ffff7e19ac0 + r9 20 + r10 10 + r11 7ffff7e19ac8 + r12 7fffffffee38 —▸ 7fffffffefea ◂— "./list" + r13 1 + r14 7ffff7ffd000 —▸ 7ffff7ffe3c0 ◂— 0 + r15 10029c0 ◂— 1 + rip 1001926 (reverse+22) + eflags 206 + + 000001001910 test rdi, rdi + 000001001913 je 0x1001935 + 000001001915 push rbp + 000001001916 mov rbp, rsp + 000001001919 xor eax, eax + 00000100191b nop dword ptr [rax + rax] + 000001001920 mov rcx, rax + 000001001923 mov rax, rdi + ► 000001001926 mov rdi, qword ptr [rdi + 8] + 00000100192a mov qword ptr [rax + 8], rcx + 00000100192e test rdi, rdi + 000001001931 jne 0x1001920 + 000001001933 pop rbp + 000001001934 ret + 000001001935 xor eax, eax + 000001001937 ret + + 00:0000│ rsp 7fffffffece0 —▸ 7fffffffed00 —▸ 7fffffffedb0 —▸ 7fffffffee10 ◂— 0 + 01:0008│ 7fffffffece8 —▸ 10018b0 (main+80) + 02:0010│ 7fffffffecf0 ◂— 7ffff7e20de8 + 03:0018│ 7fffffffecf8 ◂— 0 + 04:0020│ 7fffffffed00 —▸ 7fffffffedb0 —▸ 7fffffffee10 ◂— 0 + 05:0028│ 7fffffffed08 ◂— 7ffff7c27781 + 06:0030│ 7fffffffed10 —▸ 7ffff7fe0c60 (ld-linux-x86-64.so.2!22c60) + 07:0038│ 7fffffffed18 —▸ 7fffffffee38 —▸ 7fffffffefea ◂— "./list" + + #0 1001926 reverse+22 + #1 10018b0 main+80 + #2 7ffff7c27781 + #3 7ffff7c278b9 + #4 1001755 _start+37 + +(ztrace) x $rsp 1024 +7fffffffece0 00 ed ff ff ff 7f 00 00 b0 18 00 01 00 00 00 00 ................ +7fffffffecf0 e8 0d e2 f7 ff 7f 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffed00 b0 ed ff ff ff 7f 00 00 81 77 c2 f7 ff 7f 00 00 .........w...... +7fffffffed10 60 0c fe f7 ff 7f 00 00 38 ee ff ff ff 7f 00 00 `.......8....... +7fffffffed20 00 e0 fb f7 01 00 00 00 60 18 00 01 00 00 00 00 ........`....... +7fffffffed30 70 ed ff ff ff 7f 00 00 60 f2 fd f7 ff 7f 00 00 p.......`....... +7fffffffed40 00 00 00 00 00 00 00 00 1c 78 a5 95 fc 35 e3 1f .........x...5.. +7fffffffed50 38 ee ff ff ff 7f 00 00 01 00 00 00 00 00 00 00 8............... +7fffffffed60 00 d0 ff f7 ff 7f 00 00 c0 29 00 01 00 00 00 00 .........)...... +7fffffffed70 1c 78 e5 94 fc 35 e3 1f 1c 78 af a0 87 25 e3 1f .x...5...x...%.. +7fffffffed80 00 00 00 00 ff 7f 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffed90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffeda0 38 ee ff ff ff 7f 00 00 00 fb da b8 c6 f7 f6 15 8............... +7fffffffedb0 10 ee ff ff ff 7f 00 00 b9 78 c2 f7 ff 7f 00 00 .........x...... +7fffffffedc0 48 ee ff ff ff 7f 00 00 c0 29 00 01 00 00 00 00 H........)...... +7fffffffedd0 60 18 00 01 00 00 00 00 48 ee ff ff ff 7f 00 00 `.......H....... +7fffffffede0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffedf0 30 17 00 01 00 00 00 00 30 ee ff ff ff 7f 00 00 0.......0....... +7fffffffee00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffee10 00 00 00 00 00 00 00 00 55 17 00 01 00 00 00 00 ........U....... +7fffffffee20 28 ee ff ff ff 7f 00 00 38 00 00 00 00 00 00 00 (.......8....... +7fffffffee30 01 00 00 00 00 00 00 00 ea ef ff ff ff 7f 00 00 ................ +7fffffffee40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffee50 21 00 00 00 00 00 00 00 00 c0 fb f7 ff 7f 00 00 !............... +7fffffffee60 33 00 00 00 00 00 00 00 30 0e 00 00 00 00 00 00 3.......0....... +7fffffffee70 10 00 00 00 00 00 00 00 ff fb eb bf 00 00 00 00 ................ +7fffffffee80 06 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 ................ +7fffffffee90 11 00 00 00 00 00 00 00 64 00 00 00 00 00 00 00 ........d....... +7fffffffeea0 03 00 00 00 00 00 00 00 40 00 00 01 00 00 00 00 ........@....... +7fffffffeeb0 04 00 00 00 00 00 00 00 38 00 00 00 00 00 00 00 ........8....... +7fffffffeec0 05 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 ................ +7fffffffeed0 07 00 00 00 00 00 00 00 00 e0 fb f7 ff 7f 00 00 ................ +7fffffffeee0 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffeef0 09 00 00 00 00 00 00 00 30 17 00 01 00 00 00 00 ........0....... +7fffffffef00 0b 00 00 00 00 00 00 00 e8 03 00 00 00 00 00 00 ................ +7fffffffef10 0c 00 00 00 00 00 00 00 e8 03 00 00 00 00 00 00 ................ +7fffffffef20 0d 00 00 00 00 00 00 00 e8 03 00 00 00 00 00 00 ................ +7fffffffef30 0e 00 00 00 00 00 00 00 e8 03 00 00 00 00 00 00 ................ +7fffffffef40 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffef50 19 00 00 00 00 00 00 00 c9 ef ff ff ff 7f 00 00 ................ +7fffffffef60 1a 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................ +7fffffffef70 1f 00 00 00 00 00 00 00 f1 ef ff ff ff 7f 00 00 ................ +7fffffffef80 0f 00 00 00 00 00 00 00 d9 ef ff ff ff 7f 00 00 ................ +7fffffffef90 1b 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +7fffffffefa0 1c 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ........@....... +7fffffffefb0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +7fffffffefc0 00 00 00 00 00 00 00 00 00 84 c8 54 0f f6 1f c4 ...........T.... +7fffffffefd0 b2 f5 2b eb c7 65 9e 6d 65 78 38 36 5f 36 34 00 ..+..e.mex86_64. +7fffffffefe0 00 00 00 00 00 00 00 00 00 00 2e 2f 6c 69 73 74 .........../list +7fffffffeff0 00 2e 2f 6c 69 73 74 00 00 00 00 00 00 00 00 00 ../list......... +(ztrace) x 0x1004000 512 +000001004000 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004010 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 $............... +000001004020 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004030 19 00 00 00 00 00 00 00 10 40 00 01 00 00 00 00 .........@...... +000001004040 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004050 10 00 00 00 00 00 00 00 30 40 00 01 00 00 00 00 ........0@...... +000001004060 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004070 09 00 00 00 00 00 00 00 50 40 00 01 00 00 00 00 ........P@...... +000001004080 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004090 04 00 00 00 00 00 00 00 70 40 00 01 00 00 00 00 ........p@...... +0000010040a0 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +0000010040b0 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010040c0 00 00 00 00 00 00 00 00 41 0f 02 00 00 00 00 00 ........A....... +0000010040d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010040e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010040f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +(ztrace) si +[3] step at 100192a reverse+26 (list.c:22) +(ztrace) x 0x1004000 512 +000001004000 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004010 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 $............... +000001004020 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004030 19 00 00 00 00 00 00 00 10 40 00 01 00 00 00 00 .........@...... +000001004040 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004050 10 00 00 00 00 00 00 00 30 40 00 01 00 00 00 00 ........0@...... +000001004060 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004070 09 00 00 00 00 00 00 00 50 40 00 01 00 00 00 00 ........P@...... +000001004080 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +000001004090 04 00 00 00 00 00 00 00 70 40 00 01 00 00 00 00 ........p@...... +0000010040a0 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ........!....... +0000010040b0 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010040c0 00 00 00 00 00 00 00 00 41 0f 02 00 00 00 00 00 ........A....... +0000010040d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010040e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010040f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +000001004190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +0000010041f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +(ztrace) q +list3.ztrace: 4 moments diff --git a/design/mock/list.dis b/design/mock/list.dis new file mode 100644 index 0000000..7cdee2b --- /dev/null +++ b/design/mock/list.dis @@ -0,0 +1,263 @@ +0000000001001730 <_start>: +_start(): + 1001730: endbr64 + 1001734: xor ebp,ebp + 1001736: mov r9,rdx + 1001739: pop rsi + 100173a: mov rdx,rsp + 100173d: and rsp,0xfffffffffffffff0 + 1001741: push rax + 1001742: push rsp + 1001743: xor r8d,r8d + 1001746: xor ecx,ecx + 1001748: lea rdi,[rip+0x111] # 1001860
+ 100174f: call QWORD PTR [rip+0x141b] # 1002b70 <__libc_start_main@GLIBC_2.34> + 1001755: hlt + 1001756: cs nop WORD PTR [rax+rax*1+0x0] + +0000000001001760 <_dl_relocate_static_pie>: +_dl_relocate_static_pie(): + 1001760: endbr64 + 1001764: ret + 1001765: data16 cs nop WORD PTR [rax+rax*1+0x0] + +0000000001001770 <_dl_relocate_static_pie_ifunc>: +_dl_relocate_static_pie_ifunc(): + 1001770: endbr64 + 1001774: ret + 1001775: int3 + 1001776: int3 + 1001777: int3 + 1001778: int3 + 1001779: int3 + 100177a: int3 + 100177b: int3 + 100177c: int3 + 100177d: int3 + 100177e: int3 + 100177f: int3 + +0000000001001780 : +deregister_tm_clones(): + 1001780: mov eax,0x1003bd0 + 1001785: cmp rax,0x1003bd0 + 100178b: je 10017a0 + 100178d: mov rax,QWORD PTR [rip+0x13ec] # 1002b80 <_ITM_deregisterTMCloneTable> + 1001794: test rax,rax + 1001797: je 10017a0 + 1001799: mov edi,0x1003bd0 + 100179e: jmp rax + 10017a0: ret + 10017a1: nop DWORD PTR [rax+0x0] + 10017a5: data16 cs nop WORD PTR [rax+rax*1+0x0] + +00000000010017b0 : +register_tm_clones(): + 10017b0: mov esi,0x1003bd0 + 10017b5: sub rsi,0x1003bd0 + 10017bc: mov rax,rsi + 10017bf: shr rsi,0x3f + 10017c3: sar rax,0x3 + 10017c7: add rsi,rax + 10017ca: sar rsi,1 + 10017cd: je 10017e8 + 10017cf: mov rax,QWORD PTR [rip+0x13b2] # 1002b88 <_ITM_registerTMCloneTable> + 10017d6: test rax,rax + 10017d9: je 10017e8 + 10017db: mov edi,0x1003bd0 + 10017e0: jmp rax + 10017e2: nop WORD PTR [rax+rax*1+0x0] + 10017e8: ret + 10017e9: nop DWORD PTR [rax+0x0] + +00000000010017f0 <__do_global_dtors_aux>: +__do_global_dtors_aux(): + 10017f0: endbr64 + 10017f4: cmp BYTE PTR [rip+0x23d5],0x0 # 1003bd0 + 10017fb: jne 1001810 <__do_global_dtors_aux+0x20> + 10017fd: push rbp + 10017fe: mov rbp,rsp + 1001801: call 1001780 + 1001806: mov BYTE PTR [rip+0x23c3],0x1 # 1003bd0 + 100180d: pop rbp + 100180e: ret + 100180f: nop + 1001810: ret + 1001811: nop DWORD PTR [rax+0x0] + 1001815: data16 cs nop WORD PTR [rax+rax*1+0x0] + +0000000001001820 : +frame_dummy(): + 1001820: endbr64 + 1001824: jmp 10017b0 + 1001826: int3 + 1001827: int3 + 1001828: int3 + 1001829: int3 + 100182a: int3 + 100182b: int3 + 100182c: int3 + 100182d: int3 + 100182e: int3 + 100182f: int3 + +0000000001001830 : +list_done(): +targets/list.c:31 + 1001830: test rdi,rdi + 1001833: je 100184e + 1001835: push rbp + 1001836: mov rbp,rsp + 1001839: xor eax,eax + 100183b: nop DWORD PTR [rax+rax*1+0x0] + 1001840: add rax,QWORD PTR [rdi] + 1001843: mov rdi,QWORD PTR [rdi+0x8] + 1001847: test rdi,rdi + 100184a: jne 1001840 + 100184c: pop rbp +targets/list.c:32 + 100184d: ret + 100184e: xor eax,eax + 1001850: ret + 1001851: data16 data16 data16 data16 data16 cs nop WORD PTR [rax+rax*1+0x0] + +0000000001001860
: +main(): +targets/list.c:35 + 1001860: push rbp + 1001861: mov rbp,rsp + 1001864: push rbx + 1001865: push rax + 1001866: mov eax,0x6 +targets/list.c:36 + 100186b: cmp edi,0x2 + 100186e: jl 1001880 + 1001870: mov rdi,QWORD PTR [rsi+0x8] +atoi(): +/usr/include/stdlib.h:487 + 1001874: xor esi,esi + 1001876: mov edx,0xa + 100187b: call 1001980 +main(): +targets/list.c:38 + 1001880: test eax,eax + 1001882: jle 10018a6 + 1001884: mov ebx,eax + 1001886: xor eax,eax + 1001888: nop DWORD PTR [rax+rax*1+0x0] + 1001890: mov rsi,rbx + 1001893: imul rsi,rbx + 1001897: mov rdi,rax + 100189a: call 10018e0 + 100189f: dec rbx + 10018a2: jg 1001890 + 10018a4: jmp 10018a8 + 10018a6: xor eax,eax +targets/list.c:39 + 10018a8: mov rdi,rax + 10018ab: call 1001910 +targets/list.c:40 + 10018b0: mov rdi,rax + 10018b3: call 1001830 + 10018b8: lea rdi,[rip+0xffffffffffffed35] # 10005f4 <_IO_stdin_used+0x4> + 10018bf: mov rsi,rax + 10018c2: xor eax,eax + 10018c4: call 1001990 +targets/list.c:41 + 10018c9: xor eax,eax + 10018cb: add rsp,0x8 + 10018cf: pop rbx + 10018d0: pop rbp + 10018d1: ret + 10018d2: data16 data16 data16 data16 cs nop WORD PTR [rax+rax*1+0x0] + +00000000010018e0 : +push(): +targets/list.c:11 + 10018e0: push rbp + 10018e1: mov rbp,rsp + 10018e4: push r14 + 10018e6: push rbx + 10018e7: mov rbx,rsi + 10018ea: mov r14,rdi +targets/list.c:12 + 10018ed: mov edi,0x10 + 10018f2: call 10019a0 +targets/list.c:13 + 10018f7: mov QWORD PTR [rax],rbx +targets/list.c:14 + 10018fa: mov QWORD PTR [rax+0x8],r14 +targets/list.c:15 + 10018fe: pop rbx + 10018ff: pop r14 + 1001901: pop rbp + 1001902: ret + 1001903: data16 data16 data16 cs nop WORD PTR [rax+rax*1+0x0] + +0000000001001910 : +reverse(): +targets/list.c:20 + 1001910: test rdi,rdi + 1001913: je 1001935 + 1001915: push rbp + 1001916: mov rbp,rsp + 1001919: xor eax,eax + 100191b: nop DWORD PTR [rax+rax*1+0x0] + 1001920: mov rcx,rax + 1001923: mov rax,rdi +targets/list.c:21 + 1001926: mov rdi,QWORD PTR [rdi+0x8] +targets/list.c:22 + 100192a: mov QWORD PTR [rax+0x8],rcx +targets/list.c:20 + 100192e: test rdi,rdi + 1001931: jne 1001920 + 1001933: pop rbp +targets/list.c:26 + 1001934: ret + 1001935: xor eax,eax + 1001937: ret + +Disassembly of section .init: + +0000000001001938 <_init>: +_init(): + 1001938: endbr64 + 100193c: sub rsp,0x8 + 1001940: mov rax,QWORD PTR [rip+0x1231] # 1002b78 <__gmon_start__> + 1001947: test rax,rax + 100194a: je 100194e <_init+0x16> + 100194c: call rax + 100194e: add rsp,0x8 + 1001952: ret + +Disassembly of section .fini: + +0000000001001954 <_fini>: +_fini(): + 1001954: endbr64 + 1001958: sub rsp,0x8 + 100195c: add rsp,0x8 + 1001960: ret + +Disassembly of section .plt: + +0000000001001970 : + 1001970: push QWORD PTR [rip+0x1222] # 1002b98 <_GLOBAL_OFFSET_TABLE_+0x8> + 1001976: jmp QWORD PTR [rip+0x1224] # 1002ba0 <_GLOBAL_OFFSET_TABLE_+0x10> + 100197c: nop DWORD PTR [rax+0x0] + +0000000001001980 : + 1001980: jmp QWORD PTR [rip+0x1222] # 1002ba8 + 1001986: push 0x0 + 100198b: jmp 1001970 <_fini+0x1c> + +0000000001001990 : + 1001990: jmp QWORD PTR [rip+0x121a] # 1002bb0 + 1001996: push 0x1 + 100199b: jmp 1001970 <_fini+0x1c> + +00000000010019a0 : + 10019a0: jmp QWORD PTR [rip+0x1212] # 1002bb8 + 10019a6: push 0x2 + 10019ab: jmp 1001970 <_fini+0x1c> -- cgit v1.3