Debugging: Catching Bugs ( II ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.

Slides:



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

C# Programming: From Problem Analysis to Program Design1 Debugging and Handling Exceptions C# Programming: From Problem Analysis to Program Design 3 rd.
Chapter 11 Debugging and Handling Exceptions
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.
The Art of Design 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.
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.
1 String Library and Stream I/O Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
 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.
Control Statements (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.
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
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.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
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 Cluster Programs using symbolic debuggers.
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.
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.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
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.
1 C++ Classes (I) Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
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.
Debugging Logic Errors CPS120 Introduction to Computer Science.
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
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.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
MOOR ERROR HANDLING Types of error How to test your code for errors How to detect errors How to recover from errors.
Tutorial 1 Writing Your First C++ Program CSC1110C Introduction to Computer Programming By Paul Pun Acknowledgement: Special thanks to Dr. Michael Fung.
DEBUG.
Debugging and Handling Exceptions
Testing and Debugging.
Testing Key Revision Points.
Using Visual Studio with C#
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
Debugging Taken from notes by Dr. Neil Moore
An Introduction to Debugging
Hello World Program In Visual Studio and Debugging
Presentation transcript:

Debugging: Catching Bugs ( II ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series

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

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

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

!!! 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!

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

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.

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

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

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

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!

Let’s rock & roll! // functions to check the characters bool IsCharALetter(const char& c) { return( (c>='A' && c ='a' && c<='z') || (c=='_') ); } bool IsCharADigit(const char& c) { return( (c>='0' && c<='9')); // } bool IsCharAOperator(const char& c) { return( c=='+' || c=='-' || c=='*' || c=='/' || c=='='); }

int ReadAPiece(const char* buffer, int& st, int& ed) { int err_code = 1; while(buffer[st]==' ' && buffer[st]!=0)st++; ed = st; if(buffer[st] == 0) err_code = 0; else{ if(IsCharALetter(buffer[st])){ while(IsCharALetter(buffer[ed]) || IsCharADigit(buffer[ed])) ed ++; } else if(IsCharADigit(buffer[st])){ while(IsCharADigit(buffer[ed])) ed ++; } else if(IsCharAOperator(buffer[st])){ while(IsCharAOperator(buffer[ed])) ed ++; } else{ err_code = 0; } // } return err_code; }

#define SIZE_CL_BUFF 100 void main() { char CL_Buffer[SIZE_CL_BUFF]; while(1){ cout >"; cin.getline(CL_Buffer, SIZE_CL_BUFF); if(strcmp(CL_Buffer, "quit")==0){ cout << "Thank you and Bye!" << endl; break; } else{ // main processing int st = 0, ed; char seg[5]; // a very tough bug!!! how to fix it??? (DMA) while(ReadAPiece(CL_Buffer, st, ed)==1){ for(int i=st;i<=ed;i++) seg[i-st] = CL_Buffer[i]; seg[ed-st+1]= '\0'; cout << seg << endl; // }

Testing Cases “a = b + 1” “a=3.14” “dafdafdfasdfadafds = kdfjdkfajdkfjd + 1” …