GNU Debugger - gdb

GDB Cheat Sheet

gdb cheatsheet1

gdb cheatsheet2

GDB Init File

GDB Init File 包含一组 gdb 命令,每次启动 gdb 时自动执行,这个文件可以有 3 个位置

  • ~/.config/gdb/gdbinit
  • ~/.gdbinit
  • ./.gdbinit

GDB Script File

将下面的 gdb 命令写入一个 script 文件里 gdbscript.txt,执行 gdb glxgears -x gdbscript.txt, gdb 会自动执行这个 script 文件里的命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Avoid keyboard input
set pagination off

# Save log to file
set logging file llvmpipe.log
set logging enabled on

# Avoid prompt that "Make breakpoint pending on future shared library load?"
set breakpoint pending on

# Add breakpoint at llvmpipe_flush()
break llvmpipe_flush
command 1
shell date +"%T.%3N" >> llvmpipe.log # Append a timestamp to log file
backtrace
continue
end

# Start the program
run

continue

set logging off
quit

P.S. llvmpipe.log