分享
 
 
 

Using the Debugger

王朝asp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

Using the Debugger

Visual Studio .NET provides a useful toolbar you can use while debugging but

doesn't display it by default. In this section, you'll see both how to load

the Debug toolbar and how to get started debugging.

Three Modes of Existence

While creating applications in Visual Studio .NET, you'll find yourself in

one of three "modes." Each mode has a specific function, and knowing which

mode you are in is important. The three modes are as follows:

Design mode. In this mode you build your user interface and write your code.

Break mode. In this mode you can single-step through code, view and modify

variable values, and inspect memory.

Run mode. In this mode you are, effectively, testing your application

within the Visual Studio .NET environment.

You can determine which mode you are in by looking at the Visual Studio

.NET title bar. At the end of the other information in the title bar, you

will see one of the following: [design], , or [break]. Get used to looking

at the title bar for information on what mode you are currently in. There

are things you can and can't do in each mode.

TIP

What can't you do in design mode? You can't use the Immediate window to

test out code or expressions as you could in VB6. In break mode, you can't

modify code, as you could in VB6. If you're coming to VB .NET from VB6, you

may find some of these new limitations frustrating and confusing.

It is Break mode we'll focus on in this chapter, because it's in Break mode

that you'll be able to single-step through code and debug the code as it

runs.

Finding the Debug Toolbar

Visual Studio .NET provides many options for debugging your code, and

although you can use menu items or keyboard shortcuts, you may find the

Debug toolbar the easiest way to work. To make sure the Debug toolbar is

visible, right-click the toolbar area of the Visual Studio .NET IDE and

then select the Debug toolbar from the list of available toolbars. Once

you've made the selection, you will see the toolbar shown in Figure 9.1.

Figure 9.1. The Debug toolbar gives you most of the debugging functionality

without needing to dig into keyboard shortcuts or menu items.

From this toolbar, you will be able to run, stop, and pause the

application. You will also be able to perform other functions related to

debugging your application. From the left, the tools are as follows:

Start. Runs the project.

Break All. Pauses the project.

Stop Debugging.

Restart. Continues running the application from the current location.

Show Next Statement. Jumps to the next statement that will be executed

while single-stepping through code.

Step Into. Single-steps into procedures in your code.

Step Over. Single-steps, running procedures full speed.

Step Out. Runs full speed from the current location back to the procedure

that called the current procedure.

Hexadecimal Display. Toggles the display of all values in the QuickWatch

window between decimal and hexadecimal formats.

Breakpoints/Immediate. Displays and then toggles between displaying the

Breakpoints and Immediate windows.

You will learn more about these and other tools in this chapter.

TIP

While in Break mode, you have other tricks up your sleeve, as well. You can

select the next line of code you'd like to execute, for example, by simply

dragging the current line indicator to a different line (within the same

procedure). You'll find debugging in Visual Studio .NET to be a very

powerful experience!

Invoking the Debugger

To begin debugging your application, select Debug, Step Into or the Debug,

Step Over menu options (or the corresponding toolbar items). The hotkeys

for each of these may be different, depending on how you customized your

profile when you first ran Visual Studio .NET. For example, if you are set

up as a Visual Studio developer, the hotkeys for these two commands will be

F11 and F10, respectively. If you are set up as a Visual Basic developer,

however, you will use F8 and Shift+F8, respectively.

TIP

No matter how hard you try, debugging from within an ASP.NET application

simply doesn't work unless you press F5 (or use the Debug, Start menu item)

to begin running your code. (Your application must have a start page in

order for this to work. Right-click the correct page, in the Solution

Explorer window, and select Set as Start Page from the context menu.) There

are other ways to accomplish the same goal, but this is how we've gotten

debugging to work. Certainly, selecting a page, right-clicking, and

selecting the Build and Browse or View With… context menu item will not

allow you to debug. In addition, before you can debug an ASP.NET project,

you must set the project properties correctly. Right-click the project in

the Solution Explorer, select Properties from the context menu, and verify

that on the Configuration Properties, Debugging page, the ASP.NET Debugging

check box is selected. Otherwise, you'll never be able to debug the current

project.

Stepping into Code

Single-step mode executes each statement in your code, one at a time. You

can step through code by clicking the Step Into button on the Debug toolbar

or by selecting Debug, Step Into.

If, while debugging, you encounter a user-defined procedure during

single-step execution, you will single-step into each statement within that

procedure before returning to the called procedure.

Stepping over Code

Stepping over code is very similar to stepping into code, except that

rather than executing every statement within a called procedure, stepping

over code executes the entire procedure, while your debugging session never

leaves the current procedure. This allows you to quickly step over

procedures that you've already determined to be error free.

Use procedure step mode by clicking the Step Over toolbar button or

selecting Debug, Step Over.

TIP

We're not going to attempt to describe the keystrokes associated with each

debugging toolbar item, because the keystrokes depend on the profile you've

selected. Instead, check the Debug menu for each item and determine the

keystrokes from the tips provided on the menus.

WARNING

If you are moving from Visual Basic 6.0, you may be used to changing your

code while in Break mode and then continuing with these changes in place.

Visual Studio .NET doesn't make this possible, at least not in this first

release. You must stop your application, make your changes, and then

restart your debugging session in order to test your changes.

Entering Break Mode

When your application is running, you may invoke the debugger and enter the

Break mode in several ways:

Press Ctrl+Break while your code is running.

Place a Stop statement in your code. (Be wary of this technique! We'll have

more discussion of this later in the chapter.)

Set a breakpoint in your code.

Select Debug, Step Into to run the program.

The Stop Statement

If you want to place a permanent breakpoint into your code, place a Stop

statement at the location where you want the breakpoint. You'll want to

make sure you remove any Stop statements prior to distributing your

application梕ven when you create the release version of your application,

Stop statements drop into Break mode (or they halt the application, if the

debugger isn't available).

One good way to make sure any Stop statements are removed from your code at

release time is to always surround them with conditional compilation

directives that only include the statements if you've built a Debug build,

like this:

Private Sub BreakPointsSample()

Dim intValue As Integer

#If DEBUG Then

Stop

#End If

intValue = 10

Proc1()

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有