| Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- SymbolVendor.cpp ----------------------------------------*- C++ -*-===// |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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/SymbolVendor.h" |
| 11 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
| 13 | #include "lldb/Core/PluginManager.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/CompileUnit.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/ObjectFile.h" |
| 16 | #include "lldb/Symbol/SymbolFile.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 17 | #include "lldb/Utility/Stream.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | //---------------------------------------------------------------------- |
| 23 | // FindPlugin |
| 24 | // |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 25 | // Platforms can register a callback to use when creating symbol vendors to |
| 26 | // allow for complex debug information file setups, and to also allow for |
| 27 | // finding separate debug information files. |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | //---------------------------------------------------------------------- |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | SymbolVendor *SymbolVendor::FindPlugin(const lldb::ModuleSP &module_sp, |
| 30 | lldb_private::Stream *feedback_strm) { |
| 31 | std::unique_ptr<SymbolVendor> instance_ap; |
| 32 | SymbolVendorCreateInstance create_callback; |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 33 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | for (size_t idx = 0; |
| 35 | (create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex( |
| 36 | idx)) != nullptr; |
| 37 | ++idx) { |
| 38 | instance_ap.reset(create_callback(module_sp, feedback_strm)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | if (instance_ap.get()) { |
| 41 | return instance_ap.release(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | } |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 44 | // The default implementation just tries to create debug information using |
| 45 | // the file representation for the module. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | instance_ap.reset(new SymbolVendor(module_sp)); |
| 47 | if (instance_ap.get()) { |
| 48 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 49 | if (objfile) |
| 50 | instance_ap->AddSymbolFileRepresentation(objfile->shared_from_this()); |
| 51 | } |
| 52 | return instance_ap.release(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | //---------------------------------------------------------------------- |
| 56 | // SymbolVendor constructor |
| 57 | //---------------------------------------------------------------------- |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp) |
| 59 | : ModuleChild(module_sp), m_type_list(), m_compile_units(), |
| Aleksandr Urakov | 8cfb12b | 2018-11-30 06:56:37 +0000 | [diff] [blame] | 60 | m_sym_file_ap(), m_symtab() {} |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
| 62 | //---------------------------------------------------------------------- |
| 63 | // Destructor |
| 64 | //---------------------------------------------------------------------- |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | SymbolVendor::~SymbolVendor() {} |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | |
| 67 | //---------------------------------------------------------------------- |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 68 | // Add a representation given an object file. |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | //---------------------------------------------------------------------- |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | void SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp) { |
| 71 | ModuleSP module_sp(GetModule()); |
| 72 | if (module_sp) { |
| 73 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 74 | if (objfile_sp) { |
| 75 | m_objfile_sp = objfile_sp; |
| 76 | m_sym_file_ap.reset(SymbolFile::FindPlugin(objfile_sp.get())); |
| Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 77 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | bool SymbolVendor::SetCompileUnitAtIndex(size_t idx, const CompUnitSP &cu_sp) { |
| 82 | ModuleSP module_sp(GetModule()); |
| 83 | if (module_sp) { |
| 84 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 85 | const size_t num_compile_units = GetNumCompileUnits(); |
| 86 | if (idx < num_compile_units) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 87 | // Fire off an assertion if this compile unit already exists for now. The |
| 88 | // partial parsing should take care of only setting the compile unit |
| 89 | // once, so if this assertion fails, we need to make sure that we don't |
| 90 | // have a race condition, or have a second parse of the same compile |
| 91 | // unit. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | assert(m_compile_units[idx].get() == nullptr); |
| 93 | m_compile_units[idx] = cu_sp; |
| 94 | return true; |
| 95 | } else { |
| 96 | // This should NOT happen, and if it does, we want to crash and know |
| 97 | // about it |
| 98 | assert(idx < num_compile_units); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | } |
| 101 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | size_t SymbolVendor::GetNumCompileUnits() { |
| 105 | ModuleSP module_sp(GetModule()); |
| 106 | if (module_sp) { |
| 107 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 108 | if (m_compile_units.empty()) { |
| 109 | if (m_sym_file_ap.get()) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 110 | // Resize our array of compile unit shared pointers -- which will each |
| 111 | // remain NULL until someone asks for the actual compile unit |
| 112 | // information. When this happens, the symbol file will be asked to |
| 113 | // parse this compile unit information. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | m_compile_units.resize(m_sym_file_ap->GetNumCompileUnits()); |
| 115 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | } |
| 118 | return m_compile_units.size(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 121 | lldb::LanguageType |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | SymbolVendor::ParseCompileUnitLanguage(const SymbolContext &sc) { |
| 123 | ModuleSP module_sp(GetModule()); |
| 124 | if (module_sp) { |
| 125 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 126 | if (m_sym_file_ap.get()) |
| 127 | return m_sym_file_ap->ParseCompileUnitLanguage(sc); |
| 128 | } |
| 129 | return eLanguageTypeUnknown; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | size_t SymbolVendor::ParseCompileUnitFunctions(const SymbolContext &sc) { |
| 133 | ModuleSP module_sp(GetModule()); |
| 134 | if (module_sp) { |
| 135 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 136 | if (m_sym_file_ap.get()) |
| 137 | return m_sym_file_ap->ParseCompileUnitFunctions(sc); |
| 138 | } |
| 139 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | bool SymbolVendor::ParseCompileUnitLineTable(const SymbolContext &sc) { |
| 143 | ModuleSP module_sp(GetModule()); |
| 144 | if (module_sp) { |
| 145 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 146 | if (m_sym_file_ap.get()) |
| 147 | return m_sym_file_ap->ParseCompileUnitLineTable(sc); |
| 148 | } |
| 149 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | bool SymbolVendor::ParseCompileUnitDebugMacros(const SymbolContext &sc) { |
| 153 | ModuleSP module_sp(GetModule()); |
| 154 | if (module_sp) { |
| 155 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 156 | if (m_sym_file_ap.get()) |
| 157 | return m_sym_file_ap->ParseCompileUnitDebugMacros(sc); |
| 158 | } |
| 159 | return false; |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 160 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | bool SymbolVendor::ParseCompileUnitSupportFiles(const SymbolContext &sc, |
| 162 | FileSpecList &support_files) { |
| 163 | ModuleSP module_sp(GetModule()); |
| 164 | if (module_sp) { |
| 165 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 166 | if (m_sym_file_ap.get()) |
| 167 | return m_sym_file_ap->ParseCompileUnitSupportFiles(sc, support_files); |
| 168 | } |
| 169 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | bool SymbolVendor::ParseCompileUnitIsOptimized(const SymbolContext &sc) { |
| 173 | ModuleSP module_sp(GetModule()); |
| 174 | if (module_sp) { |
| 175 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 176 | if (m_sym_file_ap.get()) |
| 177 | return m_sym_file_ap->ParseCompileUnitIsOptimized(sc); |
| 178 | } |
| 179 | return false; |
| Greg Clayton | ad2b63c | 2016-07-05 23:01:20 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 182 | bool SymbolVendor::ParseImportedModules( |
| 183 | const SymbolContext &sc, std::vector<ConstString> &imported_modules) { |
| 184 | ModuleSP module_sp(GetModule()); |
| 185 | if (module_sp) { |
| 186 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 187 | if (m_sym_file_ap.get()) |
| 188 | return m_sym_file_ap->ParseImportedModules(sc, imported_modules); |
| 189 | } |
| 190 | return false; |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 193 | size_t SymbolVendor::ParseFunctionBlocks(const SymbolContext &sc) { |
| 194 | ModuleSP module_sp(GetModule()); |
| 195 | if (module_sp) { |
| 196 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 197 | if (m_sym_file_ap.get()) |
| 198 | return m_sym_file_ap->ParseFunctionBlocks(sc); |
| 199 | } |
| 200 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| Zachary Turner | ac0d41c | 2019-01-10 20:57:50 +0000 | [diff] [blame] | 203 | size_t SymbolVendor::ParseTypesForCompileUnit(CompileUnit &comp_unit) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | ModuleSP module_sp(GetModule()); |
| 205 | if (module_sp) { |
| 206 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 207 | if (m_sym_file_ap.get()) |
| Zachary Turner | ac0d41c | 2019-01-10 20:57:50 +0000 | [diff] [blame] | 208 | return m_sym_file_ap->ParseTypesForCompileUnit(comp_unit); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | } |
| 210 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | size_t SymbolVendor::ParseVariablesForContext(const SymbolContext &sc) { |
| 214 | ModuleSP module_sp(GetModule()); |
| 215 | if (module_sp) { |
| 216 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 217 | if (m_sym_file_ap.get()) |
| 218 | return m_sym_file_ap->ParseVariablesForContext(sc); |
| 219 | } |
| 220 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 223 | Type *SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid) { |
| 224 | ModuleSP module_sp(GetModule()); |
| 225 | if (module_sp) { |
| 226 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 227 | if (m_sym_file_ap.get()) |
| 228 | return m_sym_file_ap->ResolveTypeUID(type_uid); |
| 229 | } |
| 230 | return nullptr; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | uint32_t SymbolVendor::ResolveSymbolContext(const Address &so_addr, |
| Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 234 | SymbolContextItem resolve_scope, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 235 | SymbolContext &sc) { |
| 236 | ModuleSP module_sp(GetModule()); |
| 237 | if (module_sp) { |
| 238 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 239 | if (m_sym_file_ap.get()) |
| 240 | return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc); |
| 241 | } |
| 242 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | uint32_t SymbolVendor::ResolveSymbolContext(const FileSpec &file_spec, |
| 246 | uint32_t line, bool check_inlines, |
| Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 247 | SymbolContextItem resolve_scope, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | SymbolContextList &sc_list) { |
| 249 | ModuleSP module_sp(GetModule()); |
| 250 | if (module_sp) { |
| 251 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 252 | if (m_sym_file_ap.get()) |
| 253 | return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines, |
| 254 | resolve_scope, sc_list); |
| 255 | } |
| 256 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 259 | size_t |
| 260 | SymbolVendor::FindGlobalVariables(const ConstString &name, |
| 261 | const CompilerDeclContext *parent_decl_ctx, |
| 262 | size_t max_matches, VariableList &variables) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | ModuleSP module_sp(GetModule()); |
| 264 | if (module_sp) { |
| 265 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 266 | if (m_sym_file_ap.get()) |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 267 | return m_sym_file_ap->FindGlobalVariables(name, parent_decl_ctx, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | max_matches, variables); |
| 269 | } |
| 270 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 273 | size_t SymbolVendor::FindGlobalVariables(const RegularExpression ®ex, |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 274 | size_t max_matches, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | VariableList &variables) { |
| 276 | ModuleSP module_sp(GetModule()); |
| 277 | if (module_sp) { |
| 278 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 279 | if (m_sym_file_ap.get()) |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 280 | return m_sym_file_ap->FindGlobalVariables(regex, max_matches, variables); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 281 | } |
| 282 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 285 | size_t SymbolVendor::FindFunctions(const ConstString &name, |
| 286 | const CompilerDeclContext *parent_decl_ctx, |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 287 | FunctionNameType name_type_mask, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 288 | bool include_inlines, bool append, |
| 289 | SymbolContextList &sc_list) { |
| 290 | ModuleSP module_sp(GetModule()); |
| 291 | if (module_sp) { |
| 292 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 293 | if (m_sym_file_ap.get()) |
| 294 | return m_sym_file_ap->FindFunctions(name, parent_decl_ctx, name_type_mask, |
| 295 | include_inlines, append, sc_list); |
| 296 | } |
| 297 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 300 | size_t SymbolVendor::FindFunctions(const RegularExpression ®ex, |
| 301 | bool include_inlines, bool append, |
| 302 | SymbolContextList &sc_list) { |
| 303 | ModuleSP module_sp(GetModule()); |
| 304 | if (module_sp) { |
| 305 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 306 | if (m_sym_file_ap.get()) |
| 307 | return m_sym_file_ap->FindFunctions(regex, include_inlines, append, |
| 308 | sc_list); |
| 309 | } |
| 310 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | size_t SymbolVendor::FindTypes( |
| 314 | const SymbolContext &sc, const ConstString &name, |
| 315 | const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, |
| 316 | llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, |
| 317 | TypeMap &types) { |
| 318 | ModuleSP module_sp(GetModule()); |
| 319 | if (module_sp) { |
| 320 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 321 | if (m_sym_file_ap.get()) |
| 322 | return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append, |
| 323 | max_matches, searched_symbol_files, |
| 324 | types); |
| 325 | } |
| 326 | if (!append) |
| 327 | types.Clear(); |
| 328 | return 0; |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 329 | } |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 330 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | size_t SymbolVendor::FindTypes(const std::vector<CompilerContext> &context, |
| 332 | bool append, TypeMap &types) { |
| 333 | ModuleSP module_sp(GetModule()); |
| 334 | if (module_sp) { |
| 335 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 336 | if (m_sym_file_ap.get()) |
| 337 | return m_sym_file_ap->FindTypes(context, append, types); |
| 338 | } |
| 339 | if (!append) |
| 340 | types.Clear(); |
| 341 | return 0; |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 344 | size_t SymbolVendor::GetTypes(SymbolContextScope *sc_scope, TypeClass type_mask, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 345 | lldb_private::TypeList &type_list) { |
| 346 | ModuleSP module_sp(GetModule()); |
| 347 | if (module_sp) { |
| 348 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 349 | if (m_sym_file_ap.get()) |
| 350 | return m_sym_file_ap->GetTypes(sc_scope, type_mask, type_list); |
| 351 | } |
| 352 | return 0; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 355 | CompilerDeclContext |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 356 | SymbolVendor::FindNamespace(const SymbolContext &sc, const ConstString &name, |
| 357 | const CompilerDeclContext *parent_decl_ctx) { |
| 358 | CompilerDeclContext namespace_decl_ctx; |
| 359 | ModuleSP module_sp(GetModule()); |
| 360 | if (module_sp) { |
| 361 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 362 | if (m_sym_file_ap.get()) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 363 | namespace_decl_ctx = |
| 364 | m_sym_file_ap->FindNamespace(sc, name, parent_decl_ctx); |
| 365 | } |
| 366 | return namespace_decl_ctx; |
| Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 369 | void SymbolVendor::Dump(Stream *s) { |
| 370 | ModuleSP module_sp(GetModule()); |
| 371 | if (module_sp) { |
| 372 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 373 | |
| 374 | bool show_context = false; |
| 375 | |
| 376 | s->Printf("%p: ", static_cast<void *>(this)); |
| 377 | s->Indent(); |
| 378 | s->PutCString("SymbolVendor"); |
| 379 | if (m_sym_file_ap.get()) { |
| Pavel Labath | 1cf23e1 | 2019-01-11 11:17:51 +0000 | [diff] [blame^] | 380 | *s << " " << m_sym_file_ap->GetPluginName(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 381 | ObjectFile *objfile = m_sym_file_ap->GetObjectFile(); |
| 382 | if (objfile) { |
| 383 | const FileSpec &objfile_file_spec = objfile->GetFileSpec(); |
| 384 | if (objfile_file_spec) { |
| 385 | s->PutCString(" ("); |
| 386 | objfile_file_spec.Dump(s); |
| 387 | s->PutChar(')'); |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 388 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 389 | } |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 390 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 391 | s->EOL(); |
| Pavel Labath | 9337b41 | 2018-06-06 11:35:23 +0000 | [diff] [blame] | 392 | if (m_sym_file_ap) |
| 393 | m_sym_file_ap->Dump(*s); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 394 | s->IndentMore(); |
| 395 | m_type_list.Dump(s, show_context); |
| 396 | |
| 397 | CompileUnitConstIter cu_pos, cu_end; |
| 398 | cu_end = m_compile_units.end(); |
| 399 | for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos) { |
| 400 | // We currently only dump the compile units that have been parsed |
| 401 | if (cu_pos->get()) |
| 402 | (*cu_pos)->Dump(s, show_context); |
| 403 | } |
| 404 | |
| Pavel Labath | 1cf23e1 | 2019-01-11 11:17:51 +0000 | [diff] [blame^] | 405 | if (Symtab *symtab = GetSymtab()) |
| 406 | symtab->Dump(s, nullptr, eSortOrderNone); |
| 407 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 408 | s->IndentLess(); |
| 409 | } |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | CompUnitSP SymbolVendor::GetCompileUnitAtIndex(size_t idx) { |
| 413 | CompUnitSP cu_sp; |
| 414 | ModuleSP module_sp(GetModule()); |
| 415 | if (module_sp) { |
| 416 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 417 | const size_t num_compile_units = GetNumCompileUnits(); |
| 418 | if (idx < num_compile_units) { |
| 419 | cu_sp = m_compile_units[idx]; |
| 420 | if (cu_sp.get() == nullptr) { |
| 421 | m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx); |
| 422 | cu_sp = m_compile_units[idx]; |
| 423 | } |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 424 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 425 | } |
| 426 | return cu_sp; |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 427 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 429 | FileSpec SymbolVendor::GetMainFileSpec() const { |
| 430 | if (m_sym_file_ap.get()) { |
| 431 | const ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile(); |
| 432 | if (symfile_objfile) |
| 433 | return symfile_objfile->GetFileSpec(); |
| 434 | } |
| 435 | |
| 436 | return FileSpec(); |
| 437 | } |
| 438 | |
| 439 | Symtab *SymbolVendor::GetSymtab() { |
| 440 | ModuleSP module_sp(GetModule()); |
| Aleksandr Urakov | 8cfb12b | 2018-11-30 06:56:37 +0000 | [diff] [blame] | 441 | if (!module_sp) |
| 442 | return nullptr; |
| 443 | |
| 444 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 445 | |
| 446 | if (m_symtab) |
| 447 | return m_symtab; |
| 448 | |
| 449 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 450 | if (!objfile) |
| 451 | return nullptr; |
| 452 | |
| 453 | m_symtab = objfile->GetSymtab(); |
| 454 | if (m_symtab && m_sym_file_ap) |
| 455 | m_sym_file_ap->AddSymbols(*m_symtab); |
| 456 | |
| 457 | return m_symtab; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void SymbolVendor::ClearSymtab() { |
| 461 | ModuleSP module_sp(GetModule()); |
| 462 | if (module_sp) { |
| 463 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 464 | if (objfile) { |
| 465 | // Clear symbol table from unified section list. |
| 466 | objfile->ClearSymtab(); |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | void SymbolVendor::SectionFileAddressesChanged() { |
| 472 | ModuleSP module_sp(GetModule()); |
| 473 | if (module_sp) { |
| 474 | ObjectFile *module_objfile = module_sp->GetObjectFile(); |
| 475 | if (m_sym_file_ap.get()) { |
| 476 | ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile(); |
| 477 | if (symfile_objfile != module_objfile) |
| 478 | symfile_objfile->SectionFileAddressesChanged(); |
| 479 | } |
| 480 | Symtab *symtab = GetSymtab(); |
| 481 | if (symtab) { |
| 482 | symtab->SectionFileAddressesChanged(); |
| 483 | } |
| 484 | } |
| Jason Molenda | 05a09c6 | 2014-08-22 02:46:46 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | //------------------------------------------------------------------ |
| 488 | // PluginInterface protocol |
| 489 | //------------------------------------------------------------------ |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | lldb_private::ConstString SymbolVendor::GetPluginName() { |
| 491 | static ConstString g_name("vendor-default"); |
| 492 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 495 | uint32_t SymbolVendor::GetPluginVersion() { return 1; } |