Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | #include "lldb/Symbol/SymbolFile.h" |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 11 | |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/ObjectFile.h" |
Ravitheja Addepally | 4069730 | 2015-10-08 09:45:41 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/TypeMap.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/TypeSystem.h" |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/VariableList.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/StreamString.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | #include "lldb/lldb-private.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb_private; |
| 23 | |
Jim Ingham | 7fca8c0 | 2017-04-28 00:51:06 +0000 | [diff] [blame] | 24 | void SymbolFile::PreloadSymbols() { |
| 25 | // No-op for most implementations. |
| 26 | } |
| 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) { |
| 29 | std::unique_ptr<SymbolFile> best_symfile_ap; |
| 30 | if (obj_file != nullptr) { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | // We need to test the abilities of this section list. So create what it |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame^] | 33 | // would be with this new obj_file. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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()); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame^] | 62 | // If any symbol file parser has all of the abilities, then we should |
| 63 | // just stop looking. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | if ((kAllAbilities & sym_file_abilities) == kAllAbilities) |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | if (best_symfile_ap.get()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame^] | 70 | // Let the winning symbol file parser initialize itself more completely |
| 71 | // now that it has been chosen |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | best_symfile_ap->InitializeObject(); |
| 73 | } |
| 74 | } |
| 75 | return best_symfile_ap.release(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | TypeList *SymbolFile::GetTypeList() { |
| 79 | if (m_obj_file) |
| 80 | return m_obj_file->GetModule()->GetTypeList(); |
| 81 | return nullptr; |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 82 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | uint32_t SymbolFile::FindGlobalVariables( |
| 100 | const ConstString &name, const CompilerDeclContext *parent_decl_ctx, |
| 101 | bool append, uint32_t max_matches, VariableList &variables) { |
| 102 | if (!append) |
| 103 | variables.Clear(); |
| 104 | return 0; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex, |
| 108 | bool append, uint32_t max_matches, |
| 109 | VariableList &variables) { |
| 110 | if (!append) |
| 111 | variables.Clear(); |
| 112 | return 0; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | uint32_t SymbolFile::FindFunctions(const ConstString &name, |
| 116 | const CompilerDeclContext *parent_decl_ctx, |
| 117 | uint32_t name_type_mask, |
| 118 | bool include_inlines, bool append, |
| 119 | SymbolContextList &sc_list) { |
| 120 | if (!append) |
| 121 | sc_list.Clear(); |
| 122 | return 0; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex, |
| 126 | bool include_inlines, bool append, |
| 127 | SymbolContextList &sc_list) { |
| 128 | if (!append) |
| 129 | sc_list.Clear(); |
| 130 | return 0; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | void SymbolFile::GetMangledNamesForFunction( |
| 134 | const std::string &scope_qualified_name, |
| 135 | std::vector<ConstString> &mangled_names) { |
| 136 | return; |
Siva Chandra | 9293fc4 | 2016-01-07 23:32:34 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | uint32_t SymbolFile::FindTypes( |
| 140 | const SymbolContext &sc, const ConstString &name, |
| 141 | const CompilerDeclContext *parent_decl_ctx, bool append, |
| 142 | uint32_t max_matches, |
| 143 | llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, |
| 144 | TypeMap &types) { |
| 145 | if (!append) |
| 146 | types.Clear(); |
| 147 | return 0; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context, |
| 151 | bool append, TypeMap &types) { |
| 152 | if (!append) |
| 153 | types.Clear(); |
| 154 | return 0; |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 155 | } |