I have a struct in C++ something like this:
struct HeapBlock {
char* data;
}
struct DataBlock {
int size;
HeapBlock hb;
}
These are part of a framework and have several other members, helpers and so on, but these are are the important parts. I would like to show this in a Python GDB pretty-printer something like this:
NAME TYPE VALUE
DataBlock: DataBlock "Size 2000 @ 0x445343"
|--->size int 2000
|--->data HeapBlock {...}
|--->[0] char 0x34
|--->[1] char 0x45
....
<more values>
So far, I have failed at getting the HeapBlock to be shown as a separate child. I have successfully abused an iterator to produce:
NAME TYPE VALUE
DataBlock: DataBlock
|--->size int 2000
|--->[0] char 0x34
|--->[1] char 0x45
....
<more values>
This was done by returning the db["size"]
in the first result from the iterator returned by DataBlockPrinter
's children()
method, and then from db["hb"]["data"]
for the next size
results.
I have also tried to use a separate printer for HeapBlocks
, but the problem there is that a HeapBlock
has no idea how big it is: that is stored in the parent (DataBlock
), so the HeapBlock
printer also doesn't know when to stop iterating.
Is it possible to get the size
field to the HeapBlock
pretty printer when it is printed as part of DataBlock
here?