[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures
Vlad Serebrennikov via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sun Aug 20 00:39:46 PDT 2023
Endill added a comment.
I tested this patch together with the following new code:
uint32_t TypeSystemClang::GetNumMemberEnums(lldb::opaque_compiler_type_t type) {
using EnumIt = clang::DeclContext::specific_decl_iterator<clang::EnumDecl>;
if (!type)
return 0;
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
clang::DeclContext *ctx = qual_type->getAsRecordDecl()->getDeclContext();
return std::distance(EnumIt(ctx->decls_begin()), EnumIt(ctx->decls_end()));
}
CompilerType
TypeSystemClang::GetMemberEnumAtIndex(lldb::opaque_compiler_type_t type,
size_t index) {
using EnumIt = clang::DeclContext::specific_decl_iterator<clang::EnumDecl>;
if (!type)
return CompilerType();
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
clang::DeclContext *ctx = qual_type->getAsRecordDecl()->getDeclContext();
size_t enum_index = 0;
for (EnumIt enums_it(ctx->decls_begin()), enums_end(ctx->decls_end());
enums_it != enums_end;
++enums_it, ++enum_index) {
if (enum_index == index) {
return CompilerType(weak_from_this(), *enums_it);
}
}
}
I created all the wrappers to make it available in Python. The result was unsatisfactory: this code doesn't even trigger `DWARFASTParserClang::ParseChildMembers` that this patch touches, and return 0 instead of 1. This doesn't change even if I trigger `ParseChildMembers` via other means before asking for a number of member enums in a type.
Code I tested this on:
using intptr_t = long;
using uintptr_t = unsigned long;
struct PointerIntPairInfo {
enum MaskAndShiftConstants : uintptr_t {
PointerBitMask =
~(uintptr_t)(((intptr_t)1 << 3) - 1),
};
int a{};
};
static uintptr_t dummy() {
return PointerIntPairInfo::PointerBitMask;
}
int main()
{
PointerIntPairInfo p;
__builtin_debugtrap();
return p.a + foo();
}
If you have any suggestions what I missed or did wrong, please let me know.
I'll continue with this patch nevertheless, but it's clear now that there's still a way to go until I can access that enum without going through slow expression evaluator.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156774/new/
https://reviews.llvm.org/D156774
More information about the lldb-commits
mailing list