diff --git a/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h b/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h --- a/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h +++ b/lldb/include/lldb/Host/freebsd/HostInfoFreeBSD.h @@ -19,7 +19,6 @@ public: static llvm::VersionTuple GetOSVersion(); static llvm::Optional 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 --- a/lldb/include/lldb/Host/linux/HostInfoLinux.h +++ b/lldb/include/lldb/Host/linux/HostInfoLinux.h @@ -27,7 +27,6 @@ static llvm::VersionTuple GetOSVersion(); static llvm::Optional 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 --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -25,7 +25,6 @@ static llvm::VersionTuple GetOSVersion(); static llvm::VersionTuple GetMacCatalystVersion(); static llvm::Optional GetOSBuildString(); - static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); static FileSpec GetXcodeContentsDirectory(); static FileSpec GetXcodeDeveloperDirectory(); diff --git a/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h b/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h --- a/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h +++ b/lldb/include/lldb/Host/netbsd/HostInfoNetBSD.h @@ -19,7 +19,6 @@ public: static llvm::VersionTuple GetOSVersion(); static llvm::Optional 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 --- a/lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h +++ b/lldb/include/lldb/Host/openbsd/HostInfoOpenBSD.h @@ -19,7 +19,6 @@ public: static llvm::VersionTuple GetOSVersion(); static llvm::Optional GetOSBuildString(); - static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); }; } diff --git a/lldb/include/lldb/Host/posix/HostInfoPosix.h b/lldb/include/lldb/Host/posix/HostInfoPosix.h --- a/lldb/include/lldb/Host/posix/HostInfoPosix.h +++ b/lldb/include/lldb/Host/posix/HostInfoPosix.h @@ -22,6 +22,7 @@ public: static size_t GetPageSize(); static bool GetHostname(std::string &s); + static llvm::Optional GetOSKernelDescription(); static uint32_t GetUserID(); static uint32_t GetGroupID(); diff --git a/lldb/include/lldb/Host/windows/HostInfoWindows.h b/lldb/include/lldb/Host/windows/HostInfoWindows.h --- a/lldb/include/lldb/Host/windows/HostInfoWindows.h +++ b/lldb/include/lldb/Host/windows/HostInfoWindows.h @@ -28,7 +28,7 @@ static llvm::VersionTuple GetOSVersion(); static llvm::Optional GetOSBuildString(); - static bool GetOSKernelDescription(std::string &s); + static llvm::Optional GetOSKernelDescription(); static bool GetHostname(std::string &s); static FileSpec GetProgramFileSpec(); static FileSpec GetDefaultShell(); diff --git a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp --- a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp +++ b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp @@ -41,20 +41,6 @@ return llvm::None; } -bool HostInfoFreeBSD::GetOSKernelDescription(std::string &s) { - struct utsname un; - - ::memset(&un, 0, sizeof(utsname)); - s.clear(); - - if (uname(&un) < 0) - return false; - - s.assign(un.version); - - return true; -} - FileSpec HostInfoFreeBSD::GetProgramFileSpec() { static FileSpec g_program_filespec; if (!g_program_filespec) { diff --git a/lldb/source/Host/linux/HostInfoLinux.cpp b/lldb/source/Host/linux/HostInfoLinux.cpp --- a/lldb/source/Host/linux/HostInfoLinux.cpp +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -75,19 +75,6 @@ return std::string(un.release); } -bool HostInfoLinux::GetOSKernelDescription(std::string &s) { - struct utsname un; - - ::memset(&un, 0, sizeof(utsname)); - s.clear(); - - if (uname(&un) < 0) - return false; - - s.assign(un.version); - return true; -} - llvm::StringRef HostInfoLinux::GetDistributionId() { assert(g_fields && "Missing call to Initialize?"); // Try to run 'lbs_release -i', and use that response for the distribution diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -65,18 +65,6 @@ return llvm::None; } -bool HostInfoMacOSX::GetOSKernelDescription(std::string &s) { - int mib[2] = {CTL_KERN, KERN_VERSION}; - 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; - } - s.clear(); - return false; -} - static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) { @autoreleasepool { NSDictionary *version_info = diff --git a/lldb/source/Host/netbsd/HostInfoNetBSD.cpp b/lldb/source/Host/netbsd/HostInfoNetBSD.cpp --- a/lldb/source/Host/netbsd/HostInfoNetBSD.cpp +++ b/lldb/source/Host/netbsd/HostInfoNetBSD.cpp @@ -54,20 +54,6 @@ return llvm::None; } -bool HostInfoNetBSD::GetOSKernelDescription(std::string &s) { - struct utsname un; - - ::memset(&un, 0, sizeof(un)); - s.clear(); - - if (::uname(&un) < 0) - return false; - - s.assign(un.version); - - return true; -} - FileSpec HostInfoNetBSD::GetProgramFileSpec() { static FileSpec g_program_filespec; diff --git a/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp b/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp --- a/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp +++ b/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp @@ -41,20 +41,6 @@ return llvm::None; } -bool HostInfoOpenBSD::GetOSKernelDescription(std::string &s) { - struct utsname un; - - ::memset(&un, 0, sizeof(utsname)); - s.clear(); - - if (uname(&un) < 0) - return false; - - s.assign(un.version); - - return true; -} - FileSpec HostInfoOpenBSD::GetProgramFileSpec() { static FileSpec g_program_filespec; return g_program_filespec; diff --git a/lldb/source/Host/windows/HostInfoWindows.cpp b/lldb/source/Host/windows/HostInfoWindows.cpp --- a/lldb/source/Host/windows/HostInfoWindows.cpp +++ b/lldb/source/Host/windows/HostInfoWindows.cpp @@ -82,10 +82,8 @@ return "Windows NT " + version.getAsString(); } -bool HostInfoWindows::GetOSKernelDescription(std::string &s) { - llvm::Optional build = GetOSBuildString(); - s = build.getValueOr(""); - return build.hasValue(); +llvm::Optional HostInfoWindows::GetOSKernelDescription() { + return GetOSBuildString(); } bool HostInfoWindows::GetHostname(std::string &s) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -272,13 +272,13 @@ response.PutStringAsRawHex8(*s); response.PutChar(';'); } - std::string s; - if (HostInfo::GetOSKernelDescription(s)) { + if (llvm::Optional s = HostInfo::GetOSKernelDescription()) { response.PutCString("os_kernel:"); - response.PutStringAsRawHex8(s); + response.PutStringAsRawHex8(*s); response.PutChar(';'); } + std::string s; #if defined(__APPLE__) #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -493,8 +493,11 @@ } bool Platform::GetOSKernelDescription(std::string &s) { - if (IsHost()) - return HostInfo::GetOSKernelDescription(s); + if (IsHost()) { + llvm::Optional desc = HostInfo::GetOSKernelDescription(); + s = desc.getValueOr(""); + return desc.hasValue(); + } return GetRemoteOSKernelDescription(s); }