刚开始使用gdb,在重启gdb的时候断点、环境变量等信息都必须重新设置,感觉很不方便。不过gdb提供了.gdbinit,可以方便的在启动的时候对gdb进行设置。比如下面用于保存和加载breakpoints

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
define bsave
  shell rm -f brestore.txt
  set logging file brestore.txt
  set logging on
  info break
  set logging off
  # reformat on-the-fly to a valid gdb command file
  shell perl -n -e 'print "break $1n" if /^d+.+?(S+)$/g' brestore.txt > brestore.gdb
end 
document bsave
store actual breakpoints
end

define brestore
  source brestore.gdb
end
document brestore
restore breakpoints saved by bsave
end

调用bsave保存breakpoints,调用bresotre加载breakpoints。 再如对于调试ncurses的设置:

1
2
3
4
5
6
7
8
9
define settty
  tty /dev/pts/$arg0
end

define setterminfo
  set env TERM=xterm
  set env COLUMNS=144
  set env LINES=29
end