用VS2017debugging(官方文档摘要)

来源:互联网 发布:医脉通官 软件 编辑:程序博客网 时间:2024/04/29 19:47

Source

Configuring a Build

two basic types of build configuration: Debug and Release.The default build configuration is Debug.

can also specify a specific build platform to target, click onbuildplatform dropdown and select a different platform or Configuration Manager…

the configuration and platform values are also used to determine what project directory path is created to store the executable. For example, a project with a configuration of Debug and a platform of x86 would be found under Projects\MyProjectNameHere\MyProjectNameHere\bin\Debug\x86

Building your Code

pressF7selecting Build->Build Solution 

Rebuild your project by pressing either F7 again (to recompile only the files with errors) or Ctrl+Alt+F7 (for a clean and complete rebuild).

There are two build tabbed windows in the results window below the editor: the Output window, ; and the Error List window

Reviewing the Error List

快速调出代码的行号:turn on line numbers by clicking in the Quick Launch (Ctrl+Q) bar in the upper-right, typing “line numbers” into it, and pressing Enter. 

UseCtrl+G to quickly jump to the line number where the error occurred.

Theerroris identified by a red “squiggle” underscore. Hover over it for additional details. Make the fix and it will go away, although you may introduce a new error with the correction. (This is called a “regression”.)

Reviewing Errors in Detail

From the Error List window, you can do an automatic Bing search for more information on the error (or warning) by right-clicking on the corresponding entry line and selecting Show Error Help from the context menu.

click on the hyperlinked error code value in the Code column of the Error List. This will launch a Bing search for just the error code.


Performing Static Code Analysis

“Static code analysis” is a fancy way of saying “automatically check my code for common problems that can lead to run-time errors or problems in code management”. Get in the habit of running it once you’ve cleaned up the obvious errors preventing build, and take some time to address the warnings it may produce. You’ll save yourself some headaches down the road, as well as learn a few code style techniques.

PressAlt+F11 (or select Analyze->Run Code Analysis on Solution from the top menu) to start static code analysis. 

Thewarningswill be identified with a bright yellow-green squiggle
Hover over them for more detail, and right-click on them to get a context menu to assist in fixes or refactoring options.

Using Light Bulbs to Fix or Refactor Code

Light Bulbs are a new feature for Visual Studio that let you refactor code inline. They are an easy way to fix common warnings quickly and effectively. To access them, right-click on a warning squiggle (or pressCtrl+.while hovering over the squiggle), and then select Quick Actions.

Light Bulbs can be used wherever the code analyzers determine there is an opportunity to fix, refactor, or improve your code. Click on any line of code, right-click to open the context menu, and select Quick Options (or, again, if you prefer efficiency, press Ctrl+.). If there is area refactoring or improvement options available, they will be displayed; otherwise, the message No quick options available here will be displayed in the lower-left corner bezel of the IDE.

With experience, you can quickly use the arrow keys and Ctrl+. to check for Quick Option refactoring opportunities and clean up your code!  Perform quick actions with light bulbs.

Light bulbs are a productivity feature in Visual Studio. 

Small Light Bulb Icon

In C++, when you add a new function to a header file, you’ll see a light bulb that offers to create a stub implementation of that function.


鼠标悬停在波浪线处,或者插入点在有波浪线附近时按下Ctrl+.,灯泡就会出现。 


Debugging Your Running Code

pressing F5 or selecting Debug->Start Debugging

the Autos/Locals/Modules/Watch tabbed window and the Call Stack/Breakpoints/Exception Settings/Output tabbed window

Visual Studio Autos and Call Stack Windows

pause the app by pressing Ctrl+Alt+Break (or click on the Pause button).

PressF5to continue running the app (or click the Continue button).

stop your app by pressing Shift+F5 or by clicking the Stop button, or simply close the app’s main window (or command line dialog)

Setting Simple Breakpoints

(You do NOT need to rebuild a project after setting and removing breakpoints.)

Set a breakpoint by clicking in the far margin of the line where you want the break to occur, or select the line of code and pressF9.

When the code breaks, the marked line of code has not executed yet. 

Using Breakpoints

Setting Conditional Breakpoints

click in the margin to set a breakpoint, and then select the “cog” from the hover menu that appears.

Breakpoint Configuration Experience in Visual Studio.

Inspecting Your Code at Run-time

Usethe Diagnostic Tools window in conjunction with the Watch window and breakpoints

Running Unit Tests

Unit tests are programs that exercise code paths in your app or service. Visual Studio installs the Microsoft unit testing frameworks for both managed and native code. Use a unit testing framework to create unit tests, run them, and report the results of these tests. Rerun unit tests when you make changes to test that your code is still working correctly. When you use Visual Studio Enterprise edition, you can run tests automatically after every build.

To get started, read Generate unit tests for your code with IntelliTest.

To learn more about unit tests in Visual Studio and how they can help you create better quality code, read Unit Test Basics.


See Also

Debugging in Visual Studio
Debugger Settings and Preparation
Debug 64-Bit Applications
Debugger Basics




0 0
原创粉丝点击