[实践OK] gdb断点保存,gdb单文件多文件断点设置及断点管理,GDB通过自定义命令实现一次执行多个命令。

jackxiang 2015-3-19 11:21 | |
背景:调试大的程序时,经常会设置很多断点。但一旦退出gdb,这些断点会全部丢失,再调试时又得重新设置断点,费时费力。gdb断点保存势在必行。
实践如下:
vi bp.list
set follow-fork-mode child
b  187
b 194
b 290    

后用-x命令载入这个断电的列表:

GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...
Breakpoint 1 at 0x4025de: file multipepollserver.cpp, line 187.
Breakpoint 2 at 0x4026cf: file multipepollserver.cpp, line 194.
Breakpoint 3 at 0x402c2a: file multipepollserver.cpp, line 290.

有时进程退出有问题,于是得杀死,其shell一行解决:
ps aux|grep httpmut|grep -v grep|awk '{print "kill -9 "$2 }'
kill:

——————————————————————————————————————————————————————————
一、Share: gdb断点保存
调试大的程序时,经常会设置很多断点。但一旦退出gdb,这些断点会全部丢失,再调试时又得重新设置断点,费时费力。
我们可能利用gdb的-x参数来载入所有预设的断点,步骤如下:

1.将断点保存到一个文件中,如bp.list;

2.用gdb调试时,加-x参数载入上述文件。这相当于是gdb的一个批处理功能,因此你还可以在上述文件中加上其他你经常要用到的命令。

For example:

bash-3.00$ cat bp.list
b main
b 8

bash-3.00$ g++ -g test.cpp
bash-3.00$ gdb ./a.out -x bp.list -tui

GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.10"...
Breakpoint 1 at 0x11000: file test.cpp, line 26.
Breakpoint 2 at 0x10e28: file test.cpp, line 8.
(gdb)

Enjoy it~


例如,你每次启动gdb,想在main 函数处设断点

编辑一个文件比如叫   a
a中输入  
br   main
保存

gdb   你的可执行文件   -x   a就自动执行设断点了。

这相当于是gdb的一个批处理功能,你还可以在文件中加上其他你经常要用到的命令

只要用-x   参数加批处理文件运行就可以了


来自:http://blog.csdn.net/rxl2008/article/details/6273664

http://topic.csdn.net/t/20041117/17/3562393.html
可以把一些需要用到的命令写到一个文件中,运行gdb的时候读取之就ok了。

6 楼datuhao(峡谷)回复于 2004-11-18 19:22:14 得分 90
例如  
  你每次启动gdb   ,想在main   函数处设断点  
    
  编辑一个文件比如叫   a  
  a中输入    
  br   main  
  保存  
    
  gdb   你的可执行文件   -x   a就自动执行设断点了。  
    
  这相当于是gdb的一个批处理功能,你还可以在文件中加上其他你经常要用到的命令  
    
  只要用-x   参数加批处理文件运行就可以了



二、gdb单文件多文件断点设置及断点管理:
摘自:http://blog.163.com/xychenbaihu@yeah/blog/static/13222965520112179264986/




三、GDB通过自定义命令实现一次执行多个命令
今天,想在gdb一次执行next和p num_caches两条命令,尝试

next; p num_cache

等基于分割符的命令无效后,查了下,需要通过自定义命令实现,具体如下:

(gdb) next;p num_caches

Invalid character ';' in expression.

(gdb) define myfun

Type commands for definition of "myfun".

End with a line saying just "end".

>next

>p num_caches

>end

(gdb) myfun

731           cpus[j].dcache->owner = (struct godson2_cpu *)&cpus[j];

$4 = 3

另外,有些常用的命令组合可以在~/.gdbinit中定义

原文:http://mblog.sigma.me/2011/09/22/gdb-run-multi-cmd.html

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/7875/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2015-3-19 16:36
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]