PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV Mobile 26 feature!
  • In this lesson you will learn the following concepts
  • Overview
  • Using the debugger
  • Conclusion
Lesson 3.8. Debugger
In this lesson you will learn the following concepts
  • Overview.
  • Using the debugger.
Lesson duration

Estimated time: 30 mn
Previous LessonTable of contentsNext Lesson
Overview
Let's take a look at the debugger that comes standard with WINDEV, WEBDEV and WINDEV Mobile.
What is the debugger?
The debugger is a powerful tool used to track the execution of a code or application, step by step. It includes many functionalities:
  • Breakpoints,
  • Execution of lines of code step by step,
  • Visualization of variables,
  • Visualization of process hierarchy,
  • Evaluation of expressions and use of auto-stop expressions,
  • Visualization of the content of data file items, etc.
It is very easy to optimize a process or an entire application.
In this lesson, we will use the debugger on the code of the procedures we created in the previous lesson. This will allow us to discover the main functionalities of the debugger.
Using the debugger
  • We will use the debugger on the "WLanguage" project:
    1. If necessary, open the "WLanguage" project that you created in the first lesson (see A project to discover WLanguage in lesson 3.2).
    2. If necessary, open the WLanguage events of the project:
      • Right-click the "P" button next to the open element tabs. The context menu appears.
      • Select "Element code".
      • The code editor displays the different events associated with the project.
  • To start the debugger, we will set a breakpoint and run the project test. A breakpoint sets the line of code at which the debugger is to be started. In the code editor, breakpoints appear as a red dot in the left margin of the desired line of code.
  • Set a breakpoint in the project initialization code:
    1. Click to the left of the first line of code ("gcyAmountInclTax is currency"), or press Ctrl + B.
    2. A red dot appears, representing the breakpoint.
      The debugger will be automatically started when the line preceded by the breakpoint is run.

      Note

      Several methods can be used to start the debugger.
      For more details, see Start modes of the debugger.
  • We will now run the project test:
    1. Click "GO" in the quick access icons.
    2. Once the line of code that has the breakpoint is executed, the debugger starts.
    3. The code editor appears in "Debug" mode. The line of code being executed has a little arrow ( ). A tooltip shows the content of the variables manipulated in the line of code. The "Debugger" pane appears in the lower section of the screen. This pane displays two distinct areas:
      • the call stack: This area allows you to know the hierarchy of the events and processes displayed in the debugger. In our example, we are debugging the "Initializing WLanguage" event.
      • the list of expressions to evaluate. By default, the main variables used in the WLanguage code are displayed in this area. You can add variables to track their evolution (this feature will be presented later). For now, only the gcyAmountInclTax variable is displayed in this area.
