Introduction
Debugging is a stage of algorithm development in which errors can be detected, localized, and eliminated. Studio Pro has its own debugger that allows you to monitor algorithm execution, stop and restart it.
How to debug an algorithm in Studio Pro
Debugging in Studio Pro should be used when you want to find out exactly at what stage of the algorithm's operation errors occur. After the error is localized, you can understand the reasons for it and eliminate them. Below we look through the capabilities of the debugging tool and show some examples.
Concepts
Breakpoint
Breakpoint is the main tool for working with the debugging tool. If you set a breakpoint on some activity, all previous activities will be executed and the execution of the algorithm will stop before the designated breakpoint. Thus, you will be able to capture the current state of the system and analyze the functionality of the algorithm. To set a breakpoint, put the cursor on the desired input port of the desired activity and click the left mouse button.
You can also add or remove a breakpoint by right-clicking on the desired activity on the canvas.
Another way to add a breakpoint is to use the "Toggle breakpoint" option in the "Debug" tab. Before that, you need to select the activity block where you want to add a breakpoint.
After that the port will be highlighted with a green circle, indicating a breakpoint. You can remove a breakpoint by reverse actions: left-click on the port where the breakpoint is set, right-click on the action block and select "Remove breakpoint" option or use "Switch Breakpoint" option. Use the "Remove all breakpoints in file" option in the "Debug" tab to remove all breakpoints from the algorithm.
Debugging process
After setting at least one breakpoint, the "Run debug mode" action appears on the top toolbar. Having started in debug mode, the bot will perform all activities up to the breakpoint.
After that, the debugging tools will appear in the top toolbar.
These symbols (from left to right) denote:
- "Resume" - continue executing the algorithm in debug mode until the next breakpoint. If there are no more breakpoints, the algorithm will be executed to the end and the bot in debug mode will stop.
- "Step over" - execute a step over.
- "Step into" - execute a step into.
- "Step out" - execute a step out.
- "Stop" - stop the execution of the algorithm in debug mode. In this case no further actions will be performed.
Debug mode can also be run directly during the execution of the algorithm. This is useful when executing a large algorithm - you don't have to run the whole algorithm over again in debug mode, you can just set a breakpoint at some action (of course, if the bot hasn't started executing it yet). That way, when the breakpoint is reached, the execution of the algorithm will stop and the debug mode will start.
The "Resume" and "Stop" actions are used to resume or stop the debugging mode generally. The "Step over", "Step into", and "Step out" actions apply directly to activity blocks. They apply to all activities including the Subprogram activity. Let's take a closer look at them:
Step into
If you use a "Step into" with any activity other than the "Subprogram", the bot will simply execute that activity. In the case of a subprogram, a step into will open it and the algorithm will stop, after which you can continue debugging the subprogram activity with all the available debugging tools.
Step over
The "Step over" as well as the "Step into" will simply execute any activity except the "Subprogram". In the case of a subprogram, the "Step over" will execute it completely, without stopping at each activity and without opening the subprogram.
Step out
The "Step out" performs an activity and ends the execution of the algorithm in debug mode in the current subprogram. Thus, if you use the "Step out" inside a subprogram that is not called anywhere else, the bot will stop after using this step. If, however, this activity is not performed in a main subprogram, you will exit the child subprogram after hitting "Step out" and be able to continue working in debug mode in the main subprogram.
By default, Studio Pro will be minimized every time you perform some activity in debug mode, which is necessary to test how the bot works with interfaces (websites or applications). If you are debugging an algorithm that does not require working with interfaces, you can disable the Studio Pro minimization to reduce the algorithm's running time. This can be done in the menu "Settings" → "Execution" → "Debugging settings" → "Do not minimize Studio Pro while debugging".
Debugging example
Let's take a look at an example of debugging the algorithm. Note that in the example below we show only the principle of debugging, there are no errors in this algorithm. In reality, all sorts of errors can occur, and the processing of the algorithm will always have individual aspects.
For a simple demonstration, let's take the algorithm that outputs messages to the Studio Pro console.
Let's put a breakpoint on the "Message output subprogram" activity and run the algorithm in debug mode.
There will be two activities before the breakpoint - we will see two logs in the console.
Let's assume that at this stage we are satisfied with everything. Next, we want to continue with the actions of the "Subprogram". Let's leave the breakpoint at the same place and execute the "Step into".
This will get us inside the subprogram, but the activities in it will not be executed. Let's put a breakpoint on the second activity and press "Resume".
This will execute the activity up to the breakpoint.
Next, perform the "Step out" - to return to the main subprogram.
The last subprogram activity will be executed, and we will return to the main subprogram. Note that the last activity in the algorithm has not yet been executed, we are still in debug mode.
Now you can press "Resume" again to finish the execution of the algorithm with the last activity after the "Subprogram".
Note some features of working with variables:
- If your algorithm contains the Assign value to variable activity, the value of the variable will be set only after the activity is executed in the debug mode.
- The variables will be saved after creation. If you need the variables to be set anew each time you repeat an action during debugging, use the "Clear variables before execution" option.