Visual Studio debugging method, Visual Studio

Source: Internet
Author: User

Visual Studio debugging method, Visual Studio

1: Command window

CTRL + D + I, you can write some temporary code in the immediate window

 

2: Edit and continue

Select the following options to pause debugging and modify the code without restarting,

 

3: Run

One-step execution: F10

Hop-in method: F11

Bounce method: SHIFT + F11

Execute to the cursor: CTRL + F10

 

4. Hover the mouse over to view the expression value

It is troublesome to view the expression and local variable values. You can move your cursor over the data you want to view. If it is a class or structure, click expand to view its fields conveniently and quickly.

 

 

5. Change the variable value during running

The debugger is not only a tool for analyzing program crashes and strange behaviors, but also a solution to many bugs by gradually debugging and checking whether data and behavior meet the program's expectations. Sometimes, you may want to set certain conditions to true so that the program can run correctly. In fact, you just need to move the mouse over the variable, double-click the value, and enter the value you need. In this way, you do not need to modify the code and restart the program.

 

 

 

6. Set the next running location

We often use the step-by-step debugging method to analyze why a function fails. In this case, you encounter an error returned when this function calls other functions, which is not what you want. What should you do? Restart the debugger? Here is a better way to drag the Yellow running position arrow to the desired running position. In fact, it is to skip the intermediate code and directly go to the desired position.

 

7. A convenient viewing window

The visual studio display window is very easy to use, you can easily add and delete variables. Just click a blank line in the window, enter the expression, and press enter. Or click the expression and press the delete key to delete unnecessary expressions.

In the debugging window, you can not only view common variable values, but also enter $ handles to track the number of opened handles, $ err: view the Error code of the function (use Tools-> Error to view the description of the Error Code) or input @ eax (@ rax in 64-Bit mode) view the register value that contains the function return value.

 

8. roll back the current Execution Code

For example, if the code runs on 49 lines and you want to return to 45 lines, it doesn't matter. You can drag the yellow arrow from 49 lines to 45 lines, as shown below:

 

9. Start debugging from the process

Sometimes, you do not want to start VS for debugging. For example, if you want to debug the current browser page from the running status when the website is deployed on the local machine, you can use Attack to Process to start debugging, as shown below:

 

10. Conditional breakpoint

If you want to reproduce a small probability event, the breakpoint will also be triggered under a large number of unnecessary conditions. You can easily set conditional breakpoints. When this breakpoint condition is set in the breakpoint window, Visual studio automatically ignores non-conforming breakpoints.

 

11. Command window

Visual studio supports a Command Window, which can be opened through the menu View> Other Windows> Command Window. You can enter different commands in the window to automate debugging.

 


How to debug the code using the Microsoft visual studio Debugger

F9 adds a breakpoint, F5 starts debugging, and F10 executes one sentence

How does visual studio 2008 perform breakpoint debugging?

Find the menu option first, that is, debug is included in the drop-down menu, which can only be executed in debug mode. If you execute in Release, the expected results will not be obtained.
After a breakpoint is set, you can pause the execution at the breakpoint during the program execution, in this way, you have the opportunity to check the values of each variable in the program stack, or verify whether the program is executed here.

For example, the simplest function
Void myTest ()
{
Int I;
For (I = 0; I <100; I ++)
{
J = I + data;
}
}
You can set a breakpoint at j = I + data so that you can stop here during each loop, so that you can observe the changes in the value of each temporary variable. Of course, if your data comes from the database, you can easily check whether the data read by each database operation is correct. If this debugging function is not available, for example, the above Code throws an exception when I = 50 and the program stops automatically, so you do not know where an error has occurred. However, with the debug function, programmers can find that when I = 50, the value of data is changed to-68697083, which is obviously a memory leak, that is, database operations are abnormal, this is much more convenient!

Of course, you can also place a breakpoint on the first line of myTest to check whether the program has executed this function. Because sometimes the program fails to call the function you expected to call.

The debug debugging function is mainly applicable to debugging, and of course it is also convenient for you to read other people's code. It is very troublesome to directly read tens of thousands of lines of code, especially the workload of maintaining code without comments is too heavy. At this time, you can set a breakpoint at the beginning of each function name and then execute it in sequence, then you will quickly understand the Program Execution Process and grasp the basic structure of the entire project in a short time. It is not easy to maintain it!
I hope my explanation will help the landlord understand:-0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.