This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC/Patch] Call overloaded operators to perform valid Python operations on struct/class values.
- From: Doug Evans <xdje42 at gmail dot com>
- To: Siva Chandra <sivachandra at google dot com>
- Cc: Tom Tromey <tromey at redhat dot com>, gdb-patches <gdb-patches at sourceware dot org>
- Date: Wed, 18 Dec 2013 08:37:32 -0800
- Subject: Re: [RFC/Patch] Call overloaded operators to perform valid Python operations on struct/class values.
- Authentication-results: sourceware.org; auth=none
- References: <CAGyQ6gxk9zcLKQ1Ef2XhgUMCyB8MB1v=6tA4jsfPyEFgxR8bNw at mail dot gmail dot com> <m31u1q1oq0 dot fsf at sspiff dot org> <871u1j2ldi dot fsf at fleche dot redhat dot com> <CAP9bCMSPpz8px2ZFvRroHcNP8PWWQV39P7GmXCmj+fdSR7NT2Q at mail dot gmail dot com> <CAGyQ6gzYE_NthBxc17VPxjgtYSqTW3HGhPVp8qvk=Nye27G8hg at mail dot gmail dot com>
On Mon, Dec 16, 2013 at 2:24 PM, Siva Chandra <sivachandra@google.com> wrote:
> On Sun, Dec 15, 2013 at 11:48 PM, Doug Evans <xdje42@gmail.com> wrote:
>> For myself, I'm just going slow on this one. E.g., is there another
>> way to provide this?
>> E.g., some kind of facility that uses gdb's language parsers but let's
>> one pass in gdb.Value objects from Python?
>> It sounds doable, but I haven't thought about it very hard (it might
>> not even make sense, or it may require more effort).
>> Its drawback to the current proposal is that it would be a bit more
>> verbose, but it has to potential of handling a lot more cases.
>
> I am not sure I fully understand this alternative.
It could be done in various ways I think. One way would be language parsers
and the evaluator have some way of recognizing a value as coming from
an extension language and fetch the underlying gdb value accordingly.
Kinda like the gdb.parse_and_eval method in Python, but with the
ability to pass Python values to it.
Not that this could work, but for illustration's sake:
smart_ptr = gdb.parse_and_eval ("my_smart_ptr");
dereferenced_smart_ptr = gdb.parse_and_eval("*%V" % smart_ptr)
I can think of a quick hack that was just a wrapper on parse_and_eval that
used some convenience variables to temporarily hold the values that
came from Python (using some syntax that worked, the above
is just for illustration's sake).
> My patch adds the
> ability to use valid Python operators on gdb.Value objects in Python
> code. Operators which have different semantics in Python (like '[]',
> ',' etc.), and operators which do not exist in Python (like '->')
> cannot be facilitated. But, my patch adds the ability to use all
> other operators which are valid (as far as my understanding today
> stands at) in Python.