CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.

Slides:



Advertisements
Similar presentations
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
CS 202 Computer Science II Lab Fall 2009 September 24.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
CSE 303 Lecture 13a Debugging C programs
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
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,
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.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Homework Reading Programming Assignments
Debugging Cluster Programs using symbolic debuggers.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
1 ENERGY 211 / CME 211 Lecture 13 October 20, 2008.
Chapter 12 Recursion, Complexity, and Searching and Sorting
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.
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.
Problem of the Day  Why are manhole covers round?
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
Debugging and Profiling With some help from Software Carpentry resources.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
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.
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.
Debugging. Outline Announcements: –HW II due Fridayl db.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
C++ crash course Class 9 flight times program, using gdb.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
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.
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?
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
Debugging: Tips and Tools Also, Aloha Recitation Wednesday, February 7th, 2007.
Systems Dev. Tutorial IV: Debugging: Tips and Tools Recitation Wednesday, Sept 27th, 2006.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
GDB Introduction And Lab 2
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Using the GNU Debugger (GDB)‏ Techzemplary Pvt.Ltd February 24 th 2008 Pranav Peshwe.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
DEBUG.
Computer System Laboratory
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
CSE 374 Programming Concepts & Tools
Testing and Debugging.
Debugging with gdb gdb is the GNU debugger on our CS machines.
gdb gdb is the GNU debugger on our CS machines.
COMP 2710 Software Construction Introduction to GDB
Debugging Techniques.
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Debugging at Scale.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CSE 303 Concepts and Tools for Software Development
Debugging.
By Hugues Leger / Intro to GDB debugger By Hugues Leger / 11/16/2019.
Presentation transcript:

CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging

Agenda Debuggers, particularly gdb Why? –To learn general features of breakpoint-debugging –To learn specifics of gdb –To learn general debugging “survival skills” Skill #1: don’t panic! Skill #2: be systematic – have a plan 2

An execution monitor? What would you like to “see inside” and “do to” a running program? Why might all that be helpful? What are reasonable ways to debug a program? A “debugger” is a tool that lets you stop running programs, inspect (sometimes set) values, etc. –A “MRI” for observing executing code 3

Issues Source information for compiled code. (Get compiler help) Stopping your program too late to find the problem. (Art) Trying to “debug” the wrong algorithm Trying to “run the debugger” instead of understanding the program It’s an important tool Debugging C vs. Java –Eliminating crashes does not make your C program correct –Debugging Java is “easier” because (some) crashes and memory errors do not exist –But programming Java is “easier” for the same reason! 4

gdb gdb (Gnu debugger) is part of the standard Linux toolchain. gdb supports several languages, including C compiled by gcc. Modern IDEs have fancy GUI interfaces, which help, but concepts are the same. Compiling with debugging information: gcc -g –Otherwise, gdb can tell you little more than the stack of function calls. Running gdb: gdb executable –Source files should be in same directory (or use the -d flag). At prompt: run args Note: You can also inspect core files, which is why they get saved –(Mostly useful for analyzing crashed programs after-the-fact, not for systematic debugging. The original use of db.) 5

Basic functions backtrace frame, up, down print expression, info args, info locals Often enough for “crash debugging” Also often enough for learning how “the compiler does things” (e.g., stack direction, malloc policy,...) 6

Breakpoints break function (or line-number or...) conditional breakpoints (break XXX if expr) 1.to skip a bunch of iterations 2.to do assertion checking going forward: continue, next, step, finish –Some debuggers let you “go backwards” (typically an illusion) Often enough for “binary search debugging” Also useful for learning program structure (e.g., when is some function called) Skim the manual for other features. 7

A few tricks Everyone develops their own “debugging tricks”; here are a few: –Printing pointer values to see how big objects were. –Always checking why a seg-fault happened (infinite stack and array-overflow very different) –“Staring at code” even if it does not crash –Printing array contents (especially last elements) –... 8

Advice Understand what the tool provides you Use it to accomplish a task, for example “I want to know the call-stack when I get the NULL-pointer dereference” Optimize your time developing software –Think of debugging as a systematic experiment to discover what’s wrong — not a way to randomly poke around. Observation: the problem; hypothesis: I think the cause is …; experiment: use debugger to verify Use development environments that have debuggers? See also: jdb for Java Like any tool, takes extra time at first but designed to save you time in the long run –Education is an investment 9

gdb summary – running programs Be sure to compile with gcc –g Open the program with: gdb Start or restart the program: run Quit the program: kill Quit gdb: quit Reference information: help Most commands have short abbreviations often repeats the last command –Particularly useful when stepping through code 10

gdb summary – looking around bt – stack backtrace up, down – change current stack frame list – display source code (list n, list ) print expression – evaluate and print expression display expression – (re-)evaluate and print expression every time execution pauses. –undisplay – remove an expression from this recurring list. info locals – print all locals (but not parameters) x (examine) – look at blocks of memory in various formats 11

gdb summary – breakpoints, stepping break – set breakpoint. (break, break, break : ) info break – print table of currently set breakpoints clear – remove breakpoints disable/enable – temporarily turn breakpoints off/on without removing them from the breakpoint table continue – resume execution to next breakpoint or end of program step – execute next source line next – execute next source line, but treat function calls as a single statement and don't step into them finish – execute to the conclusion of the current function –How to recover if you meant “next” instead of “step” 12