[RFC - Python Scripting] New method gdb.Architecture.disassemble

Matt Rice ratmice@gmail.com
Thu Feb 7 23:03:00 GMT 2013


On Wed, Feb 6, 2013 at 5:11 PM, Siva Chandra <sivachandra@google.com> wrote:
> On Wed, Feb 6, 2013 at 3:18 PM, Siva Chandra <sivachandra@google.com> wrote:
>> Based on what Matt says in his comments, it seems like a leaf row can
>> look like one of these 3 possibilities:
>>
>> 1. [1, 2, 3]
>> 2. ['a' : 1, 'b': 2, 'c': 3]
>> 3. ['a': 1, 'a': 2, 'a': 3]
>>
>> 1 and 2 can be encapsulated with fundamental Python data structures. I
>> am not aware of any fundamental Python data structure which can
>> capture 3. So, is using a helper class called LabelValuePair a good
>> idea? With this, all leaf rows can be lists whose elements are either
>> all values, or are all LabelValuePairs: [value, value, value] or
>> [LabelValuePair, LabelValuePair, LabelValuePair]. Does this sound
>> reasonable? We can always go in for a list of single element dicts,
>> but I think that kind of makes it ugly. LabelValuePair can look like
>> this (in its Python form):
>>
>> class LabelValuePair(object):
>>   def __init__(self, label, value):
>>     self.label = label # not a writable attribute
>>     self.value = value # not a writable attribute
>
> Or, could it be a named tuple:
> http://docs.python.org/2.7/library/collections.html#collections.namedtuple
> The down side is that they are available only on Python 2.4 and higher.

I definitely agree that these make it possible to do the py-out stuff
without the headache of modifying existing ui-out callers which is
desirable,

and turning it into {'a': (1, 2, 3)} doesn't really achieve that due
to the single 'uiout_list_type' entry point currently available.
one nice thing about the latter is that any python version can parse
it via 'literal_eval'.
which means if someone wanted to replace mi with py-out as a wire protocol
they need to share either the named_tuple stuff, or the LabelValuePair
object code on both the gdb and py-out client side.

so, my preference had been to represent duplicate keys as dict with a
list value just because it makes parsing dead simple/can just use a
stock python, that said I definitely see the appeal of a custom class
or named tuple, so I'm sort of on the fence on this one.



More information about the Gdb-patches mailing list