Differences between revisions 9 and 10
Revision 9 as of 2008-09-13 22:34:09
Size: 4214
Editor: TomTromey
Comment: mention .gdb.py and -P
Revision 10 as of 2008-09-14 21:33:07
Size: 4075
Editor: TomTromey
Comment: update for changes to values
Deletions are marked like this. Additions are marked like this.
Line 36: Line 36:
 * Breakpoints, blocks, frames, symbols, symbol tables, and values have Python representations. Some of these representations are not finalized (in particular values will definitely change).  * Breakpoints, blocks, frames, symbols, symbol tables, and values have Python representations. Some of these representations are not finalized.
Line 49: Line 49:
 * Values need a rewrite so that they are simpler to manipulate from Python. (Thiago is doing this.)
Line 55: Line 54:
 * We need documentation for the Python API.
 * We need test cases for the Python API.
 * We need more documentation for the Python API.
 * We need more test cases for the Python API.

PythonGdb

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

Getting the code / Helping

Discussions are going on in the GDB mailing lists, and code for this effort is being held in a git repository hosted by gitorious. You can check out the code with:

$ git clone git://git.gitorious.org/gdb-python/mainline.git
$ cd mainline
$ git checkout --track -b python-revisited origin/python-revisited

{i} The branch is based on Vladimir's git repository, so it contains history not related to this effort. The first commit related to Python work is 710e23e7bd57137a8686d6bc679a739a556afba2.

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

The development happens in the python-revisited branch, but we also maintain patches which apply to a relatively recent version of CVS HEAD in the python-patches branch. If you prefer to apply the patches instead of just checking out the python-revisited branch, you can extract each of them with:

$ git log -p -n1 <commit id> > a-python-patch.diff

Please note that the patches tend to lag behind a bit and may not reflect the latest changes made to the python-revisited branch.

Things that work

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

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

  • Breakpoints, blocks, frames, symbols, symbol tables, and values have Python representations. Some of these representations are not finalized.
  • You can tell MI to use a Python function to change how a particular type of object is displayed.
  • Python code can be auto-loaded based on an objfile's file name. The file .gdb.py in the objfile's directory is read, if it exists. This works with the separate debuginfo feature as well.
  • 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

  • Types need to be represented in Python.
  • It should be possible to override CLI printing of a value using Python. In particular code for this should be distributed with a library or executable and automatically found. Pretty-printing should be the default, with a new /r (raw) flag to print that bypasses the display.

  • 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.