B.4 The GNU Debugger (gdb)

The following tables list some useful commands of the GNU Debugger (gdb). For a complete list of available commands, see the gdb online documentation.[94]

Command

Description

gdb program

Starts gdb with program to debug.

quit

Exits the debugger.

Command

Description

run arguments

Starts debugged program (with arguments).

attach processID

Attaches the debugger to the running process with processID.

Command

Description

break <file:> function

Sets a breakpoint at the beginning of the specified function (in file).

break <file:> line number

Sets a breakpoint at the start of the code for that line number (in file).

break *address

Sets a breakpoint at the specified address.

info breakpoints

Lists information about existing breakpoints.

delete number

Removes previously set breakpoints specified by their number.

Command

Description

stepi

Executes one machine instruction. Will step into subfunctions.

nexti

Executes one machine instruction. Will not enter subfunctions.

continue

Resumes execution.

Command

Description

x/CountFormatSize address

Prints the specified number of objects (Count) of the specified Size according to the Format at address.

Size: b (byte), h (halfword), w (word), g (giant, 8 bytes).

Format: o (octal), x (hexadecimal), d (decimal), u (unsigned decimal), t (binary), f (float), a (address), i (instruction), c (char), s (string).

Command

Description

info registers

Lists registers and their contents.

backtrace

Prints a backtrace of all stack frames.

disassemble address

Dumps a range of memory around address as machine instructions.

Command

Description

set disassembly-flavor intel|att

Sets the disassembly flavor to Intel or AT&T assembly syntax. Default is AT&T syntax.

shell command

Executes a shell command.

set variable *(address)=value

Stores value at the memory location specified by address.

source file

Reads debugger commands from a file.

set follow-fork-mode parent|child

Tells the debugger to follow the child or parent process.