struct VirtualInheritanceTestSetup
Defined at line 75 of file ../../src/developer/debug/zxdb/expr/virtual_inheritance_test_setup.h
Setup the required information for a test hierarchy including virtual inheritance. Virtual
inheritance in C++ isn't just inheritance with virtual functions, but rather:
class Derived : public virtual Bar { ... }
The "virtual" in this case means that the base class is accessed indirectly, allowing diamond
inheritance to be resolved. This indirect operation is expressed as an expression in the
DWARF inheritance information rather than the constant offset used by normal inheritance.
This class sets up an inheritance hierarchy with three steps of inheritance between four classes:
class Derived : public IntermediateDerived { // Non-virtual.
int derived_i = 1;
};
class IntermediateDerived : public virtual IntermediateBase { // Virtual
int intermediate_derived_i = 2;
};
class IntermediateBase : public Base { // Non-virtual
int intermediate_base_i = 3;
};
class Base {
int base_i = 4;
};
The binary structure looks like this:
Value
+----------------------------------+------------+
Derived -> | derived_i (4 bytes) | 1 |
+----------------------------------+------------+
IntermediateDerived -> |
<vtable
_ptr> (8 bytes) | kVtablePtr |
| intermediate_derived_i (4 bytes) | 2 |
+----------------------------------+------------+
IntermediateBase -> | intermediate_base_i (4 bytes) | 3 |
+----------------------------------+------------+
Base -> | base_i (4 bytes) | 4 |
+----------------------------------+------------+
Note that this is actually backwards than most compilers will generated (they will normally
put "Base" at the beginning of "IntermediateBase") but doing it this way allows us to have an
offset for each step of inheritance which is better for testing.
+---------------------------------------------------------------------+
kVirtualDataAddress -> |
<offset
of "IntermediateBase" from "IntermediateDerived"> (8 bytes) |
|
<some
other value> (8 bytes) |
|
<some
other value> (8 bytes) |
+---------------------------------------------------------------------+
vtable_ptr -> |
<vtable
entries> |
| ... |
The vtable_ptr referenced in the structure is 24 bytes after the offset needed (this is taken
from what GCC generated for a test). This offset is retrieved and added to the
IntermediateDerived pointer to get the address of IntermediateBase (so the offset should be 4).
This uses GCC's style of expressions. See also ResolveCollectionTest.VirtualInheritance which
tests Clang's version of virtual inheritance.
Public Members
RefPtr derived
RefPtr intermediate_derived_inherited
RefPtr intermediate_derived
RefPtr intermediate_base_inherited
RefPtr intermediate_base
RefPtr base_inherited
RefPtr base
ExprValue derived_value
vector virtual_data
static const TargetPointer kDerivedAddress
static const TargetPointer kIntermediateDerivedAddress
static const TargetPointer kIntermediateBaseAddress
static const TargetPointer kBaseAddress
static const TargetPointer kVirtualDataAddress
static const TargetPointer kVtablePtr
Public Methods
void VirtualInheritanceTestSetup ()
Defined at line 15 of file ../../src/developer/debug/zxdb/expr/virtual_inheritance_test_setup.cc
void SaveMockData (MockSymbolDataProvider * mock)
Sets the mock vtable data to be served.
Defined at line 87 of file ../../src/developer/debug/zxdb/expr/virtual_inheritance_test_setup.cc