blob: d4408780b423a2938741ed2fd740a38a5a2d7436 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Lattner30fdc8d2010-06-08 16:52:24 +000010#include "lldb/Symbol/SymbolFile.h"
Greg Claytonc982b3d2011-11-28 01:45:00 +000011
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000012#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Core/PluginManager.h"
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000014#include "lldb/Symbol/ObjectFile.h"
Ravitheja Addepally40697302015-10-08 09:45:41 +000015#include "lldb/Symbol/TypeMap.h"
Greg Clayton56939cb2015-09-17 22:23:34 +000016#include "lldb/Symbol/TypeSystem.h"
Greg Clayton99558cc42015-08-24 23:46:31 +000017#include "lldb/Symbol/VariableList.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000018#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000019#include "lldb/Utility/StreamString.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000020#include "lldb/lldb-private.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
Jonas Devlieghere4f78c4f2018-10-22 20:14:36 +000022#include <future>
23
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024using namespace lldb_private;
25
Jim Ingham7fca8c02017-04-28 00:51:06 +000026void SymbolFile::PreloadSymbols() {
27 // No-op for most implementations.
28}
29
Jonas Devlieghere4f78c4f2018-10-22 20:14:36 +000030std::recursive_mutex &SymbolFile::GetModuleMutex() const {
31 return GetObjectFile()->GetModule()->GetMutex();
32}
33
Kate Stoneb9c1b512016-09-06 20:57:50 +000034SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
35 std::unique_ptr<SymbolFile> best_symfile_ap;
36 if (obj_file != nullptr) {
Greg Clayton3046e662013-07-10 01:23:25 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 // We need to test the abilities of this section list. So create what it
Adrian Prantl05097242018-04-30 16:49:04 +000039 // would be with this new obj_file.
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 lldb::ModuleSP module_sp(obj_file->GetModule());
41 if (module_sp) {
42 // Default to the main module section list.
43 ObjectFile *module_obj_file = module_sp->GetObjectFile();
44 if (module_obj_file != obj_file) {
45 // Make sure the main object file's sections are created
46 module_obj_file->GetSectionList();
47 obj_file->CreateSections(*module_sp->GetUnifiedSectionList());
48 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000050
51 // TODO: Load any plug-ins in the appropriate plug-in search paths and
52 // iterate over all of them to find the best one for the job.
53
54 uint32_t best_symfile_abilities = 0;
55
56 SymbolFileCreateInstance create_callback;
57 for (uint32_t idx = 0;
58 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(
59 idx)) != nullptr;
60 ++idx) {
61 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
62
63 if (curr_symfile_ap.get()) {
64 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
65 if (sym_file_abilities > best_symfile_abilities) {
66 best_symfile_abilities = sym_file_abilities;
67 best_symfile_ap.reset(curr_symfile_ap.release());
Adrian Prantl05097242018-04-30 16:49:04 +000068 // If any symbol file parser has all of the abilities, then we should
69 // just stop looking.
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
71 break;
72 }
73 }
74 }
75 if (best_symfile_ap.get()) {
Adrian Prantl05097242018-04-30 16:49:04 +000076 // Let the winning symbol file parser initialize itself more completely
77 // now that it has been chosen
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 best_symfile_ap->InitializeObject();
79 }
80 }
81 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082}
83
Kate Stoneb9c1b512016-09-06 20:57:50 +000084TypeList *SymbolFile::GetTypeList() {
85 if (m_obj_file)
86 return m_obj_file->GetModule()->GetTypeList();
87 return nullptr;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000088}
Greg Clayton6beaaa62011-01-17 03:46:26 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
91 TypeSystem *type_system =
92 m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
93 if (type_system)
94 type_system->SetSymbolFile(this);
95 return type_system;
Greg Clayton8b4edba2015-08-14 20:02:05 +000096}
97
Kate Stoneb9c1b512016-09-06 20:57:50 +000098uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
99 uint32_t line, bool check_inlines,
Zachary Turner991e4452018-10-25 20:45:19 +0000100 lldb::SymbolContextItem resolve_scope,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 SymbolContextList &sc_list) {
102 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000103}
104
Pavel Labath34cda142018-05-31 09:46:26 +0000105uint32_t
106SymbolFile::FindGlobalVariables(const ConstString &name,
107 const CompilerDeclContext *parent_decl_ctx,
108 uint32_t max_matches, VariableList &variables) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000110}
111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112uint32_t SymbolFile::FindGlobalVariables(const RegularExpression &regex,
Pavel Labath34cda142018-05-31 09:46:26 +0000113 uint32_t max_matches,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 VariableList &variables) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000116}
117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118uint32_t SymbolFile::FindFunctions(const ConstString &name,
119 const CompilerDeclContext *parent_decl_ctx,
Zachary Turner117b1fa2018-10-25 20:45:40 +0000120 lldb::FunctionNameType name_type_mask,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 bool include_inlines, bool append,
122 SymbolContextList &sc_list) {
123 if (!append)
124 sc_list.Clear();
125 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000126}
127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128uint32_t SymbolFile::FindFunctions(const RegularExpression &regex,
129 bool include_inlines, bool append,
130 SymbolContextList &sc_list) {
131 if (!append)
132 sc_list.Clear();
133 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000134}
135
Kate Stoneb9c1b512016-09-06 20:57:50 +0000136void SymbolFile::GetMangledNamesForFunction(
137 const std::string &scope_qualified_name,
138 std::vector<ConstString> &mangled_names) {
139 return;
Siva Chandra9293fc42016-01-07 23:32:34 +0000140}
141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142uint32_t SymbolFile::FindTypes(
143 const SymbolContext &sc, const ConstString &name,
144 const CompilerDeclContext *parent_decl_ctx, bool append,
145 uint32_t max_matches,
146 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
147 TypeMap &types) {
148 if (!append)
149 types.Clear();
150 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000151}
152
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
154 bool append, TypeMap &types) {
155 if (!append)
156 types.Clear();
157 return 0;
Greg Claytone6b36cd2015-12-08 01:02:08 +0000158}
Jonas Devlieghere4f78c4f2018-10-22 20:14:36 +0000159
160void SymbolFile::AssertModuleLock() {
161 // The code below is too expensive to leave enabled in release builds. It's
162 // enabled in debug builds or when the correct macro is set.
163#if defined(LLDB_CONFIGURATION_DEBUG)
164 // We assert that we have to module lock by trying to acquire the lock from a
165 // different thread. Note that we must abort if the result is true to
166 // guarantee correctness.
167 assert(std::async(std::launch::async,
168 [this] { return this->GetModuleMutex().try_lock(); })
169 .get() == false &&
170 "Module is not locked");
171#endif
172}