Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lldb/bindings/interface/SBTypeDocstrings.i
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,13 @@ SBType supports the eq/ne operator. For example,::
"
) lldb::SBType::GetTypeFlags;

%feature("docstring",
"Searches for a nested type that has provided name.

Returns the type if it was found.
Returns invalid type if nothing was found."
) lldb::SBType::FindNestedType;

%feature("docstring",
"Represents a list of :py:class:`SBType` s.

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBType.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class SBType {
bool GetDescription(lldb::SBStream &description,
lldb::DescriptionLevel description_level);

lldb::SBType FindNestedType(const char *name);

lldb::SBType &operator=(const lldb::SBType &rhs);

bool operator==(lldb::SBType &rhs);
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Symbol/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ class TypeImpl {
bool GetDescription(lldb_private::Stream &strm,
lldb::DescriptionLevel description_level);

CompilerType FindNestedType(ConstString name);

private:
bool CheckModule(lldb::ModuleSP &module_sp) const;
bool CheckExeModule(lldb::ModuleSP &module_sp) const;
Expand Down
5 changes: 5 additions & 0 deletions lldb/include/lldb/Symbol/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class TypeSystem : public PluginInterface,

virtual lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) = 0;

// CompilerType functions

virtual CompilerDeclContext
GetCompilerDeclContextForType(const CompilerType &type);

// Tests
#ifndef NDEBUG
/// Verify the integrity of the type to catch CompilerTypes that mix
Expand Down
9 changes: 9 additions & 0 deletions lldb/source/API/SBType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,15 @@ lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) {
return eTemplateArgumentKindNull;
}

SBType SBType::FindNestedType(const char *name) {
LLDB_INSTRUMENT_VA(this, name);

if (!IsValid())
return SBType();
auto ret = SBType(m_opaque_sp->FindNestedType(ConstString(name)));
return ret;
}

SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {
LLDB_INSTRUMENT_VA(this);
}
Expand Down
7 changes: 7 additions & 0 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,6 +2636,13 @@ TypeSystemClang::GetDeclContextForType(const CompilerType &type) {
return GetDeclContextForType(ClangUtil::GetQualType(type));
}

CompilerDeclContext
TypeSystemClang::GetCompilerDeclContextForType(const CompilerType &type) {
if (auto *decl_context = GetDeclContextForType(type))
return CreateDeclContext(decl_context);
return CompilerDeclContext();
}

/// Aggressively desugar the provided type, skipping past various kinds of
/// syntactic sugar and other constructs one typically wants to ignore.
/// The \p mask argument allows one to skip certain kinds of simplifications,
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ class TypeSystemClang : public TypeSystem {

static clang::DeclContext *GetDeclContextForType(const CompilerType &type);

CompilerDeclContext
GetCompilerDeclContextForType(const CompilerType &type) override;

uint32_t GetPointerByteSize() override;

clang::TranslationUnitDecl *GetTranslationUnitDecl() {
Expand Down
15 changes: 15 additions & 0 deletions lldb/source/Symbol/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,21 @@ bool TypeImpl::GetDescription(lldb_private::Stream &strm,
return true;
}

CompilerType TypeImpl::FindNestedType(ConstString name) {
auto type_system = GetTypeSystem(/*prefer_dynamic*/ false);
auto *symbol_file = type_system->GetSymbolFile();
auto decl_context = type_system->GetCompilerDeclContextForType(m_static_type);
if (!decl_context.IsValid())
return CompilerType();
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
TypeMap search_result;
symbol_file->FindTypes(name, decl_context, /*max_matches*/ 1,
searched_symbol_files, search_result);
if (search_result.Empty())
return CompilerType();
return search_result.GetTypeAtIndex(0)->GetFullCompilerType();
}

bool TypeMemberFunctionImpl::IsValid() {
return m_type.IsValid() && m_kind != lldb::eMemberFunctionKindUnknown;
}
Expand Down
5 changes: 5 additions & 0 deletions lldb/source/Symbol/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ std::optional<llvm::json::Value> TypeSystem::ReportStatistics() {
return std::nullopt;
}

CompilerDeclContext
TypeSystem::GetCompilerDeclContextForType(const CompilerType &type) {
return CompilerDeclContext();
}

#pragma mark TypeSystemMap

TypeSystemMap::TypeSystemMap() : m_mutex(), m_map() {}
Expand Down
9 changes: 9 additions & 0 deletions lldb/test/API/python_api/type/TestTypeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def test(self):

self.assertEqual(task_type, task_head_pointee_type)

# Check whether we can find a nested type by name
name_type = task_type.FindNestedType("name")
self.assertTrue(name_type)
self.DebugSBType(name_type)

task_ptr_type = task_type.GetPointerType()
invalid_type = task_ptr_type.FindNestedType("name")
self.assertFalse(invalid_type.IsValid())

# We'll now get the child member 'id' from 'task_head'.
id = task_head.GetChildMemberWithName("id")
self.DebugSBValue(id)
Expand Down