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 Reserve(size_t count);
44 Symbol *Resize(size_t count);
45 uint32_t AddSymbol(const Symbol &symbol);
46 size_t GetNumSymbols() const;
47 void SectionFileAddressesChanged();
48 void Dump(Stream *s, Target *target, SortOrder sort_type);
49 void Dump(Stream *s, Target *target, std::vector<uint32_t> &indexes) const;
50 uint32_t GetIndexForSymbol(const Symbol *symbol) const;
51 std::recursive_mutex &GetMutex() { return m_mutex; }
52 Symbol *FindSymbolByID(lldb::user_id_t uid) const;
53 Symbol *SymbolAtIndex(size_t idx);
54 const Symbol *SymbolAtIndex(size_t idx) const;
55 Symbol *FindSymbolWithType(lldb::SymbolType symbol_type,
56 Debug symbol_debug_type,
57 Visibility symbol_visibility, uint32_t &start_idx);
58 //----------------------------------------------------------------------
59 /// Get the parent symbol for the given symbol.
61 /// Many symbols in symbol tables are scoped by other symbols that
62 /// contain one or more symbol. This function will look for such a
63 /// containing symbol and return it if there is one.
64 //----------------------------------------------------------------------
65 const Symbol *GetParent(Symbol *symbol) const;
66 uint32_t AppendSymbolIndexesWithType(lldb::SymbolType symbol_type,
67 std::vector<uint32_t> &indexes,
68 uint32_t start_idx = 0,
69 uint32_t end_index = UINT32_MAX) const;
70 uint32_t AppendSymbolIndexesWithTypeAndFlagsValue(
71 lldb::SymbolType symbol_type, uint32_t flags_value,
72 std::vector<uint32_t> &indexes, uint32_t start_idx = 0,
73 uint32_t end_index = UINT32_MAX) const;
74 uint32_t AppendSymbolIndexesWithType(lldb::SymbolType symbol_type,
75 Debug symbol_debug_type,
76 Visibility symbol_visibility,
77 std::vector<uint32_t> &matches,
78 uint32_t start_idx = 0,
79 uint32_t end_index = UINT32_MAX) const;
80 uint32_t AppendSymbolIndexesWithName(const ConstString &symbol_name,
81 std::vector<uint32_t> &matches);
82 uint32_t AppendSymbolIndexesWithName(const ConstString &symbol_name,
83 Debug symbol_debug_type,
84 Visibility symbol_visibility,
85 std::vector<uint32_t> &matches);
86 uint32_t AppendSymbolIndexesWithNameAndType(const ConstString &symbol_name,
87 lldb::SymbolType symbol_type,
88 std::vector<uint32_t> &matches);
89 uint32_t AppendSymbolIndexesWithNameAndType(const ConstString &symbol_name,
90 lldb::SymbolType symbol_type,
91 Debug symbol_debug_type,
92 Visibility symbol_visibility,
93 std::vector<uint32_t> &matches);
95 AppendSymbolIndexesMatchingRegExAndType(const RegularExpression ®ex,
96 lldb::SymbolType symbol_type,
97 std::vector<uint32_t> &indexes);
98 uint32_t AppendSymbolIndexesMatchingRegExAndType(
99 const RegularExpression ®ex, lldb::SymbolType symbol_type,
100 Debug symbol_debug_type, Visibility symbol_visibility,
101 std::vector<uint32_t> &indexes);
102 size_t FindAllSymbolsWithNameAndType(const ConstString &name,
103 lldb::SymbolType symbol_type,
104 std::vector<uint32_t> &symbol_indexes);
105 size_t FindAllSymbolsWithNameAndType(const ConstString &name,
106 lldb::SymbolType symbol_type,
107 Debug symbol_debug_type,
108 Visibility symbol_visibility,
109 std::vector<uint32_t> &symbol_indexes);
110 size_t FindAllSymbolsMatchingRexExAndType(
111 const RegularExpression ®ex, lldb::SymbolType symbol_type,
112 Debug symbol_debug_type, Visibility symbol_visibility,
113 std::vector<uint32_t> &symbol_indexes);
114 Symbol *FindFirstSymbolWithNameAndType(const ConstString &name,
115 lldb::SymbolType symbol_type,
116 Debug symbol_debug_type,
117 Visibility symbol_visibility);
118 Symbol *FindSymbolAtFileAddress(lldb::addr_t file_addr);
119 Symbol *FindSymbolContainingFileAddress(lldb::addr_t file_addr);
120 void ForEachSymbolContainingFileAddress(
121 lldb::addr_t file_addr, std::function<bool(Symbol *)> const &callback);
122 size_t FindFunctionSymbols(const ConstString &name, uint32_t name_type_mask,
123 SymbolContextList &sc_list);
124 void CalculateSymbolSizes();
126 void SortSymbolIndexesByValue(std::vector<uint32_t> &indexes,
127 bool remove_duplicates) const;
129 static void DumpSymbolHeader(Stream *s);
132 // Shrink to fit the symbols so we don't waste memory
133 if (m_symbols.capacity() > m_symbols.size()) {
134 collection new_symbols(m_symbols.begin(), m_symbols.end());
135 m_symbols.swap(new_symbols);
139 void AppendSymbolNamesToMap(const IndexCollection &indexes,
140 bool add_demangled, bool add_mangled,
141 NameToIndexMap &name_to_index_map) const;
143 ObjectFile *GetObjectFile() { return m_objfile; }
146 typedef std::vector<Symbol> collection;
147 typedef collection::iterator iterator;
148 typedef collection::const_iterator const_iterator;
149 typedef RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t>
151 void InitNameIndexes();
152 void InitAddressIndexes();
154 ObjectFile *m_objfile;
155 collection m_symbols;
156 FileRangeToIndexMap m_file_addr_to_index;
157 UniqueCStringMap<uint32_t> m_name_to_index;
158 UniqueCStringMap<uint32_t> m_basename_to_index;
159 UniqueCStringMap<uint32_t> m_method_to_index;
160 UniqueCStringMap<uint32_t> m_selector_to_index;
161 mutable std::recursive_mutex
162 m_mutex; // Provide thread safety for this symbol table
163 bool m_file_addr_to_index_computed : 1, m_name_indexes_computed : 1;
166 bool CheckSymbolAtIndex(size_t idx, Debug symbol_debug_type,
167 Visibility symbol_visibility) const {
168 switch (symbol_debug_type) {
170 if (m_symbols[idx].IsDebug() == true)
175 if (m_symbols[idx].IsDebug() == false)
183 switch (symbol_visibility) {
187 case eVisibilityExtern:
188 return m_symbols[idx].IsExternal();
190 case eVisibilityPrivate:
191 return !m_symbols[idx].IsExternal();
196 void SymbolIndicesToSymbolContextList(std::vector<uint32_t> &symbol_indexes,
197 SymbolContextList &sc_list);
199 DISALLOW_COPY_AND_ASSIGN(Symtab);
202 } // namespace lldb_private
204 #endif // liblldb_Symtab_h_