This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

inferior calls from python?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]