Vs sets breakpoints

Source: Internet
Author: User

 

If no debugging function is available, VS can only be regarded as an editor that allows you to compile programs with rich functions. With the debugging function, vs becomes a rare development tool. In fact, judging whether an IDE is good or bad depends mainly on its debugging function.

Vs provides rich debugging experience. You can set breakpoints and execute them one by one. You can set and read variable values during program execution. This article mainly shows how to make full use of the debugging function of vs. It will learn how to set breakpoints, check breakpoints, and pause execution when exceptions are thrown, and how to debug scripting languages like JavaScript, VBScript, and T-SQL running on sqlserver instances.

# Hack 36. set breakpoints

Vs provides a powerful debugger. The most common function is to set breakpoints. When a breakpoint is reached, the program is suspended and enters the interrupt mode; in this mode, developers can check or change program variables. In vs2005, you can even change the program code. VS can set SMART breakpoints. For example, when a specific condition is met or a breakpoint is triggered for a certain number of times, the program is suspended.

(1) enter the interrupt mode when a specific row is reached

In fact, it is a common method to set breakpoints. Click a margin on the left of this line and a red circle will appear. Its name is breakpoint. If the breakpoint is removed, click it again, in fact, you can switch back and forth with the shortcut key F9. Use Ctrl + Shift + F9 to delete all breakpoints.

This book says that you can create a breakpoint through the create breakpoint dialog box. The shortcut is Ctrl + B, but I only bring up a dialog box for adding a function breakpoint, which is different from the one mentioned in the book, maybe vs2005 has changed.

This dialog box has four pages:

Function: Used to add a breakpoint to a specific row of a function;
File: Used to add a breakpoint to a specific line of a file in the solution;
Address: Set a breakpoint for a specific memory address. It is usually used to debug unmanaged code;
Data: Used to add breakpoints to a variable. When the variable changes, the breakpoint is triggered. Data breakpoints can only be used when debugging unmanaged code.

It may be that vs2005 has indeed modified it and provided the function breakpoint settings. In addition, there is another new data breakpoint, but it is always unavailable and may be relatively intelligent, it can distinguish whether the current code is not managed. I personally think that there is no need for file breakpoints. In fact, they are similar.

(2) When a function is called, it enters the interrupt mode.

In vs2005, you can call up the breakpoint Setting Dialog Box by pressing CTRL + B and specify the function name. The format is as follows: namespace. Class Name. method name. If you only specify the method or Class Name and method name, vs lists them intelligently for your selection.

You can also use the call Stack window to configure the debugger to interrupt a special function. In debug mode, choose debug> WINDOW> call stack menu, this window lists all functions on the call stack. Right-click the function name and select the insert breakpoint option. It is convenient to set breakpoints when debugging recursive functions.

(3) view breakpoints

You can call up the breakpoint window by pressing CTRL + ALT + B. The current breakpoint list can be provided and breakpoint, deletion, addition, and editing can be disabled or enabled. If you want to edit the breakpoint attribute, you can right-click the "location" item in the menu. It is similar to creating a file breakpoint in the breakpoint, many methods that have changed from multiple tab pages in one window to direct.

(4) conditional interruption

You can perform operations in the breakpoint window and select "condition" from the context menu of the breakpoint. The interrupt condition expression can be any expression that complies with the debugger expression standard, including Relational operators and non-Relational operators +,-, and. Both variables and object attributes can be part of an expression. The list of valid expressions of the complete tuner is as follows:

Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/vsdebug/html/vchowusingexpressionsindebugger. asp

(5) control the number of hit points

You can use the breakpoint window to set the number of hits in the context menu of the breakpoint. It can be set to always interrupted, greater than or equal to, equal to, or several times. It is useful for specific cyclic factor values in a loop.

# Hack 37. Check for breakpoint faults

The breakpoint sometimes cannot work normally. The Microsoft developer vs debugger provides an online small web program to help solve the breakpoint problem. Using this tool, you can obtain some suggestions for solving problems through interactive Q &.

Http://www.controlav.com/bphelper

# Hack 38. Custom vs Exception Handling

There are two ways for vs to enter the interrupt mode: first, breakpoint; second, exception. You may want to switch to the interrupt mode when an exception occurs, regardless of whether it is processed or not. VS can be customized to quickly enter the interrupt mode when a specific exception occurs.

(1) usage exception dialog box
 
The "debug-> exception" dialog box or press CTRL + ALT + e to call up the exception dialog box. This dialog box allows you to specify vs behavior when a specific type of exception occurs, the default action is to continue when an exception is thrown. If the exception is not processed, the system enters the debugger. To modify an exception type, you only need to select it in the exception tree list and customize the single-choice button to specify the behavior of the debugger.

Note: modifying a behavior of an exception type affects its derivative behavior of the exception type.

(2) adding a custom exception

The exception dialog box can be used to change the debugger action for system exceptions, but you may want to define the action for your own exceptions. To achieve this goal, select the top-level item of the exception tree, and click "add" to add the item. Enter the full name, including the namespace, when entering the Exception name, case sensitive. You can delete custom exceptions.

(3) quickly find the Exception name

The exception dialog box allows you to quickly locate an exception by its name.

# Hack 39. debug the script

VS has powerful debugging functions and is also very powerful in web projects. It not only targets ASP. NET, but also has strict debugging functions for JavaScript and VBScript scripts. This section describes how to set vs to allow you to debug scripts in the browser.

To debug the script in the browser, take IE6 as an example. You must first enable the script debugging function of the browser, as shown below:

A. Open IE;
B. Select "tools-> Internet Options", select the "advanced" page in the window, and remove the check box before "Disable script debugging;
C. Restart the browser and you will find an additional "script debugging program" under the "View" menu of the browser ";

Once the script debugging function is enabled, You can debug the script in multiple ways:

The first is to use two sub-menu items under "script debugging program". You can select "open" to open the debugger and set the breakpoint; another option is to interrupt the next statement, which causes the debugger to run into the next statement.

The second is to start debugging from inside vs, use vs to open the WEB Project and start the debugger. After debugging is started, you need to access the document window. You can enable it by selecting "debug-> window-> document window" or pressing CTRL + ALT + N. This window shows the list of currently running Web documents, usually containing only one page, there may be more than one document when using the frame framework. Select the document to be debugged. The HTML output of that document is displayed as a normal HTML file. You can set breakpoints and debug them.

 

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.