Debugging your programs

In this section you will learn how to debug a Magik program.

  1. Start a session in debug mode.
  2. Ensure, that the session is assigned to environment_manager project and as_environment_manager module is loaded to the session.
  3. In Product Explorer view in Magik Development perspective, double-click as_environment_dialog.magik. to open it in the editor.
  4. 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.

    as_environment_dialog.magik editor showing added 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.

  5. Run the program in the console with a command:
  6. 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.

    Debug perspective

  7. In the editor of the Debug perspective, select method as_environment_dialog above the breakpoint, right-click on it and select Inspect.

    Magik editor with selected breakpoint
     line showing context menu
    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.

  8. 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.
  9. 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 (Step Over). Execution will continue to the next line in the same method.

    Variables view

  10. Try other step buttons (Step Into Step Into) to step through the code.  Note the differences in stepping techniques.
  11. Insert additional breakpoint in following line in as_environment_dialog.get_data() method:

    result <<

    and continue execution of the program to the next breakpoint by using Resume (Resume) button or pressing F8

    as_environment_dialog.magik editor showing halt on additional brakepoint

  12. 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.

    Variables view in default mode

    Variables view in logical mode

  13. You can end the debugging session by allowing the program to run to completion, or by terminating it.

Related concepts
Local debugging

Related tasks
Adding breakpoints
Resuming the execution of suspended threads
Running and debugging

Related reference
Debug view
Breakpoints view
Console view
Expressions view
Variables view

Run menu actions