GDB QUICK REFERENCE GDB Version 4

Similar documents
Debug for GDB Users. Action Description Debug GDB $debug <program> <args> >create <program> <args>

Princeton University COS 217: Introduction to Programming Systems GDB Tutorial and Reference for x86-64 Assembly Language

GDB cheatsheet - page 1

GDB Linux GNU Linux Distribution. gdb gcc g++ -g gdb EB_01.cpp

Program Design: Using the Debugger

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

gdbtui - Linux Command

Migrating from Inspect to Native Inspect

ALD Assembly Language Debugger Copyright (C) Patrick Alken

Using gdb to find the point of failure

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

Princeton University COS 217: Introduction to Programming Systems GDB Tutorial and Reference

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Exercise Session 6 Computer Architecture and Systems Programming

Libgdb. Version 0.3 Oct Thomas Lord

CS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel

Systems/DBG Debugger Version 2.20

DS-5 ARM. Debugger Command Reference. Version 5.3. Copyright 2010 ARM. All rights reserved. ARM DUI 0452C (ID112910)

Source level debugging. October 18, 2016

DS-5 ARM. Debugger Command Reference. Version Copyright ARM. All rights reserved. ARM DUI 0452P (ID091713)

ARM DS-5. Debugger Command Reference. Copyright 2010 ARM. All rights reserved. ARM DUI 0452A (ID070310)

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program

CSE 410: Systems Programming

MIT OpenCourseWare Multicore Programming Primer, January (IAP) Please use the following citation format:

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

CSE 374 Programming Concepts & Tools

1 Basic functions of a debugger

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here

More fun with Java. Packages. Simple Declarations. Import. Basic Structure of a Java Program. /* a comment */ // a comment

CS201 Lecture 2 GDB, The C Library

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Advanced Magic - GDB

Native Inspect Manual

Using the GNU Debugger

Using the GNU Debugger

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

CSE 351. GDB Introduction

Debugging uclinux on Coldfire

Useful Unix Commands Cheat Sheet

Programming in C++ 4. The lexical basis of C++

Implementation of Breakpoints in GDB for Sim-nML based Architectures

Implementation of a simple shell, xssh

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on

Debugging in LISP. trace causes a trace to be printed for a function when it is called

Debugging and Debugger. Terminology. GNU gcc and gdb. Debugging C programs in Unix and Windows Environments - Part One

CS3210: Tutorial Session 2. Kyuhong Park-- edited by Kyle Harrigan

Tips on Using GDB to Track Down and Stamp Out Software Bugs

Your code must have been compiled with the -g compiler option. Example:

18-600: Recitation #3

Implementation of a simple shell, xssh

CS/COE 0449 term 2174 Lab 5: gdb

CMPSC 311- Introduction to Systems Programming Module: Debugging

Your code must have been compiled with the -g compiler option. Example:

CMPSC 311- Introduction to Systems Programming Module: Debugging

You can also start with both an executable program and a core file specified:

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

1 A Brief Introduction To GDB

Intro x86 Part 3: Linux Tools & Analysis

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

Code Review and Debugging (Lab 05)

bash, part 3 Chris GauthierDickey

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

CS2: Debugging in Java

Using a debugger. Segmentation fault? GDB to the rescue!

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

Understanding the Program Run

Section 1: Tools. Kaifei Chen, Luca Zuccarini. January 23, Make Motivation How... 2

Shell Programming (ch 10)

Computer Labs: Debugging

Testing and Debugging C Programming and Software Tools. N.C. State Department of Computer Science

11/3/71 SYS BREAK (II)

Debugging with GDB and DDT

The Dynamic Debugger gdb

NYU SCPS X Section 1 Unix Tools. Fall 2004 Handout 5

EE 355 Lab 3 - Algorithms & Control Structures

Exploits and gdb. Tutorial 5

CS155: Computer Security Spring Project #1. Due: Part 1: Thursday, April pm, Part 2: Monday, April pm.

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

CS354 gdb Tutorial Written by Chris Feilbach

Recitation: Bomb Lab. September 17 th 2018

Debugging. P.Dagna, M.Cremonesi. May 2015

Lecture 03 Bits, Bytes and Data Types

dbx90: Fortran debugger March 9, 2009

A Fast Review of C Essentials Part I

Today s presentation. Git gdb Project 1

C: How to Program. Week /Mar/05

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

Debugging Core Files Using HP WDB

We first learn one useful option of gcc. Copy the following C source file to your

BLM2031 Structured Programming. Zeyneb KURT

