Previous: Command hooks, Up: Hook functions


3.4.4.2 Break hooks

We have seen in the previous section how to associate hooks to command execution, but they are not the whole story. You can also associate hook functions to program interruption, that is, specify functions that should be called every time the execution of a MIX program is stopped due to the presence of a breakpoint, either explicit or conditional. Break hooks take as arguments the line number and memory address at which the break occurred. A simple hook that logs the line and address of the breakpoint could be defined as:

     (define break-hook
       (lambda (line address)
         (display "Breakpoint encountered at line ")
         (display line)
         (display " and address ")
         (display address)
         (newline)))

and installed for explicit and conditional breakpoints using

     (mix-add-break-hook break-hook)
     (mix-add-cond-break-hook break-hook)

after that, every time the virtual machine encounters a breakpoint, break-code shall be evaluated for you1.


Footnotes

[1] You may have noticed that break hooks can be implemented in terms of command hooks associated to mix-run and mix-next. As a matter of fact, they are implemented this way: take a look at the file install_dir/share/mdk/mix-vm-stat.scm if you are curious.