Chapter 15 Debugging

Similar documents
Programming in C in a UNIX environment

Program Correctness and Efficiency. Chapter 2

Introduction to Problem Solving and Programming in Python.

Ch. 15: Tesing and Debugging

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

MPLAB X Debugging Techniques

Chapter 11, Testing. Using UML, Patterns, and Java. Object-Oriented Software Engineering

Lecture 10: Introduction to Correctness

Introduction. C provides two styles of flow control:

1 Getting used to Python

Learning to Program with Haiku

Supplement: Visual C++ Debugging

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

EXAMINING THE CODE. 1. Examining the Design and Code 2. Formal Review: 3. Coding Standards and Guidelines: 4. Generic Code Review Checklist:

Darshan Institute of Engineering & Technology for Diploma Studies

12. Debugging. Overview. COMP1917: Computing 1. Developing Programs. The Programming Cycle. Programming cycle. Do-it-yourself debugging

Verification and Validation

TESTING AND DEBUGGING

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Object Oriented Programming Exception Handling

Objectives. Chapter 19. Verification vs. validation. Topics covered. Static and dynamic verification. The V&V process

EIO: Error-handling is Occasionally Correct

Static program checking and verification

Chapter 8. Achmad Benny Mutiara

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

Part 5. Verification and Validation

Terminology. There are many different types of errors and different ways how we can deal with them.

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

11Debugging and Handling. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

Flow Control. CSC215 Lecture

The First Real Bug. gdb. Computer Organization I McQuain

C Programming for Engineers Functions

CSE 303 Lecture 8. Intro to C programming

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Testing. UW CSE 160 Winter 2016

Software Testing. Overview

Fundamentals of Programming Session 12

Object-Oriented Software Engineering Conquering Complex and Changing Systems. Chapter 9, Testing

Functions. (transfer of parameters, returned values, recursion, function pointers).

Chapter 8. More Control Statements

Debug Tool: Introduction. Performance Objectives

Introduction to C Programming

Verification and Validation

CS 11 C track: lecture 5

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

Verification and Validation

Chapter 2, Part I Introduction to C Programming

Sums. Here's a (poor) program to add three numbers

Examining the Code. [Reading assignment: Chapter 6, pp ]

Using a debugger. Segmentation fault? GDB to the rescue!

Debugging. CSE 2231 Supplement A Annatala Wolf

Program Development. Program Development. A Foundation for Programming. Program Development

Programming I Laboratory - lesson 01

Repetition and Loop Statements Chapter 5

CSE 374 Programming Concepts & Tools

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2

Software Testing. Software Testing

THE JAVA FOR STATEMENT

Programming for Engineers Introduction to C

Understanding the Program Run

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #13. Loops: Do - While

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Debugging and testing

Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

CS 520 Theory and Practice of Software Engineering Fall 2018

Fundamentals of Programming Session 4

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

18-642: Unit Testing 1/31/ Philip Koopman

Program Verification. Aarti Gupta

CMPSC 311- Introduction to Systems Programming Module: Debugging

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

[0569] p 0318 garbage

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Goals of this Lecture

COSC121: Computer Systems: Runtime Stack

Object-Oriented and Classical Software Engineering

Object-Oriented and Classical Software Engineering

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The four laws of programs

CS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

Guidelines for Writing C Code

Regression testing. Whenever you find a bug. Why is this a good idea?

TITAN 5300 Software. Unit Test Guidelines. S. Darling, S. Harpster, R. Hite, K. Konecki, W. Martersteck, R. Stewart. Revision 2.0

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

M.CS201 Programming language

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Ian Sommerville 2006 Software Engineering, 8th edition. Chapter 22 Slide 1

CMPSC 311- Introduction to Systems Programming Module: Debugging

Full file at C How to Program, 6/e Multiple Choice Test Bank

C++ Programming: From Problem Analysis to Program Design, Third Edition

(From Glenford Myers: The Art of Software Testing)

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

We first learn one useful option of gcc. Copy the following C source file to your

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Lecture 15 Software Testing

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Transcription:

