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/PDB | |
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/PDB')
-rw-r--r-- | source/Plugins/SymbolFile/PDB/PDBASTParser.cpp | 23 | ||||
-rw-r--r-- | source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp | 2 | ||||
-rw-r--r-- | source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 345 | ||||
-rw-r--r-- | source/Plugins/SymbolFile/PDB/SymbolFilePDB.h | 56 |
4 files changed, 249 insertions, 177 deletions
diff --git a/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp index 82cfcfbb040f..47c4ad088494 100644 --- a/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ b/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -120,24 +120,31 @@ GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast, return clang_ast.GetBasicType(eBasicTypeBool); case PDB_BuiltinType::Long: if (width == ast->getTypeSize(ast->LongTy)) - return CompilerType(ast, ast->LongTy); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->LongTy.getAsOpaquePtr()); if (width == ast->getTypeSize(ast->LongLongTy)) - return CompilerType(ast, ast->LongLongTy); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->LongLongTy.getAsOpaquePtr()); break; case PDB_BuiltinType::ULong: if (width == ast->getTypeSize(ast->UnsignedLongTy)) - return CompilerType(ast, ast->UnsignedLongTy); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->UnsignedLongTy.getAsOpaquePtr()); if (width == ast->getTypeSize(ast->UnsignedLongLongTy)) - return CompilerType(ast, ast->UnsignedLongLongTy); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->UnsignedLongLongTy.getAsOpaquePtr()); break; case PDB_BuiltinType::WCharT: if (width == ast->getTypeSize(ast->WCharTy)) - return CompilerType(ast, ast->WCharTy); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->WCharTy.getAsOpaquePtr()); break; case PDB_BuiltinType::Char16: - return CompilerType(ast, ast->Char16Ty); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->Char16Ty.getAsOpaquePtr()); case PDB_BuiltinType::Char32: - return CompilerType(ast, ast->Char32Ty); + return CompilerType(ClangASTContext::GetASTContext(ast), + ast->Char32Ty.getAsOpaquePtr()); case PDB_BuiltinType::Float: // Note: types `long double` and `double` have same bit size in MSVC and // there is no information in the PDB to distinguish them. So when falling @@ -940,7 +947,7 @@ PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) { clang::ParmVarDecl *param = m_ast.CreateParameterDeclaration( decl, nullptr, arg_type->GetForwardCompilerType(), - clang::SC_None); + clang::SC_None, true); if (param) params.push_back(param); } diff --git a/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp b/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp index 1c17bf6563b3..42bf1b34c956 100644 --- a/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp +++ b/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp @@ -174,7 +174,7 @@ DWARFExpression ConvertPDBLocationToDWARFExpression( 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; diff --git a/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp index 17dfcdaceb9c..854e735b5f83 100644 --- a/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ b/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -24,6 +24,7 @@ #include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/TypeMap.h" #include "lldb/Symbol/Variable.h" +#include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" #include "llvm/DebugInfo/PDB/GenericError.h" @@ -118,29 +119,28 @@ const char *SymbolFilePDB::GetPluginDescriptionStatic() { } lldb_private::SymbolFile * -SymbolFilePDB::CreateInstance(lldb_private::ObjectFile *obj_file) { - return new SymbolFilePDB(obj_file); +SymbolFilePDB::CreateInstance(ObjectFileSP objfile_sp) { + return new SymbolFilePDB(std::move(objfile_sp)); } -SymbolFilePDB::SymbolFilePDB(lldb_private::ObjectFile *object_file) - : SymbolFile(object_file), m_session_up(), m_global_scope_up(), - m_cached_compile_unit_count(0) {} +SymbolFilePDB::SymbolFilePDB(lldb::ObjectFileSP objfile_sp) + : SymbolFile(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {} SymbolFilePDB::~SymbolFilePDB() {} uint32_t SymbolFilePDB::CalculateAbilities() { uint32_t abilities = 0; - if (!m_obj_file) + if (!m_objfile_sp) return 0; if (!m_session_up) { // Lazily load and match the PDB file, but only do this once. - std::string exePath = m_obj_file->GetFileSpec().GetPath(); + std::string exePath = m_objfile_sp->GetFileSpec().GetPath(); auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath), m_session_up); if (error) { llvm::consumeError(std::move(error)); - 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. @@ -183,7 +183,8 @@ uint32_t SymbolFilePDB::CalculateAbilities() { } void SymbolFilePDB::InitializeObject() { - lldb::addr_t obj_load_address = m_obj_file->GetBaseAddress().GetFileAddress(); + lldb::addr_t obj_load_address = + m_objfile_sp->GetBaseAddress().GetFileAddress(); lldbassert(obj_load_address && obj_load_address != LLDB_INVALID_ADDRESS); m_session_up->setLoadAddress(obj_load_address); if (!m_global_scope_up) @@ -191,33 +192,30 @@ void SymbolFilePDB::InitializeObject() { lldbassert(m_global_scope_up.get()); } -uint32_t SymbolFilePDB::GetNumCompileUnits() { - if (m_cached_compile_unit_count == 0) { - auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>(); - if (!compilands) - return 0; +uint32_t SymbolFilePDB::CalculateNumCompileUnits() { + auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>(); + if (!compilands) + return 0; - // The linker could link *.dll (compiland language = LINK), or import - // *.dll. For example, a compiland with name `Import:KERNEL32.dll` could be - // found as a child of the global scope (PDB executable). Usually, such - // compilands contain `thunk` symbols in which we are not interested for - // now. However we still count them in the compiland list. If we perform - // any compiland related activity, like finding symbols through - // llvm::pdb::IPDBSession methods, such compilands will all be searched - // automatically no matter whether we include them or not. - m_cached_compile_unit_count = compilands->getChildCount(); - - // The linker can inject an additional "dummy" compilation unit into the - // PDB. Ignore this special compile unit for our purposes, if it is there. - // It is always the last one. - auto last_compiland_up = - compilands->getChildAtIndex(m_cached_compile_unit_count - 1); - lldbassert(last_compiland_up.get()); - std::string name = last_compiland_up->getName(); - if (name == "* Linker *") - --m_cached_compile_unit_count; - } - return m_cached_compile_unit_count; + // The linker could link *.dll (compiland language = LINK), or import + // *.dll. For example, a compiland with name `Import:KERNEL32.dll` could be + // found as a child of the global scope (PDB executable). Usually, such + // compilands contain `thunk` symbols in which we are not interested for + // now. However we still count them in the compiland list. If we perform + // any compiland related activity, like finding symbols through + // llvm::pdb::IPDBSession methods, such compilands will all be searched + // automatically no matter whether we include them or not. + uint32_t compile_unit_count = compilands->getChildCount(); + + // The linker can inject an additional "dummy" compilation unit into the + // PDB. Ignore this special compile unit for our purposes, if it is there. + // It is always the last one. + auto last_compiland_up = compilands->getChildAtIndex(compile_unit_count - 1); + lldbassert(last_compiland_up.get()); + std::string name = last_compiland_up->getName(); + if (name == "* Linker *") + --compile_unit_count; + return compile_unit_count; } void SymbolFilePDB::GetCompileUnitIndex( @@ -261,6 +259,7 @@ lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitAtIndex(uint32_t index) { } lldb::LanguageType SymbolFilePDB::ParseLanguage(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID()); if (!compiland_up) return lldb::eLanguageTypeUnknown; @@ -302,11 +301,15 @@ SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc(const PDBSymbolFunc &pdb_func, comp_unit.AddFunction(func_sp); LanguageType lang = ParseLanguage(comp_unit); - TypeSystem *type_system = GetTypeSystemForLanguage(lang); - if (!type_system) + auto type_system_or_err = GetTypeSystemForLanguage(lang); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to parse PDBFunc"); return nullptr; + } + ClangASTContext *clang_type_system = - llvm::dyn_cast_or_null<ClangASTContext>(type_system); + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_type_system) return nullptr; clang_type_system->GetPDBParser()->GetDeclForSymbol(pdb_func); @@ -315,6 +318,7 @@ SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc(const PDBSymbolFunc &pdb_func, } size_t SymbolFilePDB::ParseFunctions(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); size_t func_added = 0; auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID()); if (!compiland_up) @@ -333,6 +337,7 @@ size_t SymbolFilePDB::ParseFunctions(CompileUnit &comp_unit) { } bool SymbolFilePDB::ParseLineTable(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (comp_unit.GetLineTable()) return true; return ParseCompileUnitLineTable(comp_unit, 0); @@ -351,6 +356,7 @@ bool SymbolFilePDB::ParseSupportFiles( // second time seems like a waste. Unfortunately, there's no good way around // this short of a moderate refactor since SymbolVendor depends on being able // to cache this list. + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID()); if (!compiland_up) return false; @@ -428,6 +434,7 @@ static size_t ParseFunctionBlocksForPDBSymbol( } size_t SymbolFilePDB::ParseBlocksRecursive(Function &func) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); size_t num_added = 0; auto uid = func.GetID(); auto pdb_func_up = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid); @@ -440,6 +447,7 @@ size_t SymbolFilePDB::ParseBlocksRecursive(Function &func) { } size_t SymbolFilePDB::ParseTypes(CompileUnit &comp_unit) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); size_t num_added = 0; auto compiland = GetPDBCompilandByUID(comp_unit.GetID()); @@ -492,6 +500,7 @@ size_t SymbolFilePDB::ParseTypes(CompileUnit &comp_unit) { size_t SymbolFilePDB::ParseVariablesForContext(const lldb_private::SymbolContext &sc) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (!sc.comp_unit) return 0; @@ -540,14 +549,21 @@ SymbolFilePDB::ParseVariablesForContext(const lldb_private::SymbolContext &sc) { } lldb_private::Type *SymbolFilePDB::ResolveTypeUID(lldb::user_id_t type_uid) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); auto find_result = m_types.find(type_uid); if (find_result != m_types.end()) return find_result->second.get(); - TypeSystem *type_system = + auto type_system_or_err = GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to ResolveTypeUID"); + return nullptr; + } + ClangASTContext *clang_type_system = - llvm::dyn_cast_or_null<ClangASTContext>(type_system); + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_type_system) return nullptr; PDBASTParser *pdb = clang_type_system->GetPDBParser(); @@ -561,9 +577,7 @@ lldb_private::Type *SymbolFilePDB::ResolveTypeUID(lldb::user_id_t type_uid) { lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type); if (result) { m_types.insert(std::make_pair(type_uid, result)); - auto type_list = GetTypeList(); - if (type_list) - type_list->Insert(result); + GetTypeList().Insert(result); } return result.get(); } @@ -577,8 +591,17 @@ bool SymbolFilePDB::CompleteType(lldb_private::CompilerType &compiler_type) { std::lock_guard<std::recursive_mutex> guard( GetObjectFile()->GetModule()->GetMutex()); - ClangASTContext *clang_ast_ctx = llvm::dyn_cast_or_null<ClangASTContext>( - GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus)); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to get dynamic array info for UID"); + return false; + } + + ClangASTContext *clang_ast_ctx = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); + if (!clang_ast_ctx) return false; @@ -590,8 +613,16 @@ bool SymbolFilePDB::CompleteType(lldb_private::CompilerType &compiler_type) { } lldb_private::CompilerDecl SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) { - ClangASTContext *clang_ast_ctx = llvm::dyn_cast_or_null<ClangASTContext>( - GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus)); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to get decl for UID"); + return CompilerDecl(); + } + + ClangASTContext *clang_ast_ctx = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_ast_ctx) return CompilerDecl(); @@ -612,8 +643,16 @@ lldb_private::CompilerDecl SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) { lldb_private::CompilerDeclContext SymbolFilePDB::GetDeclContextForUID(lldb::user_id_t uid) { - ClangASTContext *clang_ast_ctx = llvm::dyn_cast_or_null<ClangASTContext>( - GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus)); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to get DeclContext for UID"); + return CompilerDeclContext(); + } + + ClangASTContext *clang_ast_ctx = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_ast_ctx) return CompilerDeclContext(); @@ -634,8 +673,16 @@ SymbolFilePDB::GetDeclContextForUID(lldb::user_id_t uid) { lldb_private::CompilerDeclContext SymbolFilePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { - ClangASTContext *clang_ast_ctx = llvm::dyn_cast_or_null<ClangASTContext>( - GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus)); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to get DeclContext containing UID"); + return CompilerDeclContext(); + } + + ClangASTContext *clang_ast_ctx = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_ast_ctx) return CompilerDeclContext(); @@ -655,8 +702,16 @@ SymbolFilePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { void SymbolFilePDB::ParseDeclsForContext( lldb_private::CompilerDeclContext decl_ctx) { - ClangASTContext *clang_ast_ctx = llvm::dyn_cast_or_null<ClangASTContext>( - GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus)); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to parse decls for context"); + return; + } + + ClangASTContext *clang_ast_ctx = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_ast_ctx) return; @@ -672,6 +727,7 @@ uint32_t SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr, SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); uint32_t resolved_flags = 0; if (resolve_scope & eSymbolContextCompUnit || resolve_scope & eSymbolContextVariable || @@ -680,7 +736,7 @@ SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr, resolve_scope & eSymbolContextLineEntry) { auto cu_sp = GetCompileUnitContainsAddress(so_addr); if (!cu_sp) { - if (resolved_flags | eSymbolContextVariable) { + if (resolved_flags & eSymbolContextVariable) { // TODO: Resolve variables } return 0; @@ -732,6 +788,7 @@ SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr, uint32_t SymbolFilePDB::ResolveSymbolContext( const lldb_private::FileSpec &file_spec, uint32_t line, bool check_inlines, SymbolContextItem resolve_scope, lldb_private::SymbolContextList &sc_list) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); const size_t old_size = sc_list.GetSize(); if (resolve_scope & lldb::eSymbolContextCompUnit) { // Locate all compilation units with line numbers referencing the specified @@ -1040,18 +1097,19 @@ SymbolFilePDB::ParseVariables(const lldb_private::SymbolContext &sc, return num_added; } -uint32_t SymbolFilePDB::FindGlobalVariables( +void SymbolFilePDB::FindGlobalVariables( lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) - return 0; + return; if (name.IsEmpty()) - return 0; + return; auto results = m_global_scope_up->findAllChildren<PDBSymbolData>(); if (!results) - return 0; + return; uint32_t matches = 0; size_t old_size = variables.GetSize(); @@ -1061,7 +1119,7 @@ uint32_t SymbolFilePDB::FindGlobalVariables( break; SymbolContext sc; - sc.module_sp = m_obj_file->GetModule(); + sc.module_sp = m_objfile_sp->GetModule(); lldbassert(sc.module_sp.get()); if (!name.GetStringRef().equals( @@ -1080,19 +1138,17 @@ uint32_t SymbolFilePDB::FindGlobalVariables( ParseVariables(sc, *pdb_data, &variables); matches = variables.GetSize() - old_size; } - - return matches; } -uint32_t -SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression ®ex, - uint32_t max_matches, - lldb_private::VariableList &variables) { +void SymbolFilePDB::FindGlobalVariables( + const lldb_private::RegularExpression ®ex, uint32_t max_matches, + lldb_private::VariableList &variables) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (!regex.IsValid()) - return 0; + return; auto results = m_global_scope_up->findAllChildren<PDBSymbolData>(); if (!results) - return 0; + return; uint32_t matches = 0; size_t old_size = variables.GetSize(); @@ -1106,7 +1162,7 @@ SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression ®ex, if (!regex.Execute(var_name)) continue; SymbolContext sc; - sc.module_sp = m_obj_file->GetModule(); + sc.module_sp = m_objfile_sp->GetModule(); lldbassert(sc.module_sp.get()); sc.comp_unit = ParseCompileUnitForUID(GetCompilandId(*pdb_data)).get(); @@ -1117,8 +1173,6 @@ SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression ®ex, ParseVariables(sc, *pdb_data, &variables); matches = variables.GetSize() - old_size; } - - return matches; } bool SymbolFilePDB::ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, @@ -1240,23 +1294,21 @@ void SymbolFilePDB::CacheFunctionNames() { m_func_base_names.SizeToFit(); } -uint32_t SymbolFilePDB::FindFunctions( +void SymbolFilePDB::FindFunctions( lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, - FunctionNameType name_type_mask, bool include_inlines, bool append, + FunctionNameType name_type_mask, bool include_inlines, lldb_private::SymbolContextList &sc_list) { - if (!append) - sc_list.Clear(); + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); lldbassert((name_type_mask & eFunctionNameTypeAuto) == 0); if (name_type_mask == eFunctionNameTypeNone) - return 0; + return; if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) - return 0; + return; if (name.IsEmpty()) - return 0; + return; - auto old_size = sc_list.GetSize(); if (name_type_mask & eFunctionNameTypeFull || name_type_mask & eFunctionNameTypeBase || name_type_mask & eFunctionNameTypeMethod) { @@ -1286,26 +1338,20 @@ uint32_t SymbolFilePDB::FindFunctions( ResolveFn(m_func_base_names); ResolveFn(m_func_method_names); } - if (name_type_mask & eFunctionNameTypeBase) { + if (name_type_mask & eFunctionNameTypeBase) ResolveFn(m_func_base_names); - } - if (name_type_mask & eFunctionNameTypeMethod) { + if (name_type_mask & eFunctionNameTypeMethod) ResolveFn(m_func_method_names); - } } - return sc_list.GetSize() - old_size; } -uint32_t -SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression ®ex, - bool include_inlines, bool append, - lldb_private::SymbolContextList &sc_list) { - if (!append) - sc_list.Clear(); +void SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression ®ex, + bool include_inlines, + lldb_private::SymbolContextList &sc_list) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (!regex.IsValid()) - return 0; + return; - auto old_size = sc_list.GetSize(); CacheFunctionNames(); std::set<uint32_t> resolved_ids; @@ -1322,8 +1368,6 @@ SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression ®ex, }; ResolveFn(m_func_full_names); ResolveFn(m_func_base_names); - - return sc_list.GetSize() - old_size; } void SymbolFilePDB::GetMangledNamesForFunction( @@ -1339,7 +1383,7 @@ void SymbolFilePDB::AddSymbols(lldb_private::Symtab &symtab) { if (!results) return; - auto section_list = m_obj_file->GetSectionList(); + auto section_list = m_objfile_sp->GetSectionList(); if (!section_list) return; @@ -1361,7 +1405,6 @@ void SymbolFilePDB::AddSymbols(lldb_private::Symtab &symtab) { symtab.AddSymbol( Symbol(pub_symbol->getSymIndexId(), // symID pub_symbol->getName().c_str(), // name - true, // name_is_mangled pub_symbol->isCode() ? eSymbolTypeCode : eSymbolTypeData, // type true, // external false, // is_debug @@ -1380,34 +1423,39 @@ void SymbolFilePDB::AddSymbols(lldb_private::Symtab &symtab) { symtab.Finalize(); } -uint32_t SymbolFilePDB::FindTypes( +void SymbolFilePDB::FindTypes( lldb_private::ConstString name, - const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, + const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, lldb_private::TypeMap &types) { - if (!append) - types.Clear(); + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); if (!name) - return 0; + return; if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) - return 0; + return; searched_symbol_files.clear(); searched_symbol_files.insert(this); // There is an assumption 'name' is not a regex FindTypesByName(name.GetStringRef(), parent_decl_ctx, max_matches, types); - - return types.GetSize(); } void SymbolFilePDB::DumpClangAST(Stream &s) { - auto type_system = GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); - auto clang = llvm::dyn_cast_or_null<ClangASTContext>(type_system); - if (!clang) + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to dump ClangAST"); + return; + } + + auto *clang_type_system = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); + if (!clang_type_system) return; - clang->Dump(s); + clang_type_system->Dump(s); } void SymbolFilePDB::FindTypesByRegex( @@ -1514,15 +1562,9 @@ void SymbolFilePDB::FindTypesByName( } } -size_t SymbolFilePDB::FindTypes( - const std::vector<lldb_private::CompilerContext> &contexts, bool append, - lldb_private::TypeMap &types) { - return 0; -} - -lldb_private::TypeList *SymbolFilePDB::GetTypeList() { - return m_obj_file->GetModule()->GetTypeList(); -} +void SymbolFilePDB::FindTypes(llvm::ArrayRef<CompilerContext> pattern, + LanguageSet languages, + lldb_private::TypeMap &types) {} void SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, uint32_t type_mask, @@ -1574,17 +1616,17 @@ void SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, GetTypesForPDBSymbol(*symbol_up, type_mask, type_collection); } -size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, - TypeClass type_mask, - lldb_private::TypeList &type_list) { +void SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, + TypeClass type_mask, + lldb_private::TypeList &type_list) { + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); TypeCollection type_collection; - uint32_t old_size = type_list.GetSize(); CompileUnit *cu = sc_scope ? sc_scope->CalculateSymbolContextCompileUnit() : nullptr; if (cu) { auto compiland_up = GetPDBCompilandByUID(cu->GetID()); if (!compiland_up) - return 0; + return; GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection); } else { for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) { @@ -1600,21 +1642,29 @@ size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, type->GetForwardCompilerType(); type_list.Insert(type->shared_from_this()); } - return type_list.GetSize() - old_size; } -lldb_private::TypeSystem * +llvm::Expected<lldb_private::TypeSystem &> SymbolFilePDB::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; } PDBASTParser *SymbolFilePDB::GetPDBAstParser() { - auto type_system = GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); - auto clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to get PDB AST parser"); + return nullptr; + } + + auto *clang_type_system = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_type_system) return nullptr; @@ -1625,8 +1675,18 @@ PDBASTParser *SymbolFilePDB::GetPDBAstParser() { lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace( lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx) { - auto type_system = GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); - auto clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system); + std::lock_guard<std::recursive_mutex> guard(GetModuleMutex()); + auto type_system_or_err = + GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to find namespace {}", + name.AsCString()); + return CompilerDeclContext(); + } + + auto *clang_type_system = + llvm::dyn_cast_or_null<ClangASTContext>(&type_system_or_err.get()); if (!clang_type_system) return CompilerDeclContext(); @@ -1644,7 +1704,7 @@ lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace( if (!namespace_decl) return CompilerDeclContext(); - return CompilerDeclContext(type_system, + return CompilerDeclContext(clang_type_system, static_cast<clang::DeclContext *>(namespace_decl)); } @@ -1688,7 +1748,7 @@ lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitForUID(uint32_t id, // Don't support optimized code for now, DebugInfoPDB does not return this // information. LazyBool optimized = eLazyBoolNo; - auto cu_sp = std::make_shared<CompileUnit>(m_obj_file->GetModule(), nullptr, + auto cu_sp = std::make_shared<CompileUnit>(m_objfile_sp->GetModule(), nullptr, path.c_str(), id, lang, optimized); if (!cu_sp) @@ -1698,8 +1758,7 @@ lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitForUID(uint32_t id, if (index == UINT32_MAX) GetCompileUnitIndex(*compiland_up, index); lldbassert(index != UINT32_MAX); - m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(index, - cu_sp); + SetCompileUnitAtIndex(index, cu_sp); return cu_sp; } @@ -1715,7 +1774,7 @@ bool SymbolFilePDB::ParseCompileUnitLineTable(CompileUnit &comp_unit, // to do a mapping so that we can hand out indices. llvm::DenseMap<uint32_t, uint32_t> index_map; BuildSupportFileIdToSupportFileIndexMap(*compiland_up, index_map); - auto line_table = llvm::make_unique<LineTable>(&comp_unit); + auto line_table = std::make_unique<LineTable>(&comp_unit); // Find contributions to `compiland` from all source and header files. std::string path = comp_unit.GetPath(); @@ -1925,9 +1984,17 @@ bool SymbolFilePDB::DeclContextMatchesThisSymbolFile( TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem(); if (!decl_ctx_type_system) return false; - TypeSystem *type_system = GetTypeSystemForLanguage( + auto type_system_or_err = GetTypeSystemForLanguage( decl_ctx_type_system->GetMinimumLanguage(nullptr)); - if (decl_ctx_type_system == type_system) + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR( + lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), + "Unable to determine if DeclContext matches this symbol file"); + return false; + } + + if (decl_ctx_type_system == &type_system_or_err.get()) return true; // The type systems match, return true return false; diff --git a/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h b/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h index ba3099aaec4d..df717bbbbdb0 100644 --- a/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h +++ b/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h @@ -35,10 +35,10 @@ public: static const char *GetPluginDescriptionStatic(); static lldb_private::SymbolFile * - CreateInstance(lldb_private::ObjectFile *obj_file); + CreateInstance(lldb::ObjectFileSP objfile_sp); // Constructors and Destructors - SymbolFilePDB(lldb_private::ObjectFile *ofile); + SymbolFilePDB(lldb::ObjectFileSP objfile_sp); ~SymbolFilePDB() override; @@ -48,10 +48,6 @@ public: // Compile Unit function calls - uint32_t GetNumCompileUnits() override; - - lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; - lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override; @@ -103,25 +99,25 @@ public: lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContextList &sc_list) override; - uint32_t + void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override; - uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex, - uint32_t max_matches, - lldb_private::VariableList &variables) override; + void FindGlobalVariables(const lldb_private::RegularExpression ®ex, + uint32_t max_matches, + lldb_private::VariableList &variables) override; - uint32_t - FindFunctions(lldb_private::ConstString name, - const lldb_private::CompilerDeclContext *parent_decl_ctx, - lldb::FunctionNameType name_type_mask, bool include_inlines, - bool append, lldb_private::SymbolContextList &sc_list) override; + void FindFunctions(lldb_private::ConstString name, + const lldb_private::CompilerDeclContext *parent_decl_ctx, + lldb::FunctionNameType name_type_mask, + bool include_inlines, + lldb_private::SymbolContextList &sc_list) override; - uint32_t FindFunctions(const lldb_private::RegularExpression ®ex, - bool include_inlines, bool append, - lldb_private::SymbolContextList &sc_list) override; + void FindFunctions(const lldb_private::RegularExpression ®ex, + bool include_inlines, + lldb_private::SymbolContextList &sc_list) override; void GetMangledNamesForFunction( const std::string &scope_qualified_name, @@ -129,26 +125,25 @@ public: void AddSymbols(lldb_private::Symtab &symtab) override; - uint32_t + void FindTypes(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, - bool append, uint32_t max_matches, + uint32_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, lldb_private::TypeMap &types) override; - size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context, - bool append, lldb_private::TypeMap &types) override; + void FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern, + lldb_private::LanguageSet languages, + lldb_private::TypeMap &types) override; void FindTypesByRegex(const lldb_private::RegularExpression ®ex, uint32_t max_matches, lldb_private::TypeMap &types); - lldb_private::TypeList *GetTypeList() override; - - size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, - lldb::TypeClass type_mask, - lldb_private::TypeList &type_list) override; + void GetTypes(lldb_private::SymbolContextScope *sc_scope, + lldb::TypeClass type_mask, + lldb_private::TypeList &type_list) override; - lldb_private::TypeSystem * + llvm::Expected<lldb_private::TypeSystem &> GetTypeSystemForLanguage(lldb::LanguageType language) override; lldb_private::CompilerDeclContext FindNamespace( @@ -173,6 +168,10 @@ private: }; using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>; + uint32_t CalculateNumCompileUnits() override; + + lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; + lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, uint32_t index = UINT32_MAX); @@ -245,7 +244,6 @@ private: std::vector<lldb::TypeSP> m_builtin_types; std::unique_ptr<llvm::pdb::IPDBSession> m_session_up; std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up; - uint32_t m_cached_compile_unit_count; lldb_private::UniqueCStringMap<uint32_t> m_func_full_names; lldb_private::UniqueCStringMap<uint32_t> m_func_base_names; |