Chapter 15 Debugging. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 15-2 Debugging with High Level Languages.

Slides:



Advertisements
Similar presentations
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements Animated Version.
Advertisements

Chapter 11 Introduction to Programming in C
Chapter 14 Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Function Smaller, simpler, subcomponent.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four Trusses.
PART 6 Programming 1.Decomposition 2.Three Constructs 3.Counting Example 4.Debugging.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Chapter 2: Input, Processing, and Output
Copyright © The McGraw-Hill Companies, Inc
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
Chapter 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
Technology in Action Alan Evans Kendall Martin Mary Anne Poatsy Twelfth Edition.
Programming Lifecycle
Chapter 02 (Part III) Introduction to C++ Programming.
2_Testing Testing techniques. Testing Crucial stage in the software development process. Significant portion of your time on testing for each programming.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
How to Program? -- Part 1 Part 1: Problem Solving –Analyze a problem –Decide what steps need to be taken to solve it. –Take into consideration any special.
Chapter 6 Programming. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 6-2 Solving Problems using a Computer.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Compilers and Interpreters
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
Chapter 6 Testing and running a solution. Errors X Three types Syntax Logic Run-time.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Wrapper Classes Debugging Interlude 1
Introduction to Algorithms Second Edition by
Introduction to Algorithms Second Edition by
Chapter 10 Image Slides Title
Software Design and Development
PowerPoint Presentations
Copyright © The McGraw-Hill Companies, Inc
Chapter 15 Debugging.
Chapter 3 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to Algorithms Second Edition by
Chapter 8 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter R A Review of Basic Concepts and Skills
Introduction to Algorithms Second Edition by
Copyright ©2014 The McGraw-Hill Companies, Inc
Chapter 15 Debugging.
Introduction to Algorithms Second Edition by
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Assignment Pages: 10 – 12 (Day 1) Questions over Assignment? # 1 – 4
Introduction to Algorithms Second Edition by
Chapter R.2 A Review of Basic Concepts and Skills
Chapter 12 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to Algorithms Second Edition by
Introduction to Algorithms Second Edition by
Chapter 5 Foundations in Microbiology Fourth Edition
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Introduction to Algorithms Second Edition by
Introduction to Algorithms Second Edition by
Title Chapter 22 Image Slides
Chapter 3 Foundations in Microbiology Fourth Edition
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Copyright © The McGraw-Hill Companies, Inc
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Introduction to Algorithms Second Edition by
CHAPTER 6 SKELETAL SYSTEM
Introduction to Algorithms Second Edition by
Chapter 15 Debugging.
Journey to the Cosmic Frontier
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 3 Introduction to Physical Design of Transportation Facilities.
Chapter 15 Debugging.
Introduction to Algorithms Second Edition by
Presentation transcript:

Chapter 15 Debugging

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display 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

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display 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

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Syntactic Errors Common errors: missing semicolon or brace mis-spelled type in declaration One mistake can cause an avalanche of errors because compiler can't recover and gets confused main () { int i int j; for (i = 0; i <= 10; i++) { j = i * 7; printf("%d x 7 = %d\n", i, j); } } missing semicolon

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Semantic Errors 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 h main () { int i int j; for (i = 0; i <= 10; i++) j = i * 7; printf("%d x 7 = %d\n", i, j); } missing braces, so printf not part of if

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display 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__

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display 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

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Source-Level Debugger main window of Cygwin version of gdb

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display 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

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display 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 19 and 17