Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.

Slides:



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

Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
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.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Chapter 11 Debugging and Handling Exceptions
Programming Types of Testing.
Lecture Roger Sutton 21: Revision 1.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
Lecture Roger Sutton CO331 Visual Programming 1: Module introduction and the programming environment 1.
Lecture Roger Sutton CO331 Visual Programming 19: Simple file i/o Exceptions – Error handling 1.
Well-behaved objects Debugging. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection.
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
How to Debug VB .NET Code.
Visual Basic Debugging Tools Appendix D 6/27/20151Dr. Monther Aldwairi.
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Fundamentals of Python: From First Programs Through Data Structures
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Fundamentals of Python: First Programs
Using a Debugger. SWC What is ”debugging”? An error in a computer program is often called a ”bug”… …so, to ”debug” is to find and get rid of errors in.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
Programming Translators.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Tutorial 11 Using and Writing Visual Basic for Applications Code
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
General Programming Introduction to Computing Science and Programming I.
Debugging Projects Using C++.NET Click with the mouse button to control the flow of the presentation.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Object Oriented Software Development 8. Exceptions, testing and debugging.
ME 142 Engineering Computation I Debugging Techniques.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Data Structures and Debugging Dr. Nancy Warter-Perez June 18, 2003.
Lecture 4 Programming Technique Programming Appreciation.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Chapter 7 Debugging Techniques Xiaogang Su Department of Statistics University of Central Florida.
CS320n –Visual Programming More LabVIEW Foundations.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
© 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,
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Chapter – 8 Software Tools.
Debugging What coders (programmers) do to find the errors (“bugs”) in their own programs “Bugs” – Admiral Grace Hopper, developer of the world’s first.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Component 1.6.
Debugging and Handling Exceptions
Testing and Debugging.
13 Enhancing the Wage Calculator App
Computer Programming I
Variables and Arithmetic Operations
Tonga Institute of Higher Education
Software Development Process
Software Development Environment, File Storage & Compiling
Chapter 15 Debugging.
Presentation transcript:

Lecture Roger Sutton CO331 Visual programming 15: Debugging 1

CO331 Visual Programming Introduction In constructing a program, the code produced by the programmer, usually referred to as source code, will progress through three stages: 1.Compilation – A programming language usually comprises  a set of reserved words, i.e. sequences of characters, that have a particular interpretation, and  a set of rules governing the acceptable input of other characters. This is referred to as the language’s syntax. Once a program has been written, it is submitted to a compiler. This is a program which examines the code character by character to ensure that it complies with the language’s syntax. If not, the compiler produces a report usually indicating the point at which the code started to deviate with a possible explanation. Such instances are called compilation or syntax errors. 2

CO331 Visual Programming Introduction – cont’d Working within an IDE, code is usually checked as it is typed in. In such cases the code is being interpreted as opposed to compiled – hence the term interpreter. Once the source code has compiled without error it is converted into a more machine readable form called object or binary code. In the process it will be noted whether any library methods or programmer-written classes are required. 2.Linking Here any necessary library methods or programmer-written classes are incorporated. If the code is being interpreted and these are not available, it will be detected early on, following the syntax check. 3.Running When the source code has been compiled and linked successfully, it is loaded to produce machine code and the program can then be run. 3

CO331 Visual Programming Errors ‘That’s not a bug it’s a feature !’ Syntax Compilation Errors - coding that does not conform to the language specification. Run-time Although syntax error-free, program may fail as the result of a situation developing that is inconsistent with program constraints or which cannot be handled by the program. Logic Errors in the program design that produce unacceptable results. 4

CO331 Visual Programming Error detection Understanding how your program works is essential in the search for errors. The effort required is often reduced substantially with the aid of a debugger. A debugger is a facility of the IDE and is a program that lets programmers execute their software one step at a time; allows them to stop and start at different points, and to examine the value of the variables. 5

CO331 Visual Programming Syntax Errors To ensure the greatest possible error checking is brought into action, it is recommended that the options Explicit and Strict are switched on. Explicit: ensures that the compiler checks that all variables have been declared. Strict: requires the compiler to check that all data conversions have been carried out explicitly. 6

CO331 Visual Programming Syntax Errors – cont’d The zig-zag underlining indicates a syntax error. Hovering over the error provides some indication of the nature of the error. E.g. Correcting the variable name ‘num’ and substituting ‘Text’ for ‘value’ produces: Requires: 7 n = CInt(txtNumber.Text)

CO331 Visual Programming Run-time errors As a program runs, variables usually take a number of different values - the program is said to be in different states. Sometimes the values of variables become inconsistent, i.e. they might not comply with previous declarations or it is not possible to perform required operations. E.g. A value assigned to a variable is not of the correct type An array subscript value is outside the declared range An attempt is made to divide by a variable whose value is zero An attempt is made to find the square root of a negative value These are run-time errors since they become apparent when the program is run in particular circumstances. A program might appear to run satisfactorily for one set of input but ‘crash’ (break, fall-over) for another; hence the need for methodical testing. 8

CO331 Visual Programming Run-time errors – cont’d E.g. Entering a value 9 in the textbox produces: Clicking Break and hovering over the array subscript produces : 9 The upper bound of the array is declared to be 8. So is the declaration wrong or is there an error in the program logic?

CO331 Visual Programming Debugging facilities The VB IDE debugger allows a program to be executed one step at a time and to examine the changing values of the variables. Breakpoints – allow a program to be halted at specified points. Breakpoints are introduced by clicking the margin, level with the line at which the program is to halt. Values of variables can then be examined by hovering over the relevant variable. Execution is restarted by clicking the Continue arrow. 10

CO331 Visual Programming Debugging facilities – cont’d Breakpoints are removed by re-clicking the margin or, alternatively, by selecting the Clear All Breakpoints in the Debug menu Watch Window - sometimes it is useful to examine several variables together. Once the program has halted, variables can be added to a watch window panel by selecting the variable, right-clicking and selecting Add Watch. The variables name, value and type are then displayed in the panel to allow continuous monitoring. 11

CO331 Visual Programming Debugging facilities – cont’d Single stepping Alternatively a program may be executed one step at a time by selecting Step Into from the Debug menu or using the function key: It is usual to use breakpoints and single stepping together to focus on particular sections of code. The yellow arrow and highlighting indicates the next line to be executed. Changes of value are shown in red in the watch window. 12

CO331 Visual Programming Debugging facilities – cont’d Single stepping – cont’d Two other stepping processes are available:  Step over: When a method call is reached, single-stepping is suspended for the called method to be executed and then continued with the step immediately following the call.  Step Out: Finishes executing the method and returns control to the step immediately following the call. 13

CO331 Visual Programming Debugging strategy The debugger is a useful facility but should be used in a methodical fashion. E.g. 1.From the symptoms observed, infer where the bug lies – possibly within 2 or 3 methods 2.Place breakpoints at the entry and exit of suspected methods 3.Run the program. When the program stops examine the values of the methods’ arguments and subsequently any return value. In this way the method containing the error may be identified. 4.Re-run the program stopping at the erroneous method and then single step through it until the cause has been pin-pointed. 14

CO331 Visual Programming 15 Summary Compilation process and error types  Compiling – syntax errors  Linking  Running – run-time, logic errors Explicit and Strict Debugger  Zig-zag line, hovering  Breakpoints  Stepping process: into, over, out  Watch window Debugging strategy