Chapter 15 Debugging

Known, but unfixed errors Just ignore errors at this point. There is nothing we can do except to try to keep going. -A comment in XFS (xfs_vnodeops.c, line 1785) Error, skip block and hope for the best. -A comment in ext3 (namei.c, line 880) Note: todo: log error handler -A comment in IBM JFS (jfs_logmgr.c, line 222) -- Excerpt from Prof. Haryadi Gunawi s PhD thesis 15-2

Debugging with High Level Languages Same goals as low-level debugging Examine and set values in memory Execute portions of program Stop execution when (and where) desired Want debugging tools to operate on high-level language constructs Examine and set variables, not memory locations Trace and set breakpoints on statements and function calls, not instructions...but also want access to low-level tools when needed 15-3

Types of Errors Syntactic Errors Input code is not legal Caught by compiler (or other translation mechanism) Semantic Errors Legal code, but not what programmer intended Not caught by compiler, because syntax is correct Algorithmic Errors Problem with the logic of the program Program does what programmer intended, but it doesn't solve the right problem 15-4

Syntactic Errors Common errors: missing semicolon or brace missing variable/function declarations One mistake can cause an avalanche of errors because compiler can't recover and gets confused main () { missing semicolon int i int j; for (i = 0; i <= 10; i++) { j = i * 7; printf("%d x 7 = %d\n", i, j); } } 15-5

Semantic Errors - The real problem starts once the syntax errors are fixed - Common Errors Missing braces to group statements together Confusing assignment with equality Wrong assumptions about operator precedence, associativity Wrong limits on for-loop counter Uninitialized variables missing braces, main () { so printf not part of if int i int j; for (i = 0; i <= 10; i++) j = i * 7; printf("%d x 7 = %d\n", i, j); } 15-6

Algorithmic Errors Design is wrong, so program does not solve the correct problem Difficult to find Program does what we intended Problem might not show up until many runs of program Maybe difficult to fix Have to redesign, may have large impact on program code Classic example: Y2K bug only allow 2 digits for year, assuming 19 15-7

Testing Program testing can be used to show the presence of bugs, but never show their absence -- Edsger W. Dijkstra and you need to accept that an exhaustive testing is not possible Black-Box Testing assumes nothing about the internals of the program replies upon input/output specification is sometimes automated White-Box Testing supplements black-box testing increases test coverage often uses an assertion 15-8

Debugging Techniques Ad-Hoc Insert printf statements to track control flow and values Code explicitly checks for values out of expected range, etc. Advantage: No special debugging tools needed Disadvantages: Requires intimate knowledge of code and expected values Frequent re-compile and execute cycles Inserted code can be buggy Source-Level Debugger Examine and set variable values Tracing, breakpoints, single-stepping on source-code statements 15-9

Source-Level Debugger debug web page of cloud 9 15-10

Source-Level Debugging Techniques Breakpoints Stop when a particular statement is reached Stop at entry or exit of a function Conditional breakpoints: Stop if a variable is equal to a specific value, etc. Watchpoints: Stop when a variable is set to a specific value Single-Stepping Execute one statement at a time Step "into" or step "over" function calls Step into: next statement is first inside function call Step over: execute function without stopping Step out: finish executing current function and stop on exit 15-11

Source-Level Debugging Techniques Displaying Values Show value consistent with declared type of variable Dereference pointers (variables that hold addresses) See Chapter 17 Inspect parts of a data structure See Chapters 17 and 19 15-12

Programming for Correctness Accurate Specification Modular Design Defensive Programming Comment your code Adopt a consistent coding style Avoid (unsubstantiated) assumptions Avoid global variables Reply on the compiler (let the compiler generate as many warning messages as possible) 15-13

꼭기억해야할것 Type of errors Syntactic errors Semantic errors Algorithmic errors Testing Black-box testing White-box testing Source-level debugger Breakpoints Single-stepping Displaying values Programming for correctness Accurate specification Modular design Defensive programming 15-14