Debugging. CSE 2231 Supplement A Annatala Wolf

Similar documents
7 The Integrated Debugger

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

Clickteam Fusion 2.5 Creating a Debug System - Guide

Introduction to IntelliJ

Lab Exercise 1 Using EGit and JUnit

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging

MITOCW watch?v=9h6muyzjms0

Lab 8 - Vectors, and Debugging. Directions

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

Slide 1 CS 170 Java Programming 1 Testing Karel

1 Getting used to Python

Adafruit WebIDE. Created by Tyler Cooper. Last updated on :29:47 PM UTC

vi Primer Adapted from:

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

Reliable programming

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Visual Studio 2008 Load Symbols Manually

Java Programming Constructs Java Programming 2 Lesson 1

Assignment #4 Minesweeper

The Stack, Free Store, and Global Namespace

Chapter 1 Getting Started

Windows 7 Will Not Install On My Computer Says I'm

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Intro. Speed V Growth

AHHHHHHH!!!! NOT TESTING! Anything but testing! Beat me, whip me, send me to Detroit, but don t make me write tests!

Problem 1. Remove consecutive duplicates (6 points, 11 mintues)

Chris Piech Handout #7 CS 106A April 18, Debugging

Troubleshooting Maple Worksheets: Common Problems

Physics REU Unix Tutorial

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Hardware versus software

The NetBeans Debugger: A Brief Tutorial

CSE 3. Debugging: What's the Problem? Lexical Structures. Chapter 7: To Err Is Human: An Introduction to Debugging

Version Copyright Feel free to distribute this guide at no charge...

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010

CSE 3. Comics Updates Shortcuts/FIT Tips of the Day In class activities Windows Update Your mail/web server common quota

From time to time Google changes the way it does things, and old tutorials may not apply to some new procedures.

Windows 7 Will Not Load On My Computer Says Its

We are built to make mistakes, coded for error. Lewis Thomas

Debugging with Karel

Arduino IDE Friday, 26 October 2018

Client Side JavaScript and AJAX

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

Regression testing. Whenever you find a bug. Why is this a good idea?

05. SINGLETON PATTERN. One of a Kind Objects

Stacks and queues (chapters 6.6, 15.1, 15.5)

Polygon Modeling Basics Chapter 1 - Vertices

Microsoft's latest OS is a lot better than its predecessor, but it still has some annoying quirks. We help you solve them.

Chapter 12 Visual Program Debugger

Supplement: Visual C++ Debugging

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device.

Here's how you declare a function that returns a pointer to a character:

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

HELPLINE. Dilwyn Jones

Slide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Advance mode: Auto

CSE 374 Programming Concepts & Tools

CSE 331 Software Design & Implementation. Hal Perkins Fall 2016 Debugging

Using Visual Studio.NET: IntelliSense and Debugging

CS3 Midterm 1 Fall 2006

Screenshots Made Easy

6.001 Notes: Section 7.1

Wednesday. Wednesday, September 17, CS 1251 Page 1

the NXT-G programming environment

Capturing Network Traffic With Wireshark 2

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

Note: Photoshop tutorial is spread over two pages. Click on 2 (top or bottom) to go to the second page.

Manual. Note: This software has only been tested with VF-1 firmware Compatibility with other firmware versions cannot be guaranteed!

Staleness and Isolation in Prometheus 2.0. Brian Brazil Founder

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

Chaos Culture. Multiclip Editor / Multiclip Note preview 1.5. Edited by Jason Cowling

Basic Fiction Formatting for Smashwords in OpenOffice L. Leona Davis. Copyright 2012 L. Leona Davis All Rights Reserved

Android Programming Family Fun Day using AppInventor

Intro to MS Visual C++ Debugging

Linked Lists. What is a Linked List?

1.2 - Introduction to the IAR Workbench IDE *

Steps for project success. git status. Milestones. Deliverables. Homework 1 submitted Homework 2 will be posted October 26.

TESTING AND DEBUGGING

Using X-Particles with Team Render

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Introduction; Parsing LL Grammars

Windows 7 Will Not Load On My Computer Says I'm

Binary Search Trees. Carlos Moreno uwaterloo.ca EIT

GETTING STARTED WITH ECLIPSE Caitrin Armstrong

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue

05: A Gentle Introduction to Virtools

Molecular Statistics Exercise 1. As was shown to you this morning, the interactive python shell can add, subtract, multiply and divide numbers.

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

An Introduction to Python (TEJ3M & TEJ4M)

Warmup : Name that tune!

Listen to. the podcast. Transcript: podcast is. of syntax. those kinds. it will come. to correct. 1 Page. Chandoo.org

Data structures. Priority queues, binary heaps. Dr. Alex Gerdes DIT961 - VT 2018

Remove Default Program Association Windows 7 Regedit

Lab 2: Conservation of Momentum

New and Improved Formula Editor in JMP 13

CS103 Spring 2018 Mathematical Vocabulary

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

This lesson is part 5 of 5 in a series. You can go to Invoice, Part 1: Free Shipping if you'd like to start from the beginning.

Transcription:

Debugging CSE 2231 Supplement A Annatala Wolf

Testing is not debugging! The purpose of testing is to detect the existence of errors, not to identify precisely where the errors came from. Error messages may be unhelpful or even deceptive. This is especially true with "kernel" implementations. The only way to isolate and fix errors is by using a systematic strategy to locate mistakes in code. This process of "detective work" is known as debugging, and it is the vast majority of what we do in software engineering.

Curiosity is not a good debugging strategy! If you're new to debugging, you will be tempted to investigate bizarre output. "Why did my Word Counter program just tell me that jet fuel can't melt steel beams?" This is a natural reaction, but it's a bad approach. It might seem strange, but it is 100x easier to fix a program than to figure out why it broke!

Before you begin... Start with the simplest-looking test case that fails. Then, reduce that case to a minimal example that fails. The simpler the thing that fails, the more luck you'll have finding the problem. You can do this very quickly (logarithmic time) with a binary search. (As in, remove half the problem; if that removes the bug, add back half what you removed...)

Warning! Debugging in "kernel" implementations... It can be very tricky to debug components with a data rep. If tostring() or equals() is called, what happens? Those methods are written in the abstract class, remember? Those methods call your methods: the same code you're testing! Testing with a reference class uses assertequals(), which calls equals(). This means it is pointless to test kernel code until you have written every method. It's also more dangerous to debug kernels: if you accidentally tostring() this while debugging, it can ruin your test...

Assertions: The Programmer's Friend If you see a violated assertion that isn't from the JUnit test case itself (like, it isn't one of the assertequals() calls), this is usually a good sign! It means that somewhere in your code, you called a method without satisfying the precondition first. It also tells you the exact place in code where the bad call was made (it will appear one line down in the stack trace.) These tend to be the easiest errors to locate, which is why we use assertions to check preconditions during testing. In some cases it won't help much, though. For example, the assertion might have failed because you did something to corrupt the data representation in a different method.

The failure stack trace is on the left. It shows us dequeue() was called incorrectly by set.add() on line 122 (highlighted). The assertion was "this /= <>", meaning the Queue was supposed to not-equal empty string. In other words, line 122 calls dequeue on an empty Queue.

What if assertequals() messages make no sense? Example on next slide: equals() detected an error (it returned false), but tostring() afterwards doesn't see the error. Several possible ways this can happen but it means you have an error and why it's an error is not revealed by testing: now use debugging strategies

If you see: expected: Set1L<{A, B, C}> but was: Set2<{B, A, C}>, that's the same problem. Those should return equal. tostring() is not an equality test and is never a substitute for equals()!

Setting up a test properly for reference unit testing Set up test object Set up ref object identically MAKE SINGLE CALL TO METHOD BEING TESTED IN UUT (exception: exhaustive tests, like you'll need to do for Project 5) Make identical call to RU (exception: next slide) Test return values for equality (if applicable) Test UUT and RU for equality (always do this!) (important to do in right order)

Exceptions exhaustive unit tests NOTE: you're testing a lot of stuff, but the reason you only make a single call to the test method (except with exhaustive unit tests) is you want to be certain you have isolated that specific test; it's fine to overtest, remember testing /= debugging tests where results aren't fully deterministic (next slide)

Testing methods with indefinite behavior can be a little challenging. For removeany(), we need an intermediate check to safely "match" the call we made on the UUT to the RU (by calling remove() instead).

Where to begin? You can't test your kernel until you've written all of the methods because it can fail when you try to tostring() or equals() the test object, and all JUnit tests do these You don't want to start tracing into your code at the beginning of your test cases unless that's where it broke You should trace right before the error was detected, which often means tracing through equals() You don't have code for equals(), but can trace in by: Putting breakpoints into the kernel methods Cleverly turning breakpoints on/off at the right time

Identify where things first might have gone wrong... Three potential places: object setup, test call, assertequals() Start with the last one and work your way backwards. Let the test run up to assertequals() before you pause. Check to see if the object is already messed up. If it isn't, this is where you start. If it is, stop the test and back up to the test call.

Before doing any debugging in a kernel, breakpoint the beginning of each kernel method

Right-click to run a single test case in debug mode

You need to use the debugger to have any hope of writing code that works. Running a debug should automatically open the Debug perspective (a bunch of debug windows). If you ever screw up Debug perspective you can reset the perspective from the menu. When I see this pop-up it usually tells me you have no clue what you're doing because you never use the debugger! :V

Working with Eclipse Perspectives You'll mainly be using Java and Debug perspectives (well, also version control perspectives) View Perspective Reset Perspective when you need to fix things (like if you accidentally remove a window) You can modify perspectives there too Play around, use Google, etc.

I've never used an editor whose default setup is such a mess. My suggestions are above.

Debugging Panes Outline: it's bookmarks that jump you to places in the program; I rarely use this in debug because I almost always want to stay where the action is (the line being run) add stuff about other panes (Debug, Breakpoints, Variables), kind of obvious from upcoming slides though

Much better! To the right is the stack trace. Note we're currently in createfromargstest(), which is earlier than we wanted to start debugging.

Debugging Controls When you run debug mode nothing will happen unless you remembered to turn on at least one breakpoint Play skips to the next breakpoint Stop quits (this helps if you're in an infinite loop) Step into follows the next method call into method you're calling; won't work if you don't have access to code Step over is your friend! It's usually what you usually want Runs one line of code so you can see variable changes Step out skips to the end of the method (use this if you accidentally step into code that you don't have)

Let's skip to the breakpoint in our JUnit test by turning off the kernel breakpoints for now

We can't step into assertequals, but we can turn the kernel breakpoints back on and hit play

Okay, we're currently in our test object, on which equals() in SetSecondary is calling size()

In what order are your methods called...? You don't know the order the methods will be called in, but you can examine the initial/final states of variables each time a method runs to find the error) The asserts inside kernel methods can call additional kernel methods (not a violation of KPR, because it's an assert, and it happens before method begins running)

Why debugging in a kernel is dangerous Anytime equals() or tostring() is called, it's going to automatically test many of the test unit's methods tostring() gets called DURING debugging if you: hover your cursor over this (in the kernel) highlight this in the variables window The way to prevent this is by very carefully clicking the arrow to open up the object in the variables window without highlighting it. It's fine to look at the fields of the object.

If you hover over variable this or highlight it in the vars window, you'll tostring() it which will call all your kernel methods; OOPS

But if you click the arrow, you can safely look at the fields of this

Here's what happens if you accidentally go somewhere where you don't have code (I stepped over the return in size())

Find the first error, fix, then rerun tests

Baby Steps In debugging you want to find and correct the first error that you see. As soon as you've found an error, correct that error only, then run that same test case again. Don't try to find more errors until you've rerun your tests (but you can correct any errors you see). Even if the error you found couldn't possibly fix the test case you're debugging, the case could run differently without that error. Simple errors can mask more complicated errors.