1 //===-- Symtab.h ------------------------------------------------*- 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 #ifndef liblldb_Symtab_h_
11 #define liblldb_Symtab_h_
16 #include "lldb/Core/RangeMap.h"
17 #include "lldb/Core/UniqueCStringMap.h"
18 #include "lldb/Symbol/Symbol.h"
19 #include "lldb/lldb-private.h"
21 namespace lldb_private {
25 typedef std::vector<uint32_t> IndexCollection;
26 typedef UniqueCStringMap<uint32_t> NameToIndexMap;
29 eDebugNo, // Not a debug symbol
30 eDebugYes, // A debug symbol
34 typedef enum Visibility {
40 Symtab(ObjectFile *objfile);
43 void PreloadSymbols();
44 void Reserve(size_t count);
45 Symbol *Resize(size_t count);
46 uint32_t AddSymbol(const Symbol &symbol);
47 size_t GetNumSymbols() const;
48 void SectionFileAddressesChanged();
49 void Dump(Stream *s, Target *target, SortOrder sort_type);
50 void Dump(Stream *s, Target *target, std::vector<uint32_t> &indexes) const;
51 uint32_t GetIndexForSymbol(const Symbol *symbol) const;
52 std::recursive_mutex &GetMutex() { return m_mutex; }
53 Symbol *FindSymbolByID(lldb::user_id_t uid) const;
54 Symbol *SymbolAtIndex(size_t idx);
55 const Symbol *SymbolAtIndex(size_t idx) const;
56 Symbol *FindSymbolWithType(lldb::SymbolType symbol_type,
57 Debug symbol_debug_type,
58 Visibility symbol_visibility, uint32_t &start_idx);
59 //----------------------------------------------------------------------
60 /// Get the parent symbol for the given symbol.
62 /// Many symbols in symbol tables are scoped by other symbols that
63 /// contain one or more symbol. This function will look for such a
64 /// containing symbol and return it if there is one.
65 //----------------------------------------------------------------------
66 const Symbol *GetParent(Symbol *symbol) const;
67 uint32_t AppendSymbolIndexesWithType(lldb::SymbolType symbol_type,
68 std::vector<uint32_t> &indexes,
69 uint32_t start_idx = 0,
70 uint32_t end_index = UINT32_MAX) const;
71 uint32_t AppendSymbolIndexesWithTypeAndFlagsValue(
72 lldb::SymbolType symbol_type, uint32_t flags_value,
73 std::vector<uint32_t> &indexes, uint32_t start_idx = 0,
74 uint32_t end_index = UINT32_MAX) const;
75 uint32_t AppendSymbolIndexesWithType(lldb::SymbolType symbol_type,
76 Debug symbol_debug_type,
77 Visibility symbol_visibility,
78 std::vector<uint32_t> &matches,
79 uint32_t start_idx = 0,
80 uint32_t end_index = UINT32_MAX) const;
81 uint32_t AppendSymbolIndexesWithName(const ConstString &symbol_name,
82 std::vector<uint32_t> &matches);
83 uint32_t AppendSymbolIndexesWithName(const ConstString &symbol_name,
84 Debug symbol_debug_type,
85 Visibility symbol_visibility,
86 std::vector<uint32_t> &matches);
87 uint32_t AppendSymbolIndexesWithNameAndType(const ConstString &symbol_name,
88 lldb::SymbolType symbol_type,
89 std::vector<uint32_t> &matches);
90 uint32_t AppendSymbolIndexesWithNameAndType(const ConstString &symbol_name,
91 lldb::SymbolType symbol_type,
92 Debug symbol_debug_type,
93 Visibility symbol_visibility,
94 std::vector<uint32_t> &matches);
96 AppendSymbolIndexesMatchingRegExAndType(const RegularExpression ®ex,
97 lldb::SymbolType symbol_type,
98 std::vector<uint32_t> &indexes);
99 uint32_t AppendSymbolIndexesMatchingRegExAndType(
100 const RegularExpression ®ex, lldb::SymbolType symbol_type,
101 Debug symbol_debug_type, Visibility symbol_visibility,
102 std::vector<uint32_t> &indexes);
103 size_t FindAllSymbolsWithNameAndType(const ConstString &name,
104 lldb::SymbolType symbol_type,
105 std::vector<uint32_t> &symbol_indexes);
106 size_t FindAllSymbolsWithNameAndType(const ConstString &name,
107 lldb::SymbolType symbol_type,
108 Debug symbol_debug_type,
109 Visibility symbol_visibility,
110 std::vector<uint32_t> &symbol_indexes);
111 size_t FindAllSymbolsMatchingRexExAndType(
112 const RegularExpression ®ex, lldb::SymbolType symbol_type,
113 Debug symbol_debug_type, Visibility symbol_visibility,
114 std::vector<uint32_t> &symbol_indexes);
115 Symbol *FindFirstSymbolWithNameAndType(const ConstString &name,
116 lldb::SymbolType symbol_type,
117 Debug symbol_debug_type,
118 Visibility symbol_visibility);
119 Symbol *FindSymbolAtFileAddress(lldb::addr_t file_addr);
120 Symbol *FindSymbolContainingFileAddress(lldb::addr_t file_addr);
121 void ForEachSymbolContainingFileAddress(
122 lldb::addr_t file_addr, std::function<bool(Symbol *)> const &callback);
123 size_t FindFunctionSymbols(const ConstString &name, uint32_t name_type_mask,
124 SymbolContextList &sc_list);
125 void CalculateSymbolSizes();
127 void SortSymbolIndexesByValue(std::vector<uint32_t> &indexes,
128 bool remove_duplicates) const;
130 static void DumpSymbolHeader(Stream *s);
133 // Shrink to fit the symbols so we don't waste memory
134 if (m_symbols.capacity() > m_symbols.size()) {
135 collection new_symbols(m_symbols.begin(), m_symbols.end());
136 m_symbols.swap(new_symbols);
140 void AppendSymbolNamesToMap(const IndexCollection &indexes,
141 bool add_demangled, bool add_mangled,
142 NameToIndexMap &name_to_index_map) const;
144 ObjectFile *GetObjectFile() { return m_objfile; }
147 typedef std::vector<Symbol> collection;
148 typedef collection::iterator iterator;
149 typedef collection::const_iterator const_iterator;
150 typedef RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t>
152 void InitNameIndexes();
153 void InitAddressIndexes();
155 ObjectFile *m_objfile;
156 collection m_symbols;
157 FileRangeToIndexMap m_file_addr_to_index;
158 UniqueCStringMap<uint32_t> m_name_to_index;
159 UniqueCStringMap<uint32_t> m_basename_to_index;
160 UniqueCStringMap<uint32_t> m_method_to_index;
161 UniqueCStringMap<uint32_t> m_selector_to_index;
162 mutable std::recursive_mutex
163 m_mutex; // Provide thread safety for this symbol table
164 bool m_file_addr_to_index_computed : 1, m_name_indexes_computed : 1;
167 bool CheckSymbolAtIndex(size_t idx, Debug symbol_debug_type,
168 Visibility symbol_visibility) const {
169 switch (symbol_debug_type) {
171 if (m_symbols[idx].IsDebug())
176 if (!m_symbols[idx].IsDebug())
184 switch (symbol_visibility) {
188 case eVisibilityExtern:
189 return m_symbols[idx].IsExternal();
191 case eVisibilityPrivate:
192 return !m_symbols[idx].IsExternal();
197 void SymbolIndicesToSymbolContextList(std::vector<uint32_t> &symbol_indexes,
198 SymbolContextList &sc_list);
200 void RegisterMangledNameEntry(
201 NameToIndexMap::Entry &entry, std::set<const char *> &class_contexts,
202 std::vector<std::pair<NameToIndexMap::Entry, const char *>> &backlog,
203 RichManglingContext &rmc);
205 void RegisterBacklogEntry(const NameToIndexMap::Entry &entry,
206 const char *decl_context,
207 const std::set<const char *> &class_contexts);
209 DISALLOW_COPY_AND_ASSIGN(Symtab);
212 } // namespace lldb_private
214 #endif // liblldb_Symtab_h_