1 //===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Symbol/SymbolFile.h"
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"
24 using namespace lldb_private;
26 void SymbolFile::PreloadSymbols() {
27 // No-op for most implementations.
30 std::recursive_mutex &SymbolFile::GetModuleMutex() const {
31 return GetObjectFile()->GetModule()->GetMutex();
34 SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
35 std::unique_ptr<SymbolFile> best_symfile_ap;
36 if (obj_file != nullptr) {
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());
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());
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.
54 uint32_t best_symfile_abilities = 0;
56 SymbolFileCreateInstance create_callback;
57 for (uint32_t idx = 0;
58 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(
61 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
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
70 if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
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();
81 return best_symfile_ap.release();
84 TypeList *SymbolFile::GetTypeList() {
86 return m_obj_file->GetModule()->GetTypeList();
90 TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
91 TypeSystem *type_system =
92 m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
94 type_system->SetSymbolFile(this);
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) {
106 SymbolFile::FindGlobalVariables(const ConstString &name,
107 const CompilerDeclContext *parent_decl_ctx,
108 uint32_t max_matches, VariableList &variables) {
112 uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex,
113 uint32_t max_matches,
114 VariableList &variables) {
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) {
128 uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex,
129 bool include_inlines, bool append,
130 SymbolContextList &sc_list) {
136 void SymbolFile::GetMangledNamesForFunction(
137 const std::string &scope_qualified_name,
138 std::vector<ConstString> &mangled_names) {
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,
152 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
153 bool append, TypeMap &types) {
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(); })
169 "Module is not locked");