ITM 352 © Port,KazmanDebugging - 1 ITM 352 Debugging.

Slides:



Advertisements
Similar presentations
Automating Software Module Testing for FAA Certification Usha Santhanam The Boeing Company.
Advertisements

SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
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.
Software Engineering-II Sir zubair sajid. What’s the difference? Verification – Are you building the product right? – Software must conform to its specification.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
Programming Types of Testing.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
CSCI 215 Web Programming II Debugging & Error Handling.
Program Correctness and Efficiency Chapter 2. Chapter 2: Program Correctness and Efficiency2 Chapter Objectives To understand the differences between.
© The McGraw-Hill Companies, 2006 Chapter 9 Software quality.
Program Correctness and Efficiency Chapter 2. Chapter Objectives  To understand the differences between the three categories of program errors  To understand.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Fall 2007CS 225 Program Correctness and Efficiency Chapter 2.
Verification and Validation CIS 376 Bruce R. Maxim UM-Dearborn.
Lecture 8 : PHP Errors & Exceptions UFCFR Advanced Topics in Web Development II 2014/15 SHAPE Hong Kong.
CSCI 5801: Software Engineering
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Testing Tools. Categories of testing tools Black box testing, or functional testing Testing performed via GUI. The tool helps in emulating end-user actions.
Testing. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
1 Shawlands Academy Higher Computing Software Development Unit.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
หลักการโปรแกรม เพื่อแก้ปัญหาโดยใช้คอมพิวเตอร์
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Lecture 11 Testing and Debugging SFDV Principles of Information Systems.
PHP Workshop ‹#› PHP Error Handling. PHP Workshop ‹#› Types There are 12 unique error types, which can be grouped into 3 main categories: Informational.
Programming Lifecycle
Testing Basics of Testing Presented by: Vijay.C.G – Glister Tech.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Debugging. Compile problems Read the whole complaint! Runtime problems –Exceptions –Incorrect behavior.
CSC 230: C and Software Tools Rudra Dutta Computer Science Department Course Introduction.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Cohesion and Coupling CS 4311
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
1 Introduction to Software Testing. Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Chapter 1 2.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
The Software Development Process
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Chapter 8 Error Handling and Debugging. Debugging “When you get frustrated, step away from the computer!”
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
PHP Exception Handling How to handle and create user-defined exceptions Mario Peshev Technical Trainer Software University
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
ITM 352 © Port,KazmanFile I/O - 1 File I/O in PHP Persistent Data.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
ITM 352 Debugging.
Software Testing.
Types for Programs and Proofs
Testing and Debugging.
Chapter 18 Software Testing Strategies
Problem Solving Techniques
Software testing strategies 2
Chapter 15 Debugging.
Chapter 15 Debugging.
Program Correctness and Efficiency
ITM 352 Debugging.
An Introduction to Debugging
Applying Use Cases (Chapters 25,26)
Chapter 15 Debugging.
Chapter 15 Debugging.
Presentation transcript:

ITM 352 © Port,KazmanDebugging - 1 ITM 352 Debugging

ITM 352 © Port,KazmanDebugging - 2 Debugging  Debugging is a “black art”.  What we will discuss:  relation to testing  why debugging is hard  types of bugs  process  techniques  tools  avoiding bugs

ITM 352 © Port,KazmanDebugging - 3 Debugging and Testing  Testing and debugging go together like peas in a pod:  Testing finds errors; debugging repairs them.  Together these form the "testing/debugging cycle": we test, then debug, then repeat.  Any debugging should be followed by a reapplication of all relevant tests, particularly regression tests. This helps avoid the introduction of new bugs.  Testing and debugging need not be done by the same people (and often should not be).

ITM 352 © Port,KazmanDebugging - 4 Why Debugging is Hard  There may be no obvious relationship between the external manifestation(s) of an error and its internal cause(s)!!   Cause and symptom may be in remote parts of the program.   Changes (new features, bug fixes) in program may mask (or modify) bugs.   Symptom may be due to a human mistake or misunderstanding that is difficult to trace.   Bug may be triggered by rare or difficult to reproduce input sequence, program timing or other external causes.           

ITM 352 © Port,KazmanDebugging - 5 Types of Bugs  Types of bugs (gotta love em):  Compile time: syntax, spelling, static type mismatch.  Design: flawed algorithm.  Program logic (if/else, loop termination, select case, etc).  Memory nonsense: null pointers, array bounds, bad types, leaks.  Interface errors between modules, threads, programs (in particular, with shared resources: sockets, files, memory, etc).  Off-nominal conditions: failure of some part of software of underlying machinery (network, etc).  Deadlocks: multiple processes fighting for a resource.

ITM 352 © Port,KazmanDebugging - 6 The Ideal Debugging Process 1. Identify test case(s) that reliably show existence of fault (when possible) 2. Isolate problem to small fragment(s) of program 3. Correlate incorrect behavior with program logic 4. Change the program (and check for other parts of program where same or similar program logic may also occur) 5. Regression test to verify that the error has really been removed - without inserting new errors 6. Update documentation when appropriate Not all these steps need be done by the same person!

ITM 352 © Port,KazmanDebugging - 7 Debugging Techniques, 1  Execution tracing  running the program  print  trace utilities  single stepping in debugger  hand simulation/walkthroughs  Avoiding bugs  Comment as you code  Programming conventions  Reuse of known good code  Modularization  Test small pieces before combining them

