An Introduction to Debugging

Slides:



Advertisements
Similar presentations
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.
Advertisements

If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Programming Fundamentals (750113) Ch1. Problem Solving
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
PRE-PROGRAMMING PHASE
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
General Programming Introduction to Computing Science and Programming I.
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Designing and Debugging Batch and Interactive COBOL Programs Chapter 5.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
CPS120: Introduction to Computer Science Compiling Your Programs Using Visual C++
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Review, Pseudocode, Flow Charting, and Storyboarding.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
CPS120 Introduction to Computer Science Programming & Debugging Lecture 6.
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.
CPS120: Introduction to Computer Science Compiling Your First Program.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
CSE1222: Lecture 1The Ohio State University1. Computing Basics  Computers CPU, Memory & Input/Output (IO)  Program Sequence of instructions for the.
The Debugging Process Syntax Errors CPS120 Introduction to Computer Science Lecture 4.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
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.
Introduction to Computing Science and Programming I
5.01 Understand Different Types of Programming Errors
CSC201: Computer Programming
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Testing and Debugging.
Introduction to C# Applications
Chapter 2 Assignment and Interactive Input
Programming Mehdi Bukhari.
Software Design and Development
Understand the Programming Process
Cracking the Coding Interview
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 2 – Getting Started
Conditions and Ifs BIS1523 – Lecture 8.
Chapter 15 Debugging.
Introduction to C++ Programming
Common C Programming Errors, GDB Debugging
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
An Introduction to Structured Program Design in COBOL
Chapter 15 Debugging.
Understand the Programming Process
Algorithm and Ambiguity
Programming Fundamentals (750113) Ch1. Problem Solving
Software Development Process
Basic Debugging (compilation)
Lesson 2 Get Started with Python – Post-Installation – Use the GUI.
Data and Flowcharts Session
ICT Gaming Lesson 2.
Programming Fundamentals (750113) Ch1. Problem Solving
Data and Flowcharts Session
Chapter 2: Input, Processing, and Output
An Overview of C.
Review of Previous Lesson
Chapter 1 c++ structure C++ Input / Output
WJEC GCSE Computer Science
CHAPTER 6 Testing and Debugging.
Programming Logic and Design Eighth Edition
Presentation transcript:

An Introduction to Debugging CPS120 Introduction to Computer Science

Compiling and Debugging Executable code will not be created until you correct all of the syntax errors in your source code

Syntax & Logic Errors A syntax error is simply the violation of the rules of a language; misuse of structure and form in programming or a violation of the compiler’s rules. These errors are detected by the compiler Also know as 'fatal compilation errors' A logic error is a mistake that complies with the rules of the compiler that causes the program to generate incorrect output

Linker Errors Not all syntax errors are detectable by the compiler These errors do not become apparent until files are put together to create an executable These errors are not linked to a specific line of code Look for the name of the variable and see what lines of code it occurs on using EDIT and FIND LNIK2001: unresolved external LNK1120: unresolved externals The equivalent of the use of to, two and too in English.

Debugging Debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code or the engineering of a hardware device. To debug a program or hardware device is to start with a problem, isolate the source of the problem, and then fix it.

Debugging Objective Find the line(s) containing the syntax error(s) using the compiler's chosen line and error messages as a starting point

Debugging is an Art Compilers often miss reporting an actual error and report on subsequent lines which are effected by error but may be completely correct After encountering a real syntax error, compilers often generate many incorrect syntax error messages Different compilers produce different errors and warnings for the same errors in the same program

Debugging Steps Proofread before compiling Compile Correct all the obvious errors Start at the beginning of the list of errors and warnings A single syntax error may cause the compiler to believe numerous other syntax errors are occurring Look at the error lines and if you see the error, fix it. Otherwise, leave it for later. It may vanish when you fix something else Don’t worry if more errors appear. Some errors mask other errors

Debugging Steps Recompile when you have fixed what you recognize Repeat 3 & 4 until no further errors are obvious Attempt to solve the remaining errors in a top-down fashion Solve whatever errors you can without spending long periods of time on any given error Recompile whenever you feel you don’t see any further solutions

Debugging Aids In the Visual C++ (and other GUI-based compilers) double-clicking on an error message move the cursor to the line where the compiler detected the error This may not be the actual line where the error occurred – don’t trust the compiler on lines Work from the beginning of the program, because in most compilers, the errors are detected from the beginning to end, sequentially Some errors are so severe, they stop the compiler from continuing so more errors may appear after you successfully fix one or more

A Debugging Mindset Assume your syntax is wrong. Look it up! Add working comments as you change things If you are 100% sure a line is correct, then search for a syntax error in the lines ABOVE that line Start with the immediately previous line and work backward Never make a change you can’t explain

Sample Debugging Comment cuot << "This is a line of code"<< endl; /*************Debug************* Error is undeclared identifier Checked syntax for endl Check syntax for screen output -- cuot is misspelled */

Debugging Checklist Visually verify the spelling and case of keywords and identifiers -- Remember, in the editor, keywords are blue, literals are black and comments are green -- Look for problems with l and 1 and o and 0 Verify syntax with a reference book, not just visually -- Don’t trust your eyes; you see what is supposed to be there Try to find an example in the reference book that does something similar and compare the code Verify that the necessary delimiters used for that line are there -- Check the lines above and below as well

Debugging Checklist Without looking at your source code or notes, rewrite the instruction on a piece of paper and then compare it to your actual code; don’t cheat Verify that the line is really the source of the error by commenting the line using // Don’t worry about other errors that result from this If the error disappears, it probably results from the line you are working on If it moves to the next line it is probably caused earlier in the code Remember that the compiler cannot be trusted to pinpoint lines

Warnings Actions that may represent problems but do not cause the compiler to flag an error Don’t ignore warnings Most common warning is a ‘typecasting’ warning Indicates that the conversion of one type of a number was moved to a number (variable) of a different type without inclusion of a typecasting operation E.G. – Moving a float to an integer variable

Common Causes for Warnings An equal sign used in an expression is actually an assignment operator, not the relational operator testing for equality Loops where one condition could never logically be executed Testing a variable that has not received a value yet

Disk Space Issues If the floppy is full or becomes full during the compilation process, the compile will fail with an error message such as: fatal error C1033: cannot open program database A very cryptic message like this can result If you are not able to view all of the intermediate files created in a compile, suspect a space error

Semantic Error Detection Use the tracing method to display the value of critical variables Make the error reproducible Get a stack trace of function calls to verify sequencing Correct the error immediately when you find it and check if you made it somewhere else Examine your last code changes for errors Ensure that you have saved and run the corrected programs

Error Prevention & Testing Use good design and programming style Don't use global variables Study your code before typing and running it Have someone else look at it Make your program self-documented Program defensively – put in assertions and self-checking code and comment them out Test your code at boundary values for variables Log your bugs Test code in pieces using "stubs" Consider – correctness, reliability, utility and performance