diff options
Diffstat (limited to 'lldb/source/Host')
-rw-r--r-- | lldb/source/Host/CMakeLists.txt | 5 | ||||
-rw-r--r-- | lldb/source/Host/common/Host.cpp | 146 | ||||
-rw-r--r-- | lldb/source/Host/common/HostInfoBase.cpp | 78 | ||||
-rw-r--r-- | lldb/source/Host/freebsd/Host.cpp | 51 | ||||
-rw-r--r-- | lldb/source/Host/freebsd/HostInfoFreeBSD.cpp | 63 | ||||
-rw-r--r-- | lldb/source/Host/linux/Host.cpp | 133 | ||||
-rw-r--r-- | lldb/source/Host/linux/HostInfoLinux.cpp | 149 | ||||
-rw-r--r-- | lldb/source/Host/macosx/Host.mm | 66 | ||||
-rw-r--r-- | lldb/source/Host/macosx/HostInfoMacOSX.mm | 85 | ||||
-rw-r--r-- | lldb/source/Host/posix/HostInfoPosix.cpp | 39 | ||||
-rw-r--r-- | lldb/source/Host/windows/Host.cpp | 51 | ||||
-rw-r--r-- | lldb/source/Host/windows/HostInfoWindows.cpp | 80 |
12 files changed, 507 insertions, 439 deletions
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index b4ac5dc1bd6..3fc9dd939e2 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -11,6 +11,7 @@ add_host_subdirectory(common common/FileCache.cpp common/FileSpec.cpp common/Host.cpp + common/HostInfoBase.cpp common/IOObject.cpp common/Mutex.cpp common/NativeBreakpoint.cpp @@ -32,6 +33,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows") add_host_subdirectory(windows windows/FileSystem.cpp windows/Host.cpp + windows/HostInfoWindows.cpp windows/ProcessRunLock.cpp windows/Mutex.cpp windows/Condition.cpp @@ -41,6 +43,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows") else() add_host_subdirectory(posix posix/FileSystem.cpp + posix/HostInfoPosix.cpp ) if (CMAKE_SYSTEM_NAME MATCHES "Darwin") @@ -59,10 +62,12 @@ else() elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") add_host_subdirectory(linux linux/Host.cpp + linux/HostInfoLinux.cpp ) elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") add_host_subdirectory(freebsd freebsd/Host.cpp + freebsd/HostInfoFreeBSD.cpp ) endif() endif() diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index 885104fecbf..43aa5bacfe0 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -56,6 +56,7 @@ #include <limits> #include "lldb/Host/Host.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" @@ -416,9 +417,11 @@ Host::GetArchitecture (SystemDefaultArchitecture arch_kind) // for the default triple. It's probably an artifact of config.guess. if (triple.getOS() == llvm::Triple::Linux && triple.getVendor() == llvm::Triple::UnknownVendor) triple.setVendorName (""); - - const char* distribution_id = GetDistributionId ().AsCString(); - +#if defined(__linux__) + const char *distribution_id = HostInfo::GetDistributionId().data(); +#else + const char *distribution_id = ""; +#endif switch (triple.getArch()) { default: @@ -448,7 +451,7 @@ Host::GetArchitecture (SystemDefaultArchitecture arch_kind) g_supports_32 = g_host_arch_32.IsValid(); g_supports_64 = g_host_arch_64.IsValid(); } - + #endif // #else for #if defined (__APPLE__) if (arch_kind == eSystemDefaultArchitecture32) @@ -462,57 +465,6 @@ Host::GetArchitecture (SystemDefaultArchitecture arch_kind) return g_host_arch_32; } -const ConstString & -Host::GetVendorString() -{ - static ConstString g_vendor; - if (!g_vendor) - { - const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); - const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName(); - g_vendor.SetCStringWithLength(str_ref.data(), str_ref.size()); - } - return g_vendor; -} - -const ConstString & -Host::GetOSString() -{ - static ConstString g_os_string; - if (!g_os_string) - { - const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); - const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName(); - g_os_string.SetCStringWithLength(str_ref.data(), str_ref.size()); - } - return g_os_string; -} - -const ConstString & -Host::GetTargetTriple() -{ - static ConstString g_host_triple; - if (!(g_host_triple)) - { - const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); - g_host_triple.SetCString(host_arch.GetTriple().getTriple().c_str()); - } - return g_host_triple; -} - -// See linux/Host.cpp for Linux-based implementations of this. -// Add your platform-specific implementation to the appropriate host file. -#if !defined(__linux__) - -const ConstString & - Host::GetDistributionId () -{ - static ConstString s_distribution_id; - return s_distribution_id; -} - -#endif // #if !defined(__linux__) - lldb::pid_t Host::GetCurrentProcessID() { @@ -1401,24 +1353,6 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) return false; } - -bool -Host::GetHostname (std::string &s) -{ - char hostname[PATH_MAX]; - hostname[sizeof(hostname) - 1] = '\0'; - if (::gethostname (hostname, sizeof(hostname) - 1) == 0) - { - struct hostent* h = ::gethostbyname (hostname); - if (h) - s.assign (h->h_name); - else - s.assign (hostname); - return true; - } - return false; -} - #ifndef _WIN32 const char * @@ -1506,22 +1440,6 @@ Host::GetEffectiveGroupID () #endif -#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) // see macosx/Host.mm -bool -Host::GetOSBuildString (std::string &s) -{ - s.clear(); - return false; -} - -bool -Host::GetOSKernelDescription (std::string &s) -{ - s.clear(); - return false; -} -#endif - #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) \ && !defined(__linux__) && !defined(_WIN32) uint32_t @@ -1792,7 +1710,7 @@ Host::GetPosixspawnFlags (ProcessLaunchInfo &launch_info) g_use_close_on_exec_flag = eLazyBoolNo; uint32_t major, minor, update; - if (Host::GetOSVersion(major, minor, update)) + if (HostInfo::GetOSVersion(major, minor, update)) { // Kernel panic if we use the POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7 or earlier if (major > 10 || (major == 10 && minor > 7)) @@ -2179,54 +2097,6 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info) #ifndef _WIN32 -size_t -Host::GetPageSize() -{ - return ::getpagesize(); -} - -uint32_t -Host::GetNumberCPUS () -{ - static uint32_t g_num_cores = UINT32_MAX; - if (g_num_cores == UINT32_MAX) - { -#if defined(__APPLE__) or defined (__linux__) or defined (__FreeBSD__) or defined (__FreeBSD_kernel__) - - g_num_cores = ::sysconf(_SC_NPROCESSORS_ONLN); - -#else - - // Assume POSIX support if a host specific case has not been supplied above - g_num_cores = 0; - int num_cores = 0; - size_t num_cores_len = sizeof(num_cores); -#ifdef HW_AVAILCPU - int mib[] = { CTL_HW, HW_AVAILCPU }; -#else - int mib[] = { CTL_HW, HW_NCPU }; -#endif - - /* get the number of CPUs from the system */ - if (sysctl(mib, llvm::array_lengthof(mib), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0)) - { - g_num_cores = num_cores; - } - else - { - mib[1] = HW_NCPU; - num_cores_len = sizeof(num_cores); - if (sysctl(mib, llvm::array_lengthof(mib), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0)) - { - if (num_cores > 0) - g_num_cores = num_cores; - } - } -#endif - } - return g_num_cores; -} - void Host::Kill(lldb::pid_t pid, int signo) { diff --git a/lldb/source/Host/common/HostInfoBase.cpp b/lldb/source/Host/common/HostInfoBase.cpp new file mode 100644 index 00000000000..5433bf0e568 --- /dev/null +++ b/lldb/source/Host/common/HostInfoBase.cpp @@ -0,0 +1,78 @@ +//===-- HostInfoBase.cpp ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/Config.h" + +#include "lldb/Core/ArchSpec.h" +#include "lldb/Host/HostInfoBase.h" +#include "lldb/Host/Host.h" + +#include <thread> + +using namespace lldb; +using namespace lldb_private; + +uint32_t HostInfoBase::m_number_cpus = 0; +std::string HostInfoBase::m_vendor_string; +std::string HostInfoBase::m_os_string; +std::string HostInfoBase::m_host_triple; + +uint32_t +HostInfoBase::GetNumberCPUS() +{ + static bool is_initialized = false; + if (!is_initialized) + { + m_number_cpus = std::thread::hardware_concurrency(); + is_initialized = true; + } + + return m_number_cpus; +} + +llvm::StringRef +HostInfoBase::GetVendorString() +{ + static bool is_initialized = false; + if (!is_initialized) + { + const ArchSpec &host_arch = Host::GetArchitecture(); + const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName(); + m_vendor_string.assign(str_ref.begin(), str_ref.end()); + is_initialized = true; + } + return m_vendor_string; +} + +llvm::StringRef +HostInfoBase::GetOSString() +{ + static bool is_initialized = false; + if (!is_initialized) + { + const ArchSpec &host_arch = Host::GetArchitecture(); + const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName(); + m_os_string.assign(str_ref.begin(), str_ref.end()); + is_initialized = true; + } + return m_os_string; +} + +llvm::StringRef +HostInfoBase::GetTargetTriple() +{ + static bool is_initialized = false; + if (!is_initialized) + { + const ArchSpec &host_arch = Host::GetArchitecture(); + m_host_triple = host_arch.GetTriple().getTriple(); + is_initialized = true; + } + return m_host_triple; +} diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp index 8376463561b..bd13ff76392 100644 --- a/lldb/source/Host/freebsd/Host.cpp +++ b/lldb/source/Host/freebsd/Host.cpp @@ -13,7 +13,6 @@ #include <execinfo.h> #include <sys/types.h> #include <sys/user.h> -#include <sys/utsname.h> #include <sys/sysctl.h> #include <sys/proc.h> @@ -167,56 +166,6 @@ Host::GetEnvironment (StringList &env) return env.GetSize(); } -bool -Host::GetOSVersion(uint32_t &major, - uint32_t &minor, - uint32_t &update) -{ - struct utsname un; - - ::memset(&un, 0, sizeof(utsname)); - if (uname(&un) < 0) - return false; - - int status = sscanf(un.release, "%u.%u", &major, &minor); - return status == 2; -} - -bool -Host::GetOSBuildString (std::string &s) -{ - 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; - } - - s.clear(); - return false; -} - -bool -Host::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; -} - static bool GetFreeBSDProcessArgs (const ProcessInstanceInfoMatch *match_info_ptr, ProcessInstanceInfo &process_info) diff --git a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp new file mode 100644 index 00000000000..b1c42f25f1e --- /dev/null +++ b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp @@ -0,0 +1,63 @@ +//===-- HostInfoFreeBSD.cpp -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/freebsd/HostInfoFreeBSD.h" + +#include <stdio.h> +#include <string.h> +#include <sys/sysctl.h> +#include <sys/utsname.h> + +bool +HostInfoFreeBSD::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) +{ + struct utsname un; + + ::memset(&un, 0, sizeof(utsname)); + if (uname(&un) < 0) + return false; + + int status = sscanf(un.release, "%u.%u", &major, &minor); + return status == 2; +} + +bool +HostInfoFreeBSD::GetOSBuildString(std::string &s) +{ + 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; + } + + s.clear(); + return false; +} + +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; +} diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp index 6c900063c85..a7cca2cb44f 100644 --- a/lldb/source/Host/linux/Host.cpp +++ b/lldb/source/Host/linux/Host.cpp @@ -147,28 +147,6 @@ GetLinuxProcessUserAndGroup (lldb::pid_t pid, ProcessInstanceInfo &process_info, process_info.SetEffectiveGroupID (eGid); } -bool -Host::GetOSVersion(uint32_t &major, - uint32_t &minor, - uint32_t &update) -{ - struct utsname un; - int status; - - if (uname(&un)) - return false; - - status = sscanf(un.release, "%u.%u.%u", &major, &minor, &update); - if (status == 3) - return true; - - // Some kernels omit the update version, so try looking for just "X.Y" and - // set update to 0. - update = 0; - status = sscanf(un.release, "%u.%u", &major, &minor); - return status == 2; -} - lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { @@ -446,114 +424,3 @@ Host::GetEnvironment (StringList &env) env.AppendString(env_entry); return i; } - -const ConstString & -Host::GetDistributionId () -{ - // Try to run 'lbs_release -i', and use that response - // for the distribution id. - - static bool s_evaluated; - static ConstString s_distribution_id; - - if (!s_evaluated) - { - s_evaluated = true; - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST)); - if (log) - log->Printf ("attempting to determine Linux distribution..."); - - // check if the lsb_release command exists at one of the - // following paths - const char *const exe_paths[] = { - "/bin/lsb_release", - "/usr/bin/lsb_release" - }; - - for (size_t exe_index = 0; - exe_index < sizeof (exe_paths) / sizeof (exe_paths[0]); - ++exe_index) - { - const char *const get_distribution_info_exe = exe_paths[exe_index]; - if (access (get_distribution_info_exe, F_OK)) - { - // this exe doesn't exist, move on to next exe - if (log) - log->Printf ("executable doesn't exist: %s", - get_distribution_info_exe); - continue; - } - - // execute the distribution-retrieval command, read output - std::string get_distribution_id_command (get_distribution_info_exe); - get_distribution_id_command += " -i"; - - FILE *file = popen (get_distribution_id_command.c_str (), "r"); - if (!file) - { - if (log) - log->Printf ( - "failed to run command: \"%s\", cannot retrieve " - "platform information", - get_distribution_id_command.c_str ()); - return s_distribution_id; - } - - // retrieve the distribution id string. - char distribution_id[256] = { '\0' }; - if (fgets (distribution_id, sizeof (distribution_id) - 1, file) - != NULL) - { - if (log) - log->Printf ("distribution id command returned \"%s\"", - distribution_id); - - const char *const distributor_id_key = "Distributor ID:\t"; - if (strstr (distribution_id, distributor_id_key)) - { - // strip newlines - std::string id_string (distribution_id + - strlen (distributor_id_key)); - id_string.erase( - std::remove ( - id_string.begin (), - id_string.end (), - '\n'), - id_string.end ()); - - // lower case it and convert whitespace to underscores - std::transform ( - id_string.begin(), - id_string.end (), - id_string.begin (), - [] (char ch) - { return tolower ( isspace (ch) ? '_' : ch ); }); - - s_distribution_id.SetCString (id_string.c_str ()); - if (log) - log->Printf ("distribution id set to \"%s\"", - s_distribution_id.GetCString ()); - } - else - { - if (log) - log->Printf ("failed to find \"%s\" field in \"%s\"", - distributor_id_key, distribution_id); - } - } - else - { - if (log) - log->Printf ( - "failed to retrieve distribution id, \"%s\" returned no" - " lines", get_distribution_id_command.c_str ()); - } - - // clean up the file - pclose(file); - } - } - - return s_distribution_id; -} diff --git a/lldb/source/Host/linux/HostInfoLinux.cpp b/lldb/source/Host/linux/HostInfoLinux.cpp new file mode 100644 index 00000000000..8e620f43ca6 --- /dev/null +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -0,0 +1,149 @@ +//===-- HostInfoLinux.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/Log.h" +#include "lldb/Host/linux/HostInfoLinux.h" + +#include <stdio.h> +#include <string.h> +#include <sys/utsname.h> + +#include <algorithm> + +using namespace lldb_private; + +std::string HostInfoLinux::m_distribution_id; +uint32_t HostInfoLinux::m_os_major = 0; +uint32_t HostInfoLinux::m_os_minor = 0; +uint32_t HostInfoLinux::m_os_update = 0; + +bool +HostInfoLinux::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) +{ + static bool is_initialized = false; + static bool success = false; + + if (!is_initialized) + { + is_initialized = true; + struct utsname un; + + if (uname(&un)) + goto finished; + + int status = sscanf(un.release, "%u.%u.%u", &major, &minor, &update); + if (status == 3) + { + success = true; + goto finished; + } + + // Some kernels omit the update version, so try looking for just "X.Y" and + // set update to 0. + update = 0; + status = sscanf(un.release, "%u.%u", &major, &minor); + success = !!(status == 2); + } + +finished: + major = m_os_major; + minor = m_os_minor; + update = m_os_update; + return success; +} + +llvm::StringRef +HostInfoLinux::GetDistributionId() +{ + static bool is_initialized = false; + // Try to run 'lbs_release -i', and use that response + // for the distribution id. + + if (!is_initialized) + { + is_initialized = true; + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST)); + if (log) + log->Printf("attempting to determine Linux distribution..."); + + // check if the lsb_release command exists at one of the + // following paths + const char *const exe_paths[] = {"/bin/lsb_release", "/usr/bin/lsb_release"}; + + for (size_t exe_index = 0; exe_index < sizeof(exe_paths) / sizeof(exe_paths[0]); ++exe_index) + { + const char *const get_distribution_info_exe = exe_paths[exe_index]; + if (access(get_distribution_info_exe, F_OK)) + { + // this exe doesn't exist, move on to next exe + if (log) + log->Printf("executable doesn't exist: %s", get_distribution_info_exe); + continue; + } + + // execute the distribution-retrieval command, read output + std::string get_distribution_id_command(get_distribution_info_exe); + get_distribution_id_command += " -i"; + + FILE *file = popen(get_distribution_id_command.c_str(), "r"); + if (!file) + { + if (log) + log->Printf("failed to run command: \"%s\", cannot retrieve " + "platform information", + get_distribution_id_command.c_str()); + break; + } + + // retrieve the distribution id string. + char distribution_id[256] = {'\0'}; + if (fgets(distribution_id, sizeof(distribution_id) - 1, file) != NULL) + { + if (log) + log->Printf("distribution id command returned \"%s\"", distribution_id); + + const char *const distributor_id_key = "Distributor ID:\t"; + if (strstr(distribution_id, distributor_id_key)) + { + // strip newlines + std::string id_string(distribution_id + strlen(distributor_id_key)); + id_string.erase(std::remove(id_string.begin(), id_string.end(), '\n'), id_string.end()); + + // lower case it and convert whitespace to underscores + std::transform(id_string.begin(), id_string.end(), id_string.begin(), [](char ch) + { + return tolower(isspace(ch) ? '_' : ch); + }); + + m_distribution_id = id_string; + if (log) + log->Printf("distribution id set to \"%s\"", m_distribution_id.c_str()); + } + else + { + if (log) + log->Printf("failed to find \"%s\" field in \"%s\"", distributor_id_key, distribution_id); + } + } + else + { + if (log) + log->Printf("failed to retrieve distribution id, \"%s\" returned no" + " lines", + get_distribution_id_command.c_str()); + } + + // clean up the file + pclose(file); + } + } + + return m_distribution_id.c_str(); +} diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index 0fa6ea560e3..06664f7be3a 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -871,72 +871,6 @@ Host::GetEnvironment (StringList &env) } - -bool -Host::GetOSBuildString (std::string &s) -{ - 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; - } - - s.clear(); - return false; -} - -bool -Host::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; -} - -bool -Host::GetOSVersion -( - uint32_t &major, - uint32_t &minor, - uint32_t &update -) -{ - static uint32_t g_major = 0; - static uint32_t g_minor = 0; - static uint32_t g_update = 0; - - if (g_major == 0) - { - @autoreleasepool { - NSDictionary *version_info = [NSDictionary dictionaryWithContentsOfFile: - @"/System/Library/CoreServices/SystemVersion.plist"]; - NSString *version_value = [version_info objectForKey:@"ProductVersion"]; - const char *version_str = [version_value UTF8String]; - if (version_str) - Args::StringToVersion(version_str, g_major, g_minor, g_update); - } - } - - if (g_major != 0) - { - major = g_major; - minor = g_minor; - update = g_update; - return true; - } - return false; -} - static bool GetMacOSXProcessCPUType (ProcessInstanceInfo &process_info) { diff --git a/lldb/source/Host/macosx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/HostInfoMacOSX.mm new file mode 100644 index 00000000000..5f154029302 --- /dev/null +++ b/lldb/source/Host/macosx/HostInfoMacOSX.mm @@ -0,0 +1,85 @@ +//===-- HostInfoMacOSX.mm ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/macosx/HostInfoMacOSX.h" +#include "lldb/Interpreter/Args.h" + +// C++ Includes +#include <string> + +// C inclues +#include <sys/sysctl.h> +#include <sys/types.h> + +// Objective C/C++ includes +#include <CoreFoundation/CoreFoundation.h> +#include <Foundation/Foundation.h> +#include <objc/objc-auto.h> + +using namespace lldb_private; + +bool +HostInfoMacOSX::GetOSBuildString(std::string &s) +{ + 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; + } + + s.clear(); + return false; +} + +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; +} + +bool +HostInfoMacOSX::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) +{ + static uint32_t g_major = 0; + static uint32_t g_minor = 0; + static uint32_t g_update = 0; + + if (g_major == 0) + { + @autoreleasepool + { + NSDictionary *version_info = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; + NSString *version_value = [version_info objectForKey:@"ProductVersion"]; + const char *version_str = [version_value UTF8String]; + if (version_str) + Args::StringToVersion(version_str, g_major, g_minor, g_update); + } + } + + if (g_major != 0) + { + major = g_major; + minor = g_minor; + update = g_update; + return true; + } + return false; +} diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp new file mode 100644 index 00000000000..ae65e0ef019 --- /dev/null +++ b/lldb/source/Host/posix/HostInfoPosix.cpp @@ -0,0 +1,39 @@ +//===-- HostInfoPosix.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/posix/HostInfoPosix.h" + +#include <netdb.h> +#include <limits.h> +#include <unistd.h> + +using namespace lldb_private; + +size_t +HostInfoPosix::GetPageSize() +{ + return ::getpagesize(); +} + +bool +HostInfoPosix::GetHostname(std::string &s) +{ + char hostname[PATH_MAX]; + hostname[sizeof(hostname) - 1] = '\0'; + if (::gethostname(hostname, sizeof(hostname) - 1) == 0) + { + struct hostent *h = ::gethostbyname(hostname); + if (h) + s.assign(h->h_name); + else + s.assign(hostname); + return true; + } + return false; +} diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index 9fa265200e4..6511c5aa6fd 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -96,32 +96,6 @@ namespace } } -bool -Host::GetOSVersion(uint32_t &major, - uint32_t &minor, - uint32_t &update) -{ - OSVERSIONINFOEX info; - - ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); -#pragma warning(push) -#pragma warning(disable: 4996) - // Starting with Microsoft SDK for Windows 8.1, this function is deprecated in favor of the - // new Windows Version Helper APIs. Since we don't specify a minimum SDK version, it's easier - // to simply disable the warning rather than try to support both APIs. - if (GetVersionEx((LPOSVERSIONINFO) &info) == 0) { - return false; - } -#pragma warning(pop) - - major = (uint32_t) info.dwMajorVersion; - minor = (uint32_t) info.dwMinorVersion; - update = (uint32_t) info.wServicePackMajor; - - return true; -} - Error Host::LaunchProcess (ProcessLaunchInfo &launch_info) { @@ -211,31 +185,6 @@ Host::Kill(lldb::pid_t pid, int signo) TerminateProcess((HANDLE) pid, 1); } -uint32_t -Host::GetNumberCPUS() -{ - static uint32_t g_num_cores = UINT32_MAX; - if (g_num_cores == UINT32_MAX) - { - SYSTEM_INFO system_info; - ::GetSystemInfo(&system_info); - g_num_cores = system_info.dwNumberOfProcessors; - } - return g_num_cores; -} - -size_t -Host::GetPageSize() -{ - static long g_pagesize = 0; - if (!g_pagesize) - { - SYSTEM_INFO systemInfo; - GetNativeSystemInfo(&systemInfo); - g_pagesize = systemInfo.dwPageSize; - } - return g_pagesize; -} const char * Host::GetSignalAsCString(int signo) diff --git a/lldb/source/Host/windows/HostInfoWindows.cpp b/lldb/source/Host/windows/HostInfoWindows.cpp new file mode 100644 index 00000000000..dfaff795437 --- /dev/null +++ b/lldb/source/Host/windows/HostInfoWindows.cpp @@ -0,0 +1,80 @@ +//===-- HostInfoWindows.cpp -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/windows/windows.h" + +#include "lldb/Host/windows/HostInfoWindows.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/raw_ostream.h" + +using namespace lldb_private; + +size_t +HostInfoWindows::GetPageSize() +{ + SYSTEM_INFO systemInfo; + GetNativeSystemInfo(&systemInfo); + return systemInfo.dwPageSize; +} + +bool +HostInfoWindows::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) +{ + OSVERSIONINFOEX info; + + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); +#pragma warning(push) +#pragma warning(disable : 4996) + // Starting with Microsoft SDK for Windows 8.1, this function is deprecated in favor of the + // new Windows Version Helper APIs. Since we don't specify a minimum SDK version, it's easier + // to simply disable the warning rather than try to support both APIs. + if (GetVersionEx((LPOSVERSIONINFO)&info) == 0) + { + return false; + } +#pragma warning(pop) + + major = info.dwMajorVersion; + minor = info.dwMinorVersion; + update = info.wServicePackMajor; + + return true; +} + +bool +HostInfoWindows::GetOSBuildString(std::string &s) +{ + s.clear(); + uint32_t major, minor, update; + if (!GetOSVersion(major, minor, update)) + return false; + + llvm::raw_string_ostream stream(s); + stream << "Windows NT " << major << "." << minor << "." << update; + return true; +} + +bool +HostInfoWindows::GetOSKernelDescription(std::string &s) +{ + return GetOSBuildString(s); +} + +bool +HostInfoWindows::GetHostname(std::string &s) +{ + char buffer[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; + if (!::GetComputerName(buffer, &dwSize)) + return false; + + s.assign(buffer, buffer + dwSize); + return true; +} |