Symtab.h revision 0c496cd73b30842b49dcc26975fb50c0c77ad34f
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/UniqueCStringMap.h" 18#include "lldb/Host/Mutex.h" 19#include "lldb/Symbol/Symbol.h" 20 21namespace lldb_private { 22 23class Symtab 24{ 25public: 26 typedef enum Debug { 27 eDebugNo, // Not a debug symbol 28 eDebugYes, // A debug symbol 29 eDebugAny 30 } Debug; 31 32 typedef enum Visibility { 33 eVisibilityAny, 34 eVisibilityExtern, 35 eVisibilityPrivate 36 } Visibility; 37 38 Symtab(ObjectFile *objfile); 39 ~Symtab(); 40 41 void Reserve (uint32_t count); 42 Symbol * Resize (uint32_t count); 43 uint32_t AddSymbol(const Symbol& symbol); 44 size_t GetNumSymbols() const; 45 void Dump(Stream *s, Target *target, SortOrder sort_type); 46 void Dump(Stream *s, Target *target, std::vector<uint32_t>& indexes) const; 47 uint32_t GetIndexForSymbol (const Symbol *symbol) const; 48 Mutex & GetMutex () 49 { 50 return m_mutex; 51 } 52 Symbol * FindSymbolByID (lldb::user_id_t uid) const; 53 Symbol * SymbolAtIndex (uint32_t idx); 54 const Symbol * SymbolAtIndex (uint32_t idx) const; 55 Symbol * FindSymbolWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx); 56// const Symbol * FindSymbolWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx) const; 57 uint32_t AppendSymbolIndexesWithType (lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const; 58 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; 59 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; 60 uint32_t AppendSymbolIndexesWithName (const ConstString& symbol_name, std::vector<uint32_t>& matches); 61 uint32_t AppendSymbolIndexesWithName (const ConstString& symbol_name, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches); 62 uint32_t AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, std::vector<uint32_t>& matches); 63 uint32_t AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches); 64 uint32_t AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes); 65 uint32_t AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes); 66 size_t FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes); 67 size_t FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); 68 size_t FindAllSymbolsMatchingRexExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); 69 Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility); 70 Symbol * FindSymbolWithFileAddress (lldb::addr_t file_addr); 71// Symbol * FindSymbolContainingAddress (const Address& value, const uint32_t* indexes, uint32_t num_indexes); 72// Symbol * FindSymbolContainingAddress (const Address& value); 73 Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr, const uint32_t* indexes, uint32_t num_indexes); 74 Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr); 75 size_t CalculateSymbolSize (Symbol *symbol); 76 77 void SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_duplicates) const; 78 79 static void DumpSymbolHeader (Stream *s); 80 81 82 void Finalize () 83 { 84 // Shrink to fit the symbols so we don't waste memory 85 if (m_symbols.capacity() > m_symbols.size()) 86 { 87 collection new_symbols (m_symbols.begin(), m_symbols.end()); 88 m_symbols.swap (new_symbols); 89 } 90 } 91protected: 92 typedef std::vector<Symbol> collection; 93 typedef collection::iterator iterator; 94 typedef collection::const_iterator const_iterator; 95 96 void InitNameIndexes (); 97 void InitAddressIndexes (); 98 99 ObjectFile * m_objfile; 100 collection m_symbols; 101 std::vector<uint32_t> m_addr_indexes; 102 UniqueCStringMap<uint32_t> m_name_to_index; 103 mutable Mutex m_mutex; // Provide thread safety for this symbol table 104 bool m_addr_indexes_computed:1, 105 m_name_indexes_computed:1; 106private: 107 108 bool 109 CheckSymbolAtIndex (uint32_t idx, Debug symbol_debug_type, Visibility symbol_visibility) const 110 { 111 switch (symbol_debug_type) 112 { 113 case eDebugNo: 114 if (m_symbols[idx].IsDebug() == true) 115 return false; 116 break; 117 118 case eDebugYes: 119 if (m_symbols[idx].IsDebug() == false) 120 return false; 121 break; 122 123 case eDebugAny: 124 break; 125 } 126 127 switch (symbol_visibility) 128 { 129 case eVisibilityAny: 130 return true; 131 132 case eVisibilityExtern: 133 return m_symbols[idx].IsExternal(); 134 135 case eVisibilityPrivate: 136 return !m_symbols[idx].IsExternal(); 137 } 138 return false; 139 } 140 141 142 DISALLOW_COPY_AND_ASSIGN (Symtab); 143}; 144 145} // namespace lldb_private 146 147#endif // liblldb_Symtab_h_ 148