Debugging is an important part of the software development cycle.It is challenging,It's also very confusing and upsetting.In general,For larger programs,Commissioning is inevitable.Recent years,The development of debugging tools has made many debugging tasks easier and less time consuming.
1Hover over the expression value
Debugging is very challenging.For example, if you run step by step inside the function, you can see what went wrong.Look at the stack information to know who called the function and so on.
But in either case,Viewing the values of expressions and local variables is cumbersome (put expressions and local variables in the watch window).
A simpler way,Hover your mouse over the data i want to view.If it is a class or structure,Then click to expand to view its fields quickly and easily.
2 Change the value of a variable during operation
Debugger is more than a tool to analyze program crashes and weird behaviors,Many bugs can also be resolved by step-by-step debugging to check that the data and behavior are as expected by the program. Sometimes you wonder if you set certain conditions to true,The program will run correctly.In fact, you just move your mouse over the variable,Double-click the value and enter the value you need.There is no need to modify the code,Restart the program.
3 Set the next operating position
typical A typical debugging case is that we often use step-by-step debugging to analyze why the function is wrong.At this time, you encounter errors when this function calls other functions,And this error is not what i want,what should you do?Restart the debugger?Here is a better way,Drag the yellow running position arrow directly to the running position i want.It's actually skipping the middle running code,Go directly to the desired location.It's simple.
4 Edit and continue
run When running a very complex program and plugin,Found an error,But don't want to waste time recompiling and restarting the program.
It's very simple, just fix the bug at this location and continue debugging.visual studio will modify this program,Allows you to continue debugging without restarting the program.
It is worth noting that there are several limitations to the "Edit and Continue" feature.First, it cannot be used on 64-bit code.If i want to use this feature,Go to the compilation options in the project settings,Select "x86" as the target platform.do not worry,The target platform is separated from "debug" in the release configuration.In other words, it is still the setting of "any cpu". Second, the "Edit and Continue" feature only applies to changes within a function.If i want to change the declaration of this function or add new methods,You can only choose to restart the program,Or continue without making any changes.If the modified method contains a lambda expression, it means that the delegate type automatically generated by the compiler is modified.This will cause the compiler to stop running.
5 A convenient viewing window
Most modern debuggers have viewing windows.However, the viewing window of visual studio is particularly simple to use,You can easily add and delete variables.Just click on the blank line in the window,Enter the expression and press enter. Or click on the expression,Press delete to delete unwanted expressions.
Do not In the debug window, you can not only view ordinary variable values,You can even enter $handles to track the number of open handles.$err to see the function's error code (then use tools->error to see the description of the error code) or enter @eax (@rax on 64-bit) to see the register value containing the function's return value.
6 Comment disassembly
Using internal disassembly function makes it easier to optimize local code.visual studio can display assembly instructions under each line of your code,And you can debug the assembly code step by step,You can also set a breakpoint at any position.Viewing and modifying assembly code is similar to c++.
7 Thread window for stack information
Debugging multithreaded code is painful.Maybe also interesting.It depends on your debugger.A great feature of visual studio is to view the thread stack information in the thread window.You can easily see all threads and their stack information directly.
8 conditional breakpoints
If i want to reproduce a small probability event,But breakpoints are also triggered in a lot of unwanted conditions.You can easily set conditional breakpoints.Set the breakpoint condition in the breakpoint window,Visual Studio automatically ignores breakpoints that do not meet the criteria.
9 Memory window
Some bugs are caused by incorrect structure definitions, missing alignment attributes, and so on.Viewing the contents of each line of memory is easy to locate and resolve these bugs. The memory window of visual studio can translate data into 8/16/32/64-bit numbers or floating point numbers.You can change the value directly in the edit window.
10 Jump to definition
If you are solving a bug in someone else's code, you will encounter questions like "What is this type" and "What does this function do",You can use visual studio's jump to definition command to see the definition of a type or function.
11 Command window
This little tip is suggested by chaau, it can save you a lot of time.visual studio supports a command window,You can open it via menu view->other windows->command window. You can enter different commands in the window to automate debugging.For example, you can test mfc'scoledatetime variable with a very simple command.
- visual studio code debug php method (detailed graphic)
- Analysis of Visual Studio Code breakpoint debugging Vue
- Breakpoint debugging Nodejs with Visual Studio Code
- Explain how to use VisualStudio to efficiently develop and debug AndroidNDK
- Visual Studio 2017 debug NET Core on Linux via SSH
- C # client program Visual Studio remote debugging method detailed
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- dart - flutter: the instance member'stars' can't be accessed in an initializer error