ITM 352 © Port,KazmanDebugging - 8 Debugging Techniques, 2  Interface checking  check procedure parameter number/type (if not enforced by compiler) and value  defensive programming: check inputs/results from other modules  documents assumptions about caller/callee relationships in modules, communication protocols, etc  Assertions: include range constraints or other information with data.  Skipping code: comment out suspect code, then check if error remains.

ITM 352 © Port,KazmanDebugging - 9 Debugging with Print - 1  How debugging with “print” (or “echo”) can be made more useful: –print variables other than just those you think suspect (use var_dump() or print_r() ) –print valuable statements (not just "hi\n"). –use exit() to concentrate on a part of a program. –move print through a through program to track down a bug.

ITM 352 © Port,KazmanDebugging - 10 Debugging with Print - 2  Building debugging with print into a program: –print messages, variables in useful places throughout program. –turn debugging messages on or off as needed ini_set('error_reporting', E_ALL); ini_set('display_errors', 'on'); –possibly use a global find/replace to insert/remove debug statements.

ITM 352 © Port,KazmanDebugging - 11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Error handling and logging ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; error_reporting is a bit-field. Or each number up to get desired error ; reporting level ; E_ALL - All errors and warnings (doesn't include E_STRICT) ; E_ERROR - fatal run-time errors ; E_WARNING - run-time warnings (non-fatal errors) ; E_PARSE - compile-time parse errors ; E_NOTICE - run-time notices (these are warnings which often result ; from a bug in your code, but it's possible that it was ; intentional (e.g., using an uninitialized variable and ; relying on the fact it's automatically initialized to an ; empty string) ; E_STRICT - run-time notices, enable to have PHP suggest changes ; to your code which will ensure the best interoperability ; and forward compatibility of your code ; E_CORE_ERROR - fatal errors that occur during PHP's initial startup ; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's ; initial startup ; E_COMPILE_ERROR - fatal compile-time errors ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) ; E_USER_ERROR - user-generated error message ; E_USER_WARNING - user-generated warning message ; E_USER_NOTICE - user-generated notice message ; ; Examples: ; - Show all errors, except for notices and coding standards warnings ;error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT ; ; - Show all errors, except for notices ;error_reporting = E_ALL & ~E_NOTICE ; ; - Show only errors ;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; ; - Show all errors except for notices and coding standards warnings error_reporting =E_ALL & ~E_NOTICE & ~E_STRICT ; Print out errors (as a part of the output). For production web sites, ; you're strongly encouraged to turn this feature off, and use error logging ; instead (see below). Keeping display_errors enabled on a production web site ; may reveal security information to end users, such as file paths on your Web ; server, your database schema or other information. display_errors = On ; Even when display_errors is on, errors that occur during PHP's startup ; sequence are not displayed. It's strongly recommended to keep ; display_startup_errors off, except for when debugging. display_startup_errors = Off

ITM 352 © Port,KazmanDebugging - 12 Avoiding Bugs in the First Place  Coding style: use clear, consistent style and useful naming standards.  Document everything that is non-obvious, from architecture and interface specification documents to comments on code lines.  Hold code reviews.  Program defensively.  Use/implement exception handling liberally; think constantly about anomalous conditions.  Be suspicious of cut/paste.

ITM 352 © Port,KazmanDebugging - 13 Code Reviews  Primary programmer(s) for some piece of code presents and explains that code, line by line.  Audience of programmers experienced in language, code's general domain. Audience may also contain designers, testers, customers and others less versed in code but concerned with quality and consistency.  Review is a dialogue: audience pushes presenters to reevaluate and rationalize their implementation decisions.  Extremely useful: reviews often turn up errors, inconsistencies, inefficiencies and unconsidered exceptional conditions.  Also useful in familiarizing a project team with a member's code.

ITM 352 © Port,KazmanDebugging - 14 Exercise: Debug the Following $product = array('name' => 'small gumball', price => '$0.34'); $tax_rate = 0.045; $total = $product['price'] + $tax_rate * $product['price']; echo "A $product['name'] costs $total";

ITM 352 © Port,KazmanDebugging - 15 Exercise 2: Debug the Following <?php $prices = array(5.95, 3.00, 12.50); $total_price = 0; $tax_rate = 1.08; // 8% tax foreach ($prices as $price) { $total_price = $price * $tax_rate; } printf('Total price (with tax): $%.2f', $total_price); ?>

ITM 352 © Port,KazmanDebugging - 16 Exercise 3: Debug the Following <?php if (array_key_exists($_GET, 'Submit') { $j = ""; foreach($_GET as $key => $i) { if ($j = "Tyler") echo "Found him!"; } else { ?> Name:

ITM 352 © Port,KazmanDebugging - 17 Exercise 3: Print Statements Help! <?php if (array_key_exists($_GET, 'Submit') { $j = ""; print(“The variables submitted via GET: "); foreach($_GET as $key => $i){ print("$key=$j "); if ($j = "Tyler") echo "Found him!"; } } else ?> Name:

ITM 352 © Port,KazmanDebugging - 18 Exercise 4: For Extra Credit To view: Examples/Debug.txt To run: Examples/Debug.php