This is the mail archive of the 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]

Re: pretty printing of smart pointers and making function calls

>>>>> "Vladimir" == Vladimir  <> writes:

Sorry about the long delay here.
I managed to forget about this thread somehow :(

Tom> You can work around this a little by having the base printer also print
Tom> the pointed-to value.  This is what the libstdc++ iterator printers do
Tom> (for now).

Vladimir> I'm not sure I understand you correctly. Do you mean that if
Vladimir> the user asks for a value of variable a and pretty printer
Vladimir> knows that it's a pointer then along with pointer address it
Vladimir> should print the value the pointer points too? Anyway some
Vladimir> reference to document or example would be useful here.

E.g., the libstdc++ printers for iterators print the referred-to object
as well.  Here's a simple one:

class StdSlistIteratorPrinter:
    "Print __gnu_cxx::slist::iterator"

    def __init__(self, typename, val):
        self.val = val

    def to_string(self):
        nodetype = find_type(self.val.type, '_Node')
        nodetype = nodetype.strip_typedefs().pointer()
        return self.val['_M_node'].cast(nodetype).dereference()['_M_data']

This looks into the iterator representation, finds the pointer to the
iterated-over data, and prints that.

This is a hack, but often a useful one.

Vladimir> But you are right that this doesn't work with core-file. Is
Vladimir> there any way to check in Python whether I debug alive process
Vladimir> or see its dead body?

Nothing direct but as a workaround you can often find this stuff using
gdb.execute(..., to_string=True) and then parsing the result.
The output here might change between releases, though, so it is
generally better to get a real Python API.


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