Move some Host logic into HostInfo class.

This patch creates a HostInfo class, a static class used to answer
basic queries about the host platform.  As part of this change,
some functionality is moved from Host to HostInfo, and relevant
fixups are performed in the rest of the codebase.

This is part of a larger effort to isolate more code in the Host
layer into platform-specific groups, to make it easier to make
platform specific changes for a particular Host without breaking
other hosts.

Reviewed by: Greg Clayton

Differential Revision: http://reviews.llvm.org/D4963

llvm-svn: 215992
This commit is contained in:
Zachary Turner 2014-08-19 17:18:29 +00:00
parent 91b2fa2a9a
commit 97a14e60b2
32 changed files with 920 additions and 554 deletions

View File

@ -238,7 +238,7 @@ public:
///
/// This will be something like "ubuntu", "fedora", etc. on Linux.
/// This should be the same value returned by
/// Host::GetDistributionId ().
/// HostInfo::GetDistributionId ().
///------------------------------------------------------------------
void
SetDistributionId (const char* distribution_id);

View File

@ -91,49 +91,6 @@ public:
lldb::pid_t pid,
bool monitor_signals);
//------------------------------------------------------------------
/// Get the host page size.
///
/// @return
/// The size in bytes of a VM page on the host system.
//------------------------------------------------------------------
static size_t
GetPageSize();
//------------------------------------------------------------------
/// Returns the endianness of the host system.
///
/// @return
/// Returns the endianness of the host system as a lldb::ByteOrder
/// enumeration.
//------------------------------------------------------------------
static lldb::ByteOrder
GetByteOrder ();
//------------------------------------------------------------------
/// Returns the number of CPUs on this current host.
///
/// @return
/// Number of CPUs on this current host, or zero if the number
/// of CPUs can't be determined on this host.
//------------------------------------------------------------------
static uint32_t
GetNumberCPUS ();
static bool
GetOSVersion (uint32_t &major,
uint32_t &minor,
uint32_t &update);
static bool
GetOSBuildString (std::string &s);
static bool
GetOSKernelDescription (std::string &s);
static bool
GetHostname (std::string &s);
static const char *
GetUserName (uint32_t uid, std::string &user_name);
@ -182,50 +139,6 @@ public:
static const ArchSpec &
GetArchitecture (SystemDefaultArchitecture arch_kind = eSystemDefaultArchitecture);
//------------------------------------------------------------------
/// Gets the host vendor string.
///
/// @return
/// A const string object containing the host vendor name.
//------------------------------------------------------------------
static const ConstString &
GetVendorString ();
//------------------------------------------------------------------
/// Gets the host Operating System (OS) string.
///
/// @return
/// A const string object containing the host OS name.
//------------------------------------------------------------------
static const ConstString &
GetOSString ();
//------------------------------------------------------------------
/// Gets the host target triple as a const string.
///
/// @return
/// A const string object containing the host target triple.
//------------------------------------------------------------------
static const ConstString &
GetTargetTriple ();
//------------------------------------------------------------------
/// Gets the name of the distribution (i.e. distributor id).
///
/// On Linux, this will return the equivalent of lsb_release -i.
/// Android will return 'android'. Other systems may return
/// nothing.
///
/// @return
/// A ConstString reference containing the OS distribution id.
/// The return string will be all lower case, with whitespace
/// replaced with underscores. The return string will be
/// empty (result.AsCString() will return NULL) if the distribution
/// cannot be obtained.
//------------------------------------------------------------------
static const ConstString &
GetDistributionId ();
//------------------------------------------------------------------
/// Get the process ID for the calling process.
///

View File

