CMSC 202 Lesson 15 Debugging. Warmup  What is the bug in the following code? int* foo(int a) { return &a; }

Slides:



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

Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
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.
Programming Types of Testing.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Guidelines for working with Microsoft Visual Studio.Net.
Guidelines for working with Microsoft Visual Studio 6.
JavaScript, Fourth Edition
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Debugger Presented by 李明璋 2012/05/08. The Definition of Bug –Part of the code which would result in an error, fault or malfunctioning of the program.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Debugging Tips for Programmers. Outline Script debugging Script debugging –C shell –BASH/Bourne/Korn shell tips Compiled language debugging Compiled language.
Homework Reading Programming Assignments
Debugging Cluster Programs using symbolic debuggers.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Warmup Write a function to add two integer parameters and return the result.
1 4.8The do/while Repetition Structure The do/while repetition structure –Similar to the while structure –Condition for repetition tested after the body.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Our Environment We will exercise on Microsoft Visual C++ v.6 We will exercise on Microsoft Visual C++ v.6 because that is what we have in the univ. because.
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.
Active-HDL Interfaces Debugging C Code Course 10.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Debugging Logic Errors CPS120 Introduction to Computer Science.
CMSC 104, Version 9/011 More Loops Topics Counter-Controlled (Definite) Repetition Event-Controlled (Indefinite) Repetition for Loops do-while Loops Choosing.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Unit - V. Debugging GNU Debugger helps you in getting information about the following: 1.If a core dump happened, then what statement or expression did.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
Loops and Simple Functions COSC Review: While Loops Typically used when the number of times the loop will execute is indefinite Typically used when.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors Locate seg faults and bus errors Prepared by Dr. Spiegel.
Lab 4: Loops and Iteration Graham Northup
DEBUG.
14 Compilers, Interpreters and Debuggers
Testing and Debugging.
Computer Programming I
Testing Key Revision Points.
Selected Topics From Chapter 6 Iteration
Debuggers.
Debugging CSCE 121 J. Michael Moore.
Debugging at Scale.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Chapter 15 Debugging.
Our Environment We will exercise on Microsoft Visual C++ v.6
Homework Reading Programming Assignments Finish K&R Chapter 1
Loops and Simple Functions
Warmup Write a function to add two integer parameters and return the result.
Chapter 15 Debugging.
Debugging.
More Loops Topics Counter-Controlled (Definite) Repetition
CHAPTER 6 Testing and Debugging.
Chapter 15 Debugging.
Presentation transcript:

CMSC 202 Lesson 15 Debugging

Warmup  What is the bug in the following code? int* foo(int a) { return &a; }

What are Errors?  Syntax Errors Compiler/Linker catch these Mistakes in your formatting of C++  Semantic/Logic Errors Nothing catches these Misunderstanding of programmer about what system is supposed to do  These are BUGS  Mismatch between what system is supposed to do and what it actually does

Finding Bugs  Categories of Bugs Seg-fault or core-dump (fatal!) Program infinitely loops Runs but output is incorrect  Strategies Look through code line by line Print values every once in a while Use a debugger (best choice!)  Professional Programmers? Use a mix of these strategies!

Debuggers on GL  GDB “GNU DeBugger” Text-based Fast to load  DDD “GNU Data Display Debugger” Graphically based Easier to use Slower to load/interact with (remotely) Must install an *NIX emulator  Check Resources page “Remotely Accessing the GL Servers”

GDB/DDD – Linux/UNIX debugger  Allows you to: Run program from start See which line seg-faulted Run program line by line Stop at any point Print variables at any point View parameters Trace through function calls Exit Get Help on any feature

GDB Basic Commands CommandAbbreviationDescription gdb [executable]Starts gdb and loads the executable run [cmdLineParms]r cmdLineParmsRuns the loaded executable list [point]l l lineNbr l File:lineNbr l function Lists several lines of code around/at a point. Points can be line numbers, function names, or lines in a particular file, absence of a point indicates “next few lines” break [point]b b lineNbr b function Sets a breakpoint at a point. This will stop execution at this point. You can then view variables at that point or perform other tasks. continuecRun until next breakpoint or end print variable print function p variableName p functionCall Prints the value of a variable or the return value from a function call at the current line. printf formatting var/funcWorks just like printf in C. display var/funcdisp variableName disp functionCall Works just like print, except that it displays those values every time you stop watch variablewa variableNamePause execution whenever variable changes nextnRuns the next line of code, skips over functions stepsRuns to first line of code inside a function call backtrace where up down btAllows you to see function call sequence that led to current line of code. Up takes you up one level Down takes you down one level quitqQuit gdb help [topic]h topicGets help on a particular topic, or general help

In-class Debugging Demo  Conway’s Game of Life Simulates Genetic growth patterns Grid of cells  Cell is alive == ‘*’  Cell is dead == ‘ ‘ Generate next generation via rules  If cell has 2 living neighbors, it stays the same  If cell has 3, it come alive  If cell has < 2, it dies of loneliness  If cell has > 3, it dies of overcrowding

Challenge  Write a program that averages positive integers from the user: Stop accepting numbers when 0 is entered Discard any negative numbers  Put at least 5 bugs in the program  Swap your code with a friend Debug their program