GDB Basic Commands: A Guide for Students and Developers, Study notes of Computer Science

A comprehensive list of basic gdb (gnu debugger) commands for students and developers. Learn how to compile your program with the -g flag, run gdb, set breakpoints, examine source code, and inspect variables. Useful for debugging c++ programs.

Typology: Study notes

Pre 2010

Uploaded on 08/01/2009

koofers-user-1ek
koofers-user-1ek 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
How to use GDB: Basic Commands
g
Compiling your program
All source files must be compiled with the -g flag. For example: g++ -g -c main.cc
g
Running GDB
To run gdb, type: gdb <executable file name>
g
To exit from GDB
q
g
To run your program (possibly after setting some breakpoints)
r
g
To look at source code
l <fn name> Print 10 lines, centered around the start of the given function.
l Print 10 more lines.
l - Print the 10 lines just before the lines last printed.
l <start #>,<stop #> Print lines <start #> through <stop #>.
g
Breakpoints
b <fn name> Stop at entry to the given function.
b <line #> Stop at the given line of the current file.
info b To see what breakpoints are set.
clear <fn name> Remove breakpoint at entry to given function.
clear <line #> Remove breakpoint at given line of current file.
delete <breakpoint #> Remove a single breakpoint (use ‘info b’ to find breakpoint numbers).
cond <#> <cond> Stop at breakpoint <#> only if condition <cond> evaluates to true. <cond> can be any
C++ expression.
commands Use this after setting a breakpoint or after stopping at a breakpoint to specify gdb com-
mands that are to be executed every time execution stops at this breakpoint. You will be
asked to type commands, one per line, ending with "end".
c Continue execution after stopping at a breakpoint.
s Execute a single statement after stopping at a breakpoint.
n Like ‘s’, but execute function calls as a single unit.
g
To look at and/or change the values of variables
p <exp> Print the value of the given expression. The expression can be any legal C++ expression,
including a function call, e.g., L.myItems[0], L.CurrentItem(), etc.
set <variable>=<exp> Set the given variable to have the value of the given expression.
g
Call information
bt Show all currently active functions.
g
Help information
help To see a summary of GDB commands (follow instructions for more detailed information).
g
C++ classes and class templates
To refer to a class member function (e.g. to look at the source code or to set a breakpoint) use: <class
name>::<function name>. For example: b StringList::CurrentItem
To refer to a member function of a class derived from a class template use: ’<class template
name><<type>>::<function name>(<args>)’. For example: b ’List<String>::CurrentItem(void)’

Partial preview of the text

Download GDB Basic Commands: A Guide for Students and Developers and more Study notes Computer Science in PDF only on Docsity!

How to use GDB: Basic Commands

g Compiling your program All source files must be compiled with the -g flag. For example: g++ -g -c main.cc

g Running GDB To run gdb, type: gdb

g To exit from GDB q

g To run your program (possibly after setting some breakpoints) r

g To look at source code l Print 10 lines, centered around the start of the given function. l Print 10 more lines. l - Print the 10 lines just before the lines last printed. l <start #>,<stop #> Print lines <start #> through <stop #>.

g Breakpoints b Stop at entry to the given function. b <line #> Stop at the given line of the current file. info b To see what breakpoints are set. clear Remove breakpoint at entry to given function. clear <line #> Remove breakpoint at given line of current file. delete <breakpoint #> Remove a single breakpoint (use ‘info b’ to find breakpoint numbers). cond <#> Stop at breakpoint <#> only if condition evaluates to true. can be any C++ expression. commands Use this after setting a breakpoint or after stopping at a breakpoint to specify gdb com- mands that are to be executed every time execution stops at this breakpoint. You will be asked to type commands, one per line, ending with "end". c Continue execution after stopping at a breakpoint. s Execute a single statement after stopping at a breakpoint. n Like ‘s’, but execute function calls as a single unit.

g To look at and/or change the values of variables p Print the value of the given expression. The expression can be any legal C++ expression, including a function call, e.g. , L.myItems[0], L.CurrentItem(), etc. set = Set the given variable to have the value of the given expression.

g Call information bt Show all currently active functions.

g Help information help To see a summary of GDB commands (follow instructions for more detailed information).

g C++ classes and class templates

To refer to a class member function ( e.g. to look at the source code or to set a breakpoint) use: ::. For example: b StringList::CurrentItem To refer to a member function of a class derived from a class template use: <>::()’. For example: b ’List::CurrentItem(void)’