From 3031818a2e9fca1e53cd882ccfcc3718699991b4 Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Thu, 14 Nov 2019 13:41:52 -0800 Subject: [PATCH] [Target] Remove Target::GetScratchClangASTContext Target doesn't really need to know about ClangASTContext more than any other TypeSystem. We can create a method ClangASTContext::GetScratch for anything who needs a ClangASTContext specifically instead of just a generic TypeSystem. --- lldb/include/lldb/Symbol/ClangASTContext.h | 15 ++++++++++++++ lldb/include/lldb/Target/Target.h | 2 -- .../MacOSX-DYLD/DynamicLoaderDarwin.cpp | 2 +- .../MacOSX-DYLD/DynamicLoaderMacOS.cpp | 5 ++++- .../MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp | 5 ++++- .../Clang/ASTResultSynthesizer.cpp | 2 +- .../ExpressionParser/Clang/ClangASTSource.cpp | 17 ++++++++------- .../Clang/ClangExpressionDeclMap.cpp | 23 +++++++++++++-------- lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp | 11 ++++++---- lldb/source/Plugins/Language/ObjC/NSArray.cpp | 24 ++++++++++++---------- lldb/source/Plugins/Language/ObjC/NSDictionary.cpp | 2 +- lldb/source/Plugins/Language/ObjC/NSError.cpp | 12 +++++------ lldb/source/Plugins/Language/ObjC/NSException.cpp | 10 +++++---- lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp | 5 ++--- lldb/source/Plugins/Language/ObjC/NSString.cpp | 2 +- .../ItaniumABI/ItaniumABILanguageRuntime.cpp | 5 ++++- .../ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp | 16 +++++++++++---- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 14 +++++++------ .../AppleObjCTrampolineHandler.cpp | 15 +++++++++++--- .../Plugins/Platform/POSIX/PlatformPOSIX.cpp | 10 +++++++-- .../MacOSX/AppleGetItemInfoHandler.cpp | 2 +- .../MacOSX/AppleGetPendingItemsHandler.cpp | 4 ++-- .../SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp | 4 ++-- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 4 ++-- .../SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp | 2 +- lldb/source/Target/Target.cpp | 14 ------------- 26 files changed, 138 insertions(+), 89 deletions(-) diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 97b151c..43d4210 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -30,7 +30,10 @@ #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Symbol/CompilerType.h" #include "lldb/Symbol/TypeSystem.h" +#include "lldb/Target/Target.h" #include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Logging.h" #include "lldb/lldb-enumerations.h" class DWARFASTParserClang; @@ -86,6 +89,18 @@ public: static ClangASTContext *GetASTContext(clang::ASTContext *ast_ctx); + static ClangASTContext *GetScratch(Target &target, + bool create_on_demand = true) { + auto type_system_or_err = target.GetScratchTypeSystemForLanguage( + lldb::eLanguageTypeC, create_on_demand); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), + std::move(err), "Couldn't get scratch ClangASTContext"); + return nullptr; + } + return llvm::dyn_cast(&type_system_or_err.get()); + } + clang::ASTContext *getASTContext(); clang::Builtin::Context *getBuiltinContext(); diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 96c5a58..29384fa 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -1067,8 +1067,6 @@ public: const char *name, Status &error); - ClangASTContext *GetScratchClangASTContext(bool create_on_demand = true); - lldb::ClangASTImporterSP GetClangASTImporter(); // Install any files through the platform that need be to installed prior to diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index f8a7c9d..70064a5 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -1073,7 +1073,7 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp, StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0); if (frame_sp) { ClangASTContext *clang_ast_context = - target.GetScratchClangASTContext(); + ClangASTContext::GetScratch(target); if (!clang_ast_context) return LLDB_INVALID_ADDRESS; diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp index aab0e12..fd7d94f4 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -223,7 +223,10 @@ bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton, // get the values from the ABI: ClangASTContext *clang_ast_context = - process->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(process->GetTarget()); + if (!clang_ast_context) + return false; + ValueList argument_values; Value mode_value; // enum dyld_notify_mode { dyld_notify_adding=0, diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index fb8b48c..253215b 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -342,7 +342,10 @@ bool DynamicLoaderMacOSXDYLD::NotifyBreakpointHit( // get the values from the ABI: ClangASTContext *clang_ast_context = - process->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(process->GetTarget()); + if (!clang_ast_context) + return false; + ValueList argument_values; Value input_value; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index 68eaad3..24dc726 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -453,7 +453,7 @@ void ASTResultSynthesizer::CommitPersistentDecls() { ConstString name_cs(name.str().c_str()); Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl( - m_target.GetScratchClangASTContext()->getASTContext(), m_ast_context, + ClangASTContext::GetScratch(m_target)->getASTContext(), m_ast_context, decl); if (!D_scratch) { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 0fef262..d05c074 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -120,14 +120,17 @@ void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context, // Update the scratch AST context's merger to reflect any new sources we // might have come across since the last time an expression was parsed. - auto scratch_ast_context = static_cast( - m_target->GetScratchClangASTContext()); + if (auto *clang_ast_context = ClangASTContext::GetScratch(*m_target)) { - scratch_ast_context->GetMergerUnchecked().AddSources(sources); + auto scratch_ast_context = + static_cast(clang_ast_context); - sources.push_back({*scratch_ast_context->getASTContext(), - *scratch_ast_context->getFileManager(), - scratch_ast_context->GetOriginMap()}); + scratch_ast_context->GetMergerUnchecked().AddSources(sources); + + sources.push_back({*scratch_ast_context->getASTContext(), + *scratch_ast_context->getFileManager(), + scratch_ast_context->GetOriginMap()}); + } } m_merger_up = @@ -145,7 +148,7 @@ ClangASTSource::~ClangASTSource() { // demand by passing false to // Target::GetScratchClangASTContext(create_on_demand). ClangASTContext *scratch_clang_ast_context = - m_target->GetScratchClangASTContext(false); + ClangASTContext::GetScratch(*m_target, false); if (!scratch_clang_ast_context) return; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index 7a2dbbd..b16c181 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -108,7 +108,7 @@ bool ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx, m_parser_vars->m_persistent_vars = llvm::cast( target->GetPersistentExpressionStateForLanguage(eLanguageTypeC)); - if (!target->GetScratchClangASTContext()) + if (!ClangASTContext::GetScratch(*target)) return false; } @@ -201,7 +201,7 @@ static clang::QualType ExportAllDeclaredTypes( TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target, ClangASTContext &source, TypeFromParser parser_type) { - assert(&target == m_target->GetScratchClangASTContext()); + assert(&target == ClangASTContext::GetScratch(*m_target)); assert((TypeSystem *)&source == parser_type.GetTypeSystem()); assert(source.getASTContext() == m_ast_context); @@ -215,7 +215,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target, source.getASTContext()->getSourceManager().getFileID( source.getASTContext()->getTranslationUnitDecl()->getLocation()); auto scratch_ast_context = static_cast( - m_target->GetScratchClangASTContext()); + ClangASTContext::GetScratch(*m_target)); clang::QualType exported_type = ExportAllDeclaredTypes( *m_merger_up.get(), scratch_ast_context->GetMergerUnchecked(), *source.getASTContext(), *source.getFileManager(), @@ -248,8 +248,11 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl, if (target == nullptr) return false; - TypeFromUser user_type = - DeportType(*target->GetScratchClangASTContext(), *ast, parser_type); + auto *clang_ast_context = ClangASTContext::GetScratch(*target); + if (!clang_ast_context) + return false; + + TypeFromUser user_type = DeportType(*clang_ast_context, *ast, parser_type); uint32_t offset = m_parser_vars->m_materializer->AddResultVariable( user_type, is_lvalue, m_keep_result_in_memory, m_result_delegate, err); @@ -284,7 +287,9 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl, if (target == nullptr) return false; - ClangASTContext *context(target->GetScratchClangASTContext()); + ClangASTContext *context = ClangASTContext::GetScratch(*target); + if (!context) + return false; TypeFromUser user_type = DeportType(*context, *ast, parser_type); @@ -777,7 +782,7 @@ void ClangExpressionDeclMap::SearchPersistenDecls(NameSearchContext &context, return; ClangASTContext *scratch_clang_ast_context = - target->GetScratchClangASTContext(); + ClangASTContext::GetScratch(*target); if (!scratch_clang_ast_context) return; @@ -1714,7 +1719,9 @@ void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context, if (target == nullptr) return; - ClangASTContext *scratch_ast_context = target->GetScratchClangASTContext(); + ClangASTContext *scratch_ast_context = ClangASTContext::GetScratch(*target); + if (!scratch_ast_context) + return; TypeFromUser user_type(scratch_ast_context->GetBasicType(eBasicTypeVoid) .GetPointerType() diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index abe8903..ecadaef 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -572,10 +572,13 @@ bool lldb_private::formatters::LibcxxWStringSummaryProvider( location_sp->GetPointeeData(extractor, 0, size); // std::wstring::size() is measured in 'characters', not bytes - auto wchar_t_size = valobj.GetTargetSP() - ->GetScratchClangASTContext() - ->GetBasicType(lldb::eBasicTypeWChar) - .GetByteSize(nullptr); + ClangASTContext *ast_context = + ClangASTContext::GetScratch(*valobj.GetTargetSP()); + if (!ast_context) + return false; + + auto wchar_t_size = + ast_context->GetBasicType(lldb::eBasicTypeWChar).GetByteSize(nullptr); if (!wchar_t_size) return false; diff --git a/lldb/source/Plugins/Language/ObjC/NSArray.cpp b/lldb/source/Plugins/Language/ObjC/NSArray.cpp index 7219c01..3498c9d 100644 --- a/lldb/source/Plugins/Language/ObjC/NSArray.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSArray.cpp @@ -461,9 +461,8 @@ lldb_private::formatters::NSArrayMSyntheticFrontEndBase::NSArrayMSyntheticFrontE : SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8), m_id_type() { if (valobj_sp) { - auto *clang_ast_context = valobj_sp->GetExecutionContextRef() - .GetTargetSP() - ->GetScratchClangASTContext(); + auto *clang_ast_context = ClangASTContext::GetScratch( + *valobj_sp->GetExecutionContextRef().GetTargetSP()); if (clang_ast_context) m_id_type = CompilerType( clang_ast_context, @@ -610,9 +609,8 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd:: if (valobj_sp) { CompilerType type = valobj_sp->GetCompilerType(); if (type) { - auto *clang_ast_context = valobj_sp->GetExecutionContextRef() - .GetTargetSP() - ->GetScratchClangASTContext(); + auto *clang_ast_context = ClangASTContext::GetScratch( + *valobj_sp->GetExecutionContextRef().GetTargetSP()); if (clang_ast_context) m_id_type = CompilerType(clang_ast_context, clang_ast_context->getASTContext() @@ -780,11 +778,15 @@ lldb_private::formatters::NSArray1SyntheticFrontEnd::GetChildAtIndex( static const ConstString g_zero("[0]"); if (idx == 0) { - CompilerType id_type( - m_backend.GetTargetSP()->GetScratchClangASTContext()->GetBasicType( - lldb::eBasicTypeObjCID)); - return m_backend.GetSyntheticChildAtOffset( - m_backend.GetProcessSP()->GetAddressByteSize(), id_type, true, g_zero); + auto *clang_ast_context = + ClangASTContext::GetScratch(*m_backend.GetTargetSP()); + if (clang_ast_context) { + CompilerType id_type( + clang_ast_context->GetBasicType(lldb::eBasicTypeObjCID)); + return m_backend.GetSyntheticChildAtOffset( + m_backend.GetProcessSP()->GetAddressByteSize(), id_type, true, + g_zero); + } } return lldb::ValueObjectSP(); } diff --git a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp index 10f66c4..ae00674 100644 --- a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp @@ -65,7 +65,7 @@ NSDictionary_Additionals::GetAdditionalSynthetics() { static CompilerType GetLLDBNSPairType(TargetSP target_sp) { CompilerType compiler_type; - ClangASTContext *target_ast_context = target_sp->GetScratchClangASTContext(); + ClangASTContext *target_ast_context = ClangASTContext::GetScratch(*target_sp); if (target_ast_context) { ConstString g___lldb_autogen_nspair("__lldb_autogen_nspair"); diff --git a/lldb/source/Plugins/Language/ObjC/NSError.cpp b/lldb/source/Plugins/Language/ObjC/NSError.cpp index 97df3be..94a97c8 100644 --- a/lldb/source/Plugins/Language/ObjC/NSError.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSError.cpp @@ -86,10 +86,10 @@ bool lldb_private::formatters::NSError_SummaryProvider( ValueObjectSP domain_str_sp = ValueObject::CreateValueObjectFromData( "domain_str", isw.GetAsData(process_sp->GetByteOrder()), - valobj.GetExecutionContextRef(), process_sp->GetTarget() - .GetScratchClangASTContext() - ->GetBasicType(lldb::eBasicTypeVoid) - .GetPointerType()); + valobj.GetExecutionContextRef(), + ClangASTContext::GetScratch(process_sp->GetTarget()) + ->GetBasicType(lldb::eBasicTypeVoid) + .GetPointerType()); if (!domain_str_sp) return false; @@ -156,8 +156,8 @@ public: m_child_sp = CreateValueObjectFromData( "_userInfo", isw.GetAsData(process_sp->GetByteOrder()), m_backend.GetExecutionContextRef(), - process_sp->GetTarget().GetScratchClangASTContext()->GetBasicType( - lldb::eBasicTypeObjCID)); + ClangASTContext::GetScratch(process_sp->GetTarget()) + ->GetBasicType(lldb::eBasicTypeObjCID)); return false; } diff --git a/lldb/source/Plugins/Language/ObjC/NSException.cpp b/lldb/source/Plugins/Language/ObjC/NSException.cpp index 931794a..6f3c356 100644 --- a/lldb/source/Plugins/Language/ObjC/NSException.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSException.cpp @@ -69,10 +69,12 @@ static bool ExtractFields(ValueObject &valobj, ValueObjectSP *name_sp, InferiorSizedWord userinfo_isw(userinfo, *process_sp); InferiorSizedWord reserved_isw(reserved, *process_sp); - CompilerType voidstar = process_sp->GetTarget() - .GetScratchClangASTContext() - ->GetBasicType(lldb::eBasicTypeVoid) - .GetPointerType(); + auto *clang_ast_context = ClangASTContext::GetScratch(process_sp->GetTarget()); + if (!clang_ast_context) + return false; + + CompilerType voidstar = + clang_ast_context->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); if (name_sp) *name_sp = ValueObject::CreateValueObjectFromData( diff --git a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp index 9ee6021..587dd13 100644 --- a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp @@ -53,9 +53,8 @@ public: if (!type_system) return false; - ClangASTContext *ast = m_backend.GetExecutionContextRef() - .GetTargetSP() - ->GetScratchClangASTContext(); + ClangASTContext *ast = ClangASTContext::GetScratch( + *m_backend.GetExecutionContextRef().GetTargetSP()); if (!ast) return false; diff --git a/lldb/source/Plugins/Language/ObjC/NSString.cpp b/lldb/source/Plugins/Language/ObjC/NSString.cpp index 55e129b..ce54d65 100644 --- a/lldb/source/Plugins/Language/ObjC/NSString.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSString.cpp @@ -35,7 +35,7 @@ NSString_Additionals::GetAdditionalSummaries() { static CompilerType GetNSPathStore2Type(Target &target) { static ConstString g_type_name("__lldb_autogen_nspathstore2"); - ClangASTContext *ast_ctx = target.GetScratchClangASTContext(); + ClangASTContext *ast_ctx = ClangASTContext::GetScratch(target); if (!ast_ctx) return CompilerType(); diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp index 70b0b51..9efb021 100644 --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -537,7 +537,10 @@ ValueObjectSP ItaniumABILanguageRuntime::GetExceptionObjectForThread( return {}; ClangASTContext *clang_ast_context = - m_process->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(m_process->GetTarget()); + if (!clang_ast_context) + return {}; + CompilerType voidstar = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index 8ca9ad7..7076959 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -111,7 +111,10 @@ bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value, } } else { // If it is not a pointer, see if we can make it into a pointer. - ClangASTContext *ast_context = target->GetScratchClangASTContext(); + ClangASTContext *ast_context = ClangASTContext::GetScratch(*target); + if (!ast_context) + return false; + CompilerType opaque_type = ast_context->GetBasicType(eBasicTypeObjCID); if (!opaque_type) opaque_type = ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); @@ -123,7 +126,9 @@ bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value, arg_value_list.PushValue(value); // This is the return value: - ClangASTContext *ast_context = target->GetScratchClangASTContext(); + ClangASTContext *ast_context = ClangASTContext::GetScratch(*target); + if (!ast_context) + return false; CompilerType return_compiler_type = ast_context->GetCStringType(true); Value ret; @@ -494,9 +499,12 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException( reserved_dict = reserved_dict->GetSyntheticValue(); if (!reserved_dict) return ThreadSP(); + ClangASTContext *clang_ast_context = + ClangASTContext::GetScratch(*exception_sp->GetTargetSP()); + if (!clang_ast_context) + return ThreadSP(); CompilerType objc_id = - exception_sp->GetTargetSP()->GetScratchClangASTContext()->GetBasicType( - lldb::eBasicTypeObjCID); + clang_ast_context->GetBasicType(lldb::eBasicTypeObjCID); ValueObjectSP return_addresses; auto objc_object_from_address = [&exception_sp, &objc_id](uint64_t addr, diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 750b6ce..c2d24ed 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1301,7 +1301,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic( return DescriptorMapUpdateResult::Fail(); thread_sp->CalculateExecutionContext(exe_ctx); - ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); + ClangASTContext *ast = ClangASTContext::GetScratch(process->GetTarget()); if (!ast) return DescriptorMapUpdateResult::Fail(); @@ -1563,7 +1563,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() { return DescriptorMapUpdateResult::Fail(); thread_sp->CalculateExecutionContext(exe_ctx); - ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); + ClangASTContext *ast = ClangASTContext::GetScratch(process->GetTarget()); if (!ast) return DescriptorMapUpdateResult::Fail(); @@ -2672,10 +2672,12 @@ class ObjCExceptionRecognizedStackFrame : public RecognizedStackFrame { const lldb::ABISP &abi = process_sp->GetABI(); if (!abi) return; - CompilerType voidstar = process_sp->GetTarget() - .GetScratchClangASTContext() - ->GetBasicType(lldb::eBasicTypeVoid) - .GetPointerType(); + ClangASTContext *clang_ast_context = + ClangASTContext::GetScratch(process_sp->GetTarget()); + if (!clang_ast_context) + return; + CompilerType voidstar = + clang_ast_context->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); ValueList args; Value input_value; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index 379ef3d..36f95c06 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -522,7 +522,10 @@ bool AppleObjCTrampolineHandler::AppleObjCVTables::RefreshTrampolines( const ABI *abi = process->GetABI().get(); ClangASTContext *clang_ast_context = - process->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(process->GetTarget()); + if (!clang_ast_context) + return false; + ValueList argument_values; Value input_value; CompilerType clang_void_ptr_type = @@ -802,7 +805,10 @@ AppleObjCTrampolineHandler::SetupDispatchFunction(Thread &thread, // Next make the runner function for our implementation utility function. ClangASTContext *clang_ast_context = - thread.GetProcess()->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(thread.GetProcess()->GetTarget()); + if (!clang_ast_context) + return LLDB_INVALID_ADDRESS; + CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); Status error; @@ -895,7 +901,10 @@ AppleObjCTrampolineHandler::GetStepThroughDispatchPlan(Thread &thread, TargetSP target_sp(thread.CalculateTarget()); - ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = ClangASTContext::GetScratch(*target_sp); + if (!clang_ast_context) + return ret_plan_sp; + ValueList argument_values; Value void_ptr_value; CompilerType clang_void_ptr_type = diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index f24856b..2b64be6 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -706,7 +706,9 @@ PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, FunctionCaller *do_dlopen_function = nullptr; // Fetch the clang types we will need: - ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); + ClangASTContext *ast = ClangASTContext::GetScratch(process->GetTarget()); + if (!ast) + return nullptr; CompilerType clang_void_pointer_type = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); @@ -948,7 +950,11 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process, Value return_value; // Fetch the clang types we will need: - ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); + ClangASTContext *ast = ClangASTContext::GetScratch(process->GetTarget()); + if (!ast) { + error.SetErrorString("dlopen error: Unable to get ClangASTContext"); + return LLDB_INVALID_IMAGE_TOKEN; + } CompilerType clang_void_pointer_type = ast->GetBasicType(eBasicTypeVoid).GetPointerType(); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp index b75a581..571e1d8 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp @@ -229,7 +229,7 @@ AppleGetItemInfoHandler::GetItemInfo(Thread &thread, uint64_t item, lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = ClangASTContext::GetScratch(*target_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); GetItemInfoReturnInfo return_value; diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp index 05e34ab..be1b100 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp @@ -177,7 +177,7 @@ lldb::addr_t AppleGetPendingItemsHandler::SetupGetPendingItemsFunction( // Next make the runner function for our implementation utility function. Status error; ClangASTContext *clang_ast_context = - thread.GetProcess()->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(thread.GetProcess()->GetTarget()); CompilerType get_pending_items_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); get_pending_items_caller = @@ -228,7 +228,7 @@ AppleGetPendingItemsHandler::GetPendingItems(Thread &thread, addr_t queue, lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = ClangASTContext::GetScratch(*target_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); GetPendingItemsReturnInfo return_value; diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp index 7194c40..338d63d 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp @@ -191,7 +191,7 @@ AppleGetQueuesHandler::SetupGetQueuesFunction(Thread &thread, // Next make the runner function for our implementation utility function. ClangASTContext *clang_ast_context = - thread.GetProcess()->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(thread.GetProcess()->GetTarget()); CompilerType get_queues_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); Status error; @@ -231,7 +231,7 @@ AppleGetQueuesHandler::GetCurrentQueues(Thread &thread, addr_t page_to_free, lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = ClangASTContext::GetScratch(*target_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); GetQueuesReturnInfo return_value; diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp index 3dcfda2..22beda8 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp @@ -186,7 +186,7 @@ lldb::addr_t AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction( // Also make the FunctionCaller for this UtilityFunction: ClangASTContext *clang_ast_context = - thread.GetProcess()->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(thread.GetProcess()->GetTarget()); CompilerType get_thread_item_info_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); @@ -237,7 +237,7 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo(Thread &thread, lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); ProcessSP process_sp(thread.CalculateProcess()); TargetSP target_sp(thread.CalculateTarget()); - ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = ClangASTContext::GetScratch(*target_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); GetThreadItemInfoReturnInfo return_value; diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index 69e59bc..08e3737 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -412,7 +412,7 @@ void SystemRuntimeMacOSX::ReadLibdispatchTSDIndexes() { #endif ClangASTContext *ast_ctx = - m_process->GetTarget().GetScratchClangASTContext(); + ClangASTContext::GetScratch(m_process->GetTarget()); if (ast_ctx->getASTContext() && m_dispatch_tsd_indexes_addr != LLDB_INVALID_ADDRESS) { CompilerType uint16 = diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 59f7214..dbbfb536 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2258,20 +2258,6 @@ Target::GetUtilityFunctionForLanguage(const char *text, return utility_fn; } -ClangASTContext *Target::GetScratchClangASTContext(bool create_on_demand) { - if (!m_valid) - return nullptr; - - auto type_system_or_err = - GetScratchTypeSystemForLanguage(eLanguageTypeC, create_on_demand); - if (auto err = type_system_or_err.takeError()) { - LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), - std::move(err), "Couldn't get scratch ClangASTContext"); - return nullptr; - } - return llvm::dyn_cast(&type_system_or_err.get()); -} - ClangASTImporterSP Target::GetClangASTImporter() { if (m_valid) { if (!m_ast_importer_sp) { -- 2.7.4