首页 / PYTHON / gdb自动化,使用python
gdb自动化,使用python
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了gdb自动化,使用python,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3786字,纯文字阅读大概需要6分钟。
内容图文
![gdb自动化,使用python](/upload/InfoBanner/zyjiaocheng/599/3024ce58f56642459db786e6ce68215d.jpg)
相关API列表:
https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html
使用python 3
demo1: vim mybugreport.py
import os class BugReport (gdb.Command): """Collect required info for a bug report""" def__init__(self): super(BugReport, self).__init__("bugreport", gdb.COMMAND_USER) def invoke(self, arg, from_tty): pagination = gdb.parameter("pagination") if pagination: gdb.execute("set pagination off") f = open("/tmp/bugreport.txt", "w") f.write(gdb.execute("thread apply all backtrace full", to_string=True)) f.close() os.system("uname -a >> /tmp/bugreport.txt") if pagination: gdb.execute("set pagination on") BugReport()
demo2:
def invoke(self, arg, from_tty): pagination = gdb.execute("show pagination", to_string=True).endswith("on.\n") if pagination: gdb.execute("set pagination off") gdb.execute('thread apply all backtrace full') import os os.system('uname -a') if pagination: gdb.execute("set pagination on")
other: https://sourceware.org/gdb/wiki/PythonGdbTutorial
Tom Tromey wrote a PythonGdb tutorial which helps make the [[http://sourceware.org/gdb/onlinedocs/gdb/Python.html|official Python binding docs]] much more accessible: 1. [[http://tromey.com/blog/?p=494|Installing a Python-enabled debugger]]<<BR>>We’ll start at the very beginning: checking it out, building it, and then “hello, world”. 1. [[http://tromey.com/blog/?p=501|Writing a new gdb command]]<<BR>>I'll show you how to implement a new command to save breakpoints to a file. 1. [[http://tromey.com/blog/?p=515|gdb convenience functions]]<<BR>>Now we’ll see how to write new functions, so your Python code can be called during expression evaluation. 1. [[http://tromey.com/blog/?p=520|Parameters, and extending require]]<<BR>>Parameters are a nice feature when you are polishing your gdb extensions for more general use. Having Python extensions which are themselves extensible - like require - is an emerging theme of python-gdb. 1. [[http://tromey.com/blog/?p=522|The filtering backtrace]]<<BR>>Now let’s do something really useful. We’ve reimplemented backtrace, entirely in Python. And, in so doing, we’ve added some functionality, namely filtering and reverse backtraces 1. [[http://tromey.com/blog/?p=535|Auto-loading Python code]]<<BR>>Suppose someone writes a new filter - it would be nice to get it without having to edit anything. Naturally, we provide an automatic mechanism for loading code. 1. [[http://tromey.com/blog/?p=524|Pretty printing, part 1]]<<BR>>You can register a pretty-printer class by matching the name of a type; any time gdb tries to print a value whose type matches that regular expression, your printer will be used instead. 1. [[http://tromey.com/blog/?p=546|Pretty printing, part 2]]<<BR>>There are a few additions which are helpful with more complex data types. This post will explain the other printer methods used by gdb, and will explain how pretty-printing interacts with MI, the gdb machine interface. 1. [[http://tromey.com/blog/?p=548|Scripting gdb]]<<BR>>In this post I want to look at gdb from a different angle: as a library. I’ve long thought it would be pretty useful to be able to use gdb as a kind of scriptable tool for messing around with running programs, or even just symbol tables and debug info; the Python work enables this. 1. [[http://tromey.com/blog/?p=550|Wacky stuff]]<<BR>>What could be flashier than a GUI? 1. [[http://tromey.com/blog/?p=552|The End]]<<BR>>What next? Now is an exciting time to be working on gdb. There are a number of very interesting projects underway. 1. [[http://tromey.com/blog/?p=696|Events]]<<BR>>Gdb's event system. 1. [[http://tromey.com/blog/?p=698|Breakpoints]]<<BR>>API for handling breakpoints. 1. [[http://www.cinsk.org/articles/gdb3.en.html|Adding new GDB Commands using Python]]<<BR>>Adding some useful commands (i.e. hexdump, iconv) to GDB
内容总结
以上是互联网集市为您收集整理的gdb自动化,使用python全部内容,希望文章能够帮你解决gdb自动化,使用python所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。