Vs. Net's debugging function introduction (debugging in Visual Studio. NET)

Source: Internet
Author: User
Recently, I plan to systematically learn the C # language. I am looking at professional C #. I don't know if you have any suggestions on how to learn C # systematically. If you have any suggestions, please kindly advise :)

To do a good job, you must first sharpen the tool. To do a good job in software development, it is necessary to master good debugging tools and skills! When I was reading a book, I found some vs that I didn't know before. net useful debugging functions (many people may already know these functions, if anyone has relevant experience to share), here is a very simple introduction:

I. breakpoint settings (breakpoints)

We usually use the breakpoint function by clicking the mouse in the gray area before a line of code or pressing F9 to set the breakpoint for that line, then, when the program is being debugged, it will be interrupted at the breakpoint. But have you ever encountered such a situation: If you are in a loop statement for (INT I = 0; I <count; I ++, you want to interrupt the loop counter when I reaches a certain value, instead of starting from 0 every time, because it is likely that the Count of this loop is very large, or the I value that you want to interrupt is very large, and sometimes you want to interrupt the breakpoint when an expression reaches a certain condition, so that you can clearly capture the debugging problem.

In fact, the above functions have been provided in vs. NET and are quite flexible. I can set or modify the breakpoint attributes. Before setting a breakpoint, you need to bring up the breakpoint properties dialog box. You can choose "debug-> New breakpoint... ", or press Ctrl + B to bring up the breakpoint setting box:


To set an existing breakpoint, choose "debug-> Windows-> breakpoints" or CTRL + ALT + B to open the breakpoints form:


Select the breakpoint you want to modify, click the button with a small hand in the upper right or select Properties from the right-click menu, the above breakpoint Setting Dialog Box will pop up.

The labels in the breakpoint setting box allow you to set breakpoints in different ways. The preceding three labels have nothing to say:

Function: allows you to define breakpoints from the function position. File: You can define breakpoints somewhere in the source file. Address: You can set breakpoints through the Code address in the memory;

I am a little confused about the fourth tag data (please kindly advise ):


It is said that it can monitor the value of a variable, or even the value at an array or pointer offset (set Internal offset through items ), once the value of this variable changes, the breakpoint is interrupted. This function seems very powerful, but I tried it myself and found that the breakpoint of C # And CLR does not support this function, it may be related to the variable address being unable to be determined in the hosting mode, sorry ~~


If you forcibly select C ++ as the language, an error is returned:


Forget it. The function that was originally tempting can only be left empty :)

Next, let's take a look at how to set the breakpoint interruption conditions,

Click the condition... button under the breakpoint setting box to display the following dialog box:


Here, you specify that this breakpoint is interrupted only when an expression or variable reaches true or the value changes. (In fact, the variable value changes here as the interrupt condition is different from the above variable monitoring function)

Click the hitcount... button under the breakpoint setting box to set the interruption conditions for the number of times the breakpoint is triggered:


There are four condition settings:

1. always interrupt (that is, the default breakpoint setting); 2. Interrupt when the number of triggers is equal to a value; 3. Interrupt when the number of triggers is an integer multiple of a value; 4. It is interrupted when the number of triggers is greater than or equal to a value.

This feature can be used to interrupt debugging of a statement in a large loop.

Ii. Monitoring (watches)



The monitoring function is mainly composed of several forms. You are familiar with these functions:

Autos: the content of the variable finally accessed by the program; locals: the content of the local variable in the current function scope in the stack; this: the content of the current instance object; callstack, the status of the current program call stack; treads can provide all the threads of the current application. There are also watch and memory forms,. NET 2003 supports four watches forms and four memory forms at the same time, allowing you to view multiple variables or multiple memory areas at the same time, in particular, the watches form is very useful for monitoring the content of variables and supports the drag operation. You can directly drag the variable string of the Code to the watch form for display during debugging.

All monitoring-related forms can appear only during debugging. You can find all forms through the "debug-> Windows" menu.

In addition, there are some debugging-related forms: modules, disassembly, register, running documents. Among them, running documents does not know what to do? If you want to know the experts, please be knowledgeable. Thank you!

Iii. Exceptions)



Vs. net can also be captured flexibly. In the past, I thought that only exceptions that are not captured by a program (that is, no related processing program is written) can be finally captured by the debugger. In fact,. net allows you to flexibly capture various exceptions and perform debugging. You can use "debug-> exceptions" or press CTRL + ALT + e to open the following exception capture dialog box:


Here you can see.. Net debugger can identify all exceptions at runtime, including not only CLR exceptions, but also C ++ exceptions, native exceptions and Win32 exceptions. Expand the root nodes of these four exceptions, and you can see all subclasses representing various exceptions:


All exceptions in. NET Framework are listed by default. You can also add exceptions defined in your code and click Add on the right,


Enter the full name of the exception class in the text box.

After you select an exception, you can specify the action taken by the debugger for the exception:


There are two situations: when an exception is thrown, that is, the throw statement, and the exception that is finally thrown and not processed by the application.

For both cases, you can take three actions: interrupt and enter the debugger, ignore the exception and continue to execute the code, and use the settings of the parent node (Basic exception.

According to the default settings, the debugger will not catch exceptions as long as they are caught in the program. Now, through the settings in the preceding dialog box, you can easily capture and debug exceptions.

In addition, there are many debugging functions in the Debug menu, which I have not read, so I will not talk about.

Well, I have mentioned so much about the debugging functions in vs. net, and I may understand the errors. please correct me. I hope you can share your debugging experience and skills. You can learn from each other and make progress together! :)

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.