Exercise 5.19: Alyssa P. Hacker wants a
breakpoint feature in the simulator to help her debug her machine
designs. You have been hired to install this feature for her. She wants to be
able to specify a place in the controller sequence where the simulator will
stop and allow her to examine the state of the machine. You are to implement a
procedure
(set-breakpoint ⟨machine⟩ ⟨label⟩ ⟨n⟩)
that sets a breakpoint just before the n
th instruction after the given
label. For example,
(set-breakpoint gcd-machine 'test-b 4)
installs a breakpoint in gcd-machine just before the assignment to
register a. When the simulator reaches the breakpoint it should print
the label and the offset of the breakpoint and stop executing instructions.
Alyssa can then use get-register-contents and
set-register-contents! to manipulate the state of the simulated machine.
She should then be able to continue execution by saying
(proceed-machine ⟨machine⟩)
She should also be able to remove a specific breakpoint by means of
(cancel-breakpoint ⟨machine⟩ ⟨label⟩ ⟨n⟩)
or to remove all breakpoints by means of
(cancel-all-breakpoints ⟨machine⟩)
练习 5.19:Alyssa P. Hacker 希望在模拟器中加入断点功能,以帮助她调试机器设计。你受雇为她安装这一功能。她希望能够在控制器序列中指定一个位置,使模拟器在该处停止并允许她检查机器状态。你需要实现一个过程:
(set-breakpoint ⟨machine⟩ ⟨label⟩ ⟨n⟩)
该过程在给定标号之后第 n 条指令的前面设置一个断点。例如:
(set-breakpoint gcd-machine 'test-b 4)
在 gcd-machine 中、寄存器 a 被赋值之前设置断点。模拟器到达断点时应打印标号和断点的偏移量,并停止执行指令。随后,Alyssa 可以用 get-register-contents 和 set-register-contents! 来查看和修改被模拟机器的状态。此后她应能通过以下方式继续执行:
(proceed-machine ⟨machine⟩)
她还应能通过以下方式删除某个断点:
(cancel-breakpoint ⟨machine⟩ ⟨label⟩ ⟨n⟩)
或通过以下方式删除所有断点:
(cancel-all-breakpoints ⟨machine⟩)
(set-breakpoint ⟨machine⟩ ⟨label⟩ ⟨n⟩) (set-breakpoint gcd-machine 'test-b 4) (proceed-machine ⟨machine⟩) (cancel-breakpoint ⟨machine⟩ ⟨label⟩ ⟨n⟩) (cancel-all-breakpoints ⟨machine⟩)