We are going to perform some operations in the debugger to discover its capabilities.
  • First of all, we will run the different statements step by step and see the content of the variables:
    1. Press F8 (or click "Step by step" in the ribbon). The line following the current line is automatically run. The values of variables are modified (if necessary) in the "Debugger" pane (displayed at the bottom of the screen).
    2. To execute the CalculateInclTax procedure via the debugger, press F7 (or click "Detailed step by step" in the ribbon).

      Note

      Difference between F7 and F8:
      • F8 executes the lines of code "step by step", but without going into the code of the functions/procedures.
      • F7 executes a more detailed step-by-step process: this mode allows you to go into the code of the procedures/functions and execute the corresponding code step by step.
    3. The code of the CalculateInclTax procedure is displayed.
    4. Press F8: the procedure is executed step by step (line by line).
    5. Press Alt + End ("Exit" option in the ribbon) to exit the procedure.
  • Close the debugger: click the "End test" option in the debugger ribbon.
  • For the following actions in the debugger, we will use a section of WLanguage code that we worked on in the previous lesson.
    1. If necessary, clear the "Initializing" event of the project and copy the following code:
      garrNumbers is array of int
       
      FOR nIndex = 1 TO 100
       
      Trace("Loop | Index value: [%nIndex%]")
       
      IF nIndex = 50 THEN
      Trace("Break condition")
      BREAK
      END
       
      IF IsOdd(nIndex) = False THEN
      Trace("Odd index: go to next iteration")
      CONTINUE
      END
      garrNumbers.Add(nIndex)
      Trace("[%nIndex%] was added to the array")
      END
       
      FOR nIndex = 1 _TO_ garrNumbers.Count
      // Display the index and the corresponding value in the array
      Trace("Index: " + nIndex + " | Value: " + garrNumbers[nIndex])
      END
      Reminder: This code fills an array via a loop by adding only even numbers between 1 and 10.
    2. Set a breakpoint on the first line of code and start the project test.
    3. The debugger starts. We will do some operations to discover the capabilities of the debugger.
  • First, let's see how to execute a set of lines of code directly. You don't have to execute every line of code in the process to be debugged.
    1. Move the cursor to the following line of code:
      IF IsOdd(nIndex) = False THEN
    2. Press F6 (or click "Run until cursor" in the ribbon). All the lines of code between the current line and the line where the cursor is positioned will be executed. The trace window is displayed with the following content:
      Loop | Index value: 1

      Note

      Caution: The trace window can be displayed "behind" the editor.
    3. Press F8 (to execute the lines of code step by step). Since the condition is false, the code of the IF statement is not executed.
  • The debugger also allows you to determine which statement must be executed next. This allows you to "skip" certain lines of code, for example: these lines of code will not be executed.
    1. Move the arrow that marks the current line ( ) to the line of code that contains the "Trace" function in the IF statement. This action defines the next statement. In our example, we "skip" the lines that add elements in the array: no elements will be added.
    2. Set a breakpoint on the following line:
      garrNumbers.Add(nIndex)
      To do so, simply click to the left of the line of code. A red dot appears.
    3. Press F5 to execute the code up to the breakpoint. The trace window now shows:
      Loop | Index value: 1
      Odd index: go to next iteration
      Loop | Index value: 2
      Odd index: go to next iteration
      Loop | Index value: 3
      The tooltip of the variables in the debugger tells us that we are at index 3.
    4. Remove the breakpoint.
  • Now, we will add an expression and track the changes in its value in the "Debugger" pane. This expression can be of any type: variable, function, operation on variables, ... The result of the expression is calculated and displayed. This expression is used to perform a custom debugging. For example, you can watch the content of a variable while it is being used in the application.
    1. Set a breakpoint on the following line:
      FOR nIndex = 1 _TO_ garrNumbers.Count
      To do so, simply click to the left of the line of code. A red dot appears.
    2. Press F5 to execute the code up to the new breakpoint.
    3. Select "nIndex" in the code editor and right click to open the context menu. Select "Add expression to debugger".
    4. The expression is automatically added in the debugger pane at the bottom of the screen. For now, the expression cannot be evaluated because the line of code has not been executed.
    5. Press F8 to execute the code step by step.
    6. The value of nIndex changes to 1.
  • We will use an "Auto-stop" expression. An "Auto-stop" expression is used to start the debugger as soon as a condition evaluates to true or when the value of a variable is modified. In our example, we will start the debugger as soon as the value of nIndex is 10:
    1. In the "Debugger" pane, select the "nIndex" expression that we added earlier.
    2. Click the green dot: it becomes red.
    3. Press F5 to continue the test.
    4. A message is displayed, indicating that the value of the "nIndex" variable has changed.
    5. Validate.
    6. In the "Debugger" pane, select the "nIndex" expression. Click the expression again: the "Expression" column becomes editable. In the "Expression" area, add "=10". You will get "nIndex = 10". Press Enter to validate.
    7. Press F5. The program continues to run. The debugger is started again when the value of the nIndex variable is 10.
  • We will now see the contents of the Array variable. These contents can be viewed in a specific window ("Watch Window").
    1. In the "Debugger" pane, select the "garrNumbers" expression.
    2. Select "Edit" in the context menu. A specific window shows the contents of the variable, i.e., the different values in the array. This window can remain open while the application is debugged.

      Note

      The watch window allows you to view the contents of any type of variables. The information can be shown in text or hexadecimal format.
  • That's it! We have covered the main features of the debugger. To stop the test in the debugger, click "End test" in the ribbon.
Conclusion
In this lesson, you have discovered the main options of the debugger:
  • How to start the debugger,
  • How to execute a project step by step,
  • How to define the following statement,
  • How to create an auto-stop expression.
In the next lesson, we will see how to use OOP.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment