24
Chapter 11 Chapter 11 How to debug an How to debug an application Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 1

How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Embed Size (px)

Citation preview

Page 1: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Chapter 11Chapter 11

How to debug anHow to debug an application

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 1

Page 2: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Objectives jApplied 1. Use the debugging techniques presented in this chapter to debug any

h dl d i l i l i h li i hunhandled exceptions or logical errors in the applications that you develop.

Knowledge g1. Describe the differences between the three Step commands that you

can use to control the execution of an application. 2. Describe the primary differences between the Autos window, the2. Describe the primary differences between the Autos window, the

Locals window, and the Watch window. 3. Describe the use of the Immediate window. 4 Describe the call stack that’s displayed in the Call Stack window4. Describe the call stack that s displayed in the Call Stack window.5. Explain how you can use the Console class to display information in

the Output window.

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 2

Page 3: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Options dialog boxp g

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 3

Page 4: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Exceptions dialog boxp g

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 4

Page 5: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Future Value application in break modepp

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 5

Page 6: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Four ways to enter break mode y• Force an unhandled exception to be thrown. • Set a breakpoint and run the application.

h h b d b i• Choose the Debug Step Into command or press F11 to begin debugging at the first line of the application.

• Choose the Debug Break All command or press Ctrl+Alt+Break hil h li i i iwhile the application is executing.

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 6

Page 7: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Future Value application ppwith a data tip displayed

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 7

Page 8: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Future Value application with a breakpointpp p

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 8

Page 9: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

How to set and clear breakpoints p• To set a breakpoint, click in the margin indicator bar to the left of

a statement. Or, press the F9 key to set a breakpoint at the insertion point. p

• You can set a breakpoint before you run an application or while the application is in break mode.

• To remove a breakpoint use either technique for setting a• To remove a breakpoint, use either technique for setting a breakpoint. To remove all breakpoints at once, use the Debug Delete All Breakpoints command.

• To disable all breakpoints use the Debug Disable All• To disable all breakpoints, use the Debug Disable All Breakpoints command. To enable all breakpoints, use the Debug Enable All Breakpoints command.

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 9

Page 10: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Commands in the Debug menu and toolbargCommand Toolbar Keyboard Start/Continue F5 B k All Ct l+Alt+B kBreak All Ctrl+Alt+BreakStop Debugging Shift+F5 Restart Ctrl+Shift+F5 Show Next Statement Step Into F11 Step Over F10Step Over F10 Step Out Shift+F11

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 10

Page 11: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Commands in the Code Editor’s shortcut menuCommand Description Run to Cursor Execute the application until it reaches the

statement that contains the insertion pointstatement that contains the insertion point.Set Next Statement Set the statement that contains the

insertion point as the next statement to be executedexecuted.

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 11

Page 12: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Locals window

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 12

Page 13: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

How to use the Locals window• The Locals window displays information about the variables

within the current scope. • To display the Locals window click on the Locals tab or use the• To display the Locals window, click on the Locals tab or use the

Debug Windows Locals command. • If you are debugging a form and you click on the plus sign to the

left of the this keyword the properties and variables of the formleft of the this keyword, the properties and variables of the form are displayed.

• To change the value of a property or variable, double-click on the value in the Value column then type a new value and press thevalue in the Value column, then type a new value and press the Enter key.

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 13

Page 14: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

How to use the Autos window• The Autos window works like the Locals window, but it only

displays information about variables used by the current statement and the previous statement.p

• To display the Autos window, you can use the Debug Windows Autos command.

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 14

Page 15: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

A Watch window

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 15

Page 16: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Immediate window

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 16

Page 17: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Call Stack window

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 17

Page 18: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Call Hierarchy window ywith two methods displayed

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 18

Page 19: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

An Output window that shows debug informationp g

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 19

Page 20: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

An Output window that shows build informationp

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 20

Page 21: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

An Output window with debugging informationp gg g

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 21

Page 22: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

Methods of the Console class that write data to the Output window

Write(string)

WriteLine(string)( g)

Three statements that write data to the Output window

Console.WriteLine( "Entering CalculateFutureValue method..."); Console.WriteLine("month: " + (i+1)); Console.WriteLine("futureValue: " + futureValue);

Code that uses an if statement to control when data is written

if ((i 1)%12 0) // 12 hif ((i+1)%12 == 0) // every 12 months Console.WriteLine("futureValue: " + futureValue);

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 22

Page 23: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Visualizer drop-down menu pin the Locals window

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 23

Page 24: How to debug anHow to debug an application - …enanawa/bcis222/slides/ch11slides.pdf · How to debug anHow to debug an application Murach's C# 2012, ... Show Next Statement ... Mike

The Text Visualizer dialog boxg

Murach's C# 2012, C11 © 2013, Mike Murach & Associates, Inc. Slide 24