Debugging Your Code with Script Debugger

Desktop Studio helps you to test and troubleshoot your project. You can set breakpoints in your code to enable step-by-step execution, view the values of local and watch variables, and execute code on the fly.

Start a Project in Debug Mode

A project can be started in two different ways:

  • From Desktop Studio

  • Via a shortcut

Start via a Shortcut

This is the standard way to launch an application in Production.

The shortcut generated by Desktop Studio (at export time) starts the Engine in Release mode.

Alternatively, it can be started in Debug mode by adding the command line argument: -t 512 to the shortcut arguments (see the Installation Guide for details of command line options).

If the project is started in Debug mode via a shortcut, Desktop Studio is not required. In this case, however, interaction with Desktop Studio is disabled. Debugging will then be performed via the Control Pane.

Start from Desktop Studio

To start a project via Desktop Studio, you can use one of the following commands from the Main menu or from the Debugger toolbar:

Run

Starts the project in Release mode (without debugger)

Debug

Starts the project in Debug mode

Debug in Export mode

Starts the project from the Export result in Debug mode

Working Directory

The working directory is mandatory to launch the project in Release or Debug mode. This working directory must be write-enabled in order to host the log files. If the working directory is missing, the launch of Desktop Agent will fail.

By default, Desktop Studio sets the working directory in the folder containing the project file.

If the project file is opened from a Web URL or if it is located in a read-only directory, Desktop Studio uses a temporary working directory. For example: C:\Users\<user login>\AppData\Local\Temp\

Manage Debug Options

You can manage debug options when starting a project in debug mode. To do so, choose Start of the navigation pathDebug Next navigation step Manage Debugging OptionsEnd of the navigation path from the main menu or debugger toolbar.

The Manage Debugging Options dialog is displayed.

The Debugger tab lets you choose the Debugger that will be used:

This dialog also lets you specify whether you wish to automatically minimize Desktop Studio when running.

The Trace options tab lets you choose the trace level:

  • Trace level for the log files:

    • Trace events

    • Detailed tracking of orders

    • Simplified tracking of orders

    • Tracking of the context data

    • Tracking of the “Extend Pilots”

    • Trace objects

    • Trace all Event Win

    • Trace messages (MESSBOX)

  • Trace level for the framework:

    • Log framework trace in file

    • Capture screenshots

The Technical options tab lets you choose the technical trace level.

A technical trace provides information from Desktop Studio connectors.

Step-By-Step Execution

Desktop Studio supports step-by-step execution. This enables code to be executed line by line.

To enter step-by-step execution, execution must break on a breakpoint.

Manage Breakpoints

Breakpoints are set or removed on a script or XML block line in the Code Editor using the Toggle Breakpoint command from the Main menu or from the Debugger toolbar:

  • If a breakpoint already exists on this line, it is removed.

  • Otherwise, it is set.

When a breakpoint is set, the icon is set in the margin and the line is highlighted in red:

The Breakpoint tool window in the Editor Perspective displays a list of breakpoints that have already been set.

Right-click to:

  • Navigate to the selected breakpoint

  • Delete the selected breakpoint

  • Delete all breakpoints

Step-by-Step Debugging in the Code Editor

When a breakpoint is reached:

  • Execution is suspended.

  • The script or XML block containing the line with the break is automatically brought to the front.

  • A indicator is set in the Indicator Margin and the Running line is highlighted in yellow:

  • The Call Stack, Locals, and Watch tool windows are refreshed.

To resume execution, use one of the following commands from the Main menu or the Debugger toolbar:

Debug Commands

Resume

F5

Continue execution until another breakpoint is reached

Toggle Breakpoint

F9

Toggle a breakpoint on the current line

Step into

F11

If we are on a line containing a method call, this command will enter the method and break again on the first line of code inside the method. Use Step Into to see what happens inside a method call

Step over

F10

Executes the entire method call and break on the next line of code in the current method. Use Step Over to execute the entire method and continue in the current code block

Step out

SHIFT + F11

Executes the rest of the current method and return to the calling method. Execution will break at the return point in the calling function

Run and Break

SHIFT + F10

Continue execution up until another line of your code is executed. This command is particularly useful to break execution when a callback function is called

Break All

It is possible to break execution even if no breakpoint is reached. To do this, use the Break all command from the Main menu or from the Debugger toolbar:

Break all

Breaks execution on the next executed line.

This command is particularly useful when you want to find out what code is currently being executed (in other words, in infinite loops).

Manage Watches

The Watches tool window in the Editor perspective displays a list of watched variables.

A line is displayed for each variable. It shows the following information:

  • The variable name

  • The variable value

  • The variable type (Integer, Boolean, String, Object, Array, and so forth).

The value and type data are only filled when the project is running in debug mode and when execution is halted at a break.

Each variable line is preceded by an indicator that shows its type:

Simple Variable

Object or Array

Properties or Method

Undefined

By right-clicking the desired value, you can :

  • Delete a watch

  • Copy the variable value to the clipboard

To add a watch to the Watch tool window:

  • Select the code block to watch in the Code Editor

  • Right-click the selected code block

  • Select the Add Watch command

View Local Variables

The Locals tool window in the Editor perspective automatically displays a list of variables local to the current execution context.

It is only filled when the project is run in Debug mode and when execution halts at a break.

A line is displayed for each variable. It shows the following information:

  • The name

  • The value

  • The type (Integer, Boolean, String, Object, Array, and so forth)

Each variable line is preceded by an indicator that shows its type:

Simple Variable

Object or Array

Properties or Method

Undefined

Right-click the desired value to:

  • Add a variable to the watches

  • Copy the variable value to the clipboard

Use the Call Stack

When execution halts on a break, the Call Stack tool window in the Editor perspective displays the call stack. The call stack is the set of nested function calls that are currently running and waiting to return.

The Call Stack window displays the name of each function:

  • The line number where the call occurs

  • The function name (if known)

  • The script file containing the function.

By double-clicking a function’s line, you can navigate to the corresponding line in the script file.