diff options
author | Pavel Labath <labath@google.com> | 2018-06-18 15:02:23 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-06-18 15:02:23 +0000 |
commit | 5368ebc87be3548597daca304164ef0c7fe38f98 (patch) | |
tree | 14e635c282a51cda894e14c7b2eff9a9ce7fa152 /lldb/source/Plugins | |
parent | 20137c2ed060758a0e85fdfd1cba7154228090ee (diff) |
Use llvm::VersionTuple instead of manual version marshalling
Summary:
This has multiple advantages:
- we need only one function argument/instance variable instead of three
- no need to default initialize variables
- no custom parsing code
- VersionTuple has comparison operators, which makes version comparisons much
simpler
Reviewers: zturner, friss, clayborg, jingham
Subscribers: emaste, lldb-commits
Differential Revision: https://reviews.llvm.org/D47889
Diffstat (limited to 'lldb/source/Plugins')
18 files changed, 111 insertions, 241 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index 96242fd958d..c35905bd71e 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -1122,34 +1122,29 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp, bool DynamicLoaderDarwin::UseDYLDSPI(Process *process) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); - uint32_t major, minor, update; - bool use_new_spi_interface = false; - if (process->GetHostOSVersion(major, minor, update)) { + llvm::VersionTuple version = process->GetHostOSVersion(); + if (!version.empty()) { const llvm::Triple::OSType os_type = process->GetTarget().GetArchitecture().GetTriple().getOS(); // macOS 10.12 and newer if (os_type == llvm::Triple::MacOSX && - (major > 10 || (major == 10 && minor >= 12))) { + version >= llvm::VersionTuple(10, 12)) use_new_spi_interface = true; - } // iOS 10 and newer - if (os_type == llvm::Triple::IOS && major >= 10) { + if (os_type == llvm::Triple::IOS && version >= llvm::VersionTuple(10)) use_new_spi_interface = true; - } // tvOS 10 and newer - if (os_type == llvm::Triple::TvOS && major >= 10) { + if (os_type == llvm::Triple::TvOS && version >= llvm::VersionTuple(10)) use_new_spi_interface = true; - } // watchOS 3 and newer - if (os_type == llvm::Triple::WatchOS && major >= 3) { + if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3)) use_new_spi_interface = true; - } } if (log) { diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp index 68df4335c9e..b1513b51a90 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp @@ -454,9 +454,8 @@ std::string DYLDRendezvous::ReadStringFromMemory(addr_t addr) { static bool isLoadBiasIncorrect(Target &target, const std::string &file_path) { // On Android L (API 21, 22) the load address of the "/system/bin/linker" // isn't filled in correctly. - uint32_t os_major = 0, os_minor = 0, os_update = 0; + unsigned os_major = target.GetPlatform()->GetOSVersion().getMajor(); if (target.GetArchitecture().GetTriple().isAndroid() && - target.GetPlatform()->GetOSVersion(os_major, os_minor, os_update) && (os_major == 21 || os_major == 22) && (file_path == "/system/bin/linker" || file_path == "/system/bin/linker64")) { diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index 5516cf90122..fef42c78b24 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -293,16 +293,14 @@ bool AppleObjCRuntime::AppleIsModuleObjCLibrary(const ModuleSP &module_sp) { uint32_t AppleObjCRuntime::GetFoundationVersion() { if (!m_Foundation_major.hasValue()) { const ModuleList &modules = m_process->GetTarget().GetImages(); - uint32_t major = UINT32_MAX; for (uint32_t idx = 0; idx < modules.GetSize(); idx++) { lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx); if (!module_sp) continue; if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(""), "Foundation") == 0) { - module_sp->GetVersion(&major, 1); - m_Foundation_major = major; - return major; + m_Foundation_major = module_sp->GetVersion().getMajor(); + return *m_Foundation_major; } } return LLDB_INVALID_MODULE_VERSION; diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index ce62077f125..0aa0fc91e40 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5549,8 +5549,7 @@ ObjectFile::Strata ObjectFileMachO::CalculateStrata() { return eStrataUnknown; } -uint32_t ObjectFileMachO::GetVersion(uint32_t *versions, - uint32_t num_versions) { +llvm::VersionTuple ObjectFileMachO::GetVersion() { ModuleSP module_sp(GetModule()); if (module_sp) { std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); @@ -5578,23 +5577,13 @@ uint32_t ObjectFileMachO::GetVersion(uint32_t *versions, } if (version_cmd == LC_ID_DYLIB) { - if (versions != NULL && num_versions > 0) { - if (num_versions > 0) - versions[0] = (version & 0xFFFF0000ull) >> 16; - if (num_versions > 1) - versions[1] = (version & 0x0000FF00ull) >> 8; - if (num_versions > 2) - versions[2] = (version & 0x000000FFull); - // Fill in an remaining version numbers with invalid values - for (i = 3; i < num_versions; ++i) - versions[i] = UINT32_MAX; - } - // The LC_ID_DYLIB load command has a version with 3 version numbers in - // it, so always return 3 - return 3; + unsigned major = (version & 0xFFFF0000ull) >> 16; + unsigned minor = (version & 0x0000FF00ull) >> 8; + unsigned subminor = (version & 0x000000FFull); + return llvm::VersionTuple(major, minor, subminor); } } - return false; + return llvm::VersionTuple(); } bool ObjectFileMachO::GetArchitecture(ArchSpec &arch) { @@ -5708,12 +5697,10 @@ void ObjectFileMachO::GetLLDBSharedCacheUUID(addr_t &base_addr, UUID &uuid) { #endif } -uint32_t ObjectFileMachO::GetMinimumOSVersion(uint32_t *versions, - uint32_t num_versions) { - if (m_min_os_versions.empty()) { +llvm::VersionTuple ObjectFileMachO::GetMinimumOSVersion() { + if (!m_min_os_version) { lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); - bool success = false; - for (uint32_t i = 0; success == false && 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; @@ -5729,35 +5716,21 @@ uint32_t ObjectFileMachO::GetMinimumOSVersion(uint32_t *versions, const uint32_t yy = (lc.version >> 8) & 0xffu; const uint32_t zz = lc.version & 0xffu; if (xxxx) { - m_min_os_versions.push_back(xxxx); - m_min_os_versions.push_back(yy); - m_min_os_versions.push_back(zz); + m_min_os_version = llvm::VersionTuple(xxxx, yy, zz); + break; } - success = true; } } offset = load_cmd_offset + lc.cmdsize; } - if (success == false) { - // Push an invalid value so we don't keep trying to - m_min_os_versions.push_back(UINT32_MAX); + if (!m_min_os_version) { + // Set version to an empty value so we don't keep trying to + m_min_os_version = llvm::VersionTuple(); } } - if (m_min_os_versions.size() > 1 || m_min_os_versions[0] != UINT32_MAX) { - if (versions != NULL && num_versions > 0) { - for (size_t i = 0; i < num_versions; ++i) { - if (i < m_min_os_versions.size()) - versions[i] = m_min_os_versions[i]; - else - versions[i] = 0; - } - } - return m_min_os_versions.size(); - } - // Call the superclasses version that will empty out the data - return ObjectFile::GetMinimumOSVersion(versions, num_versions); + return *m_min_os_version; } uint32_t ObjectFileMachO::GetSDKVersion(uint32_t *versions, diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h index ca64d88706f..8cdd80fb265 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -123,10 +123,9 @@ public: ObjectFile::Strata CalculateStrata() override; - uint32_t GetVersion(uint32_t *versions, uint32_t num_versions) override; + llvm::VersionTuple GetVersion() override; - uint32_t GetMinimumOSVersion(uint32_t *versions, - uint32_t num_versions) override; + llvm::VersionTuple GetMinimumOSVersion() override; uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override; @@ -209,7 +208,7 @@ protected: llvm::MachO::dysymtab_command m_dysymtab; std::vector<llvm::MachO::segment_command_64> m_mach_segments; std::vector<llvm::MachO::section_64> m_mach_sections; - std::vector<uint32_t> m_min_os_versions; + llvm::Optional<llvm::VersionTuple> m_min_os_version; std::vector<uint32_t> m_sdk_versions; typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray; lldb_private::Address m_entry_point_address; diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index b7fd5064765..1cedcde97a9 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -360,10 +360,8 @@ Status PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp, } bool PlatformAndroid::GetRemoteOSVersion() { - m_major_os_version = GetSdkVersion(); - m_minor_os_version = 0; - m_update_os_version = 0; - return m_major_os_version != 0; + m_os_version = llvm::VersionTuple(GetSdkVersion()); + return !m_os_version.empty(); } llvm::StringRef diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 9e2b721b67f..10da80f4500 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1382,18 +1382,14 @@ static FileSpec GetXcodeContentsPath() { return g_xcode_filespec; } -bool PlatformDarwin::SDKSupportsModules(SDKType sdk_type, uint32_t major, - uint32_t minor, uint32_t micro) { +bool PlatformDarwin::SDKSupportsModules(SDKType sdk_type, + llvm::VersionTuple version) { switch (sdk_type) { case SDKType::MacOSX: - if (major > 10 || (major == 10 && minor >= 10)) - return true; - break; + return version >= llvm::VersionTuple(10, 10); case SDKType::iPhoneOS: case SDKType::iPhoneSimulator: - if (major >= 8) - return true; - break; + return version >= llvm::VersionTuple(8); } return false; @@ -1415,32 +1411,10 @@ bool PlatformDarwin::SDKSupportsModules(SDKType desired_type, return false; } - const size_t major_dot_offset = version_part.find('.'); - if (major_dot_offset == llvm::StringRef::npos) - return false; - - const llvm::StringRef major_version = - version_part.slice(0, major_dot_offset); - const llvm::StringRef minor_part = - version_part.drop_front(major_dot_offset + 1); - - const size_t minor_dot_offset = minor_part.find('.'); - if (minor_dot_offset == llvm::StringRef::npos) - return false; - - const llvm::StringRef minor_version = minor_part.slice(0, minor_dot_offset); - - unsigned int major = 0; - unsigned int minor = 0; - unsigned int micro = 0; - - if (major_version.getAsInteger(10, major)) - return false; - - if (minor_version.getAsInteger(10, minor)) + llvm::VersionTuple version; + if (version.tryParse(version_part)) return false; - - return SDKSupportsModules(desired_type, major, minor, micro); + return SDKSupportsModules(desired_type, version); } return false; @@ -1512,18 +1486,17 @@ FileSpec PlatformDarwin::GetSDKDirectoryForModules(SDKType sdk_type) { sdks_spec.AppendPathComponent("SDKs"); if (sdk_type == SDKType::MacOSX) { - uint32_t major = 0; - uint32_t minor = 0; - uint32_t micro = 0; + llvm::VersionTuple version = HostInfo::GetOSVersion(); - if (HostInfo::GetOSVersion(major, minor, micro)) { - if (SDKSupportsModules(SDKType::MacOSX, major, minor, micro)) { + if (!version.empty()) { + if (SDKSupportsModules(SDKType::MacOSX, version)) { // We slightly prefer the exact SDK for this machine. See if it is // there. FileSpec native_sdk_spec = sdks_spec; StreamString native_sdk_name; - native_sdk_name.Printf("MacOSX%u.%u.sdk", major, minor); + native_sdk_name.Printf("MacOSX%u.%u.sdk", version.getMajor(), + version.getMinor().getValueOr(0)); native_sdk_spec.AppendPathComponent(native_sdk_name.GetString()); if (native_sdk_spec.Exists()) { @@ -1536,14 +1509,14 @@ FileSpec PlatformDarwin::GetSDKDirectoryForModules(SDKType sdk_type) { return FindSDKInXcodeForModules(sdk_type, sdks_spec); } -std::tuple<uint32_t, uint32_t, uint32_t, llvm::StringRef> +std::tuple<llvm::VersionTuple, llvm::StringRef> PlatformDarwin::ParseVersionBuildDir(llvm::StringRef dir) { - uint32_t major, minor, update; llvm::StringRef build; llvm::StringRef version_str; llvm::StringRef build_str; std::tie(version_str, build_str) = dir.split(' '); - if (Args::StringToVersion(version_str, major, minor, update) || + llvm::VersionTuple version; + if (!version.tryParse(version_str) || build_str.empty()) { if (build_str.consume_front("(")) { size_t pos = build_str.find(')'); @@ -1551,7 +1524,7 @@ PlatformDarwin::ParseVersionBuildDir(llvm::StringRef dir) { } } - return std::make_tuple(major, minor, update, build); + return std::make_tuple(version, build); } void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( @@ -1563,7 +1536,6 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( options.insert(options.end(), apple_arguments.begin(), apple_arguments.end()); StreamString minimum_version_option; - uint32_t versions[3] = {0, 0, 0}; bool use_current_os_version = false; switch (sdk_type) { case SDKType::iPhoneOS: @@ -1587,9 +1559,9 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( break; } - bool versions_valid = false; + llvm::VersionTuple version; if (use_current_os_version) - versions_valid = GetOSVersion(versions[0], versions[1], versions[2]); + version = GetOSVersion(); else if (target) { // Our OS doesn't match our executable so we need to get the min OS version // from the object file @@ -1597,35 +1569,23 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (exe_module_sp) { ObjectFile *object_file = exe_module_sp->GetObjectFile(); if (object_file) - versions_valid = object_file->GetMinimumOSVersion(versions, 3) > 0; + version = object_file->GetMinimumOSVersion(); } } // Only add the version-min options if we got a version from somewhere - if (versions_valid && versions[0] != UINT32_MAX) { - // Make any invalid versions be zero if needed - if (versions[1] == UINT32_MAX) - versions[1] = 0; - if (versions[2] == UINT32_MAX) - versions[2] = 0; - + if (!version.empty()) { switch (sdk_type) { case SDKType::iPhoneOS: minimum_version_option.PutCString("-mios-version-min="); - minimum_version_option.PutCString( - llvm::VersionTuple(versions[0], versions[1], versions[2]) - .getAsString()); + minimum_version_option.PutCString(version.getAsString()); break; case SDKType::iPhoneSimulator: minimum_version_option.PutCString("-mios-simulator-version-min="); - minimum_version_option.PutCString( - llvm::VersionTuple(versions[0], versions[1], versions[2]) - .getAsString()); + minimum_version_option.PutCString(version.getAsString()); break; case SDKType::MacOSX: minimum_version_option.PutCString("-mmacosx-version-min="); - minimum_version_option.PutCString( - llvm::VersionTuple(versions[0], versions[1], versions[2]) - .getAsString()); + minimum_version_option.PutCString(version.getAsString()); } options.push_back(minimum_version_option.GetString()); } @@ -1652,16 +1612,15 @@ ConstString PlatformDarwin::GetFullNameForDylib(ConstString basename) { return ConstString(stream.GetString()); } -bool PlatformDarwin::GetOSVersion(uint32_t &major, uint32_t &minor, - uint32_t &update, Process *process) { +llvm::VersionTuple PlatformDarwin::GetOSVersion(Process *process) { if (process && strstr(GetPluginName().GetCString(), "-simulator")) { lldb_private::ProcessInstanceInfo proc_info; if (Host::GetProcessInfo(process->GetID(), proc_info)) { const Environment &env = proc_info.GetEnvironment(); - if (Args::StringToVersion(env.lookup("SIMULATOR_RUNTIME_VERSION"), major, - minor, update)) - return true; + llvm::VersionTuple result; + if (!result.tryParse(env.lookup("SIMULATOR_RUNTIME_VERSION"))) + return result; std::string dyld_root_path = env.lookup("DYLD_ROOT_PATH"); if (!dyld_root_path.empty()) { @@ -1670,17 +1629,18 @@ bool PlatformDarwin::GetOSVersion(uint32_t &major, uint32_t &minor, std::string product_version; if (system_version_plist.GetValueAsString("ProductVersion", product_version)) { - return Args::StringToVersion(product_version, major, minor, update); + if (!result.tryParse(product_version)) + return result; } } } // For simulator platforms, do NOT call back through // Platform::GetOSVersion() as it might call Process::GetHostOSVersion() // which we don't want as it will be incorrect - return false; + return llvm::VersionTuple(); } - return Platform::GetOSVersion(major, minor, update, process); + return Platform::GetOSVersion(process); } lldb_private::FileSpec PlatformDarwin::LocateExecutable(const char *basename) { diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index c04318e98ca..3ad29ec1a0b 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -69,8 +69,8 @@ public: void CalculateTrapHandlerSymbolNames() override; - bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update, - lldb_private::Process *process = nullptr) override; + llvm::VersionTuple + GetOSVersion(lldb_private::Process *process = nullptr) override; bool SupportsModules() override { return true; } @@ -82,7 +82,7 @@ public: lldb_private::Status LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override; - static std::tuple<uint32_t, uint32_t, uint32_t, llvm::StringRef> + static std::tuple<llvm::VersionTuple, llvm::StringRef> ParseVersionBuildDir(llvm::StringRef str); protected: @@ -101,8 +101,7 @@ protected: iPhoneOS, }; - static bool SDKSupportsModules(SDKType sdk_type, uint32_t major, - uint32_t minor, uint32_t micro); + static bool SDKSupportsModules(SDKType sdk_type, llvm::VersionTuple version); static bool SDKSupportsModules(SDKType desired_type, const lldb_private::FileSpec &sdk_path); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp index 7b78c674c26..930d062fe41 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp @@ -31,12 +31,10 @@ using namespace lldb_private; PlatformRemoteDarwinDevice::SDKDirectoryInfo::SDKDirectoryInfo( const lldb_private::FileSpec &sdk_dir) - : directory(sdk_dir), build(), version_major(0), version_minor(0), - version_update(0), user_cached(false) { + : directory(sdk_dir), build(), user_cached(false) { llvm::StringRef dirname_str = sdk_dir.GetFilename().GetStringRef(); llvm::StringRef build_str; - std::tie(version_major, version_minor, version_update, build_str) = - ParseVersionBuildDir(dirname_str); + std::tie(version, build_str) = ParseVersionBuildDir(dirname_str); build.SetString(build_str); } @@ -255,24 +253,23 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForCurrentOSVersion() { // If we are connected we can find the version of the OS the platform us // running on and select the right SDK - uint32_t major, minor, update; - if (GetOSVersion(major, minor, update)) { + llvm::VersionTuple version = GetOSVersion(); + if (!version.empty()) { if (UpdateSDKDirectoryInfosIfNeeded()) { // First try for an exact match of major, minor and update for (i = 0; i < num_sdk_infos; ++i) { if (check_sdk_info[i]) { - if (m_sdk_directory_infos[i].version_major == major && - m_sdk_directory_infos[i].version_minor == minor && - m_sdk_directory_infos[i].version_update == update) { + if (m_sdk_directory_infos[i].version == version) return &m_sdk_directory_infos[i]; - } } } // First try for an exact match of major and minor for (i = 0; i < num_sdk_infos; ++i) { if (check_sdk_info[i]) { - if (m_sdk_directory_infos[i].version_major == major && - m_sdk_directory_infos[i].version_minor == minor) { + if (m_sdk_directory_infos[i].version.getMajor() == + version.getMajor() && + m_sdk_directory_infos[i].version.getMinor() == + version.getMinor()) { return &m_sdk_directory_infos[i]; } } @@ -280,7 +277,8 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForCurrentOSVersion() { // Lastly try to match of major version only.. for (i = 0; i < num_sdk_infos; ++i) { if (check_sdk_info[i]) { - if (m_sdk_directory_infos[i].version_major == major) { + if (m_sdk_directory_infos[i].version.getMajor() == + version.getMajor()) { return &m_sdk_directory_infos[i]; } } @@ -300,25 +298,13 @@ const PlatformRemoteDarwinDevice::SDKDirectoryInfo * PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() { const PlatformRemoteDarwinDevice::SDKDirectoryInfo *result = NULL; if (UpdateSDKDirectoryInfosIfNeeded()) { - const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); - // First try for an exact match of major, minor and update - for (uint32_t i = 0; i < num_sdk_infos; ++i) { - const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i]; - if (sdk_dir_info.version_major != UINT32_MAX) { - if (result == NULL || - sdk_dir_info.version_major > result->version_major) { - result = &sdk_dir_info; - } else if (sdk_dir_info.version_major == result->version_major) { - if (sdk_dir_info.version_minor > result->version_minor) { - result = &sdk_dir_info; - } else if (sdk_dir_info.version_minor == result->version_minor) { - if (sdk_dir_info.version_update > result->version_update) { - result = &sdk_dir_info; - } - } - } - } - } + auto max = std::max_element( + m_sdk_directory_infos.begin(), m_sdk_directory_infos.end(), + [](const SDKDirectoryInfo &a, const SDKDirectoryInfo &b) { + return a.version < b.version; + }); + if (max != m_sdk_directory_infos.end()) + result = &*max; } return result; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h index f159e8575d7..8ddfd51600f 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h @@ -60,9 +60,7 @@ protected: SDKDirectoryInfo(const lldb_private::FileSpec &sdk_dir_spec); lldb_private::FileSpec directory; lldb_private::ConstString build; - uint32_t version_major; - uint32_t version_minor; - uint32_t version_update; + llvm::VersionTuple version; bool user_cached; }; diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index d3f43399a0e..9ac1638d27a 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -653,9 +653,10 @@ bool PlatformPOSIX::SetRemoteWorkingDirectory(const FileSpec &working_dir) { } bool PlatformPOSIX::GetRemoteOSVersion() { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetOSVersion( - m_major_os_version, m_minor_os_version, m_update_os_version); + if (m_remote_platform_sp) { + m_os_version = m_remote_platform_sp->GetOSVersion(); + return !m_os_version.empty(); + } return false; } diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index 5501710a235..c752d645c55 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -280,9 +280,10 @@ Status PlatformWindows::ResolveExecutable( } bool PlatformWindows::GetRemoteOSVersion() { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetOSVersion( - m_major_os_version, m_minor_os_version, m_update_os_version); + if (m_remote_platform_sp) { + m_os_version = m_remote_platform_sp->GetOSVersion(); + return !m_os_version.empty(); + } return false; } diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 10cff9e5943..348bb825a5c 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -236,14 +236,8 @@ size_t PlatformRemoteGDBServer::GetSoftwareBreakpointTrapOpcode( } bool PlatformRemoteGDBServer::GetRemoteOSVersion() { - uint32_t major, minor, update; - if (m_gdb_client.GetOSVersion(major, minor, update)) { - m_major_os_version = major; - m_minor_os_version = minor; - m_update_os_version = update; - return true; - } - return false; + m_os_version = m_gdb_client.GetOSVersion(); + return !m_os_version.empty(); } bool PlatformRemoteGDBServer::GetRemoteOSBuildString(std::string &s) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 6948339c676..319fa654323 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -100,11 +100,10 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient() m_curr_pid(LLDB_INVALID_PROCESS_ID), m_curr_tid(LLDB_INVALID_THREAD_ID), m_curr_tid_run(LLDB_INVALID_THREAD_ID), m_num_supported_hardware_watchpoints(0), m_host_arch(), m_process_arch(), - m_os_version_major(UINT32_MAX), m_os_version_minor(UINT32_MAX), - m_os_version_update(UINT32_MAX), m_os_build(), m_os_kernel(), - m_hostname(), m_gdb_server_name(), m_gdb_server_version(UINT32_MAX), - m_default_packet_timeout(0), m_max_packet_size(0), - m_qSupported_response(), m_supported_async_json_packets_is_valid(false), + m_os_build(), m_os_kernel(), m_hostname(), m_gdb_server_name(), + m_gdb_server_version(UINT32_MAX), m_default_packet_timeout(0), + m_max_packet_size(0), m_qSupported_response(), + m_supported_async_json_packets_is_valid(false), m_supported_async_json_packets_sp(), m_qXfer_memory_map(), m_qXfer_memory_map_loaded(false) {} @@ -323,9 +322,7 @@ void GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) { m_qSymbol_requests_done = false; m_supports_qModuleInfo = true; m_host_arch.Clear(); - m_os_version_major = UINT32_MAX; - m_os_version_minor = UINT32_MAX; - m_os_version_update = UINT32_MAX; + m_os_version = llvm::VersionTuple(); m_os_build.clear(); m_os_kernel.clear(); m_hostname.clear(); @@ -944,18 +941,9 @@ int GDBRemoteCommunicationClient::SendLaunchEventDataPacket( return -1; } -bool GDBRemoteCommunicationClient::GetOSVersion(uint32_t &major, - uint32_t &minor, - uint32_t &update) { - if (GetHostInfo()) { - if (m_os_version_major != UINT32_MAX) { - major = m_os_version_major; - minor = m_os_version_minor; - update = m_os_version_update; - return true; - } - } - return false; +llvm::VersionTuple GDBRemoteCommunicationClient::GetOSVersion() { + GetHostInfo(); + return m_os_version; } bool GDBRemoteCommunicationClient::GetOSBuildString(std::string &s) { @@ -1218,9 +1206,7 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) { // "version" key instead of // "os_version"... { - Args::StringToVersion(value, m_os_version_major, m_os_version_minor, - m_os_version_update); - if (m_os_version_major != UINT32_MAX) + if (!m_os_version.tryParse(value)) ++num_keys_decoded; } else if (name.equals("watchpoint_exceptions_received")) { m_watchpoints_trigger_after_instruction = diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index fcf578f9918..cf1d249768d 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -266,7 +266,7 @@ public: bool GetDefaultThreadId(lldb::tid_t &tid); - bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update); + llvm::VersionTuple GetOSVersion(); bool GetOSBuildString(std::string &s); @@ -573,9 +573,7 @@ protected: ArchSpec m_host_arch; ArchSpec m_process_arch; - uint32_t m_os_version_major; - uint32_t m_os_version_minor; - uint32_t m_os_version_update; + llvm::VersionTuple m_os_version; std::string m_os_build; std::string m_os_kernel; std::string m_hostname; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index d0cdbf3e292..c5b478378fa 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -269,19 +269,10 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo( break; } - uint32_t major = UINT32_MAX; - uint32_t minor = UINT32_MAX; - uint32_t update = UINT32_MAX; - if (HostInfo::GetOSVersion(major, minor, update)) { - if (major != UINT32_MAX) { - response.Printf("os_version:%u", major); - if (minor != UINT32_MAX) { - response.Printf(".%u", minor); - if (update != UINT32_MAX) - response.Printf(".%u", update); - } - response.PutChar(';'); - } + llvm::VersionTuple version = HostInfo::GetOSVersion(); + if (!version.empty()) { + response.Format("os_version:{0}", version.getAsString()); + response.PutChar(';'); } std::string s; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index e65f2f3e3b1..648df1a835f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -4241,13 +4241,8 @@ void ProcessGDBRemote::PrefetchModuleSpecs( } } -bool ProcessGDBRemote::GetHostOSVersion(uint32_t &major, uint32_t &minor, - uint32_t &update) { - if (m_gdb_comm.GetOSVersion(major, minor, update)) - return true; - // We failed to get the host OS version, defer to the base implementation to - // correctly invalidate the arguments. - return Process::GetHostOSVersion(major, minor, update); +llvm::VersionTuple ProcessGDBRemote::GetHostOSVersion() { + return m_gdb_comm.GetOSVersion(); } namespace { diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index f0b68b2505c..45bb2d4c28e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -217,8 +217,7 @@ public: void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs, const llvm::Triple &triple) override; - bool GetHostOSVersion(uint32_t &major, uint32_t &minor, - uint32_t &update) override; + llvm::VersionTuple GetHostOSVersion() override; size_t LoadModules(LoadedModuleInfoList &module_list) override; |