26.8. Python Debugger

MATE comes with an integrated Python debugger. Its symbols and basic functions resemble those of Visual Studio. Depending on the operating system, the available key commands are taken from Visual Studio (Windows/Linux) and XCode (Mac OS X).

Debugging can be used for .py Python files and for .script files. In case of the latter, only lines with real Python code (i.e. starting with "py: or "*py:) will work as breakpoints.

There are two main ways to open code in the MATE-integrated debugger:

When debugging is enabled, the views Debug Output, Breakpoints, Stack Frames, Variables, and the Debugging toolbar are switched on in standard configuration.

[Note]Note

Configuration changes made by the user will be saved separately for MATE without debugging and for MATE with debugging enabled. This way, two basic configurations are available.

Figure 26.17. MATE with Python Debugger

MATE with Python Debugger

Figure 26.18. MATE Debug Menu

MATE Debug Menu

Once the debugging is enabled in principle, the actual process needs to get started. For a first test, the module TestPython can be used.

  1. In a line with executable code, click between line number and code to set a breakpoint. A red dot will be displayed at that position.

    Breakpoints offer context menus.

    Breakpoints can be set to conditional; this condition can also be removed. Conditions have to be entered in Python syntax, for example: a==12.

  2. In a next step, do something on the module's panel in MeVisLab, e.g., click a button.

    [Note]Note

    It is important to remember that the Python scripts in MeVisLab are part of a module or network, and not stand-alone. Therefore, you cannot simply open a script in the MATE debugger and debug it at runtime. What looks like a Start button is actually a Continue button.

    [Note]Note

    During the debugging, MeVisLab is unresponsive! Finish the debugging by letting it run its course before trying to interact with MeVisLab.

    [Note]Note

    The debugger needs an up-to-date .pyc file for associating the run-time state with the lines in the .py file. The debugger will not work (correctly) if you have multiple .pyc copies of one Python file on your system!

    The script stops at the breakpoint, showing a yellow arrow. The Debug Output is the same as in MeVisLab. In the Breakpoints view a list of all breakpoints can be found, and a context menu is available for editing them. The Stack Frames view shows where the script currently is. In the Variables view, existing variables can be examined.

  3. Click the Continue button to run to the next breakpoint, or other buttons for other actions.

Table 26.1. Buttons for Debugging

ButtonDescriptionExplanation
BreakPauses the running function.
StopStops and finishes the running function.
ContinueRuns to the next breakpoint or the end of the routine.
Run to cursorRuns to line where the cursor is placed.
Step InStep through the code one statement a time. If the statement executes another function, the debugger will step into that function.
Step OverStep Over is the same as Step In, except that when it reaches a call for another function, it will not step into it. The function will run, and then go to the next statement in the current function.
Step OutIf Step In has been used, Step Out can be used to run the currently called function and return to the function it was called from.

Table 26.2. Icons for Debugging

IconDescriptionExplanation
BreakpointStatic breakpoint set by user.
Conditional breakpointBreakpoint depending on a statement to be true. The condition (in Python syntax) can be set via the context menu of a breakpoint.
Top stack locationLast executed statement.
Current stack locationDisplayed via double-clicking the stacks in the Stack Frames view.