]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/Symtab.h
Update llvm, clang and lldb to release_38 branch r260756.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / Symtab.h
1 //===-- Symtab.h ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10
11 #ifndef liblldb_Symtab_h_
12 #define liblldb_Symtab_h_
13
14 #include <vector>
15
16 #include "lldb/lldb-private.h"
17 #include "lldb/Core/RangeMap.h"
18 #include "lldb/Core/UniqueCStringMap.h"
19 #include "lldb/Host/Mutex.h"
20 #include "lldb/Symbol/Symbol.h"
21
22 namespace lldb_private {
23
24 class Symtab
25 {
26 public:
27     typedef std::vector<uint32_t> IndexCollection;
28     typedef UniqueCStringMap<uint32_t> NameToIndexMap;
29
30     typedef enum Debug {
31         eDebugNo,   // Not a debug symbol
32         eDebugYes,  // A debug symbol 
33         eDebugAny
34     } Debug;
35
36     typedef enum Visibility {
37         eVisibilityAny,
38         eVisibilityExtern,
39         eVisibilityPrivate
40     } Visibility;
41         
42                         Symtab(ObjectFile *objfile);
43                         ~Symtab();
44
45             void        Reserve (size_t count);
46             Symbol *    Resize (size_t count);
47             uint32_t    AddSymbol(const Symbol& symbol);
48             size_t      GetNumSymbols() const;
49             void        SectionFileAddressesChanged ();
50             void        Dump(Stream *s, Target *target, SortOrder sort_type);
51             void        Dump(Stream *s, Target *target, std::vector<uint32_t>& indexes) const;
52             uint32_t    GetIndexForSymbol (const Symbol *symbol) const;
53             Mutex &     GetMutex ()
54                         {
55                             return m_mutex;
56                         }
57             Symbol *    FindSymbolByID (lldb::user_id_t uid) const;
58             Symbol *    SymbolAtIndex (size_t idx);
59     const   Symbol *    SymbolAtIndex (size_t idx) const;
60             Symbol *    FindSymbolWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx);
61             //----------------------------------------------------------------------
62             /// Get the parent symbol for the given symbol.
63             ///
64             /// Many symbols in symbol tables are scoped by other symbols that
65             /// contain one or more symbol. This function will look for such a
66             /// containing symbol and return it if there is one.
67             //----------------------------------------------------------------------
68     const   Symbol *    GetParent (Symbol *symbol) const;
69             uint32_t    AppendSymbolIndexesWithType (lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const;
70             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;
71             uint32_t    AppendSymbolIndexesWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const;
72             uint32_t    AppendSymbolIndexesWithName (const ConstString& symbol_name, std::vector<uint32_t>& matches);
73             uint32_t    AppendSymbolIndexesWithName (const ConstString& symbol_name, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches);
74             uint32_t    AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, std::vector<uint32_t>& matches);
75             uint32_t    AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches);
76             uint32_t    AppendSymbolIndexesMatchingRegExAndType (const RegularExpression &regex, lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes);
77             uint32_t    AppendSymbolIndexesMatchingRegExAndType (const RegularExpression &regex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes);
78             size_t      FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes);
79             size_t      FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes);
80             size_t      FindAllSymbolsMatchingRexExAndType (const RegularExpression &regex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes);
81             Symbol *    FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility);
82             Symbol *    FindSymbolContainingFileAddress (lldb::addr_t file_addr, const uint32_t* indexes, uint32_t num_indexes);
83             Symbol *    FindSymbolContainingFileAddress (lldb::addr_t file_addr);
84             void        ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function<bool(Symbol *)> const &callback);
85             size_t      FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list);
86             void        CalculateSymbolSizes ();
87
88             void        SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_duplicates) const;
89
90     static  void        DumpSymbolHeader (Stream *s);
91
92     
93             void        Finalize ()
94                         {
95                             // Shrink to fit the symbols so we don't waste memory
96                             if (m_symbols.capacity() > m_symbols.size())
97                             {
98                                 collection new_symbols (m_symbols.begin(), m_symbols.end());
99                                 m_symbols.swap (new_symbols);
100                             }
101                         }
102     
103             void        AppendSymbolNamesToMap (const IndexCollection &indexes, 
104                                                 bool add_demangled,
105                                                 bool add_mangled,
106                                                 NameToIndexMap &name_to_index_map) const;
107
108     ObjectFile *        GetObjectFile()
109                         {
110                             return m_objfile;
111                         }
112 protected:
113     typedef std::vector<Symbol>         collection;
114     typedef collection::iterator        iterator;
115     typedef collection::const_iterator  const_iterator;
116     typedef RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t> FileRangeToIndexMap;
117             void        InitNameIndexes ();
118             void        InitAddressIndexes ();
119
120     ObjectFile *        m_objfile;
121     collection          m_symbols;
122     FileRangeToIndexMap m_file_addr_to_index;
123     UniqueCStringMap<uint32_t> m_name_to_index;
124     UniqueCStringMap<uint32_t> m_basename_to_index;
125     UniqueCStringMap<uint32_t> m_method_to_index;
126     UniqueCStringMap<uint32_t> m_selector_to_index;
127     mutable Mutex       m_mutex; // Provide thread safety for this symbol table
128     bool                m_file_addr_to_index_computed:1,
129                         m_name_indexes_computed:1;
130 private:
131
132     bool
133     CheckSymbolAtIndex (size_t idx, Debug symbol_debug_type, Visibility symbol_visibility) const
134     {
135         switch (symbol_debug_type)
136         {
137         case eDebugNo:
138             if (m_symbols[idx].IsDebug() == true)
139                 return false;
140             break;
141             
142         case eDebugYes:
143             if (m_symbols[idx].IsDebug() == false)
144                 return false;
145             break;
146
147         case eDebugAny: 
148             break;
149         }
150         
151         switch (symbol_visibility)
152         {
153         case eVisibilityAny:
154             return true;
155
156         case eVisibilityExtern:
157             return m_symbols[idx].IsExternal();
158         
159         case eVisibilityPrivate:
160             return !m_symbols[idx].IsExternal();
161         }
162         return false;
163     }
164
165     void
166     SymbolIndicesToSymbolContextList (std::vector<uint32_t> &symbol_indexes,
167                                       SymbolContextList &sc_list);
168
169     DISALLOW_COPY_AND_ASSIGN (Symtab);
170 };
171
172 } // namespace lldb_private
173
174 #endif  // liblldb_Symtab_h_