- iDigi Dia Home
- User
  - Getting Started
  - Dia Concepts
  - Devices
  - Loggers
  - Presentations
  - Services
  - Tracing
- Developer
  - Overview
  - Drivers
  - Loggers
  - Presentations
  - Services
  - Integrating Application
  - Tracing Manager
  - Debugging
  - Specific Considerations
  - API Reference

- Email
- Phone
- Contact us:

### Navigation

- index
- next |
- previous |
- iDigi Dia |
- Developer Documentation »
- Dia Debugging Topics »

# Debugging Applications Using Digi ESP for Python

## Debug Basics

This document will serve as a brief introduction to debugging Python Applications remotely using the Digi ESP for Python. The ESP help pages also include a debugging document with images of the interface that may serve as a useful additional reference. Debugging an application remotely means that the IDE can control the execution of the application on the remote device and retrieve information about its state. Before performing a remote debugging you will need to set the following configurations:

- A Device Configuration should be linked to the project.
- A Debug Configuration must be created, where options to debug the application are set.

## Debug configuration

To create a new Digi Python Debug Configuration, from the menu, select Run > Debug Configurations. In the Debug wizard, select Remote Digi Python Application inside the Configurations tree, and select New. This debug configurations wizard can also be accessed by clicking on the debug button on the ESP toolbar.

The new Remote Debugging Configuration contains a Name text box and two tabs. Change the name of this Debug Configuration.

The Remote Debugging Configuration parameters are organized on two tabs: Main and Common tabs.

The Main tab parameters are organized on blocks.

- Project: The project associated with this remote debugging configuration. You can change it by clicking on the Browse button and selecting your desired project from the new dialog.
- Main Module: This is only an information field that will display the selected projects Main Module File.
- Advanced Settings: The advanced settings in Eclipse allow access to more advanced configuration settings for the currently selected project type. For the ESP’s Python Application Project there will only be one advanced setting to configure: Upload project resources to the target before launch. It specifies the possibility to transfer the resources folder contents to the remote device before launching (debugging) the application. It is useful in the case your application needs to use specific resources like images, text files, etc.
- Debug Settings: This property gives the user the possibility to always stop at the beginning of the application, never or ask when starting the debugging process.
- Name, Project, and main module file configuration fields will be automatically filled when a project is selected before creating a new Debug Configuration.
- Arguments tab allows to specify text arguments to be given to the Python application when launching it. We will leave it blank.
- The Common tab specifies the location where the Debug Configuration will be stored and how to access it. Accept the default values.

Click Apply to save the Debug Configuration. Once it is saved, click the Debug button in order to start the Debug Process.

## Start Remote Debugging process

The debug process will begin by attempting to verify compatibility between the remote device and the debugging process. If any incompatibility is found, an error will be displayed. Some common errors are listed below:

- Configuration incompatibility: iDigi configurations don’t support the remote debugging feature. Only configurations with local (LAN) devices are supported.
- Device incompatibility: At present, ConnectPort X3 device doesn’t support the remote debugging.
- Firmware incompatibility: In order to perform a remote debugging with your device it is necessary that you update it to the latest firmware.

If no error were found, the debug process will proceed, and you will be presented with the Remote Debugging window. Depending on the Debug Configuration settings, you may be prompted by the environment to stop at the beginning of the application. If you select yes, a new breakpoint will be added automatically to the first line of code.

While the perspective is being changed, the IDE will transfer the files to the remote device like in the Launch process, but this time it will also include a new zip file containing the necessary modules for the debug process. These files are located in the build/debug folder of the project.

After transferring all the files to the remote device, a reboot will be performed in order to make the device able to access these files.

After the application starts, it will be stopped at first line of code if you set it that way in the Debug configuration.

## Remote Debugging perspective

When the debugging process starts, the perspective is automatically changed to the Remote Debugging perspective. The Remote Debugging perspective permits access to several new tools and views including Debug Navigation, Breakpoints, and Variables. Here is a little explanation of the new views appeared with this perspective:

