Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | 5x 5x 184x 184x 157x 157x 157x 28x 28x 28x 28x 28x 5x 285x 285x 285x 285x 285x 285x 285x 285x 285x 285x 285x 285x 285x 47x 47x 285x 11x 285x 10x 10x 10x 10x 4x 6x 4x 285x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 285x 5x 7x 3x 2x 189x 285x 298x 298x 298x 298x 2997x 494x 671x 495x 1165x 1165x 1165x 1165x 1165x 9477x 1165x 1165x 9399x 9399x 1165x 18876x 18876x 18876x 51048x 18876x 18876x 18876x 18876x 28x 28x 18876x 18876x 18876x 18876x 18876x 18876x 18876x 18876x 15936x 15936x 15936x 15936x 15936x 129x 129x 129x 129x 15807x 195x 195x 195x 195x 195x 195x 18876x 15178x 2x 18876x 758x 18876x 18876x 18876x 42x 18876x 18876x 18876x 9403x 9403x 8x 3x 3x 3x 18887x 18887x 18887x 78x 18887x 2519x 18898x 11x 11x 11x 5x 11x 11x 6x | import { byteChar, hexbyte, hexword } from "../hex.js";
import { nameUrl } from "../symbol-sets.js";
import { SidewaysEnd, SidewaysStart, viewedBank } from "../paging.js";
import { machineSheilaBlocks, sheilaName } from "../sheila.js";
import { bindGotoForm, externalLink, FittedRows, labelHtml } from "./debug-dom.js";
import { keyLine } from "./panel-keys.js";
const InitialRows = 16;
const WheelPixelsPerInstruction = 30;
function nameTitle({ name, set }, addr) {
const url = nameUrl(set, name, addr);
return `${name}: $${hexword(addr)}, from ${set.title}${url ? `\nDefined at ${url}` : ""}`;
}
function showName(node, named, addr) {
node.classList.add("named");
node.textContent = named.name;
node.title = nameTitle(named, addr);
}
function nameNode(named, addr) {
const url = nameUrl(named.set, named.name, addr);
const node = url ? externalLink(url, "") : document.createElement("span");
node.classList.add("symbol");
showName(node, named, addr);
return node;
}
/** The disassembly panel's keys; see panel-keys.js for the shape. */
export const DisassemblyKeys = [
{
combo: "c",
key: "c",
run: "runToCursor",
label: "run to cursor",
description: "Run to the highlighted instruction",
},
{
combo: "t",
key: "t",
run: "toggleBreakpoint",
label: "breakpoint",
description: "Set or clear a breakpoint on the highlighted instruction",
},
{ combo: "j k", label: "move", description: "Move the highlight down or up" },
{ key: "j", run: "down" },
{ key: "k", run: "up" },
{ combo: "b", key: "b", run: "back", label: "back", description: "Back after clicking a jump target" },
];
/**
* The disassembly panel: the instructions around a cursor, named from the symbol sets, with the breakpoints set on
* them. Its keys move the cursor, follow and come back from jumps, and set breakpoints; running the machine is the
* debugger's, which it asks for through `runToCursor`.
*/
export class DisassemblyView {
/**
* @param {object} options
* @param {import("./floating-panel.js").FloatingPanel} options.floating - its panel, whose keys answer while open
* @param {import("./panel-keys.js").PanelKeys} options.keys
* @param {import("./paging-override.js").PagingOverride} options.paging - what it reads memory through
* @param {() => import("../symbol-names.js").SymbolNames} options.names - the names matched to memory now
* @param {(text: string) => {address: number, view: string} | undefined} options.resolve - the address a "Go to"
* text names, and the view to show it in
* @param {(sets: Set<import("../symbol-names.js").SymbolSet>) => void} options.showing - the sets whose names it
* shows
* @param {(address: number) => void} options.showMemory - follows a memory operand
* @param {(event: MouseEvent, address: number, name: string | undefined) => void} options.offerWatch - offers a
* right-clicked address as a watch
* @param {() => void} options.runToCursor
* @param {() => void} options.refit - redraws it, once its rows have changed in number
*/
constructor({ floating, keys, paging, names, resolve, showing, showMemory, offerWatch, runToCursor, refit }) {
this._paging = paging;
this._names = names;
this._showing = showing;
this._showMemory = showMemory;
this._cpu = null;
this._sheila = [];
this._cursor = 0;
this._cursorRow = Math.floor(InitialRows / 2);
this._backStack = [];
this._unwatchBreakpoints = null;
this._widget = floating.panel.querySelector("#disassembly");
this._rows = new FittedRows(this._widget, InitialRows, refit);
bindGotoForm(floating.panel.querySelector(".goto-form"), resolve, ({ address, view }) => {
this._paging.view = view;
this.update(address);
});
this._widget.addEventListener("click", (e) => {
if (e.target.closest(".bp_gutter")) this._gutterClick(e);
});
this._widget.addEventListener("contextmenu", (e) => {
const at = Number(e.target.closest(".dis_elem")?.dataset.addr);
const operand = e.target.closest(".instr_mem_ref, .instr_instr_ref");
const named = (address, name) => offerWatch(e, address, this._paging.differs(address) ? undefined : name);
if (operand) {
named(Number(operand.dataset.ref), operand.dataset.name);
} else if (e.target.closest(".dis_addr")) {
named(at, this._names().address(at, this._cpu.pc)?.name);
}
});
this._widget.addEventListener("wheel", (evt) => {
let deltaY = evt.deltaY;
Iif (deltaY === 0) return;
let addr = this._cursor;
const func = deltaY < 0 ? this._prevInstruction.bind(this) : this._nextInstruction.bind(this);
deltaY = Math.abs(deltaY);
while (deltaY > 0) {
addr = func(addr);
deltaY -= WheelPixelsPerInstruction;
}
this.update(addr);
evt.preventDefault();
});
keys.register({
table: DisassemblyKeys,
actions: {
runToCursor,
toggleBreakpoint: () => this._toggleBreakpoint(this._cursor),
down: () => this.update(this._nextInstruction(this._cursor)),
up: () => this.update(this._prevInstruction(this._cursor)),
back: () => {
if (this._backStack.length) this.update(this._backStack.pop());
},
},
isLive: () => floating.isOpen,
panel: floating,
});
floating.panel.querySelector(".panel-keys").textContent = keyLine(DisassemblyKeys);
}
setCpu(cpu) {
this._cpu = cpu;
this._unwatchBreakpoints?.();
this._unwatchBreakpoints = cpu.breakpoints.onChange(() => this.redraw());
this._sheila = machineSheilaBlocks(cpu);
}
/** The highlighted instruction's address. */
get cursor() {
return this._cursor;
}
/** Shows the instructions around `address`, highlighting it in the middle row. */
update(address) {
this._draw(address, this._middleRow());
}
/** Shows the highlighted instruction again in the row it is in, or the middle row if that row has gone. */
redraw() {
this._draw(this._cursor, this._cursorRow < this._rows.rows.length ? this._cursorRow : this._middleRow());
}
_middleRow() {
return Math.floor(this._rows.rows.length / 2);
}
_draw(address, cursorRow) {
this._cursor = address;
this._cursorRow = cursorRow;
const { rows } = this._rows;
const shown = new Set();
for (let i = cursorRow; i < rows.length; ++i) {
address = this._showRow(rows[i], address, shown);
}
address = this._cursor;
for (let i = cursorRow - 1; i >= 0; --i) {
address = this._prevInstruction(address);
this._showRow(rows[i], address, shown);
}
this._showing(shown);
}
/** Shows the instruction at `address` in `row`, adding the sets it names to `shown`; returns the next's address. */
_showRow(row, address, shown) {
const cpu = this._cpu;
const names = this._names();
const [text, end] = this._paging.disassembler.disassemble(address);
const bytes = Array.from({ length: end - address }, (_, i) => this._paging.peek(address + i));
const addrNode = row.querySelector(".dis_addr");
addrNode.innerHTML = labelHtml(address);
const named = names.address(address, cpu.pc);
if (named) {
addrNode.append(" ", nameNode(named, address));
shown.add(named.set);
}
row.classList.toggle("current", address === cpu.pc && !this._paging.differs(address));
row.classList.toggle("highlight", address === this._cursor);
row.querySelector(".instr_bytes").textContent = bytes.map(hexbyte).join(" ");
row.querySelector(".instr_asc").textContent = bytes.map(byteChar).join("");
const disNode = row.querySelector(".disassembly");
disNode.innerHTML = text;
const { accesses } = cpu.disassembler.describeOpcode(cpu.peekmem(address));
for (const ref of disNode.querySelectorAll(".instr_mem_ref, .instr_instr_ref")) {
const target = parseInt(ref.dataset.ref, 10);
const operand = names.operand(address, target);
const register = ref.classList.contains("instr_mem_ref")
? sheilaName(this._sheila, target, accesses)
: undefined;
// A register's name displaces a MOS's name for it, but not a program's, which says what it is for.
const inline = register && operand?.set.system ? undefined : operand;
if (inline) {
showName(ref, inline, target);
if (register) ref.title += `\n${register.title}`;
shown.add(inline.set);
ref.dataset.name = inline.name;
} else if (register) {
const note = document.createElement("span");
note.className = "note";
note.textContent = ` ; ${register.name}`;
note.title = operand ? `${register.title}\n${nameTitle(operand, target)}` : register.title;
disNode.append(note);
ref.dataset.name = register.name;
}
}
for (const ref of disNode.querySelectorAll(".instr_mem_ref")) {
ref.addEventListener("click", (e) =>
this._showMemory(parseInt(e.target.closest("[data-ref]").dataset.ref, 10)),
);
}
for (const ref of disNode.querySelectorAll(".instr_instr_ref")) {
ref.addEventListener("click", (e) => this._followJump(e));
}
const executes = this._executeBreakpoints(address);
const gutter = row.querySelector(".bp_gutter");
gutter.classList.toggle(
"active",
executes.some((bp) => bp.enabled),
);
gutter.classList.toggle("disabled", executes.length > 0 && !executes.some((bp) => bp.enabled));
row.dataset.addr = address;
return end & 0xffff;
}
_prevInstruction(address) {
// The program counter steers the walk back only where the view shows the code it is running.
const { pc } = this._cpu;
return this._paging.disassembler.prevInstruction(address, this._paging.differs(pc) ? undefined : pc);
}
_nextInstruction(address) {
return this._paging.disassembler.nextInstruction(address);
}
_followJump(e) {
const ref = parseInt(e.target.closest("[data-ref]").dataset.ref, 10);
this._backStack.push(this._cursor);
this.update(ref);
}
/**
* The execute breakpoints on the code the row at `address` shows: unpinned, pinned to the bank the panel is set to
* show there, or anywhere it is not set to a bank, pinned to a bank the CPU would stop in there now.
*/
_executeBreakpoints(address) {
const cpu = this._cpu;
const viewed = this._viewedBankAt(address);
const applies = (bank) =>
bank === undefined || (viewed === undefined ? cpu.isBankPagedAt(bank, address) : bank === viewed);
return cpu.breakpoints
.list()
.filter((bp) => bp.kind === "execute" && bp.start <= address && address <= bp.end && applies(bp.bank));
}
/** The sideways bank the panel is set to show at `address`, if it is set to show one there. */
_viewedBankAt(address) {
return address >= SidewaysStart && address < SidewaysEnd ? viewedBank(this._paging.view) : undefined;
}
/**
* Removes the plain breakpoints on just `address`, or with none there, sets one: pinned to the bank shown, when the
* panel is set to show one, so that it stops in the code shown. One with a condition, a hit count or logging is
* left for the Breakpoints panel or the console to change.
*/
_toggleBreakpoint(address) {
const { breakpoints } = this._cpu;
const pin = this._viewedBankAt(address);
const onAddress = this._executeBreakpoints(address).filter(
(bp) =>
bp.start === bp.end &&
bp.owner === "user" &&
bp.condition === undefined &&
bp.hitCount === 1 &&
bp.action === "stop",
);
if (!onAddress.length) breakpoints.add({ kind: "execute", start: address, bank: pin });
for (const { id } of onAddress) breakpoints.remove(id);
}
_gutterClick(e) {
this._toggleBreakpoint(parseInt(e.target.closest(".dis_elem").dataset.addr, 10));
}
}
|