Previous: Interactive mode, Up: Running the program


3.3.3 Debugging commands

The interactive mode of mixvm lets you step by step execution of programs as well as breakpoint setting. Use next to step through the program, running its instructions one by one. To run our two-instruction hello.mix sample you can do the following:

     MIX > load hello
     Program loaded. Start address: 3000
     MIX > pc
     Current address: 3000
     MIX > next
     MIXAL HELLO WORLD
     Elapsed time: 1 /Total program time: 1 (Total uptime: 1)
     MIX > pc
     Current address: 3001
     MIX > next
     End of program reached at address 3002
     Elapsed time: 10 /Total program time: 11 (Total uptime: 11)
     MIX > pc
     Current address: 3002
     MIX > next
     MIXAL HELLO WORLD
     Elapsed time: 1 /Total program time: 1 (Total uptime: 12)
     MIX >
     MIX > run
     Running ...
     ... done
     Elapsed time: 10 /Total program time: 11 (Total uptime: 22)
     MIX >

(As an aside, the above sample also shows how the virtual machine handles cummulative time statistics and automatic program restart).

You can set a breakpoint at a given address using the command sbpa (set breakpoint at address). When a breakpoint is set, run will stop before executing the instruction at the given address. Typing run again will resume program execution. Coming back to our hello world example, we would have:

     MIX > sbpa 3001
     Breakpoint set at address 3001
     MIX > run
     Running ...
     MIXAL HELLO WORLD
     ... stopped: breakpoint at line 8 (address 3001)
     Elapsed time: 1 /Total program time: 1 (Total uptime: 23)
     MIX > run
     Running ...
     ... done
     Elapsed time: 10 /Total program time: 11 (Total uptime: 33)
     MIX >

Note that, since we compiled hello.mixal with debug info enabled, the virtual machine is able to tell us the line in the source file corresponding to the breakpoint we are setting. As a matter of fact, you can directly set breakpoints at source code lines using the command sbp LINE_NO, e.g.

     MIX > sbp 4
     Breakpoint set at line 7
     MIX >

sbp sets the breakpoint at the first meaningful source code line; thus, in the above example we have requested a breakpoint at a line which does not correspond to a MIX instruction and the breakpoint is set at the first line containing a real instruction after the given one. To unset breakpoints, use cbpa ADDRESS and cbp LINE_NO, or cabp to remove all currently set breakpoints. You can also set conditional breakpoints, i.e., tell mixvm to interrupt program execution whenever a register, a memory cell, the comparison flag or the overflow toggle change using the commands sbp[rmco] (see Debug commands).

MIXAL lets you define symbolic constants, either using the EQU pseudoinstruction or starting an instruction line with a label (which assigns to the label the value of the current memory address). Each MIXAL program has, therefore, an associated symbol table which you can inspect using the psym command. For our hello world sample, you will obtain the following output:

     MIX > psym
     START:  3000
     TERM:  19
     MSG:  3002
     MIX >

Other useful commands for debugging are strace (which turns on tracing of executed intructions), pbt (which prints a backtrace of executed instructions) and weval (which evaluates w-expressions on the fly). For a complete description of all available MIX commands, See mixvm.