- Debug view: Contains the debug sessions and their thread executions. When a breakpoint is reached it is possible to navigate between the files that made the call from this view.
- Breakpoints view: This view shows the list of breakpoints added to the debugging session. Each breakpoint displays the file and line where it is located.
- Variables view: Contains all the variables of the Python application that is being debugged. Changing between files or threads from the Debug view will repopulate the list of variables to correspond with the new focus.
- Expressions view: Lets the user view and add variables and expressions.

This perspective also includes the editor where the files will be opened when a breakpoint is reached, the Process view to check the status of the debugging process and the Terminal view which prints the data reported by the remote application.

## Breakpoints

Breakpoints pause execution of code so that the environment can be examined at a particular point. Breakpoints are set by line of code and can be established before or even during execution.

Breakpoints can be added to a project by opening the pertinent python document and double clicking on the left margin or by right clicking anywhere on the line and selecting the add breakpoint option. A green marker will indicate that the line contains a breakpoint, and the breakpoint will be added to the Breakpoints view.

A breakpoint can be set to execute only under certain specific conditions. Right-click on a breakpoint and select Breakpoint Properties. By clicking the Enable checkbox and providing a conditional expression, you can allow breakpoints to trigger under only interesting circumstances and avoid having to slog through breakpoints when the program is acting properly. Conditional statements should be written in python.

A breakpoint can also be disables without removing it completely from the Breakpoints view by deselecting the checkbox next to it or from the editor view by right-clicking and selecing disable from the drop down menu. A disabled breakpoint will show up as a grey dot in the left margin instead of a green one.

Removing a breakpoint follows the same prodedure that inserting one did. A double-click on the left-margin or a right-click remove will delete a breakpoint entirely. The Breakpoints view also provides this functionality.

## Debug view

The Debug view shows debugging and remote process information. If the Stop at startup option was checked on the Debug Configuration settings, when the debug process starts, the application is automatically suspended at the first line of code. The Editor view marks the line where the application is suspended with a small arrow and highlights it.

The Debug view toolbar has several buttons for controlling the debug session:

- Resume: Resumes execution of the code until it reaches the next breakpoint.
- Suspend: Stops execution of the program at the moment the suspend button is pushed. This is not an accurate way of stopping on a particular line. Use breakpoints for that instead.
- Terminate: Stops the debugging process killing the aplication.
- Disconnect: Stops the debugging process. The Python application will continue to execute until its termination, but it will no longer halt at breakpoints.
- Step Into: Steps into a statement.
- Step Over: Executes one instruction. If it is a method call or class definition it won’t go into the corresponding code.
- Step Return: Returns from a statement.

To continue with the debug session until the conditional breakpoint, click Resume. When the process is suspended at the breakpoint, the Debug view shows several stack frames instances with the stack frame number, the function name where the debug session is suspended, the source file name, and the line number. Use the Step Over button to execute the code step-by-step, and Step Into to go into a statement.

## Variables view

The Variables view displays the values of the variables in the current execution context. This allows the changes in variables values between breakpoints to be observed directly. A variables value can also be changed from this view by right-clicking on it and substituting a new value in the dialogue box.

## Expressions view

The expressions view allows combinations or functions of variables to be displayed along with their actual functions. To create a new expression select the “Add a new watch expression” button from the toolbar. Enter your expression in terms of available variable names, arithmetic operators, and numeric values. The new expression will be added to the list of displayed expressions.

## Shortcuts

To debug a Digi Python Application without going through the Debug Configurations Dialog, you can create a default debug configuration or execute the application using the most recent Debug Configuration.

If a debug configuration for a project has not been created yet, then a default Remote Digi Python Application can be created to fill in most of the default values. You can debug your application as a Remote Digi Python Application by selecting Debug as from the Debug Menu and choosing Remote Digi Python Application. This will then be selected as the default debugging configuration for your project.

You can also launch a project from the Pydev Package Explorer view by right clicking the project in question, selecting Debug as and then choosing Remote Python Application Project. This will launch a debug configuration using default values for the current selected project and device configuration.

Selecting Debug from the Run menu or clicking the Debug button on the main toolbar will open the Debug perspective and launch the application using the most recent debug settings. This will save you time when debugging the same application multiple times.

### Navigation

- index
- next |
- previous |
- iDigi Dia |
- Developer Documentation »
- Dia Debugging Topics »