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