1 //===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Symbol/SymbolFile.h" 10 11 #include "lldb/Core/Module.h" 12 #include "lldb/Core/PluginManager.h" 13 #include "lldb/Symbol/ObjectFile.h" 14 #include "lldb/Symbol/TypeMap.h" 15 #include "lldb/Symbol/TypeSystem.h" 16 #include "lldb/Symbol/VariableList.h" 17 #include "lldb/Utility/Log.h" 18 #include "lldb/Utility/StreamString.h" 19 #include "lldb/lldb-private.h" 20 21 #include <future> 22 23 using namespace lldb_private; 24 25 void SymbolFile::PreloadSymbols() { 26 // No-op for most implementations. 27 } 28 29 std::recursive_mutex &SymbolFile::GetModuleMutex() const { 30 return GetObjectFile()->GetModule()->GetMutex(); 31 } 32 33 SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) { 34 std::unique_ptr<SymbolFile> best_symfile_up; 35 if (obj_file != nullptr) { 36 37 // We need to test the abilities of this section list. So create what it 38 // would be with this new obj_file. 39 lldb::ModuleSP module_sp(obj_file->GetModule()); 40 if (module_sp) { 41 // Default to the main module section list. 42 ObjectFile *module_obj_file = module_sp->GetObjectFile(); 43 if (module_obj_file != obj_file) { 44 // Make sure the main object file's sections are created 45 module_obj_file->GetSectionList(); 46 obj_file->CreateSections(*module_sp->GetUnifiedSectionList()); 47 } 48 } 49 50 // TODO: Load any plug-ins in the appropriate plug-in search paths and 51 // iterate over all of them to find the best one for the job. 52 53 uint32_t best_symfile_abilities = 0; 54 55 SymbolFileCreateInstance create_callback; 56 for (uint32_t idx = 0; 57 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex( 58 idx)) != nullptr; 59 ++idx) { 60 std::unique_ptr<SymbolFile> curr_symfile_up(create_callback(obj_file)); 61 62 if (curr_symfile_up) { 63 const uint32_t sym_file_abilities = curr_symfile_up->GetAbilities(); 64 if (sym_file_abilities > best_symfile_abilities) { 65 best_symfile_abilities = sym_file_abilities; 66 best_symfile_up.reset(curr_symfile_up.release()); 67 // If any symbol file parser has all of the abilities, then we should 68 // just stop looking. 69 if ((kAllAbilities & sym_file_abilities) == kAllAbilities) 70 break; 71 } 72 } 73 } 74 if (best_symfile_up) { 75 // Let the winning symbol file parser initialize itself more completely 76 // now that it has been chosen 77 best_symfile_up->InitializeObject(); 78 } 79 } 80 return best_symfile_up.release(); 81 } 82 83 TypeList *SymbolFile::GetTypeList() { 84 if (m_obj_file) 85 return m_obj_file->GetModule()->GetTypeList(); 86 return nullptr; 87 } 88 89 TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) { 90 TypeSystem *type_system = 91 m_obj_file->GetModule()->GetTypeSystemForLanguage(language); 92 if (type_system) 93 type_system->SetSymbolFile(this); 94 return type_system; 95 } 96 97 uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec, 98 uint32_t line, bool check_inlines, 99 lldb::SymbolContextItem resolve_scope, 100 SymbolContextList &sc_list) { 101 return 0; 102 } 103 104 uint32_t 105 SymbolFile::FindGlobalVariables(ConstString name, 106 const CompilerDeclContext *parent_decl_ctx, 107 uint32_t max_matches, VariableList &variables) { 108 return 0; 109 } 110 111 uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex, 112 uint32_t max_matches, 113 VariableList &variables) { 114 return 0; 115 } 116 117 uint32_t SymbolFile::FindFunctions(ConstString name, 118 const CompilerDeclContext *parent_decl_ctx, 119 lldb::FunctionNameType name_type_mask, 120 bool include_inlines, bool append, 121 SymbolContextList &sc_list) { 122 if (!append) 123 sc_list.Clear(); 124 return 0; 125 } 126 127 uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex, 128 bool include_inlines, bool append, 129 SymbolContextList &sc_list) { 130 if (!append) 131 sc_list.Clear(); 132 return 0; 133 } 134 135 void SymbolFile::GetMangledNamesForFunction( 136 const std::string &scope_qualified_name, 137 std::vector<ConstString> &mangled_names) { 138 return; 139 } 140 141 uint32_t SymbolFile::FindTypes( 142 ConstString name, const CompilerDeclContext *parent_decl_ctx, 143 bool append, uint32_t max_matches, 144 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 145 TypeMap &types) { 146 if (!append) 147 types.Clear(); 148 return 0; 149 } 150 151 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context, 152 bool append, TypeMap &types) { 153 if (!append) 154 types.Clear(); 155 return 0; 156 } 157 158 void SymbolFile::AssertModuleLock() { 159 // The code below is too expensive to leave enabled in release builds. It's 160 // enabled in debug builds or when the correct macro is set. 161 #if defined(LLDB_CONFIGURATION_DEBUG) 162 // We assert that we have to module lock by trying to acquire the lock from a 163 // different thread. Note that we must abort if the result is true to 164 // guarantee correctness. 165 assert(std::async(std::launch::async, 166 [this] { return this->GetModuleMutex().try_lock(); }) 167 .get() == false && 168 "Module is not locked"); 169 #endif 170 } 171 172 SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default; 173