Binghamton University. CS-220 Spring C Debugging Basics. No relevant text

Chapter 1 INTRODUCTION. SYS-ED/ Computer Education Techniques, Inc.

CS 11 C track: lecture 6

Blue Gene/Q User Workshop. Debugging

Continue reading command lines even after an execution error has caused the abandonment of aline.

Transcription:

GDB QUICK REFERENCE GDB Version 4 Essential Commands gdb program [core] debug program [using coredump core] b [file:]function run [arglist] bt p expr c n s set breakpoint at function [in file] start your program [with arglist] backtrace: display program stack display the value of an expression continue running your program next line, stepping over function calls next line, stepping into function calls Starting GDB gdb gdb program gdb program core gdb --help start GDB, with no debugging files begin debugging program debug coredump core produced by program describe command line options Stopping GDB quit INTERRUPT exit GDB; also q or EOF (eg C-d) (eg C-c) terminate current command, or send to running process Getting Help help help class help command list classes of commands one-line descriptions for commands in class describe command Executing your Program run arglist run run... <inf >outf kill start your program with arglist start your program with current argument list start your program with input, output redirected kill running program tty dev set args arglist set args show args show env show env var set env var string unset env var use dev as stdin and stdout for next run specify arglist for next run specify empty argument list display argument list show all environment variables show value of environment variable var set environment variable var remove var from environment Shell Commands cd dir pwd make... shell cmd change working directory to dir Print working directory call make execute arbitrary shell command string [ ] surround optional arguments... show one or more arguments c 1998 Free Software Foundation, Inc. Permissions on back

Breakpoints and Watchpoints break [file:]line b [file:]line break [file:]func break +offset break -offset break *addr break break... if expr cond n [expr] tbreak... rbreak regex watch expr catch event info break info watch clear clear [file:]fun clear [file:]line set breakpoint at line number [in file] eg: break main.c:37 set breakpoint at func [in file] set break at offset lines from current stop set breakpoint at address addr set breakpoint at next instruction break conditionally on nonzero expr new conditional expression on breakpoint n; make unconditional if no expr temporary break; disable when reached break on all functions matching regex set a watchpoint for expression expr break at event, which may be catch, throw, exec, fork, vfork, load, or unload. show defined breakpoints show defined watchpoints delete breakpoints at next instruction delete breakpoints at entry to fun() delete breakpoints on source line delete [n] delete breakpoints [or breakpoint n] disable [n] disable breakpoints [or breakpoint n] enable [n] enable breakpoints [or breakpoint n] enable once [n] enable del [n] ignore n count enable breakpoints [or breakpoint n]; disable again when reached enable breakpoints [or breakpoint n]; delete when reached ignore breakpoint n, count times commands n [silent] command-list end execute GDB command-list every time breakpoint n is reached. [silent suppresses default display] end of command-list Program Stack backtrace [n] bt [n] frame [n] up n down n info frame [addr] info args info locals info reg [rn]... info all-reg [rn] print trace of all frames in stack; or of n frames innermost if n>0, outermost if n<0 select frame number n or frame at address n; if no n, display current frame select frame n frames up select frame n frames down describe selected frame, or frame at addr arguments of selected frame local variables of selected frame register values [for regs rn] in selected frame; all-reg includes floating point

Execution Control continue [count] c [count] step [count] s [count] stepi [count] si [count] next [count] n [count] nexti [count] ni [count] continue running; if count specified, ignore this breakpoint next count times execute until another line reached; repeat count times if specified step by machine instructions rather than source lines execute next line, including any function calls next machine instruction rather than source line until [location] run until next instruction (or location) finish run until selected stack frame returns return [expr] pop selected stack frame without executing [setting return value] signal num resume execution with signal s (none if 0) jump line jump *address resume execution at specified line number or address set var=expr evaluate expr without displaying it; use for altering program variables Display print [/f ] [expr] p [/f ] [expr] x d u o t a c f call [/f ] expr x [/Nuf ] expr N u f disassem [addr] show value of expr [or last value $] according to format f: hexadecimal signed decimal unsigned decimal octal binary address, absolute and relative character floating point like print but does not display void examine memory at address expr; optional format spec follows slash count of how many units to display unit size; one of b individual bytes h halfwords (two bytes) w words (four bytes) g giant words (eight bytes) printing format. Any print format, or s null-terminated string i machine instructions display memory as machine instructions Automatic Display display [/f ] expr show value of expr each time program stops [according to format f ] display display all enabled expressions on list undisplay n remove number(s) n from list of automatically displayed expressions disable disp n disable display for expression(s) number n enable disp n enable display for expression(s) number n info display numbered list of display expressions

