diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:53:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:53:01 +0000 |
commit | ead246455adf1a215ec2715dad6533073a6beb4e (patch) | |
tree | f3f97a47d77053bf96fe74cdbd6fae74380e8a92 /source/Plugins/SymbolFile/NativePDB | |
parent | fdb00c4408990a0a63ef7f496d809ce59f263bc5 (diff) | |
download | src-vendor/lldb.tar.gz src-vendor/lldb.zip |
Vendor import of stripped lldb trunk r375505, the last commit before thevendor/lldb/lldb-trunk-r375505vendor/lldb
upstream Subversion repository was made read-only, and the LLVM project
migrated to GitHub:
https://llvm.org/svn/llvm-project/lldb/trunk@375505
Notes
Notes:
svn path=/vendor/lldb/dist/; revision=353952
svn path=/vendor/lldb/lldb-r375505/; revision=353953; tag=vendor/lldb/lldb-trunk-r375505
Diffstat (limited to 'source/Plugins/SymbolFile/NativePDB')
8 files changed, 135 insertions, 174 deletions
diff --git a/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp b/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp index 1838204e4ca6..830d78f81679 100644 --- a/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp +++ b/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp @@ -130,7 +130,7 @@ CompilandIndexItem &CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) { if (!stream_data) { llvm::pdb::ModuleDebugStreamRef debug_stream(descriptor, nullptr); - cci = llvm::make_unique<CompilandIndexItem>(PdbCompilandId{ modi }, debug_stream, std::move(descriptor)); + cci = std::make_unique<CompilandIndexItem>(PdbCompilandId{ modi }, debug_stream, std::move(descriptor)); return *cci; } @@ -139,7 +139,7 @@ CompilandIndexItem &CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) { cantFail(debug_stream.reload()); - cci = llvm::make_unique<CompilandIndexItem>( + cci = std::make_unique<CompilandIndexItem>( PdbCompilandId{modi}, std::move(debug_stream), std::move(descriptor)); ParseExtendedInfo(m_index, *cci); diff --git a/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp b/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp index 3d8bfb058721..6aaff06cc134 100644 --- a/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp +++ b/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp @@ -122,7 +122,7 @@ static DWARFExpression MakeLocationExpressionInternal(lldb::ModuleSP module, DataBufferSP buffer = std::make_shared<DataBufferHeap>(stream.GetData(), stream.GetSize()); DataExtractor extractor(buffer, byte_order, address_size, byte_size); - DWARFExpression result(module, extractor, nullptr, 0, buffer->GetByteSize()); + DWARFExpression result(module, extractor, nullptr); result.SetRegisterKind(register_kind); return result; @@ -247,6 +247,6 @@ DWARFExpression lldb_private::npdb::MakeConstantLocationExpression( .take_front(size); buffer->CopyData(bytes.data(), size); DataExtractor extractor(buffer, lldb::eByteOrderLittle, address_size); - DWARFExpression result(nullptr, extractor, nullptr, 0, size); + DWARFExpression result(nullptr, extractor, nullptr); return result; } diff --git a/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp index 4991be8e70ce..986b0b785d87 100644 --- a/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -121,13 +121,6 @@ AnyScopesHaveTemplateParams(llvm::ArrayRef<llvm::ms_demangle::Node *> scopes) { return false; } -static ClangASTContext &GetClangASTContext(ObjectFile &obj) { - TypeSystem *ts = - obj.GetModule()->GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); - lldbassert(ts); - return static_cast<ClangASTContext &>(*ts); -} - static llvm::Optional<clang::CallingConv> TranslateCallingConvention(llvm::codeview::CallingConvention conv) { using CC = llvm::codeview::CallingConvention; @@ -209,8 +202,8 @@ static bool IsAnonymousNamespaceName(llvm::StringRef name) { return name == "`anonymous namespace'" || name == "`anonymous-namespace'"; } -PdbAstBuilder::PdbAstBuilder(ObjectFile &obj, PdbIndex &index) - : m_index(index), m_clang(GetClangASTContext(obj)) { +PdbAstBuilder::PdbAstBuilder(ObjectFile &obj, PdbIndex &index, ClangASTContext &clang) + : m_index(index), m_clang(clang) { BuildParentMap(); } @@ -465,9 +458,9 @@ clang::Decl *PdbAstBuilder::GetOrCreateSymbolForId(PdbCompilandSymId id) { } } -clang::Decl *PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { +llvm::Optional<CompilerDecl> PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { if (clang::Decl *result = TryGetDecl(uid)) - return result; + return ToCompilerDecl(*result); clang::Decl *result = nullptr; switch (uid.kind()) { @@ -480,13 +473,13 @@ clang::Decl *PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) { result = tag; break; } - return nullptr; + return llvm::None; } default: - return nullptr; + return llvm::None; } m_uid_to_decl[toOpaqueUid(uid)] = result; - return result; + return ToCompilerDecl(*result); } clang::DeclContext *PdbAstBuilder::GetOrCreateDeclContextForUid(PdbSymUid uid) { @@ -494,8 +487,10 @@ clang::DeclContext *PdbAstBuilder::GetOrCreateDeclContextForUid(PdbSymUid uid) { if (uid.asCompilandSym().offset == 0) return FromCompilerDeclContext(GetTranslationUnitDecl()); } - - clang::Decl *decl = GetOrCreateDeclForUid(uid); + auto option = GetOrCreateDeclForUid(uid); + if (!option) + return nullptr; + clang::Decl *decl = FromCompilerDecl(option.getValue()); if (!decl) return nullptr; @@ -1089,7 +1084,7 @@ void PdbAstBuilder::CreateFunctionParameters(PdbCompilandSymId func_id, CompilerType param_type_ct(&m_clang, qt.getAsOpaquePtr()); clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration( &function_decl, param_name.str().c_str(), param_type_ct, - clang::SC_None); + clang::SC_None, true); lldbassert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0); m_uid_to_decl[toOpaqueUid(param_uid)] = param; diff --git a/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h b/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h index 67d024741e0d..a4242e90810d 100644 --- a/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h +++ b/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h @@ -51,11 +51,12 @@ struct DeclStatus { class PdbAstBuilder { public: // Constructors and Destructors - PdbAstBuilder(ObjectFile &obj, PdbIndex &index); + PdbAstBuilder(ObjectFile &obj, PdbIndex &index, ClangASTContext &clang); lldb_private::CompilerDeclContext GetTranslationUnitDecl(); - clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid); + llvm::Optional<lldb_private::CompilerDecl> + GetOrCreateDeclForUid(PdbSymUid uid); clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid); clang::DeclContext *GetParentDeclContext(PdbSymUid uid); @@ -76,7 +77,7 @@ public: CompilerDecl ToCompilerDecl(clang::Decl &decl); CompilerType ToCompilerType(clang::QualType qt); CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context); - clang::Decl * FromCompilerDecl(CompilerDecl decl); + clang::Decl *FromCompilerDecl(CompilerDecl decl); clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context); ClangASTContext &clang() { return m_clang; } diff --git a/source/Plugins/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpression.cpp b/source/Plugins/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpression.cpp index 79dd010ff311..a7bc23519710 100644 --- a/source/Plugins/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpression.cpp +++ b/source/Plugins/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpression.cpp @@ -51,54 +51,23 @@ static uint32_t ResolveLLDBRegisterNum(llvm::StringRef reg_name, llvm::Triple::A return npdb::GetLLDBRegisterNumber(arch_type, reg_id); } -static bool ParseFPOSingleAssignmentProgram(llvm::StringRef program, - llvm::BumpPtrAllocator &alloc, - llvm::StringRef ®ister_name, - Node *&ast) { - // lvalue of assignment is always first token - // rvalue program goes next - std::tie(register_name, program) = getToken(program); - if (register_name.empty()) - return false; - - ast = Parse(program, alloc); - return ast != nullptr; -} - -static Node *ParseFPOProgram(llvm::StringRef program, +static Node *ResolveFPOProgram(llvm::StringRef program, llvm::StringRef register_name, llvm::Triple::ArchType arch_type, llvm::BumpPtrAllocator &alloc) { - llvm::DenseMap<llvm::StringRef, Node *> dependent_programs; - - size_t cur = 0; - while (true) { - size_t assign_index = program.find('=', cur); - if (assign_index == llvm::StringRef::npos) { - llvm::StringRef tail = program.slice(cur, llvm::StringRef::npos); - if (!tail.trim().empty()) { - // missing assign operator - return nullptr; - } - break; - } - llvm::StringRef assignment_program = program.slice(cur, assign_index); - - llvm::StringRef lvalue_name; - Node *rvalue_ast = nullptr; - if (!ParseFPOSingleAssignmentProgram(assignment_program, alloc, lvalue_name, - rvalue_ast)) { - return nullptr; - } - - lldbassert(rvalue_ast); + std::vector<std::pair<llvm::StringRef, Node *>> parsed = + postfix::ParseFPOProgram(program, alloc); + for (auto it = parsed.begin(), end = parsed.end(); it != end; ++it) { // Emplace valid dependent subtrees to make target assignment independent // from predecessors. Resolve all other SymbolNodes as registers. bool success = - ResolveSymbols(rvalue_ast, [&](SymbolNode &symbol) -> Node * { - if (Node *node = dependent_programs.lookup(symbol.GetName())) - return node; + ResolveSymbols(it->second, [&](SymbolNode &symbol) -> Node * { + for (const auto &pair : llvm::make_range(parsed.begin(), it)) { + if (pair.first == symbol.GetName()) + return pair.second; + } + uint32_t reg_num = ResolveLLDBRegisterNum(symbol.GetName().drop_front(1), arch_type); @@ -110,13 +79,10 @@ static Node *ParseFPOProgram(llvm::StringRef program, if (!success) return nullptr; - if (lvalue_name == register_name) { + if (it->first == register_name) { // found target assignment program - no need to parse further - return rvalue_ast; + return it->second; } - - dependent_programs[lvalue_name] = rvalue_ast; - cur = assign_index + 1; } return nullptr; @@ -127,7 +93,7 @@ bool lldb_private::npdb::TranslateFPOProgramToDWARFExpression( llvm::Triple::ArchType arch_type, Stream &stream) { llvm::BumpPtrAllocator node_alloc; Node *target_program = - ParseFPOProgram(program, register_name, arch_type, node_alloc); + ResolveFPOProgram(program, register_name, arch_type, node_alloc); if (target_program == nullptr) { return false; } diff --git a/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp b/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp index 1f5c97da81cf..fc047e25a2f4 100644 --- a/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp +++ b/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp @@ -641,14 +641,14 @@ VariableInfo lldb_private::npdb::GetVariableLocationInfo( llvm::StringRef program; if (GetFrameDataProgram(index, ranges, program)) { result.location = - MakeVFrameRelLocationExpression(program, loc.Offset, module); + MakeVFrameRelLocationExpression(program, loc.Hdr.Offset, module); result.ranges = std::move(ranges); } else { // invalid variable } } else { result.location = - MakeRegRelLocationExpression(base_reg, loc.Offset, module); + MakeRegRelLocationExpression(base_reg, loc.Hdr.Offset, module); result.ranges = std::move(ranges); } } else if (loc_specifier_cvs.kind() == S_DEFRANGE_REGISTER_REL) { diff --git a/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index e27d4699ae2f..33b8da3b543b 100644 --- a/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -20,7 +20,6 @@ #include "lldb/Core/StreamBuffer.h" #include "lldb/Core/StreamFile.h" #include "lldb/Symbol/ClangASTContext.h" -#include "lldb/Symbol/ClangASTImporter.h" #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Symbol/ClangUtil.h" #include "lldb/Symbol/CompileUnit.h" @@ -30,6 +29,7 @@ #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Symbol/Variable.h" #include "lldb/Symbol/VariableList.h" +#include "lldb/Utility/Log.h" #include "llvm/DebugInfo/CodeView/CVRecord.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" @@ -90,10 +90,10 @@ static std::unique_ptr<PDBFile> loadPDBFile(std::string PdbPath, std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); llvm::StringRef Path = Buffer->getBufferIdentifier(); - auto Stream = llvm::make_unique<llvm::MemoryBufferByteStream>( + auto Stream = std::make_unique<llvm::MemoryBufferByteStream>( std::move(Buffer), llvm::support::little); - auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), Allocator); + auto File = std::make_unique<PDBFile>(Path, std::move(Stream), Allocator); if (auto EC = File->parseFileHeaders()) { llvm::consumeError(std::move(EC)); return nullptr; @@ -119,6 +119,8 @@ loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) { } OwningBinary<Binary> binary = std::move(*expected_binary); + // TODO: Avoid opening the PE/COFF binary twice by reading this information + // directly from the lldb_private::ObjectFile. auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary()); if (!obj) return nullptr; @@ -264,27 +266,27 @@ const char *SymbolFileNativePDB::GetPluginDescriptionStatic() { return "Microsoft PDB debug symbol cross-platform file reader."; } -SymbolFile *SymbolFileNativePDB::CreateInstance(ObjectFile *obj_file) { - return new SymbolFileNativePDB(obj_file); +SymbolFile *SymbolFileNativePDB::CreateInstance(ObjectFileSP objfile_sp) { + return new SymbolFileNativePDB(std::move(objfile_sp)); } -SymbolFileNativePDB::SymbolFileNativePDB(ObjectFile *object_file) - : SymbolFile(object_file) {} +SymbolFileNativePDB::SymbolFileNativePDB(ObjectFileSP objfile_sp) + : SymbolFile(std::move(objfile_sp)) {} SymbolFileNativePDB::~SymbolFileNativePDB() {} uint32_t SymbolFileNativePDB::CalculateAbilities() { uint32_t abilities = 0; - if (!m_obj_file) + if (!m_objfile_sp) return 0; if (!m_index) { // Lazily load and match the PDB file, but only do this once. std::unique_ptr<PDBFile> file_up = - loadMatchingPDBFile(m_obj_file->GetFileSpec().GetPath(), m_allocator); + loadMatchingPDBFile(m_objfile_sp->GetFileSpec().GetPath(), m_allocator); if (!file_up) { - auto module_sp = m_obj_file->GetModule(); + auto module_sp = m_objfile_sp->GetModule(); if (!module_sp) return 0; // See if any symbol file is specified through `--symfile` option. @@ -317,19 +319,24 @@ uint32_t SymbolFileNativePDB::CalculateAbilities() { } void SymbolFileNativePDB::InitializeObject() { - m_obj_load_address = m_obj_file->GetBaseAddress().GetFileAddress(); + m_obj_load_address = m_objfile_sp->GetBaseAddress().GetFileAddress(); m_index->SetLoadAddress(m_obj_load_address); m_index->ParseSectionContribs(); - TypeSystem *ts = m_obj_file->GetModule()->GetTypeSystemForLanguage( + auto ts_or_err = m_objfile_sp->GetModule()->GetTypeSystemForLanguage( lldb::eLanguageTypeC_plus_plus); - if (ts) - ts->SetSymbolFile(this); - - m_ast = llvm::make_unique<PdbAstBuilder>(*m_obj_file, *m_index); + if (auto err = ts_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Failed to initialize"); + } else { + ts_or_err->SetSymbolFile(this); + auto *clang = llvm::cast_or_null<ClangASTContext>(&ts_or_err.get()); + lldbassert(clang); + m_ast = std::make_unique<PdbAstBuilder>(*m_objfile_sp, *m_index, *clang); + } } -uint32_t SymbolFileNativePDB::GetNumCompileUnits() { +uint32_t SymbolFileNativePDB::CalculateNumCompileUnits() { const DbiModuleList &modules = m_index->dbi().modules(); uint32_t count = modules.getModuleCount(); if (count == 0) @@ -430,11 +437,10 @@ SymbolFileNativePDB::CreateCompileUnit(const CompilandIndexItem &cci) { FileSpec fs(source_file_name); CompUnitSP cu_sp = - std::make_shared<CompileUnit>(m_obj_file->GetModule(), nullptr, fs, + std::make_shared<CompileUnit>(m_objfile_sp->GetModule(), nullptr, fs, toOpaqueUid(cci.m_id), lang, optimized); - m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex( - cci.m_id.modi, cu_sp); + SetCompileUnitAtIndex(cci.m_id.modi, cu_sp); return cu_sp; } @@ -730,7 +736,7 @@ TypeSP SymbolFileNativePDB::GetOrCreateType(PdbTypeSymId type_id) { TypeSP type = CreateAndCacheType(type_id); if (type) - m_obj_file->GetModule()->GetTypeList()->Insert(type); + GetTypeList().Insert(type); return type; } @@ -900,6 +906,7 @@ lldb::CompUnitSP SymbolFileNativePDB::ParseCompileUnitAtIndex(uint32_t index) { } lldb::LanguageType SymbolFileNativePDB::ParseLanguage(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); PdbSymUid uid(comp_unit.GetID()); lldbassert(uid.kind() == PdbSymUidKind::Compiland); @@ -915,6 +922,7 @@ lldb::LanguageType SymbolFileNativePDB::ParseLanguage(CompileUnit &comp_unit) { void SymbolFileNativePDB::AddSymbols(Symtab &symtab) { return; } size_t SymbolFileNativePDB::ParseFunctions(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); PdbSymUid uid{comp_unit.GetID()}; lldbassert(uid.kind() == PdbSymUidKind::Compiland); uint16_t modi = uid.asCompiland().modi; @@ -948,6 +956,7 @@ static bool NeedsResolvedCompileUnit(uint32_t resolve_scope) { uint32_t SymbolFileNativePDB::ResolveSymbolContext( const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); uint32_t resolved_flags = 0; lldb::addr_t file_addr = addr.GetFileAddress(); @@ -1052,12 +1061,13 @@ bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) { // all at once, even if all it really needs is line info for a specific // function. In the future it would be nice if it could set the sc.m_function // member, and we could only get the line info for the function in question. + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); PdbSymUid cu_id(comp_unit.GetID()); lldbassert(cu_id.kind() == PdbSymUidKind::Compiland); CompilandIndexItem *cci = m_index->compilands().GetCompiland(cu_id.asCompiland().modi); lldbassert(cci); - auto line_table = llvm::make_unique<LineTable>(&comp_unit); + auto line_table = std::make_unique<LineTable>(&comp_unit); // This is basically a copy of the .debug$S subsections from all original COFF // object files merged together with address relocations applied. We are @@ -1130,6 +1140,7 @@ bool SymbolFileNativePDB::ParseDebugMacros(CompileUnit &comp_unit) { bool SymbolFileNativePDB::ParseSupportFiles(CompileUnit &comp_unit, FileSpecList &support_files) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); PdbSymUid cu_id(comp_unit.GetID()); lldbassert(cu_id.kind() == PdbSymUidKind::Compiland); CompilandIndexItem *cci = @@ -1160,6 +1171,7 @@ bool SymbolFileNativePDB::ParseImportedModules( } size_t SymbolFileNativePDB::ParseBlocksRecursive(Function &func) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); GetOrCreateBlock(PdbSymUid(func.GetID()).asCompilandSym()); // FIXME: Parse child blocks return 1; @@ -1167,9 +1179,10 @@ size_t SymbolFileNativePDB::ParseBlocksRecursive(Function &func) { void SymbolFileNativePDB::DumpClangAST(Stream &s) { m_ast->Dump(s); } -uint32_t SymbolFileNativePDB::FindGlobalVariables( +void SymbolFileNativePDB::FindGlobalVariables( ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, VariableList &variables) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>; std::vector<SymbolAndOffset> results = m_index->globals().findRecordsByName( @@ -1191,16 +1204,16 @@ uint32_t SymbolFileNativePDB::FindGlobalVariables( continue; } } - return variables.GetSize(); } -uint32_t SymbolFileNativePDB::FindFunctions( +void SymbolFileNativePDB::FindFunctions( ConstString name, const CompilerDeclContext *parent_decl_ctx, - FunctionNameType name_type_mask, bool include_inlines, bool append, + FunctionNameType name_type_mask, bool include_inlines, SymbolContextList &sc_list) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); // For now we only support lookup by method name. if (!(name_type_mask & eFunctionNameTypeMethod)) - return 0; + return; using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>; @@ -1225,45 +1238,34 @@ uint32_t SymbolFileNativePDB::FindFunctions( sc_list.Append(sc); } - - return sc_list.GetSize(); } -uint32_t SymbolFileNativePDB::FindFunctions(const RegularExpression ®ex, - bool include_inlines, bool append, - SymbolContextList &sc_list) { - return 0; -} +void SymbolFileNativePDB::FindFunctions(const RegularExpression ®ex, + bool include_inlines, + SymbolContextList &sc_list) {} -uint32_t SymbolFileNativePDB::FindTypes( +void SymbolFileNativePDB::FindTypes( ConstString name, const CompilerDeclContext *parent_decl_ctx, - bool append, uint32_t max_matches, - llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) { - if (!append) - types.Clear(); + uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files, + TypeMap &types) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (!name) - return 0; + return; searched_symbol_files.clear(); searched_symbol_files.insert(this); // There is an assumption 'name' is not a regex - size_t match_count = FindTypesByName(name.GetStringRef(), max_matches, types); - - return match_count; + FindTypesByName(name.GetStringRef(), max_matches, types); } -size_t -SymbolFileNativePDB::FindTypes(const std::vector<CompilerContext> &context, - bool append, TypeMap &types) { - return 0; -} +void SymbolFileNativePDB::FindTypes(llvm::ArrayRef<CompilerContext> pattern, + LanguageSet languages, TypeMap &types) {} -size_t SymbolFileNativePDB::FindTypesByName(llvm::StringRef name, - uint32_t max_matches, - TypeMap &types) { +void SymbolFileNativePDB::FindTypesByName(llvm::StringRef name, + uint32_t max_matches, + TypeMap &types) { - size_t match_count = 0; std::vector<TypeIndex> matches = m_index->tpi().findRecordsByName(name); if (max_matches > 0 && max_matches < matches.size()) matches.resize(max_matches); @@ -1274,17 +1276,16 @@ size_t SymbolFileNativePDB::FindTypesByName(llvm::StringRef name, continue; types.Insert(type); - ++match_count; } - return match_count; } size_t SymbolFileNativePDB::ParseTypes(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); // Only do the full type scan the first time. if (m_done_full_type_scan) return 0; - size_t old_count = m_obj_file->GetModule()->GetTypeList()->GetSize(); + const size_t old_count = GetTypeList().GetSize(); LazyRandomTypeCollection &types = m_index->tpi().typeCollection(); // First process the entire TPI stream. @@ -1314,7 +1315,7 @@ size_t SymbolFileNativePDB::ParseTypes(CompileUnit &comp_unit) { GetOrCreateTypedef(global); } - size_t new_count = m_obj_file->GetModule()->GetTypeList()->GetSize(); + const size_t new_count = GetTypeList().GetSize(); m_done_full_type_scan = true; @@ -1476,6 +1477,7 @@ size_t SymbolFileNativePDB::ParseVariablesForBlock(PdbCompilandSymId block_id) { } size_t SymbolFileNativePDB::ParseVariablesForContext(const SymbolContext &sc) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); lldbassert(sc.function || sc.comp_unit); VariableListSP variables; @@ -1506,9 +1508,10 @@ size_t SymbolFileNativePDB::ParseVariablesForContext(const SymbolContext &sc) { } CompilerDecl SymbolFileNativePDB::GetDeclForUID(lldb::user_id_t uid) { - clang::Decl *decl = m_ast->GetOrCreateDeclForUid(PdbSymUid(uid)); - - return m_ast->ToCompilerDecl(*decl); + if (auto decl = m_ast->GetOrCreateDeclForUid(uid)) + return decl.getValue(); + else + return CompilerDecl(); } CompilerDeclContext @@ -1528,6 +1531,7 @@ SymbolFileNativePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { } Type *SymbolFileNativePDB::ResolveTypeUID(lldb::user_id_t type_uid) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); auto iter = m_types.find(type_uid); // lldb should not be passing us non-sensical type uids. the only way it // could have a type uid in the first place is if we handed it out, in which @@ -1561,11 +1565,9 @@ bool SymbolFileNativePDB::CompleteType(CompilerType &compiler_type) { return m_ast->CompleteType(qt); } -size_t SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, - TypeClass type_mask, - lldb_private::TypeList &type_list) { - return 0; -} +void SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, + TypeClass type_mask, + lldb_private::TypeList &type_list) {} CompilerDeclContext SymbolFileNativePDB::FindNamespace(ConstString name, @@ -1573,13 +1575,14 @@ SymbolFileNativePDB::FindNamespace(ConstString name, return {}; } -TypeSystem * +llvm::Expected<TypeSystem &> SymbolFileNativePDB::GetTypeSystemForLanguage(lldb::LanguageType language) { - auto type_system = - m_obj_file->GetModule()->GetTypeSystemForLanguage(language); - if (type_system) - type_system->SetSymbolFile(this); - return type_system; + auto type_system_or_err = + m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language); + if (type_system_or_err) { + type_system_or_err->SetSymbolFile(this); + } + return type_system_or_err; } ConstString SymbolFileNativePDB::GetPluginName() { diff --git a/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h index 20daff219a0a..ca7de0e7d1ed 100644 --- a/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h +++ b/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h @@ -9,7 +9,6 @@ #ifndef LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H #define LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H -#include "lldb/Symbol/ClangASTImporter.h" #include "lldb/Symbol/SymbolFile.h" #include "llvm/ADT/DenseMap.h" @@ -35,7 +34,6 @@ struct UnionRecord; } // namespace llvm namespace lldb_private { -class ClangASTImporter; namespace npdb { class PdbAstBuilder; @@ -55,10 +53,10 @@ public: static const char *GetPluginDescriptionStatic(); - static SymbolFile *CreateInstance(ObjectFile *obj_file); + static SymbolFile *CreateInstance(lldb::ObjectFileSP objfile_sp); // Constructors and Destructors - SymbolFileNativePDB(ObjectFile *ofile); + SymbolFileNativePDB(lldb::ObjectFileSP objfile_sp); ~SymbolFileNativePDB() override; @@ -68,13 +66,9 @@ public: // Compile Unit function calls - uint32_t GetNumCompileUnits() override; - void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; - lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; - lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override; @@ -94,10 +88,10 @@ public: size_t ParseBlocksRecursive(Function &func) override; - uint32_t FindGlobalVariables(ConstString name, - const CompilerDeclContext *parent_decl_ctx, - uint32_t max_matches, - VariableList &variables) override; + void FindGlobalVariables(ConstString name, + const CompilerDeclContext *parent_decl_ctx, + uint32_t max_matches, + VariableList &variables) override; size_t ParseVariablesForContext(const SymbolContext &sc) override; @@ -120,28 +114,27 @@ public: lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) override; - size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, - TypeList &type_list) override; + void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, + TypeList &type_list) override; - uint32_t FindFunctions(ConstString name, - const CompilerDeclContext *parent_decl_ctx, - lldb::FunctionNameType name_type_mask, - bool include_inlines, bool append, - SymbolContextList &sc_list) override; + void FindFunctions(ConstString name, + const CompilerDeclContext *parent_decl_ctx, + lldb::FunctionNameType name_type_mask, + bool include_inlines, SymbolContextList &sc_list) override; - uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, - bool append, SymbolContextList &sc_list) override; + void FindFunctions(const RegularExpression ®ex, bool include_inlines, + SymbolContextList &sc_list) override; - uint32_t FindTypes(ConstString name, - const CompilerDeclContext *parent_decl_ctx, bool append, - uint32_t max_matches, - llvm::DenseSet<SymbolFile *> &searched_symbol_files, - TypeMap &types) override; + void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, + uint32_t max_matches, + llvm::DenseSet<SymbolFile *> &searched_symbol_files, + TypeMap &types) override; - size_t FindTypes(const std::vector<CompilerContext> &context, bool append, - TypeMap &types) override; + void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages, + TypeMap &types) override; - TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override; + llvm::Expected<TypeSystem &> + GetTypeSystemForLanguage(lldb::LanguageType language) override; CompilerDeclContext FindNamespace(ConstString name, @@ -157,9 +150,12 @@ public: void DumpClangAST(Stream &s) override; private: + uint32_t CalculateNumCompileUnits() override; + + lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; - size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches, - TypeMap &types); + void FindTypesByName(llvm::StringRef name, uint32_t max_matches, + TypeMap &types); lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, const llvm::codeview::ModifierRecord &mr, |