top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

GDB cheat sheet - Part 3

+1 vote
348 views

In continuation of
http://tech.queryhome.com/51444/gdb-cheat-sheet-part-1
http://tech.queryhome.com/51818/gdb-cheat-sheet-part-2

Variables and memory

Print content of variable/memory/register

gdb> print/format <what>

Print the information after each stepping instruction

gdb> display/format <what>

Enable Display

gdb> enable display <display#>

Disable Display

gdb> disable display <display#>

Print memory

gdb> x/nfu <address>

n: How many units to print (default 1).
f: Format character.
u: Unit - b: Byte,  h: Half-word (two bytes)  w: Word (four bytes)  g: Giant word (eight bytes)

Manipulating the program

Change the content of a variable to the given value.

gdb> set var <variable_name>=<value>
gdb> return <expression>

Code Sources

Add directory to the list of directories that is searched for sources

gdb> directory <directory>

Listing the Code

gdb> list
gdb> list <filename>:<function>
gdb> list <filename>:<line_number>
gdb> list <first>,<last>

Get Informations

gdb> disassemble
gdb> disassemble <where>
gdb> info args
gdb> info breakpoints
gdb> info display
gdb> info locals
gdb> info sharedlibrary
gdb> info signals
gdb> info threads
gdb> show directories
gdb> show listsize
gdb> whatis variable_name
posted Jul 23, 2014 by anonymous

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

In continuation of http://tech.queryhome.com/51444/gdb-cheat-sheet-part-1

Setting a Watch Point

Set a new watchpoint

gdb> watch <where>

Delete/enable/disable watchpoint

gdb> delete/enable/disable <watchpoint#>

Adding a condition

gdb> break/watch <where> if <condition>

Break/watch at the given location if the condition is met. Conditions may be almost any C expression that evaluate to true or false.

Examining the stack

Show call stack

gdb> backtrace
gdb> where

Show call stack with full frame each frame.

gdb> backtrace full
gdb> where full

Jumping to a stack frame

gdb> frame <frame#>

Stepping in Debug Mode

Go to next instruction (source line)

gdb> step or s

Go to next instruction (source line) but donʻt dive into functions

gdb> next or n

Continue until the current function ends

gdb> finish or fin

Continue normal execution

gdb> continue or c
READ MORE

Basic GDB

Start GDB with Binary

$ gdb <program> <core dump>

Start GDB with core dump

$ gdb <program> <core dump>

Start GDB and pass arguments

$ gdb --args <program> <args…> 

Start GDB and attach to process

$ gdb --pid <pid>

Run the program in in debug mode after above steps

gdb> run [ <args...>]

BreakPoint

Set a new breakpoint

gdb> break <where>

Remove a breakpoint.

gdb> delete <breakpoint#>

Delete all breakpoints

gdb> clear

Disable a breakpoint.

gdb> disable <breakpoint#>

Enable a disabled breakpoint

gdb> enable <breakpoint#>
READ MORE
...