@ -0,0 +1,61 @@
//===-- HostInfoBase.h ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_HostInfo_h_
#define lldb_Host_HostInfo_h_
//----------------------------------------------------------------------
/// @class HostInfo HostInfo.h "lldb/Host/HostInfo.h"
/// @brief A class that provides host computer information.
///
/// HostInfo is a class that answers information about the host operating
/// system. Note that HostInfo is NOT intended to be used to manipulate or
/// control the operating system.
///
/// HostInfo is implemented in an OS-specific class (for example
/// HostInfoWindows) in a separate file, and then typedefed to HostInfo here.
/// Users of the class reference it as HostInfo::method().
///
/// Not all hosts provide the same functionality. It is important that methods
/// only be implemented at the lowest level at which they make sense. It should
/// be up to the clients of the class to ensure that they not attempt to call a
/// method which doesn't make sense for a particular platform. For example,
/// when implementing a method that only makes sense on a posix-compliant
/// system, implement it on HostInfoPosix, and not on HostInfoBase with a
/// default implementation. This way, users of HostInfo are required to think
/// about the implications of calling a particular method and if used in a
/// context where the method doesn't make sense, will generate a compiler error.
///
//----------------------------------------------------------------------
#if defined(_WIN32)
#include "lldb/Host/windows/HostInfoWindows.h"
#define HOST_INFO_TYPE HostInfoWindows
#elif defined(__linux__)
#include "lldb/Host/linux/HostInfoLinux.h"
#define HOST_INFO_TYPE HostInfoLinux
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include "lldb/Host/freebsd/HostInfoFreeBSD.h"
#define HOST_INFO_TYPE HostInfoFreeBSD
#elif defined(__APPLE__)
#include "lldb/Host/macosx/HostInfoMacOSX.h"
#define HOST_INFO_TYPE HostInfoMacOSX
#else
#include "lldb/Host/posix/HostInfoPosix.h"
#define HOST_INFO_TYPE HostInfoPosix
#endif
namespace lldb_private
{
typedef HOST_INFO_TYPE HostInfo;
}
#undef HOST_INFO_TYPE
#endif

View File

@ -0,0 +1,71 @@
//===-- HostInfoBase.h ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_HostInfoBase_h_
#define lldb_Host_HostInfoBase_h_
#include "llvm/ADT/StringRef.h"
#include <stdint.h>
#include <string>
namespace lldb_private
{
class HostInfoBase
{
private:
// Static class, unconstructable.
HostInfoBase() {}
~HostInfoBase() {}
public:
//------------------------------------------------------------------
/// Returns the number of CPUs on this current host.
///
/// @return
/// Number of CPUs on this current host, or zero if the number
/// of CPUs can't be determined on this host.
//------------------------------------------------------------------
static uint32_t GetNumberCPUS();
//------------------------------------------------------------------
/// Gets the host vendor string.
///
/// @return
/// A const string object containing the host vendor name.
//------------------------------------------------------------------
static llvm::StringRef GetVendorString();
//------------------------------------------------------------------
/// Gets the host Operating System (OS) string.
///
/// @return
/// A const string object containing the host OS name.
//------------------------------------------------------------------
static llvm::StringRef GetOSString();
//------------------------------------------------------------------
/// Gets the host target triple as a const string.
///
/// @return
/// A const string object containing the host target triple.
//------------------------------------------------------------------
static llvm::StringRef GetTargetTriple();
protected:
static uint32_t m_number_cpus;
static std::string m_vendor_string;
static std::string m_os_string;
static std::string m_host_triple;
};
}
#endif

View File

@ -0,0 +1,27 @@
//===-- HostInfoFreeBSD.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_freebsd_HostInfoFreeBSD_h_
#define lldb_Host_freebsd_HostInfoFreeBSD_h_
#include "lldb/Host/posix/HostInfoPosix.h"
namespace lldb_private
{
class HostInfoFreeBSD : public HostInfoPosix
{
public:
bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
bool GetOSBuildString(std::string &s);
bool GetOSKernelDescription(std::string &s);
};
}
#endif

View File

@ -0,0 +1,40 @@
//===-- HostInfoLinux.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_linux_HostInfoLinux_h_
#define lldb_Host_linux_HostInfoLinux_h_
#include "lldb/Host/posix/HostInfoPosix.h"
#include "llvm/ADT/StringRef.h"
#include <string>
namespace lldb_private
{
class HostInfoLinux : public HostInfoPosix
{
private:
// Static class, unconstructable.
HostInfoLinux();
~HostInfoLinux();
public:
static bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
static llvm::StringRef GetDistributionId();
protected:
static std::string m_distribution_id;
static uint32_t m_os_major;
static uint32_t m_os_minor;
static uint32_t m_os_update;
};
}
#endif

