Summary of Visual Studio debugging tips-Practical tips

Source: Internet
Author: User
Tags delete key error code

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

1 hover mouse View expression value

Debugging is a very challenging one. For example, in the function of the step-by-step operation can be seen where the error, look at the stack information can know the function by who called and so on.

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

A simpler way to stop the mouse on the data you want to view. If it's a class or structure, clicking on it makes it easy to see its fields quickly.

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 solve many bugs by gradually debugging ways to check that data and behavior conform to the program's expectations. Sometimes, you will want to set certain conditions to be 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 will not need to modify the code, restart the program.

3 Set the next Run location

A typical debugging case is that we often use step-by-step debugging methods to analyze why the function is wrong. When you encounter this function call other function return error, and this error is not what you want, what should you do? Reboot the debugger? Here's a better way to just drag the yellow arrow to the location where you want it to run. In fact, skip the middle run code, directly to the desired position. It's very simple.

4 Edit then continue to run

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 simply, just modify the bug in this location and continue debugging. Visual Studio modifies this program so that you can continue debugging without having to restart the program.

It's worth noting 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, to the compilation options in the Project settings, select "x86" as the target platform. Do not worry, the target platform in the Reslease configuration is and "debug is separate, which is still the" any CPU "settings. Second, "Edit and Continue" This function only applies to a function internal change. If you want to change the declaration of this function or add new methods, 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 automatically generated delegate type is modified, which causes the compiler to stop running.

51 Convenient viewing Windows

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

Not only can you see the normal variable values in the Debugging window, you can even enter $handles to track the number of open handles, $err to view the error code of the function (and then use Tools->error to view the description of the error code), or enter @eax (under 64 digits @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 either step through the assembly code or set breakpoints in any location. Viewing and modifying assembly code is similar to C + +.

  7 Thread window for stack information

Debugging multithreaded code is painful. Maybe it's also interesting. It depends on your debugger. A great feature of Visual Studio is the thread window that looks at the stack of threads. You can easily see all the threads and their stack information directly.

  8 Conditional Breakpoint

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

  9 Memory Windows

Some bugs are caused by incorrect structure definitions, lack of alignment attributes, and so on. Viewing the contents of each line of memory is easy to locate and resolve these bugs. Visual Studio's memory window can translate data into 8/16/32/64-bit numbers or floating points. You can change the value directly in the edit window.

  10 Jump to Definition

If you're solving a bug in someone else's code that says "What's This type", "what does this function do", you can use Visual Studio's jump to a defined command to see the definition of a type or function.

 11 Command Window

This tip is suggested by Chaau, which saves you a lot of time. Visual Studio supports a command window that you can open via the menu View->other windows->command window. You can enter different commands in the window to automate debugging. For example, you can test MFC's COleDateTime variables with very simple commands.

These are the 11 Visual Studio debugging techniques that we share for you, and hope to help you learn.

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.