1 //===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
3 // 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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/SymbolFile.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Core/PluginManager.h"
13 #include "lldb/Symbol/ObjectFile.h"
14 #include "lldb/Symbol/TypeMap.h"
15 #include "lldb/Symbol/TypeSystem.h"
16 #include "lldb/Symbol/VariableList.h"
17 #include "lldb/Utility/Log.h"
18 #include "lldb/Utility/StreamString.h"
19 #include "lldb/lldb-private.h"
23 using namespace lldb_private;
25 void SymbolFile::PreloadSymbols() {
26 // No-op for most implementations.
29 std::recursive_mutex &SymbolFile::GetModuleMutex() const {
30 return GetObjectFile()->GetModule()->GetMutex();
33 SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
34 std::unique_ptr<SymbolFile> best_symfile_up;
35 if (obj_file != nullptr) {
37 // We need to test the abilities of this section list. So create what it
38 // would be with this new obj_file.
39 lldb::ModuleSP module_sp(obj_file->GetModule());
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());
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.
53 uint32_t best_symfile_abilities = 0;
55 SymbolFileCreateInstance create_callback;
56 for (uint32_t idx = 0;
57 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(
60 std::unique_ptr<SymbolFile> curr_symfile_up(create_callback(obj_file));
62 if (curr_symfile_up) {
63 const uint32_t sym_file_abilities = curr_symfile_up->GetAbilities();
64 if (sym_file_abilities > best_symfile_abilities) {
65 best_symfile_abilities = sym_file_abilities;
66 best_symfile_up.reset(curr_symfile_up.release());
67 // If any symbol file parser has all of the abilities, then we should
69 if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
74 if (best_symfile_up) {
75 // Let the winning symbol file parser initialize itself more completely
76 // now that it has been chosen
77 best_symfile_up->InitializeObject();
80 return best_symfile_up.release();
83 TypeList *SymbolFile::GetTypeList() {
85 return m_obj_file->GetModule()->GetTypeList();
89 TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
90 TypeSystem *type_system =
91 m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
93 type_system->SetSymbolFile(this);
97 uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
98 uint32_t line, bool check_inlines,
99 lldb::SymbolContextItem resolve_scope,
100 SymbolContextList &sc_list) {
105 SymbolFile::FindGlobalVariables(ConstString name,
106 const CompilerDeclContext *parent_decl_ctx,
107 uint32_t max_matches, VariableList &variables) {
111 uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex,
112 uint32_t max_matches,
113 VariableList &variables) {
117 uint32_t SymbolFile::FindFunctions(ConstString name,
118 const CompilerDeclContext *parent_decl_ctx,
119 lldb::FunctionNameType name_type_mask,
120 bool include_inlines, bool append,
121 SymbolContextList &sc_list) {
127 uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex,
128 bool include_inlines, bool append,
129 SymbolContextList &sc_list) {
135 void SymbolFile::GetMangledNamesForFunction(
136 const std::string &scope_qualified_name,
137 std::vector<ConstString> &mangled_names) {
141 uint32_t SymbolFile::FindTypes(
142 ConstString name, const CompilerDeclContext *parent_decl_ctx,
143 bool append, uint32_t max_matches,
144 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
151 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
152 bool append, TypeMap &types) {
158 void 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(); })
168 "Module is not locked");
172 SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;