Author: Pavel Labath Date: 2021-10-22T12:59:58+02:00 New Revision: 8b8070e23442351ae153e36a4d05790252c6ad96
URL: https://github.com/llvm/llvm-project/commit/8b8070e23442351ae153e36a4d05790252c6ad96 DIFF: https://github.com/llvm/llvm-project/commit/8b8070e23442351ae153e36a4d05790252c6ad96.diff LOG: Host::GetOSBuildString Added: Modified: lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h lldb/include/lldb/Host/linux/HostInfoLinux.h lldb/include/lldb/Host/macosx/HostInfoMacOSX.h lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h lldb/include/lldb/Host/windows/HostInfoWindows.h lldb/source/Host/freebsd/HostInfoFreeBSD.cpp lldb/source/Host/linux/HostInfoLinux.cpp lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm lldb/source/Host/netbsd/HostInfoNetBSD.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp lldb/source/Target/Platform.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h b/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h index 56f20bbd23d3b..8207e9093f715 100644 --- a/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h +++ b/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h @@ -18,7 +18,7 @@ namespace lldb_private { class HostInfoFreeBSD : public HostInfoPosix { public: static llvm::VersionTuple GetOSVersion(); - static bool GetOSBuildString(std::string &s); + static llvm::Optional<std::string> GetOSBuildString(); static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); }; diff --git a/lldb/include/lldb/Host/linux/HostInfoLinux.h b/lldb/include/lldb/Host/linux/HostInfoLinux.h index 3220046488677..6287670606643 100644 --- a/lldb/include/lldb/Host/linux/HostInfoLinux.h +++ b/lldb/include/lldb/Host/linux/HostInfoLinux.h @@ -26,7 +26,7 @@ class HostInfoLinux : public HostInfoPosix { static void Terminate(); static llvm::VersionTuple GetOSVersion(); - static bool GetOSBuildString(std::string &s); + static llvm::Optional<std::string> GetOSBuildString(); static bool GetOSKernelDescription(std::string &s); static llvm::StringRef GetDistributionId(); static FileSpec GetProgramFileSpec(); diff --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h index 4623932ab2b4c..42c2872af2182 100644 --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -24,7 +24,7 @@ class HostInfoMacOSX : public HostInfoPosix { public: static llvm::VersionTuple GetOSVersion(); static llvm::VersionTuple GetMacCatalystVersion(); - static bool GetOSBuildString(std::string &s); + static llvm::Optional<std::string> GetOSBuildString(); static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); static FileSpec GetXcodeContentsDirectory(); diff --git a/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h b/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h index f9ad66eb2b2af..021f8626733b0 100644 --- a/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h +++ b/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h @@ -18,7 +18,7 @@ namespace lldb_private { class HostInfoNetBSD : public HostInfoPosix { public: static llvm::VersionTuple GetOSVersion(); - static bool GetOSBuildString(std::string &s); + static llvm::Optional<std::string> GetOSBuildString(); static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); }; diff --git a/lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h b/lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h index 7ec1d5fc3606d..ba5ac8cbb169f 100644 --- a/lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h +++ b/lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h @@ -18,7 +18,7 @@ namespace lldb_private { class HostInfoOpenBSD : public HostInfoPosix { public: static llvm::VersionTuple GetOSVersion(); - static bool GetOSBuildString(std::string &s); + static llvm::Optional<std::string> GetOSBuildString(); static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); }; diff --git a/lldb/include/lldb/Host/windows/HostInfoWindows.h b/lldb/include/lldb/Host/windows/HostInfoWindows.h index f01113e900493..d7f9e68254c9e 100644 --- a/lldb/include/lldb/Host/windows/HostInfoWindows.h +++ b/lldb/include/lldb/Host/windows/HostInfoWindows.h @@ -27,7 +27,7 @@ class HostInfoWindows : public HostInfoBase { static UserIDResolver &GetUserIDResolver(); static llvm::VersionTuple GetOSVersion(); - static bool GetOSBuildString(std::string &s); + static llvm::Optional<std::string> GetOSBuildString(); static bool GetOSKernelDescription(std::string &s); static bool GetHostname(std::string &s); static FileSpec GetProgramFileSpec(); diff --git a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp index 1b9e3ccaf1818..22af5bda66108 100644 --- a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp +++ b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/freebsd/HostInfoFreeBSD.h" - +#include "llvm/Support/FormatVariadic.h" #include <cstdio> #include <cstring> #include <sys/sysctl.h> @@ -30,20 +30,16 @@ llvm::VersionTuple HostInfoFreeBSD::GetOSVersion() { return llvm::VersionTuple(); } -bool HostInfoFreeBSD::GetOSBuildString(std::string &s) { +llvm::Optional<std::string> HostInfoFreeBSD::GetOSBuildString() { int mib[2] = {CTL_KERN, KERN_OSREV}; char osrev_str[12]; uint32_t osrev = 0; size_t osrev_len = sizeof(osrev); - if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) { - ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev); - s.assign(osrev_str); - return true; - } + if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) + return llvm::formatv("{0,8:8}", osrev).str(); - s.clear(); - return false; + return llvm::None; } bool HostInfoFreeBSD::GetOSKernelDescription(std::string &s) { diff --git a/lldb/source/Host/linux/HostInfoLinux.cpp b/lldb/source/Host/linux/HostInfoLinux.cpp index 13dcc5aed65c6..32642ed375f04 100644 --- a/lldb/source/Host/linux/HostInfoLinux.cpp +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -65,16 +65,14 @@ llvm::VersionTuple HostInfoLinux::GetOSVersion() { return g_fields->m_os_version; } -bool HostInfoLinux::GetOSBuildString(std::string &s) { +llvm::Optional<std::string> HostInfoLinux::GetOSBuildString() { struct utsname un; ::memset(&un, 0, sizeof(utsname)); - s.clear(); if (uname(&un) < 0) - return false; + return llvm::None; - s.assign(un.release); - return true; + return std::string(un.release); } bool HostInfoLinux::GetOSKernelDescription(std::string &s) { diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm index a0706ec9ff6ae..e32cfb0aade00 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -55,17 +55,14 @@ using namespace lldb_private; -bool HostInfoMacOSX::GetOSBuildString(std::string &s) { +llvm::Optional<std::string> HostInfoMacOSX::GetOSBuildString() { int mib[2] = {CTL_KERN, KERN_OSVERSION}; char cstr[PATH_MAX]; size_t cstr_len = sizeof(cstr); - if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0) { - s.assign(cstr, cstr_len); - return true; - } + if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0) + return std::string(cstr, cstr_len); - s.clear(); - return false; + return llvm::None; } bool HostInfoMacOSX::GetOSKernelDescription(std::string &s) { diff --git a/lldb/source/Host/netbsd/HostInfoNetBSD.cpp b/lldb/source/Host/netbsd/HostInfoNetBSD.cpp index bddd46cec3ee4..42bfb205b27c8 100644 --- a/lldb/source/Host/netbsd/HostInfoNetBSD.cpp +++ b/lldb/source/Host/netbsd/HostInfoNetBSD.cpp @@ -42,20 +42,16 @@ llvm::VersionTuple HostInfoNetBSD::GetOSVersion() { return llvm::VersionTuple(); } -bool HostInfoNetBSD::GetOSBuildString(std::string &s) { +llvm::Optional<std::string> HostInfoNetBSD::GetOSBuildString() { int mib[2] = {CTL_KERN, KERN_OSREV}; char osrev_str[12]; int osrev = 0; size_t osrev_len = sizeof(osrev); - if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) { - ::snprintf(osrev_str, sizeof(osrev_str), "%-10.10d", osrev); - s.assign(osrev_str); - return true; - } + if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) + return llvm::formatv("{0,10:10}", osrev).str(); - s.clear(); - return false; + return llvm::None; } bool HostInfoNetBSD::GetOSKernelDescription(std::string &s) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index d4a753d23469e..17b7f1759d174 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -267,12 +267,12 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo( } #endif - std::string s; - if (HostInfo::GetOSBuildString(s)) { + if (llvm::Optional<std::string> s = HostInfo::GetOSBuildString()) { response.PutCString("os_build:"); - response.PutStringAsRawHex8(s); + response.PutStringAsRawHex8(*s); response.PutChar(';'); } + std::string s; if (HostInfo::GetOSKernelDescription(s)) { response.PutCString("os_kernel:"); response.PutStringAsRawHex8(s); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 9c57689b419ea..0f2eee893fe6e 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -487,10 +487,12 @@ llvm::VersionTuple Platform::GetOSVersion(Process *process) { } bool Platform::GetOSBuildString(std::string &s) { + if (IsHost()) { + llvm::Optional<std::string> str = HostInfo::GetOSBuildString(); + s = str.getValueOr(""); + return str.hasValue(); + } s.clear(); - - if (IsHost()) - return HostInfo::GetOSBuildString(s); return GetRemoteOSBuildString(s); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits