Debugging CMSC 202.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
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.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
How to Debug VB .NET Code.
Visual Basic Debugging Tools Appendix D 6/27/20151Dr. Monther Aldwairi.
CIT 590 Debugging. Find a laptop Please take a moment to open up your laptop and open up Eclipse. If you do not have a laptop, please find a friend. If.
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
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.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Debugging Projects Using C++.NET Click with the mouse button to control the flow of the presentation.
Debugging Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
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.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Exceptions in Java. What is an exception? An exception is an error condition that changes the normal flow of control in a program Exceptions in Java separates.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Debugging What coders (programmers) do to find the errors (“bugs”) in their own programs “Bugs” – Admiral Grace Hopper, developer of the world’s first.
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
Debugging using By: Samuel Ashby. What is debugging?  A bug is an error in either a program or the hardware itself.  Debugging is first locating and.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
1 Using an Integrated Development Environment. Integrated Development Environments An Integrated Development Environment, or IDE, permits you to edit,
Error Analysis Logic Errors.
Wrapper Classes Debugging Interlude 1
Debugging with Eclipse
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Programming in visual basic .net Visual Basic Building Blocks
CS1101X Programming Methodology
Debugging Dwight Deugo
Eclipse Navigation & Usage.
Testing and Debugging.
Computer Programming I
Software Design and Development
2_Testing Testing techniques.
Barb Ericson Georgia Institute of Technology Dec 2009
Using Visual Studio with C#
Important terms Black-box testing White-box testing Regression testing
DEBUGGING.
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
Unit 1: Introduction Lesson 1: PArts of a java program
Comp 110/401 Appendix: Debugging Using Eclipse
Debugging 9/22/15 & 9/23/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Tonga Institute of Higher Education
Using a Debugger 1-Jan-19.
Debugging Taken from notes by Dr. Neil Moore
Testing, debugging, and using support libraries
Debuggers and Debugging
Error messages 24-Feb-19.
Debugging Taken from notes by Dr. Neil Moore
IDE’s and Debugging.
Debugging Dwight Deugo
Error messages 14-Apr-19.
Error messages 16-Apr-19.
Error messages 4-May-19.
CMSC 202 Exceptions.
Debugging with Eclipse
Presentation transcript:

Debugging CMSC 202

Overview Debugging Error Types Stack Traces Probing Eclipse debugger

Debugging Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge in another. —Wikipedia

Error/Bug Types Compile time errors Bugs caught by compiler Syntax errors Runtime errors that terminate program execution Bugs caught by the runtime system NullPointerException ArrayIndexOutOfBoundsException Runtime errors that do not terminate the program Bugs not caught by the runtime system, but hopefully caught by developer Logic errors

Stack Trace A stack trace is a dump of the active stack frames at a given point in execution time. In Java, when the JVM detects an error condition (such as trying to invoke a method on a null reference), it raises an exception resulting in a stack trace. This stack trace shows you where the error originated from and how it came to be executed.

Reading a Stack Trace Exception Error Message Stack trace Exception in thread "main" java.lang.ArithmeticException: / by zero at Bar.derp(Bar.java:8) at Foo.herp(Foo.java:6) at Test.main(Test.java:7) Stack trace The source of the error is at the top of the stack trace

Errors Inside a Java-Provided Class Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 12, Size: 0 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.remove(ArrayList.java:387) at Bar.derp(Bar.java:12) at Foo.herp(Foo.java:6) at Test.main(Test.java:7) Sometimes errors originate in a class that’s provided by Java. Scan from the top down looking for the first reference to your code. That’s usually a good place to start looking. This is where the error manifested itself, though the cause is almost always in your code up the stack.

Tracing with Print Statements Print (a.k.a. tracing, probing ) debugging is the act of watching (live or recorded) trace statements, or print statements, that indicate the flow of execution of a pr.ocess —Wikipedia

Tracing with Print Statements Once you’ve identified the location of the error (by reading the stack trace), start printing out variables. This can be as basic as simply printing out all local variables, members, objects, parameters, etc. using System.out.println(). Having a working toString() method for all of your objects really aids in this debugging process.

Debugger A special program used to find errors (bugs) in other programs. A debugger allows a programmer to stop a program at any point and examine and change the values of variables. —Webopedia

Eclipse Debugger Eclipse has a built-in perspective that is dedicated to debugging Java code. To run a program in the debugger, simply right click on the class to run and select… Debug As → Java Application Allow Eclipse to open the Debug perspective if it asks. If you do nothing else, Eclipse will simply run your program just like a normal “Run As”.

Breakpoints Breakpoints can be used to pause your program at a certain point. Once paused, you can examine (and even change) the state of variables. There are many different ways to break… Line Method Member change Etc.

Line Breakpoints To set a breakpoint on a line, simply double click in the gutter left of the line to stop on. Once you do so, you’ll see a small blue bubble in the gutter like so… Notes Simply double click again to toggle the breakpoint off. In order to break on a line, there must be an executable statement (e.g. you cannot break on a curly brace).

Variable/Breakpoint Tables Stack Frames Current Line

Breakpoint View Easily toggle ALL breakpoints on/off Toggle individual breakpoints on/off

Double Click to change current values Variable View Double Click to change current values Variables in Scope

Hover to View Variable Values

Continuing Execution If you click the resume button in the Debug view, execution will continue until the next breakpoint is encountered.

Stepping There are several step buttons that allow you to walk through the execution of your code. Step Into If the line contains a method call, step into that method and pause execution. Step Over Completely execute this line (including any method calls) and pause execution at the next line. Step Return Complete the current method and pause execution where the method was called from.

Stack Frames Eclipse’s Debug view also shows you stack frames so you can see how you got somewhere. Current stack frame is at the top, main should be at the bottom

Method Breakpoints Double clicking on the margin next to method will create a method entry breakpoint. Right click → Breakpoint Properties… allows you to also set exit breakpoint.

Watching Members You can also set breakpoints (also called watch points) to see when a member is being accessed or changed. Simply double click next to the member and it will set both breakpoints. Double click again to toggle off Right click → Breakpoint Properties… to change

Additional References Java Logging Overview http://download.oracle.com/javase/1.5.0/docs/guide/logging/overview.html Lars Vogel’s Java Logging API Tutorial http://www.vogella.de/articles/Logging/article.html Lars Vogel’s Java Debugging with Eclipse Tutorial http://www.vogella.de/articles/EclipseDebugging/article.html