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.

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.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
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:
Ten debugging techniques. The execution process Execution proceeds in a standard series of steps Compute values of subexpressions first Then call value.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Finding and Debugging Errors
How to Debug VB .NET Code.
Visual Basic Debugging Tools Appendix D 6/27/20151Dr. Monther Aldwairi.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
JavaScript, Fourth Edition
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.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 6 Debugging and Error Handling.
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
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
Our Environment We will exercise on Microsoft Visual C++ v.6 We will exercise on Microsoft Visual C++ v.6 because that is what we have in the univ. because.
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
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.
Problem of the Day  Why are manhole covers round?
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Proposed Debugger Features Ken Ryall Warren Paul.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
Debugging and Profiling With some help from Software Carpentry resources.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
©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.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
11 Debugging Programs Session Session Overview  Create and test a method to calculate percentages  Discover how to use Microsoft Visual Studio.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
1 Advanced.Net Debugging Using Visual Studio, R# and OzCode IT Week, Summer 2015.
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.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Debugging with Eclipse
14 Compilers, Interpreters and Debuggers
Dept of Computer Science University of Maryland College Park
Debugging Dwight Deugo
Testing and Debugging.
Debugging CMSC 202.
LESSON 20.
Barb Ericson Georgia Institute of Technology Dec 2009
Debugging Techniques.
Using Visual Studio with C#
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
Chapter 15 Debugging.
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
Chapter 15 Debugging.
Testing, debugging, and using support libraries
Debuggers and Debugging
Our Environment We will exercise on Microsoft Visual C++ v.6
Debugging Taken from notes by Dr. Neil Moore
Debugging Dwight Deugo
Chapter 15 Debugging.
Debugging with Eclipse
Chapter 15 Debugging.
Presentation transcript:

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 of typing errors. Logic errors different from run-time errors because there are no exceptions thrown, but the output still does not appear as it should These errors can range from buffer overflows to memory leaks. Run-time errors occur during the execution of the program and typically generate Java exceptions Threading errors are the most difficult to replicate and track down.

How to Debug a Program Identify the statement that causes the problem Set breakpoint on that line Run the program with debugging mode The program will stop at the defined breakpoint Trace through the program – using step into, step return, step over, etc. Inspect the variables that may cause the problem Identify the problem if possible or repeat the tracing until the problem is found

Set Breakpoint Breakpoints are temporary markers you place in your program to tell the debugger where to stop your program execution You could set a breakpoint on the line containing the statement Execution stops at the breakpoint before the statement is executed You can then check the contents of variables, registers, storage and the stack, then step over (or execute) the statement to see how the problem arises

Types of Breakpoints Line breakpoints are triggered before the code at a particular line in a program is executed Method breakpoints are triggered when a method that has been set as a breakpoint is reached Counter breakpoints are triggered when a counter assumes or goes beyond a particular value Exception breakpoints are triggered when code throws a particular type of exception Storage change breakpoints are triggered when the storage within a particular storage address range is changed Address breakpoints are triggered when the address a breakpoint is set for has been reached.

Stepping Through a Program After you have set your breakpoints, begin executing code in the debugger When the first breakpoint is hit, you can step over statements, step into other methods or classes, continue running until the next breakpoint is reached, or continue running until you reach the end of the program

Stepping in a debugger Stepping into executes the current line. If the current line contains a call to a method, the execution traverses to the first line in the called method. If the method is in a class that was not compiled with debug information, you will see a No Source Available message Stepping over executes the current line without stopping in any functions or routines called within the line Step return executes from the current execution point up to the line immediately following the line that called the current method

Inspecting variables Typically a program is core dumping because a value of a variable is not set correctly Visual debuggers usually have a monitoring window where they display the values of all the variables local to the current class that you are currently in Some debuggers even display the address of the variable and may even let you dynamically change the value to see if the program will continue to execute as you originally expected it to You can even investigate the entire contents of an array by displaying every row and column's contents

Debugging with system.out.println() It is the simplest way of debugging a piece of small code System.out.println() displays messages, variables, and state information on the console or where ever you redirect your output during run time

Other Debugging Techniques Observe the program behavior by inserting printing statements along the main flow and exceptional flows Split the compound statement if needed For example, key = Integer.parseInt(st.nextToken()); is split into String token = st.nextToken(); key = Integer.parseInt(token);

Using Eclipse to Debug

Set breakpoint

Run->Debug As->Java Application Stop at each breakpoint Method to be debugged Variables to be inspected Resume, Pause, Stop, Step Filter, Step into, Step over, Step return

Array Variables Watch and Change Variable Value

Watch Variables

Using Scrapbook to test

Typing Source Code to Execute in Scrapbook

Scrapbook execution & import

Example dubugging

Then, Run->Debug As->Java Application

Step Into: will go into object creation (we see object, not the init method of applet, on the Debug view), let ’ s Step Return to come back from within the method. Step Into again, now we will enter “ into ” the run() method of the Console class

From here Step Return: will go out of run(), but not really since it encounters the next breakpoint first. Step Into: will go into frame creation, we don ’ t want this because it is not part of our code. But if we go past this part, we can Step Into the title() method-> not much there anyway. Step Over: will go to the next line. Now we ’ re at SetupClosing(). We can Step Into or Step Over (or Step Return, but not much point). Let ’ s Step Over until we are at init() method of the applet.

Here we can Step Into the init() method, or Step Over, but won ’ t get pass because we will encounter breakpoint first. At the for loop, let us try to step over. As expected, we will be in the loop for quite a while. But look on the top right :) You see the value that changes as you go through the loop.

To evaluate any expression, type it in the Display view, then right click it and choose Display. The Display view will show the value. The expression can be something a bit more complicated, like msg.charAt(i) i.e expression that does not exist in actual code. Or we can choose Inspect, which will also add this expression to the watchlist in Expression view. But the Display view is not updated as you go through the code. The value of any expression added to the watchlist from the Display view is also not updated. But we can make this work (in the Expression view) by..(see in a couple of pages).

How to make the expression update itself