A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.

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

Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
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’
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Unix Programming Tools Operating Systems. man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating.
Finding and Debugging Errors
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
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.
Embedded Systems Principle of Debugger. Reference Materials kl.de/avr_projects/arm_projects/#winarmhttp://
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.
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.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
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.
UBI >> Contents Chapter 2 Software Development tools Code Composer Essentials v3: Code Debugging Texas Instruments Incorporated University of Beira Interior.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
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.
S OME USEFUL D EBUG C OMMANDS FOR C LEAR -S PEED S OFTWARE D EVELOPMENT K IT -- COMMANDS FROM CHAP.7 By: Pallav Laskar.
©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 C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
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.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Debugging Lab Antonio Gómez-Iglesias Texas Advanced Computing Center.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
What's New in Visual Studio 2010 Debugging Brian Peek Senior Consultant, ASPSOFT, Inc. Microsoft MVP - C#
Debugging using By: Samuel Ashby. What is debugging?  A bug is an error in either a program or the hardware itself.  Debugging is first locating and.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 4, 2010 CSCE 212Honors Computer Organization.
Lecture 6 UNIX Development Tools. Software Development Tools.
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.
CSCI 4061 Recitation 2 1.
DEBUG.
Dynamic Analysis ddaa.
CSE 374 Programming Concepts & Tools
CSCE 212Honors Computer Organization
Debugging with gdb gdb is the GNU debugger on our CS machines.
Editor, Compiler, Linker, Debugger, Makefiles
gdb gdb is the GNU debugger on our CS machines.
Debugging with Eclipse
Debuggers.
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Getting Started: Developing Code with Cloud9
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]
Testing, debugging, and using support libraries
Module 6: Debugging a Windows CE Image
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
CSCE 212Honors Computer Organization
Debugging.
Makefiles, GDB, Valgrind
Debugging with Eclipse
By Hugues Leger / Intro to GDB debugger By Hugues Leger / 11/16/2019.
Presentation transcript:

A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology

WISDOM W-What do you learn from this I-What is your Interest S-Your level of Sophistication D-Level of Detail O-Ownership-“The Pragmatic Programmer” »By Andy Hunt and David Thomas M-My Motivation

Topics discussed Part 1: Introduction Part 2: THE WHY: gdb? –Features Part 3: THE HOW –Commands Part 4: PRACTICE: Hands on debugging session Part 4: Advanced concepts Part 5: Conclusion –Q & A –References

Part 1 Introduction

What is a debugger? Why do we need one? gdb is NOT –A shell –A text editor –A programming environment Other types of debuggers –ddd, GDBTk, Insight, dbx, softice, etc.

What is a BUG? Bug- program does not generate the expected output BUG or Fault? Errors or bugs –syntactic –Logical Syntactic errors - caught by compiler Logical errors - difficult to find and remove.

Part 2 Why do you need to learn GDB?

Advantages of gdb Interactive Responsive Permissive Capability to work with very large programs –Reported cases: file size close to 1 GB Extremely portable –No other debugger works on so many configurations

Advantages continued Can debug optimized code Can debug macros Multiple processor support Capability to debug multi threaded applications Remote debugging

Major Features Set Breakpoints Examine Data Specify Files Run Program Examine Stack Report Status Trace Execution

Part 3: Working

Compiling the program C-program - compiled using gcc compiler Compilation command: –Example: “gcc -o testout -g test.c” “-o” generates the output “-g” enables gdb C++ program - compiled using g++ Compilation command: –Example: “g++ -o testout -g test.cpp” “-o” generates the output “-g” enables gdb

How to get in and get out Command: gdb Alternate Formats –gdb –gdb program pid –gdb program core –gdb a.out (not recommended) –gdb --args./exe/ To quit gdb use the “quit” or “q” command

Modes of Operation Has many modes some of which are: –Silent –Batch useful for running GDB as a filter. –Example: Download and run a program on another computer –Shell –No windows –Set baud rate (for remote debugging) –Output statistics about time and memory

Logging output set logging on –Enable logging. set logging off –Disable logging. set logging file file –Change the name of the current logfile. The default logfile is `gdb.txt'. set logging overwrite [on|off] –By default, GDB will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead. set logging redirect [on|off] –By default, GDB output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file. show logging –Show the current values of the logging settings.

Halting program execution Break Points –Predefined points where program stops Watch Points –Special breakpoint that stops the program when the value of an expression changes Catch Points –Special breakpoint that stops the program on an event Throwing of a C++ exception Loading of a library

Break Points break function break +/-offset break linenum break filename:linenum break filename:function break *address break break... if cond

Watch Points watch expr rwatch expr awatch expr info watchpoints Hardware & Software watchpoints –set can-use-hw-watchpoints 0

Catch Points Syntax: –catch event Event can be any of the following –throw The throwing of a C++ exception –catch The catching of a C++ exception –exec A call to exec. This is currently only available for HP-UX –fork A call to fork. This is currently only available for HP-UX –vfork A call to vfork. This is currently only available for HP-UX

Break point commands info break list ignore Remove break points –“delete” –“clear” or

Stepping Stepping is the process of executing the program line by line Commands –next – step over –step – step through –continue – jump between break points To step over a few lines of code –step –next

Print command Formats –o – octal –x – hexadecimal –d – decimal –u - unsigned decimal –t – binary –f – float –a – address –i – instruction –c – char –s - string

Useful commands set whatis ptype Call Return gdb has command completion –Hit TAB to complete a command complete r –Lists all commands starting with r. aprops

Most useful command help

Examining Data list linenum list function list list - list + set listsize count show listsize

Edit Data edit edit number edit function edit *address edit filename:number edit filename:function

Editors Vi Emacs XEmacs Choose an editor –EDITOR=/usr/bin/vi –export EDITOR –gdb …….

Search source files forward-search regexp search regexp reverse-search regexp SPECIFY SOURCE DIRECTORY –dir dirname... Adds the name of the directory to the beginning of the source directory path –show directories Shows the source path –show directories Resets the source path to empty.

Examine Stack Very useful in debugging Each function is placed on a stack Function “main” is the only function – one stack frame –Each additional function has a stack frame frame args: Move from one stack to another select-frame: silent version of frame command

Frame Information info f –This command prints a verbose description of the selected stack frame, including: the address of the frame the address of the next frame down (called by this frame) the address of the next frame up (caller of this frame) the language in which the source code corresponding to this frame is written the address of the frame's arguments the address of the frame's local variables the program counter saved in it (the address of execution in the caller frame) which registers were saved in the frame

Info command for frames info frame addr info args info locals info catch SELECT A STACK FRAME –frame –frame addr –up n –down n

Back Trace bt (backtrace) –Stop by hitting control-C backtrace n backtrace full

D E M O Debugging Session Getting our hands dirty

Q & A 10 Minutes