View File

@ -0,0 +1,32 @@
//===-- HostInfoMacOSX.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_macosx_HostInfoMacOSX_h_
#define lldb_Host_macosx_HostInfoMacOSX_h_
#include "lldb/Host/posix/HostInfoPosix.h"
namespace lldb_private
{
class HostInfoMacOSX : public HostInfoPosix
{
private:
// Static class, unconstructable.
HostInfoMacOSX();
~HostInfoMacOSX();
public:
static bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
static bool GetOSBuildString(std::string &s);
static bool GetOSKernelDescription(std::string &s);
};
}
#endif

View File

@ -0,0 +1,26 @@
//===-- HostInfoPosix.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_posix_HostInfoPosix_h_
#define lldb_Host_posix_HostInfoPosix_h_
#include "lldb/Host/HostInfoBase.h"
namespace lldb_private
{
class HostInfoPosix : public HostInfoBase
{
public:
static size_t GetPageSize();
static bool GetHostname(std::string &s);
};
}
#endif

View File

@ -0,0 +1,35 @@
//===-- HostInfoWindows.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_Host_windows_HostInfoWindows_h_
#define lldb_Host_windows_HostInfoWindows_h_
#include "lldb/Host/HostInfoBase.h"
namespace lldb_private
{
class HostInfoWindows : public HostInfoBase
{
private:
// Static class, unconstructable.
HostInfoWindows();
~HostInfoWindows();
public:
static size_t GetPageSize();
static bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
static bool GetOSBuildString(std::string &s);
static bool GetOSKernelDescription(std::string &s);
static bool GetHostname(std::string &s);
};
}
#endif

View File

