]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Symbol/SymbolFile.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Symbol / SymbolFile.cpp
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
10 #include "lldb/Symbol/SymbolFile.h"
11
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/PluginManager.h"
14 #include "lldb/Symbol/ObjectFile.h"
15 #include "lldb/Symbol/TypeMap.h"
16 #include "lldb/Symbol/TypeSystem.h"
17 #include "lldb/Symbol/VariableList.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/StreamString.h"
20 #include "lldb/lldb-private.h"
21
22 #include <future>
23
24 using namespace lldb_private;
25
26 void SymbolFile::PreloadSymbols() {
27   // No-op for most implementations.
28 }
29
30 std::recursive_mutex &SymbolFile::GetModuleMutex() const {
31   return GetObjectFile()->GetModule()->GetMutex();
32 }
33
34 SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
35   std::unique_ptr<SymbolFile> best_symfile_ap;
36   if (obj_file != nullptr) {
37
38     // We need to test the abilities of this section list. So create what it
39     // would be with this new obj_file.
40     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       }
49     }
50
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());
68           // If any symbol file parser has all of the abilities, then we should
69           // just stop looking.
70           if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
71             break;
72         }
73       }
74     }
75     if (best_symfile_ap.get()) {
76       // Let the winning symbol file parser initialize itself more completely
77       // now that it has been chosen
78       best_symfile_ap->InitializeObject();
79     }
80   }
81   return best_symfile_ap.release();
82 }
83
84 TypeList *SymbolFile::GetTypeList() {
85   if (m_obj_file)
86     return m_obj_file->GetModule()->GetTypeList();
87   return nullptr;
88 }
89
90 TypeSystem *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;
96 }
97
98 uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
99                                           uint32_t line, bool check_inlines,
100                                           lldb::SymbolContextItem resolve_scope,
101                                           SymbolContextList &sc_list) {
102   return 0;
103 }
104
105 uint32_t
106 SymbolFile::FindGlobalVariables(const ConstString &name,
107                                 const CompilerDeclContext *parent_decl_ctx,
108                                 uint32_t max_matches, VariableList &variables) {
109   return 0;
110 }
111
112 uint32_t SymbolFile::FindGlobalVariables(const RegularExpression &regex,
113                                          uint32_t max_matches,
114                                          VariableList &variables) {
115   return 0;
116 }
117
118 uint32_t SymbolFile::FindFunctions(const ConstString &name,
119                                    const CompilerDeclContext *parent_decl_ctx,
120                                    lldb::FunctionNameType name_type_mask,
121                                    bool include_inlines, bool append,
122                                    SymbolContextList &sc_list) {
123   if (!append)
124     sc_list.Clear();
125   return 0;
126 }
127
128 uint32_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;
134 }
135
136 void SymbolFile::GetMangledNamesForFunction(
137     const std::string &scope_qualified_name,
138     std::vector<ConstString> &mangled_names) {
139   return;
140 }
141
142 uint32_t SymbolFile::FindTypes(
143     const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
144     bool append, uint32_t max_matches,
145     llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
146     TypeMap &types) {
147   if (!append)
148     types.Clear();
149   return 0;
150 }
151
152 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
153                              bool append, TypeMap &types) {
154   if (!append)
155     types.Clear();
156   return 0;
157 }
158
159 void SymbolFile::AssertModuleLock() {
160   // The code below is too expensive to leave enabled in release builds. It's
161   // enabled in debug builds or when the correct macro is set.
162 #if defined(LLDB_CONFIGURATION_DEBUG)
163   // We assert that we have to module lock by trying to acquire the lock from a
164   // different thread. Note that we must abort if the result is true to
165   // guarantee correctness.
166   assert(std::async(std::launch::async,
167                     [this] { return this->GetModuleMutex().try_lock(); })
168                  .get() == false &&
169          "Module is not locked");
170 #endif
171 }