博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
gdb脚本
阅读量:4646 次
发布时间:2019-06-09

本文共 2198 字,大约阅读时间需要 7 分钟。

一、简介

作为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方式            #需要把 脚本放置到/usr/share/gdb/auto-load/usr/lib/目录下gdb -x script方式gdb命令source script方式

转载于:https://www.cnblogs.com/274914765qq/p/4547563.html

你可能感兴趣的文章
重温JSP学习笔记--与日期数字格式化有关的jstl标签库
查看>>
java-Date-DateFormat-Calendar
查看>>
封装CLLocationManager定位获取经纬度
查看>>
我的第一篇博客-(Eclipse中或Myeclipse中如果不小心删除了包那可怎么办?)
查看>>
对easyui datagrid组件的一个小改进
查看>>
类似以下三图竞争关系的IT企业
查看>>
清明节
查看>>
ubuntu如何安装svn客户端?
查看>>
arcgis for javascript (3.17)
查看>>
AI之路,第二篇:python数学知识2
查看>>
[LintCode] 空格替换
查看>>
JSSDK微信支付封装的支付类方法,代码比较齐全,适合收藏
查看>>
mfc Radio Buttons
查看>>
86. Partition List
查看>>
[LintCode] 378 Convert Binary Search Tree to Doubly Linked List 解题报告
查看>>
3.9 java基础总结集合①LIst②Set③Map④泛型⑤Collections
查看>>
Unix和Linux下C语言学习指南
查看>>
css3圈圈进度条
查看>>
Python 函数动态参数
查看>>
javascript之非构造函数的继承
查看>>