blob: f29149d3bb27d0b2b07303c2bb082ecc63a0f422 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
Chris Lattner30fdc8d2010-06-08 16:52:24 +00009#include "lldb/Symbol/SymbolFile.h"
Greg Claytonc982b3d2011-11-28 01:45:00 +000010
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000011#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/PluginManager.h"
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000013#include "lldb/Symbol/ObjectFile.h"
Ravitheja Addepally40697302015-10-08 09:45:41 +000014#include "lldb/Symbol/TypeMap.h"
Greg Clayton56939cb2015-09-17 22:23:34 +000015#include "lldb/Symbol/TypeSystem.h"
Greg Clayton99558cc42015-08-24 23:46:31 +000016#include "lldb/Symbol/VariableList.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000017#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000018#include "lldb/Utility/StreamString.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/lldb-private.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
Jonas Devlieghere4f78c4f2018-10-22 20:14:36 +000021#include <future>
22
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023using namespace lldb_private;
24
Jim Ingham7fca8c02017-04-28 00:51:06 +000025void SymbolFile::PreloadSymbols() {
26 // No-op for most implementations.
27}
28
Jonas Devlieghere4f78c4f2018-10-22 20:14:36 +000029std::recursive_mutex &SymbolFile::GetModuleMutex() const {
30 return GetObjectFile()->GetModule()->GetMutex();
31}
32
Kate Stoneb9c1b512016-09-06 20:57:50 +000033SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
34 std::unique_ptr<SymbolFile> best_symfile_ap;
35 if (obj_file != nullptr) {
Greg Clayton3046e662013-07-10 01:23:25 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 // We need to test the abilities of this section list. So create what it
Adrian Prantl05097242018-04-30 16:49:04 +000038 // would be with this new obj_file.
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 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 Lattner30fdc8d2010-06-08 16:52:24 +000048 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000049
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 Prantl05097242018-04-30 16:49:04 +000067 // If any symbol file parser has all of the abilities, then we should
68 // just stop looking.
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
70 break;
71 }
72 }
73 }
74 if (best_symfile_ap.get()) {
Adrian Prantl05097242018-04-30 16:49:04 +000075 // Let the winning symbol file parser initialize itself more completely
76 // now that it has been chosen
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 best_symfile_ap->InitializeObject();
78 }
79 }
80 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081}
82
Kate Stoneb9c1b512016-09-06 20:57:50 +000083TypeList *SymbolFile::GetTypeList() {
84 if (m_obj_file)
85 return m_obj_file->GetModule()->GetTypeList();
86 return nullptr;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000087}
Greg Clayton6beaaa62011-01-17 03:46:26 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089TypeSystem *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 Clayton8b4edba2015-08-14 20:02:05 +000095}
96
Kate Stoneb9c1b512016-09-06 20:57:50 +000097uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
98 uint32_t line, bool check_inlines,
Zachary Turner991e4452018-10-25 20:45:19 +000099 lldb::SymbolContextItem resolve_scope,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 SymbolContextList &sc_list) {
101 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000102}
103
Pavel Labath34cda142018-05-31 09:46:26 +0000104uint32_t
105SymbolFile::FindGlobalVariables(const ConstString &name,
106 const CompilerDeclContext *parent_decl_ctx,
107 uint32_t max_matches, VariableList &variables) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000109}
110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111uint32_t SymbolFile::FindGlobalVariables(const RegularExpression &regex,
Pavel Labath34cda142018-05-31 09:46:26 +0000112 uint32_t max_matches,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 VariableList &variables) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000115}
116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117uint32_t SymbolFile::FindFunctions(const ConstString &name,
118 const CompilerDeclContext *parent_decl_ctx,
Zachary Turner117b1fa2018-10-25 20:45:40 +0000119 lldb::FunctionNameType name_type_mask,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000120 bool include_inlines, bool append,
121 SymbolContextList &sc_list) {
122 if (!append)
123 sc_list.Clear();
124 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000125}
126
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127uint32_t SymbolFile::FindFunctions(const RegularExpression &regex,
128 bool include_inlines, bool append,
129 SymbolContextList &sc_list) {
130 if (!append)
131 sc_list.Clear();
132 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000133}
134
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135void SymbolFile::GetMangledNamesForFunction(
136 const std::string &scope_qualified_name,
137 std::vector<ConstString> &mangled_names) {
138 return;
Siva Chandra9293fc42016-01-07 23:32:34 +0000139}
140
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141uint32_t SymbolFile::FindTypes(
Zachary Turner576495e2019-01-14 22:41:21 +0000142 const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
143 bool append, uint32_t max_matches,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
145 TypeMap &types) {
146 if (!append)
147 types.Clear();
148 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000149}
150
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
152 bool append, TypeMap &types) {
153 if (!append)
154 types.Clear();
155 return 0;
Greg Claytone6b36cd2015-12-08 01:02:08 +0000156}
Jonas Devlieghere4f78c4f2018-10-22 20:14:36 +0000157
158void 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}