Debugging your programs
In this section you will learn how to debug a Magik program.
- Start a session in debug mode.
- Ensure, that the session is assigned to environment_manager project and as_environment_manager
module is loaded to the session.
- In Product Explorer view in Magik Development perspective, double-click as_environment_dialog.magik.
to open it in the editor.
- Place your cursor on the vertical ruler along the left edge of the editor, on the
following line in as_environment_dialog.init() method:
_if .menu_items _is _unset
double-click on the ruler to set a breakpoint.

A breakpoint icon indicates the status of a breakpoint. A plain blue breakpoint icon
indicates that a breakpoint has been set, but not yet installed.
Note: Once the file is transmitted to a session, the breakpoint will be installed
and a checkmark symbol will be displayed on the breakpoint icon.
- Run the program in the console with a command:
as_environment_dialog.open()
- The program will execute until the breakpoint is reached. When the breakpoint is
triggered, execution will be suspended and you will be asked, whether to switch to the Debug
perspective. Click Yes. Notice that the process is still active (not terminated)
in the Debug view. Other threads might still be running.

- In the editor of the Debug perspective, select method
as_environment_dialog
above the breakpoint, right-click on it and select Inspect.
Expression is evaluated in the context of the current stack frame, and a pop-up displays the
results. You can send the result to the Expressions view by pressing a key binding displayed at the
bottom of the pop-up.
- You can check the values of the variables in the Variables view. Expand self
tree in the Variables view until you can see menu_items.
- The variables (e.g., menu_items) in the Variables view will change when you step through
the code. To step through the code, click Step Over (
). Execution
will continue to the next line in the same method.

- Try other step buttons (Step Into
) to step
through the code. Note the differences in stepping techniques.
- Insert additional breakpoint in following line in as_environment_dialog.get_data() method:
result << rope.new()
and continue execution of the program to the next breakpoint by using Resume (
) button or pressing F8

-
Try to step several times through the code. Note the changes in result variable.
In the Variables view you can choose to display certain types as logical structures. This action hides
the type's implementation details and simply shows it as arrays or fields. You can define
logical structures by yourself in
Logical Structures preference page.


- You can end the debugging session by allowing the program to run to completion, or by
terminating it.
- You can continue to step over the code with Step buttons until the
program completes.
- You can click Resume (
) button to allow
the program to run until the next breakpoint is encountered or until the program is completed.
- You can select Terminate from the context menu of the program's process
in the Debug view to terminate the program.

Breakpoints
Local debugging

Adding breakpoints
Resuming the execution of suspended threads
Running and debugging

Debug view
Breakpoints view
Console view
Expressions view
Variables view
Run menu actions