NetLogic debugging

Introduction

This module describes some basic procedures to identify, investigate and correct any problems in the NetLogic code using Microsoft Visual Studio or Visual Studio Code locally. For remote debugging see Runtime NetLogic remote debugging

Note

the example screens refer to Visual Studio, set in English.

NetLogic errors are reported at runtime in the Q Studio log panel. In particular, the errors of runtime NetLogics are reported in the tab of the target on which the application is run (for example Emulator Output), the errors of design time NetLogics are reported in the Q Studio Output tab.

To install Visual Studio or Visual Studio Code, or for references on all related debugging features, please refer to the Microsoft website.

Prerequisites

The project must be running for runtime NetLogic debugging. Typically, for debugging purposes the project runs on the Emulator target.

For debugging with Visual Studio Code, the Microsoft C# extension must be installed (available at this link). It is also recommended that the vscode-solution-explorer extension (available at this link) be installed to navigate in the project folder in a similar way to Visual Studio.

Procedure macro

  1. Set the debugging.

  2. Start the debugging.

  3. Change the code after debugging.

  4. Start debugging after a code change.

Set the debugging

  1. Click image1: the C# project opens in Visual Studio or Visual Studio Code, depending on the default editor (see Set the predefined code editor).

  2. (Only for runtime NetLogic debugging) In Q Studio click image2 to compile and run the Q Application.

  3. Set the debugging:

    If using…

    Then…

    Visual Studio

    1. In the Debug menu click Attach to Process: a window appears showing all the processes running on the machine.

    2. In Attach to click Select, select Managed (v4.6, v4.5, v4.0) and click OK.

    3. In Available Process select the QRuntime.exe process for runtime NetLogic debugging or QStudio.exe for design time NetLogic debugging.

    4. Click Attach: debug mode is started and the bottom bar turns orange.

    5. Insert one or more breakpoints (see Use the breakpoints), to indicate the lines of code where the execution stops to allow the user to check their status, the contents of variables etc.

    Visual Studio Code

    1. Open the Run view (CTRL+MAIUSC+D).

    2. In the RUN drop-down menu select Attach to QRuntime for runtime NetLogic debugging or Attach to QStudio for design time NetLogic debugging.

Use the breakpoints

To set a breakpoint, click the column to the left of the row number: an indicator appears.

To remove a breakpoint, click the indicator.

Below is an example of Visual Studio:

../../_images/4811537509cdbd1f71075ab04c0bdcc6df0ce3ac.png

Note

breakpoints cannot be set on blank lines

At runtime, the indicator signals when the execution is stopped on the line. Below is a Visual Studio example:

../../_images/b5d26fa40c787054025828bb1bedc28ff3a46117.png

Start the debugging

  1. In Visual Studio or Visual Studio Code in debug mode, open the NetLogic(s) to be checked and, depending on whether it is runtime or design time NetLogic, do as follows:

    If the NetLogic is…

    Then…

    runtime

    press F5: the code execution starts, which stops at the first breakpoint.

    design time

    in Q Studio, right-click the desired NetLogic, then click the method to execute: code execution starts, that stops at the first breakpoint.

  2. In the Locals tab in Visual Studio, or the VARIABLES tab in Visual Studio Code, the local objects and variables of the execution context are listed. For each variable, the current values and their type are reported. In the example, the elements shown in the Locals tab refer to the context of the AddTwoNumbers() method.

    ../../_images/56890aa50fc4a6963d22eef023cc4683df3cd089.png

    It is possible to expand the elements containing properties to display their values and types of data/objects. Below is an example:

    ../../_images/b24d764cd4e9b22cf3082d9d2cf2c8a07c43e621.png
  3. To continue the execution of the code of the next line, press F10.

  4. To continue the execution of the code up to the next breakpoint, press F5.

  5. Repeat steps 3 and 4 until debugging is complete.

Change the code after debugging

  1. Stop debugging:

    If the NetLogic(s) is/are…

    Then…

    runtime

    in Q Studio click image4 to stop the execution of the project and to stop debugging.

    design time

    in Visual Studio or Visual Studio Code press MAIUSC+F5 to stop debugging.

  2. Change the code and save the edited .cs files: Q Studio automatically recompiles the .NET solution.

Start debugging after a code change

  1. (Only for runtime NetLogic debugging or if new custom types are created in the project) In Q Studio click image5 to compile and run the Q Application.

  2. Depending on whether you are using Visual Studio or Visual Studio Code, do as follows:

    If using…

    Then…

    Visual Studio

    In the Debug menu click Reattach to Process: the process selected in the previous debugging session is automatically selected and debug mode is entered.

    Important

    if Visual Studio was closed between the previous debugging and the next, it is necessary to click Attach to Process and reset the link (see Set the debugging).

    Visual Studio Code

    1. Open the Run view (CTRL+MAIUSC+D).

    2. In the RUN drop-down menu select Attach to QRuntime for runtime NetLogic debugging or Attach to QStudio for design time NetLogic debugging.

    Important

    if Visual Studio Code ignores the breakpoints in the debugging following the first debugging, restart Visual Studio Code and repeat this procedure.

  3. Open NetLogic to check and, depending on whether it is runtime or design time NetLogic, do as follows:

    If the NetLogic is…

    Then…

    runtime

    press F5: the code execution starts, which stops at the first breakpoint.

    design time

    in Q Studio, right-click the desired NetLogic, then click the method to execute: code execution starts, that stops at the first breakpoint.