Gnu Debugger (gdb) Debuggers are used to: Find semantic errors

Slides:



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

Utilizing the GDB debugger to analyze programs Background and application.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
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.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Homework Reading Programming Assignments
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Debugging Projects Using C++.NET Click with the mouse button to control the flow of the presentation.
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.
CSE 332: C++ debugging in Eclipse C++ Debugging in Eclipse We’ve now covered several key program features –Variable declarations, expressions and statements.
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.
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
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.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
C++ crash course Class 9 flight times program, using gdb.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
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.
CSI605 Introduction to ddd. ddd ddd stands for the Data Display Debugger ddd is a graphical environment that resides on top of gdb We recall that gdb.
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?
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
 Wind River Systems, Inc Chapter - 4 CrossWind.
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.
DEBUG.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Programming in visual basic .net Visual Basic Building Blocks
14 Compilers, Interpreters and Debuggers
CSE 374 Programming Concepts & Tools
Testing and Debugging.
Debugging with gdb gdb is the GNU debugger on our CS machines.
Computer Programming I
Debugging CMSC 202.
Editor, Compiler, Linker, Debugger, Makefiles
Scripts & Functions Scripts and functions are contained in .m-files
gdb gdb is the GNU debugger on our CS machines.
Lab: ssh, scp, gdb, valgrind
COMP 2710 Software Construction Introduction to GDB
Computer Architecture “Bomb Lab Hints”
Debugging with Eclipse
Lab: ssh, scp, gdb, valgrind
Debuggers.
Common C Programming Errors, GDB Debugging
Debugging CSCE 121 J. Michael Moore.
Tonga Institute of Higher Education
Getting Started: Developing Code with Cloud9
Using a Debugger 1-Jan-19.
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]
Testing, debugging, and using support libraries
CSC235 - Visual Studio Tutorial
Debuggers and Debugging
Our Environment We will exercise on Microsoft Visual C++ v.6
Basic Debugging (compilation)
Debugging Visual Basic Programs
Homework Reading Programming Assignments Finish K&R Chapter 1
CSE 303 Concepts and Tools for Software Development
Chapter 15 Debugging.
Debugging.
Makefiles, GDB, Valgrind
Debugging with Eclipse
Presentation transcript:

Gnu Debugger (gdb) Debuggers are used to: Find semantic errors Locate seg faults and bus errors Prepared by Dr. Spiegel

Using GDB When to use a debugger? Sometimes you can figure out errors just by using cout (print statements) Incorrect output Unexpected executions Debuggers permit fine-tuned control An absolute must for finding subtle and more complex errors Debuggers quickly provide the location of run-time errors

The best option is usually to run gdb inside emacs Using GDB Basic Functions of a Debugger: Run Program & Enter/Exit Debug Mode In Debug Mode: Control Execution Watch Things The best option is usually to run gdb inside emacs

Using GDB First step: Compile the program with flag for debugging Flag: -g Instructs the compiler to retain user’s code Otherwise, resulting machine code bears no resemblence to original code Note use of –g in makefile (example in next slide) In makefile, -g employed easily via macro

Array Debug Example’s Makefile Macro (const declaration) DebugFlag=-g debug: Array.o ArrayDebug.o g++ -o debug Array.o ArrayDebug.o $(DebugFlag) ArrayDebug.o: ArrayDebug.cpp Array.h g++ -c ArrayDebug.cpp $(DebugFlag) Array.o: Array.cpp Array.h g++ -c Array.cpp $(DebugFlag) Replaces If –g is removed from macro, $(DebugFlag) is replaced by nothing

Starting GDB You will be in the debugging environment Run gdb inside emacs Provides dual window environment Top window: Command environment Bottom Window: Code Being Debugged Build Using make Start emacs ESC-x (Display at bottom: M-x) gdb <Enter> <Enter> You will be in the debugging environment There will be a single window at this time

Run Program & Enter/Exit Debug Mode Breakpoints Designate a location where execution is suspended and debug mode entered Command: break <argument> Three possibilities for <argument> line number function name PC address Note: Underlined character(s) in command are shortcuts

Run Program & Enter/Exit Debug Mode Break Command Arguments line number Use <file name>:<line number> in other files Example: b Array.cpp:121 Can appear alone in application file (some versions of gdb only) function name Can appear alone in application file Use <class name>::<function name> in other files Example: b Array::~Array PC address Preface address with * More commonly used with assembler code Note: Tab completion for setting breakpoints is available

Run Program & Enter/Exit Debug Mode Set up breakpoints before starting the program Run the program Command: run <cmd line argument(s)> program will run until it hits a breakpoint Resume execution: Command: continue You can also use run to restart a currently running program if you want to go back to the beginning

Run Program & Enter/Exit Debug Mode When a breakpoint is encountered: Execution stops The screen will split New window opens showing current file with arrow (=>) to current line this line hasn’t actually been executed yet Program is in debug mode Use debugger commands Control Watch Removing Breakpoints Once a breakpoint’s usefulness has ended it may be removed Command: delete <breakpoint number> No argument will cause prompt to delete all breakpoints Breakpoint number is by order breakpoints were established given when created or when reached during execution

Control Execution Run one line at a time Commands: step next The difference between step and next is when the current statement is a function call next executes the function If function has breakpoint, it will stop there and re-enter debug mode step enters the function to debug it Stops at first line to await next command

Control Execution Other commands: finish up <# frames> Resume execution until end of current function or a breakpoint is encountered up <# frames> Go up the number of functions indicated in the stack I the argument is 1, goes to the line where the current function was called down <# frames> Opposite of up

Control Execution Entering a function When a function is entered, gdb displays information about this call Name of function Parameters, including values Pitfall: Entering a library function e.g. The stream insertion operator The window footer gives file name and line number DO NOT try to debug in here Use fin to exit back to where you entered

Watching Stuff View variable and test functions Commands: print display (no shortcut key) print displays value of its argument argument can be quite intricate array : shows address; you can supply subscript object: will try to provide value of all members if item is address, * can be used to dereference argument can be function call!! function will be executed if function alters program data, alteration sticks display is a persistent print shows argument value after each command when argument is in scope

Finding Causes of Crashes Run-time Errors’ Location(s) are not Reported in Unix Must use gdb to find the location and examine program state at time of crash Usually, the state at the time of crash is preserved If not, once location is determined, set breakpoint before line of crash to examine variables, etc; Procedure

Determine Location of Crash Steps to find location: Start debugger Run program using same input No breakpoints; just let it crash Use where command to show run-time stack displays sequence of function calls to arrive at current location Each function’s call in the stack is numbered Find the 1st function in the list that you wrote. Note the number X The first several functions may be library functions Issue command up <X> Screen will split and display line where crash occurred (=> denotes) Use print or display to examine variables for irregularities.

Resources Quick Primer by Dr. Spiegel Complete Manual - Delore.com   GDB Cheat Sheet   YoLinux Command Cheat Sheet