xiaobai created this revision.
xiaobai added reviewers: JDevlieghere, jingham, clayborg, compnerd.
The methods to find types in a Target aren't clang specific and are
pretty generalizable to type systems. Additionally, to support some of
the use cases in SBTarget, I've added a "GetScratchTypeSystems" method
to Target to support getting all type systems for a target we are
debugging.
https://reviews.llvm.org/D64964
Files:
include/lldb/Target/Target.h
source/API/SBTarget.cpp
source/Target/Target.cpp
Index: source/Target/Target.cpp
===================================================================
--- source/Target/Target.cpp
+++ source/Target/Target.cpp
@@ -2199,6 +2199,29 @@
create_on_demand);
}
+std::vector<TypeSystem *> Target::GetScratchTypeSystems(Status *error,
+ bool create_on_demand) {
+ if (!m_valid)
+ return {};
+
+ std::vector<TypeSystem *> scratch_type_systems;
+
+ std::set<lldb::LanguageType> languages_for_types;
+ std::set<lldb::LanguageType> languages_for_expressions;
+
+ Language::GetLanguagesSupportingTypeSystems(languages_for_types,
+ languages_for_expressions);
+
+ for (auto lang : languages_for_expressions) {
+ if (auto *type_system =
+ GetScratchTypeSystemForLanguage(error, lang, create_on_demand)) {
+ scratch_type_systems.emplace_back(type_system);
+ }
+ }
+
+ return scratch_type_systems;
+}
+
PersistentExpressionState *
Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) {
TypeSystem *type_system =
Index: source/API/SBTarget.cpp
===================================================================
--- source/API/SBTarget.cpp
+++ source/API/SBTarget.cpp
@@ -44,11 +44,11 @@
#include "lldb/Core/ValueObjectList.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Host/Host.h"
-#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/DeclVendor.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/Language.h"
@@ -1858,11 +1858,12 @@
}
// No matches, search for basic typename matches
- ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
- if (clang_ast)
- return LLDB_RECORD_RESULT(SBType(ClangASTContext::GetBasicType(
- clang_ast->getASTContext(), const_typename)));
+ for (auto *type_system :
+ target_sp->GetScratchTypeSystems(/*error*/ nullptr))
+ if (auto type = type_system->GetBuiltinTypeByName(const_typename))
+ return LLDB_RECORD_RESULT(SBType(type));
}
+
return LLDB_RECORD_RESULT(SBType());
}
@@ -1872,10 +1873,10 @@
TargetSP target_sp(GetSP());
if (target_sp) {
- ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
- if (clang_ast)
- return LLDB_RECORD_RESULT(SBType(
- ClangASTContext::GetBasicType(clang_ast->getASTContext(), type)));
+ for (auto *type_system :
+ target_sp->GetScratchTypeSystems(/*error*/ nullptr))
+ if (auto compiler_type = type_system->GetBasicTypeFromAST(type))
+ return LLDB_RECORD_RESULT(SBType(compiler_type));
}
return LLDB_RECORD_RESULT(SBType());
}
@@ -1918,10 +1919,11 @@
if (sb_type_list.GetSize() == 0) {
// No matches, search for basic typename matches
- ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
- if (clang_ast)
- sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
- clang_ast->getASTContext(), const_typename)));
+ for (auto *type_system :
+ target_sp->GetScratchTypeSystems(/*error*/ nullptr))
+ if (auto compiler_type =
+ type_system->GetBuiltinTypeByName(const_typename))
+ sb_type_list.Append(SBType(compiler_type));
}
}
return LLDB_RECORD_RESULT(sb_type_list);
Index: include/lldb/Target/Target.h
===================================================================
--- include/lldb/Target/Target.h
+++ include/lldb/Target/Target.h
@@ -1031,6 +1031,9 @@
lldb::LanguageType language,
bool create_on_demand = true);
+ std::vector<TypeSystem *> GetScratchTypeSystems(Status *error,
+ bool create_on_demand = true);
+
PersistentExpressionState *
GetPersistentExpressionStateForLanguage(lldb::LanguageType language);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits