LLDB  mainline
Symtab.h
Go to the documentation of this file.
1 //===-- Symtab.h ------------------------------------------------*- 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 
9 #ifndef liblldb_Symtab_h_
10 #define liblldb_Symtab_h_
11 
13 #include "lldb/Symbol/Symbol.h"
14 #include "lldb/Utility/RangeMap.h"
15 #include "lldb/lldb-private.h"
16 #include <mutex>
17 #include <vector>
18 
19 namespace lldb_private {
20 
21 class Symtab {
22 public:
23  typedef std::vector<uint32_t> IndexCollection;
25 
26  typedef enum Debug {
27  eDebugNo, // Not a debug symbol
28  eDebugYes, // A debug symbol
30  } Debug;
31 
32  typedef enum Visibility {
36  } Visibility;
37 
38  Symtab(ObjectFile *objfile);
39  ~Symtab();
40 
41  void PreloadSymbols();
42  void Reserve(size_t count);
43  Symbol *Resize(size_t count);
44  uint32_t AddSymbol(const Symbol &symbol);
45  size_t GetNumSymbols() const;
47  void Dump(Stream *s, Target *target, SortOrder sort_type);
48  void Dump(Stream *s, Target *target, std::vector<uint32_t> &indexes) const;
49  uint32_t GetIndexForSymbol(const Symbol *symbol) const;
50  std::recursive_mutex &GetMutex() { return m_mutex; }
52  Symbol *SymbolAtIndex(size_t idx);
53  const Symbol *SymbolAtIndex(size_t idx) const;
55  Debug symbol_debug_type,
56  Visibility symbol_visibility, uint32_t &start_idx);
57  /// Get the parent symbol for the given symbol.
58  ///
59  /// Many symbols in symbol tables are scoped by other symbols that
60  /// contain one or more symbol. This function will look for such a
61  /// containing symbol and return it if there is one.
62  const Symbol *GetParent(Symbol *symbol) const;
64  std::vector<uint32_t> &indexes,
65  uint32_t start_idx = 0,
66  uint32_t end_index = UINT32_MAX) const;
68  lldb::SymbolType symbol_type, uint32_t flags_value,
69  std::vector<uint32_t> &indexes, uint32_t start_idx = 0,
70  uint32_t end_index = UINT32_MAX) const;
72  Debug symbol_debug_type,
73  Visibility symbol_visibility,
74  std::vector<uint32_t> &matches,
75  uint32_t start_idx = 0,
76  uint32_t end_index = UINT32_MAX) const;
78  std::vector<uint32_t> &matches);
80  Debug symbol_debug_type,
81  Visibility symbol_visibility,
82  std::vector<uint32_t> &matches);
84  lldb::SymbolType symbol_type,
85  std::vector<uint32_t> &matches);
87  lldb::SymbolType symbol_type,
88  Debug symbol_debug_type,
89  Visibility symbol_visibility,
90  std::vector<uint32_t> &matches);
91  uint32_t
93  lldb::SymbolType symbol_type,
94  std::vector<uint32_t> &indexes);
96  const RegularExpression &regex, lldb::SymbolType symbol_type,
97  Debug symbol_debug_type, Visibility symbol_visibility,
98  std::vector<uint32_t> &indexes);
100  lldb::SymbolType symbol_type,
101  std::vector<uint32_t> &symbol_indexes);
103  lldb::SymbolType symbol_type,
104  Debug symbol_debug_type,
105  Visibility symbol_visibility,
106  std::vector<uint32_t> &symbol_indexes);
108  const RegularExpression &regex, lldb::SymbolType symbol_type,
109  Debug symbol_debug_type, Visibility symbol_visibility,
110  std::vector<uint32_t> &symbol_indexes);
112  lldb::SymbolType symbol_type,
113  Debug symbol_debug_type,
114  Visibility symbol_visibility);
118  lldb::addr_t file_addr, std::function<bool(Symbol *)> const &callback);
119  size_t FindFunctionSymbols(ConstString name, uint32_t name_type_mask,
120  SymbolContextList &sc_list);
121  void CalculateSymbolSizes();
122 
123  void SortSymbolIndexesByValue(std::vector<uint32_t> &indexes,
124  bool remove_duplicates) const;
125 
126  static void DumpSymbolHeader(Stream *s);
127 
128  void Finalize() {
129  // Shrink to fit the symbols so we don't waste memory
130  if (m_symbols.capacity() > m_symbols.size()) {
131  collection new_symbols(m_symbols.begin(), m_symbols.end());
132  m_symbols.swap(new_symbols);
133  }
134  }
135 
136  void AppendSymbolNamesToMap(const IndexCollection &indexes,
137  bool add_demangled, bool add_mangled,
138  NameToIndexMap &name_to_index_map) const;
139 
141 
142 protected:
143  typedef std::vector<Symbol> collection;
144  typedef collection::iterator iterator;
145  typedef collection::const_iterator const_iterator;
148  void InitNameIndexes();
149  void InitAddressIndexes();
150 
152  collection m_symbols;
158  mutable std::recursive_mutex
159  m_mutex; // Provide thread safety for this symbol table
161 
162 private:
163  bool CheckSymbolAtIndex(size_t idx, Debug symbol_debug_type,
164  Visibility symbol_visibility) const {
165  switch (symbol_debug_type) {
166  case eDebugNo:
167  if (m_symbols[idx].IsDebug())
168  return false;
169  break;
170 
171  case eDebugYes:
172  if (!m_symbols[idx].IsDebug())
173  return false;
174  break;
175 
176  case eDebugAny:
177  break;
178  }
179 
180  switch (symbol_visibility) {
181  case eVisibilityAny:
182  return true;
183 
184  case eVisibilityExtern:
185  return m_symbols[idx].IsExternal();
186 
187  case eVisibilityPrivate:
188  return !m_symbols[idx].IsExternal();
189  }
190  return false;
191  }
192 
193  void SymbolIndicesToSymbolContextList(std::vector<uint32_t> &symbol_indexes,
194  SymbolContextList &sc_list);
195 
196  void RegisterMangledNameEntry(
197  NameToIndexMap::Entry &entry, std::set<const char *> &class_contexts,
198  std::vector<std::pair<NameToIndexMap::Entry, const char *>> &backlog,
199  RichManglingContext &rmc);
200 
201  void RegisterBacklogEntry(const NameToIndexMap::Entry &entry,
202  const char *decl_context,
203  const std::set<const char *> &class_contexts);
204 
205  DISALLOW_COPY_AND_ASSIGN(Symtab);
206 };
207 
208 } // namespace lldb_private
209 
210 #endif // liblldb_Symtab_h_
Uniform wrapper for access to rich mangling information from different providers. ...
UniqueCStringMap< uint32_t > m_method_to_index
Definition: Symtab.h:156
std::recursive_mutex & GetMutex()
Definition: Symtab.h:50
UniqueCStringMap< uint32_t > m_name_to_index
Definition: Symtab.h:154
Defines a list of symbol context objects.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
Symtab(ObjectFile *objfile)
Definition: Symtab.cpp:31
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void CalculateSymbolSizes()
Definition: Symtab.cpp:973
uint32_t AppendSymbolIndexesWithNameAndType(ConstString symbol_name, lldb::SymbolType symbol_type, std::vector< uint32_t > &matches)
Definition: Symtab.cpp:668
std::recursive_mutex m_mutex
Definition: Symtab.h:159
ObjectFile * GetObjectFile()
Definition: Symtab.h:140
const Symbol * GetParent(Symbol *symbol) const
Get the parent symbol for the given symbol.
Definition: Symtab.cpp:1142
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
Symbol * FindSymbolWithType(lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx)
Definition: Symtab.cpp:752
size_t GetNumSymbols() const
Definition: Symtab.cpp:63
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
void AppendSymbolNamesToMap(const IndexCollection &indexes, bool add_demangled, bool add_mangled, NameToIndexMap &name_to_index_map) const
Definition: Symtab.cpp:441
void InitNameIndexes()
Definition: Symtab.cpp:254
Symbol * FindSymbolAtFileAddress(lldb::addr_t file_addr)
Definition: Symtab.cpp:979
UniqueCStringMap< uint32_t > m_basename_to_index
Definition: Symtab.h:155
void SectionFileAddressesChanged()
Definition: Symtab.cpp:68
void SortSymbolIndexesByValue(std::vector< uint32_t > &indexes, bool remove_duplicates) const
Definition: Symtab.cpp:599
#define UINT32_MAX
Definition: lldb-defines.h:31
size_t FindAllSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, std::vector< uint32_t > &symbol_indexes)
Definition: Symtab.cpp:772
uint64_t user_id_t
Definition: lldb-types.h:84
std::vector< Symbol > collection
Definition: Symtab.h:143
uint32_t AppendSymbolIndexesWithTypeAndFlagsValue(lldb::SymbolType symbol_type, uint32_t flags_value, std::vector< uint32_t > &indexes, uint32_t start_idx=0, uint32_t end_index=UINT32_MAX) const
Definition: Symtab.cpp:491
uint32_t AppendSymbolIndexesWithName(ConstString symbol_name, std::vector< uint32_t > &matches)
Definition: Symtab.cpp:626
uint32_t AddSymbol(const Symbol &symbol)
Definition: Symtab.cpp:51
FileRangeToIndexMap m_file_addr_to_index
Definition: Symtab.h:153
collection m_symbols
Definition: Symtab.h:152
static void DumpSymbolHeader(Stream *s)
Definition: Symtab.cpp:172
void InitAddressIndexes()
Definition: Symtab.cpp:890
std::vector< uint32_t > IndexCollection
Definition: Symtab.h:23
bool m_name_indexes_computed
Definition: Symtab.h:160
collection::iterator iterator
Definition: Symtab.h:144
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
Definition: Symtab.cpp:994
ObjectFile * m_objfile
Definition: Symtab.h:151
uint32_t AppendSymbolIndexesWithType(lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes, uint32_t start_idx=0, uint32_t end_index=UINT32_MAX) const
Definition: Symtab.cpp:473
void Dump(Stream *s, Target *target, SortOrder sort_type)
Definition: Symtab.cpp:73
collection::const_iterator const_iterator
Definition: Symtab.h:145
Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
Definition: Symtab.cpp:824
Symbol * SymbolAtIndex(size_t idx)
Definition: Symtab.cpp:203
size_t FindAllSymbolsMatchingRexExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector< uint32_t > &symbol_indexes)
Definition: Symtab.cpp:813
uint64_t addr_t
Definition: lldb-types.h:83
uint32_t GetIndexForSymbol(const Symbol *symbol) const
Definition: Symtab.cpp:534
UniqueCStringMap< uint32_t > m_selector_to_index
Definition: Symtab.h:157
A uniqued constant string class.
Definition: ConstString.h:38
bool m_file_addr_to_index_computed
Definition: Symtab.h:160
RangeDataVector< lldb::addr_t, lldb::addr_t, uint32_t > FileRangeToIndexMap
Definition: Symtab.h:147
Symbol * Resize(size_t count)
Definition: Symtab.cpp:44
void ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function< bool(Symbol *)> const &callback)
Definition: Symtab.cpp:1010
UniqueCStringMap< uint32_t > NameToIndexMap
Definition: Symtab.h:24
Symbol * FindSymbolByID(lldb::user_id_t uid) const
Definition: Symtab.cpp:194
size_t FindFunctionSymbols(ConstString name, uint32_t name_type_mask, SymbolContextList &sc_list)
Definition: Symtab.cpp:1051
void Reserve(size_t count)
Definition: Symtab.cpp:38
uint32_t AppendSymbolIndexesMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes)
Definition: Symtab.cpp:706