[Lldb-commits] [lldb] r367480 - [API] Remove use of ClangASTContext from SBTarget
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 31 13:47:39 PDT 2019
Author: xiaobai
Date: Wed Jul 31 13:47:38 2019
New Revision: 367480
URL: http://llvm.org/viewvc/llvm-project?rev=367480&view=rev
Log:
[API] Remove use of ClangASTContext from SBTarget
Summary:
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.
Differential Revision: https://reviews.llvm.org/D64964
Modified:
lldb/trunk/include/lldb/Target/Target.h
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Target/Target.cpp
Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=367480&r1=367479&r2=367480&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Wed Jul 31 13:47:38 2019
@@ -1026,6 +1026,8 @@ public:
GetScratchTypeSystemForLanguage(lldb::LanguageType language,
bool create_on_demand = true);
+ std::vector<TypeSystem *> GetScratchTypeSystems(bool create_on_demand = true);
+
PersistentExpressionState *
GetPersistentExpressionStateForLanguage(lldb::LanguageType language);
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=367480&r1=367479&r2=367480&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Wed Jul 31 13:47:38 2019
@@ -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,11 @@ lldb::SBType SBTarget::FindFirstType(con
}
// 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())
+ if (auto type = type_system->GetBuiltinTypeByName(const_typename))
+ return LLDB_RECORD_RESULT(SBType(type));
}
+
return LLDB_RECORD_RESULT(SBType());
}
@@ -1872,10 +1872,9 @@ SBType SBTarget::GetBasicType(lldb::Basi
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())
+ if (auto compiler_type = type_system->GetBasicTypeFromAST(type))
+ return LLDB_RECORD_RESULT(SBType(compiler_type));
}
return LLDB_RECORD_RESULT(SBType());
}
@@ -1918,10 +1917,10 @@ lldb::SBTypeList SBTarget::FindTypes(con
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())
+ if (auto compiler_type =
+ type_system->GetBuiltinTypeByName(const_typename))
+ sb_type_list.Append(SBType(compiler_type));
}
}
return LLDB_RECORD_RESULT(sb_type_list);
Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=367480&r1=367479&r2=367480&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Wed Jul 31 13:47:38 2019
@@ -2153,6 +2153,34 @@ Target::GetScratchTypeSystemForLanguage(
create_on_demand);
}
+std::vector<TypeSystem *> Target::GetScratchTypeSystems(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) {
+ auto type_system_or_err =
+ GetScratchTypeSystemForLanguage(lang, create_on_demand);
+ if (!type_system_or_err)
+ LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
+ type_system_or_err.takeError(),
+ "Language '{}' has expression support but no scratch type "
+ "system available",
+ Language::GetNameForLanguageType(lang));
+ else
+ scratch_type_systems.emplace_back(&type_system_or_err.get());
+ }
+
+ return scratch_type_systems;
+}
+
PersistentExpressionState *
Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) {
auto type_system_or_err = GetScratchTypeSystemForLanguage(language, true);
More information about the lldb-commits
mailing list