This is the mail archive of the gdb@sourceware.org mailing list for the GDB 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: automated cast to different data type possible?


On Sunday 15 May 2011 16:20:00 ext Klaus Rudolph wrote:
> André Pönitz wrote:
>
> > Assuming that I understood the task correctly it can be done with 
> > gdb python scripting nevertheless. [...It] takes three lines of python code:
> > 
> >    def qdump__KRBase(d, item):
> >        base = ["KRA", "KRB"][int(item.value["type"])]
> >        d.putItem(Item(item.value.cast(lookupType(base)), item.iname))
> > 
> > [using, admittedly, the *cough* "other" approach to pretty printing]
> 
> Sorry,
> 
> please give me an idea who is calling qdump_KRBase and what is parameter
> d? I actually have no idea how to add that to the printer script... or
> maybe any other python script to gdb.

The code would be called from a Python script that creates the full
display for an local variable including all expanded children in one go. 
'd' is an object that accumulates output that's finally 'printed', and
takes care of properly closing nested items in case of exceptions.

The approach is different from the one taken by the "official" pretty 
printers, but also uses gdb's python scripting. Since this approach
gives access to all levels of the hierarchy at one time, re-arranging
items or re-writing parts of the "parent" items (like in your case the 
name of the type) is straightforward.

Andre'


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