Debugging “Why you were up till 2AM”

Slides:



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

Debugging Introduction to Computing Science and Programming I.
Debugging CPSC 315 – Programming Studio Fall 2008.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
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.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
String and Lists Dr. José M. Reyes Álamo.
Debugging with Eclipse
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
14 Compilers, Interpreters and Debuggers
BIT116: Scripting Lecture 06
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Dept of Computer Science University of Maryland College Park
Logger, Assert and Invariants
Introduction To Repetition The for loop
CSE 374 Programming Concepts & Tools
CS1101X Programming Methodology
What to do when a test fails
Testing and Debugging.
Programming Mehdi Bukhari.
Loop Structures.
Debugging CMSC 202.
Chapter 5: Loops and Files.
Scripts & Functions Scripts and functions are contained in .m-files
Control Structures
Barb Ericson Georgia Institute of Technology Dec 2009
Recursion 12-Nov-18.
Manipulating Pictures, Arrays, and Loops part 2
File Handling Programming Guides.
Conditions and Ifs BIS1523 – Lecture 8.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Recursion 2-Dec-18.
Recursion 2-Dec-18.
<INSERT_WITTY_QUOTE_HERE>
Teaching London Computing
Introduction to Computer Programming
Tonga Institute of Higher Education
Recursion 29-Dec-18.
Coding Concepts (Basics)
Debugging at Scale.
String and Lists Dr. José M. Reyes Álamo.
Debugging Taken from notes by Dr. Neil Moore
DEBUGGING CS2110.
Chapter 6: Repetition Statements
Debugging Taken from notes by Dr. Neil Moore
Homework Reading Programming Assignments Finish K&R Chapter 1
Barb Ericson Georgia Institute of Technology June 2005
Tonga Institute of Higher Education IT 141: Information Systems
An Introduction to Debugging
Recursion 23-Apr-19.
Tonga Institute of Higher Education IT 141: Information Systems
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
Peer Instruction 4 Control Loops.
Barb Ericson Georgia Institute of Technology Oct 2005
CSC1401 Manipulating Pictures 2
Chapter 3 Debugging Section 3.4
Arrays.
Review of Previous Lesson
slides created by Ethan Apter
Exceptions 5-Jul-19.
Presentation transcript:

Debugging “Why you were up till 2AM” Dan Fleck Fall 2007

Debugging Definition: The process of finding problems (bugs) in programs and removing them

Why do we call it debugging? 1947, one of the first computers the Harvard University Mark II Aiken Relay Calculator On the 9th of September, 1947, when the machine was experiencing problems, an investigation showed that there was a moth trapped between the points of Relay #70, in Panel F. The operators removed the moth and affixed it to the log. The entry reads: "First actual case of bug being found." - http://www.jamesshuggins.com

General Steps Recognize that a bug exists Isolate the source of the bug Identify the cause of the bug Determine a fix for the bug Apply the fix and test it

Isolating source of the bug Once found, and understood, most bugs are easy to fix. We will concentrate only on finding the bug

Confirm your beliefs Finding your bug is a process of confirming the many things you believe are true, until you find one which is not true You believe that at a certain point in your source file, a certain variable has a certain value You believe that in a given if-then-else statement, the “else” part is the one that is executed You believe that when you call a certain function, the function receives its parameters correctly

Confirm your beliefs So the processing of finding the location of a bug consists of confirming all these things! Check everything! Okay… How?

One way Put lots of print statements in at each point that says “I am in method X with parameters set to Y,Z” Note: If you do this, be able to turn them on/off easily! Boolean DEBUG = true; If (DEBUG) System.out.println…..

Often a better way Use the debugger Set a breakpoint at a point in the code Step through the code Look at the variables (local and class variables) to see ones that are not as you expected The debugger is usually better/faster… but print statements are also easy to turn on/off as a whole to make a DEBUG mode for your program. Which is often useful.

The Most Important Thing To do ANY debugging you must understand what the program should do What each method should do What each if statement should do If your beliefs are wrong, confirming your beliefs will not help!

The Most Important Thing Add beliefs into your code… beliefs are otherwise known as COMMENTS!

Lets work some examples See Netbeans debugging project Fibonacci - Compile time problems DebugMe - Use the debugger to find the problems WordAnalyzer - Test 1 - Use print statements Test 2 - Use print statements Test 3 - Use the debugger

My Presidents aren’t sorted by party What are your beliefs? Or more specifically, what are some hypothesis that you should confirm? You’re not calling the sort routine at all CLASS ENDED HERE.

My Presidents aren’t sorted by party What are your beliefs? Or more specifically, what are some hypothesis that you should confirm? You’re not calling the sort routine at all The sort is not “seeing” every president The sort is sorting by something other than party The array is not getting updated by the sort The array is getting sorted, then resorted by something else

My Presidents aren’t sorted by party Confirming your beliefs You’re not calling the sort routine at all: Confirm: put in a print statement inside the sort routine saying “DEBUG: sorting begun” The sort is not “seeing” every president Confirm: put in a print statement to print out every president the sort loop “sees” The sort is sorting by something other than party Write code that says “sorted president (Reagan, Rebulican) after (Clinton, Democrats)”

When I print I see duplicate Presidents During the sort I don’t add any new data Confirm: Check the length of the data before/after the sort During the print, I only print each value once Confirm: compare the length of the list to the number of times you issue a print statement assert (length == countPrints) : “Too many ”+length+”:”+countPrints;

Suduko cannot find a solution Confirm there is a solution Confirm you’re reading the values in correctly from the grid Confirm you’re able to access the correct value using index -> row, col conversion Confirm your List can move both forward and backward correctly Confirm you are setting / clearing BitSets appropriately (at various points print out the BitSets for a row/col/box and the grid and compare

Suduko cannot find a solution Confirm you’re able to find the “next” value correctly Confirm you’re updating the SudokuList appropriately ….

COMMENT YOUR CODE! COMMENT! COMMENT! COMMENT! COMMENT! COMMENT!

Whoa there… I can’t even compile! First, try never to get here. Compile early, compile often. If you can’t compile at any point STOP… fix the code before adding any new code. Review the compiler error, read it carefully Check your book and online resources for examples and see what may be wrong Ask questions on WebCT, to your TA or Professor.

The Most Important Thing (again) Add beliefs into your code… beliefs are otherwise known as COMMENTS! Or if you can… java assertions!

More info: http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html Java Assertions assert Expression1 : Expression2 ; If Expression 1 is not true, throw an error with String in Expression2 assert x<4 : “Invalid x value ”+x ; Assertions can be enabled during debugging and disabled for production use (increasing performance) java -ea edu.gmu.MyClass // enable java -da edu.gmu.MyClass // disable More info: http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

References http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/Debug.html#tth_sEc2 http://en.wikipedia.org/wiki/Debugging