gdb脚本
2015-06-02 20:23
661 查看
一、简介
作为UNIX/Linux下使用广泛的调试器,gdb不仅提供了丰富的命令,还引入了对脚本的支持:一种是对已存在的脚本语言支持,比如python,用户可以直接书写python脚本,由gdb调用python解释器执行;另一种是命令脚本(command file),用户可以在脚本中书写gdb已经提供的或者自定义的gdb命令,再由gdb执行。
二、命令脚本
自定义命令格式如下
自定义命令帮助文档格式如下
提示:在gdb中执行脚本要使用source命令,例如:“source xxx.gdb”。
三、python脚本
脚本示例:
运行:
四、脚本加载方式
gdb加载脚本的方式有
gdb -x script方式
gdb命令source
script方式[/code]
作为UNIX/Linux下使用广泛的调试器,gdb不仅提供了丰富的命令,还引入了对脚本的支持:一种是对已存在的脚本语言支持,比如python,用户可以直接书写python脚本,由gdb调用python解释器执行;另一种是命令脚本(command file),用户可以在脚本中书写gdb已经提供的或者自定义的gdb命令,再由gdb执行。
二、命令脚本
自定义命令格式如下
define commandName statement ...... end
自定义命令帮助文档格式如下
document commandName statement ....... end
提示:在gdb中执行脚本要使用source命令,例如:“source xxx.gdb”。
三、python脚本
脚本示例:
1 #!/usr/bin/env python 2 from __future__ import with_statement 3 import gdb 4 5 class SaveBreakpointsCommand (gdb.Command): 6 """Save the current breakpoints to a file. 7 This command takes a single argument, a file name. 8 The breakpoints can be restored using the 'source' command.""" 9 10 def __init__ (self): 11 super (SaveBreakpointsCommand, self).__init__ ("save breakpoints", 12 gdb.COMMAND_SUPPORT, 13 gdb.COMPLETE_FILENAME) 14 15 def invoke (self, arg, from_tty): 16 with open (arg, 'w') as f: 17 for bp in gdb.get_breakpoints (): 18 print >> f, "break", bp.get_location (), 19 if bp.get_thread () is not None: 20 print >> f, " thread", bp.get_thread (), 21 if bp.get_condition () is not None: 22 print >> f, " if", bp.get_condition (), 23 print >> f 24 if not bp.is_enabled (): 25 print >> f, "disable $bpnum" 26 # Note: we don't save the ignore count; there doesn't 27 # seem to be much point. 28 commands = bp.get_commands () 29 if commands is not None: 30 print >> f, "commands" 31 # Note that COMMANDS has a trailing newline. 32 print >> f, commands, 33 print >> f, "end" 34 35 SaveBreakpointsCommand ()
运行:
四、脚本加载方式
gdb加载脚本的方式有
autoload方式 #需要把 脚本放置到[code]/usr/share/gdb/auto-load/usr/lib/目录下
gdb -x script方式
gdb命令source
script方式[/code]
相关文章推荐
- 8.15编写一个模板函数,求数组中最大元素
- Linux目录管理全面掌握
- C++继承与派生的访问基本规则
- 【C语言】关于printf函数输出字符格式
- Linux目录管理全面掌握
- JQuery的Ajax跨域请求的解决方案
- java本地接口(jni)
- ViewPager+自定义标题实现右左滑动,当前指示标题根着改变
- android Launcher基础知识
- 浅谈程序优化
- 23个MySQL常用查询语句
- Jenkins+tomcat+jdk setup
- Android Audio 音频输出设备切换
- Android之Http通信——1.初识Http协议
- 图片上传与预览插件
- 仿支付宝支付密码输入框
- Java二维数组及常见相关算法讲解
- + $exception {"“DataList1”上同时定义了 DataSource 和 DataSourceID。请移除
- MVC北京络捷斯特第三方物流系统技术解析(七)签收录入
- jQuery代码片段