public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* inferior calls from python?
@ 2009-06-29  0:47 Roland McGrath
  2009-06-29  3:22 ` Paul Pluzhnikov
  2009-06-29 18:20 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Roland McGrath @ 2009-06-29  0:47 UTC (permalink / raw)
  To: Project Archer

I wanted to try hacking a pretty-printer that uses an inferior call.
(I know well the reasons why that is a bad way for them to be.  This
is a quick hack to reduce typing in my current debugging scenario, not
a fancy set of pretty-printers to publish.)

The basic idea is I am writing a pretty printer for type T1 where
printing "x" of type T1 would do like:

	printf "T1 id %#x\n", x.id()

but rather than just use "define p_T1" that does this, I want to do it
in python so that std::list<T1> prints elements this way, etc.

So in a pretty-printer, I have a gdb.Value object.  
I don't see how to do this with it.

Two possible approaches occur to me for this.  One is to have a python
method to make the inferior call as a fine-grained operation.

Then it would do:

    def to_string(self):
	return 'T1 id ' + self.val['id'].call(self.val).to_string ()

In the general case, 'call' would take a variable number of gdb.Value
arguments to pass the inferior (or perhaps allow literal numbers and
strings too), and return a gdb.Value of the inferior call's return
value.  (Here I assume that ['id'] yields a gdb.Value of "pointer to
member function" type with no remaining internal pointer to self.val,
so call() has to be given the implicit "this" argument explicitly.
Perhaps C++ method calls would be handled some other way that is more
convenient to use, but equivalent to this.)

The other method is to punt an arbitrary amount of work like the field
selection and inferior calls to the expression parser.  Then it would do:

    def to_string(self):
	return 'T1 id ' + parse_and_eval('$a1.id()', self.val).to_string ()

In the general case, parse_and_eval takes a variable number of
gdb.Value arguments that are each bound to a different $something that
the expression can refer to.  (Perhaps pass one $name->gdb.Value
dictionary instead of variable arguments.)

Am I missing an existing way this can be done?
(I'm using gdb-6.8.50.20090302-27.fc11.x86_64.)


Thanks,
Roland

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: inferior calls from python?
  2009-06-29  0:47 inferior calls from python? Roland McGrath
@ 2009-06-29  3:22 ` Paul Pluzhnikov
  2009-06-29 18:28   ` Roland McGrath
  2009-06-29 18:20 ` Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Paul Pluzhnikov @ 2009-06-29  3:22 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Project Archer

On Sun, Jun 28, 2009 at 5:47 PM, Roland McGrath<roland@redhat.com> wrote:

> Am I missing an existing way this can be done?

I've used parse_and_eval with an earlier archer version like this:

  def to_string(self):
    return 'T1 id ' + str(parse_and_eval('TypeOfT1::id(%s)' %
str(self.val.address())))


I think this will still work with current GDB versions.

-- 
Paul Pluzhnikov

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: inferior calls from python?
  2009-06-29  0:47 inferior calls from python? Roland McGrath
  2009-06-29  3:22 ` Paul Pluzhnikov
@ 2009-06-29 18:20 ` Tom Tromey
  2009-06-29 18:25   ` Roland McGrath
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2009-06-29 18:20 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Project Archer

>>>>> "Roland" == Roland McGrath <roland@redhat.com> writes:

Roland> Two possible approaches occur to me for this.  One is to have a python
Roland> method to make the inferior call as a fine-grained operation.

This is what we want to do, but we haven't gotten to it yet.

You might be able to abuse parse_and_eval somehow already -- but Paul
said on one of the gdb lists that he's made gdb crash this way.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: inferior calls from python?
  2009-06-29 18:20 ` Tom Tromey
@ 2009-06-29 18:25   ` Roland McGrath
  0 siblings, 0 replies; 5+ messages in thread
From: Roland McGrath @ 2009-06-29 18:25 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Project Archer

> Roland> Two possible approaches occur to me for this.  One is to have a python
> Roland> method to make the inferior call as a fine-grained operation.
> 
> This is what we want to do, but we haven't gotten to it yet.

Ok, good.

> You might be able to abuse parse_and_eval somehow already -- but Paul
> said on one of the gdb lists that he's made gdb crash this way.

Paul pointed out abusing parse_and_eval using address literals.
That is a doable kludge for many situations.  But I still think the
eval-with-local-convenience-vars-bound feature has merit in general.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: inferior calls from python?
  2009-06-29  3:22 ` Paul Pluzhnikov
@ 2009-06-29 18:28   ` Roland McGrath
  0 siblings, 0 replies; 5+ messages in thread
From: Roland McGrath @ 2009-06-29 18:28 UTC (permalink / raw)
  To: Paul Pluzhnikov; +Cc: Project Archer

> On Sun, Jun 28, 2009 at 5:47 PM, Roland McGrath<roland@redhat.com> wrote:
> 
> > Am I missing an existing way this can be done?
> 
> I've used parse_and_eval with an earlier archer version like this:
> 
>   def to_string(self):
>     return 'T1 id ' + str(parse_and_eval('TypeOfT1::id(%s)' %
> str(self.val.address())))

Ah, thanks!  That is an excellent terrible idea.
(I somehow overlooked gdb.Value.address.)


Thanks,
Roland

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-06-29 18:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-29  0:47 inferior calls from python? Roland McGrath
2009-06-29  3:22 ` Paul Pluzhnikov
2009-06-29 18:28   ` Roland McGrath
2009-06-29 18:20 ` Tom Tromey
2009-06-29 18:25   ` Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).