Debugging, bug finding and bug avoidance Part 3 Alan Dix www.hcibook.com/alan/teaching/debugging/

Slides:



Advertisements
Similar presentations
VCE SD Theory Slideshows By Mark Kelly Vceit.com Debugging Techniques.
Advertisements

Chapter 5 Errors Bjarne Stroustrup
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Yoshi
CSC241 Object-Oriented Programming (OOP) Lecture No. 9.
Java Review Interface, Casting, Generics, Iterator.
Debugging tutorial. Outline Brief refresher on debugging using Eclipse Logging with log4j – Logging levels – log4j.properties Debugging strategically.
Interactive Media and Game Development Debugging.
DEBUGGING IN THE REAL WORLD : Recitation 4.
Debugging: Catching Bugs ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Interactive Media and Game Development Debugging.
11-Jun-15 Exceptions. 2 Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Debugging CPSC 315 – Programming Studio Fall 2008.
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
. Compilation / Pointers Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Plab – Tirgul 3 Makefiles, Libraries, Debugging and Common Bugs.
Interactive Media and Game Development Debugging.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
1 Gentle Introduction to Programming Tirgul 2: Scala “hands on” in the lab.
Min Kwan Park Test Tech Lead Visual C# QA team. Fail fast To-Dos for fail fast Analyze issues Information for further action Q&A Agenda.
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
C Programming - Lecture 6 This lecture we will learn: –Error checking in C –What is a ‘wrappered function’? –What is a clean interface? –How to earn your.
Debugging !!!  ► Believe it or not, errors happen ► The most frustrating part of programming ► Hunting down an error can be harder and more time consuming.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
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.
How to Design Error Steady Code Ivaylo Bratoev Telerik Corporation
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
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.
Best Practices. Contents Bad Practices Good Practices.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 9: Designing Exceptionally.
Debugging, bug finding and bug avoidance Part 1 Alan Dix
Debugging, bug finding and bug avoidance Part 2 Alan Dix
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
Introduction to Exceptions in Java CS201, SW Development Methods.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
Harvard Mark I Howard Aiken was a pioneer in computing and a creator of conceptual design for IBM in the 1940s. He envisioned an electro-mechanical computing.
Hank Childs, University of Oregon April 13 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Completing the Problem-Solving Process
Eclipse Navigation & Usage.
Testing and Debugging.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
CSE 403 Lecture 17 Coding.
Debugging at Scale.
When your program crashes
Testing, debugging, and using support libraries
Debugging “Why you were up till 2AM”
Barb Ericson Georgia Institute of Technology June 2005
An Introduction to Debugging
debugging, bug finding and bug avoidance Part 4
Workshop for Programming And Systems Management Teachers
Presentation transcript:

debugging, bug finding and bug avoidance Part 3 Alan Dix

outline part 1 – general issues and heuristics part 2 – the system as it is understand and document part 3 – locating and fixing bugs part 4 – bug engineering design to expose, avoid and recover including fail-fast programming

debugging – part 3 locating and fixing bugs isolate error don’t assume anything! secondary errors using tools

locating bugs instrument program (print/log) isolate error - find subsystem simplify program/system

isolate error binary chop original program fails working part  failing part original program fails working part  failing part original program fails working part  failing part problem here! comment out parts of program... good for crashes, syntax/parse errors aim for: – biggest working program – smallest failing program

isolate error use fixed values can’t comment out beginning substitute for calculations/input use value from logging val = complexCalculation(); suspectCalculation(val);

isolate error use fixed values can’t comment out beginning substitute for calculations/input use value from logging // val = complexCalculation(); // print(val); val = fixed_value; suspectCalculation(val);

isolate error binary chop for internal state print out internal values... buggy program print OK print FAIL  print OK print FAIL  problem here!

isolate error unfold methods/functions problem code between two methods Aclas obj; obj.add(3);... class Aclas { private int x; void add(int y) { x = x + y; } }

isolate error unfold methods/functions substitute code from inner method Aclas obj; // obj.add(3); obj.x = obj.x + 3; // param y = 3 // unfold from Aclas... class Aclas { public int x; // remember to change back!...

the real location internal state - OK external behaviour OK latent error exposed latent error actual error

the real location find the real bug locate error location error in code? internal state str = null where produced? bad data NO fix it! YES from file fix other program make robust

don’t assume anything! when all else is impossible... question everything check the obvious print(“x=“+x); y = x; print(“x=“+x+”, y=“+y);

don’t assume anything! capture errors is it what you think? – method / object / function / file may not be: –classpath, linking, inheritance, overload, file upload directory, caching, compile fail print(“x=“+x); f(x);... void f(x) { print(“f(“+x+”)“);... }

don’t assume anything! type conversion overflow before conversion – also beware integer divide C++ more complex conversions Java String concatenation print(“x+1=“+x+1); int secs_yr = 365*24*60*60; long ms_yr = 1000 * secs_yr;

don’t assume anything! platform/language it may not be your fault but be really sure! simplify minimal case differences between platforms: Java AWT event order, NullPointerException bugs / omissions blank/stub bodies for some Java methods JIT / optimisers

secondary errors debugging causes bugs! if capture if ( x != null ) System.out.println(“x is “+x); x.val ++; null print System.out.println(“val = “+x.val); if ( x != null ) x.val ++;

secondary errors - 2 changes in compiler optimisation int x = obj.z; print(x); // forces calculation // x never used again changes in memory layout – C/C++ array overrun bugs etc. – not in Java, but threading changes

secondary errors flushing serious blank screen / core dump... – insert prints – see when they stop out.println(“one”); calculation(); out.println(“two”); calc2(); one ** crash ** doesn’t appear output error here?

out.println(“one”); calculation(); out.println(“two”); out.flush(); calc2(); secondary errors flushing internal buffer for error log output – need to flush in logging code one two ** crash ** output real error here buffer flushed ‘two’ now appears

tools use your compiler thin classes class salary { public int amount; } rename methods/variables int xgetVal() {... } – unexpected use  compile errors use private/protected dynamic errors  static errors

tools use your debugger get to know it! – breakpoints, conditional breaks, – bugs in the debugger! debugger friendly code return complex_expr; int x = complex_expr; return x;

... and when you’ve fixed it do you understand what went wrong? do you know why the fix works? are there similar bugs? can you prevent similar bugs in future?