visual studio debugger debugging

We all knowWhen the code does not run properly,Errors can be located through debugging.Common program debugging operations include setting breakpoints, starting, interrupting, and stopping program execution, stepping through the program, and running the program to a specified location.The following will introduce these several commonly used program debugging operations in detail.Not much to sayTake a look at the detailed introduction together.

1. Breakpoint operation

The breakpoint informs the debugger,Causes the application to be interrupted at some point (suspending execution) or when something happens.When an interruption occurs,The program and debugger are said to be in interrupt mode.Entering interrupt mode does not terminate or end program execution.All elements (such as functions, variables, and objects) remain in memory.Execution can continue at any time.

There are 3 ways to insert a breakpoint:click in the gray space next to the line of code where i want to set a breakpoint;Right-click the line of code where i want to set a breakpoint,In the pop-up shortcut menu, select the "Breakpoint" → "Insert Breakpoint" command, as shown in Figure 11.4;Select the "Debug" → "Toggle Breakpoint (g)" command in the menu, as shown in Figure 11.5.

Figure 11.4 Insert a breakpoint in the context menu

Figure 11.5 Insert a breakpoint in the menu bar

After inserting a breakpoint,A red dot appears in the gray space next to the line where the breakpoint was set,And that line of code is also highlighted,As shown in Figure 11.6.

There are three main ways to delete breakpoints, as follows:

(1) You can click the red dot to the left of the line where the breakpoint is set.

(2) Right-click the red dot on the left of the line of code where the breakpoint is set,Select the "Delete Breakpoint" command in the pop-up shortcut menu, as shown in Figure 11.7.

Figure 11.7 Right-click shortcut menu to delete breakpoint

(3) Right-click on the line of code where the breakpoint is set,Select the "Breakpoint"/"Delete Breakpoint" command in the pop-up shortcut menu

2. Begin execution

Starting execution is one of the most basic debugging functions,Select the "Start Debugging" menu from the "Debugging" menu (shown in Figure 11.8), or right-click a line in the executable code in the source code window,Select the "Run to Cursor" menu from the pop-up shortcut menu, as shown in Figure 11.9.

Figure 11.8 Selecting the "Start Debugging" menu

Figure 11.9 Select the "Run to Cursor" menu

In addition to starting execution using the method described above,You can also directly click the button in the toolbar,Start debugging,As shown in Figure 11.10.

Figure 11.10 Start debugging button in toolbar

If you select the Start Debug menu, the application starts and runs to the breakpoint,The code at the breakpoint is now displayed with a yellow background,As shown in Figure 11.11. Execution can be interrupted at any time,To see the value (mouse over the corresponding variable or object,To see its specific value,(As shown in Figure 11.12), modify variables or observe the program status.

Figure 11.11 Running to a breakpoint

Figure 11.12 Viewing the value of a variable

If you select the "Run to Cursor" command, the application starts and runs to the breakpoint or cursor position,It depends on whether the breakpoint is in front or the cursor is in front.The cursor position can be set in the source window.If the cursor is in front of the breakpoint,The code first runs to the cursor,As shown in Figure 11.13.

Figure 11.13 Run to the cursor

3. Interrupt execution

When execution reaches a breakpoint or an exception occurs,The debugger will interrupt the execution of the program.After selecting the "Debug" → "Break All" menu, the debugger will stop the execution of all programs running under the debugger.The program did not exit,Can resume execution at any time,The application is now in interrupt mode.The "All interrupts" menu in the "Debug" menu is shown in Figure 11.14.

Figure 11.14 "Debug" → "Break All" Menu

In addition to interrupting execution by selecting the "Debug" → "Break All" command,You can also click the button in the toolbar to interrupt execution,As shown in Figure 11.15.

Figure 11.15 Interrupt execution button in the toolbar

4. Stop execution

Stopping execution means terminating the process being debugged and ending the debugging session,You can end the running and debugging by selecting the "Debug" → "Stop Debugging" command in the menu.You can also select a button in the toolbar to stop execution.

5. Single step and step by step

By stepping through,The debugger executes only one line of code at a time,Single-step execution is mainly realized by the three kinds of commands:step by step, step by step, and step out.The main difference between statement-by-statement and procedure-by-procedure is that when a line contains a function call,"Step by step" executes only the call itself,Then stop at the first line of code within the function.And execute the entire function "procedure-by-procedure",Then stop at the first line of code outside the function.If you are inside a function call and want to return to the calling function,Should use "bounce out", which will always execute the code,Until the function returns,Then break at the return point in the calling function.

When debugging is started,You can click the button in the toolbar to execute the "step by step" operation, click the button to perform the "step by step" operation, and click the button to perform the "jump out" operation, as shown in Figure 11.16.

Figure 11.16 Three commands for single step execution

Note:In addition to clicking these 3 buttons in the toolbar,You can also perform these three operations through shortcut keys. After starting debugging,Press the<f11>key to perform a "statement-by-statement" operation, the<f10>key to perform a"procedure"operation, and the<shift + f10>key to perform a "jump out" operation.

to sum up

  • Previous Summary of two methods for implementing circular queues based on Java arrays
  • Next Vue's seamless scroll component vue-seamless-scroll instance