Debugging

Debugging Startup

  1. After setting breakpoints and run configurations, click the debug icon on the toolbar to start debugging.
  2. After the debugging function is started, the system stops at the first (enabled) breakpoint, and on the right of the line where a code variable is located, the variable value is automatically displayed, as shown in the information in green in Figure 1. The Debugger view is displayed in the lower right corner of the project window.
    • The Frames area on the left is the program's method call stack. This area displays all methods that have been called by the program before the breakpoint. The methods at the bottom are called earlier. The information in the red box indicates the code line where the current debugging program stays, for example, line 19 of the main.cpp file.
    • The Variables area displays the variable and thread information.
      Figure 1 Project debugging window

      Table 1 describes the icons in the Debugger view.

      Table 1 Description of icons in the Debugger view

      Icon

      Name

      Description

      Rerun(Ctrl+F5)

      Reruns debugging.

      Resume program(F9)

      Resumes the program running until the next breakpoint.

      Runs the code that needs to be executed between two breakpoints. If there is no breakpoint in the subsequent code, clicking this icon again will complete the program execution.

      Stop(Ctrl+F2)

      Stops debugging.

      View Breakpoints(Ctrl+Shift+F8)

      Views all breakpoints.

      Views the set breakpoints and sets attributes to the breakpoints. For details about the displayed window and its functions, see Viewing Breakpoints.

      Mute Breakpoints

      Mutes all breakpoints.

      For details, see Mute Breakpoints.

      Step Over(F8)

      Goes to the next code line.

      Click this icon to make the program execute the next line. If a function is called in the current line, it will be executed and returned. Then, the program will display information about the frames and variables in the next line. For details, see Step Over.

      Step Into(F7)

      Steps into the function.

      The program executes the next line. If a custom function is present in this line, it will be executed directly, bypassing the functions in the official library, and displaying information about the frames and variables involved. For details, see Step Into.

      Force Step Into(Alt+Shift+F7)

      Forcibly steps into a function.

      Click this icon to debug any function, including custom functions and functions in the official library.

      Step Out(Shift+F8)

      Steps out of a function.

      If you steps into a function during debugging and the function is normal, click this icon to step out of the function and return to the original position. For details, see Step Out.

      Run to cursor(Alt+F9)

      Runs to the cursor.

      If no breakpoint is set, the program pauses at the line where the cursor is located, and information about the frames and variables involved is displayed. For details, see Run to Cursor.

The following describes the debugging features with examples.

Adding Variables to the Watches Area

Right-click the variable to be viewed and choose Add to Watches from the shortcut menu. The variable is then added to the Watches area, as shown in Figure 2.
Figure 2 Adding a variable to the Watches area

You can also click the icons on the toolbar on the left to perform more functions:

  • : adds a variable to the Watches area.
  • : deletes the selected variable.
  • : copies the selected variable. You can modify the copied variable to a desired parameter as follows:

    Right-click the copied variable, choose Edit from the shortcut menu, and enter a new variable name.

  • : opens a new Watches window if there are too many variables or threads in the original Watches area. The variables are automatically displayed in this new window, as shown in Figure 3. Click in the upper part of the Watches window, and the Watches window is automatically merged into the Variables window.
    Figure 3 Opening the Watches window

Step Over

  1. Set a breakpoint.
  2. Start debugging. The Debug window stops at the breakpoint.
  3. Click to execute the next line, as shown in Figure 4.
    Figure 4 Step over

Step Into

  1. Set a breakpoint.
  2. Start debugging. The Debug window stops at the breakpoint.
  3. Click to execute the next line. If there is a customized method in the line, run the customized method, as shown in Figure 5.
    Figure 5 Step into

Step Out

During debugging, if you step into a function through Step Into, for example, GetFileList, and find that the function is normal, you can click to step out of the function and return to the original position, as shown in Figure 6.

Figure 6 Step out

Run to Cursor

If no breakpoint is set for a code line and you want to debug the code line, click to move the breakpoint to the code line where the cursor is located, as shown in Figure 7.

Figure 7 Run to cursor

Mute Breakpoints

If you want to mute all breakpoints during debugging, click . Then all breakpoints are grayed out, as shown in Figure 8, and the icons turn gray. Click to finish debugging directly.

Figure 8 Mute breakpoints