Skip to content

Tools for Morpho

The morpho debugger

Morpho provides a debugger that allows you to pause execution of a program, examine the state of variables and registers, and continue. To enable it run morpho with the -debug command line switch. Note that there is a performance penalty for running with debugging enabled.

You may set hard breakpoints in your codeplaces where morpho will always pauseby inserting an @ symbol. For example:

@
print "Hello World"

will break immediately before executing the print statement. When morpho reaches one of these breakpoints, it enters debugging mode:

---Morpho debugger---
Type '?' or 'h' for help.
Breakpoint in global at line 5 [Instruction 15]
@>

The @> prompt reminds you that you're in the debugger rather than in interactive mode. You can then perform a number of commands to understand the current state of the virtual machine, set additional breakpoints, examine the contents of variables and registers, etc. Most commands have a long form, e.g. "break" or "clear" and a short form "b" or "x" respectively. Debugger commands are largely consistent with those for the gdb tool.

Some of the debugging features require knowledge of how morpho's virtual machine works, which is documented in Chapter [chap:The-Morpho-Virtual].

Debugging commands

Break

The b command sets a breakpoint:

::: list

Break at a given line number.

Break at a given instruction.

Break at a given function.

Break at a given method. :::

Continue

Continues program execution, leaving the debugger.

Disassemble

Displays disassembly for the current line of code.

Garbage collect

Forces a garbage collection.

Clear

Clears a breakpoint. The syntax is the same as for b. Note the abbreviation is x not c.

Info

Info reports on various features of the virtual machine.

::: list

Displays the physical address of the object in register n. [This is primarily useful when debugging morpho itself]

Displays all active breakpoints

Displays the value of all globals

Displays the contents of global n

Displays registers for the current function call

Displays the current stack

Displays a list of valid info commands :::

List

Prints a program listing of the lines around the current execution point.

Print

Prints the value of variables.

::: list

Prints the value of a given symbol

Print all currently visible symbols :::

Set

Prints the value of a variable or register.

::: list

Sets the value of register n to be \<expr>.

Sets the value of variable \<symbol> to be \<expr>. :::

Expressions must be simple constant values.

Quit

Terminates program execution.

Step

Continues execution, but returns to the debugger at the next line.

Trace

Shows the current execution trace, i.e. the list of functions and method calls that the program has made to get to the current point.