11 Efficient vs Debugging Tips

Source: Internet
Author: User
Tags delete key

Introduced

Debugging is an important part of the software development cycle, sometimes challenging, and sometimes confusing to programmers, sometimes making programmers mad, but. To be sure, debugging is unavoidable for any program that is not too trivial. In recent years, the development of debugging tools has made many debugging tasks simple and time-saving.

This article summarizes 10 debugging techniques that can save you a lot of time when you use vs.

1. Hover the mouse to view the expression

Debugging is sometimes challenging when you step into a function and want to see which block is wrong, look at the call stack to see where the value comes from. In other cases, you'll need to add some watch expressions, or see a list of local variables, which usually takes some time, but. If you point your mouse at a variable that interests you. You'll find it much easier. Also, classes and structs can be expanded by clicking. Such You can quickly and easily find the variables you want to see.

2 changing values in real time

The debugger is not just a tool for parsing program crashes or abnormal results, many bugs can be prevented by stepping into a newly written function to check if the function is running as expected. Sometimes you might wonder, "if the condition is true, the function will run correctly." In most cases, you do not need to change the code restart, just hover over a variable, double-click the value and enter a new value.

3. Set the Next statement

A typical debug scenario is to analyze why a function call failed with a single-step trace. What do you do when you find another function call that returns an error? Restart debugging? There's a better way. Drag the yellow statement to identify the statement you want to execute next. Like the one you just failed, and then step in. Simple, isn't it?

4. Edit and Continue

When debugging a complex program, or a plug-in, an error is found in a function that has been called many times. But do not want to waste time to stop, recompile and then re-debug. No problem, just fix the code here and go on with one step. VS will fix the program then continue debugging no need to restart

Note that editing then continues to have a large number of known limitations, first of all, 64-bit code is not possible. If he works for your C # program. Just go to the build option for the project setup, and then the target platform is x86. Don't worry. The target platform for the release version is separate from the debugging. Can be set to any platform:

Second Editing and then continuing to change in a method should be local. If you change the method signature, add some new methods or classes. You'll have to restart the program. Or undo the change to continue. The change method also contains an automatically generated proxy class that is implicitly modified by the lambda expression, and therefore cannot continue.

5. Convenient monitoring window

Probably the modern debugger has a watch window, anyway. VS allows you to simply add or remove variables. Click the blank line, enter your expression to press ENTER, or you can delete it by pressing the DELETE key on the unwanted expression.

And. From the Watch window you can see not just the "normal" variables. You can enter $handles to track how many handles your program has opened (you can easily fix a memory leak), enter $err to see the error code of the previous function, and then use the tool-error message to see a more detailed description, or enter @eax (64-bit is @rax) to see the register that contains the function return value.

6. Annotated Disassembly

Using the interactive disassembly mode makes the key parts of the optimizer easy, VS gives the assembly instructions that correspond to each line of your code, and runs the single-step operation. At the same time, breakpoints can be set at any location. Also, the expression is viewed and modified in the same way as in C + + code

7. Thread Windows with stacks

Debugging a multithreaded program is painful. Or it could be fun. Depends on your debugger. VS2010 really beautiful feature is the stack view of the thread window, through the call stack of the window you can conveniently overview the thread.

8. Conditional breakpoints

If you try to reproduce a rare event through a breakpoint, the situation raises some serious errors. You can add conditional breakpoints. Defines the condition of a breakpoint, and if the condition is not true, VS ignores the breakpoint

9. Memory Window

Some bugs are caused by incorrect struct definitions, ignored alignment attributes, and so on. View the contents in memory to locate and fix the bug. VS provides a century-old memory window that can display values in 8/16/32/64. There are also floating-point values. They are also allowed to change in real time. Just like in a text editor.

10. Go To Definition

This feature is not directly about debugging, but about browsing large projects. If you try to find something that is not in your own code, quickly know "what this type is" or "What this function is for", and you can save a lot of time, vs. it's convenient for you to go to the definition command.

11. Command Window

The 11th tip, Chaau, has been suggested. It can really save a lot of time, and the VS Support Command window can be launched through the view-Other Windows-command window. Once activated, you can enter different commands to automate debugging. Let me give you an example. You can simply simulate the MFC COleDateTime variable with the following command.

? Dt. Format ("%y-%m-%d%h:%m:%s")


11 Efficient vs Debugging Tips

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.