Symtab.h revision 254721
131921Sbrian//===-- Symtab.h ------------------------------------------------*- C++ -*-===// 231921Sbrian// 331921Sbrian// The LLVM Compiler Infrastructure 431921Sbrian// 531921Sbrian// This file is distributed under the University of Illinois Open Source 631921Sbrian// License. See LICENSE.TXT for details. 731921Sbrian// 831921Sbrian//===----------------------------------------------------------------------===// 931921Sbrian 1031921Sbrian 1131921Sbrian#ifndef liblldb_Symtab_h_ 1231921Sbrian#define liblldb_Symtab_h_ 1331921Sbrian 1431921Sbrian#include <vector> 1531921Sbrian 1631921Sbrian#include "lldb/lldb-private.h" 1731921Sbrian#include "lldb/Core/RangeMap.h" 1831921Sbrian#include "lldb/Core/UniqueCStringMap.h" 1931921Sbrian#include "lldb/Host/Mutex.h" 2031921Sbrian#include "lldb/Symbol/Symbol.h" 2131921Sbrian 2231921Sbriannamespace lldb_private { 2331921Sbrian 2431921Sbrianclass Symtab 2531921Sbrian{ 2634539Sbrianpublic: 2730715Sbrian typedef std::vector<uint32_t> IndexCollection; 2830715Sbrian typedef UniqueCStringMap<uint32_t> NameToIndexMap; 2931196Sbrian 3031196Sbrian typedef enum Debug { 3131196Sbrian eDebugNo, // Not a debug symbol 3231196Sbrian eDebugYes, // A debug symbol 3331196Sbrian eDebugAny 3430715Sbrian } Debug; 3531121Sbrian 3634539Sbrian typedef enum Visibility { 3731196Sbrian eVisibilityAny, 3830715Sbrian eVisibilityExtern, 3930715Sbrian eVisibilityPrivate 4031343Sbrian } Visibility; 4131196Sbrian 4231196Sbrian Symtab(ObjectFile *objfile); 4331196Sbrian ~Symtab(); 4431196Sbrian 4530715Sbrian void Reserve (size_t count); 4630715Sbrian Symbol * Resize (size_t count); 4730715Sbrian uint32_t AddSymbol(const Symbol& symbol); 4830715Sbrian size_t GetNumSymbols() const; 4930715Sbrian void Dump(Stream *s, Target *target, SortOrder sort_type); 5030715Sbrian void Dump(Stream *s, Target *target, std::vector<uint32_t>& indexes) const; 5130715Sbrian uint32_t GetIndexForSymbol (const Symbol *symbol) const; 5230715Sbrian Mutex & GetMutex () 5331121Sbrian { 5431121Sbrian return m_mutex; 5530715Sbrian } 5631121Sbrian Symbol * FindSymbolByID (lldb::user_id_t uid) const; 5731121Sbrian Symbol * SymbolAtIndex (size_t idx); 5831121Sbrian const Symbol * SymbolAtIndex (size_t idx) const; 5931962Sbrian Symbol * FindSymbolWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx); 6031121Sbrian uint32_t AppendSymbolIndexesWithType (lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const; 6131121Sbrian 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; 6231121Sbrian 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; 6331121Sbrian uint32_t AppendSymbolIndexesWithName (const ConstString& symbol_name, std::vector<uint32_t>& matches); 6431121Sbrian uint32_t AppendSymbolIndexesWithName (const ConstString& symbol_name, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches); 6531121Sbrian uint32_t AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, std::vector<uint32_t>& matches); 6631121Sbrian uint32_t AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& matches); 6731121Sbrian uint32_t AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, std::vector<uint32_t>& indexes); 6831121Sbrian uint32_t AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes); 6931121Sbrian size_t FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes); 7031121Sbrian size_t FindAllSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); 7130715Sbrian size_t FindAllSymbolsMatchingRexExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes); 7230715Sbrian Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility); 7334539Sbrian Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr, const uint32_t* indexes, uint32_t num_indexes); 7430715Sbrian Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr); 7530715Sbrian size_t FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list); 7630715Sbrian void CalculateSymbolSizes (); 7730715Sbrian 7830715Sbrian void SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_duplicates) const; 7930715Sbrian 8031343Sbrian static void DumpSymbolHeader (Stream *s); 8131343Sbrian 8231343Sbrian 8330715Sbrian void Finalize () 8431196Sbrian { 8531196Sbrian // Shrink to fit the symbols so we don't waste memory 8631196Sbrian if (m_symbols.capacity() > m_symbols.size()) 8731196Sbrian { 8831196Sbrian collection new_symbols (m_symbols.begin(), m_symbols.end()); 8931196Sbrian m_symbols.swap (new_symbols); 9031196Sbrian } 9131962Sbrian } 9232125Sbrian 9331196Sbrian void AppendSymbolNamesToMap (const IndexCollection &indexes, 9431196Sbrian bool add_demangled, 9531196Sbrian bool add_mangled, 9631196Sbrian NameToIndexMap &name_to_index_map) const; 9731196Sbrian 9831196Sbrianprotected: 9931196Sbrian typedef std::vector<Symbol> collection; 10031196Sbrian typedef collection::iterator iterator; 10131203Sbrian typedef collection::const_iterator const_iterator; 10231203Sbrian typedef RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t> FileRangeToIndexMap; 10332021Sbrian void InitNameIndexes (); 10431203Sbrian void InitAddressIndexes (); 10531203Sbrian 10631203Sbrian ObjectFile * m_objfile; 10731203Sbrian collection m_symbols; 10831203Sbrian FileRangeToIndexMap m_file_addr_to_index; 10931203Sbrian UniqueCStringMap<uint32_t> m_name_to_index; 11031203Sbrian UniqueCStringMap<uint32_t> m_basename_to_index; 11131203Sbrian UniqueCStringMap<uint32_t> m_method_to_index; 11231203Sbrian UniqueCStringMap<uint32_t> m_selector_to_index; 11331203Sbrian mutable Mutex m_mutex; // Provide thread safety for this symbol table 11432021Sbrian bool m_file_addr_to_index_computed:1, 11532021Sbrian m_name_indexes_computed:1; 11631203Sbrianprivate: 11731203Sbrian 118 bool 119 CheckSymbolAtIndex (size_t idx, Debug symbol_debug_type, Visibility symbol_visibility) const 120 { 121 switch (symbol_debug_type) 122 { 123 case eDebugNo: 124 if (m_symbols[idx].IsDebug() == true) 125 return false; 126 break; 127 128 case eDebugYes: 129 if (m_symbols[idx].IsDebug() == false) 130 return false; 131 break; 132 133 case eDebugAny: 134 break; 135 } 136 137 switch (symbol_visibility) 138 { 139 case eVisibilityAny: 140 return true; 141 142 case eVisibilityExtern: 143 return m_symbols[idx].IsExternal(); 144 145 case eVisibilityPrivate: 146 return !m_symbols[idx].IsExternal(); 147 } 148 return false; 149 } 150 151 void 152 SymbolIndicesToSymbolContextList (std::vector<uint32_t> &symbol_indexes, 153 SymbolContextList &sc_list); 154 155 DISALLOW_COPY_AND_ASSIGN (Symtab); 156}; 157 158} // namespace lldb_private 159 160#endif // liblldb_Symtab_h_ 161