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 using namespace lldb_private; 23 24 void SymbolFile::PreloadSymbols() { 25 // No-op for most implementations. 26 } 27 28 SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) { 29 std::unique_ptr<SymbolFile> best_symfile_ap; 30 if (obj_file != nullptr) { 31 32 // We need to test the abilities of this section list. So create what it 33 // would be with this new obj_file. 34 lldb::ModuleSP module_sp(obj_file->GetModule()); 35 if (module_sp) { 36 // Default to the main module section list. 37 ObjectFile *module_obj_file = module_sp->GetObjectFile(); 38 if (module_obj_file != obj_file) { 39 // Make sure the main object file's sections are created 40 module_obj_file->GetSectionList(); 41 obj_file->CreateSections(*module_sp->GetUnifiedSectionList()); 42 } 43 } 44 45 // TODO: Load any plug-ins in the appropriate plug-in search paths and 46 // iterate over all of them to find the best one for the job. 47 48 uint32_t best_symfile_abilities = 0; 49 50 SymbolFileCreateInstance create_callback; 51 for (uint32_t idx = 0; 52 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex( 53 idx)) != nullptr; 54 ++idx) { 55 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file)); 56 57 if (curr_symfile_ap.get()) { 58 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities(); 59 if (sym_file_abilities > best_symfile_abilities) { 60 best_symfile_abilities = sym_file_abilities; 61 best_symfile_ap.reset(curr_symfile_ap.release()); 62 // If any symbol file parser has all of the abilities, then we should 63 // just stop looking. 64 if ((kAllAbilities & sym_file_abilities) == kAllAbilities) 65 break; 66 } 67 } 68 } 69 if (best_symfile_ap.get()) { 70 // Let the winning symbol file parser initialize itself more completely 71 // now that it has been chosen 72 best_symfile_ap->InitializeObject(); 73 } 74 } 75 return best_symfile_ap.release(); 76 } 77 78 TypeList *SymbolFile::GetTypeList() { 79 if (m_obj_file) 80 return m_obj_file->GetModule()->GetTypeList(); 81 return nullptr; 82 } 83 84 TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) { 85 TypeSystem *type_system = 86 m_obj_file->GetModule()->GetTypeSystemForLanguage(language); 87 if (type_system) 88 type_system->SetSymbolFile(this); 89 return type_system; 90 } 91 92 uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec, 93 uint32_t line, bool check_inlines, 94 uint32_t resolve_scope, 95 SymbolContextList &sc_list) { 96 return 0; 97 } 98 99 uint32_t 100 SymbolFile::FindGlobalVariables(const ConstString &name, 101 const CompilerDeclContext *parent_decl_ctx, 102 uint32_t max_matches, VariableList &variables) { 103 return 0; 104 } 105 106 uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex, 107 uint32_t max_matches, 108 VariableList &variables) { 109 return 0; 110 } 111 112 uint32_t SymbolFile::FindFunctions(const ConstString &name, 113 const CompilerDeclContext *parent_decl_ctx, 114 uint32_t name_type_mask, 115 bool include_inlines, bool append, 116 SymbolContextList &sc_list) { 117 if (!append) 118 sc_list.Clear(); 119 return 0; 120 } 121 122 uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex, 123 bool include_inlines, bool append, 124 SymbolContextList &sc_list) { 125 if (!append) 126 sc_list.Clear(); 127 return 0; 128 } 129 130 void SymbolFile::GetMangledNamesForFunction( 131 const std::string &scope_qualified_name, 132 std::vector<ConstString> &mangled_names) { 133 return; 134 } 135 136 uint32_t SymbolFile::FindTypes( 137 const SymbolContext &sc, const ConstString &name, 138 const CompilerDeclContext *parent_decl_ctx, bool append, 139 uint32_t max_matches, 140 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 141 TypeMap &types) { 142 if (!append) 143 types.Clear(); 144 return 0; 145 } 146 147 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context, 148 bool append, TypeMap &types) { 149 if (!append) 150 types.Clear(); 151 return 0; 152 } 153