Index: lldb/include/lldb/Symbol/ObjectFile.h =================================================================== --- lldb/include/lldb/Symbol/ObjectFile.h +++ lldb/include/lldb/Symbol/ObjectFile.h @@ -578,15 +578,11 @@ /// Get the SDK OS version this object file was built with. /// - /// The versions arguments and returns values are the same as the - /// GetMinimumOSVersion() - virtual uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) { - if (versions && num_versions) { - for (uint32_t i = 0; i < num_versions; ++i) - versions[i] = UINT32_MAX; - } - return 0; - } + /// \return + /// This function returns extracted version numbers as a + /// llvm::VersionTuple. In case of error an empty VersionTuple is + /// returned. + virtual llvm::VersionTuple GetSDKVersion() { return llvm::VersionTuple(); } /// Return true if this file is a dynamic link editor (dyld) /// Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h =================================================================== --- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -116,7 +116,7 @@ llvm::VersionTuple GetMinimumOSVersion() override; - uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override; + llvm::VersionTuple GetSDKVersion() override; bool GetIsDynamicLinkEditor() override; @@ -198,7 +198,7 @@ std::vector m_mach_segments; std::vector m_mach_sections; llvm::Optional m_min_os_version; - std::vector m_sdk_versions; + llvm::Optional m_sdk_versions; typedef lldb_private::RangeVector FileRangeArray; lldb_private::Address m_entry_point_address; FileRangeArray m_thread_context_offsets; Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5847,12 +5847,10 @@ return *m_min_os_version; } -uint32_t ObjectFileMachO::GetSDKVersion(uint32_t *versions, - uint32_t num_versions) { - if (m_sdk_versions.empty()) { +llvm::VersionTuple ObjectFileMachO::GetSDKVersion() { + if (!m_sdk_versions.hasValue()) { lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); - bool success = false; - for (uint32_t i = 0; !success && i < m_header.ncmds; ++i) { + for (uint32_t i = 0; i < m_header.ncmds; ++i) { const lldb::offset_t load_cmd_offset = offset; version_min_command lc; @@ -5868,10 +5866,8 @@ const uint32_t yy = (lc.sdk >> 8) & 0xffu; const uint32_t zz = lc.sdk & 0xffu; if (xxxx) { - m_sdk_versions.push_back(xxxx); - m_sdk_versions.push_back(yy); - m_sdk_versions.push_back(zz); - success = true; + m_sdk_versions = llvm::VersionTuple(xxxx, yy, zz); + break; } else { GetModule()->ReportWarning( "minimum OS version load command with invalid (0) version found."); @@ -5881,9 +5877,9 @@ offset = load_cmd_offset + lc.cmdsize; } - if (!success) { + if (!m_sdk_versions.hasValue()) { offset = MachHeaderSizeFromMagic(m_header.magic); - for (uint32_t i = 0; !success && i < m_header.ncmds; ++i) { + for (uint32_t i = 0; i < m_header.ncmds; ++i) { const lldb::offset_t load_cmd_offset = offset; version_min_command lc; @@ -5910,41 +5906,19 @@ const uint32_t yy = (minos >> 8) & 0xffu; const uint32_t zz = minos & 0xffu; if (xxxx) { - m_sdk_versions.push_back(xxxx); - m_sdk_versions.push_back(yy); - m_sdk_versions.push_back(zz); - success = true; + m_sdk_versions = llvm::VersionTuple(xxxx, yy, zz); + break; } } offset = load_cmd_offset + lc.cmdsize; } } - if (!success) { - // Push an invalid value so we don't try to find - // the version # again on the next call to this - // method. - m_sdk_versions.push_back(UINT32_MAX); - } + if (!m_sdk_versions.hasValue()) + m_sdk_versions = llvm::VersionTuple(); } - // Legitimate version numbers will have 3 entries pushed - // on to m_sdk_versions. If we only have one value, it's - // the sentinel value indicating that this object file - // does not have a valid minimum os version #. - if (m_sdk_versions.size() > 1) { - if (versions != nullptr && num_versions > 0) { - for (size_t i = 0; i < num_versions; ++i) { - if (i < m_sdk_versions.size()) - versions[i] = m_sdk_versions[i]; - else - versions[i] = 0; - } - } - return m_sdk_versions.size(); - } - // Call the superclasses version that will empty out the data - return ObjectFile::GetSDKVersion(versions, num_versions); + return m_sdk_versions.getValue(); } bool ObjectFileMachO::GetIsDynamicLinkEditor() { Index: lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -163,8 +163,8 @@ std::string xcode_contents_path; std::string default_xcode_sdk; FileSpec fspec; - uint32_t versions[2]; - if (objfile->GetSDKVersion(versions, 2)) { + llvm::VersionTuple version = objfile->GetSDKVersion(); + if (!version.empty()) { fspec = HostInfo::GetShlibDir(); if (fspec) { std::string path; @@ -208,8 +208,8 @@ StreamString sdk_path; sdk_path.Printf("%sDeveloper/Platforms/MacOSX.platform/Developer/" "SDKs/MacOSX%u.%u.sdk", - xcode_contents_path.c_str(), versions[0], - versions[1]); + xcode_contents_path.c_str(), version.getMajor(), + version.getMinor().getValue()); fspec.SetFile(sdk_path.GetString(), FileSpec::Style::native); if (FileSystem::Instance().Exists(fspec)) return ConstString(sdk_path.GetString());