10 + powerful debugging tricks with Visual Studio

Source: Internet
Author: User
Tags visual studio 2010

 

Introduction

Debugging is a major part of the development lifecycle. sometimes challenging, sometimes puzzling, sometimes annoying, one for sure-it is unavoidable for any not-so-trivial program. the progress of debugging tools over the last years has made includebugging
Tasks much easier and less time-consuming.

This article summarizes ten debugging tricks and techniques that can save you a lot of time when using Visual Studio.

 

1. Hover mouse to evaluate expression

 

Debugging can be challenging. stepping through a function to understand what went wrong, looking through the call stack to see where did that value come from... in either case adding watch expressions or looking through a list of locals can take quite
Time. however, things get easier if you just point your mouse at a variable of interest. moreover, classes and structures will be expanded with one click, allowing to find the field you need quickly and conveniently.

 

2. Change values on-the-fly

Debugger is much more than a tool for analyzing crashes and wierd behavior. specified bugs can be prevented by stepping through a freshly written function and checking that it behaves as expected. sometimes you are curous "wocould the function behave correctly
If this condition was true? ". And in most cases it does not mean changing the code and restarting. Just hover the mouse over a variable, double-click at the value and type in the new one!

 

3. Set next statement

One typical debugging scenario is analyzing why does a function call fail by going through the function step-by-step. and what do you do when you 've just discovered that a function called another function that returned an error? Restart debugging? There's
A better idea: Just drag the yellow statement marker to the line you want to be executed next, like the function that has just failed, and then simply step in. simple, isn' t it?

 

4. Edit and continue

Debugging a complex program, or a plugin? Found an error, but don't want to lose time stopping, rebuilding and restarting again and the function is called too often to use the previous trick each time? No problem, just fix the bug in-place and continue stepping.
Visual Studio will modify your program and continue debugging with no need to restart.

 

5. A convenient Watch window

Probably, every modern debugger has a watch window. however, what's really cool about the Visual Studio One is how easy you can add and remove variables there. just click at the empty line, type your expression and press Enter. or simply press delete button
To remove an expression that is no longer needed.

 

6. Annotated Disassembly

Optimizing the performance of the critical parts of your program can be much easier using the interactive disassembly mode. visual Studio shows you the instructions corresponding to every line of your code and allows running the code step-by-step, as well
As setting breakpoints at arbitrary locations. And, of course, the expression evaluation and modification will work just like for the c ++ code.

 

7. threads window with stacks

Debugging multi-threaded applications can be painful. or it can be fun. depends on your debugger. the one really nice feature of Visual Studio 2010 is the stack view in the threads window. you can get a convenient overview of all your threads and navigate through
Their call stacks directly from the window.

 

8. Conditional breakpoints

 

If you're trying to reproduce a rare event and getting too limit false positives with your breakpoints, you can easily make them conditional! Simply specify the condition for a breakpoint and Visual Studio will automatically ignore the breakpoint when
Condition does not hold.

 

9. Memory Window

Some bugs are caused by incorrect structure definitions, missing alignment attributes, etc. seeing the raw memory contents simplifies locating and fixing those bugs. visual Studio features a convenient memory window that can interpret the values as 8/16/32/64 -bit
Numbers, as well as floating-point numbers and allows changing them on-the-fly by simply typing the new values over the old ones like in a text editor.

 

10. Go to definition

One last feature to mention is not directly related to debugging, rather to sort ing big projects. if you are trying to find a bug in some code you have not written yourself, having a quick answer to "what is this type" or "What does this function do"
Can save you a lot of time. and Visual Studio does this with your via the go to definition command.

 

11. Command window

This eleventh trick has been suggested
Chaau and it can indeed save you a lot of time. Visual Studio supports a command window that can be activated throughView-> other Windows-> command windowMenu. Once active, you can type varous commands to automate the debugging.
Example, you can easily evaluate an MFC coledatetime variable by running a simple command:

? dt.Format("%Y-%m-%d %H:%M:%S") 

 

 

Note: This article Reprinted from: http://www.codeproject.com/Articles/359801/10plus-powerful-debugging-tricks-with-Visual-Studio

 

 

Related Article

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.