This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: automated cast to different data type possible?
André Pönitz wrote:
>
> Assuming that I understood the task correctly it can be done with
> gdb python scripting nevertheless.
>
> Given
>
> struct KRBase
> {
> enum Type { TYPE_A, TYPE_B } type;
> KRBase(Type _type) : type(_type) {}
> };
>
> struct KRA : KRBase { int x, y; KRA() : KRBase(TYPE_A), x(1), y(32) {} };
> struct KRB : KRBase { KRB() : KRBase(TYPE_B) {} };
>
> void testKR()
> {
> KRBase *ptr1 = new KRA;
> KRBase *ptr2 = new KRB;
> break_here();
> }
>
> creating a display of
>
> ptr1 @0x809a9d0 KRA
> KRBase KRA
> x 1 int
> y 32 int
> ptr2 @0x809a9e0 KRB
> KRBase KRB
>
> 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.
Thanks
Klaus