Visual Studio Debugging Tips Summary

Source: Internet
Author: User
Debugging is an important part of the software development cycle. It's challenging, and it's also confusing and annoying. In general, for a slightly larger program, debugging is unavoidable. In recent years, the development of debugging tools has made many debugging tasks more and more simple and time-saving.

1 hover the mouse to view the value of an expression

debugging is very challenging. For example, stepping through a function can see where the error occurs, view the stack information to know who the function was called, and so on.

But in either case, it is cumbersome to look at the values of expressions and local variables (put expressions and local variables in the Watch window).

An easier way to stop the mouse on the data you want to see. If it's a class or structure, clicking Expand makes it easy and quick to see its fields.

2 Changing the value of a variable during operation

The debugger is not just a tool for analyzing program crashes and weird behavior, but it can also be done by stepping through debugging to check whether the data and behavior conform to the program's intended approach to solving many bugs. Sometimes you wonder if certain conditions are true and the program will run correctly. In fact, you just move the mouse over the variable, double-click the value, and then enter the value you want. This way, you don't need to modify the code to restart the program.

3 Setting the next Run location

A typical debug case is that we often use step-by-stage debugging methods to analyze why a function has failed. Then you encounter this function call other function return error, and this error is not what you want, what should you do? Restart the debugger? Here's a better way to just drag the yellow run-position arrows to where you want them to run. In fact, just skip the middle running code and go straight to the desired location. It's simple.

4 Edit and Continue running

When running a very complex program and plug-in, you find an error, but do not want to waste time to recompile the restart program.

Very simple, just modify the bug in this position and then continue debugging. Visual Studio modifies the program so that you can continue debugging without restarting the program.

It is important to note that the "Edit and Continue" feature has several limitations. One, it cannot be used on 64-bit code. If you want to use this feature, go to the build option in the Project settings and select "x86" as the target platform. Do not worry, this target platform in the Reslease configuration is and "debug is separated, that is, still the" any CPU "setting. Second, the "Edit and then continue" feature applies only to changes within a function. If you want to change the declaration of this function or add a new method, you can only choose to restart the program, or do not make any changes to continue. If the modified method contains a lambda expression, it means that the compiler's automatically generated delegate type is modified, which causes the compiler to stop running.

51 Convenient viewing Windows

Most modern debuggers have a viewing window. However, Visual Studio's viewing window is especially easy to use, and you can easily add and remove variables. Just click the blank line in the window, enter an expression, and press ENTER. Or click the expression and press the DELETE key to delete the unwanted expression.

In the debug window you can not only view the normal variable values, you can even enter $handles to track the number of open handles, $err to see the function's error code (and then use Tools->error to see the description of the error code) or enter @eax (under 64 bits is @rax ) to view the register value that contains the return value of the function.

6 Annotation Disassembly

Using the internal disassembly feature makes it easier to optimize local code. Visual Studio can display assembly instructions under each of your lines of code, and you can step through the assembly code, or you can set breakpoints at any point. Viewing and modifying assembly code is similar to C + +.

7 Thread window for stack information

It is painful to debug multithreaded code. Maybe it's interesting, too. It depends on your debugger. One of the great features of Visual Studio is that the thread window looks at the stack information for threads. You can easily see all the threads and their stack information directly.

8 Conditional breakpoints

If you want to reproduce a small probability event, the breakpoint will also be triggered under a large number of unwanted conditions. You can set conditional breakpoints very simply. When you set the breakpoint condition in the Breakpoints window, Visual Studio automatically ignores breakpoints that do not meet the criteria.

9 Memory Window

Some bugs are caused by the wrong structure definition, lack of alignment properties, and so on. Viewing the contents of each row of memory makes it easy to locate and resolve these bugs. Visual Studio's memory window can translate data into 8/16/32/64-bit digits or floating-point numbers. You can change the value directly in the edit window.

10 Jump to Definition

If you're dealing with a bug in someone else's code, and you're going to get a "what's this type of thing" or "what does this function do" question, you can use Visual Studio to jump to a defined command to see the definition of a type or function.

11 Command Window

This tip is recommended by Chaau, and it can save you a lot of time. Visual Studio supports a command window that you can open through the menu View->other windows->command window. You can automate the debugging by entering different commands in the window. For example, you can test MFC's COleDateTime variables with very simple commands.

The above is for everyone to share the 11 Visual Studio debugging skills, hope that everyone's learning is helpful.

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.