Debugging applications, using properties Jim Warren – COMPSCI 280 S2 2015 Enterprise Software Development.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
© 2002 ComputerPREP, Inc. All rights reserved. Excel 2000: Customizing Excel and Using Macros.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
BIM313 – Advanced Programming Techniques Debugging 1.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Finding and Debugging Errors
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
CHAPTER SIX.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
A First Program Using C#
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Debugging Projects Using C++.NET Click with the mouse button to control the flow of the presentation.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Debugging Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
VB – Debugging Tools Appendix D. Why do we need debugging? Every program has errors, and the process of finding these errors is debugging Types of errors.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Debugging Visual Basic.NET Programs ► ► Use debugging tools ► ► Set breakpoints and correct mistakes. ► ► Use a Watch and Local window to examine variables.
Debugging Xin Tong. GDB GNU Project debugger Allows you to see what is going on `inside' another program while it executes or crashed. (Faster than printing.
Centric features In this presentation… –macro capabilities more sophisticated functionality –advanced macro features Inspector Debugging error trapping.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
CSC 1201 LAB RULES Nouf Aljaffan (C) CSC 1201 Course at KSU.
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
A variable is a name for a value stored in memory.
Chapter 2: The Visual Studio .NET Development Environment
Programming in visual basic .net Visual Basic Building Blocks
ME 142 Engineering Computation I
How to debug an application
Debugging Dwight Deugo
Testing and Debugging.
Microsoft Access Illustrated
Using Visual Studio with C#
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
CIS16 Application Development Programming with Visual Basic
Testing, debugging, and using support libraries
Debugging Visual Basic Programs
Debugging Dwight Deugo
Debugging with Eclipse
Presentation transcript:

Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development

Learning Objectives COMPSCI2802  To be able to take advantage of the features of an IDE such as VS in debugging your applications  Including setting break points and watch windows and working effectively in break mode  To understand the value of, and be able to apply Properties to improve the software quality of classes that you define  Additional information on debugging in VS at:  Given where you’re up to with Assignment 2, I thought debugging might be a popular topic!

Three Types of Errors in Coding COMPSCI2803  Syntax errors  Syntax Error (compile error) is a programming mistake that violates the rules of the language.  VS points out syntax error while you type program statements  VS prompts if you attempt to run a program before you fix all the syntax errors.  Run-time errors  A run-time error is a mistake that causes a program to stop unexpectedly during execution  Logic errors  A logic error is where the program runs, but a programming mistake makes the program code produce the wrong results.  Debugging efforts are particularly focused on tracking down the logic errors, but also help with understanding sources of run-time errors

Debugging COMPSCI2804  The Visual Studio debugger is a powerful tool that allows you to observe the run-time behavior of your program and locate logic errors.  With the debugger, you can break, or suspend, execution of your program to  examine your code,  evaluate and edit variables in your program  The debugger works with several files in order to cross-reference memory to the source files used to build the assembly  A program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program.  To debug your code, the debugger needs PDB files containing symbols for your application

Debugger Settings COMPSCI2805  You can specify various settings for debugger behavior,  including how variables are displayed,  whether certain warnings are presented,  how breakpoints are set, and  how breaking affects running programs.  To set debugger options  Choose Tools -> Options.  Expand Debugging

Debugger Roadmap COMPSCI2806  Code Stepping  Step Into  Step Over  Step Out  Breakpoints  Insert Breakpoint  Break at Function  Break Mode  Run to Cursor  Call Stack Viewing Data in the Debugger DataTips Variable Windows  Locals  Autos  Watch  Quick Watch Immediate Window Hit Counts

Code Stepping 7  One of the most common debugging procedures is stepping:  executing code one line at a time.  Choose Debug -> Step Into/Over/Out  Step Into/Over  Instruct the debugger to execute the next line of code  Note:  Step Into executes only the call itself for a function call, then halts at the first line of code inside the function.  Step Over executes the entire function, then halts at the first line outside the function.  Step Out resumes execution of your code until the function returns, then breaks at the return point in the calling function. Stepping controls Stop debugging

Breakpoints COMPSCI2808  Breakpoints tell the debugger that an application should break – i.e. pause execution, at a certain point.  When a break occurs, your program and the debugger are said to be in break mode  To set a simple breakpoint  Click on a line of executable code in the source window  Choose Debug->Toggle Breakpoint, or  Right-click, choose Breakpoint->Insert Breakpoint  To start/stop debugging  Choose Debug->Start/Stop Debugging  To stop debugging and restart  Choose Debug->Restart.  Note: Restart stops the current debugging session and restarts the project from the beginning.

Breakpoints (con’t) COMPSCI2809  To insert a function breakpoint  In a source window, click on the name of a function.  Choose Debug->New Breakpoint->Break at Function.  To set a breakpoint on a function call  In the Call Stack window, right-click the function call  Choose Insert Breakpoint  To delete a breakpoint  In the Breakpoints window, right-click on a breakpoint, and choose Delete from the shortcut  To disable/enable a breakpoint  Right-click on a line containing the breakpoint  Choose Disable/Enable Breakpoint from the shortcut menu

Break Mode COMPSCI28010  Breaks execution:  When execution reaches a breakpoint  Or when an unhandled exception occurs  Break execution manually at any time  Choose Debug->Break All  Break at the location where the cursor is set.  In a source window, right-click on a line of executable code, and  Right-click, choose Run to Cursor  Break at a specified function  Choose Debug->Windows->Call Stack  In the Call Stack window, right-click the function name and choose Run To Cursor from the shortcut menu.

Viewing Data in the Debugger COMPSCI28011  The Visual Studio debugger provides a variety of tools for inspecting and modifying the state of your program.  Most of these tools function only in break mode.  DataTips  Variable Windows  Locals  Autos  Watch  QuickWatch dialog box  Immediate Window  Hit Counts

Data Tips COMPSCI28012  Conditions  DataTips work only in break mode, and  Only with variables that are within the current scope of execution.  To display a DataTip  Enter break mode  In a source window, place the mouse pointer over any variable in the current scope.  Expanding Information  With enhanced DataTips, you can expand an array, structure, or object to view its members.  To expand a variable to see its elements  Hover the mouse cursor over the + sign that precedes the variable name.  In the case of variable assigned a LINQ query, this may cause the query to be executed

Variable Windows COMPSCI28013  The debugger provides a number of variable windows for displaying, evaluating, and editing variables and expressions.  Each variable window includes a grid with three columns: Name, Value, and Type.  The Name column contains variable names or expressions.  The Value and Type column display the value and data type of the variable or expression.  Variable windows  Locals  Autos  Watch

Locals Windows COMPSCI28014  Locals Window  It displays variables local to the current context or scope.  Usually, this means the procedure or function you are currently executing.  Note: the debugger populates this window automatically.  To open the Locals window  Enter break mode  Choose Debug->Windows->Locals  To expand a variable to see its elements  Click with the mouse on the triangle arrow that precedes the variable name.

Autos Windows COMPSCI28015  Autos Window  It displays variables used in the current line of code and the preceding line of code.  Again, the debugger populates this window automatically.  To open the Autos window  Enter break mode  Choose Debug->Windows->Autos

Watch Windows COMPSCI28016  Watch window  It is where you can add variables whose value you want to watch.  Note you can undock the window from its default position  You can add variables (e.g. “j”) or any valid expressions (e.g. “(j+i)*2”)  You can also interactively edit/change the value of a variable in a row of a watch window  You can open up to four watch windows, numbered Watch 1, Watch 2, Watch 3, and Watch 4.  To open the watch window  Enter break mode  Select the variable you want to add from the Code editor, right click on it, and click the Add Watch command  Or choose Debug->Windows->Watch 1

QuickWatch dialog box Handout15COMPSCI28017  The QuickWatch dialog box is similar in concept to the Watch window, but QuickWatch can display only one variable or expression at a time.  Useful when you want to take a quick look at a variable or expression without bringing up the Watch window.  QuickWatch is a modal dialog box, you have to close it before you can continue debugging  To open the QuickWatch window  Enter break mode  Select the variable you want to add from the Code editor, right click on it, and click the Quick Watch command to open the QuickWatch Dialog box  To add a QuickWatch expression to the Watch window  Click the Add Watch button  Enter the expression and press Enter.  To make it really ‘quick’ use the Ctrl+Alt+Q shortcut

Immediate Window COMPSCI28018  The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth.  It allows you to enter expressions to be evaluated or executed by the development language during debugging.  To display the Immediate window  Enter break mode  Choose Debug->Windows->Immediate.  Type the following in the Immediate window in a break mode  To modify a variable using the Immediate window  Enter break the Immediate window  Type “age=15” and press Enter  Watch the changes in the Watch 1 window ?age ?Message ?age+3 age=15

Hit counts COMPSCI28019  Can further tailor the behaviour for watching a line of code  Right-click a break point and select Hit Count…  Can set the break point to only be invoked when the line of code has been reached a certain number of time (or on a multiple of n times)

Fields & Properties  Fields  Fields store the data a class needs to fulfill its design  Fields should (generally) be declared as Private.  Properties  Properties are retrieved and set like fields, but are implemented using property Get and property Set methods, which provide more control on how values are set or returned.  It helps isolate your data and allows you to validate values before they are assigned or retrieved.  Property has Public access  The value keyword is used to define the value being assigned by the set method.  Property can be read-only (with the Get portion only) or write-only (with the Set portion only) COMPSCI class MyPoint { private int _x; private int _y; } Attributes represent the internal “state” of a given instance of this class. public int X { get { return _x; } set { if (value > 0) _x = value; } public int Y { get { return _y; } Read-only property

Fields Vs Property COMPSCI  Use property when:  You need to control when and how a value is set or retrieved.  The property has a well-defined set of values that need to be validated.  Setting the value causes some perceptible change in the object's state, such as an IsVisible property.  Setting the property causes changes to other internal variables or to the values of other properties.  A set of steps must be performed before the property can be set or retrieved.  Use field when:  The value is of a self-validating type.  Any value in the range supported by the data type is valid. This is true of many properties of type Single or Double.  The property is a String data type, and there is no constraint on the size or value of the string.

Auto-implemented properties  Auto-implemented properties make property declaration more concise when no additional logic is required in the property accessor methods  Compiler creates a private, anonymous backing field that can only be accessed through the property's get and set accessors COMPSCI28022 public class emp { public decimal salary { get; set; } } public class emp2 : emp { public new decimal salary { get {return base.salary;} set { if (value >= 0) base.salary = value; else Console.WriteLine("Cannot accept negative salary!"); } Auto-implemented accessors for anonymous private variable (the ‘backing field’) A child class can override the parent property and selectively reuse the parent (‘base’) class get and set methods

Conclusion… and where we’re up to  IDEs offer a range of features for debugging  Breakpoints  Tooltip and window based review of variables  Windows to watch variables  Ability to manipulate variables in the running program in the Immediate window  Properties provide a logical layer over fields  You should be pretty darn focused on Assignment 2  Next lecture we flesh out C# language features around exception handling COMPSCI 28023