GDB

Table of Contents

1 Using with emacs

  • M-x gdb
  • M-x gdb-many-windows
  • M-x gdb-restore-windows

In the breakpoints buffer, D to remove one.

C-x C-a C-b
gud-break
C-x C-a C-d
gud-remove

When program stops at some point (with triangle prefix), b will set breakpoint. So in gud terminal, type b if (xxx) will set conditional breakpoints.

2 Commands

next
next instruction
step
into a procedure
finish
finish current procedure
until
until a line is reached. Can be used to jump out of a loop

3 Core Dump

The "core" may not be there. On ubuntu, this is possibly because you have a core file size ulimit of 0.

Use this to enable it:

ulimit -c unlimited

The core will be dumped to ./core file.

Use gdb to analyze the core:

gdb /path/to/executable ./core

print the stack trace:

bt
bt full

4 Batch mode

It is useful to run gdb in batch mode instead of interactively.

gdb -batch -x commands.gdb /path/to/executable [/path/to/core/dump/file]

Author: Hebi Li

Created: 2017-06-14 Wed 22:43

Validate