Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Visual Studio Debug

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain the example analysis of Visual Studio Debug for you in detail. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

This tutorial will introduce some of the Debug features of the getting started phase of Visual Studio.

Like most IDE, Visual Studio has two debugging phases:

One is to find and resolve project and compilation errors in the Build process.

The second is to find and solve the dynamic errors in the process of Run.

Build stage

Build Solution

Build a Solution starts with configuration.

There are two basic types of Solution configuration: Debug and Release.

The differences are as follows:

The executable files generated by DebugRelease are unoptimized, large and slow, contain debugging information added by developers, and will not be put into the market. The generated executable file is optimized, small and fast, and can be put into the market.

The default configuration is Debug.

In addition, you can specify target platforms, such as x86 (32-bit Intel CPU), x64 (64-bit Intel CPU), and ARM (ARM CPU, which only supports certain application types).

To change this value, click the platform drop-down list and select a different platform or configuration Manager.

Once the project is configured, you can start Build.

The easiest way is to press F7, or you can select Build Solution from the menu.

2. Output window

The Build process and its results are displayed in the Output window.

The original compiler output, such as Error,Warning, is displayed here. You can click Error or Warning to go to the corresponding line of code.

This is a successful example of Build.

3. Error List window

Details of Error and Warning that appear during Build can be viewed in the Error List window.

Click on an Error or Warning to go to the corresponding line of code where Error or Warning occurs.

As shown in the image above, the red wavy line represents the Error, and you can hover over the mouse to get the details of the occurrence of this Error.

Sometimes, not all Error can be seen at a glance, and there may be terms or code that are meaningful only to the compiler, such as:

Fatal error C1189: # error...

At this time, the practice of many people is to copy and paste this passage into Baidu / Google search bar and then search. In fact, you don't have to do such repetitive work.

In case you don't know, VS comes with a search function.

Right-click on the corresponding Error or Warning entry, a menu will appear, click Show Error Help, and the Bing search for that Error or Warning will be performed automatically.

Alternatively, you can click the hyperlink to the error code in the Code column, such as CS1525, and the Bing search for that error code will also be performed.

Review and resolve all the Error,Rebuild Solution that appears in Error List one by one until the solution is successfully generated.

4. Code static analysis

After you have resolved all the Error that occurs in Error List during Build, you can try to perform a static analysis of the code.

The code static analysis will analyze the problems in the code that may cause runtime errors, and give the Warning.

Do not think that there is no Erorr, Build is successful, everything will be fine, in the beginning, try to solve the Warning in the code, you can save unnecessary trouble in the future.

You can press the shortcut key Alt+F11 or click the menu below to perform a static analysis of the code.

Warning also appears in the Error List window, click the "Warning" tab to view.

Jump to the line of code where Warning appears. The green wavy line represents the Warning and can be hovered over for more information.

Run stage

5. Basic operation

After Build Solution succeeds, press F5 to execute, which will start the program in the Debug environment.

Two windows appear by default.

Press the Break or Stop button to pause or stop the program.

Press the Continue button to continue with the program.

6. Set breakpoints

Setting breakpoints is the most common function of the Debug process.

The breakpoint indicates which line of code the VS is executing and hangs. When the program hangs, you can look at anything you want to see, such as variable values, memory, code execution branches, etc.

Setting a breakpoint is easy, as long as you click on the edge of the edit area or press F9 on the appropriate line of code, a red dot will appear next to it.

Set the breakpoint, press F5, and the program will stop at the breakpoint.

The moving picture is here.

Next, several common operations are:

F10step over code single-step F11step into code jump to the inner function Shift+F11step out code jumps out of the current function

You can set multiple breakpoints, switch between shortcut keys such as F5Magee F10, and go to different breakpoints.

7. View variables

The program executes to the breakpoint, and when it stops, you can check the variables in the code, stack calls, etc., to see if they are within the expected range.

Hover the mouse over the variable and you can see its value at the moment.

Put another moving picture to make it clearer.

This is the end of this article on "sample Analysis of Visual Studio Debug". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report