merge lldb-platform-work branch (and assorted fixes) into trunk

    Summary:
    This merge brings in the improved 'platform' command that knows how to
    interface with remote machines; that is, query OS/kernel information, push
    and pull files, run shell commands, etc... and implementation for the new
    communication packets that back that interface, at least on Darwin based
    operating systems via the POSIXPlatform class. Linux support is coming soon.

    Verified the test suite runs cleanly on Linux (x86_64), build OK on Mac OS
    X Mountain Lion.

    Additional improvements (not in the source SVN branch 'lldb-platform-work'):
    - cmake build scripts for lldb-platform
    - cleanup test suite
    - documentation stub for qPlatform_RunCommand
    - use log class instead of printf() directly
    - reverted work-in-progress-looking changes from test/types/TestAbstract.py that work towards running the test suite remotely.
    - add new logging category 'platform'

    Reviewers: Matt Kopec, Greg Clayton

    Review: http://llvm-reviews.chandlerc.com/D1493

llvm-svn: 189295
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index 343312f..ec33bca 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -83,6 +83,20 @@
     Open (path, options, permissions);
 }
 
+File::File (const FileSpec& filespec,
+            uint32_t options,
+            uint32_t permissions) :
+    m_descriptor (kInvalidDescriptor),
+    m_stream (kInvalidStream),
+    m_options (0),
+    m_owned (false)
+{
+    if (filespec)
+    {
+        Open (filespec.GetPath().c_str(), options, permissions);
+    }
+}
+
 File::File (const File &rhs) :
     m_descriptor (kInvalidDescriptor),
     m_stream (kInvalidStream),
@@ -261,6 +275,53 @@
     return error;
 }
 
+uint32_t
+File::GetPermissions (const char *path, Error &error)
+{
+    if (path && path[0])
+    {
+        struct stat file_stats;
+        if (::stat (path, &file_stats) == -1)
+            error.SetErrorToErrno();
+        else
+        {
+            error.Clear();
+            return file_stats.st_mode; // All bits from lldb_private::File::Permissions match those in POSIX mode bits
+        }
+    }
+    else
+    {
+        if (path)
+            error.SetErrorString ("invalid path");
+        else
+            error.SetErrorString ("empty path");        
+    }
+    return 0;
+}
+
+uint32_t
+File::GetPermissions(Error &error) const
+{
+    int fd = GetDescriptor();
+    if (fd != kInvalidDescriptor)
+    {
+        struct stat file_stats;
+        if (::fstat (fd, &file_stats) == -1)
+            error.SetErrorToErrno();
+        else
+        {
+            error.Clear();
+            return file_stats.st_mode; // All bits from lldb_private::File::Permissions match those in POSIX mode bits
+        }
+    }
+    else
+    {
+        error.SetErrorString ("invalid file descriptor");
+    }
+    return 0;
+}
+
+
 Error
 File::Close ()
 {
@@ -755,3 +816,51 @@
     }
     return result;
 }
+
+mode_t
+File::ConvertOpenOptionsForPOSIXOpen (uint32_t open_options)
+{
+    mode_t mode = 0;
+    if (open_options & eOpenOptionRead && open_options & eOpenOptionWrite)
+        mode |= O_RDWR;
+    else if (open_options & eOpenOptionWrite)
+        mode |= O_WRONLY;
+    
+    if (open_options & eOpenOptionAppend)
+        mode |= O_APPEND;
+
+    if (open_options & eOpenOptionTruncate)
+        mode |= O_TRUNC;
+
+    if (open_options & eOpenOptionNonBlocking)
+        mode |= O_NONBLOCK;
+
+    if (open_options & eOpenOptionCanCreateNewOnly)
+        mode |= O_CREAT | O_EXCL;
+    else if (open_options & eOpenOptionCanCreate)
+        mode |= O_CREAT;
+
+    return mode;
+}
+
+#define	O_RDONLY	0x0000		/* open for reading only */
+#define	O_WRONLY	0x0001		/* open for writing only */
+#define	O_RDWR		0x0002		/* open for reading and writing */
+#define	O_ACCMODE	0x0003		/* mask for above modes */
+#define	O_NONBLOCK	0x0004		/* no delay */
+#define	O_APPEND	0x0008		/* set append mode */
+#define	O_SYNC		0x0080		/* synch I/O file integrity */
+#define	O_SHLOCK	0x0010		/* open with shared file lock */
+#define	O_EXLOCK	0x0020		/* open with exclusive file lock */
+#define	O_ASYNC		0x0040		/* signal pgrp when data ready */
+#define	O_FSYNC		O_SYNC		/* source compatibility: do not use */
+#define O_NOFOLLOW  0x0100      /* don't follow symlinks */
+#define	O_CREAT		0x0200		/* create if nonexistant */
+#define	O_TRUNC		0x0400		/* truncate to zero length */
+#define	O_EXCL		0x0800		/* error if already exists */
+#define	O_EVTONLY	0x8000		/* descriptor requested for event notifications only */
+#define	O_NOCTTY	0x20000		/* don't assign controlling terminal */
+#define O_DIRECTORY	0x100000
+#define O_SYMLINK	0x200000	/* allow open of a symlink */
+#define O_DSYNC 	0x400000	/* synch I/O data integrity */
+#define	O_CLOEXEC	0x1000000	/* implicitly set FD_CLOEXEC */