Expressions expr addr@len file::nm an expression in C, C++, or Modula-2 (including function calls), or: an array of len elements beginning at addr a variable or function nm defined in file {type}addr read memory at addr as specified type $ most recent displayed value $n nth displayed value $$ displayed value previous to $ $$n nth displayed value back from $ $ last address examined with x $ value at address $ $var convenience variable; assign any value show values [n] show conv Symbol Table info address s info func [regex] info var [regex] whatis [expr] ptype [expr] ptype type GDB Scripts source script define cmd command-list end document cmd help-text end Signals handle signal act print noprint stop nostop pass nopass info signals show last 10 values [or surrounding $n] display all convenience variables show where symbol s is stored show names, types of defined functions (all, or matching regex) show names, types of global variables (all, or matching regex) show data type of expr [or $] without evaluating; ptype gives more detail describe type, struct, union, or enum read, execute GDB commands from file script create new GDB command cmd; execute script defined by command-list end of command-list create online documentation for new GDB command cmd end of help-text specify GDB actions for signal: announce signal be silent for signal halt execution on signal do not halt execution allow your program to handle signal do not allow your program to see signal show table of signals, GDB action for each Debugging Targets target type param help target attach param detach connect to target machine, process, or file display available targets connect to another process release target from GDB control

Controlling GDB set param value show param set one of GDB s internal parameters display current setting of parameter Parameters understood by set and show: complaint limit number of messages on unusual symbols confirm on/off enable or disable cautionary queries editing on/off control readline command-line editing height lpp number of lines before pause in display language lang Language for GDB expressions (auto, c or modula-2) listsize n number of lines shown by list prompt str use str as GDB prompt radix base octal, decimal, or hex number representation verbose on/off control messages when loading symbols width cpl number of characters before line folded write on/off Allow or forbid patching binary, core files (when reopened with exec or core) groups with the following options: history... h... h exp off/on h file filename h size size h save off/on print... p... disable/enable readline history expansion file for recording GDB command history number of commands kept in history list control use of external file for command history groups with the following options: p address on/off print memory addresses in stacks, values p array off/on compact or attractive format for arrays p demangl on/off source (demangled) or internal form for C++ symbols p asm-dem on/off demangle C++ symbols in machineinstruction output p elements limit number of array elements to display p object on/off p pretty off/on p union on/off p vtbl off/on print C++ derived types for objects struct display: compact or indented display of union members display of C++ virtual function tables show commands show commands n show commands + Working Files file [file] core [file] exec [file] symbol [file] load file add-sym file addr info files path dirs show path info share show last 10 commands show 10 commands around number n show next 10 commands use file for both symbols and executable; with no arg, discard both read file as coredump; or discard use file as executable only; or discard use symbol table from file; or discard dynamically link file and add its symbols read additional symbols from file, dynamically loaded at addr display working files and targets in use add dirs to front of path searched for executable and symbol files display executable and symbol file path list names of shared libraries currently loaded

Source Files dir names dir show dir list list - list lines [file:]num [file:]function +off -off *address list f,l info line num info source info sources forw regex rev regex add directory names to front of source path clear source path show current source path show next ten lines of source show previous ten lines display source surrounding lines, specified as: line number [in named file] beginning of function [in named file] off lines after last printed off lines previous to last printed line containing address from line f to line l show starting, ending addresses of compiled code for source line num show name of current source file list all source files in use search following source lines for regex search preceding source lines for regex GDB under GNU Emacs M-x gdb run GDB under Emacs C-h m describe GDB mode M-s step one line (step) M-n next line (next) M-i step one instruction (stepi) C-c C-f finish current stack frame (finish) M-c continue (cont) M-u up arg frames (up) M-d down arg frames (down) C-x & copy number from point, insert at end C-x SPC (in source file) set break at point GDB License show copying show warranty Display GNU General Public License There is NO WARRANTY for GDB. Display full no-warranty statement. Copyright c 1991, 92, 93, 98 Free Software Foundation, Inc. Roland H. Pesch The author assumes no responsibility for any errors on this card. This card may be freely distributed under the terms of the GNU General Public License. Please contribute to development of this card by annotating it. Improvements can be sent to bug-gdb@gnu.org. GDB itself is free software; you are welcome to distribute copies of it under the terms of the GNU General Public License. There is absolutely no warranty for GDB.