@ -246,7 +246,7 @@ namespace lldb_private {
//
// Remote classes must be connected for this to succeed. Local
// subclasses don't need to override this function as it will just
// call the Host::GetOSVersion().
// call the HostInfo::GetOSVersion().
//------------------------------------------------------------------
virtual bool
GetRemoteOSVersion ()
@ -929,7 +929,7 @@ namespace lldb_private {
// being connected. For remote platforms, we might set the version ahead
// of time before we actually connect and this version might change when
// we actually connect to a remote platform. For the host platform this
// will be set to the once we call Host::GetOSVersion().
// will be set to the once we call HostInfo::GetOSVersion().
bool m_os_version_set_while_connected;
bool m_system_arch_set_while_connected;
ConstString m_sdk_sysroot; // the root location of where the SDK files are all located

View File

@ -585,6 +585,10 @@
3FDFDDBD199C3A06009756A7 /* FileAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */; };
3FDFDDBF199D345E009756A7 /* FileCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBE199D345E009756A7 /* FileCache.cpp */; };
3FDFDDC6199D37ED009756A7 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDC5199D37ED009756A7 /* FileSystem.cpp */; };
3FDFE52C19A2917A009756A7 /* HostInfoMacOSX.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFE52B19A2917A009756A7 /* HostInfoMacOSX.mm */; };
3FDFE53119A292F0009756A7 /* HostInfoPosix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFE53019A292F0009756A7 /* HostInfoPosix.cpp */; };
3FDFE53319A29304009756A7 /* HostInfoPosix.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FDFE53219A29304009756A7 /* HostInfoPosix.h */; };
3FDFE53519A29327009756A7 /* HostInfoBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFE53419A29327009756A7 /* HostInfoBase.cpp */; };
449ACC98197DEA0B008D175E /* FastDemangle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 449ACC96197DE9EC008D175E /* FastDemangle.cpp */; };
490A36C0180F0E6F00BA31F8 /* PlatformWindows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490A36BD180F0E6F00BA31F8 /* PlatformWindows.cpp */; };
490A36C2180F0E9300BA31F8 /* PlatformWindows.h in Headers */ = {isa = PBXBuildFile; fileRef = 490A36BE180F0E6F00BA31F8 /* PlatformWindows.h */; };
@ -1746,6 +1750,30 @@
3FDFDDC0199D34E2009756A7 /* FileCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FileCache.h; path = include/lldb/Host/FileCache.h; sourceTree = "<group>"; };
3FDFDDC1199D34E2009756A7 /* FileSystem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FileSystem.h; path = include/lldb/Host/FileSystem.h; sourceTree = "<group>"; };
3FDFDDC5199D37ED009756A7 /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileSystem.cpp; path = source/Host/posix/FileSystem.cpp; sourceTree = "<group>"; };
3FDFE52B19A2917A009756A7 /* HostInfoMacOSX.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = HostInfoMacOSX.mm; path = source/Host/macosx/HostInfoMacOSX.mm; sourceTree = "<group>"; };
3FDFE52D19A291AF009756A7 /* HostInfoMacOSX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = HostInfoMacOSX.h; path = include/lldb/Host/macosx/HostInfoMacOSX.h; sourceTree = "<group>"; };
3FDFE53019A292F0009756A7 /* HostInfoPosix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HostInfoPosix.cpp; path = source/Host/posix/HostInfoPosix.cpp; sourceTree = "<group>"; };
3FDFE53219A29304009756A7 /* HostInfoPosix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HostInfoPosix.h; path = include/lldb/Host/posix/HostInfoPosix.h; sourceTree = "<group>"; };
3FDFE53419A29327009756A7 /* HostInfoBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HostInfoBase.cpp; sourceTree = "<group>"; };
3FDFE53619A2933E009756A7 /* HostInfoLinux.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HostInfoLinux.cpp; sourceTree = "<group>"; };
3FDFE53719A2936B009756A7 /* HostInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = HostInfo.h; path = include/lldb/Host/HostInfo.h; sourceTree = "<group>"; };
3FDFE53819A2936B009756A7 /* HostInfoBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = HostInfoBase.h; path = include/lldb/Host/HostInfoBase.h; sourceTree = "<group>"; };
3FDFE53B19A293B3009756A7 /* HostInfoFreeBSD.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = HostInfoFreeBSD.cpp; path = source/Host/freebsd/HostInfoFreeBSD.cpp; sourceTree = "<group>"; };
3FDFE53C19A293CA009756A7 /* Config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Config.h; path = include/lldb/Host/freebsd/Config.h; sourceTree = "<group>"; };
3FDFE53D19A293CA009756A7 /* HostInfoFreeBSD.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = HostInfoFreeBSD.h; path = include/lldb/Host/freebsd/HostInfoFreeBSD.h; sourceTree = "<group>"; };
3FDFE53F19A29448009756A7 /* Condition.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Condition.cpp; path = source/Host/windows/Condition.cpp; sourceTree = "<group>"; };
3FDFE54019A29448009756A7 /* EditLineWin.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = EditLineWin.cpp; path = source/Host/windows/EditLineWin.cpp; sourceTree = "<group>"; };
3FDFE54119A29448009756A7 /* FileSystem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = FileSystem.cpp; path = source/Host/windows/FileSystem.cpp; sourceTree = "<group>"; };
3FDFE54219A29448009756A7 /* Host.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Host.cpp; path = source/Host/windows/Host.cpp; sourceTree = "<group>"; };
3FDFE54319A29448009756A7 /* HostInfoWindows.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = HostInfoWindows.cpp; path = source/Host/windows/HostInfoWindows.cpp; sourceTree = "<group>"; };
3FDFE54419A29448009756A7 /* Mutex.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Mutex.cpp; path = source/Host/windows/Mutex.cpp; sourceTree = "<group>"; };
3FDFE54519A29448009756A7 /* ProcessRunLock.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = ProcessRunLock.cpp; path = source/Host/windows/ProcessRunLock.cpp; sourceTree = "<group>"; };
3FDFE54619A29448009756A7 /* Windows.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Windows.cpp; path = source/Host/windows/Windows.cpp; sourceTree = "<group>"; };
3FDFE54719A2946B009756A7 /* AutoHandle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AutoHandle.h; path = include/lldb/Host/windows/AutoHandle.h; sourceTree = "<group>"; };
3FDFE54819A2946B009756A7 /* editlinewin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = editlinewin.h; path = include/lldb/Host/windows/editlinewin.h; sourceTree = "<group>"; };
3FDFE54919A2946B009756A7 /* HostInfoWindows.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = HostInfoWindows.h; path = include/lldb/Host/windows/HostInfoWindows.h; sourceTree = "<group>"; };
3FDFE54A19A2946B009756A7 /* win32.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = win32.h; path = include/lldb/Host/windows/win32.h; sourceTree = "<group>"; };
3FDFE54B19A2946B009756A7 /* windows.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = windows.h; path = include/lldb/Host/windows/windows.h; sourceTree = "<group>"; };
449ACC96197DE9EC008D175E /* FastDemangle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FastDemangle.cpp; path = source/Core/FastDemangle.cpp; sourceTree = "<group>"; };
4906FD4012F2255300A2A77C /* ASTDumper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTDumper.cpp; path = source/Expression/ASTDumper.cpp; sourceTree = "<group>"; };
4906FD4412F2257600A2A77C /* ASTDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTDumper.h; path = include/lldb/Expression/ASTDumper.h; sourceTree = "<group>"; };
@ -2283,6 +2311,7 @@
isa = PBXGroup;
children = (
233B009D19610D6B0090E598 /* Host.cpp */,
3FDFE53619A2933E009756A7 /* HostInfoLinux.cpp */,
);
name = linux;
path = source/Host/linux;
@ -3464,9 +3493,11 @@
isa = PBXGroup;
children = (
69A01E1A1236C5D400C660B5 /* common */,
3FDFE53919A29399009756A7 /* freebsd */,
233B009C19610D130090E598 /* linux */,
26BC7EE510F1B88100F91463 /* MacOSX */,
3FDFDDC4199D37BE009756A7 /* posix */,
3FDFE53E19A2940E009756A7 /* windows */,
26BC7DD210F1B7D500F91463 /* Condition.h */,
266F5CBB12FC846200DFCE33 /* Config.h */,
9456F2231616645A00656F91 /* DynamicLibrary.h */,
@ -3478,6 +3509,8 @@
26FA4315130103F400E71120 /* FileSpec.h */,
3FDFDDC1199D34E2009756A7 /* FileSystem.h */,
26BC7DD410F1B7D500F91463 /* Host.h */,
3FDFE53719A2936B009756A7 /* HostInfo.h */,
3FDFE53819A2936B009756A7 /* HostInfoBase.h */,
236124A61986B50E004EFC37 /* IoObject.h */,
26BC7DD510F1B7D500F91463 /* Mutex.h */,
232CB60B191E00CC00EF39FC /* NativeBreakpoint.cpp */,
@ -3713,6 +3746,8 @@
26BC7EE510F1B88100F91463 /* MacOSX */ = {
isa = PBXGroup;
children = (
3FDFE52D19A291AF009756A7 /* HostInfoMacOSX.h */,
3FDFE52B19A2917A009756A7 /* HostInfoMacOSX.mm */,
26BC7EED10F1B8AD00F91463 /* CFCBundle.cpp */,
26BC7EEE10F1B8AD00F91463 /* CFCBundle.h */,
26BC7EEF10F1B8AD00F91463 /* CFCData.cpp */,
@ -3927,11 +3962,43 @@
3FDFDDC4199D37BE009756A7 /* posix */ = {
isa = PBXGroup;
children = (
3FDFE53219A29304009756A7 /* HostInfoPosix.h */,
3FDFE53019A292F0009756A7 /* HostInfoPosix.cpp */,
3FDFDDC5199D37ED009756A7 /* FileSystem.cpp */,
);
name = posix;
sourceTree = "<group>";
};
3FDFE53919A29399009756A7 /* freebsd */ = {
isa = PBXGroup;
children = (
3FDFE53C19A293CA009756A7 /* Config.h */,
3FDFE53D19A293CA009756A7 /* HostInfoFreeBSD.h */,
3FDFE53B19A293B3009756A7 /* HostInfoFreeBSD.cpp */,
);
name = freebsd;
sourceTree = "<group>";
};
3FDFE53E19A2940E009756A7 /* windows */ = {
isa = PBXGroup;
children = (
3FDFE54719A2946B009756A7 /* AutoHandle.h */,
3FDFE53F19A29448009756A7 /* Condition.cpp */,
3FDFE54819A2946B009756A7 /* editlinewin.h */,
3FDFE54019A29448009756A7 /* EditLineWin.cpp */,
3FDFE54119A29448009756A7 /* FileSystem.cpp */,
3FDFE54219A29448009756A7 /* Host.cpp */,
3FDFE54919A2946B009756A7 /* HostInfoWindows.h */,
3FDFE54319A29448009756A7 /* HostInfoWindows.cpp */,
3FDFE54419A29448009756A7 /* Mutex.cpp */,
3FDFE54519A29448009756A7 /* ProcessRunLock.cpp */,
3FDFE54A19A2946B009756A7 /* win32.h */,
3FDFE54B19A2946B009756A7 /* windows.h */,
3FDFE54619A29448009756A7 /* Windows.cpp */,
);
name = windows;
sourceTree = "<group>";
};
490A36BA180F0E6F00BA31F8 /* Windows */ = {
isa = PBXGroup;
children = (
@ -4019,17 +4086,18 @@
69A01E1A1236C5D400C660B5 /* common */ = {
isa = PBXGroup;
children = (
AF37E10917C861F20061E18E /* ProcessRunLock.cpp */,
9456F2211616644B00656F91 /* DynamicLibrary.cpp */,
26CFDCA2186163A4000E63E5 /* Editline.cpp */,
260C6EA213011581005E16B0 /* File.cpp */,
26FA43171301048600E71120 /* FileSpec.cpp */,
69A01E1B1236C5D400C660B5 /* Condition.cpp */,
69A01E1C1236C5D400C660B5 /* Host.cpp */,
3FDFE53419A29327009756A7 /* HostInfoBase.cpp */,
236124A21986B4E2004EFC37 /* IoObject.cpp */,
69A01E1E1236C5D400C660B5 /* Mutex.cpp */,
A36FF33B17D8E94600244D40 /* OptionParser.cpp */,
260A39A719647A4E004B4130 /* Pipe.cpp */,
AF37E10917C861F20061E18E /* ProcessRunLock.cpp */,
236124A31986B4E2004EFC37 /* Socket.cpp */,
69A01E1F1236C5D400C660B5 /* Symbols.cpp */,
268DA873130095ED00C9483A /* Terminal.cpp */,
@ -4283,6 +4351,7 @@
AF0F6E511739A76D009180FE /* RegisterContextKDP_arm64.h in Headers */,
260CC63A15D04377002BF2E0 /* OptionValueUUID.h in Headers */,
260A248E15D06C50009981B0 /* OptionValues.h in Headers */,
3FDFE53319A29304009756A7 /* HostInfoPosix.h in Headers */,
AF061F88182C97ED00B6A19C /* RegisterContextHistory.h in Headers */,
26DAED6015D327A200E15819 /* OptionValuePathMappings.h in Headers */,
26ACEC2815E077AE00E94760 /* Property.h in Headers */,
@ -4874,6 +4943,7 @@
2689008313353E2200698AC0 /* CommandObjectMultiword.cpp in Sources */,
2689008413353E2200698AC0 /* CommandObjectRegexCommand.cpp in Sources */,
2689008513353E2200698AC0 /* CommandReturnObject.cpp in Sources */,
3FDFE53519A29327009756A7 /* HostInfoBase.cpp in Sources */,
26474CBE18D0CB2D0073DEBA /* RegisterContextMach_i386.cpp in Sources */,
2689008613353E2200698AC0 /* Options.cpp in Sources */,
2689008713353E2200698AC0 /* ScriptInterpreter.cpp in Sources */,
@ -4919,7 +4989,9 @@
94D0B10C16D5535900EA9C70 /* LibCxx.cpp in Sources */,
268900C513353E5F00698AC0 /* DWARFDIECollection.cpp in Sources */,
268900C613353E5F00698AC0 /* DWARFFormValue.cpp in Sources */,
3FDFE53119A292F0009756A7 /* HostInfoPosix.cpp in Sources */,
233B007D1960C9F90090E598 /* ProcessInfo.cpp in Sources */,
3FDFE52C19A2917A009756A7 /* HostInfoMacOSX.mm in Sources */,
268900C713353E5F00698AC0 /* DWARFLocationDescription.cpp in Sources */,
26BC17B118C7F4CB00D2196D /* ThreadElfCore.cpp in Sources */,
268900C813353E5F00698AC0 /* DWARFLocationList.cpp in Sources */,

View File

@ -24,7 +24,7 @@
#include "lldb/Core/Error.h"
#include "lldb/Host/File.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Core/Log.h"
#include "lldb/lldb-private-log.h"
@ -268,7 +268,7 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
if (error.GetError() == EINVAL)
{
// We may still have a shot at memory mapping if we align things correctly
size_t page_offset = offset % Host::GetPageSize();
size_t page_offset = offset % HostInfo::GetPageSize();
if (page_offset != 0)
{
m_mmap_addr = (uint8_t *)::mmap(NULL, length + page_offset, prot, flags, fd, offset - page_offset);

View File

@ -31,7 +31,7 @@
#include "lldb/Expression/IRExecutionUnit.h"
#include "lldb/Expression/IRInterpreter.h"
#include "lldb/Expression/Materializer.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Function.h"
@ -898,7 +898,7 @@ ClangUserExpression::Execute (Stream &error_stream,
lldb::addr_t function_stack_pointer = user_expression_plan->GetFunctionStackPointer();
function_stack_bottom = function_stack_pointer - Host::GetPageSize();
function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
function_stack_top = function_stack_pointer;
if (log)

View File

@ -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()

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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;
}

View File

@ -28,8 +28,10 @@
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MathExtras.h"
#define CASE_AND_STREAM(s, def, width) \
@ -1277,8 +1279,8 @@ ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
const ArchSpec host_arch32 = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
if (host_arch32.GetCore() == arch_spec.GetCore())
{
arch_spec.GetTriple().setOSName (Host::GetOSString().GetCString());
arch_spec.GetTriple().setVendorName(Host::GetVendorString().GetCString());
arch_spec.GetTriple().setOSName(HostInfo::GetOSString().data());
arch_spec.GetTriple().setVendorName(HostInfo::GetVendorString().data());
}
}
break;
@ -1287,8 +1289,8 @@ ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
const ArchSpec host_arch64 = Host::GetArchitecture (Host::eSystemDefaultArchitecture64);
if (host_arch64.GetCore() == arch_spec.GetCore())
{
arch_spec.GetTriple().setOSName (Host::GetOSString().GetCString());
arch_spec.GetTriple().setVendorName(Host::GetVendorString().GetCString());
arch_spec.GetTriple().setOSName(HostInfo::GetOSString().data());
arch_spec.GetTriple().setVendorName(HostInfo::GetVendorString().data());
}
}
break;

View File

@ -27,6 +27,7 @@
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
@ -261,7 +262,9 @@ PlatformMacOSX::GetFileWithUUID (const lldb_private::FileSpec &platform_file,
if (IsRemote() && m_remote_platform_sp)
{
std::string local_os_build;
Host::GetOSBuildString(local_os_build);
#if !defined(__linux__)
HostInfo::GetOSBuildString(local_os_build);
#endif
std::string remote_os_build;
m_remote_platform_sp->GetOSBuildString(remote_os_build);
if (local_os_build.compare(remote_os_build) == 0)

View File

@ -23,6 +23,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Module.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
@ -662,7 +663,7 @@ PlatformWindows::GetStatus (Stream &strm)
uint32_t major;
uint32_t minor;
uint32_t update;
if (!Host::GetOSVersion(major, minor, update))
if (!HostInfo::GetOSVersion(major, minor, update))
{
strm << "Windows";
return;

View File

@ -27,6 +27,7 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Host/Endian.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/TimeValue.h"
#include "lldb/Target/Target.h"
@ -2779,7 +2780,7 @@ GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort (lldb::pid_t &pid, const
hostname = remote_accept_hostname;
else
{
if (Host::GetHostname (hostname))
if (HostInfo::GetHostname(hostname))
{
// Make the GDB server we launch only accept connections from this host
stream.Printf("host:%s;", hostname.c_str());

View File

@ -33,6 +33,7 @@
#include "lldb/Host/File.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/TimeValue.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/Platform.h"
@ -1229,7 +1230,7 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
uint32_t major = UINT32_MAX;
uint32_t minor = UINT32_MAX;
uint32_t update = UINT32_MAX;
if (Host::GetOSVersion (major, minor, update))
if (HostInfo::GetOSVersion(major, minor, update))
{
if (major != UINT32_MAX)
{
@ -1245,18 +1246,21 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
}
std::string s;
if (Host::GetOSBuildString (s))
#if !defined(__linux__)
if (HostInfo::GetOSBuildString(s))
{
response.PutCString ("os_build:");
response.PutCStringAsRawHex8(s.c_str());
response.PutChar(';');
}
if (Host::GetOSKernelDescription (s))
if (HostInfo::GetOSKernelDescription(s))
{
response.PutCString ("os_kernel:");
response.PutCStringAsRawHex8(s.c_str());
response.PutChar(';');
}
#endif
#if defined(__APPLE__)
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
@ -1267,7 +1271,7 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
response.PutCStringAsRawHex8("127.0.0.1");
response.PutChar(';');
#else // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
if (Host::GetHostname (s))
if (HostInfo::GetHostname(s))
{
response.PutCString ("hostname:");
response.PutCStringAsRawHex8(s.c_str());
@ -1276,7 +1280,7 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
#endif // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
#else // #if defined(__APPLE__)
if (Host::GetHostname (s))
if (HostInfo::GetHostname(s))
{
response.PutCString ("hostname:");
response.PutCStringAsRawHex8(s.c_str());

View File

@ -21,6 +21,7 @@
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/Utils.h"
@ -349,9 +350,7 @@ Platform::GetOSVersion (uint32_t &major,
if (!success)
{
// We have a local host platform
success = Host::GetOSVersion (m_major_os_version,
m_minor_os_version,
m_update_os_version);
success = HostInfo::GetOSVersion(m_major_os_version, m_minor_os_version, m_update_os_version);
m_os_version_set_while_connected = success;
}
}
@ -398,8 +397,14 @@ Platform::GetOSVersion (uint32_t &major,
bool
Platform::GetOSBuildString (std::string &s)
{
s.clear();
if (IsHost())
return Host::GetOSBuildString (s);
#if !defined(__linux__)
return HostInfo::GetOSBuildString(s);
#else
return false;
#endif
else
return GetRemoteOSBuildString (s);
}
@ -408,7 +413,11 @@ bool
Platform::GetOSKernelDescription (std::string &s)
{
if (IsHost())
return Host::GetOSKernelDescription (s);
#if !defined(__linux__)
return HostInfo::GetOSKernelDescription(s);
#else
return false;
#endif
else
return GetRemoteOSKernelDescription (s);
}
@ -801,8 +810,8 @@ Platform::SetOSVersion (uint32_t major,
{
if (IsHost())
{
// We don't need anyone setting the OS version for the host platform,
// we should be able to figure it out by calling Host::GetOSVersion(...).
// We don't need anyone setting the OS version for the host platform,
// we should be able to figure it out by calling HostInfo::GetOSVersion(...).
return false;
}
else

View File

@ -21,6 +21,7 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/Stream.h"
#include "lldb/Expression/ClangUserExpression.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
@ -87,7 +88,7 @@ ThreadPlanCallUserExpression::MischiefManaged ()
lldb::addr_t function_stack_bottom;
lldb::addr_t function_stack_pointer = GetFunctionStackPointer();
function_stack_bottom = function_stack_pointer - Host::GetPageSize();
function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
function_stack_top = function_stack_pointer;
StreamString error_stream;