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

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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
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.
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.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
Program Errors and Debugging Week 10, Thursday Lab.
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
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.
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.
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.
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
Debugging What coders (programmers) do to find the errors (“bugs”) in their own programs “Bugs” – Admiral Grace Hopper, developer of the world’s first.
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.
DEBUG.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Programming in visual basic .net Visual Basic Building Blocks
14 Compilers, Interpreters and Debuggers
Debugging with Clion and GDB
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
Debugging with Eclipse
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]
CSC235 - Visual Studio Tutorial
Debuggers and Debugging
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 1 c++ structure C++ Input / Output
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

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 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) Macro (const declaration) If –g is removed from macro, $(DebugFlag) is replaced by nothing Replaces

Starting GDB Run gdb inside emacs – Provides dual window environment Top window: Command environment Bottom Window: Code Being Debugged 1.Build Using make 2.Start emacs 3.ESC-x(Display at bottom: M-x) 4.gdb 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 – Three possibilities for 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 : 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 :: 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 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 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 Resume execution until end of current function or a breakpoint is encountered – up 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 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

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: 1.Start debugger 2.Run program using same input No breakpoints; just let it crash 3.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 1 st function in the list that you wrote. Note the number X – The first several functions may be library functions 4.Issue command up 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