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