Seven little known functions of visual studio debugger


Visual studio debugger is a great debugging tool, which can help people find and solve problems quickly. Here is a brief introduction to the seven little-known functions of vs debugging tool.

1. Jump to the specified statement with one click

In the process of debugging, it is often necessary to drag the yellow arrow to make a specific statement execute or not. The normal way is to use the mouse to drag directly.

In the preview version of visual studio 2017 15.3, there is a simpler way to jump to the target line: after hovering the mouse pointer in the target line, the green vertical line right arrow icon appears, hold down the CTRL and click the left mouse button to move the debugging yellow arrow, and then click debug next or F5 to run directly in the specified line.

2. Add the breakpoint of the specified instance value

Sometimes the property value of an instance will change inexplicably. When we need to know why, we will add breakpoints to the property code, but this will take effect for all instances.

During debugging, you can use the make object ID and conditional breakpoint functions to add breakpoints to the specified instance, as follows:

First of all, I define a class, initialize two objects, change the value of pointx, and want to add the change breakpoint of pointx value of instance a

During debugging, right-click instance a and select make object ID

At this time, instance a is assigned to $1. Right click the breakpoint to add and select conditions

After adding $1 = = this code and running the program, the breakpoint will take effect when the property of instance a changes, and it will not take effect when the property of instance B changes.

Note that the make object ID records the address of the object in memory, which will be changed in the next debugging and needs to be reset.

3. Reattach the process

Attach to process is a function that you often need to use. In Visual Studio 2017, there is a new option called reattach to process, which is convenient for you to reattach to the last process.

First attach to a process, click stop debugging, and then click debug to see the realtach to process option.

4. Display all threads

During debugging, a new option in the debug toolbar is called Show Threads in Source. After clicking, an icon can be displayed in front of the code line where the thread stops. The mouse stays on the icon to display the thread. Right click the icon to display the available operations.

Note that this function may affect the debugging efficiency. If it is not needed, it is recommended to turn off by default.

5. Temporarily disable the specified breakpoint

When multithreading debugging, you can use the disable breakpoint function to temporarily disable the specified breakpoint to prevent other threads from interrupting due to the breakpoint and affecting the debugging work of the current thread.

6. View the call stack of all threads

During debugging, enter “debug. Listcallstack – allthreads” in the command window to see the call stack of all threads.

You can also use the WinDbg command “~ * k”:

7. Use the method without negative effect to evaluate

Sometimes it may be necessary to check the return value of a method in the debug watch window, but the actual implementation of this method may produce negative effects. Here, you can add “NSE” to avoid negative effects when typing in the watch window, which is the abbreviation of “no side effects”. Examples are as follows:

In the beginning, add was executed six times, so the total number of testlists is 6,

Now, if you want to see the return value of the current execution of add, you can enter add (1) in the watch window, but this will have a negative effect. Change the value of testlist to 7,

Therefore, if you want to not affect the original value of the testlist, you need to add “NSE”, as shown below: 8, but the original value of the testlist remains unchanged or 7:

This is the end of the introduction. Are there any small debugging functions you like? Welcome to comment~

PS: just an introduction. Don’t spray if you don’t like it.

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.