|
19 | 19 | #include <lldb/API/LLDB.h>
|
20 | 20 | #include <cassert>
|
21 | 21 |
|
| 22 | +namespace std { |
| 23 | +/* We use the address of the name string for hashing and equality. |
| 24 | + * This relies on string de-duplication, two objects with the same name |
| 25 | + * might have different addresses, but their de-duplicated name will |
| 26 | + * have the same address. |
| 27 | + * |
| 28 | + * TODO: Is this correct? How does -fsimple-template-names impact this? |
| 29 | + * Is there a better way to do this? |
| 30 | + */ |
| 31 | +size_t hash<lldb::SBType>::operator()(const lldb::SBType& key) const { |
| 32 | + auto *name = const_cast<lldb::SBType&>(key).GetName(); |
| 33 | + auto Hasher = std::hash<const char*>(); |
| 34 | + { /* Debugging |
| 35 | + auto &keyAsSP = reinterpret_cast<const lldb::TypeImplSP&>(key); |
| 36 | + fprintf(stderr, "LLDBType::hash(key@0x%08zx = (0x%08zx, %s)) = 0x%08zx\n", |
| 37 | + (uintptr_t)keyAsSP.get(), (uintptr_t)name, name, Hasher(name)); |
| 38 | + // Debugging */ |
| 39 | + } |
| 40 | + return Hasher(name); |
| 41 | +} |
| 42 | + |
| 43 | +bool equal_to<lldb::SBType>::operator()(const lldb::SBType& lhs, const lldb::SBType& rhs) const { |
| 44 | + auto* lhsName = const_cast<lldb::SBType&>(lhs).GetName(); |
| 45 | + auto* rhsName = const_cast<lldb::SBType&>(rhs).GetName(); |
| 46 | + auto EqualTo = std::equal_to<const char*>(); |
| 47 | + { /* Debugging |
| 48 | + auto &lhsAsSP = reinterpret_cast<const lldb::TypeImplSP&>(lhs); |
| 49 | + auto &rhsAsSP = reinterpret_cast<const lldb::TypeImplSP&>(rhs); |
| 50 | + fprintf(stderr, "LLDBType::equal_to(lhs@0x%08zx = (0x%08zx, %s), rhs@0x%08zx = (0x%08zx, %s)) = %d\n", |
| 51 | + (uintptr_t)lhsAsSP.get(), (uintptr_t)lhsName, lhsName, |
| 52 | + (uintptr_t)rhsAsSP.get(), (uintptr_t)rhsName, rhsName, |
| 53 | + EqualTo(lhsName, rhsName)); |
| 54 | + // Debugging */ |
| 55 | + } |
| 56 | + return EqualTo(lhsName, rhsName); |
| 57 | +} |
| 58 | +} // namespace std |
| 59 | + |
22 | 60 | namespace oi::detail::type_graph {
|
23 | 61 |
|
24 | 62 | Type& LLDBParser::parse(lldb::SBType& root) {
|
@@ -119,12 +157,25 @@ Class& LLDBParser::enumerateClass(lldb::SBType& type) {
|
119 | 157 |
|
120 | 158 | auto &c = makeType<Class>(type, kind, displayName, name, size, virtuality);
|
121 | 159 |
|
| 160 | + enumerateClassParents(type, c.parents); |
122 | 161 | enumerateClassMembers(type, c.members);
|
123 | 162 | enumerateClassFunctions(type, c.functions);
|
124 | 163 |
|
125 | 164 | return c;
|
126 | 165 | }
|
127 | 166 |
|
| 167 | +void LLDBParser::enumerateClassParents(lldb::SBType& type, std::vector<Parent>& parents) { |
| 168 | + assert(parents.empty()); |
| 169 | + parents.reserve(type.GetNumberOfDirectBaseClasses()); |
| 170 | + |
| 171 | + for (uint32_t i = 0; i < type.GetNumberOfDirectBaseClasses(); i++) { |
| 172 | + auto base = type.GetDirectBaseClassAtIndex(i); |
| 173 | + auto baseType = base.GetType(); |
| 174 | + |
| 175 | + parents.emplace_back(enumerateType(baseType), base.GetOffsetInBits()); |
| 176 | + } |
| 177 | +} |
| 178 | + |
128 | 179 | void LLDBParser::enumerateClassMembers(lldb::SBType& type, std::vector<Member>& members) {
|
129 | 180 | assert(members.empty());
|
130 | 181 | members.reserve(type.GetNumberOfFields());
|
|
0 commit comments