LLDB  mainline
SymbolFile.cpp
Go to the documentation of this file.
1 //===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "lldb/Core/Module.h"
13 #include "lldb/Symbol/ObjectFile.h"
14 #include "lldb/Symbol/TypeMap.h"
15 #include "lldb/Symbol/TypeSystem.h"
17 #include "lldb/Utility/Log.h"
19 #include "lldb/lldb-private.h"
20 
21 #include <future>
22 
23 using namespace lldb_private;
24 
26  // No-op for most implementations.
27 }
28 
29 std::recursive_mutex &SymbolFile::GetModuleMutex() const {
30  return GetObjectFile()->GetModule()->GetMutex();
31 }
32 
34  std::unique_ptr<SymbolFile> best_symfile_up;
35  if (obj_file != nullptr) {
36 
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());
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  }
48  }
49 
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;
58  idx)) != nullptr;
59  ++idx) {
60  std::unique_ptr<SymbolFile> curr_symfile_up(create_callback(obj_file));
61 
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
68  // just stop looking.
69  if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
70  break;
71  }
72  }
73  }
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();
78  }
79  }
80  return best_symfile_up.release();
81 }
82 
84  if (m_obj_file)
85  return m_obj_file->GetModule()->GetTypeList();
86  return nullptr;
87 }
88 
90  TypeSystem *type_system =
91  m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
92  if (type_system)
93  type_system->SetSymbolFile(this);
94  return type_system;
95 }
96 
98  uint32_t line, bool check_inlines,
99  lldb::SymbolContextItem resolve_scope,
100  SymbolContextList &sc_list) {
101  return 0;
102 }
103 
104 uint32_t
106  const CompilerDeclContext *parent_decl_ctx,
107  uint32_t max_matches, VariableList &variables) {
108  return 0;
109 }
110 
112  uint32_t max_matches,
113  VariableList &variables) {
114  return 0;
115 }
116 
118  const CompilerDeclContext *parent_decl_ctx,
119  lldb::FunctionNameType name_type_mask,
120  bool include_inlines, bool append,
121  SymbolContextList &sc_list) {
122  if (!append)
123  sc_list.Clear();
124  return 0;
125 }
126 
128  bool include_inlines, bool append,
129  SymbolContextList &sc_list) {
130  if (!append)
131  sc_list.Clear();
132  return 0;
133 }
134 
136  const std::string &scope_qualified_name,
137  std::vector<ConstString> &mangled_names) {
138  return;
139 }
140 
142  ConstString name, const CompilerDeclContext *parent_decl_ctx,
143  bool append, uint32_t max_matches,
144  llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
145  TypeMap &types) {
146  if (!append)
147  types.Clear();
148  return 0;
149 }
150 
151 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
152  bool append, TypeMap &types) {
153  if (!append)
154  types.Clear();
155  return 0;
156 }
157 
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 }
Defines a list of symbol context objects.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
Definition: SymbolFile.cpp:29
virtual void SetSymbolFile(SymbolFile *sym_file)
Definition: TypeSystem.h:94
virtual uint32_t FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, llvm::DenseSet< lldb_private::SymbolFile *> &searched_symbol_files, TypeMap &types)
Definition: SymbolFile.cpp:141
static SymbolFile * FindPlugin(ObjectFile *obj_file)
Definition: SymbolFile.cpp:33
A file utility class.
Definition: FileSpec.h:55
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
virtual void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector< ConstString > &mangled_names)
Definition: SymbolFile.cpp:135
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:27
static SymbolFileCreateInstance GetSymbolFileCreateCallbackAtIndex(uint32_t idx)
virtual lldb_private::TypeSystem * GetTypeSystemForLanguage(lldb::LanguageType language)
Definition: SymbolFile.cpp:89
LanguageType
Programming language type.
virtual uint32_t FindGlobalVariables(ConstString name, const CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, VariableList &variables)
Definition: SymbolFile.cpp:105
virtual uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc)=0
virtual void PreloadSymbols()
Definition: SymbolFile.cpp:25
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:605
void Clear()
Clear the object&#39;s state.
virtual TypeList * GetTypeList()
Definition: SymbolFile.cpp:83
ObjectFile * m_obj_file
Definition: SymbolFile.h:231
A uniqued constant string class.
Definition: ConstString.h:38
ObjectFile * GetObjectFile()
Definition: SymbolFile.h:213
virtual void CreateSections(SectionList &unified_section_list)=0
virtual uint32_t FindFunctions(ConstString name, const CompilerDeclContext *parent_decl_ctx, lldb::FunctionNameType name_type_mask, bool include_inlines, bool append, SymbolContextList &sc_list)
Definition: SymbolFile.cpp:117