Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Joseph Garvin <joseph.h.garvin@gmail.com>
To: gdb@sourceware.org
Subject: Python API problems
Date: Wed, 27 Jan 2010 19:27:00 -0000	[thread overview]
Message-ID: <fea8ac9f1001271127w7efe3c38gfcb2a49eca6eb854@mail.gmail.com> (raw)

I was quite excited to see that gdb 7.0 added python scripting and so
tried to implement a few ideas. Unfortunately, under the current API,
none of them are possible AFAICT. It's possible others have pointed
out these issues already but I thought I'd share them here in case the
developers were interested in knowing what people are trying with the
API and what issues they're running into.

I wanted to be able to wildcard break on all the functions in a
particular C++ scope, so if I had a namespace called 'foo' I could do
this:

break foo::*

And any functions in the foo namespace would receive breakpoints. So I
attempted to code an alternative version of break called 'starbreak'
that would do this. Issues I ran into:

-None of gdb's standard commands are exposed directly. You have to
create strings and pass them in to gdb.execute. gdb.execute doesn't
have a return value, so you can't get back any information from
commands. If break were exposed as a python function for example, it
could return a breakpoint object on which you could later in the
python code call enable/disable, or inspect to see what address or
line number was broken at (if for example you broke by function name).

-There's a lookup_type but not a more general lookup_symbol. It'd be
nice if such a function existed. Also, search_type and search_symbol
for matches to a regex.

-That could be worked around if gdb.execute returned a string
containing what information would otherwise have gone to the console.
Then we could at least parse the output. This would be nice in general
for working around API holes until they're filled. Because of this I
can't even manually search the output from "info functions" (though
searching that would be slooooooow).

-You can't call the builtin completion functions. Basically I'd like
to call complete_symbols("foo::", "") to get a list of symbols in the
foo namespace, then iterate through them and break on each one. If in
my constructor I pass in gdb.COMPLETE_SYMBOL, I would expect then if I
call the base class version of complete, e.g.
gdb.Command.complete(self, "foo::", "") I would get back the results
of the builtin version of complete. But I don't, complete is not
defined. This doesn't feel very pythonic.

-Needing to pass the name of the class to the constructor is silly.
Python has reflection facilities (see the 'inspect' module), gdb
should be able to inspect the class and figure out its name itself.

-Needing to manually instantiate an instance of the class *may be*
silly. Python's reflection could be used to look at the imported
classes and make instantiations of any classes defined to inherit from
gdb.Command. On the other hand, real pythonistas might be able to
conjure some hack that depends on commands being instantiated in an
order they define, so this isn't necessarily a good idea, but I can't
think of why someone would want to do that off the top of my head at
least.


             reply	other threads:[~2010-01-27 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27 19:27 Joseph Garvin [this message]
2010-01-27 19:39 ` Joseph Garvin
2010-01-27 20:29 ` Rich Lane
2010-01-30  2:23 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fea8ac9f1001271127w7efe3c38gfcb2a49eca6eb854@mail.gmail.com \
    --to=joseph.h.garvin@gmail.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox