diff options
Diffstat (limited to 'lldb/source/Plugins/SymbolVendor')
4 files changed, 377 insertions, 434 deletions
diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp index 9b32484be87..4934a80c09e 100644 --- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp +++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp @@ -27,48 +27,33 @@ using namespace lldb_private; //---------------------------------------------------------------------- // SymbolVendorELF constructor //---------------------------------------------------------------------- -SymbolVendorELF::SymbolVendorELF(const lldb::ModuleSP &module_sp) : - SymbolVendor (module_sp) -{ -} +SymbolVendorELF::SymbolVendorELF(const lldb::ModuleSP &module_sp) + : SymbolVendor(module_sp) {} //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -SymbolVendorELF::~SymbolVendorELF() -{ -} +SymbolVendorELF::~SymbolVendorELF() {} -void -SymbolVendorELF::Initialize() -{ - PluginManager::RegisterPlugin (GetPluginNameStatic(), - GetPluginDescriptionStatic(), - CreateInstance); +void SymbolVendorELF::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), + GetPluginDescriptionStatic(), CreateInstance); } -void -SymbolVendorELF::Terminate() -{ - PluginManager::UnregisterPlugin (CreateInstance); +void SymbolVendorELF::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); } - -lldb_private::ConstString -SymbolVendorELF::GetPluginNameStatic() -{ - static ConstString g_name("ELF"); - return g_name; +lldb_private::ConstString SymbolVendorELF::GetPluginNameStatic() { + static ConstString g_name("ELF"); + return g_name; } -const char * -SymbolVendorELF::GetPluginDescriptionStatic() -{ - return "Symbol vendor for ELF that looks for dSYM files that match executables."; +const char *SymbolVendorELF::GetPluginDescriptionStatic() { + return "Symbol vendor for ELF that looks for dSYM files that match " + "executables."; } - - //---------------------------------------------------------------------- // CreateInstance // @@ -76,122 +61,108 @@ SymbolVendorELF::GetPluginDescriptionStatic() // vendors to allow for complex debug information file setups, and to // also allow for finding separate debug information files. //---------------------------------------------------------------------- -SymbolVendor* -SymbolVendorELF::CreateInstance (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm) -{ - if (!module_sp) - return NULL; - - ObjectFile *obj_file = module_sp->GetObjectFile(); - if (!obj_file) - return NULL; - - static ConstString obj_file_elf("elf"); - ConstString obj_name = obj_file->GetPluginName(); - if (obj_name != obj_file_elf) - return NULL; - - lldb_private::UUID uuid; - if (!obj_file->GetUUID (&uuid)) - return NULL; - - // Get the .gnu_debuglink file (if specified). - FileSpecList file_spec_list = obj_file->GetDebugSymbolFilePaths(); - - // If the module specified a filespec, use it first. - FileSpec debug_symbol_fspec (module_sp->GetSymbolFileFileSpec()); - if (debug_symbol_fspec) - file_spec_list.Insert (0, debug_symbol_fspec); - - // If we have no debug symbol files, then nothing to do. - if (file_spec_list.IsEmpty()) - return NULL; - - Timer scoped_timer (LLVM_PRETTY_FUNCTION, - "SymbolVendorELF::CreateInstance (module = %s)", - module_sp->GetFileSpec().GetPath().c_str()); - - for (size_t idx = 0; idx < file_spec_list.GetSize(); ++idx) - { - ModuleSpec module_spec; - const FileSpec fspec = file_spec_list.GetFileSpecAtIndex (idx); - - module_spec.GetFileSpec() = obj_file->GetFileSpec(); - module_spec.GetFileSpec().ResolvePath(); - module_spec.GetSymbolFileSpec() = fspec; - module_spec.GetUUID() = uuid; - FileSpec dsym_fspec = Symbols::LocateExecutableSymbolFile (module_spec); - if (dsym_fspec) - { - DataBufferSP dsym_file_data_sp; - lldb::offset_t dsym_file_data_offset = 0; - ObjectFileSP dsym_objfile_sp = ObjectFile::FindPlugin(module_sp, &dsym_fspec, 0, dsym_fspec.GetByteSize(), dsym_file_data_sp, dsym_file_data_offset); - if (dsym_objfile_sp) - { - // This objfile is for debugging purposes. Sadly, ObjectFileELF won't be able - // to figure this out consistently as the symbol file may not have stripped the - // code sections, etc. - dsym_objfile_sp->SetType (ObjectFile::eTypeDebugInfo); - - SymbolVendorELF* symbol_vendor = new SymbolVendorELF(module_sp); - if (symbol_vendor) - { - // Get the module unified section list and add our debug sections to that. - SectionList *module_section_list = module_sp->GetSectionList(); - SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList(); - - static const SectionType g_sections[] = - { - eSectionTypeDWARFDebugAbbrev, - eSectionTypeDWARFDebugAddr, - eSectionTypeDWARFDebugAranges, - eSectionTypeDWARFDebugFrame, - eSectionTypeDWARFDebugInfo, - eSectionTypeDWARFDebugLine, - eSectionTypeDWARFDebugLoc, - eSectionTypeDWARFDebugMacInfo, - eSectionTypeDWARFDebugPubNames, - eSectionTypeDWARFDebugPubTypes, - eSectionTypeDWARFDebugRanges, - eSectionTypeDWARFDebugStr, - eSectionTypeDWARFDebugStrOffsets, - eSectionTypeELFSymbolTable, - }; - for (size_t idx = 0; idx < sizeof(g_sections) / sizeof(g_sections[0]); ++idx) - { - SectionType section_type = g_sections[idx]; - SectionSP section_sp (objfile_section_list->FindSectionByType (section_type, true)); - if (section_sp) - { - SectionSP module_section_sp (module_section_list->FindSectionByType (section_type, true)); - if (module_section_sp) - module_section_list->ReplaceSection (module_section_sp->GetID(), section_sp); - else - module_section_list->AddSection (section_sp); - } - } - - symbol_vendor->AddSymbolFileRepresentation (dsym_objfile_sp); - return symbol_vendor; - } +SymbolVendor * +SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp, + lldb_private::Stream *feedback_strm) { + if (!module_sp) + return NULL; + + ObjectFile *obj_file = module_sp->GetObjectFile(); + if (!obj_file) + return NULL; + + static ConstString obj_file_elf("elf"); + ConstString obj_name = obj_file->GetPluginName(); + if (obj_name != obj_file_elf) + return NULL; + + lldb_private::UUID uuid; + if (!obj_file->GetUUID(&uuid)) + return NULL; + + // Get the .gnu_debuglink file (if specified). + FileSpecList file_spec_list = obj_file->GetDebugSymbolFilePaths(); + + // If the module specified a filespec, use it first. + FileSpec debug_symbol_fspec(module_sp->GetSymbolFileFileSpec()); + if (debug_symbol_fspec) + file_spec_list.Insert(0, debug_symbol_fspec); + + // If we have no debug symbol files, then nothing to do. + if (file_spec_list.IsEmpty()) + return NULL; + + Timer scoped_timer(LLVM_PRETTY_FUNCTION, + "SymbolVendorELF::CreateInstance (module = %s)", + module_sp->GetFileSpec().GetPath().c_str()); + + for (size_t idx = 0; idx < file_spec_list.GetSize(); ++idx) { + ModuleSpec module_spec; + const FileSpec fspec = file_spec_list.GetFileSpecAtIndex(idx); + + module_spec.GetFileSpec() = obj_file->GetFileSpec(); + module_spec.GetFileSpec().ResolvePath(); + module_spec.GetSymbolFileSpec() = fspec; + module_spec.GetUUID() = uuid; + FileSpec dsym_fspec = Symbols::LocateExecutableSymbolFile(module_spec); + if (dsym_fspec) { + DataBufferSP dsym_file_data_sp; + lldb::offset_t dsym_file_data_offset = 0; + ObjectFileSP dsym_objfile_sp = ObjectFile::FindPlugin( + module_sp, &dsym_fspec, 0, dsym_fspec.GetByteSize(), + dsym_file_data_sp, dsym_file_data_offset); + if (dsym_objfile_sp) { + // This objfile is for debugging purposes. Sadly, ObjectFileELF won't be + // able + // to figure this out consistently as the symbol file may not have + // stripped the + // code sections, etc. + dsym_objfile_sp->SetType(ObjectFile::eTypeDebugInfo); + + SymbolVendorELF *symbol_vendor = new SymbolVendorELF(module_sp); + if (symbol_vendor) { + // Get the module unified section list and add our debug sections to + // that. + SectionList *module_section_list = module_sp->GetSectionList(); + SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList(); + + static const SectionType g_sections[] = { + eSectionTypeDWARFDebugAbbrev, eSectionTypeDWARFDebugAddr, + eSectionTypeDWARFDebugAranges, eSectionTypeDWARFDebugFrame, + eSectionTypeDWARFDebugInfo, eSectionTypeDWARFDebugLine, + eSectionTypeDWARFDebugLoc, eSectionTypeDWARFDebugMacInfo, + eSectionTypeDWARFDebugPubNames, eSectionTypeDWARFDebugPubTypes, + eSectionTypeDWARFDebugRanges, eSectionTypeDWARFDebugStr, + eSectionTypeDWARFDebugStrOffsets, eSectionTypeELFSymbolTable, + }; + for (size_t idx = 0; idx < sizeof(g_sections) / sizeof(g_sections[0]); + ++idx) { + SectionType section_type = g_sections[idx]; + SectionSP section_sp( + objfile_section_list->FindSectionByType(section_type, true)); + if (section_sp) { + SectionSP module_section_sp( + module_section_list->FindSectionByType(section_type, true)); + if (module_section_sp) + module_section_list->ReplaceSection(module_section_sp->GetID(), + section_sp); + else + module_section_list->AddSection(section_sp); } + } + + symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp); + return symbol_vendor; } + } } - return NULL; + } + return NULL; } //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ -ConstString -SymbolVendorELF::GetPluginName() -{ - return GetPluginNameStatic(); -} - -uint32_t -SymbolVendorELF::GetPluginVersion() -{ - return 1; -} +ConstString SymbolVendorELF::GetPluginName() { return GetPluginNameStatic(); } +uint32_t SymbolVendorELF::GetPluginVersion() { return 1; } diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h index 425ff9efc59..e7aeebc96b9 100644 --- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h +++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h @@ -14,48 +14,42 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/lldb-private.h" #include "lldb/Symbol/SymbolVendor.h" +#include "lldb/lldb-private.h" -class SymbolVendorELF : public lldb_private::SymbolVendor -{ +class SymbolVendorELF : public lldb_private::SymbolVendor { public: - //------------------------------------------------------------------ - // Constructors and Destructors - //------------------------------------------------------------------ - SymbolVendorELF (const lldb::ModuleSP &module_sp); + //------------------------------------------------------------------ + // Constructors and Destructors + //------------------------------------------------------------------ + SymbolVendorELF(const lldb::ModuleSP &module_sp); - ~SymbolVendorELF() override; + ~SymbolVendorELF() 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::SymbolVendor* - CreateInstance (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm); + static lldb_private::SymbolVendor * + CreateInstance(const lldb::ModuleSP &module_sp, + lldb_private::Stream *feedback_strm); - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - lldb_private::ConstString - GetPluginName() override; + //------------------------------------------------------------------ + // PluginInterface protocol + //------------------------------------------------------------------ + lldb_private::ConstString GetPluginName() override; - uint32_t - GetPluginVersion() override; + uint32_t GetPluginVersion() override; private: - DISALLOW_COPY_AND_ASSIGN (SymbolVendorELF); + DISALLOW_COPY_AND_ASSIGN(SymbolVendorELF); }; #endif // liblldb_SymbolVendorELF_h_ diff --git a/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp b/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp index 94a37f8d2dd..4309d32af64 100644 --- a/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp +++ b/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp @@ -28,88 +28,69 @@ using namespace lldb_private; //---------------------------------------------------------------------- // SymbolVendorMacOSX constructor //---------------------------------------------------------------------- -SymbolVendorMacOSX::SymbolVendorMacOSX(const lldb::ModuleSP &module_sp) : - SymbolVendor (module_sp) -{ -} +SymbolVendorMacOSX::SymbolVendorMacOSX(const lldb::ModuleSP &module_sp) + : SymbolVendor(module_sp) {} //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -SymbolVendorMacOSX::~SymbolVendorMacOSX() -{ -} - - -static bool -UUIDsMatch(Module *module, ObjectFile *ofile, lldb_private::Stream *feedback_strm) -{ - if (module && ofile) - { - // Make sure the UUIDs match - lldb_private::UUID dsym_uuid; - - if (!ofile->GetUUID(&dsym_uuid)) - { - if (feedback_strm) - { - feedback_strm->PutCString("warning: failed to get the uuid for object file: '"); - ofile->GetFileSpec().Dump(feedback_strm); - feedback_strm->PutCString("\n"); - } - return false; - } +SymbolVendorMacOSX::~SymbolVendorMacOSX() {} + +static bool UUIDsMatch(Module *module, ObjectFile *ofile, + lldb_private::Stream *feedback_strm) { + if (module && ofile) { + // Make sure the UUIDs match + lldb_private::UUID dsym_uuid; + + if (!ofile->GetUUID(&dsym_uuid)) { + if (feedback_strm) { + feedback_strm->PutCString( + "warning: failed to get the uuid for object file: '"); + ofile->GetFileSpec().Dump(feedback_strm); + feedback_strm->PutCString("\n"); + } + return false; + } - if (dsym_uuid == module->GetUUID()) - return true; - - // Emit some warning messages since the UUIDs do not match! - if (feedback_strm) - { - feedback_strm->PutCString("warning: UUID mismatch detected between modules:\n "); - module->GetUUID().Dump(feedback_strm); - feedback_strm->PutChar(' '); - module->GetFileSpec().Dump(feedback_strm); - feedback_strm->PutCString("\n "); - dsym_uuid.Dump(feedback_strm); - feedback_strm->PutChar(' '); - ofile->GetFileSpec().Dump(feedback_strm); - feedback_strm->EOL(); - } + if (dsym_uuid == module->GetUUID()) + return true; + + // Emit some warning messages since the UUIDs do not match! + if (feedback_strm) { + feedback_strm->PutCString( + "warning: UUID mismatch detected between modules:\n "); + module->GetUUID().Dump(feedback_strm); + feedback_strm->PutChar(' '); + module->GetFileSpec().Dump(feedback_strm); + feedback_strm->PutCString("\n "); + dsym_uuid.Dump(feedback_strm); + feedback_strm->PutChar(' '); + ofile->GetFileSpec().Dump(feedback_strm); + feedback_strm->EOL(); } - return false; + } + return false; } -void -SymbolVendorMacOSX::Initialize() -{ - PluginManager::RegisterPlugin (GetPluginNameStatic(), - GetPluginDescriptionStatic(), - CreateInstance); +void SymbolVendorMacOSX::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), + GetPluginDescriptionStatic(), CreateInstance); } -void -SymbolVendorMacOSX::Terminate() -{ - PluginManager::UnregisterPlugin (CreateInstance); +void SymbolVendorMacOSX::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); } - -lldb_private::ConstString -SymbolVendorMacOSX::GetPluginNameStatic() -{ - static ConstString g_name("macosx"); - return g_name; +lldb_private::ConstString SymbolVendorMacOSX::GetPluginNameStatic() { + static ConstString g_name("macosx"); + return g_name; } -const char * -SymbolVendorMacOSX::GetPluginDescriptionStatic() -{ - return "Symbol vendor for MacOSX that looks for dSYM files that match executables."; +const char *SymbolVendorMacOSX::GetPluginDescriptionStatic() { + return "Symbol vendor for MacOSX that looks for dSYM files that match " + "executables."; } - - //---------------------------------------------------------------------- // CreateInstance // @@ -117,186 +98,190 @@ SymbolVendorMacOSX::GetPluginDescriptionStatic() // vendors to allow for complex debug information file setups, and to // also allow for finding separate debug information files. //---------------------------------------------------------------------- -SymbolVendor* -SymbolVendorMacOSX::CreateInstance (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm) -{ - if (!module_sp) - return NULL; - - ObjectFile * obj_file = module_sp->GetObjectFile(); - if (!obj_file) - return NULL; - - static ConstString obj_file_macho("mach-o"); - ConstString obj_name = obj_file->GetPluginName(); - if (obj_name != obj_file_macho) - return NULL; - - Timer scoped_timer (LLVM_PRETTY_FUNCTION, - "SymbolVendorMacOSX::CreateInstance (module = %s)", - module_sp->GetFileSpec().GetPath().c_str()); - SymbolVendorMacOSX* symbol_vendor = new SymbolVendorMacOSX(module_sp); - if (symbol_vendor) - { - char path[PATH_MAX]; - path[0] = '\0'; - - // Try and locate the dSYM file on Mac OS X - Timer scoped_timer2 ("SymbolVendorMacOSX::CreateInstance () locate dSYM", - "SymbolVendorMacOSX::CreateInstance (module = %s) locate dSYM", - module_sp->GetFileSpec().GetPath().c_str()); - - // First check to see if the module has a symbol file in mind already. - // If it does, then we MUST use that. - FileSpec dsym_fspec (module_sp->GetSymbolFileFileSpec()); - - ObjectFileSP dsym_objfile_sp; - if (!dsym_fspec) - { - // No symbol file was specified in the module, lets try and find - // one ourselves. - FileSpec file_spec = obj_file->GetFileSpec(); - if (!file_spec) - file_spec = module_sp->GetFileSpec(); - - ModuleSpec module_spec(file_spec, module_sp->GetArchitecture()); - module_spec.GetUUID() = module_sp->GetUUID(); - dsym_fspec = Symbols::LocateExecutableSymbolFile (module_spec); - if (module_spec.GetSourceMappingList().GetSize()) - module_sp->GetSourceMappingList().Append (module_spec.GetSourceMappingList (), true); - } - - if (dsym_fspec) - { - DataBufferSP dsym_file_data_sp; - lldb::offset_t dsym_file_data_offset = 0; - dsym_objfile_sp = ObjectFile::FindPlugin(module_sp, &dsym_fspec, 0, dsym_fspec.GetByteSize(), dsym_file_data_sp, dsym_file_data_offset); - if (UUIDsMatch(module_sp.get(), dsym_objfile_sp.get(), feedback_strm)) - { - // We need a XML parser if we hope to parse a plist... - if (XMLDocument::XMLEnabled()) - { - char dsym_path[PATH_MAX]; - if (module_sp->GetSourceMappingList().IsEmpty() && dsym_fspec.GetPath(dsym_path, sizeof(dsym_path))) - { - lldb_private::UUID dsym_uuid; - if (dsym_objfile_sp->GetUUID(&dsym_uuid)) - { - std::string uuid_str = dsym_uuid.GetAsString (); - if (!uuid_str.empty()) - { - char *resources = strstr (dsym_path, "/Contents/Resources/"); - if (resources) - { - char dsym_uuid_plist_path[PATH_MAX]; - resources[strlen("/Contents/Resources/")] = '\0'; - snprintf(dsym_uuid_plist_path, sizeof(dsym_uuid_plist_path), "%s%s.plist", dsym_path, uuid_str.c_str()); - FileSpec dsym_uuid_plist_spec(dsym_uuid_plist_path, false); - if (dsym_uuid_plist_spec.Exists()) - { - ApplePropertyList plist(dsym_uuid_plist_path); - if (plist) - { - std::string DBGBuildSourcePath; - std::string DBGSourcePath; - - plist.GetValueAsString("DBGBuildSourcePath", DBGBuildSourcePath); - plist.GetValueAsString("DBGSourcePath", DBGSourcePath); - if (!DBGBuildSourcePath.empty() && !DBGSourcePath.empty()) - { - if (DBGSourcePath[0] == '~') - { - FileSpec resolved_source_path(DBGSourcePath.c_str(), true); - DBGSourcePath = resolved_source_path.GetPath(); - } - module_sp->GetSourceMappingList().Append (ConstString(DBGBuildSourcePath), ConstString(DBGSourcePath), true); - } - - // DBGSourcePathRemapping is a dictionary in the plist with - // keys which are DBGBuildSourcePath file paths and - // values which are DBGSourcePath file paths - - StructuredData::ObjectSP plist_sp = plist.GetStructuredData(); - if (plist_sp.get() - && plist_sp->GetAsDictionary() - && plist_sp->GetAsDictionary()->HasKey("DBGSourcePathRemapping") - && plist_sp->GetAsDictionary()->GetValueForKey("DBGSourcePathRemapping")->GetAsDictionary()) - { - - // In an early version of DBGSourcePathRemapping, the DBGSourcePath - // values were incorrect. If we have a newer style - // DBGSourcePathRemapping, there will be a DBGVersion key in the plist - // (we don't care about the value at this point). - // - // If this is an old style DBGSourcePathRemapping, ignore the - // value half of the key-value remappings and use reuse the original - // gloal DBGSourcePath string. - bool new_style_source_remapping_dictionary = false; - std::string original_DBGSourcePath_value = DBGSourcePath; - if (plist_sp->GetAsDictionary()->HasKey("DBGVersion")) - { - new_style_source_remapping_dictionary = true; - } - - StructuredData::Dictionary *remappings_dict = plist_sp->GetAsDictionary()->GetValueForKey("DBGSourcePathRemapping")->GetAsDictionary(); - remappings_dict->ForEach ([&module_sp, new_style_source_remapping_dictionary, original_DBGSourcePath_value](ConstString key, StructuredData::Object *object) -> bool - { - if (object && object->GetAsString()) - { - - // key is DBGBuildSourcePath - // object is DBGSourcePath - std::string DBGSourcePath = object->GetStringValue(); - if (new_style_source_remapping_dictionary == false && !original_DBGSourcePath_value.empty()) - { - DBGSourcePath = original_DBGSourcePath_value; - } - if (DBGSourcePath[0] == '~') - { - FileSpec resolved_source_path(DBGSourcePath.c_str(), true); - DBGSourcePath = resolved_source_path.GetPath(); - } - module_sp->GetSourceMappingList().Append (key, ConstString(DBGSourcePath), true); - } - return true; - }); - - } - } - } - } - } +SymbolVendor * +SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp, + lldb_private::Stream *feedback_strm) { + if (!module_sp) + return NULL; + + ObjectFile *obj_file = module_sp->GetObjectFile(); + if (!obj_file) + return NULL; + + static ConstString obj_file_macho("mach-o"); + ConstString obj_name = obj_file->GetPluginName(); + if (obj_name != obj_file_macho) + return NULL; + + Timer scoped_timer(LLVM_PRETTY_FUNCTION, + "SymbolVendorMacOSX::CreateInstance (module = %s)", + module_sp->GetFileSpec().GetPath().c_str()); + SymbolVendorMacOSX *symbol_vendor = new SymbolVendorMacOSX(module_sp); + if (symbol_vendor) { + char path[PATH_MAX]; + path[0] = '\0'; + + // Try and locate the dSYM file on Mac OS X + Timer scoped_timer2( + "SymbolVendorMacOSX::CreateInstance () locate dSYM", + "SymbolVendorMacOSX::CreateInstance (module = %s) locate dSYM", + module_sp->GetFileSpec().GetPath().c_str()); + + // First check to see if the module has a symbol file in mind already. + // If it does, then we MUST use that. + FileSpec dsym_fspec(module_sp->GetSymbolFileFileSpec()); + + ObjectFileSP dsym_objfile_sp; + if (!dsym_fspec) { + // No symbol file was specified in the module, lets try and find + // one ourselves. + FileSpec file_spec = obj_file->GetFileSpec(); + if (!file_spec) + file_spec = module_sp->GetFileSpec(); + + ModuleSpec module_spec(file_spec, module_sp->GetArchitecture()); + module_spec.GetUUID() = module_sp->GetUUID(); + dsym_fspec = Symbols::LocateExecutableSymbolFile(module_spec); + if (module_spec.GetSourceMappingList().GetSize()) + module_sp->GetSourceMappingList().Append( + module_spec.GetSourceMappingList(), true); + } + + if (dsym_fspec) { + DataBufferSP dsym_file_data_sp; + lldb::offset_t dsym_file_data_offset = 0; + dsym_objfile_sp = ObjectFile::FindPlugin( + module_sp, &dsym_fspec, 0, dsym_fspec.GetByteSize(), + dsym_file_data_sp, dsym_file_data_offset); + if (UUIDsMatch(module_sp.get(), dsym_objfile_sp.get(), feedback_strm)) { + // We need a XML parser if we hope to parse a plist... + if (XMLDocument::XMLEnabled()) { + char dsym_path[PATH_MAX]; + if (module_sp->GetSourceMappingList().IsEmpty() && + dsym_fspec.GetPath(dsym_path, sizeof(dsym_path))) { + lldb_private::UUID dsym_uuid; + if (dsym_objfile_sp->GetUUID(&dsym_uuid)) { + std::string uuid_str = dsym_uuid.GetAsString(); + if (!uuid_str.empty()) { + char *resources = strstr(dsym_path, "/Contents/Resources/"); + if (resources) { + char dsym_uuid_plist_path[PATH_MAX]; + resources[strlen("/Contents/Resources/")] = '\0'; + snprintf(dsym_uuid_plist_path, sizeof(dsym_uuid_plist_path), + "%s%s.plist", dsym_path, uuid_str.c_str()); + FileSpec dsym_uuid_plist_spec(dsym_uuid_plist_path, false); + if (dsym_uuid_plist_spec.Exists()) { + ApplePropertyList plist(dsym_uuid_plist_path); + if (plist) { + std::string DBGBuildSourcePath; + std::string DBGSourcePath; + + plist.GetValueAsString("DBGBuildSourcePath", + DBGBuildSourcePath); + plist.GetValueAsString("DBGSourcePath", DBGSourcePath); + if (!DBGBuildSourcePath.empty() && + !DBGSourcePath.empty()) { + if (DBGSourcePath[0] == '~') { + FileSpec resolved_source_path(DBGSourcePath.c_str(), + true); + DBGSourcePath = resolved_source_path.GetPath(); + } + module_sp->GetSourceMappingList().Append( + ConstString(DBGBuildSourcePath), + ConstString(DBGSourcePath), true); + } + + // DBGSourcePathRemapping is a dictionary in the plist + // with + // keys which are DBGBuildSourcePath file paths and + // values which are DBGSourcePath file paths + + StructuredData::ObjectSP plist_sp = + plist.GetStructuredData(); + if (plist_sp.get() && plist_sp->GetAsDictionary() && + plist_sp->GetAsDictionary()->HasKey( + "DBGSourcePathRemapping") && + plist_sp->GetAsDictionary() + ->GetValueForKey("DBGSourcePathRemapping") + ->GetAsDictionary()) { + + // In an early version of DBGSourcePathRemapping, the + // DBGSourcePath + // values were incorrect. If we have a newer style + // DBGSourcePathRemapping, there will be a DBGVersion + // key in the plist + // (we don't care about the value at this point). + // + // If this is an old style DBGSourcePathRemapping, + // ignore the + // value half of the key-value remappings and use reuse + // the original + // gloal DBGSourcePath string. + bool new_style_source_remapping_dictionary = false; + std::string original_DBGSourcePath_value = + DBGSourcePath; + if (plist_sp->GetAsDictionary()->HasKey("DBGVersion")) { + new_style_source_remapping_dictionary = true; } + + StructuredData::Dictionary *remappings_dict = + plist_sp->GetAsDictionary() + ->GetValueForKey("DBGSourcePathRemapping") + ->GetAsDictionary(); + remappings_dict->ForEach( + [&module_sp, new_style_source_remapping_dictionary, + original_DBGSourcePath_value]( + ConstString key, + StructuredData::Object *object) -> bool { + if (object && object->GetAsString()) { + + // key is DBGBuildSourcePath + // object is DBGSourcePath + std::string DBGSourcePath = + object->GetStringValue(); + if (new_style_source_remapping_dictionary == + false && + !original_DBGSourcePath_value.empty()) { + DBGSourcePath = original_DBGSourcePath_value; + } + if (DBGSourcePath[0] == '~') { + FileSpec resolved_source_path( + DBGSourcePath.c_str(), true); + DBGSourcePath = + resolved_source_path.GetPath(); + } + module_sp->GetSourceMappingList().Append( + key, ConstString(DBGSourcePath), true); + } + return true; + }); + } } + } } - - symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp); - return symbol_vendor; + } } + } } - // Just create our symbol vendor using the current objfile as this is either - // an executable with no dSYM (that we could locate), an executable with - // a dSYM that has a UUID that doesn't match. - symbol_vendor->AddSymbolFileRepresentation(obj_file->shared_from_this()); + symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp); + return symbol_vendor; + } } - return symbol_vendor; -} - + // Just create our symbol vendor using the current objfile as this is either + // an executable with no dSYM (that we could locate), an executable with + // a dSYM that has a UUID that doesn't match. + symbol_vendor->AddSymbolFileRepresentation(obj_file->shared_from_this()); + } + return symbol_vendor; +} //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ -ConstString -SymbolVendorMacOSX::GetPluginName() -{ - return GetPluginNameStatic(); -} - -uint32_t -SymbolVendorMacOSX::GetPluginVersion() -{ - return 1; +ConstString SymbolVendorMacOSX::GetPluginName() { + return GetPluginNameStatic(); } +uint32_t SymbolVendorMacOSX::GetPluginVersion() { return 1; } diff --git a/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h b/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h index 31a842ade86..53b5291af03 100644 --- a/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h +++ b/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h @@ -10,49 +10,42 @@ #ifndef liblldb_SymbolVendorMacOSX_h_ #define liblldb_SymbolVendorMacOSX_h_ -#include "lldb/lldb-private.h" #include "lldb/Symbol/SymbolVendor.h" +#include "lldb/lldb-private.h" -class SymbolVendorMacOSX : public lldb_private::SymbolVendor -{ +class SymbolVendorMacOSX : public lldb_private::SymbolVendor { public: - //------------------------------------------------------------------ - // 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::SymbolVendor* - CreateInstance (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm); + static lldb_private::SymbolVendor * + CreateInstance(const lldb::ModuleSP &module_sp, + lldb_private::Stream *feedback_strm); - //------------------------------------------------------------------ - // Constructors and Destructors - //------------------------------------------------------------------ - SymbolVendorMacOSX (const lldb::ModuleSP &module_sp); + //------------------------------------------------------------------ + // Constructors and Destructors + //------------------------------------------------------------------ + SymbolVendorMacOSX(const lldb::ModuleSP &module_sp); - virtual - ~SymbolVendorMacOSX(); + virtual ~SymbolVendorMacOSX(); - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - virtual lldb_private::ConstString - GetPluginName(); + //------------------------------------------------------------------ + // PluginInterface protocol + //------------------------------------------------------------------ + virtual lldb_private::ConstString GetPluginName(); - virtual uint32_t - GetPluginVersion(); + virtual uint32_t GetPluginVersion(); private: - DISALLOW_COPY_AND_ASSIGN (SymbolVendorMacOSX); + DISALLOW_COPY_AND_ASSIGN(SymbolVendorMacOSX); }; -#endif // liblldb_SymbolVendorMacOSX_h_ +#endif // liblldb_SymbolVendorMacOSX_h_ |