diff options
Diffstat (limited to 'lldb/source/Plugins/SymbolFile/Symtab')
-rw-r--r-- | lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp | 445 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h | 142 |
2 files changed, 255 insertions, 332 deletions
diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp index 24175079c95..39073991c32 100644 --- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp +++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp @@ -24,312 +24,251 @@ using namespace lldb; using namespace lldb_private; -void -SymbolFileSymtab::Initialize() -{ - PluginManager::RegisterPlugin (GetPluginNameStatic(), - GetPluginDescriptionStatic(), - CreateInstance); +void SymbolFileSymtab::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), + GetPluginDescriptionStatic(), CreateInstance); } -void -SymbolFileSymtab::Terminate() -{ - PluginManager::UnregisterPlugin (CreateInstance); +void SymbolFileSymtab::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); } - -lldb_private::ConstString -SymbolFileSymtab::GetPluginNameStatic() -{ - static ConstString g_name("symtab"); - return g_name; +lldb_private::ConstString SymbolFileSymtab::GetPluginNameStatic() { + static ConstString g_name("symtab"); + return g_name; } -const char * -SymbolFileSymtab::GetPluginDescriptionStatic() -{ - return "Reads debug symbols from an object file's symbol table."; +const char *SymbolFileSymtab::GetPluginDescriptionStatic() { + return "Reads debug symbols from an object file's symbol table."; } - -SymbolFile* -SymbolFileSymtab::CreateInstance (ObjectFile* obj_file) -{ - return new SymbolFileSymtab(obj_file); +SymbolFile *SymbolFileSymtab::CreateInstance(ObjectFile *obj_file) { + return new SymbolFileSymtab(obj_file); } -size_t -SymbolFileSymtab::GetTypes (SymbolContextScope *sc_scope, uint32_t type_mask, lldb_private::TypeList &type_list) -{ - return 0; +size_t SymbolFileSymtab::GetTypes(SymbolContextScope *sc_scope, + uint32_t type_mask, + lldb_private::TypeList &type_list) { + return 0; } -SymbolFileSymtab::SymbolFileSymtab(ObjectFile* obj_file) : - SymbolFile(obj_file), - m_source_indexes(), - m_func_indexes(), - m_code_indexes(), - m_objc_class_name_to_index () -{ -} +SymbolFileSymtab::SymbolFileSymtab(ObjectFile *obj_file) + : SymbolFile(obj_file), m_source_indexes(), m_func_indexes(), + m_code_indexes(), m_objc_class_name_to_index() {} -SymbolFileSymtab::~SymbolFileSymtab() -{ -} - -uint32_t -SymbolFileSymtab::CalculateAbilities () -{ - uint32_t abilities = 0; - if (m_obj_file) - { - const Symtab *symtab = m_obj_file->GetSymtab(); - if (symtab) - { - //---------------------------------------------------------------------- - // The snippet of code below will get the indexes the module symbol - // table entries that are code, data, or function related (debug info), - // sort them by value (address) and dump the sorted symbols. - //---------------------------------------------------------------------- - if (symtab->AppendSymbolIndexesWithType(eSymbolTypeSourceFile, m_source_indexes)) - { - abilities |= CompileUnits; - } - - if (symtab->AppendSymbolIndexesWithType(eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes)) - { - symtab->SortSymbolIndexesByValue(m_func_indexes, true); - abilities |= Functions; - } +SymbolFileSymtab::~SymbolFileSymtab() {} - if (symtab->AppendSymbolIndexesWithType(eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny, m_code_indexes)) - { - symtab->SortSymbolIndexesByValue(m_code_indexes, true); - abilities |= Functions; - } - - if (symtab->AppendSymbolIndexesWithType(eSymbolTypeData, m_data_indexes)) - { - symtab->SortSymbolIndexesByValue(m_data_indexes, true); - abilities |= GlobalVariables; - } - - lldb_private::Symtab::IndexCollection objc_class_indexes; - if (symtab->AppendSymbolIndexesWithType (eSymbolTypeObjCClass, objc_class_indexes)) - { - symtab->AppendSymbolNamesToMap (objc_class_indexes, - true, - true, - m_objc_class_name_to_index); - m_objc_class_name_to_index.Sort(); - } - } +uint32_t SymbolFileSymtab::CalculateAbilities() { + uint32_t abilities = 0; + if (m_obj_file) { + const Symtab *symtab = m_obj_file->GetSymtab(); + if (symtab) { + //---------------------------------------------------------------------- + // The snippet of code below will get the indexes the module symbol + // table entries that are code, data, or function related (debug info), + // sort them by value (address) and dump the sorted symbols. + //---------------------------------------------------------------------- + if (symtab->AppendSymbolIndexesWithType(eSymbolTypeSourceFile, + m_source_indexes)) { + abilities |= CompileUnits; + } + + if (symtab->AppendSymbolIndexesWithType( + eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, + m_func_indexes)) { + symtab->SortSymbolIndexesByValue(m_func_indexes, true); + abilities |= Functions; + } + + if (symtab->AppendSymbolIndexesWithType(eSymbolTypeCode, Symtab::eDebugNo, + Symtab::eVisibilityAny, + m_code_indexes)) { + symtab->SortSymbolIndexesByValue(m_code_indexes, true); + abilities |= Functions; + } + + if (symtab->AppendSymbolIndexesWithType(eSymbolTypeData, + m_data_indexes)) { + symtab->SortSymbolIndexesByValue(m_data_indexes, true); + abilities |= GlobalVariables; + } + + lldb_private::Symtab::IndexCollection objc_class_indexes; + if (symtab->AppendSymbolIndexesWithType(eSymbolTypeObjCClass, + objc_class_indexes)) { + symtab->AppendSymbolNamesToMap(objc_class_indexes, true, true, + m_objc_class_name_to_index); + m_objc_class_name_to_index.Sort(); + } } - return abilities; + } + return abilities; } -uint32_t -SymbolFileSymtab::GetNumCompileUnits() -{ - // If we don't have any source file symbols we will just have one compile unit for - // the entire object file - if (m_source_indexes.empty()) - return 0; - - // If we have any source file symbols we will logically organize the object symbols - // using these. - return m_source_indexes.size(); +uint32_t SymbolFileSymtab::GetNumCompileUnits() { + // If we don't have any source file symbols we will just have one compile unit + // for + // the entire object file + if (m_source_indexes.empty()) + return 0; + + // If we have any source file symbols we will logically organize the object + // symbols + // using these. + return m_source_indexes.size(); } -CompUnitSP -SymbolFileSymtab::ParseCompileUnitAtIndex(uint32_t idx) -{ - CompUnitSP cu_sp; - - // If we don't have any source file symbols we will just have one compile unit for - // the entire object file - if (idx < m_source_indexes.size()) - { - const Symbol *cu_symbol = m_obj_file->GetSymtab()->SymbolAtIndex(m_source_indexes[idx]); - if (cu_symbol) - cu_sp.reset(new CompileUnit(m_obj_file->GetModule(), NULL, cu_symbol->GetName().AsCString(), 0, - eLanguageTypeUnknown, eLazyBoolNo)); - } - return cu_sp; +CompUnitSP SymbolFileSymtab::ParseCompileUnitAtIndex(uint32_t idx) { + CompUnitSP cu_sp; + + // If we don't have any source file symbols we will just have one compile unit + // for + // the entire object file + if (idx < m_source_indexes.size()) { + const Symbol *cu_symbol = + m_obj_file->GetSymtab()->SymbolAtIndex(m_source_indexes[idx]); + if (cu_symbol) + cu_sp.reset(new CompileUnit(m_obj_file->GetModule(), NULL, + cu_symbol->GetName().AsCString(), 0, + eLanguageTypeUnknown, eLazyBoolNo)); + } + return cu_sp; } lldb::LanguageType -SymbolFileSymtab::ParseCompileUnitLanguage (const SymbolContext& sc) -{ - return eLanguageTypeUnknown; +SymbolFileSymtab::ParseCompileUnitLanguage(const SymbolContext &sc) { + return eLanguageTypeUnknown; } +size_t SymbolFileSymtab::ParseCompileUnitFunctions(const SymbolContext &sc) { + size_t num_added = 0; + // We must at least have a valid compile unit + assert(sc.comp_unit != NULL); + const Symtab *symtab = m_obj_file->GetSymtab(); + const Symbol *curr_symbol = NULL; + const Symbol *next_symbol = NULL; + // const char *prefix = m_obj_file->SymbolPrefix(); + // if (prefix == NULL) + // prefix == ""; + // + // const uint32_t prefix_len = strlen(prefix); + + // If we don't have any source file symbols we will just have one compile unit + // for + // the entire object file + if (m_source_indexes.empty()) { + // The only time we will have a user ID of zero is when we don't have + // and source file symbols and we declare one compile unit for the + // entire object file + if (!m_func_indexes.empty()) { + } -size_t -SymbolFileSymtab::ParseCompileUnitFunctions (const SymbolContext &sc) -{ - size_t num_added = 0; - // We must at least have a valid compile unit - assert (sc.comp_unit != NULL); - const Symtab *symtab = m_obj_file->GetSymtab(); - const Symbol *curr_symbol = NULL; - const Symbol *next_symbol = NULL; -// const char *prefix = m_obj_file->SymbolPrefix(); -// if (prefix == NULL) -// prefix == ""; -// -// const uint32_t prefix_len = strlen(prefix); - - // If we don't have any source file symbols we will just have one compile unit for - // the entire object file - if (m_source_indexes.empty()) - { - // The only time we will have a user ID of zero is when we don't have - // and source file symbols and we declare one compile unit for the - // entire object file - if (!m_func_indexes.empty()) - { - - } - - if (!m_code_indexes.empty()) - { -// StreamFile s(stdout); -// symtab->Dump(&s, m_code_indexes); - - uint32_t idx = 0; // Index into the indexes - const uint32_t num_indexes = m_code_indexes.size(); - for (idx = 0; idx < num_indexes; ++idx) - { - uint32_t symbol_idx = m_code_indexes[idx]; - curr_symbol = symtab->SymbolAtIndex(symbol_idx); - if (curr_symbol) - { - // Union of all ranges in the function DIE (if the function is discontiguous) - AddressRange func_range(curr_symbol->GetAddress(), 0); - if (func_range.GetBaseAddress().IsSectionOffset()) - { - uint32_t symbol_size = curr_symbol->GetByteSize(); - if (symbol_size != 0 && !curr_symbol->GetSizeIsSibling()) - func_range.SetByteSize(symbol_size); - else if (idx + 1 < num_indexes) - { - next_symbol = symtab->SymbolAtIndex(m_code_indexes[idx + 1]); - if (next_symbol) - { - func_range.SetByteSize(next_symbol->GetAddressRef().GetOffset() - curr_symbol->GetAddressRef().GetOffset()); - } - } - - FunctionSP func_sp(new Function(sc.comp_unit, - symbol_idx, // UserID is the DIE offset - LLDB_INVALID_UID, // We don't have any type info for this function - curr_symbol->GetMangled(), // Linker/mangled name - NULL, // no return type for a code symbol... - func_range)); // first address range - - if (func_sp.get() != NULL) - { - sc.comp_unit->AddFunction(func_sp); - ++num_added; - } - } - } + if (!m_code_indexes.empty()) { + // StreamFile s(stdout); + // symtab->Dump(&s, m_code_indexes); + + uint32_t idx = 0; // Index into the indexes + const uint32_t num_indexes = m_code_indexes.size(); + for (idx = 0; idx < num_indexes; ++idx) { + uint32_t symbol_idx = m_code_indexes[idx]; + curr_symbol = symtab->SymbolAtIndex(symbol_idx); + if (curr_symbol) { + // Union of all ranges in the function DIE (if the function is + // discontiguous) + AddressRange func_range(curr_symbol->GetAddress(), 0); + if (func_range.GetBaseAddress().IsSectionOffset()) { + uint32_t symbol_size = curr_symbol->GetByteSize(); + if (symbol_size != 0 && !curr_symbol->GetSizeIsSibling()) + func_range.SetByteSize(symbol_size); + else if (idx + 1 < num_indexes) { + next_symbol = symtab->SymbolAtIndex(m_code_indexes[idx + 1]); + if (next_symbol) { + func_range.SetByteSize( + next_symbol->GetAddressRef().GetOffset() - + curr_symbol->GetAddressRef().GetOffset()); + } } + FunctionSP func_sp( + new Function(sc.comp_unit, + symbol_idx, // UserID is the DIE offset + LLDB_INVALID_UID, // We don't have any type info + // for this function + curr_symbol->GetMangled(), // Linker/mangled name + NULL, // no return type for a code symbol... + func_range)); // first address range + + if (func_sp.get() != NULL) { + sc.comp_unit->AddFunction(func_sp); + ++num_added; + } + } } + } } - else - { - // We assume we - } - return num_added; + } else { + // We assume we + } + return num_added; } -bool -SymbolFileSymtab::ParseCompileUnitLineTable (const SymbolContext &sc) -{ - return false; +bool SymbolFileSymtab::ParseCompileUnitLineTable(const SymbolContext &sc) { + return false; } -bool -SymbolFileSymtab::ParseCompileUnitDebugMacros (const SymbolContext &sc) -{ - return false; +bool SymbolFileSymtab::ParseCompileUnitDebugMacros(const SymbolContext &sc) { + return false; } -bool -SymbolFileSymtab::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files) -{ - return false; +bool SymbolFileSymtab::ParseCompileUnitSupportFiles( + const SymbolContext &sc, FileSpecList &support_files) { + return false; } -bool -SymbolFileSymtab::ParseImportedModules (const SymbolContext &sc, std::vector<ConstString> &imported_modules) -{ - return false; +bool SymbolFileSymtab::ParseImportedModules( + const SymbolContext &sc, std::vector<ConstString> &imported_modules) { + return false; } -size_t -SymbolFileSymtab::ParseFunctionBlocks (const SymbolContext &sc) -{ - return 0; +size_t SymbolFileSymtab::ParseFunctionBlocks(const SymbolContext &sc) { + return 0; } +size_t SymbolFileSymtab::ParseTypes(const SymbolContext &sc) { return 0; } -size_t -SymbolFileSymtab::ParseTypes (const SymbolContext &sc) -{ - return 0; +size_t SymbolFileSymtab::ParseVariablesForContext(const SymbolContext &sc) { + return 0; } - -size_t -SymbolFileSymtab::ParseVariablesForContext (const SymbolContext& sc) -{ - return 0; +Type *SymbolFileSymtab::ResolveTypeUID(lldb::user_id_t type_uid) { + return NULL; } -Type* -SymbolFileSymtab::ResolveTypeUID(lldb::user_id_t type_uid) -{ - return NULL; +bool SymbolFileSymtab::CompleteType(lldb_private::CompilerType &compiler_type) { + return false; } -bool -SymbolFileSymtab::CompleteType (lldb_private::CompilerType& compiler_type) -{ - return false; -} +uint32_t SymbolFileSymtab::ResolveSymbolContext(const Address &so_addr, + uint32_t resolve_scope, + SymbolContext &sc) { + if (m_obj_file->GetSymtab() == NULL) + return 0; -uint32_t -SymbolFileSymtab::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) -{ - if (m_obj_file->GetSymtab() == NULL) - return 0; - - uint32_t resolved_flags = 0; - if (resolve_scope & eSymbolContextSymbol) - { - sc.symbol = m_obj_file->GetSymtab()->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); - if (sc.symbol) - resolved_flags |= eSymbolContextSymbol; - } - return resolved_flags; + uint32_t resolved_flags = 0; + if (resolve_scope & eSymbolContextSymbol) { + sc.symbol = m_obj_file->GetSymtab()->FindSymbolContainingFileAddress( + so_addr.GetFileAddress()); + if (sc.symbol) + resolved_flags |= eSymbolContextSymbol; + } + return resolved_flags; } //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ -lldb_private::ConstString -SymbolFileSymtab::GetPluginName() -{ - return GetPluginNameStatic(); +lldb_private::ConstString SymbolFileSymtab::GetPluginName() { + return GetPluginNameStatic(); } -uint32_t -SymbolFileSymtab::GetPluginVersion() -{ - return 1; -} +uint32_t SymbolFileSymtab::GetPluginVersion() { return 1; } diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h index 4648da49cb9..1945af9a337 100644 --- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h +++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h @@ -19,112 +19,96 @@ #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/Symtab.h" -class SymbolFileSymtab : public lldb_private::SymbolFile -{ +class SymbolFileSymtab : public lldb_private::SymbolFile { public: - //------------------------------------------------------------------ - // Constructors and Destructors - //------------------------------------------------------------------ - SymbolFileSymtab(lldb_private::ObjectFile* obj_file); + //------------------------------------------------------------------ + // Constructors and Destructors + //------------------------------------------------------------------ + SymbolFileSymtab(lldb_private::ObjectFile *obj_file); - ~SymbolFileSymtab() override; + ~SymbolFileSymtab() override; - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static void - Initialize(); + //------------------------------------------------------------------ + // Static Functions + //------------------------------------------------------------------ + static void Initialize(); - static void - Terminate(); + static void Terminate(); - static lldb_private::ConstString - GetPluginNameStatic(); + static lldb_private::ConstString GetPluginNameStatic(); - static const char * - GetPluginDescriptionStatic(); + static const char *GetPluginDescriptionStatic(); - static lldb_private::SymbolFile* - CreateInstance (lldb_private::ObjectFile* obj_file); + static lldb_private::SymbolFile * + CreateInstance(lldb_private::ObjectFile *obj_file); - uint32_t - CalculateAbilities() override; + uint32_t CalculateAbilities() override; - //------------------------------------------------------------------ - // Compile Unit function calls - //------------------------------------------------------------------ - uint32_t - GetNumCompileUnits() override; + //------------------------------------------------------------------ + // Compile Unit function calls + //------------------------------------------------------------------ + uint32_t GetNumCompileUnits() override; - lldb::CompUnitSP - ParseCompileUnitAtIndex(uint32_t index) override; + lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; - lldb::LanguageType - ParseCompileUnitLanguage(const lldb_private::SymbolContext& sc) override; + lldb::LanguageType + ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override; - size_t - ParseCompileUnitFunctions(const lldb_private::SymbolContext& sc) override; + size_t + ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override; - bool - ParseCompileUnitLineTable(const lldb_private::SymbolContext& sc) override; + bool + ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override; - bool - ParseCompileUnitDebugMacros(const lldb_private::SymbolContext& sc) override; + bool + ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override; - bool - ParseCompileUnitSupportFiles(const lldb_private::SymbolContext& sc, - lldb_private::FileSpecList &support_files) override; - - bool - ParseImportedModules(const lldb_private::SymbolContext &sc, - std::vector<lldb_private::ConstString> &imported_modules) override; + bool ParseCompileUnitSupportFiles( + const lldb_private::SymbolContext &sc, + lldb_private::FileSpecList &support_files) override; - size_t - ParseFunctionBlocks(const lldb_private::SymbolContext& sc) override; + bool ParseImportedModules( + const lldb_private::SymbolContext &sc, + std::vector<lldb_private::ConstString> &imported_modules) override; - size_t - ParseTypes(const lldb_private::SymbolContext& sc) override; + size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override; - size_t - ParseVariablesForContext(const lldb_private::SymbolContext& sc) override; + size_t ParseTypes(const lldb_private::SymbolContext &sc) override; - lldb_private::Type* - ResolveTypeUID(lldb::user_id_t type_uid) override; + size_t + ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; - bool - CompleteType(lldb_private::CompilerType& compiler_type) override; + lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; - uint32_t - ResolveSymbolContext(const lldb_private::Address& so_addr, - uint32_t resolve_scope, - lldb_private::SymbolContext& sc) override; + bool CompleteType(lldb_private::CompilerType &compiler_type) override; - size_t - GetTypes(lldb_private::SymbolContextScope *sc_scope, - uint32_t type_mask, - lldb_private::TypeList &type_list) override; + uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, + uint32_t resolve_scope, + lldb_private::SymbolContext &sc) override; - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - lldb_private::ConstString - GetPluginName() override; + size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, + uint32_t type_mask, + lldb_private::TypeList &type_list) override; - uint32_t - GetPluginVersion() override; + //------------------------------------------------------------------ + // PluginInterface protocol + //------------------------------------------------------------------ + lldb_private::ConstString GetPluginName() override; + + uint32_t GetPluginVersion() override; protected: - typedef std::map<lldb_private::ConstString, lldb::TypeSP> TypeMap; - - lldb_private::Symtab::IndexCollection m_source_indexes; - lldb_private::Symtab::IndexCollection m_func_indexes; - lldb_private::Symtab::IndexCollection m_code_indexes; - lldb_private::Symtab::IndexCollection m_data_indexes; - lldb_private::Symtab::NameToIndexMap m_objc_class_name_to_index; - TypeMap m_objc_class_types; - + typedef std::map<lldb_private::ConstString, lldb::TypeSP> TypeMap; + + lldb_private::Symtab::IndexCollection m_source_indexes; + lldb_private::Symtab::IndexCollection m_func_indexes; + lldb_private::Symtab::IndexCollection m_code_indexes; + lldb_private::Symtab::IndexCollection m_data_indexes; + lldb_private::Symtab::NameToIndexMap m_objc_class_name_to_index; + TypeMap m_objc_class_types; + private: - DISALLOW_COPY_AND_ASSIGN (SymbolFileSymtab); + DISALLOW_COPY_AND_ASSIGN(SymbolFileSymtab); }; #endif // liblldb_SymbolFileSymtab_h_ |