Differences between revisions 15 and 16
Revision 15 as of 2008-11-17 22:45:36
Size: 3422
Editor: TomTromey
Comment: update objfile status; mention inferior stopping
Revision 16 as of 2008-11-22 21:29:29
Size: 3519
Editor: c952d172
Comment: provide the in-scope.py script as example code
Deletions are marked like this. Additions are marked like this.
Line 35: Line 35:
  * [[attachment:backtrace.gdbinit| Backtrace command implemented in Python]]   * [[attachment:backtrace.gdbinit| Backtrace command implemented in Python.]]
  * [[attachment:in-scope.py| Convenience function to check if given variables are in scope.]]


This page describes the work to integrate Python scripting into Gdb.

Getting the code / Helping

Discussions are going on in both the GDB and Archer mailing lists, and code for this effort is being held in the Archer git repository. See the ProjectArcher page for details on checking out Archer. The Python branch is named archer-tromey-python.

To get it, first clone the archer repository using one of the following commands:

  • git clone git://sourceware.org/git/archer.git

  • git clone ssh://sourceware.org/git/archer.git

Then you can checkout the python branch with:

cd archer; git checkout --track -b python origin/archer-tromey-python

If you are interested in helping out, and you have an FSF assignment on file, we can set you up with write access.

Things that work

  • You can create new gdb commands by subclassing gdb.Command

  • You can create new convenience functions by subclassing gdb.Function

  • You can create new gdb parameters by subclassing gdb.Parameter

  • Breakpoints, blocks, frames, symbols, symbol tables, types, and values have Python representations. Some of these representations are not finalized.
  • You can write a type-specific pretty-printer that will work with MI or the CLI; this lets you more intelligently display the contents of objects
  • Python code can be auto-loaded based on an objfile's file name. This works with the separate debuginfo feature as well. (See the manual for details.)
  • gdb has a new -P flag. This enables using gdb as a python scripting interpreter, that is, starting scripts with #!.../gdb -P.

Example code

These are some scripts which work with the current code in the python-revisited branch:

Things we want to work

  • Python code should be able to detect why the inferior has stopped.
  • Expressions should be represented in Python.
  • There should be a Python class representing a language and all methods should be overrideable.
  • There should be a Python class representing a target and all methods should be overrideable.
  • We need more documentation for the Python API.
  • We need more test cases for the Python API.
  • We need a library of useful Python code, in particular useful user-defined functions. Maybe this library needs some kind of auto-loading support -- we want to keep startup time short.
  • Nice feature: be able to register a python signal handler for inferior signals. Would help in this usecase:
    • <LimCore> how to run gdb from command line, so that it will run ./foo.bin  with arguments: foo bar baz   and it will run it instantly without waiting for 'r'; And if program segfaults then it will do 'bt' without waiting for the command.  (and if program terminates normally then it will also just quit)

Big Goals

  • It should be possible to write support for a new language entirely in Python.
  • It should be possible to rewrite Insight in Python.
  • It should be possible to write useful "executables" purely in Python. This would mean modifying the gdb startup sequence (so a script could be used in a pipeline) and maybe adding command-line options. One example of a tool like this would be a generalized strace, like frysk's ftrace.

  • ... your idea here

None: PythonGdb (last edited 2013-12-04 18:03:08 by TomTromey)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.