1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
1 Classes with Pointer Data Members (II) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230.
Debugging: Catching Bugs ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
1 Array, Pointer and Reference ( III ) Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures.
The Art of Design Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
. Pointers to functions Debugging. Logistics u Mid-term exam: 18/11  Closed books  List of topics – see web page Some you have to read by yourself!
 Monday, 9/9/02, Slide #1 CS106 Introduction to CS1 Monday, 9/9/02  QUESTIONS?? (Exercises, Lab #1, etc.)  Today:  More on float objects  C++ concept:
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Midterm Review Ying Wu Electrical Engineering & Computer Science Northwestern University EECS230 Lectures Series.
Debugging: Catching Bugs ( II ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
1 Dynamic Memory Allocation Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
Guidelines for working with Microsoft Visual Studio.Net.
1 Array, Pointer and Reference ( I ) Ying Wu Electrical Engineering and Computer Science Northwestern University EECS 230 Lectures.
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.
Guidelines for working with Microsoft Visual Studio 6.
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
Week 7 - Programming II Today – more features: – Loop control – Extending if/else – Nesting of loops Debugging tools Textbook chapter 7, pages
ECE230 Course Introduction Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
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.
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.
1 ENERGY 211 / CME 211 Lecture 13 October 20, 2008.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
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.
CS 261 – Data Structures Preconditions, Postconditions & Assert.
Introduction to Exception Handling and Defensive Programming.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
VB – Debugging Tools Appendix D. Why do we need debugging? Every program has errors, and the process of finding these errors is debugging Types of errors.
Array, Pointer and Reference ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Debugging and Profiling With some help from Software Carpentry resources.
Debugging Visual Basic.NET Programs ► ► Use debugging tools ► ► Set breakpoints and correct mistakes. ► ► Use a Watch and Local window to examine variables.
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.
Debugging Xin Tong. GDB GNU Project debugger Allows you to see what is going on `inside' another program while it executes or crashed. (Faster than printing.
Bit-DSP-MicrocontrollerTMS320F2812 Texas Instruments Incorporated European Customer Training Center University of Applied Sciences Zwickau (FH)
Function ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
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.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
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.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Efficiently Solving Computer Programming Problems Doncho Minkov Telerik Corporation Technical Trainer.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
A05. List Debug Intro Data Structures & SE Computer Science Dept Va Tech Aug., 2001 © Barnette ND, McQuain WD 1 MSVC IDE Debugger List Tracing.
Debugging and Testing Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
Dept of Computer Science University of Maryland College Park
Testing and Debugging.
Testing Key Revision Points.
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Debugging Taken from notes by Dr. Neil Moore
When your program crashes
Testing, debugging, and using support libraries
Debugging Taken from notes by Dr. Neil Moore
An Introduction to Debugging
Hello World Program In Visual Studio and Debugging
Presentation transcript:

1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series

2 What shall we learn today? Introduction –What is debugging –Why do we need debugging –What do you need Trace your code –Debugging tools

3 Why? The complier will never catch all the bugs –The complier only check syntax errors –It will never check if your code would fulfill your tasks. You are on you own to –make your program correct –make your program robust –make sure what is really going on in your code

4 What is debugging? Always make sure you know what you are expecting from the code If your program did not output what you expected, tract it down to the exact point You will find the bug! Go ahead and fix it. your code inputoutput Debugging

5 !!! What is the BEST way to mastering C/C++? Viewing examples? Reading C/C++ syntax? Taking exams? NO. The BEST way is through playing with a debugger!

6 Debug Tools Debuggers –have full control of the execution of the program set break points check values of variables and structures modify variables dump memories … – depend on platforms UNIX debuggers: e.g., adb, dbx, gdb WIN-PC debugger: e.g., VC++ debugger Integrated development environment (IDE) –Put together editor, complier, linker, debuggers, etc. –e.g., MS Visual Studio

7 Observe, Guess and Trace You get bugs, but there is no need to panic! It is very normal. How to catch and fix them? –Create testing cases (normal and abnormal) –Observe the run-time error information, intermediate results, stranger behaviors, and printouts –Guess the possible reasons (which needs experience) –Trace down to the troublesome code lines which needs strategy, tool, experience and patient. –Fix the bug, which will be a piece of cake! It is full of fun doing bug-catching.

8 Setting breakpoints Where do you want to stop and check? How to set breakpoints –at a source-code line –at the beginning of a function –when an expression is true –when a variable changes value –when an expression changes value

9 Stepping Through Your Code What if you do not want to set so many breakpoints? If you want a careful trace Stepping –run to cursor –step over –step into –step out

10 Check and Modify Variables How can access those variable? VC++ debugger provides many windows –Output –Variables –Watch –Quick watch –Call stack –Register –Memory –disassembly

11 Simulating Conditions You can test your functions by simulating some “artificial” conditions Modify the value of a variable in debugger, instead of the source code!

12 assert ( b != NULL && size > 0 ); assert ( low >= 0 && high <= size-1 ); assert ( low <= high ); #include // Binary search int binarySearch( const int b[], int searchKey, int low, int high, int size ) { int middle; while ( low < high ) { //? middle = ( low + high ) / 2; if ( searchKey == b[ middle ] ) // match return middle; else if ( searchKey < b[ middle ] ) high = middle - 1; // search low end of array else low = middle + 1; // search high end of array } return -1; // searchKey not found } Let’s Rock’n Roll!

13 #include int binarySearch( const int b[], int searchKey, int low, int high, int size ) void main() { int a[10] = {1, 3, 5, 6, 7, 10, 19, 25, 38, 88}; int q = 5; // test case 1 // int q = 6; // test case 2 int res; res = binarySearch(a, q, 0, 9, 10); if (res == -1){ cout << “not found!\n”; } else{ cout << q << “is in the database at a[“ << res<< “]\n”; }