[Lldb-commits] [lldb] r280751 - *** This commit represents a complete reformatting of the LLDB source code

Kate Stone via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 6 13:58:36 PDT 2016


Modified: lldb/trunk/source/Plugins/Process/Darwin/CFString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/CFString.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/CFString.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/CFString.cpp Tue Sep  6 15:57:50 2016
@@ -12,136 +12,110 @@
 //===----------------------------------------------------------------------===//
 
 #include "CFString.h"
-#include <string>
 #include <glob.h>
+#include <string>
 
 //----------------------------------------------------------------------
 // CFString constructor
 //----------------------------------------------------------------------
-CFString::CFString(CFStringRef s) :
-    CFReleaser<CFStringRef> (s)
-{
-}
+CFString::CFString(CFStringRef s) : CFReleaser<CFStringRef>(s) {}
 
 //----------------------------------------------------------------------
 // CFString copy constructor
 //----------------------------------------------------------------------
-CFString::CFString(const CFString& rhs) :
-    CFReleaser<CFStringRef> (rhs)
-{
-
-}
+CFString::CFString(const CFString &rhs) : CFReleaser<CFStringRef>(rhs) {}
 
 //----------------------------------------------------------------------
 // CFString copy constructor
 //----------------------------------------------------------------------
-CFString&
-CFString::operator=(const CFString& rhs)
-{
-    if (this != &rhs)
-        *this = rhs;
-    return *this;
+CFString &CFString::operator=(const CFString &rhs) {
+  if (this != &rhs)
+    *this = rhs;
+  return *this;
 }
 
-CFString::CFString (const char *cstr, CFStringEncoding cstr_encoding) :
-    CFReleaser<CFStringRef> ()
-{
-    if (cstr && cstr[0])
-    {
-        reset(::CFStringCreateWithCString(kCFAllocatorDefault, cstr, cstr_encoding));
-    }
+CFString::CFString(const char *cstr, CFStringEncoding cstr_encoding)
+    : CFReleaser<CFStringRef>() {
+  if (cstr && cstr[0]) {
+    reset(
+        ::CFStringCreateWithCString(kCFAllocatorDefault, cstr, cstr_encoding));
+  }
 }
 
 //----------------------------------------------------------------------
 // Destructor
 //----------------------------------------------------------------------
-CFString::~CFString()
-{
-}
+CFString::~CFString() {}
 
-const char *
-CFString::GetFileSystemRepresentation(std::string& s)
-{
-    return CFString::FileSystemRepresentation(get(), s);
+const char *CFString::GetFileSystemRepresentation(std::string &s) {
+  return CFString::FileSystemRepresentation(get(), s);
 }
 
-CFStringRef
-CFString::SetFileSystemRepresentation (const char *path)
-{
-    CFStringRef new_value = NULL;
-    if (path && path[0])
-        new_value = ::CFStringCreateWithFileSystemRepresentation (kCFAllocatorDefault, path);
-    reset(new_value);
-    return get();
-}
-
-
-CFStringRef
-CFString::SetFileSystemRepresentationFromCFType (CFTypeRef cf_type)
-{
-    CFStringRef new_value = NULL;
-    if (cf_type != NULL)
-    {
-        CFTypeID cf_type_id = ::CFGetTypeID(cf_type);
-
-        if (cf_type_id == ::CFStringGetTypeID())
-        {
-            // Retain since we are using the existing object
-            new_value = (CFStringRef)::CFRetain(cf_type);
-        }
-        else if (cf_type_id == ::CFURLGetTypeID())
-        {
-            new_value = ::CFURLCopyFileSystemPath((CFURLRef)cf_type, kCFURLPOSIXPathStyle);
-        }
+CFStringRef CFString::SetFileSystemRepresentation(const char *path) {
+  CFStringRef new_value = NULL;
+  if (path && path[0])
+    new_value =
+        ::CFStringCreateWithFileSystemRepresentation(kCFAllocatorDefault, path);
+  reset(new_value);
+  return get();
+}
+
+CFStringRef CFString::SetFileSystemRepresentationFromCFType(CFTypeRef cf_type) {
+  CFStringRef new_value = NULL;
+  if (cf_type != NULL) {
+    CFTypeID cf_type_id = ::CFGetTypeID(cf_type);
+
+    if (cf_type_id == ::CFStringGetTypeID()) {
+      // Retain since we are using the existing object
+      new_value = (CFStringRef)::CFRetain(cf_type);
+    } else if (cf_type_id == ::CFURLGetTypeID()) {
+      new_value =
+          ::CFURLCopyFileSystemPath((CFURLRef)cf_type, kCFURLPOSIXPathStyle);
     }
-    reset(new_value);
-    return get();
+  }
+  reset(new_value);
+  return get();
 }
 
 CFStringRef
-CFString::SetFileSystemRepresentationAndExpandTilde (const char *path)
-{
-    std::string expanded_path;
-    if (CFString::GlobPath(path, expanded_path))
-        SetFileSystemRepresentation(expanded_path.c_str());
-    else
-        reset();
-    return get();
+CFString::SetFileSystemRepresentationAndExpandTilde(const char *path) {
+  std::string expanded_path;
+  if (CFString::GlobPath(path, expanded_path))
+    SetFileSystemRepresentation(expanded_path.c_str());
+  else
+    reset();
+  return get();
 }
 
-const char *
-CFString::UTF8(std::string& str)
-{
-    return CFString::UTF8(get(), str);
+const char *CFString::UTF8(std::string &str) {
+  return CFString::UTF8(get(), str);
 }
 
 // Static function that puts a copy of the UTF8 contents of CF_STR into STR
-// and returns the C string pointer that is contained in STR when successful, else
-// NULL is returned. This allows the std::string parameter to own the extracted string,
-// and also allows that string to be returned as a C string pointer that can be used.
-
-const char *
-CFString::UTF8 (CFStringRef cf_str, std::string& str)
-{
-    if (cf_str)
-    {
-        const CFStringEncoding encoding = kCFStringEncodingUTF8;
-        CFIndex max_utf8_str_len = CFStringGetLength (cf_str);
-        max_utf8_str_len = CFStringGetMaximumSizeForEncoding (max_utf8_str_len, encoding);
-        if (max_utf8_str_len > 0)
-        {
-            str.resize(max_utf8_str_len);
-            if (!str.empty())
-            {
-                if (CFStringGetCString (cf_str, &str[0], str.size(), encoding))
-                {
-                    str.resize(strlen(str.c_str()));
-                    return str.c_str();
-                }
-            }
+// and returns the C string pointer that is contained in STR when successful,
+// else
+// NULL is returned. This allows the std::string parameter to own the extracted
+// string,
+// and also allows that string to be returned as a C string pointer that can be
+// used.
+
+const char *CFString::UTF8(CFStringRef cf_str, std::string &str) {
+  if (cf_str) {
+    const CFStringEncoding encoding = kCFStringEncodingUTF8;
+    CFIndex max_utf8_str_len = CFStringGetLength(cf_str);
+    max_utf8_str_len =
+        CFStringGetMaximumSizeForEncoding(max_utf8_str_len, encoding);
+    if (max_utf8_str_len > 0) {
+      str.resize(max_utf8_str_len);
+      if (!str.empty()) {
+        if (CFStringGetCString(cf_str, &str[0], str.size(), encoding)) {
+          str.resize(strlen(str.c_str()));
+          return str.c_str();
         }
+      }
     }
-    return NULL;
+  }
+  return NULL;
 }
 
 // Static function that puts a copy of the file system representation of CF_STR
@@ -150,52 +124,40 @@ CFString::UTF8 (CFStringRef cf_str, std:
 // to own the extracted string, and also allows that string to be returned as
 // a C string pointer that can be used.
 
-const char *
-CFString::FileSystemRepresentation (CFStringRef cf_str, std::string& str)
-{
-    if (cf_str)
-    {
-        CFIndex max_length = ::CFStringGetMaximumSizeOfFileSystemRepresentation (cf_str);
-        if (max_length > 0)
-        {
-            str.resize(max_length);
-            if (!str.empty())
-            {
-                if (::CFStringGetFileSystemRepresentation (cf_str, &str[0], str.size()))
-                {
-                    str.erase(::strlen(str.c_str()));
-                    return str.c_str();
-                }
-            }
+const char *CFString::FileSystemRepresentation(CFStringRef cf_str,
+                                               std::string &str) {
+  if (cf_str) {
+    CFIndex max_length =
+        ::CFStringGetMaximumSizeOfFileSystemRepresentation(cf_str);
+    if (max_length > 0) {
+      str.resize(max_length);
+      if (!str.empty()) {
+        if (::CFStringGetFileSystemRepresentation(cf_str, &str[0],
+                                                  str.size())) {
+          str.erase(::strlen(str.c_str()));
+          return str.c_str();
         }
+      }
     }
-    str.erase();
-    return NULL;
-}
-
+  }
+  str.erase();
+  return NULL;
+}
+
+CFIndex CFString::GetLength() const {
+  CFStringRef str = get();
+  if (str)
+    return CFStringGetLength(str);
+  return 0;
+}
+
+const char *CFString::GlobPath(const char *path, std::string &expanded_path) {
+  glob_t globbuf;
+  if (::glob(path, GLOB_TILDE, NULL, &globbuf) == 0) {
+    expanded_path = globbuf.gl_pathv[0];
+    ::globfree(&globbuf);
+  } else
+    expanded_path.clear();
 
-CFIndex
-CFString::GetLength() const
-{
-    CFStringRef str = get();
-    if (str)
-        return CFStringGetLength (str);
-    return 0;
+  return expanded_path.c_str();
 }
-
-
-const char*
-CFString::GlobPath(const char* path, std::string &expanded_path)
-{
-    glob_t globbuf;
-    if (::glob (path, GLOB_TILDE, NULL, &globbuf) == 0)
-    {
-        expanded_path = globbuf.gl_pathv[0];
-        ::globfree (&globbuf);
-    }
-    else
-        expanded_path.clear();
-
-    return expanded_path.c_str();
-}
-

Modified: lldb/trunk/source/Plugins/Process/Darwin/CFString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/CFString.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/CFString.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/CFString.h Tue Sep  6 15:57:50 2016
@@ -17,27 +17,27 @@
 #include "CFUtils.h"
 #include <iosfwd>
 
-class CFString : public CFReleaser<CFStringRef>
-{
+class CFString : public CFReleaser<CFStringRef> {
 public:
-    //------------------------------------------------------------------
-    // Constructors and Destructors
-    //------------------------------------------------------------------
-                        CFString (CFStringRef cf_str = NULL);
-                        CFString (const char *s, CFStringEncoding encoding = kCFStringEncodingUTF8);
-                        CFString (const CFString& rhs);
-                        CFString& operator= (const CFString& rhs);
-                        virtual ~CFString ();
+  //------------------------------------------------------------------
+  // Constructors and Destructors
+  //------------------------------------------------------------------
+  CFString(CFStringRef cf_str = NULL);
+  CFString(const char *s, CFStringEncoding encoding = kCFStringEncodingUTF8);
+  CFString(const CFString &rhs);
+  CFString &operator=(const CFString &rhs);
+  virtual ~CFString();
 
-        const char *    GetFileSystemRepresentation (std::string& str);
-        CFStringRef     SetFileSystemRepresentation (const char *path);
-        CFStringRef     SetFileSystemRepresentationFromCFType (CFTypeRef cf_type);
-        CFStringRef     SetFileSystemRepresentationAndExpandTilde (const char *path);
-        const char *    UTF8 (std::string& str);
-        CFIndex         GetLength() const;
-        static const char *UTF8 (CFStringRef cf_str, std::string& str);
-        static const char *FileSystemRepresentation (CFStringRef cf_str, std::string& str);
-        static const char* GlobPath(const char* path, std::string &expanded_path);
+  const char *GetFileSystemRepresentation(std::string &str);
+  CFStringRef SetFileSystemRepresentation(const char *path);
+  CFStringRef SetFileSystemRepresentationFromCFType(CFTypeRef cf_type);
+  CFStringRef SetFileSystemRepresentationAndExpandTilde(const char *path);
+  const char *UTF8(std::string &str);
+  CFIndex GetLength() const;
+  static const char *UTF8(CFStringRef cf_str, std::string &str);
+  static const char *FileSystemRepresentation(CFStringRef cf_str,
+                                              std::string &str);
+  static const char *GlobPath(const char *path, std::string &expanded_path);
 };
 
 #endif // #ifndef __CFString_h__

Modified: lldb/trunk/source/Plugins/Process/Darwin/CFUtils.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/CFUtils.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/CFUtils.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/CFUtils.h Tue Sep  6 15:57:50 2016
@@ -23,59 +23,56 @@
 // call CFRelease() on any valid pointer it owns unless that pointer is
 // explicitly released using the release() member function.
 //----------------------------------------------------------------------
-template <class T>
-class CFReleaser
-{
+template <class T> class CFReleaser {
 public:
-            // Type names for the avlue
-            typedef T element_type;
+  // Type names for the avlue
+  typedef T element_type;
 
-            // Constructors and destructors
-            CFReleaser(T ptr = NULL) : _ptr(ptr) { }
-            CFReleaser(const CFReleaser& copy) : _ptr(copy.get())
-            {
-                if (get())
-                    ::CFRetain(get());
-            }
-            virtual ~CFReleaser() { reset(); }
-
-            // Assignments
-            CFReleaser& operator= (const CFReleaser<T>& copy)
-            {
-                if (copy != *this)
-                {
-                    // Replace our owned pointer with the new one
-                    reset(copy.get());
-                    // Retain the current pointer that we own
-                    if (get())
-                        ::CFRetain(get());
-                }
-            }
-            // Get the address of the contained type
-            T *     ptr_address()   { return &_ptr; }
-
-            // Access the pointer itself
-    const   T       get() const     { return _ptr;  }
-            T       get()           { return _ptr;  }
-
-            // Set a new value for the pointer and CFRelease our old
-            // value if we had a valid one.
-            void    reset(T ptr = NULL)
-                    {
-                        if (ptr != _ptr)
-                        {
-                            if (_ptr != NULL)
-                                ::CFRelease(_ptr);
-                            _ptr = ptr;
-                        }
-                    }
+  // Constructors and destructors
+  CFReleaser(T ptr = NULL) : _ptr(ptr) {}
+  CFReleaser(const CFReleaser &copy) : _ptr(copy.get()) {
+    if (get())
+      ::CFRetain(get());
+  }
+  virtual ~CFReleaser() { reset(); }
+
+  // Assignments
+  CFReleaser &operator=(const CFReleaser<T> &copy) {
+    if (copy != *this) {
+      // Replace our owned pointer with the new one
+      reset(copy.get());
+      // Retain the current pointer that we own
+      if (get())
+        ::CFRetain(get());
+    }
+  }
+  // Get the address of the contained type
+  T *ptr_address() { return &_ptr; }
+
+  // Access the pointer itself
+  const T get() const { return _ptr; }
+  T get() { return _ptr; }
+
+  // Set a new value for the pointer and CFRelease our old
+  // value if we had a valid one.
+  void reset(T ptr = NULL) {
+    if (ptr != _ptr) {
+      if (_ptr != NULL)
+        ::CFRelease(_ptr);
+      _ptr = ptr;
+    }
+  }
+
+  // Release ownership without calling CFRelease
+  T release() {
+    T tmp = _ptr;
+    _ptr = NULL;
+    return tmp;
+  }
 
-            // Release ownership without calling CFRelease
-            T    release() { T tmp = _ptr; _ptr = NULL; return tmp; }
 private:
-    element_type _ptr;
+  element_type _ptr;
 };
 
-#endif    // #ifdef __cplusplus
-#endif    // #ifndef __CFUtils_h__
-
+#endif // #ifdef __cplusplus
+#endif // #ifndef __CFUtils_h__

Modified: lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp Tue Sep  6 15:57:50 2016
@@ -15,7 +15,7 @@
 #include <sys/sysctl.h>
 
 #ifndef _POSIX_SPAWN_DISABLE_ASLR
-#define _POSIX_SPAWN_DISABLE_ASLR       0x0100
+#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
 #endif
 
 // LLDB includes
@@ -35,703 +35,610 @@ using namespace lldb_private;
 using namespace lldb_private::process_darwin;
 using namespace lldb_private::darwin_process_launcher;
 
-namespace
-{
-    static LaunchFlavor g_launch_flavor = LaunchFlavor::Default;
+namespace {
+static LaunchFlavor g_launch_flavor = LaunchFlavor::Default;
 }
 
-namespace lldb_private
-{
-namespace darwin_process_launcher
-{
-
-static uint32_t
-GetCPUTypeForLocalProcess(::pid_t pid)
-{
-    int mib[CTL_MAXNAME]={0,};
-    size_t len = CTL_MAXNAME;
-    if (::sysctlnametomib("sysctl.proc_cputype", mib, &len))
-        return 0;
-
-    mib[len] = pid;
-    len++;
-
-    cpu_type_t cpu;
-    size_t cpu_len = sizeof(cpu);
-    if (::sysctl (mib, static_cast<u_int>(len), &cpu, &cpu_len, 0, 0))
-        cpu = 0;
-    return cpu;
+namespace lldb_private {
+namespace darwin_process_launcher {
+
+static uint32_t GetCPUTypeForLocalProcess(::pid_t pid) {
+  int mib[CTL_MAXNAME] = {
+      0,
+  };
+  size_t len = CTL_MAXNAME;
+  if (::sysctlnametomib("sysctl.proc_cputype", mib, &len))
+    return 0;
+
+  mib[len] = pid;
+  len++;
+
+  cpu_type_t cpu;
+  size_t cpu_len = sizeof(cpu);
+  if (::sysctl(mib, static_cast<u_int>(len), &cpu, &cpu_len, 0, 0))
+    cpu = 0;
+  return cpu;
 }
 
-static bool
-ResolveExecutablePath(const char *path, char *resolved_path,
-                      size_t resolved_path_size)
-{
-    if (path == NULL || path[0] == '\0')
-        return false;
-
-    char max_path[PATH_MAX];
-    std::string result;
-    CFString::GlobPath(path, result);
-
-    if (result.empty())
-        result = path;
-
-    struct stat path_stat;
-    if (::stat(path, &path_stat) == 0)
-    {
-        if ((path_stat.st_mode & S_IFMT) == S_IFDIR)
-        {
-            CFBundle bundle(path);
-            CFReleaser<CFURLRef> url(bundle.CopyExecutableURL ());
-            if (url.get())
-            {
-                if (::CFURLGetFileSystemRepresentation(url.get(), true,
-                                                       (UInt8*)resolved_path,
-                                                       resolved_path_size))
-                    return true;
-            }
-        }
-    }
+static bool ResolveExecutablePath(const char *path, char *resolved_path,
+                                  size_t resolved_path_size) {
+  if (path == NULL || path[0] == '\0')
+    return false;
 
-    if (realpath(path, max_path))
-    {
-        // Found the path relatively...
-        ::strncpy(resolved_path, max_path, resolved_path_size);
-        return strlen(resolved_path) + 1 < resolved_path_size;
-    }
-    else
-    {
-        // Not a relative path, check the PATH environment variable if the
-        const char *PATH = getenv("PATH");
-        if (PATH)
-        {
-            const char *curr_path_start = PATH;
-            const char *curr_path_end;
-            while (curr_path_start && *curr_path_start)
-            {
-                curr_path_end = strchr(curr_path_start, ':');
-                if (curr_path_end == NULL)
-                {
-                    result.assign(curr_path_start);
-                    curr_path_start = NULL;
-                }
-                else if (curr_path_end > curr_path_start)
-                {
-                    size_t len = curr_path_end - curr_path_start;
-                    result.assign(curr_path_start, len);
-                    curr_path_start += len + 1;
-                }
-                else
-                    break;
-
-                result += '/';
-                result += path;
-                struct stat s;
-                if (stat(result.c_str(), &s) == 0)
-                {
-                    ::strncpy(resolved_path, result.c_str(),
-                              resolved_path_size);
-                    return result.size() + 1 < resolved_path_size;
-                }
-            }
+  char max_path[PATH_MAX];
+  std::string result;
+  CFString::GlobPath(path, result);
+
+  if (result.empty())
+    result = path;
+
+  struct stat path_stat;
+  if (::stat(path, &path_stat) == 0) {
+    if ((path_stat.st_mode & S_IFMT) == S_IFDIR) {
+      CFBundle bundle(path);
+      CFReleaser<CFURLRef> url(bundle.CopyExecutableURL());
+      if (url.get()) {
+        if (::CFURLGetFileSystemRepresentation(
+                url.get(), true, (UInt8 *)resolved_path, resolved_path_size))
+          return true;
+      }
+    }
+  }
+
+  if (realpath(path, max_path)) {
+    // Found the path relatively...
+    ::strncpy(resolved_path, max_path, resolved_path_size);
+    return strlen(resolved_path) + 1 < resolved_path_size;
+  } else {
+    // Not a relative path, check the PATH environment variable if the
+    const char *PATH = getenv("PATH");
+    if (PATH) {
+      const char *curr_path_start = PATH;
+      const char *curr_path_end;
+      while (curr_path_start && *curr_path_start) {
+        curr_path_end = strchr(curr_path_start, ':');
+        if (curr_path_end == NULL) {
+          result.assign(curr_path_start);
+          curr_path_start = NULL;
+        } else if (curr_path_end > curr_path_start) {
+          size_t len = curr_path_end - curr_path_start;
+          result.assign(curr_path_start, len);
+          curr_path_start += len + 1;
+        } else
+          break;
+
+        result += '/';
+        result += path;
+        struct stat s;
+        if (stat(result.c_str(), &s) == 0) {
+          ::strncpy(resolved_path, result.c_str(), resolved_path_size);
+          return result.size() + 1 < resolved_path_size;
         }
+      }
     }
-    return false;
+  }
+  return false;
 }
 
 // TODO check if we have a general purpose fork and exec.  We may be
 // able to get rid of this entirely.
-static Error
-ForkChildForPTraceDebugging(const char *path,
-                            char const *argv[],
-                            char const *envp[],
-                            ::pid_t *pid,
-                            int *pty_fd)
-{
-    Error error;
-    if (!path || !argv || !envp || !pid || !pty_fd)
-    {
-        error.SetErrorString("invalid arguments");
-        return error;
-    }
-
-    // Use a fork that ties the child process's stdin/out/err to a pseudo
-    // terminal so we can read it in our MachProcess::STDIOThread
-    // as unbuffered io.
-    lldb_utility::PseudoTerminal pty;
-    char fork_error[256];
-    memset(fork_error, 0, sizeof(fork_error));
-    *pid = static_cast<::pid_t>(pty.Fork(fork_error, sizeof(fork_error)));
-    if (*pid < 0)
-    {
-        //--------------------------------------------------------------
-        // Error during fork.
-        //--------------------------------------------------------------
-        *pid = static_cast<::pid_t>(LLDB_INVALID_PROCESS_ID);
-        error.SetErrorStringWithFormat("%s(): fork failed: %s",
-                                       __FUNCTION__, fork_error);
-        return error;
-    }
-    else if (pid == 0)
-    {
-        //--------------------------------------------------------------
-        // Child process
-        //--------------------------------------------------------------
-
-        // Debug this process.
-        ::ptrace(PT_TRACE_ME, 0, 0, 0);
-
-        // Get BSD signals as mach exceptions.
-        ::ptrace(PT_SIGEXC, 0, 0, 0);
-
-        // If our parent is setgid, lets make sure we don't inherit those
-        // extra powers due to nepotism.
-        if (::setgid(getgid()) == 0)
-        {
-            // Let the child have its own process group. We need to execute
-            // this call in both the child and parent to avoid a race
-            // condition between the two processes.
-
-            // Set the child process group to match its pid.
-            ::setpgid(0, 0);
-
-            // Sleep a bit to before the exec call.
-            ::sleep(1);
+static Error ForkChildForPTraceDebugging(const char *path, char const *argv[],
+                                         char const *envp[], ::pid_t *pid,
+                                         int *pty_fd) {
+  Error error;
+  if (!path || !argv || !envp || !pid || !pty_fd) {
+    error.SetErrorString("invalid arguments");
+    return error;
+  }
 
-            // Turn this process into the given executable.
-            ::execv(path, (char * const *)argv);
-        }
-        // Exit with error code. Child process should have taken
-        // over in above exec call and if the exec fails it will
-        // exit the child process below.
-        ::exit(127);
-    }
-    else
-    {
-        //--------------------------------------------------------------
-        // Parent process
-        //--------------------------------------------------------------
-        // Let the child have its own process group. We need to execute
-        // this call in both the child and parent to avoid a race condition
-        // between the two processes.
-
-        // Set the child process group to match its pid
-        ::setpgid(*pid, *pid);
-        if (pty_fd)
-        {
-            // Release our master pty file descriptor so the pty class doesn't
-            // close it and so we can continue to use it in our STDIO thread
-            *pty_fd = pty.ReleaseMasterFileDescriptor();
-        }
-    }
+  // Use a fork that ties the child process's stdin/out/err to a pseudo
+  // terminal so we can read it in our MachProcess::STDIOThread
+  // as unbuffered io.
+  lldb_utility::PseudoTerminal pty;
+  char fork_error[256];
+  memset(fork_error, 0, sizeof(fork_error));
+  *pid = static_cast<::pid_t>(pty.Fork(fork_error, sizeof(fork_error)));
+  if (*pid < 0) {
+    //--------------------------------------------------------------
+    // Error during fork.
+    //--------------------------------------------------------------
+    *pid = static_cast<::pid_t>(LLDB_INVALID_PROCESS_ID);
+    error.SetErrorStringWithFormat("%s(): fork failed: %s", __FUNCTION__,
+                                   fork_error);
     return error;
+  } else if (pid == 0) {
+    //--------------------------------------------------------------
+    // Child process
+    //--------------------------------------------------------------
+
+    // Debug this process.
+    ::ptrace(PT_TRACE_ME, 0, 0, 0);
+
+    // Get BSD signals as mach exceptions.
+    ::ptrace(PT_SIGEXC, 0, 0, 0);
+
+    // If our parent is setgid, lets make sure we don't inherit those
+    // extra powers due to nepotism.
+    if (::setgid(getgid()) == 0) {
+      // Let the child have its own process group. We need to execute
+      // this call in both the child and parent to avoid a race
+      // condition between the two processes.
+
+      // Set the child process group to match its pid.
+      ::setpgid(0, 0);
+
+      // Sleep a bit to before the exec call.
+      ::sleep(1);
+
+      // Turn this process into the given executable.
+      ::execv(path, (char *const *)argv);
+    }
+    // Exit with error code. Child process should have taken
+    // over in above exec call and if the exec fails it will
+    // exit the child process below.
+    ::exit(127);
+  } else {
+    //--------------------------------------------------------------
+    // Parent process
+    //--------------------------------------------------------------
+    // Let the child have its own process group. We need to execute
+    // this call in both the child and parent to avoid a race condition
+    // between the two processes.
+
+    // Set the child process group to match its pid
+    ::setpgid(*pid, *pid);
+    if (pty_fd) {
+      // Release our master pty file descriptor so the pty class doesn't
+      // close it and so we can continue to use it in our STDIO thread
+      *pty_fd = pty.ReleaseMasterFileDescriptor();
+    }
+  }
+  return error;
 }
 
 static Error
 CreatePosixSpawnFileAction(const FileAction &action,
-                           posix_spawn_file_actions_t *file_actions)
-{
-    Error error;
+                           posix_spawn_file_actions_t *file_actions) {
+  Error error;
+
+  // Log it.
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log) {
+    StreamString stream;
+    stream.PutCString("converting file action for posix_spawn(): ");
+    action.Dump(stream);
+    stream.Flush();
+    log->PutCString(stream.GetString().c_str());
+  }
+
+  // Validate args.
+  if (!file_actions) {
+    error.SetErrorString("mandatory file_actions arg is null");
+    return error;
+  }
 
-    // Log it.
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  // Build the posix file action.
+  switch (action.GetAction()) {
+  case FileAction::eFileActionOpen: {
+    const int error_code = ::posix_spawn_file_actions_addopen(
+        file_actions, action.GetFD(), action.GetPath(),
+        action.GetActionArgument(), 0);
+    if (error_code != 0) {
+      error.SetError(error_code, eErrorTypePOSIX);
+      return error;
+    }
+    break;
+  }
+
+  case FileAction::eFileActionClose: {
+    const int error_code =
+        ::posix_spawn_file_actions_addclose(file_actions, action.GetFD());
+    if (error_code != 0) {
+      error.SetError(error_code, eErrorTypePOSIX);
+      return error;
+    }
+    break;
+  }
+
+  case FileAction::eFileActionDuplicate: {
+    const int error_code = ::posix_spawn_file_actions_adddup2(
+        file_actions, action.GetFD(), action.GetActionArgument());
+    if (error_code != 0) {
+      error.SetError(error_code, eErrorTypePOSIX);
+      return error;
+    }
+    break;
+  }
+
+  case FileAction::eFileActionNone:
+  default:
     if (log)
-    {
-        StreamString stream;
-        stream.PutCString("converting file action for posix_spawn(): ");
-        action.Dump(stream);
-        stream.Flush();
-        log->PutCString(stream.GetString().c_str());
-    }
-
-    // Validate args.
-    if (!file_actions)
-    {
-        error.SetErrorString("mandatory file_actions arg is null");
-        return error;
-    }
-
-    // Build the posix file action.
-    switch (action.GetAction())
-    {
-        case FileAction::eFileActionOpen:
-        {
-            const int error_code =
-                ::posix_spawn_file_actions_addopen(file_actions,
-                                                   action.GetFD(),
-                                                   action.GetPath(),
-                                                   action.GetActionArgument(),
-                                                   0);
-            if (error_code != 0)
-            {
-                error.SetError(error_code, eErrorTypePOSIX);
-                return error;
-            }
-            break;
-        }
+      log->Printf("%s(): unsupported file action %u", __FUNCTION__,
+                  action.GetAction());
+    break;
+  }
 
-        case FileAction::eFileActionClose:
-        {
-            const int error_code =
-            ::posix_spawn_file_actions_addclose(file_actions,
-                                                action.GetFD());
-            if (error_code != 0)
-            {
-                error.SetError(error_code, eErrorTypePOSIX);
-                return error;
-            }
-            break;
-        }
+  return error;
+}
 
-        case FileAction::eFileActionDuplicate:
-        {
-            const int error_code =
-            ::posix_spawn_file_actions_adddup2(file_actions,
-                                               action.GetFD(),
-                                               action.GetActionArgument());
-            if (error_code != 0)
-            {
-                error.SetError(error_code, eErrorTypePOSIX);
-                return error;
-            }
-            break;
-        }
+static Error PosixSpawnChildForPTraceDebugging(const char *path,
+                                               ProcessLaunchInfo &launch_info,
+                                               ::pid_t *pid,
+                                               cpu_type_t *actual_cpu_type) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  if (!pid) {
+    error.SetErrorStringWithFormat("%s(): pid arg cannot be null",
+                                   __FUNCTION__);
+    return error;
+  }
 
-        case FileAction::eFileActionNone:
-        default:
-            if (log)
-                log->Printf("%s(): unsupported file action %u",
-                            __FUNCTION__, action.GetAction());
-            break;
-    }
+  posix_spawnattr_t attr;
+  short flags;
+  if (log) {
+    StreamString stream;
+    stream.Printf("%s(path='%s',...)\n", __FUNCTION__, path);
+    launch_info.Dump(stream, nullptr);
+    stream.Flush();
+    log->PutCString(stream.GetString().c_str());
+  }
 
+  int error_code;
+  if ((error_code = ::posix_spawnattr_init(&attr)) != 0) {
+    if (log)
+      log->Printf("::posix_spawnattr_init(&attr) failed");
+    error.SetError(error_code, eErrorTypePOSIX);
     return error;
-}
+  }
 
-static Error
-PosixSpawnChildForPTraceDebugging(const char *path,
-                                  ProcessLaunchInfo &launch_info,
-                                  ::pid_t *pid,
-                                  cpu_type_t *actual_cpu_type)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    if (!pid)
-    {
-        error.SetErrorStringWithFormat("%s(): pid arg cannot be null",
-                                       __FUNCTION__);
-        return error;
-    }
+  // Ensure we clean up the spawnattr structure however we exit this
+  // function.
+  std::unique_ptr<posix_spawnattr_t, int (*)(posix_spawnattr_t *)> spawnattr_up(
+      &attr, ::posix_spawnattr_destroy);
+
+  flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETSIGDEF |
+          POSIX_SPAWN_SETSIGMASK;
+  if (launch_info.GetFlags().Test(eLaunchFlagDisableASLR))
+    flags |= _POSIX_SPAWN_DISABLE_ASLR;
+
+  sigset_t no_signals;
+  sigset_t all_signals;
+  sigemptyset(&no_signals);
+  sigfillset(&all_signals);
+  ::posix_spawnattr_setsigmask(&attr, &no_signals);
+  ::posix_spawnattr_setsigdefault(&attr, &all_signals);
 
-    posix_spawnattr_t attr;
-    short flags;
+  if ((error_code = ::posix_spawnattr_setflags(&attr, flags)) != 0) {
     if (log)
-    {
-        StreamString stream;
-        stream.Printf("%s(path='%s',...)\n", __FUNCTION__, path);
-        launch_info.Dump(stream, nullptr);
-        stream.Flush();
-        log->PutCString(stream.GetString().c_str());
-    }
-
-    int error_code;
-    if ((error_code = ::posix_spawnattr_init(&attr)) != 0)
-    {
-        if (log)
-            log->Printf("::posix_spawnattr_init(&attr) failed");
-        error.SetError(error_code, eErrorTypePOSIX);
-        return error;
-    }
-
-    // Ensure we clean up the spawnattr structure however we exit this
-    // function.
-    std::unique_ptr<posix_spawnattr_t, int(*)(posix_spawnattr_t*)>
-        spawnattr_up(&attr, ::posix_spawnattr_destroy);
-
-
-    flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETSIGDEF |
-        POSIX_SPAWN_SETSIGMASK;
-    if (launch_info.GetFlags().Test(eLaunchFlagDisableASLR))
-        flags |= _POSIX_SPAWN_DISABLE_ASLR;
-
-    sigset_t no_signals;
-    sigset_t all_signals;
-    sigemptyset (&no_signals);
-    sigfillset (&all_signals);
-    ::posix_spawnattr_setsigmask(&attr, &no_signals);
-    ::posix_spawnattr_setsigdefault(&attr, &all_signals);
-
-    if ((error_code = ::posix_spawnattr_setflags(&attr, flags)) != 0)
-    {
-        if (log)
-            log->Printf("::posix_spawnattr_setflags(&attr, "
-                        "POSIX_SPAWN_START_SUSPENDED%s) failed: %s",
-                        flags & _POSIX_SPAWN_DISABLE_ASLR ?
-                        " | _POSIX_SPAWN_DISABLE_ASLR" : "",
-                        strerror(error_code));
-        error.SetError(error_code, eErrorTypePOSIX);
-        return error;
-    }
+      log->Printf("::posix_spawnattr_setflags(&attr, "
+                  "POSIX_SPAWN_START_SUSPENDED%s) failed: %s",
+                  flags & _POSIX_SPAWN_DISABLE_ASLR
+                      ? " | _POSIX_SPAWN_DISABLE_ASLR"
+                      : "",
+                  strerror(error_code));
+    error.SetError(error_code, eErrorTypePOSIX);
+    return error;
+  }
 
 #if !defined(__arm__)
 
-    // We don't need to do this for ARM, and we really shouldn't now that we
-    // have multiple CPU subtypes and no posix_spawnattr call that allows us
-    // to set which CPU subtype to launch...
-    cpu_type_t desired_cpu_type =
-        launch_info.GetArchitecture().GetMachOCPUType();
-    if (desired_cpu_type != LLDB_INVALID_CPUTYPE)
-    {
-        size_t ocount = 0;
-        error_code = ::posix_spawnattr_setbinpref_np(&attr, 1,
-                                                     &desired_cpu_type,
-                                                     &ocount);
-        if (error_code != 0)
-        {
-            if (log)
-                log->Printf("::posix_spawnattr_setbinpref_np(&attr, 1, "
-                            "cpu_type = 0x%8.8x, count => %llu): %s",
-                            desired_cpu_type, (uint64_t)ocount,
-                            strerror(error_code));
-            error.SetError(error_code, eErrorTypePOSIX);
-            return error;
-        }
-        if (ocount != 1)
-        {
-            error.SetErrorStringWithFormat("posix_spawnattr_setbinpref_np "
-                                           "did not set the expected number "
-                                           "of cpu_type entries: expected 1 "
-                                           "but was %zu", ocount);
-            return error;
-        }
+  // We don't need to do this for ARM, and we really shouldn't now that we
+  // have multiple CPU subtypes and no posix_spawnattr call that allows us
+  // to set which CPU subtype to launch...
+  cpu_type_t desired_cpu_type = launch_info.GetArchitecture().GetMachOCPUType();
+  if (desired_cpu_type != LLDB_INVALID_CPUTYPE) {
+    size_t ocount = 0;
+    error_code =
+        ::posix_spawnattr_setbinpref_np(&attr, 1, &desired_cpu_type, &ocount);
+    if (error_code != 0) {
+      if (log)
+        log->Printf("::posix_spawnattr_setbinpref_np(&attr, 1, "
+                    "cpu_type = 0x%8.8x, count => %llu): %s",
+                    desired_cpu_type, (uint64_t)ocount, strerror(error_code));
+      error.SetError(error_code, eErrorTypePOSIX);
+      return error;
+    }
+    if (ocount != 1) {
+      error.SetErrorStringWithFormat("posix_spawnattr_setbinpref_np "
+                                     "did not set the expected number "
+                                     "of cpu_type entries: expected 1 "
+                                     "but was %zu",
+                                     ocount);
+      return error;
     }
+  }
 #endif
 
-    posix_spawn_file_actions_t file_actions;
-    if ((error_code = ::posix_spawn_file_actions_init(&file_actions)) != 0)
-    {
-        if (log)
-            log->Printf("::posix_spawn_file_actions_init(&file_actions) "
-                        "failed: %s",
-                        strerror(error_code));
-        error.SetError(error_code, eErrorTypePOSIX);
-        return error;
-    }
-
-    // Ensure we clean up file actions however we exit this.  When the
-    // file_actions_up below goes out of scope, we'll get our file action
-    // cleanup.
-    std::unique_ptr<posix_spawn_file_actions_t,
-                    int(*)(posix_spawn_file_actions_t*)>
-        file_actions_up(&file_actions, ::posix_spawn_file_actions_destroy);
-
-    // We assume the caller has setup the file actions appropriately.  We
-    // are not in the business of figuring out what we really need here.
-    // lldb-server will have already called FinalizeFileActions() as well
-    // to button these up properly.
-    const size_t num_actions = launch_info.GetNumFileActions();
-    for (size_t action_index = 0; action_index < num_actions; ++action_index)
-    {
-        const FileAction *const action =
-            launch_info.GetFileActionAtIndex(action_index);
-        if (!action)
-            continue;
-
-        error = CreatePosixSpawnFileAction(*action, &file_actions);
-        if (!error.Success())
-        {
-            if (log)
-                log->Printf("%s(): error converting FileAction to posix_spawn "
-                            "file action: %s", __FUNCTION__, error.AsCString());
-            return error;
-        }
-    }
+  posix_spawn_file_actions_t file_actions;
+  if ((error_code = ::posix_spawn_file_actions_init(&file_actions)) != 0) {
+    if (log)
+      log->Printf("::posix_spawn_file_actions_init(&file_actions) "
+                  "failed: %s",
+                  strerror(error_code));
+    error.SetError(error_code, eErrorTypePOSIX);
+    return error;
+  }
 
-    // TODO: Verify if we can set the working directory back immediately
-    // after the posix_spawnp call without creating a race condition???
-    const char *const working_directory =
-        launch_info.GetWorkingDirectory().GetCString();
-    if (working_directory && working_directory[0])
-        ::chdir(working_directory);
-
-    auto argv = launch_info.GetArguments().GetArgumentVector();
-    auto envp = launch_info.GetEnvironmentEntries().GetArgumentVector();
-    error_code = ::posix_spawnp(pid, path, &file_actions, &attr,
-                                (char * const*)argv, (char * const*)envp);
-    if (error_code != 0)
-    {
-        if (log)
-            log->Printf("::posix_spawnp(pid => %p, path = '%s', file_actions "
-                        "= %p, attr = %p, argv = %p, envp = %p) failed: %s",
-                        pid, path, &file_actions, &attr, argv, envp,
-                        strerror(error_code));
-        error.SetError(error_code, eErrorTypePOSIX);
-        return error;
-    }
-
-    // Validate we got a pid.
-    if (pid == LLDB_INVALID_PROCESS_ID)
-    {
-        error.SetErrorString("posix_spawn() did not indicate a failure but it "
-                             "failed to return a pid, aborting.");
-        return error;
-    }
-
-    if (actual_cpu_type)
-    {
-        *actual_cpu_type = GetCPUTypeForLocalProcess(*pid);
-        if (log)
-            log->Printf("%s(): cpu type for launched process pid=%i: "
-                        "cpu_type=0x%8.8x", __FUNCTION__, *pid,
-                        *actual_cpu_type);
-    }
+  // Ensure we clean up file actions however we exit this.  When the
+  // file_actions_up below goes out of scope, we'll get our file action
+  // cleanup.
+  std::unique_ptr<posix_spawn_file_actions_t,
+                  int (*)(posix_spawn_file_actions_t *)>
+      file_actions_up(&file_actions, ::posix_spawn_file_actions_destroy);
+
+  // We assume the caller has setup the file actions appropriately.  We
+  // are not in the business of figuring out what we really need here.
+  // lldb-server will have already called FinalizeFileActions() as well
+  // to button these up properly.
+  const size_t num_actions = launch_info.GetNumFileActions();
+  for (size_t action_index = 0; action_index < num_actions; ++action_index) {
+    const FileAction *const action =
+        launch_info.GetFileActionAtIndex(action_index);
+    if (!action)
+      continue;
+
+    error = CreatePosixSpawnFileAction(*action, &file_actions);
+    if (!error.Success()) {
+      if (log)
+        log->Printf("%s(): error converting FileAction to posix_spawn "
+                    "file action: %s",
+                    __FUNCTION__, error.AsCString());
+      return error;
+    }
+  }
+
+  // TODO: Verify if we can set the working directory back immediately
+  // after the posix_spawnp call without creating a race condition???
+  const char *const working_directory =
+      launch_info.GetWorkingDirectory().GetCString();
+  if (working_directory && working_directory[0])
+    ::chdir(working_directory);
+
+  auto argv = launch_info.GetArguments().GetArgumentVector();
+  auto envp = launch_info.GetEnvironmentEntries().GetArgumentVector();
+  error_code = ::posix_spawnp(pid, path, &file_actions, &attr,
+                              (char *const *)argv, (char *const *)envp);
+  if (error_code != 0) {
+    if (log)
+      log->Printf("::posix_spawnp(pid => %p, path = '%s', file_actions "
+                  "= %p, attr = %p, argv = %p, envp = %p) failed: %s",
+                  pid, path, &file_actions, &attr, argv, envp,
+                  strerror(error_code));
+    error.SetError(error_code, eErrorTypePOSIX);
+    return error;
+  }
 
+  // Validate we got a pid.
+  if (pid == LLDB_INVALID_PROCESS_ID) {
+    error.SetErrorString("posix_spawn() did not indicate a failure but it "
+                         "failed to return a pid, aborting.");
     return error;
+  }
+
+  if (actual_cpu_type) {
+    *actual_cpu_type = GetCPUTypeForLocalProcess(*pid);
+    if (log)
+      log->Printf("%s(): cpu type for launched process pid=%i: "
+                  "cpu_type=0x%8.8x",
+                  __FUNCTION__, *pid, *actual_cpu_type);
+  }
+
+  return error;
 }
 
-Error
-LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
-               LaunchFlavor *launch_flavor)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    if (!launch_flavor)
-    {
-        error.SetErrorString("mandatory launch_flavor field was null");
-        return error;
-    }
+Error LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
+                     LaunchFlavor *launch_flavor) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-    if (log)
-    {
-        StreamString stream;
-        stream.Printf("NativeProcessDarwin::%s(): launching with the "
-                      "following launch info:", __FUNCTION__);
-        launch_info.Dump(stream, nullptr);
-        stream.Flush();
-        log->PutCString(stream.GetString().c_str());
-    }
-
-    // Retrieve the binary name given to us.
-    char given_path[PATH_MAX];
-    given_path[0] = '\0';
-    launch_info.GetExecutableFile().GetPath(given_path, sizeof(given_path));
-
-    // Determine the manner in which we'll launch.
-    *launch_flavor = g_launch_flavor;
-    if (*launch_flavor == LaunchFlavor::Default)
-    {
-        // Our default launch method is posix spawn
-        *launch_flavor = LaunchFlavor::PosixSpawn;
+  if (!launch_flavor) {
+    error.SetErrorString("mandatory launch_flavor field was null");
+    return error;
+  }
+
+  if (log) {
+    StreamString stream;
+    stream.Printf("NativeProcessDarwin::%s(): launching with the "
+                  "following launch info:",
+                  __FUNCTION__);
+    launch_info.Dump(stream, nullptr);
+    stream.Flush();
+    log->PutCString(stream.GetString().c_str());
+  }
+
+  // Retrieve the binary name given to us.
+  char given_path[PATH_MAX];
+  given_path[0] = '\0';
+  launch_info.GetExecutableFile().GetPath(given_path, sizeof(given_path));
+
+  // Determine the manner in which we'll launch.
+  *launch_flavor = g_launch_flavor;
+  if (*launch_flavor == LaunchFlavor::Default) {
+    // Our default launch method is posix spawn
+    *launch_flavor = LaunchFlavor::PosixSpawn;
 #if defined WITH_FBS
-        // Check if we have an app bundle, if so launch using BackBoard Services.
-        if (strstr(given_path, ".app"))
-        {
-            *launch_flavor = eLaunchFlavorFBS;
-        }
+    // Check if we have an app bundle, if so launch using BackBoard Services.
+    if (strstr(given_path, ".app")) {
+      *launch_flavor = eLaunchFlavorFBS;
+    }
 #elif defined WITH_BKS
-        // Check if we have an app bundle, if so launch using BackBoard Services.
-        if (strstr(given_path, ".app"))
-        {
-            *launch_flavor = eLaunchFlavorBKS;
-        }
+    // Check if we have an app bundle, if so launch using BackBoard Services.
+    if (strstr(given_path, ".app")) {
+      *launch_flavor = eLaunchFlavorBKS;
+    }
 #elif defined WITH_SPRINGBOARD
-        // Check if we have an app bundle, if so launch using SpringBoard.
-        if (strstr(given_path, ".app"))
-        {
-            *launch_flavor = eLaunchFlavorSpringBoard;
-        }
-#endif
+    // Check if we have an app bundle, if so launch using SpringBoard.
+    if (strstr(given_path, ".app")) {
+      *launch_flavor = eLaunchFlavorSpringBoard;
     }
+#endif
+  }
 
-    // Attempt to resolve the binary name to an absolute path.
-    char resolved_path[PATH_MAX];
-    resolved_path[0] = '\0';
-
+  // Attempt to resolve the binary name to an absolute path.
+  char resolved_path[PATH_MAX];
+  resolved_path[0] = '\0';
+
+  if (log)
+    log->Printf("%s(): attempting to resolve given binary path: \"%s\"",
+                __FUNCTION__, given_path);
+
+  // If we fail to resolve the path to our executable, then just use what we
+  // were given and hope for the best
+  if (!ResolveExecutablePath(given_path, resolved_path,
+                             sizeof(resolved_path))) {
     if (log)
-        log->Printf("%s(): attempting to resolve given binary path: \"%s\"",
-                    __FUNCTION__, given_path);
+      log->Printf("%s(): failed to resolve binary path, using "
+                  "what was given verbatim and hoping for the best",
+                  __FUNCTION__);
+    ::strncpy(resolved_path, given_path, sizeof(resolved_path));
+  } else {
+    if (log)
+      log->Printf("%s(): resolved given binary path to: \"%s\"", __FUNCTION__,
+                  resolved_path);
+  }
+
+  char launch_err_str[PATH_MAX];
+  launch_err_str[0] = '\0';
+
+  // TODO figure out how to handle QSetProcessEvent
+  // const char *process_event = ctx.GetProcessEvent();
+
+  // Ensure the binary is there.
+  struct stat path_stat;
+  if (::stat(resolved_path, &path_stat) == -1) {
+    error.SetErrorToErrno();
+    return error;
+  }
 
-    // If we fail to resolve the path to our executable, then just use what we
-    // were given and hope for the best
-    if (!ResolveExecutablePath(given_path, resolved_path,
-                               sizeof(resolved_path)) )
-    {
-        if (log)
-            log->Printf("%s(): failed to resolve binary path, using "
-                        "what was given verbatim and hoping for the best",
-                        __FUNCTION__);
-        ::strncpy(resolved_path, given_path,
-                  sizeof(resolved_path));
-    }
-    else
-    {
-        if (log)
-            log->Printf("%s(): resolved given binary path to: \"%s\"",
-                        __FUNCTION__, resolved_path);
-    }
-
-    char launch_err_str[PATH_MAX];
-    launch_err_str[0] = '\0';
-    
-    // TODO figure out how to handle QSetProcessEvent
-    // const char *process_event = ctx.GetProcessEvent();
-    
-    // Ensure the binary is there.
-    struct stat path_stat;
-    if (::stat(resolved_path, &path_stat) == -1)
-    {
-        error.SetErrorToErrno();
-        return error;
-    }
-    
-    // Fork a child process for debugging
-    // state_callback(eStateLaunching);
-
-    const auto argv = launch_info.GetArguments().GetConstArgumentVector();
-    const auto envp =
-        launch_info.GetEnvironmentEntries().GetConstArgumentVector();
-
-    switch (*launch_flavor)
-    {
-        case LaunchFlavor::ForkExec:
-        {
-            ::pid_t pid = LLDB_INVALID_PROCESS_ID;
-            error = ForkChildForPTraceDebugging(resolved_path, argv, envp,
-                                                &pid, pty_master_fd);
-            if (error.Success())
-            {
-                launch_info.SetProcessID(static_cast<lldb::pid_t>(pid));
-            }
-            else
-            {
-                // Reset any variables that might have been set during a failed
-                // launch attempt.
-                if (pty_master_fd)
-                    *pty_master_fd = -1;
-                
-                // We're done.
-                return error;
-            }
-        }
-            break;
+  // Fork a child process for debugging
+  // state_callback(eStateLaunching);
+
+  const auto argv = launch_info.GetArguments().GetConstArgumentVector();
+  const auto envp =
+      launch_info.GetEnvironmentEntries().GetConstArgumentVector();
+
+  switch (*launch_flavor) {
+  case LaunchFlavor::ForkExec: {
+    ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+    error = ForkChildForPTraceDebugging(resolved_path, argv, envp, &pid,
+                                        pty_master_fd);
+    if (error.Success()) {
+      launch_info.SetProcessID(static_cast<lldb::pid_t>(pid));
+    } else {
+      // Reset any variables that might have been set during a failed
+      // launch attempt.
+      if (pty_master_fd)
+        *pty_master_fd = -1;
+
+      // We're done.
+      return error;
+    }
+  } break;
 
 #ifdef WITH_FBS
-        case LaunchFlavor::FBS:
-        {
-            const char *app_ext = strstr(path, ".app");
-            if (app_ext && (app_ext[4] == '\0' || app_ext[4] == '/'))
-            {
-                std::string app_bundle_path(path, app_ext + strlen(".app"));
-                m_flags |= eMachProcessFlagsUsingFBS;
-                if (BoardServiceLaunchForDebug (app_bundle_path.c_str(), argv, envp, no_stdio, disable_aslr, event_data, launch_err) != 0)
-                    return m_pid; // A successful SBLaunchForDebug() returns and assigns a non-zero m_pid.
-                else
-                    break; // We tried a FBS launch, but didn't succeed lets get out
-            }
-        }
-            break;
+  case LaunchFlavor::FBS: {
+    const char *app_ext = strstr(path, ".app");
+    if (app_ext && (app_ext[4] == '\0' || app_ext[4] == '/')) {
+      std::string app_bundle_path(path, app_ext + strlen(".app"));
+      m_flags |= eMachProcessFlagsUsingFBS;
+      if (BoardServiceLaunchForDebug(app_bundle_path.c_str(), argv, envp,
+                                     no_stdio, disable_aslr, event_data,
+                                     launch_err) != 0)
+        return m_pid; // A successful SBLaunchForDebug() returns and assigns a
+                      // non-zero m_pid.
+      else
+        break; // We tried a FBS launch, but didn't succeed lets get out
+    }
+  } break;
 #endif
-            
+
 #ifdef WITH_BKS
-        case LaunchFlavor::BKS:
-        {
-            const char *app_ext = strstr(path, ".app");
-            if (app_ext && (app_ext[4] == '\0' || app_ext[4] == '/'))
-            {
-                std::string app_bundle_path(path, app_ext + strlen(".app"));
-                m_flags |= eMachProcessFlagsUsingBKS;
-                if (BoardServiceLaunchForDebug (app_bundle_path.c_str(), argv, envp, no_stdio, disable_aslr, event_data, launch_err) != 0)
-                    return m_pid; // A successful SBLaunchForDebug() returns and assigns a non-zero m_pid.
-                else
-                    break; // We tried a BKS launch, but didn't succeed lets get out
-            }
-        }
-            break;
+  case LaunchFlavor::BKS: {
+    const char *app_ext = strstr(path, ".app");
+    if (app_ext && (app_ext[4] == '\0' || app_ext[4] == '/')) {
+      std::string app_bundle_path(path, app_ext + strlen(".app"));
+      m_flags |= eMachProcessFlagsUsingBKS;
+      if (BoardServiceLaunchForDebug(app_bundle_path.c_str(), argv, envp,
+                                     no_stdio, disable_aslr, event_data,
+                                     launch_err) != 0)
+        return m_pid; // A successful SBLaunchForDebug() returns and assigns a
+                      // non-zero m_pid.
+      else
+        break; // We tried a BKS launch, but didn't succeed lets get out
+    }
+  } break;
 #endif
-            
+
 #ifdef WITH_SPRINGBOARD
-        case LaunchFlavor::SpringBoard:
-        {
-            //  .../whatever.app/whatever ?
-            //  Or .../com.apple.whatever.app/whatever -- be careful of ".app" in "com.apple.whatever" here
-            const char *app_ext = strstr (path, ".app/");
-            if (app_ext == NULL)
-            {
-                // .../whatever.app ?
-                int len = strlen (path);
-                if (len > 5)
-                {
-                    if (strcmp (path + len - 4, ".app") == 0)
-                    {
-                        app_ext = path + len - 4;
-                    }
-                }
-            }
-            if (app_ext)
-            {
-                std::string app_bundle_path(path, app_ext + strlen(".app"));
-                if (SBLaunchForDebug (app_bundle_path.c_str(), argv, envp, no_stdio, disable_aslr, launch_err) != 0)
-                    return m_pid; // A successful SBLaunchForDebug() returns and assigns a non-zero m_pid.
-                else
-                    break; // We tried a springboard launch, but didn't succeed lets get out
-            }
-        }
-            break;
-#endif
-            
-        case LaunchFlavor::PosixSpawn:
-        {
-            ::pid_t pid = LLDB_INVALID_PROCESS_ID;
-
-            // Retrieve paths for stdin/stdout/stderr.
-            cpu_type_t actual_cpu_type = 0;
-            error = PosixSpawnChildForPTraceDebugging(resolved_path,
-                                                      launch_info,
-                                                      &pid,
-                                                      &actual_cpu_type);
-            if (error.Success())
-            {
-                launch_info.SetProcessID(static_cast<lldb::pid_t>(pid));
-                if (pty_master_fd)
-                    *pty_master_fd = launch_info.GetPTY().
-                        ReleaseMasterFileDescriptor();
-            }
-            else
-            {
-                // Reset any variables that might have been set during a failed
-                // launch attempt.
-                if (pty_master_fd)
-                    *pty_master_fd = -1;
-
-                // We're done.
-                return error;
-            }
-            break;
-        }
-            
-        default:
-            // Invalid launch flavor.
-            error.SetErrorStringWithFormat("NativeProcessDarwin::%s(): unknown "
-                                           "launch flavor %d", __FUNCTION__,
-                                           (int)*launch_flavor);
-            return error;
-    }
-    
-    if (launch_info.GetProcessID() == LLDB_INVALID_PROCESS_ID)
-    {
-        // If we don't have a valid process ID and no one has set the error,
-        // then return a generic error.
-        if (error.Success())
-            error.SetErrorStringWithFormat("%s(): failed to launch, no reason "
-                                           "specified", __FUNCTION__);
+  case LaunchFlavor::SpringBoard: {
+    //  .../whatever.app/whatever ?
+    //  Or .../com.apple.whatever.app/whatever -- be careful of ".app" in
+    //  "com.apple.whatever" here
+    const char *app_ext = strstr(path, ".app/");
+    if (app_ext == NULL) {
+      // .../whatever.app ?
+      int len = strlen(path);
+      if (len > 5) {
+        if (strcmp(path + len - 4, ".app") == 0) {
+          app_ext = path + len - 4;
+        }
+      }
+    }
+    if (app_ext) {
+      std::string app_bundle_path(path, app_ext + strlen(".app"));
+      if (SBLaunchForDebug(app_bundle_path.c_str(), argv, envp, no_stdio,
+                           disable_aslr, launch_err) != 0)
+        return m_pid; // A successful SBLaunchForDebug() returns and assigns a
+                      // non-zero m_pid.
+      else
+        break; // We tried a springboard launch, but didn't succeed lets get out
     }
+  } break;
+#endif
 
-    // We're done with the launch side of the operation.
+  case LaunchFlavor::PosixSpawn: {
+    ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+
+    // Retrieve paths for stdin/stdout/stderr.
+    cpu_type_t actual_cpu_type = 0;
+    error = PosixSpawnChildForPTraceDebugging(resolved_path, launch_info, &pid,
+                                              &actual_cpu_type);
+    if (error.Success()) {
+      launch_info.SetProcessID(static_cast<lldb::pid_t>(pid));
+      if (pty_master_fd)
+        *pty_master_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
+    } else {
+      // Reset any variables that might have been set during a failed
+      // launch attempt.
+      if (pty_master_fd)
+        *pty_master_fd = -1;
+
+      // We're done.
+      return error;
+    }
+    break;
+  }
+
+  default:
+    // Invalid launch flavor.
+    error.SetErrorStringWithFormat("NativeProcessDarwin::%s(): unknown "
+                                   "launch flavor %d",
+                                   __FUNCTION__, (int)*launch_flavor);
     return error;
-}
+  }
 
-}} // namespaces
+  if (launch_info.GetProcessID() == LLDB_INVALID_PROCESS_ID) {
+    // If we don't have a valid process ID and no one has set the error,
+    // then return a generic error.
+    if (error.Success())
+      error.SetErrorStringWithFormat("%s(): failed to launch, no reason "
+                                     "specified",
+                                     __FUNCTION__);
+  }
 
+  // We're done with the launch side of the operation.
+  return error;
+}
+}
+} // namespaces

Modified: lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.h Tue Sep  6 15:57:50 2016
@@ -23,10 +23,8 @@
 
 #include "LaunchFlavor.h"
 
-namespace lldb_private
-{
-namespace darwin_process_launcher
-{
+namespace lldb_private {
+namespace darwin_process_launcher {
 // =============================================================================
 /// Launches a process for debugging.
 ///
@@ -41,9 +39,8 @@ namespace darwin_process_launcher
 /// @param[out] launch_flavor
 ///     Contains the launch flavor used when launching the process.
 // =============================================================================
-Error
-LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
-               lldb_private::process_darwin::LaunchFlavor *launch_flavor);
+Error LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
+                     lldb_private::process_darwin::LaunchFlavor *launch_flavor);
 
 } // darwin_process_launcher
 } // lldb_private

Modified: lldb/trunk/source/Plugins/Process/Darwin/LaunchFlavor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/LaunchFlavor.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/LaunchFlavor.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/LaunchFlavor.h Tue Sep  6 15:57:50 2016
@@ -13,22 +13,21 @@
 namespace lldb_private {
 namespace process_darwin {
 
-enum class LaunchFlavor
-{
-    Default = 0,
-    PosixSpawn = 1,
-    ForkExec = 2,
+enum class LaunchFlavor {
+  Default = 0,
+  PosixSpawn = 1,
+  ForkExec = 2,
 #ifdef WITH_SPRINGBOARD
-    SpringBoard = 3,
+  SpringBoard = 3,
 #endif
 #ifdef WITH_BKS
-    BKS = 4,
+  BKS = 4,
 #endif
 #ifdef WITH_FBS
-    FBS = 5
+  FBS = 5
 #endif
 };
-
-}} // namespaces
+}
+} // namespaces
 
 #endif /* LaunchFlavor_h */

Modified: lldb/trunk/source/Plugins/Process/Darwin/MachException.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/MachException.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/MachException.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/MachException.cpp Tue Sep  6 15:57:50 2016
@@ -15,8 +15,8 @@
 
 // C includes
 #include <errno.h>
-#include <sys/types.h>
 #include <sys/ptrace.h>
+#include <sys/types.h>
 
 // C++ includes
 #include <mutex>
@@ -33,51 +33,29 @@ using namespace lldb_private;
 using namespace lldb_private::process_darwin;
 
 // Routine mach_exception_raise
-extern "C"
-kern_return_t catch_mach_exception_raise
-(
-    mach_port_t exception_port,
-    mach_port_t thread,
-    mach_port_t task,
-    exception_type_t exception,
-    mach_exception_data_t code,
-    mach_msg_type_number_t codeCnt
-);
-
-extern "C"
-kern_return_t catch_mach_exception_raise_state
-(
-    mach_port_t exception_port,
-    exception_type_t exception,
-    const mach_exception_data_t code,
-    mach_msg_type_number_t codeCnt,
-    int *flavor,
-    const thread_state_t old_state,
-    mach_msg_type_number_t old_stateCnt,
-    thread_state_t new_state,
-    mach_msg_type_number_t *new_stateCnt
-);
+extern "C" kern_return_t
+catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread,
+                           mach_port_t task, exception_type_t exception,
+                           mach_exception_data_t code,
+                           mach_msg_type_number_t codeCnt);
+
+extern "C" kern_return_t catch_mach_exception_raise_state(
+    mach_port_t exception_port, exception_type_t exception,
+    const mach_exception_data_t code, mach_msg_type_number_t codeCnt,
+    int *flavor, const thread_state_t old_state,
+    mach_msg_type_number_t old_stateCnt, thread_state_t new_state,
+    mach_msg_type_number_t *new_stateCnt);
 
 // Routine mach_exception_raise_state_identity
-extern "C"
-kern_return_t catch_mach_exception_raise_state_identity
-(
-    mach_port_t exception_port,
-    mach_port_t thread,
-    mach_port_t task,
-    exception_type_t exception,
-    mach_exception_data_t code,
-    mach_msg_type_number_t codeCnt,
-    int *flavor,
-    thread_state_t old_state,
-    mach_msg_type_number_t old_stateCnt,
-    thread_state_t new_state,
-    mach_msg_type_number_t *new_stateCnt
-);
-
-extern "C" boolean_t mach_exc_server(
-        mach_msg_header_t *InHeadP,
-        mach_msg_header_t *OutHeadP);
+extern "C" kern_return_t catch_mach_exception_raise_state_identity(
+    mach_port_t exception_port, mach_port_t thread, mach_port_t task,
+    exception_type_t exception, mach_exception_data_t code,
+    mach_msg_type_number_t codeCnt, int *flavor, thread_state_t old_state,
+    mach_msg_type_number_t old_stateCnt, thread_state_t new_state,
+    mach_msg_type_number_t *new_stateCnt);
+
+extern "C" boolean_t mach_exc_server(mach_msg_header_t *InHeadP,
+                                     mach_msg_header_t *OutHeadP);
 
 // Any access to the g_message variable should be done by locking the
 // g_message_mutex first, using the g_message variable, then unlocking
@@ -86,107 +64,71 @@ extern "C" boolean_t mach_exc_server(
 
 static MachException::Data *g_message = NULL;
 
-
-extern "C"
-kern_return_t
-catch_mach_exception_raise_state
-(
-    mach_port_t                 exc_port,
-    exception_type_t            exc_type,
-    const mach_exception_data_t exc_data,
-    mach_msg_type_number_t      exc_data_count,
-    int *                       flavor,
-    const thread_state_t        old_state,
-    mach_msg_type_number_t      old_stateCnt,
-    thread_state_t              new_state,
-    mach_msg_type_number_t *    new_stateCnt
-)
-{
-    // TODO change to LIBLLDB_LOG_EXCEPTION
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-    if (log)
-    {
-        log->Printf("::%s(exc_port = 0x%4.4x, exc_type = %d (%s), "
-                    "exc_data = 0x%llx, exc_data_count = %d)",
-                        __FUNCTION__, exc_port, exc_type,
-                    MachException::Name(exc_type), (uint64_t)exc_data,
-                    exc_data_count);
-    }
-    return KERN_FAILURE;
-}
-
-extern "C"
-kern_return_t
-catch_mach_exception_raise_state_identity
-(
-    mach_port_t             exc_port,
-    mach_port_t             thread_port,
-    mach_port_t             task_port,
-    exception_type_t        exc_type,
-    mach_exception_data_t   exc_data,
-    mach_msg_type_number_t  exc_data_count,
-    int *                   flavor,
-    thread_state_t          old_state,
-    mach_msg_type_number_t  old_stateCnt,
-    thread_state_t          new_state,
-    mach_msg_type_number_t *new_stateCnt
-)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-    if (log)
-    {
-        log->Printf("::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, "
-                    "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] = "
-                    "{ 0x%llx, 0x%llx })", __FUNCTION__, exc_port, thread_port,
-                    task_port, exc_type, MachException::Name(exc_type),
-                    exc_data_count,
-                    (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
-                    (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
-    }
-    mach_port_deallocate (mach_task_self(), task_port);
-    mach_port_deallocate (mach_task_self(), thread_port);
-
-    return KERN_FAILURE;
-}
-
-extern "C"
-kern_return_t
-catch_mach_exception_raise
-(
-    mach_port_t             exc_port,
-    mach_port_t             thread_port,
-    mach_port_t             task_port,
-    exception_type_t        exc_type,
-    mach_exception_data_t   exc_data,
-    mach_msg_type_number_t  exc_data_count)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-    if (log)
-    {
-        log->Printf("::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, "
-                    "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] "
-                    "= { 0x%llx, 0x%llx })", __FUNCTION__, exc_port,
-                    thread_port, task_port, exc_type,
-                    MachException::Name(exc_type), exc_data_count,
-                    (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
-                    (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
-    }
-
-    if (task_port == g_message->task_port)
-    {
-        g_message->task_port = task_port;
-        g_message->thread_port = thread_port;
-        g_message->exc_type = exc_type;
-        g_message->exc_data.resize(exc_data_count);
-        ::memcpy(&g_message->exc_data[0], exc_data,
-                 g_message->exc_data.size() *
-                 sizeof (mach_exception_data_type_t));
-        return KERN_SUCCESS;
-    }
-    return KERN_FAILURE;
+extern "C" kern_return_t catch_mach_exception_raise_state(
+    mach_port_t exc_port, exception_type_t exc_type,
+    const mach_exception_data_t exc_data, mach_msg_type_number_t exc_data_count,
+    int *flavor, const thread_state_t old_state,
+    mach_msg_type_number_t old_stateCnt, thread_state_t new_state,
+    mach_msg_type_number_t *new_stateCnt) {
+  // TODO change to LIBLLDB_LOG_EXCEPTION
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+  if (log) {
+    log->Printf("::%s(exc_port = 0x%4.4x, exc_type = %d (%s), "
+                "exc_data = 0x%llx, exc_data_count = %d)",
+                __FUNCTION__, exc_port, exc_type, MachException::Name(exc_type),
+                (uint64_t)exc_data, exc_data_count);
+  }
+  return KERN_FAILURE;
+}
+
+extern "C" kern_return_t catch_mach_exception_raise_state_identity(
+    mach_port_t exc_port, mach_port_t thread_port, mach_port_t task_port,
+    exception_type_t exc_type, mach_exception_data_t exc_data,
+    mach_msg_type_number_t exc_data_count, int *flavor,
+    thread_state_t old_state, mach_msg_type_number_t old_stateCnt,
+    thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+  if (log) {
+    log->Printf("::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, "
+                "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] = "
+                "{ 0x%llx, 0x%llx })",
+                __FUNCTION__, exc_port, thread_port, task_port, exc_type,
+                MachException::Name(exc_type), exc_data_count,
+                (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
+                (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
+  }
+  mach_port_deallocate(mach_task_self(), task_port);
+  mach_port_deallocate(mach_task_self(), thread_port);
+
+  return KERN_FAILURE;
+}
+
+extern "C" kern_return_t
+catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
+                           mach_port_t task_port, exception_type_t exc_type,
+                           mach_exception_data_t exc_data,
+                           mach_msg_type_number_t exc_data_count) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+  if (log) {
+    log->Printf("::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, "
+                "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] "
+                "= { 0x%llx, 0x%llx })",
+                __FUNCTION__, exc_port, thread_port, task_port, exc_type,
+                MachException::Name(exc_type), exc_data_count,
+                (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
+                (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
+  }
+
+  if (task_port == g_message->task_port) {
+    g_message->task_port = task_port;
+    g_message->thread_port = thread_port;
+    g_message->exc_type = exc_type;
+    g_message->exc_data.resize(exc_data_count);
+    ::memcpy(&g_message->exc_data[0], exc_data,
+             g_message->exc_data.size() * sizeof(mach_exception_data_type_t));
+    return KERN_SUCCESS;
+  }
+  return KERN_FAILURE;
 }
 
 #if 0
@@ -216,316 +158,249 @@ MachException::Message::Dump(Stream &str
 }
 #endif
 
-bool
-MachException::Data::GetStopInfo(struct ThreadStopInfo *stop_info,
-                                 const UnixSignals &signals,
-                                 Stream &stream) const
-{
-    if (!stop_info)
-        return false;
-
-    // Zero out the structure.
-    memset(stop_info, 0, sizeof(struct ThreadStopInfo));
-
-    if (exc_type == 0)
-    {
-        stop_info->reason = eStopReasonInvalid;
-        return true;
-    }
-
-    // We always stop with a mach exception.
-    stop_info->reason = eStopReasonException;
-    // Save the EXC_XXXX exception type.
-    stop_info->details.exception.type = exc_type;
-
-    // Fill in a text description
-    const char * exc_name = MachException::Name(exc_type);
-    if (exc_name)
-        stream.Printf("%s", exc_name);
-    else
-        stream.Printf("%i", exc_type);
-
-    stop_info->details.exception.data_count = exc_data.size();
-
-    int soft_signal = SoftSignal();
-    if (soft_signal)
-    {
-        const char *sig_str = signals.GetSignalAsCString(soft_signal);
-        stream.Printf(" EXC_SOFT_SIGNAL( %i ( %s ))", soft_signal,
-                      sig_str ? sig_str : "unknown signal");
-    }
-    else
-    {
-        // No special disassembly for exception data, just print it.
-        size_t idx;
-        stream.Printf(" data[%llu] = {",
-                      (uint64_t)stop_info->details.exception.data_count);
-
-        for (idx = 0; idx < stop_info->details.exception.data_count; ++idx)
-        {
-            stream.Printf("0x%llx%c", (uint64_t)exc_data[idx],
-                          ((idx + 1 == stop_info->details.exception.data_count)
-                           ? '}' : ','));
-        }
-    }
+bool MachException::Data::GetStopInfo(struct ThreadStopInfo *stop_info,
+                                      const UnixSignals &signals,
+                                      Stream &stream) const {
+  if (!stop_info)
+    return false;
 
-    // Copy the exception data
-    for (size_t i = 0; i < stop_info->details.exception.data_count; i++)
-        stop_info->details.exception.data[i] = exc_data[i];
+  // Zero out the structure.
+  memset(stop_info, 0, sizeof(struct ThreadStopInfo));
 
+  if (exc_type == 0) {
+    stop_info->reason = eStopReasonInvalid;
     return true;
-}
-
-Error
-MachException::Message::Receive(mach_port_t port, mach_msg_option_t options,
-                                mach_msg_timeout_t timeout,
-                                mach_port_t notify_port)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-
-    mach_msg_timeout_t mach_msg_timeout =
-        options & MACH_RCV_TIMEOUT ? timeout : 0;
-    if (log && ((options & MACH_RCV_TIMEOUT) == 0))
-    {
-        // Dump this log message if we have no timeout in case it never returns
-        log->Printf("::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, "
-                    "local_port = %#x, reserved = 0x%x, id = 0x%x}, "
-                    "option = %#x, send_size = 0, rcv_size = %llu, "
-                    "rcv_name = %#x, timeout = %u, notify = %#x)",
-                        exc_msg.hdr.msgh_bits,
-                        exc_msg.hdr.msgh_size,
-                        exc_msg.hdr.msgh_remote_port,
-                        exc_msg.hdr.msgh_local_port,
-                        exc_msg.hdr.msgh_reserved,
-                        exc_msg.hdr.msgh_id,
-                        options,
-                        (uint64_t)sizeof (exc_msg.data),
-                        port,
-                        mach_msg_timeout,
-                        notify_port);
-    }
-
-    mach_msg_return_t mach_err =
-        ::mach_msg (&exc_msg.hdr,
-                    options,                  // options
-                    0,                        // Send size
-                    sizeof (exc_msg.data),    // Receive size
-                    port,                     // exception port to watch for
-                                              // exception on
-                    mach_msg_timeout,         // timeout in msec (obeyed only
-                                              // if MACH_RCV_TIMEOUT is ORed
-                                              // into the options parameter)
-                    notify_port);
-    error.SetError(mach_err, eErrorTypeMachKernel);
-
-    // Dump any errors we get
-    if (error.Fail() && log)
-    {
-        log->Printf("::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, "
-                    "local_port = %#x, reserved = 0x%x, id = 0x%x}, "
-                    "option = %#x, send_size = %u, rcv_size = %lu, rcv_name "
-                    "= %#x, timeout = %u, notify = %#x) failed: %s",
-                    exc_msg.hdr.msgh_bits,
-                    exc_msg.hdr.msgh_size,
-                    exc_msg.hdr.msgh_remote_port,
-                    exc_msg.hdr.msgh_local_port,
-                    exc_msg.hdr.msgh_reserved,
-                    exc_msg.hdr.msgh_id,
-                    options,
-                    0,
-                    sizeof(exc_msg.data),
-                    port,
-                    mach_msg_timeout,
-                    notify_port,
-                    error.AsCString());
-    }
-    return error;
-}
-
-void
-MachException::Message::Dump(Stream &stream) const
-{
-    stream.Printf("  exc_msg { bits = 0x%8.8x size = 0x%8.8x remote-port = "
-                  "0x%8.8x local-port = 0x%8.8x reserved = 0x%8.8x id = "
-                  "0x%8.8x }\n",
-                  exc_msg.hdr.msgh_bits,
-                  exc_msg.hdr.msgh_size,
-                  exc_msg.hdr.msgh_remote_port,
-                  exc_msg.hdr.msgh_local_port,
-                  exc_msg.hdr.msgh_reserved,
-                  exc_msg.hdr.msgh_id);
-
-    stream.Printf("  reply_msg { bits = 0x%8.8x size = 0x%8.8x remote-port = "
-                  "0x%8.8x local-port = 0x%8.8x reserved = 0x%8.8x id = "
-                  "0x%8.8x }",
-                  reply_msg.hdr.msgh_bits,
-                  reply_msg.hdr.msgh_size,
-                  reply_msg.hdr.msgh_remote_port,
-                  reply_msg.hdr.msgh_local_port,
-                  reply_msg.hdr.msgh_reserved,
-                  reply_msg.hdr.msgh_id);
-}
-
-bool
-MachException::Message::CatchExceptionRaise(task_t task)
-{
-    bool success = false;
-    // locker will keep a mutex locked until it goes out of scope
-//    PThreadMutex::Locker locker(&g_message_mutex);
-    //    DNBLogThreaded("calling  mach_exc_server");
-    state.task_port = task;
-    g_message = &state;
-    // The exc_server function is the MIG generated server handling function
-    // to handle messages from the kernel relating to the occurrence of an
-    // exception in a thread. Such messages are delivered to the exception port
-    // set via thread_set_exception_ports or task_set_exception_ports. When an
-    // exception occurs in a thread, the thread sends an exception message to
-    // its exception port, blocking in the kernel waiting for the receipt of a
-    // reply. The exc_server function performs all necessary argument handling
-    // for this kernel message and calls catch_exception_raise,
-    // catch_exception_raise_state or catch_exception_raise_state_identity,
-    // which should handle the exception. If the called routine returns
-    // KERN_SUCCESS, a reply message will be sent, allowing the thread to
-    // continue from the point of the exception; otherwise, no reply message
-    // is sent and the called routine must have dealt with the exception
-    // thread directly.
-    if (mach_exc_server (&exc_msg.hdr, &reply_msg.hdr))
-    {
-        success = true;
-    }
-    else
-    {
-        Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                          LIBLLDB_LOG_VERBOSE));
-        if (log)
-            log->Printf("MachException::Message::%s(): mach_exc_server "
-                        "returned zero...", __FUNCTION__);
-    }
-    g_message = NULL;
-    return success;
-}
-
-Error
-MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task,
-                              int signal)
-{
-    // Reply to the exception...
-    Error error;
-
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-
-    // If we had a soft signal, we need to update the thread first so it can
-    // continue without signaling
-    int soft_signal = state.SoftSignal();
-    if (soft_signal)
-    {
-        int state_pid = -1;
-        if (inferior_task == state.task_port)
-        {
-            // This is our task, so we can update the signal to send to it
-            state_pid = inferior_pid;
-            soft_signal = signal;
-        }
-        else
-        {
-            auto mach_err = ::pid_for_task(state.task_port, &state_pid);
-            if (mach_err)
-            {
-                error.SetError(mach_err, eErrorTypeMachKernel);
-                if (log)
-                    log->Printf("MachException::Message::%s(): pid_for_task() "
-                                "failed: %s", __FUNCTION__, error.AsCString());
-                return error;
-            }
-        }
-
-        lldbassert(state_pid != -1);
-        if (state_pid != -1)
-        {
-            errno = 0;
-            caddr_t thread_port_caddr = (caddr_t)(uintptr_t)state.thread_port;
-            if (::ptrace(PT_THUPDATE, state_pid, thread_port_caddr, soft_signal)
-                != 0)
-                error.SetError(errno, eErrorTypePOSIX);
-
-            if (!error.Success())
-            {
-                if (log)
-                    log->Printf("::ptrace(request = PT_THUPDATE, pid = "
-                                "0x%4.4x, tid = 0x%4.4x, signal = %i)",
-                                state_pid, state.thread_port, soft_signal);
-                return error;
-            }
-        }
-    }
+  }
 
+  // We always stop with a mach exception.
+  stop_info->reason = eStopReasonException;
+  // Save the EXC_XXXX exception type.
+  stop_info->details.exception.type = exc_type;
+
+  // Fill in a text description
+  const char *exc_name = MachException::Name(exc_type);
+  if (exc_name)
+    stream.Printf("%s", exc_name);
+  else
+    stream.Printf("%i", exc_type);
+
+  stop_info->details.exception.data_count = exc_data.size();
+
+  int soft_signal = SoftSignal();
+  if (soft_signal) {
+    const char *sig_str = signals.GetSignalAsCString(soft_signal);
+    stream.Printf(" EXC_SOFT_SIGNAL( %i ( %s ))", soft_signal,
+                  sig_str ? sig_str : "unknown signal");
+  } else {
+    // No special disassembly for exception data, just print it.
+    size_t idx;
+    stream.Printf(" data[%llu] = {",
+                  (uint64_t)stop_info->details.exception.data_count);
+
+    for (idx = 0; idx < stop_info->details.exception.data_count; ++idx) {
+      stream.Printf(
+          "0x%llx%c", (uint64_t)exc_data[idx],
+          ((idx + 1 == stop_info->details.exception.data_count) ? '}' : ','));
+    }
+  }
+
+  // Copy the exception data
+  for (size_t i = 0; i < stop_info->details.exception.data_count; i++)
+    stop_info->details.exception.data[i] = exc_data[i];
+
+  return true;
+}
+
+Error MachException::Message::Receive(mach_port_t port,
+                                      mach_msg_option_t options,
+                                      mach_msg_timeout_t timeout,
+                                      mach_port_t notify_port) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+
+  mach_msg_timeout_t mach_msg_timeout =
+      options & MACH_RCV_TIMEOUT ? timeout : 0;
+  if (log && ((options & MACH_RCV_TIMEOUT) == 0)) {
+    // Dump this log message if we have no timeout in case it never returns
+    log->Printf("::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, "
+                "local_port = %#x, reserved = 0x%x, id = 0x%x}, "
+                "option = %#x, send_size = 0, rcv_size = %llu, "
+                "rcv_name = %#x, timeout = %u, notify = %#x)",
+                exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size,
+                exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port,
+                exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id, options,
+                (uint64_t)sizeof(exc_msg.data), port, mach_msg_timeout,
+                notify_port);
+  }
+
+  mach_msg_return_t mach_err =
+      ::mach_msg(&exc_msg.hdr,
+                 options,              // options
+                 0,                    // Send size
+                 sizeof(exc_msg.data), // Receive size
+                 port,                 // exception port to watch for
+                                       // exception on
+                 mach_msg_timeout,     // timeout in msec (obeyed only
+                                       // if MACH_RCV_TIMEOUT is ORed
+                                       // into the options parameter)
+                 notify_port);
+  error.SetError(mach_err, eErrorTypeMachKernel);
+
+  // Dump any errors we get
+  if (error.Fail() && log) {
+    log->Printf("::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, "
+                "local_port = %#x, reserved = 0x%x, id = 0x%x}, "
+                "option = %#x, send_size = %u, rcv_size = %lu, rcv_name "
+                "= %#x, timeout = %u, notify = %#x) failed: %s",
+                exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size,
+                exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port,
+                exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id, options, 0,
+                sizeof(exc_msg.data), port, mach_msg_timeout, notify_port,
+                error.AsCString());
+  }
+  return error;
+}
+
+void MachException::Message::Dump(Stream &stream) const {
+  stream.Printf("  exc_msg { bits = 0x%8.8x size = 0x%8.8x remote-port = "
+                "0x%8.8x local-port = 0x%8.8x reserved = 0x%8.8x id = "
+                "0x%8.8x }\n",
+                exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size,
+                exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port,
+                exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id);
+
+  stream.Printf("  reply_msg { bits = 0x%8.8x size = 0x%8.8x remote-port = "
+                "0x%8.8x local-port = 0x%8.8x reserved = 0x%8.8x id = "
+                "0x%8.8x }",
+                reply_msg.hdr.msgh_bits, reply_msg.hdr.msgh_size,
+                reply_msg.hdr.msgh_remote_port, reply_msg.hdr.msgh_local_port,
+                reply_msg.hdr.msgh_reserved, reply_msg.hdr.msgh_id);
+}
+
+bool MachException::Message::CatchExceptionRaise(task_t task) {
+  bool success = false;
+  // locker will keep a mutex locked until it goes out of scope
+  //    PThreadMutex::Locker locker(&g_message_mutex);
+  //    DNBLogThreaded("calling  mach_exc_server");
+  state.task_port = task;
+  g_message = &state;
+  // The exc_server function is the MIG generated server handling function
+  // to handle messages from the kernel relating to the occurrence of an
+  // exception in a thread. Such messages are delivered to the exception port
+  // set via thread_set_exception_ports or task_set_exception_ports. When an
+  // exception occurs in a thread, the thread sends an exception message to
+  // its exception port, blocking in the kernel waiting for the receipt of a
+  // reply. The exc_server function performs all necessary argument handling
+  // for this kernel message and calls catch_exception_raise,
+  // catch_exception_raise_state or catch_exception_raise_state_identity,
+  // which should handle the exception. If the called routine returns
+  // KERN_SUCCESS, a reply message will be sent, allowing the thread to
+  // continue from the point of the exception; otherwise, no reply message
+  // is sent and the called routine must have dealt with the exception
+  // thread directly.
+  if (mach_exc_server(&exc_msg.hdr, &reply_msg.hdr)) {
+    success = true;
+  } else {
+    Log *log(
+        GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
     if (log)
-        log->Printf("::mach_msg ( msg->{bits = %#x, size = %u, remote_port "
-                    "= %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, "
-                    "option = %#x, send_size = %u, rcv_size = %u, rcv_name "
-                    "= %#x, timeout = %u, notify = %#x)",
-                    reply_msg.hdr.msgh_bits,
-                    reply_msg.hdr.msgh_size,
-                    reply_msg.hdr.msgh_remote_port,
-                    reply_msg.hdr.msgh_local_port,
-                    reply_msg.hdr.msgh_reserved,
-                    reply_msg.hdr.msgh_id,
-                    MACH_SEND_MSG | MACH_SEND_INTERRUPT,
-                    reply_msg.hdr.msgh_size,
-                    0,
-                    MACH_PORT_NULL,
-                    MACH_MSG_TIMEOUT_NONE,
-                    MACH_PORT_NULL);
-
-    auto mach_err = ::mach_msg(&reply_msg.hdr,
-                               MACH_SEND_MSG | MACH_SEND_INTERRUPT,
-                               reply_msg.hdr.msgh_size,
-                               0,
-                               MACH_PORT_NULL,
-                               MACH_MSG_TIMEOUT_NONE,
-                               MACH_PORT_NULL);
-    if (mach_err)
+      log->Printf("MachException::Message::%s(): mach_exc_server "
+                  "returned zero...",
+                  __FUNCTION__);
+  }
+  g_message = NULL;
+  return success;
+}
+
+Error MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task,
+                                    int signal) {
+  // Reply to the exception...
+  Error error;
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+
+  // If we had a soft signal, we need to update the thread first so it can
+  // continue without signaling
+  int soft_signal = state.SoftSignal();
+  if (soft_signal) {
+    int state_pid = -1;
+    if (inferior_task == state.task_port) {
+      // This is our task, so we can update the signal to send to it
+      state_pid = inferior_pid;
+      soft_signal = signal;
+    } else {
+      auto mach_err = ::pid_for_task(state.task_port, &state_pid);
+      if (mach_err) {
         error.SetError(mach_err, eErrorTypeMachKernel);
-
-    // Log our error if we have one.
-    if (error.Fail() && log)
-    {
-        if (error.GetError() == MACH_SEND_INTERRUPTED)
-        {
-            log->PutCString("::mach_msg() - send interrupted");
-            // TODO: keep retrying to reply???
-        }
-        else if (state.task_port == inferior_task)
-        {
-            log->Printf("mach_msg(): returned an error when replying "
-                        "to a mach exception: error = %u (%s)",
-                        error.GetError(), error.AsCString());
-        }
-        else
-        {
-            log->Printf("::mach_msg() - failed (child of task): %u (%s)",
-                        error.GetError(), error.AsCString());
-        }
+        if (log)
+          log->Printf("MachException::Message::%s(): pid_for_task() "
+                      "failed: %s",
+                      __FUNCTION__, error.AsCString());
+        return error;
+      }
     }
 
-    return error;
-}
+    lldbassert(state_pid != -1);
+    if (state_pid != -1) {
+      errno = 0;
+      caddr_t thread_port_caddr = (caddr_t)(uintptr_t)state.thread_port;
+      if (::ptrace(PT_THUPDATE, state_pid, thread_port_caddr, soft_signal) != 0)
+        error.SetError(errno, eErrorTypePOSIX);
 
-#define PREV_EXC_MASK_ALL (EXC_MASK_BAD_ACCESS      | \
-                           EXC_MASK_BAD_INSTRUCTION | \
-                           EXC_MASK_ARITHMETIC      | \
-                           EXC_MASK_EMULATION       | \
-                           EXC_MASK_SOFTWARE        | \
-                           EXC_MASK_BREAKPOINT      | \
-                           EXC_MASK_SYSCALL         | \
-                           EXC_MASK_MACH_SYSCALL    | \
-                           EXC_MASK_RPC_ALERT       | \
-                           EXC_MASK_MACHINE)
+      if (!error.Success()) {
+        if (log)
+          log->Printf("::ptrace(request = PT_THUPDATE, pid = "
+                      "0x%4.4x, tid = 0x%4.4x, signal = %i)",
+                      state_pid, state.thread_port, soft_signal);
+        return error;
+      }
+    }
+  }
+
+  if (log)
+    log->Printf("::mach_msg ( msg->{bits = %#x, size = %u, remote_port "
+                "= %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, "
+                "option = %#x, send_size = %u, rcv_size = %u, rcv_name "
+                "= %#x, timeout = %u, notify = %#x)",
+                reply_msg.hdr.msgh_bits, reply_msg.hdr.msgh_size,
+                reply_msg.hdr.msgh_remote_port, reply_msg.hdr.msgh_local_port,
+                reply_msg.hdr.msgh_reserved, reply_msg.hdr.msgh_id,
+                MACH_SEND_MSG | MACH_SEND_INTERRUPT, reply_msg.hdr.msgh_size, 0,
+                MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+
+  auto mach_err =
+      ::mach_msg(&reply_msg.hdr, MACH_SEND_MSG | MACH_SEND_INTERRUPT,
+                 reply_msg.hdr.msgh_size, 0, MACH_PORT_NULL,
+                 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+  if (mach_err)
+    error.SetError(mach_err, eErrorTypeMachKernel);
+
+  // Log our error if we have one.
+  if (error.Fail() && log) {
+    if (error.GetError() == MACH_SEND_INTERRUPTED) {
+      log->PutCString("::mach_msg() - send interrupted");
+      // TODO: keep retrying to reply???
+    } else if (state.task_port == inferior_task) {
+      log->Printf("mach_msg(): returned an error when replying "
+                  "to a mach exception: error = %u (%s)",
+                  error.GetError(), error.AsCString());
+    } else {
+      log->Printf("::mach_msg() - failed (child of task): %u (%s)",
+                  error.GetError(), error.AsCString());
+    }
+  }
+
+  return error;
+}
+
+#define PREV_EXC_MASK_ALL                                                      \
+  (EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC |      \
+   EXC_MASK_EMULATION | EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT |              \
+   EXC_MASK_SYSCALL | EXC_MASK_MACH_SYSCALL | EXC_MASK_RPC_ALERT |             \
+   EXC_MASK_MACHINE)
 
-// Don't listen for EXC_RESOURCE, it should really get handled by the system handler.
+// Don't listen for EXC_RESOURCE, it should really get handled by the system
+// handler.
 
 #ifndef EXC_RESOURCE
 #define EXC_RESOURCE 11
@@ -537,148 +412,132 @@ MachException::Message::Reply(::pid_t in
 
 #define LLDB_EXC_MASK (EXC_MASK_ALL & ~EXC_MASK_RESOURCE)
 
-Error
-MachException::PortInfo::Save(task_t task)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-
-    if (log)
-        log->Printf("MachException::PortInfo::%s(task = 0x%4.4x)",
-                    __FUNCTION__, task);
-
-    // Be careful to be able to have debugserver built on a newer OS than what
-    // it is currently running on by being able to start with all exceptions
-    // and back off to just what is supported on the current system
-    mask = LLDB_EXC_MASK;
+Error MachException::PortInfo::Save(task_t task) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+
+  if (log)
+    log->Printf("MachException::PortInfo::%s(task = 0x%4.4x)", __FUNCTION__,
+                task);
+
+  // Be careful to be able to have debugserver built on a newer OS than what
+  // it is currently running on by being able to start with all exceptions
+  // and back off to just what is supported on the current system
+  mask = LLDB_EXC_MASK;
+
+  count = (sizeof(ports) / sizeof(ports[0]));
+  auto mach_err = ::task_get_exception_ports(task, mask, masks, &count, ports,
+                                             behaviors, flavors);
+  if (mach_err)
+    error.SetError(mach_err, eErrorTypeMachKernel);
 
+  if (log) {
+    if (error.Success()) {
+      log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = "
+                  "0x%x, maskCnt => %u, ports, behaviors, flavors)",
+                  task, mask, count);
+    } else {
+      log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = 0x%x, "
+                  "maskCnt => %u, ports, behaviors, flavors) error: %u (%s)",
+                  task, mask, count, error.GetError(), error.AsCString());
+    }
+  }
+
+  if ((error.GetError() == KERN_INVALID_ARGUMENT) &&
+      (mask != PREV_EXC_MASK_ALL)) {
+    mask = PREV_EXC_MASK_ALL;
     count = (sizeof(ports) / sizeof(ports[0]));
-    auto mach_err = ::task_get_exception_ports(task, mask, masks, &count, ports,
-                                               behaviors, flavors);
-    if (mach_err)
-        error.SetError(mach_err, eErrorTypeMachKernel);
-
-    if (log)
-    {
-        if (error.Success())
-        {
-            log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = "
-                        "0x%x, maskCnt => %u, ports, behaviors, flavors)",
-                        task, mask, count);
-        }
-        else
-        {
-            log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = 0x%x, "
-                        "maskCnt => %u, ports, behaviors, flavors) error: %u (%s)",
-                        task, mask, count, error.GetError(), error.AsCString());
-        }
-    }
-
-    if ((error.GetError() == KERN_INVALID_ARGUMENT) &&
-        (mask != PREV_EXC_MASK_ALL))
-    {
-        mask = PREV_EXC_MASK_ALL;
-        count = (sizeof(ports) / sizeof(ports[0]));
-        mach_err = ::task_get_exception_ports(task, mask, masks, &count, ports,
-                                              behaviors, flavors);
-        error.SetError(mach_err, eErrorTypeMachKernel);
-        if (log)
-        {
-            if (error.Success())
-            {
-                log->Printf("::task_get_exception_ports(task = 0x%4.4x, "
-                            "mask = 0x%x, maskCnt => %u, ports, behaviors, "
-                            "flavors)", task, mask, count);
-            }
-            else
-            {
-                log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = "
-                            "0x%x, maskCnt => %u, ports, behaviors, flavors) "
-                            "error: %u (%s)", task, mask, count,
-                            error.GetError(), error.AsCString());
-            }
-        }
-    }
-    if (error.Fail())
-    {
-        mask = 0;
-        count = 0;
-    }
-    return error;
+    mach_err = ::task_get_exception_ports(task, mask, masks, &count, ports,
+                                          behaviors, flavors);
+    error.SetError(mach_err, eErrorTypeMachKernel);
+    if (log) {
+      if (error.Success()) {
+        log->Printf("::task_get_exception_ports(task = 0x%4.4x, "
+                    "mask = 0x%x, maskCnt => %u, ports, behaviors, "
+                    "flavors)",
+                    task, mask, count);
+      } else {
+        log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = "
+                    "0x%x, maskCnt => %u, ports, behaviors, flavors) "
+                    "error: %u (%s)",
+                    task, mask, count, error.GetError(), error.AsCString());
+      }
+    }
+  }
+  if (error.Fail()) {
+    mask = 0;
+    count = 0;
+  }
+  return error;
 }
 
-Error
-MachException::PortInfo::Restore(task_t task)
-{
-    Error error;
+Error MachException::PortInfo::Restore(task_t task) {
+  Error error;
 
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
 
-    if (log)
-        log->Printf("MachException::PortInfo::Restore(task = 0x%4.4x)", task);
+  if (log)
+    log->Printf("MachException::PortInfo::Restore(task = 0x%4.4x)", task);
 
-    uint32_t i = 0;
-    if (count > 0)
-    {
-        for (i = 0; i < count; i++)
-        {
-            auto mach_err = ::task_set_exception_ports(task, masks[i], ports[i],
-                                                       behaviors[i],
-                                                       flavors[i]);
-            if (mach_err)
-                error.SetError(mach_err, eErrorTypeMachKernel);
-            if (log)
-            {
-                if (error.Success())
-                {
-                    log->Printf("::task_set_exception_ports(task = 0x%4.4x, "
-                                "exception_mask = 0x%8.8x, new_port = 0x%4.4x, "
-                                "behavior = 0x%8.8x, new_flavor = 0x%8.8x)",
-                                task, masks[i], ports[i], behaviors[i],
-                                flavors[i]);
-                }
-                else
-                {
-                    log->Printf("::task_set_exception_ports(task = 0x%4.4x, "
-                                "exception_mask = 0x%8.8x, new_port = 0x%4.4x, "
-                                "behavior = 0x%8.8x, new_flavor = 0x%8.8x): "
-                                "error %u (%s)", task, masks[i], ports[i],
-                                behaviors[i], flavors[i], error.GetError(),
-                                error.AsCString());
-                }
-            }
-
-            // Bail if we encounter any errors
-            if (error.Fail())
-                break;
+  uint32_t i = 0;
+  if (count > 0) {
+    for (i = 0; i < count; i++) {
+      auto mach_err = ::task_set_exception_ports(task, masks[i], ports[i],
+                                                 behaviors[i], flavors[i]);
+      if (mach_err)
+        error.SetError(mach_err, eErrorTypeMachKernel);
+      if (log) {
+        if (error.Success()) {
+          log->Printf("::task_set_exception_ports(task = 0x%4.4x, "
+                      "exception_mask = 0x%8.8x, new_port = 0x%4.4x, "
+                      "behavior = 0x%8.8x, new_flavor = 0x%8.8x)",
+                      task, masks[i], ports[i], behaviors[i], flavors[i]);
+        } else {
+          log->Printf("::task_set_exception_ports(task = 0x%4.4x, "
+                      "exception_mask = 0x%8.8x, new_port = 0x%4.4x, "
+                      "behavior = 0x%8.8x, new_flavor = 0x%8.8x): "
+                      "error %u (%s)",
+                      task, masks[i], ports[i], behaviors[i], flavors[i],
+                      error.GetError(), error.AsCString());
         }
+      }
+
+      // Bail if we encounter any errors
+      if (error.Fail())
+        break;
     }
+  }
 
-    count = 0;
-    return error;
+  count = 0;
+  return error;
 }
 
-const char *
-MachException::Name(exception_type_t exc_type)
-{
-    switch (exc_type)
-    {
-    case EXC_BAD_ACCESS:        return "EXC_BAD_ACCESS";
-    case EXC_BAD_INSTRUCTION:   return "EXC_BAD_INSTRUCTION";
-    case EXC_ARITHMETIC:        return "EXC_ARITHMETIC";
-    case EXC_EMULATION:         return "EXC_EMULATION";
-    case EXC_SOFTWARE:          return "EXC_SOFTWARE";
-    case EXC_BREAKPOINT:        return "EXC_BREAKPOINT";
-    case EXC_SYSCALL:           return "EXC_SYSCALL";
-    case EXC_MACH_SYSCALL:      return "EXC_MACH_SYSCALL";
-    case EXC_RPC_ALERT:         return "EXC_RPC_ALERT";
+const char *MachException::Name(exception_type_t exc_type) {
+  switch (exc_type) {
+  case EXC_BAD_ACCESS:
+    return "EXC_BAD_ACCESS";
+  case EXC_BAD_INSTRUCTION:
+    return "EXC_BAD_INSTRUCTION";
+  case EXC_ARITHMETIC:
+    return "EXC_ARITHMETIC";
+  case EXC_EMULATION:
+    return "EXC_EMULATION";
+  case EXC_SOFTWARE:
+    return "EXC_SOFTWARE";
+  case EXC_BREAKPOINT:
+    return "EXC_BREAKPOINT";
+  case EXC_SYSCALL:
+    return "EXC_SYSCALL";
+  case EXC_MACH_SYSCALL:
+    return "EXC_MACH_SYSCALL";
+  case EXC_RPC_ALERT:
+    return "EXC_RPC_ALERT";
 #ifdef EXC_CRASH
-    case EXC_CRASH:             return "EXC_CRASH";
+  case EXC_CRASH:
+    return "EXC_CRASH";
 #endif
-    default:
-        break;
-    }
-    return NULL;
+  default:
+    break;
+  }
+  return NULL;
 }

Modified: lldb/trunk/source/Plugins/Process/Darwin/MachException.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/MachException.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/MachException.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/MachException.h Tue Sep  6 15:57:50 2016
@@ -11,150 +11,127 @@
 //
 //===----------------------------------------------------------------------===//
 
-
 #ifndef __MachException_h__
 #define __MachException_h__
 
 #include <mach/mach.h>
 #include <vector>
 
+#include "lldb/Host/Debug.h"
 #include "lldb/lldb-private-forward.h"
 #include "lldb/lldb-types.h"
-#include "lldb/Host/Debug.h"
 
-namespace lldb_private
-{
-namespace process_darwin
-{
-
-typedef union MachMessageTag
-{
-    mach_msg_header_t hdr;
-    char data[1024];
-} MachMessage;
+namespace lldb_private {
+namespace process_darwin {
 
+typedef union MachMessageTag {
+  mach_msg_header_t hdr;
+  char data[1024];
+} MachMessage;
 
-class MachException
-{
+class MachException {
 public:
+  struct PortInfo {
+    exception_mask_t mask; // the exception mask for this device which may be a
+                           // subset of EXC_MASK_ALL...
+    exception_mask_t masks[EXC_TYPES_COUNT];
+    mach_port_t ports[EXC_TYPES_COUNT];
+    exception_behavior_t behaviors[EXC_TYPES_COUNT];
+    thread_state_flavor_t flavors[EXC_TYPES_COUNT];
+    mach_msg_type_number_t count;
+
+    Error Save(task_t task);
+
+    Error Restore(task_t task);
+  };
+
+  struct Data {
+    task_t task_port;
+    thread_t thread_port;
+    exception_type_t exc_type;
+    std::vector<mach_exception_data_type_t> exc_data;
+    Data()
+        : task_port(TASK_NULL), thread_port(THREAD_NULL), exc_type(0),
+          exc_data() {}
+
+    void Clear() {
+      task_port = TASK_NULL;
+      thread_port = THREAD_NULL;
+      exc_type = 0;
+      exc_data.clear();
+    }
+
+    bool IsValid() const {
+      return task_port != TASK_NULL && thread_port != THREAD_NULL &&
+             exc_type != 0;
+    }
+
+    // Return the SoftSignal for this MachException data, or zero if there is
+    // none
+    int SoftSignal() const {
+      if (exc_type == EXC_SOFTWARE && exc_data.size() == 2 &&
+          exc_data[0] == EXC_SOFT_SIGNAL)
+        return static_cast<int>(exc_data[1]);
+      return 0;
+    }
+
+    bool IsBreakpoint() const {
+      return (exc_type == EXC_BREAKPOINT ||
+              ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1));
+    }
+
+    bool GetStopInfo(ThreadStopInfo *stop_info, const UnixSignals &signals,
+                     Stream &stream) const;
+  };
+
+  struct Message {
+    MachMessage exc_msg;
+    MachMessage reply_msg;
+    Data state;
+
+    Message() : state() {
+      memset(&exc_msg, 0, sizeof(exc_msg));
+      memset(&reply_msg, 0, sizeof(reply_msg));
+    }
+
+    bool CatchExceptionRaise(task_t task);
+
+    Error Reply(::pid_t inferior_pid, task_t inferior_task, int signal);
+
+    Error Receive(mach_port_t receive_port, mach_msg_option_t options,
+                  mach_msg_timeout_t timeout,
+                  mach_port_t notify_port = MACH_PORT_NULL);
+
+    void Dump(Stream &stream) const;
+
+    typedef std::vector<Message> collection;
+    typedef collection::iterator iterator;
+    typedef collection::const_iterator const_iterator;
+  };
+
+  enum {
+    e_actionForward, // Forward signal to inferior process
+    e_actionStop,    // Stop when this signal is received
+  };
+  struct Action {
+    task_t task_port;          // Set to TASK_NULL for any TASK
+    thread_t thread_port;      // Set to THREAD_NULL for any thread
+    exception_type_t exc_mask; // Mach exception mask to watch for
+    std::vector<mach_exception_data_type_t> exc_data_mask; // Mask to apply to
+                                                           // exception data, or
+                                                           // empty to ignore
+                                                           // exc_data value for
+                                                           // exception
+    std::vector<mach_exception_data_type_t> exc_data_value; // Value to compare
+                                                            // to exception data
+                                                            // after masking, or
+                                                            // empty to ignore
+                                                            // exc_data value
+                                                            // for exception
+    uint8_t flags; // Action flags describing what to do with the exception
+  };
 
-    struct PortInfo
-    {
-        exception_mask_t        mask; // the exception mask for this device which may be a subset of EXC_MASK_ALL...
-        exception_mask_t        masks[EXC_TYPES_COUNT];
-        mach_port_t             ports[EXC_TYPES_COUNT];
-        exception_behavior_t    behaviors[EXC_TYPES_COUNT];
-        thread_state_flavor_t   flavors[EXC_TYPES_COUNT];
-        mach_msg_type_number_t  count;
-
-        Error
-        Save(task_t task);
-
-        Error
-        Restore(task_t task);
-    };
-
-    struct Data
-    {
-        task_t task_port;
-        thread_t thread_port;
-        exception_type_t exc_type;
-        std::vector<mach_exception_data_type_t> exc_data;
-        Data() :
-            task_port(TASK_NULL),
-            thread_port(THREAD_NULL),
-            exc_type(0),
-            exc_data()
-            {
-            }
-
-        void
-        Clear()
-        {
-            task_port = TASK_NULL;
-            thread_port = THREAD_NULL;
-            exc_type = 0;
-            exc_data.clear();
-        }
-
-        bool
-        IsValid() const
-        {
-            return  task_port != TASK_NULL &&
-                    thread_port != THREAD_NULL &&
-                    exc_type != 0;
-        }
-        
-        // Return the SoftSignal for this MachException data, or zero if there is none
-        int
-        SoftSignal() const
-        {
-            if (exc_type == EXC_SOFTWARE && exc_data.size() == 2 && exc_data[0] == EXC_SOFT_SIGNAL)
-                return static_cast<int>(exc_data[1]);
-            return 0;
-        }
-
-        bool
-        IsBreakpoint() const
-        {
-            return (exc_type == EXC_BREAKPOINT || ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1));
-        }
-
-        bool
-        GetStopInfo(ThreadStopInfo *stop_info, const UnixSignals &signals,
-                         Stream &stream) const;
-    };
-
-    struct Message
-    {
-        MachMessage exc_msg;
-        MachMessage reply_msg;
-        Data state;
-
-        Message() :
-            state()
-        {
-            memset(&exc_msg,   0, sizeof(exc_msg));
-            memset(&reply_msg, 0, sizeof(reply_msg));
-        }
-
-        bool
-        CatchExceptionRaise(task_t task);
-
-        Error
-        Reply(::pid_t inferior_pid, task_t inferior_task, int signal);
-
-        Error
-        Receive(mach_port_t receive_port,
-                mach_msg_option_t options,
-                mach_msg_timeout_t timeout,
-                mach_port_t notify_port = MACH_PORT_NULL);
-
-        void
-        Dump(Stream &stream) const;
-
-        typedef std::vector<Message>        collection;
-        typedef collection::iterator        iterator;
-        typedef collection::const_iterator    const_iterator;
-    };
-
-    enum
-    {
-        e_actionForward,    // Forward signal to inferior process
-        e_actionStop,        // Stop when this signal is received
-    };
-    struct Action
-    {
-        task_t task_port;            // Set to TASK_NULL for any TASK
-        thread_t thread_port;        // Set to THREAD_NULL for any thread
-        exception_type_t exc_mask;    // Mach exception mask to watch for
-        std::vector<mach_exception_data_type_t> exc_data_mask;    // Mask to apply to exception data, or empty to ignore exc_data value for exception
-        std::vector<mach_exception_data_type_t> exc_data_value;    // Value to compare to exception data after masking, or empty to ignore exc_data value for exception
-        uint8_t flags;                // Action flags describing what to do with the exception
-    };
-
-    static const char*
-    Name(exception_type_t exc_type);
+  static const char *Name(exception_type_t exc_type);
 };
 
 } // namespace process_darwin

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp Tue Sep  6 15:57:50 2016
@@ -40,170 +40,142 @@ using namespace lldb_private::darwin_pro
 // Hidden Impl
 // -----------------------------------------------------------------------------
 
-namespace
-{
-    struct hack_task_dyld_info {
-        mach_vm_address_t   all_image_info_addr;
-        mach_vm_size_t      all_image_info_size;
-    };
+namespace {
+struct hack_task_dyld_info {
+  mach_vm_address_t all_image_info_addr;
+  mach_vm_size_t all_image_info_size;
+};
 }
 
 // -----------------------------------------------------------------------------
 // Public Static Methods
 // -----------------------------------------------------------------------------
 
-Error
-NativeProcessProtocol::Launch(ProcessLaunchInfo &launch_info,
-                              NativeProcessProtocol::NativeDelegate
-                              &native_delegate,
-                              MainLoop &mainloop,
-                              NativeProcessProtocolSP &native_process_sp)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    Error error;
+Error NativeProcessProtocol::Launch(
+    ProcessLaunchInfo &launch_info,
+    NativeProcessProtocol::NativeDelegate &native_delegate, MainLoop &mainloop,
+    NativeProcessProtocolSP &native_process_sp) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  Error error;
+
+  // Verify the working directory is valid if one was specified.
+  FileSpec working_dir(launch_info.GetWorkingDirectory());
+  if (working_dir &&
+      (!working_dir.ResolvePath() ||
+       working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) {
+    error.SetErrorStringWithFormat("No such file or directory: %s",
+                                   working_dir.GetCString());
+    return error;
+  }
+
+  // Launch the inferior.
+  int pty_master_fd = -1;
+  LaunchFlavor launch_flavor = LaunchFlavor::Default;
 
-    // Verify the working directory is valid if one was specified.
-    FileSpec working_dir(launch_info.GetWorkingDirectory());
-    if (working_dir &&
-        (!working_dir.ResolvePath() ||
-         working_dir.GetFileType() != FileSpec::eFileTypeDirectory))
-    {
-        error.SetErrorStringWithFormat("No such file or directory: %s",
-                                       working_dir.GetCString());
-        return error;
-    }
+  error = LaunchInferior(launch_info, &pty_master_fd, &launch_flavor);
 
-    // Launch the inferior.
-    int pty_master_fd = -1;
-    LaunchFlavor launch_flavor = LaunchFlavor::Default;
-
-    error = LaunchInferior(launch_info, &pty_master_fd, &launch_flavor);
-
-    // Handle launch failure.
-    if (!error.Success())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() failed to launch process: "
-                        "%s",
-                        __FUNCTION__, error.AsCString());
-        return error;
-    }
-
-    // Handle failure to return a pid.
-    if (launch_info.GetProcessID() == LLDB_INVALID_PROCESS_ID)
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() launch succeeded but no "
-                        "pid was returned!  Aborting.", __FUNCTION__);
-        return error;
-    }
-
-    // Create the Darwin native process impl.
-    std::shared_ptr<NativeProcessDarwin>
-        np_darwin_sp(new NativeProcessDarwin(launch_info.GetProcessID(),
-                                             pty_master_fd));
-    if (!np_darwin_sp->RegisterNativeDelegate(native_delegate))
-    {
-        native_process_sp.reset ();
-        error.SetErrorStringWithFormat ("failed to register the native delegate");
-        return error;
-    }
-
-    // Finalize the processing needed to debug the launched process with
-    // a NativeProcessDarwin instance.
-    error = np_darwin_sp->FinalizeLaunch(launch_flavor, mainloop);
-    if (!error.Success())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() aborting, failed to finalize"
-                        " the launching of the process: %s",
-                        __FUNCTION__, error.AsCString());
-        return error;
-    }
+  // Handle launch failure.
+  if (!error.Success()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() failed to launch process: "
+                  "%s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
 
-    // Return the process and process id to the caller through the launch args.
-    native_process_sp = np_darwin_sp;
+  // Handle failure to return a pid.
+  if (launch_info.GetProcessID() == LLDB_INVALID_PROCESS_ID) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() launch succeeded but no "
+                  "pid was returned!  Aborting.",
+                  __FUNCTION__);
+    return error;
+  }
+
+  // Create the Darwin native process impl.
+  std::shared_ptr<NativeProcessDarwin> np_darwin_sp(
+      new NativeProcessDarwin(launch_info.GetProcessID(), pty_master_fd));
+  if (!np_darwin_sp->RegisterNativeDelegate(native_delegate)) {
+    native_process_sp.reset();
+    error.SetErrorStringWithFormat("failed to register the native delegate");
+    return error;
+  }
+
+  // Finalize the processing needed to debug the launched process with
+  // a NativeProcessDarwin instance.
+  error = np_darwin_sp->FinalizeLaunch(launch_flavor, mainloop);
+  if (!error.Success()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() aborting, failed to finalize"
+                  " the launching of the process: %s",
+                  __FUNCTION__, error.AsCString());
     return error;
+  }
+
+  // Return the process and process id to the caller through the launch args.
+  native_process_sp = np_darwin_sp;
+  return error;
 }
 
-Error
-NativeProcessProtocol::Attach(lldb::pid_t pid,
-                              NativeProcessProtocol::NativeDelegate
-                              &native_delegate,
-                              MainLoop &mainloop,
-                              NativeProcessProtocolSP &native_process_sp)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-    if (log)
-        log->Printf ("NativeProcessDarwin::%s(pid = %" PRIi64 ")", __FUNCTION__,
-                     pid);
+Error NativeProcessProtocol::Attach(
+    lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
+    MainLoop &mainloop, NativeProcessProtocolSP &native_process_sp) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(pid = %" PRIi64 ")", __FUNCTION__,
+                pid);
 
-    // Retrieve the architecture for the running process.
-    ArchSpec process_arch;
-    Error error = ResolveProcessArchitecture(pid, process_arch);
-    if (!error.Success())
-        return error;
-
-    // TODO get attach to return this value.
-    const int pty_master_fd = -1;
-    std::shared_ptr<NativeProcessDarwin> native_process_darwin_sp(
-                                   new NativeProcessDarwin(pid, pty_master_fd));
+  // Retrieve the architecture for the running process.
+  ArchSpec process_arch;
+  Error error = ResolveProcessArchitecture(pid, process_arch);
+  if (!error.Success())
+    return error;
 
-    if (!native_process_darwin_sp->RegisterNativeDelegate(native_delegate))
-    {
-        error.SetErrorStringWithFormat("failed to register the native "
-                                       "delegate");
-        return error;
-    }
+  // TODO get attach to return this value.
+  const int pty_master_fd = -1;
+  std::shared_ptr<NativeProcessDarwin> native_process_darwin_sp(
+      new NativeProcessDarwin(pid, pty_master_fd));
 
-    native_process_darwin_sp->AttachToInferior(mainloop, pid, error);
-    if (!error.Success())
-        return error;
+  if (!native_process_darwin_sp->RegisterNativeDelegate(native_delegate)) {
+    error.SetErrorStringWithFormat("failed to register the native "
+                                   "delegate");
+    return error;
+  }
 
-    native_process_sp = native_process_darwin_sp;
+  native_process_darwin_sp->AttachToInferior(mainloop, pid, error);
+  if (!error.Success())
     return error;
+
+  native_process_sp = native_process_darwin_sp;
+  return error;
 }
 
 // -----------------------------------------------------------------------------
 // ctor/dtor
 // -----------------------------------------------------------------------------
 
-NativeProcessDarwin::NativeProcessDarwin(lldb::pid_t pid, int pty_master_fd) :
-    NativeProcessProtocol(pid),
-    m_task(TASK_NULL),
-    m_did_exec(false),
-    m_cpu_type(0),
-    m_exception_port(MACH_PORT_NULL),
-    m_exc_port_info(),
-    m_exception_thread(nullptr),
-    m_exception_messages_mutex(),
-    m_sent_interrupt_signo(0),
-    m_auto_resume_signo(0),
-    m_thread_list(),
-    m_thread_actions(),
-    m_waitpid_pipe(),
-    m_waitpid_thread(nullptr),
-    m_waitpid_reader_handle()
-{
-    // TODO add this to the NativeProcessProtocol constructor.
-    m_terminal_fd = pty_master_fd;
+NativeProcessDarwin::NativeProcessDarwin(lldb::pid_t pid, int pty_master_fd)
+    : NativeProcessProtocol(pid), m_task(TASK_NULL), m_did_exec(false),
+      m_cpu_type(0), m_exception_port(MACH_PORT_NULL), m_exc_port_info(),
+      m_exception_thread(nullptr), m_exception_messages_mutex(),
+      m_sent_interrupt_signo(0), m_auto_resume_signo(0), m_thread_list(),
+      m_thread_actions(), m_waitpid_pipe(), m_waitpid_thread(nullptr),
+      m_waitpid_reader_handle() {
+  // TODO add this to the NativeProcessProtocol constructor.
+  m_terminal_fd = pty_master_fd;
 }
 
-NativeProcessDarwin::~NativeProcessDarwin()
-{
-}
+NativeProcessDarwin::~NativeProcessDarwin() {}
 
 // -----------------------------------------------------------------------------
 // Instance methods
 // -----------------------------------------------------------------------------
 
-Error
-NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
-                                    MainLoop &main_loop)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+Error NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
+                                          MainLoop &main_loop) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
 #if 0
     m_path = path;
@@ -213,772 +185,680 @@ NativeProcessDarwin::FinalizeLaunch(Laun
         m_args.push_back(arg);
 #endif
 
-    error = StartExceptionThread();
-    if (!error.Success())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failure starting the "
-                        "mach exception port monitor thread: %s",
-                        __FUNCTION__, error.AsCString());
-
-        // Terminate the inferior process.  There's nothing meaningful we can
-        // do if we can't receive signals and exceptions.  Since we launched
-        // the process, it's fair game for us to kill it.
-        ::ptrace(PT_KILL, m_pid, 0, 0);
-        SetState(eStateExited);
-
-        return error;
-    }
-
-    StartSTDIOThread();
-
-    if (launch_flavor == LaunchFlavor::PosixSpawn)
-    {
-        SetState(eStateAttaching);
-        errno = 0;
-        int err = ::ptrace(PT_ATTACHEXC, m_pid, 0, 0);
-        if (err == 0)
-        {
-            // m_flags |= eMachProcessFlagsAttached;
-            if (log)
-                log->Printf("NativeProcessDarwin::%s(): successfully spawned "
-                            "process with pid %" PRIu64, __FUNCTION__, m_pid);
-        }
-        else
-        {
-            error.SetErrorToErrno();
-            SetState(eStateExited);
-            if (log)
-                log->Printf("NativeProcessDarwin::%s(): error: failed to "
-                            "attach to spawned pid %" PRIu64 " (error=%d (%s))",
-                            __FUNCTION__, m_pid, (int)error.GetError(),
-                            error.AsCString());
-            return error;
-        }
-    }
-
+  error = StartExceptionThread();
+  if (!error.Success()) {
     if (log)
-        log->Printf("NativeProcessDarwin::%s(): new pid is %" PRIu64 "...",
+      log->Printf("NativeProcessDarwin::%s(): failure starting the "
+                  "mach exception port monitor thread: %s",
+                  __FUNCTION__, error.AsCString());
+
+    // Terminate the inferior process.  There's nothing meaningful we can
+    // do if we can't receive signals and exceptions.  Since we launched
+    // the process, it's fair game for us to kill it.
+    ::ptrace(PT_KILL, m_pid, 0, 0);
+    SetState(eStateExited);
+
+    return error;
+  }
+
+  StartSTDIOThread();
+
+  if (launch_flavor == LaunchFlavor::PosixSpawn) {
+    SetState(eStateAttaching);
+    errno = 0;
+    int err = ::ptrace(PT_ATTACHEXC, m_pid, 0, 0);
+    if (err == 0) {
+      // m_flags |= eMachProcessFlagsAttached;
+      if (log)
+        log->Printf("NativeProcessDarwin::%s(): successfully spawned "
+                    "process with pid %" PRIu64,
                     __FUNCTION__, m_pid);
+    } else {
+      error.SetErrorToErrno();
+      SetState(eStateExited);
+      if (log)
+        log->Printf("NativeProcessDarwin::%s(): error: failed to "
+                    "attach to spawned pid %" PRIu64 " (error=%d (%s))",
+                    __FUNCTION__, m_pid, (int)error.GetError(),
+                    error.AsCString());
+      return error;
+    }
+  }
+
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(): new pid is %" PRIu64 "...",
+                __FUNCTION__, m_pid);
+
+  // Spawn a thread to reap our child inferior process...
+  error = StartWaitpidThread(main_loop);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): failed to start waitpid() "
+                  "thread: %s",
+                  __FUNCTION__, error.AsCString());
+    kill(SIGKILL, static_cast<::pid_t>(m_pid));
+    return error;
+  }
+
+  if (TaskPortForProcessID(error) == TASK_NULL) {
+    // We failed to get the task for our process ID which is bad.
+    // Kill our process; otherwise, it will be stopped at the entry
+    // point and get reparented to someone else and never go away.
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): could not get task port "
+                  "for process, sending SIGKILL and exiting: %s",
+                  __FUNCTION__, error.AsCString());
+    kill(SIGKILL, static_cast<::pid_t>(m_pid));
+    return error;
+  }
 
-    // Spawn a thread to reap our child inferior process...
-    error = StartWaitpidThread(main_loop);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failed to start waitpid() "
-                        "thread: %s", __FUNCTION__, error.AsCString());
-        kill(SIGKILL, static_cast<::pid_t>(m_pid));
-        return error;
-    }
-
-    if (TaskPortForProcessID(error) == TASK_NULL)
-    {
-        // We failed to get the task for our process ID which is bad.
-        // Kill our process; otherwise, it will be stopped at the entry
-        // point and get reparented to someone else and never go away.
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): could not get task port "
-                        "for process, sending SIGKILL and exiting: %s",
-                        __FUNCTION__, error.AsCString());
-        kill(SIGKILL, static_cast<::pid_t>(m_pid));
-        return error;
-    }
-
-    // Indicate that we're stopped, as we always launch suspended.
-    SetState(eStateStopped);
+  // Indicate that we're stopped, as we always launch suspended.
+  SetState(eStateStopped);
 
-    // Success.
-    return error;
+  // Success.
+  return error;
 }
 
-Error
-NativeProcessDarwin::SaveExceptionPortInfo()
-{
-    return m_exc_port_info.Save(m_task);
+Error NativeProcessDarwin::SaveExceptionPortInfo() {
+  return m_exc_port_info.Save(m_task);
 }
 
-bool
-NativeProcessDarwin::ProcessUsingSpringBoard() const
-{
-    // TODO implement flags
-    // return (m_flags & eMachProcessFlagsUsingSBS) != 0;
-    return false;
+bool NativeProcessDarwin::ProcessUsingSpringBoard() const {
+  // TODO implement flags
+  // return (m_flags & eMachProcessFlagsUsingSBS) != 0;
+  return false;
 }
 
-bool
-NativeProcessDarwin::ProcessUsingBackBoard() const
-{
-    // TODO implement flags
-    // return (m_flags & eMachProcessFlagsUsingBKS) != 0;
-    return false;
+bool NativeProcessDarwin::ProcessUsingBackBoard() const {
+  // TODO implement flags
+  // return (m_flags & eMachProcessFlagsUsingBKS) != 0;
+  return false;
 }
 
 // Called by the exception thread when an exception has been received from
 // our process. The exception message is completely filled and the exception
 // data has already been copied.
-void
-NativeProcessDarwin::ExceptionMessageReceived(const MachException::Message&
-                                              message)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-
-    std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
-    if (m_exception_messages.empty())
-    {
-        // Suspend the task the moment we receive our first exception message.
-        SuspendTask();
-    }
-
-    // Use a locker to automatically unlock our mutex in case of exceptions
-    // Add the exception to our internal exception stack
-    m_exception_messages.push_back(message);
-
+void NativeProcessDarwin::ExceptionMessageReceived(
+    const MachException::Message &message) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+
+  std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
+  if (m_exception_messages.empty()) {
+    // Suspend the task the moment we receive our first exception message.
+    SuspendTask();
+  }
+
+  // Use a locker to automatically unlock our mutex in case of exceptions
+  // Add the exception to our internal exception stack
+  m_exception_messages.push_back(message);
+
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(): new queued message count: %lu",
+                __FUNCTION__, m_exception_messages.size());
+}
+
+void *NativeProcessDarwin::ExceptionThread(void *arg) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+  if (!arg) {
     if (log)
-        log->Printf("NativeProcessDarwin::%s(): new queued message count: %lu",
-                    __FUNCTION__, m_exception_messages.size());
-}
-
-void*
-NativeProcessDarwin::ExceptionThread(void *arg)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-    if (!arg)
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): cannot run mach exception "
-                        "thread, mandatory process arg was null", __FUNCTION__);
-        return nullptr;
-    }
+      log->Printf("NativeProcessDarwin::%s(): cannot run mach exception "
+                  "thread, mandatory process arg was null",
+                  __FUNCTION__);
+    return nullptr;
+  }
 
-    return reinterpret_cast<NativeProcessDarwin*>(arg)->DoExceptionThread();
+  return reinterpret_cast<NativeProcessDarwin *>(arg)->DoExceptionThread();
 }
 
-void*
-NativeProcessDarwin::DoExceptionThread()
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
-
-    if (log)
-        log->Printf("NativeProcessDarwin::%s(arg=%p) starting thread...",
-                    __FUNCTION__, this);
-
-    pthread_setname_np("exception monitoring thread");
-
-    // Ensure we don't get CPU starved.
-    MaybeRaiseThreadPriority();
-
-    // We keep a count of the number of consecutive exceptions received so
-    // we know to grab all exceptions without a timeout. We do this to get a
-    // bunch of related exceptions on our exception port so we can process
-    // then together. When we have multiple threads, we can get an exception
-    // per thread and they will come in consecutively. The main loop in this
-    // thread can stop periodically if needed to service things related to this
-    // process.
-    //
-    // [did we lose some words here?]
-    //
-    // flag set in the options, so we will wait forever for an exception on
-    //0 our exception port. After we get one exception, we then will use the
-    // MACH_RCV_TIMEOUT option with a zero timeout to grab all other current
-    // exceptions for our process. After we have received the last pending
-    // exception, we will get a timeout which enables us to then notify
-    // our main thread that we have an exception bundle available. We then wait
-    // for the main thread to tell this exception thread to start trying to get
-    // exceptions messages again and we start again with a mach_msg read with
-    // infinite timeout.
-    //
-    // We choose to park a thread on this, rather than polling, because the
-    // polling is expensive.  On devices, we need to minimize overhead caused
-    // by the process monitor.
-    uint32_t num_exceptions_received = 0;
-    Error error;
-    task_t task = m_task;
-    mach_msg_timeout_t periodic_timeout = 0;
-
-#if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
-    mach_msg_timeout_t watchdog_elapsed = 0;
-    mach_msg_timeout_t watchdog_timeout = 60 * 1000;
-    ::pid_t pid = (::pid_t)process->GetID();
-    CFReleaser<SBSWatchdogAssertionRef> watchdog;
+void *NativeProcessDarwin::DoExceptionThread() {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
 
-    if (process->ProcessUsingSpringBoard())
-    {
-        // Request a renewal for every 60 seconds if we attached using
-        // SpringBoard.
-        watchdog.reset(::SBSWatchdogAssertionCreateForPID(nullptr, pid, 60));
-        if (log)
-            log->Printf("::SBSWatchdogAssertionCreateForPID(NULL, %4.4x, 60) "
-                        "=> %p", pid, watchdog.get());
-
-        if (watchdog.get())
-        {
-            ::SBSWatchdogAssertionRenew (watchdog.get());
-
-            CFTimeInterval watchdogRenewalInterval =
-                ::SBSWatchdogAssertionGetRenewalInterval (watchdog.get());
-            if (log)
-                log->Printf("::SBSWatchdogAssertionGetRenewalInterval(%p) => "
-                            "%g seconds", watchdog.get(),
-                            watchdogRenewalInterval);
-            if (watchdogRenewalInterval > 0.0)
-            {
-                watchdog_timeout =
-                    (mach_msg_timeout_t)watchdogRenewalInterval * 1000;
-                if (watchdog_timeout > 3000)
-                {
-                    // Give us a second to renew our timeout.
-                    watchdog_timeout -= 1000;
-                }
-                else if (watchdog_timeout > 1000)
-                {
-                    // Give us a quarter of a second to renew our timeout.
-                    watchdog_timeout -= 250;
-                }
-            }
-        }
-        if (periodic_timeout == 0 || periodic_timeout > watchdog_timeout)
-            periodic_timeout = watchdog_timeout;
-    }
-#endif  // #if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(arg=%p) starting thread...",
+                __FUNCTION__, this);
+
+  pthread_setname_np("exception monitoring thread");
+
+  // Ensure we don't get CPU starved.
+  MaybeRaiseThreadPriority();
+
+  // We keep a count of the number of consecutive exceptions received so
+  // we know to grab all exceptions without a timeout. We do this to get a
+  // bunch of related exceptions on our exception port so we can process
+  // then together. When we have multiple threads, we can get an exception
+  // per thread and they will come in consecutively. The main loop in this
+  // thread can stop periodically if needed to service things related to this
+  // process.
+  //
+  // [did we lose some words here?]
+  //
+  // flag set in the options, so we will wait forever for an exception on
+  // 0 our exception port. After we get one exception, we then will use the
+  // MACH_RCV_TIMEOUT option with a zero timeout to grab all other current
+  // exceptions for our process. After we have received the last pending
+  // exception, we will get a timeout which enables us to then notify
+  // our main thread that we have an exception bundle available. We then wait
+  // for the main thread to tell this exception thread to start trying to get
+  // exceptions messages again and we start again with a mach_msg read with
+  // infinite timeout.
+  //
+  // We choose to park a thread on this, rather than polling, because the
+  // polling is expensive.  On devices, we need to minimize overhead caused
+  // by the process monitor.
+  uint32_t num_exceptions_received = 0;
+  Error error;
+  task_t task = m_task;
+  mach_msg_timeout_t periodic_timeout = 0;
+
+#if defined(WITH_SPRINGBOARD) && !defined(WITH_BKS)
+  mach_msg_timeout_t watchdog_elapsed = 0;
+  mach_msg_timeout_t watchdog_timeout = 60 * 1000;
+  ::pid_t pid = (::pid_t)process->GetID();
+  CFReleaser<SBSWatchdogAssertionRef> watchdog;
+
+  if (process->ProcessUsingSpringBoard()) {
+    // Request a renewal for every 60 seconds if we attached using
+    // SpringBoard.
+    watchdog.reset(::SBSWatchdogAssertionCreateForPID(nullptr, pid, 60));
+    if (log)
+      log->Printf("::SBSWatchdogAssertionCreateForPID(NULL, %4.4x, 60) "
+                  "=> %p",
+                  pid, watchdog.get());
+
+    if (watchdog.get()) {
+      ::SBSWatchdogAssertionRenew(watchdog.get());
+
+      CFTimeInterval watchdogRenewalInterval =
+          ::SBSWatchdogAssertionGetRenewalInterval(watchdog.get());
+      if (log)
+        log->Printf("::SBSWatchdogAssertionGetRenewalInterval(%p) => "
+                    "%g seconds",
+                    watchdog.get(), watchdogRenewalInterval);
+      if (watchdogRenewalInterval > 0.0) {
+        watchdog_timeout = (mach_msg_timeout_t)watchdogRenewalInterval * 1000;
+        if (watchdog_timeout > 3000) {
+          // Give us a second to renew our timeout.
+          watchdog_timeout -= 1000;
+        } else if (watchdog_timeout > 1000) {
+          // Give us a quarter of a second to renew our timeout.
+          watchdog_timeout -= 250;
+        }
+      }
+    }
+    if (periodic_timeout == 0 || periodic_timeout > watchdog_timeout)
+      periodic_timeout = watchdog_timeout;
+  }
+#endif // #if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
 
 #ifdef WITH_BKS
-    CFReleaser<BKSWatchdogAssertionRef> watchdog;
-    if (process->ProcessUsingBackBoard())
-    {
-        ::pid_t pid = process->GetID();
-        CFAllocatorRef alloc = kCFAllocatorDefault;
-        watchdog.reset(::BKSWatchdogAssertionCreateForPID(alloc, pid));
-    }
+  CFReleaser<BKSWatchdogAssertionRef> watchdog;
+  if (process->ProcessUsingBackBoard()) {
+    ::pid_t pid = process->GetID();
+    CFAllocatorRef alloc = kCFAllocatorDefault;
+    watchdog.reset(::BKSWatchdogAssertionCreateForPID(alloc, pid));
+  }
 #endif // #ifdef WITH_BKS
 
-    // Do we want to use a weak pointer to the NativeProcessDarwin here, in
-    // which case we can guarantee we don't whack the process monitor if we
-    // race between this thread and the main one on shutdown?
-    while (IsExceptionPortValid())
-    {
-        ::pthread_testcancel();
-
-        MachException::Message exception_message;
-
-        if (num_exceptions_received > 0)
-        {
-            // We don't want a timeout here, just receive as many exceptions as
-            // we can since we already have one.  We want to get all currently
-            // available exceptions for this task at once.
-            error = exception_message.Receive(GetExceptionPort(),
-                                              MACH_RCV_MSG | MACH_RCV_INTERRUPT
-                                              | MACH_RCV_TIMEOUT, 0);
-        }
-        else if (periodic_timeout > 0)
-        {
-            // We need to stop periodically in this loop, so try and get a mach
-            // message with a valid timeout (ms).
-            error = exception_message.Receive(GetExceptionPort(),
-                                              MACH_RCV_MSG | MACH_RCV_INTERRUPT
-                                              | MACH_RCV_TIMEOUT,
-                                              periodic_timeout);
+  // Do we want to use a weak pointer to the NativeProcessDarwin here, in
+  // which case we can guarantee we don't whack the process monitor if we
+  // race between this thread and the main one on shutdown?
+  while (IsExceptionPortValid()) {
+    ::pthread_testcancel();
+
+    MachException::Message exception_message;
+
+    if (num_exceptions_received > 0) {
+      // We don't want a timeout here, just receive as many exceptions as
+      // we can since we already have one.  We want to get all currently
+      // available exceptions for this task at once.
+      error = exception_message.Receive(
+          GetExceptionPort(),
+          MACH_RCV_MSG | MACH_RCV_INTERRUPT | MACH_RCV_TIMEOUT, 0);
+    } else if (periodic_timeout > 0) {
+      // We need to stop periodically in this loop, so try and get a mach
+      // message with a valid timeout (ms).
+      error = exception_message.Receive(GetExceptionPort(),
+                                        MACH_RCV_MSG | MACH_RCV_INTERRUPT |
+                                            MACH_RCV_TIMEOUT,
+                                        periodic_timeout);
+    } else {
+      // We don't need to parse all current exceptions or stop
+      // periodically, just wait for an exception forever.
+      error = exception_message.Receive(GetExceptionPort(),
+                                        MACH_RCV_MSG | MACH_RCV_INTERRUPT, 0);
+    }
+
+    if (error.Success()) {
+      // We successfully received an exception.
+      if (exception_message.CatchExceptionRaise(task)) {
+        ++num_exceptions_received;
+        ExceptionMessageReceived(exception_message);
+      }
+    } else {
+      if (error.GetError() == MACH_RCV_INTERRUPTED) {
+        // We were interrupted.
+
+        // If we have no task port we should exit this thread, as it implies
+        // the inferior went down.
+        if (!IsExceptionPortValid()) {
+          if (log)
+            log->Printf("NativeProcessDarwin::%s(): the inferior "
+                        "exception port is no longer valid, "
+                        "canceling exception thread...",
+                        __FUNCTION__);
+          // Should we be setting a process state here?
+          break;
         }
-        else
-        {
-            // We don't need to parse all current exceptions or stop
-            // periodically, just wait for an exception forever.
-            error = exception_message.Receive(GetExceptionPort(),
-                                              MACH_RCV_MSG | MACH_RCV_INTERRUPT,
-                                              0);
+
+        // Make sure the inferior task is still valid.
+        if (IsTaskValid()) {
+          // Task is still ok.
+          if (log)
+            log->Printf("NativeProcessDarwin::%s(): interrupted, but "
+                        "the inferior task iss till valid, "
+                        "continuing...",
+                        __FUNCTION__);
+          continue;
+        } else {
+          // The inferior task is no longer valid.  Time to exit as
+          // the process has gone away.
+          if (log)
+            log->Printf("NativeProcessDarwin::%s(): the inferior task "
+                        "has exited, and so will we...",
+                        __FUNCTION__);
+          // Does this race at all with our waitpid()?
+          SetState(eStateExited);
+          break;
+        }
+      } else if (error.GetError() == MACH_RCV_TIMED_OUT) {
+        // We timed out when waiting for exceptions.
+
+        if (num_exceptions_received > 0) {
+          // We were receiving all current exceptions with a timeout of
+          // zero.  It is time to go back to our normal looping mode.
+          num_exceptions_received = 0;
+
+          // Notify our main thread we have a complete exception message
+          // bundle available.  Get the possibly updated task port back
+          // from the process in case we exec'ed and our task port
+          // changed.
+          task = ExceptionMessageBundleComplete();
+
+          // In case we use a timeout value when getting exceptions,
+          // make sure our task is still valid.
+          if (IsTaskValid(task)) {
+            // Task is still ok.
+            if (log)
+              log->Printf("NativeProcessDarwin::%s(): got a timeout, "
+                          "continuing...",
+                          __FUNCTION__);
+            continue;
+          } else {
+            // The inferior task is no longer valid.  Time to exit as
+            // the process has gone away.
+            if (log)
+              log->Printf("NativeProcessDarwin::%s(): the inferior "
+                          "task has exited, and so will we...",
+                          __FUNCTION__);
+            // Does this race at all with our waitpid()?
+            SetState(eStateExited);
+            break;
+          }
         }
 
-        if (error.Success())
-        {
-            // We successfully received an exception.
-            if (exception_message.CatchExceptionRaise(task))
-            {
-                ++num_exceptions_received;
-                ExceptionMessageReceived(exception_message);
-            }
+#if defined(WITH_SPRINGBOARD) && !defined(WITH_BKS)
+        if (watchdog.get()) {
+          watchdog_elapsed += periodic_timeout;
+          if (watchdog_elapsed >= watchdog_timeout) {
+            if (log)
+              log->Printf("SBSWatchdogAssertionRenew(%p)", watchdog.get());
+            ::SBSWatchdogAssertionRenew(watchdog.get());
+            watchdog_elapsed = 0;
+          }
         }
-        else
-        {
-            if (error.GetError() == MACH_RCV_INTERRUPTED)
-            {
-                // We were interrupted.
-
-                // If we have no task port we should exit this thread, as it implies
-                // the inferior went down.
-                if (!IsExceptionPortValid())
-                {
-                    if (log)
-                        log->Printf("NativeProcessDarwin::%s(): the inferior "
-                                    "exception port is no longer valid, "
-                                    "canceling exception thread...", __FUNCTION__);
-                    // Should we be setting a process state here?
-                    break;
-                }
-
-                // Make sure the inferior task is still valid.
-                if (IsTaskValid())
-                {
-                    // Task is still ok.
-                    if (log)
-                        log->Printf("NativeProcessDarwin::%s(): interrupted, but "
-                                    "the inferior task iss till valid, "
-                                    "continuing...", __FUNCTION__);
-                    continue;
-                }
-                else
-                {
-                    // The inferior task is no longer valid.  Time to exit as
-                    // the process has gone away.
-                    if (log)
-                        log->Printf("NativeProcessDarwin::%s(): the inferior task "
-                                    "has exited, and so will we...", __FUNCTION__);
-                    // Does this race at all with our waitpid()?
-                    SetState(eStateExited);
-                    break;
-                }
-            }
-            else if (error.GetError() == MACH_RCV_TIMED_OUT)
-            {
-                // We timed out when waiting for exceptions.
-
-                if (num_exceptions_received > 0)
-                {
-                    // We were receiving all current exceptions with a timeout of
-                    // zero.  It is time to go back to our normal looping mode.
-                    num_exceptions_received = 0;
-
-                    // Notify our main thread we have a complete exception message
-                    // bundle available.  Get the possibly updated task port back
-                    // from the process in case we exec'ed and our task port
-                    // changed.
-                    task = ExceptionMessageBundleComplete();
-
-                    // In case we use a timeout value when getting exceptions,
-                    // make sure our task is still valid.
-                    if (IsTaskValid(task))
-                    {
-                        // Task is still ok.
-                        if (log)
-                            log->Printf("NativeProcessDarwin::%s(): got a timeout, "
-                                        "continuing...", __FUNCTION__);
-                        continue;
-                    }
-                    else
-                    {
-                        // The inferior task is no longer valid.  Time to exit as
-                        // the process has gone away.
-                        if (log)
-                            log->Printf("NativeProcessDarwin::%s(): the inferior "
-                                        "task has exited, and so will we...",
-                                        __FUNCTION__);
-                        // Does this race at all with our waitpid()?
-                        SetState(eStateExited);
-                        break;
-                    }
-                }
-
-#if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
-                if (watchdog.get())
-                {
-                    watchdog_elapsed += periodic_timeout;
-                    if (watchdog_elapsed >= watchdog_timeout)
-                    {
-                        if (log)
-                            log->Printf("SBSWatchdogAssertionRenew(%p)",
-                                        watchdog.get());
-                        ::SBSWatchdogAssertionRenew (watchdog.get());
-                        watchdog_elapsed = 0;
-                    }
-                }
 #endif
-            }
-            else
-            {
-                if (log)
-                    log->Printf("NativeProcessDarwin::%s(): continuing after "
-                                "receiving an unexpected error: %u (%s)",
-                                __FUNCTION__, error.GetError(), error.AsCString());
-                // TODO: notify of error?
-            }
-        }
-    }
-
-#if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
-    if (watchdog.get())
-    {
-        // TODO: change SBSWatchdogAssertionRelease to SBSWatchdogAssertionCancel when we
-        // all are up and running on systems that support it. The SBS framework has a #define
-        // that will forward SBSWatchdogAssertionRelease to SBSWatchdogAssertionCancel for now
-        // so it should still build either way.
-        DNBLogThreadedIf(LOG_TASK, "::SBSWatchdogAssertionRelease(%p)", watchdog.get());
-        ::SBSWatchdogAssertionRelease (watchdog.get());
-    }
-#endif  // #if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
-    
+      } else {
+        if (log)
+          log->Printf("NativeProcessDarwin::%s(): continuing after "
+                      "receiving an unexpected error: %u (%s)",
+                      __FUNCTION__, error.GetError(), error.AsCString());
+        // TODO: notify of error?
+      }
+    }
+  }
+
+#if defined(WITH_SPRINGBOARD) && !defined(WITH_BKS)
+  if (watchdog.get()) {
+    // TODO: change SBSWatchdogAssertionRelease to SBSWatchdogAssertionCancel
+    // when we
+    // all are up and running on systems that support it. The SBS framework has
+    // a #define
+    // that will forward SBSWatchdogAssertionRelease to
+    // SBSWatchdogAssertionCancel for now
+    // so it should still build either way.
+    DNBLogThreadedIf(LOG_TASK, "::SBSWatchdogAssertionRelease(%p)",
+                     watchdog.get());
+    ::SBSWatchdogAssertionRelease(watchdog.get());
+  }
+#endif // #if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS)
+
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(%p): thread exiting...", __FUNCTION__,
+                this);
+  return nullptr;
+}
+
+Error NativeProcessDarwin::StartExceptionThread() {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__);
+
+  // Make sure we've looked up the inferior port.
+  TaskPortForProcessID(error);
+
+  // Ensure the inferior task is valid.
+  if (!IsTaskValid()) {
+    error.SetErrorStringWithFormat("cannot start exception thread: "
+                                   "task 0x%4.4x is not valid",
+                                   m_task);
+    return error;
+  }
+
+  // Get the mach port for the process monitor.
+  mach_port_t task_self = mach_task_self();
+
+  // Allocate an exception port that we will use to track our child process
+  auto mach_err = ::mach_port_allocate(task_self, MACH_PORT_RIGHT_RECEIVE,
+                                       &m_exception_port);
+  error.SetError(mach_err, eErrorTypeMachKernel);
+  if (error.Fail()) {
     if (log)
-        log->Printf("NativeProcessDarwin::%s(%p): thread exiting...",
-                    __FUNCTION__, this);
-    return nullptr;
-}
-
-Error
-NativeProcessDarwin::StartExceptionThread()
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+      log->Printf("NativeProcessDarwin::%s(): mach_port_allocate("
+                  "task_self=0x%4.4x, MACH_PORT_RIGHT_RECEIVE, "
+                  "&m_exception_port) failed: %u (%s)",
+                  __FUNCTION__, task_self, error.GetError(), error.AsCString());
+    return error;
+  }
+
+  // Add the ability to send messages on the new exception port
+  mach_err = ::mach_port_insert_right(
+      task_self, m_exception_port, m_exception_port, MACH_MSG_TYPE_MAKE_SEND);
+  error.SetError(mach_err, eErrorTypeMachKernel);
+  if (error.Fail()) {
     if (log)
-        log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__);
-
-    // Make sure we've looked up the inferior port.
-    TaskPortForProcessID(error);
-
-    // Ensure the inferior task is valid.
-    if (!IsTaskValid())
-    {
-        error.SetErrorStringWithFormat("cannot start exception thread: "
-                                       "task 0x%4.4x is not valid", m_task);
-        return error;
-    }
-
-    // Get the mach port for the process monitor.
-    mach_port_t task_self = mach_task_self();
-
-    // Allocate an exception port that we will use to track our child process
-    auto mach_err = ::mach_port_allocate(task_self, MACH_PORT_RIGHT_RECEIVE,
-                                         &m_exception_port);
-    error.SetError(mach_err, eErrorTypeMachKernel);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): mach_port_allocate("
-                        "task_self=0x%4.4x, MACH_PORT_RIGHT_RECEIVE, "
-                        "&m_exception_port) failed: %u (%s)", __FUNCTION__,
-                        task_self, error.GetError(), error.AsCString());
-        return error;
-    }
-
-    // Add the ability to send messages on the new exception port
-    mach_err = ::mach_port_insert_right(task_self, m_exception_port,
-                                   m_exception_port, MACH_MSG_TYPE_MAKE_SEND);
-    error.SetError(mach_err, eErrorTypeMachKernel);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): mach_port_insert_right("
-                        "task_self=0x%4.4x, m_exception_port=0x%4.4x, "
-                        "m_exception_port=0x%4.4x, MACH_MSG_TYPE_MAKE_SEND) "
-                        "failed: %u (%s)", __FUNCTION__,
-                        task_self, m_exception_port, m_exception_port,
-                        error.GetError(), error.AsCString());
-        return error;
-    }
-
-    // Save the original state of the exception ports for our child process.
-    error = SaveExceptionPortInfo();
-    if (error.Fail() || (m_exc_port_info.mask == 0))
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): SaveExceptionPortInfo() "
-                        "failed, cannot install exception handler: %s",
-                        __FUNCTION__, error.AsCString());
-        return error;
-    }
-
-    // Set the ability to get all exceptions on this port.
-    mach_err = ::task_set_exception_ports(m_task, m_exc_port_info.mask,
-                                          m_exception_port,
-                                          EXCEPTION_DEFAULT |
-                                          MACH_EXCEPTION_CODES,
-                                          THREAD_STATE_NONE);
-    error.SetError(mach_err, eErrorTypeMachKernel);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("::task_set_exception_ports (task = 0x%4.4x, "
-                        "exception_mask = 0x%8.8x, new_port = 0x%4.4x, "
-                        "behavior = 0x%8.8x, new_flavor = 0x%8.8x) failed: "
-                        "%u (%s)", m_task, m_exc_port_info.mask,
-                        m_exception_port, (EXCEPTION_DEFAULT |
-                                           MACH_EXCEPTION_CODES),
-                        THREAD_STATE_NONE, error.GetError(),
-                        error.AsCString());
-        return error;
-    }
-
-    // Create the exception thread.
-    auto pthread_err = ::pthread_create(&m_exception_thread, nullptr,
-                                        ExceptionThread, this);
-    error.SetError(pthread_err, eErrorTypePOSIX);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failed to create Mach "
-                        "exception-handling thread: %u (%s)", __FUNCTION__,
-                        error.GetError(), error.AsCString());
-    }
+      log->Printf("NativeProcessDarwin::%s(): mach_port_insert_right("
+                  "task_self=0x%4.4x, m_exception_port=0x%4.4x, "
+                  "m_exception_port=0x%4.4x, MACH_MSG_TYPE_MAKE_SEND) "
+                  "failed: %u (%s)",
+                  __FUNCTION__, task_self, m_exception_port, m_exception_port,
+                  error.GetError(), error.AsCString());
+    return error;
+  }
+
+  // Save the original state of the exception ports for our child process.
+  error = SaveExceptionPortInfo();
+  if (error.Fail() || (m_exc_port_info.mask == 0)) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): SaveExceptionPortInfo() "
+                  "failed, cannot install exception handler: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
+
+  // Set the ability to get all exceptions on this port.
+  mach_err = ::task_set_exception_ports(
+      m_task, m_exc_port_info.mask, m_exception_port,
+      EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE);
+  error.SetError(mach_err, eErrorTypeMachKernel);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("::task_set_exception_ports (task = 0x%4.4x, "
+                  "exception_mask = 0x%8.8x, new_port = 0x%4.4x, "
+                  "behavior = 0x%8.8x, new_flavor = 0x%8.8x) failed: "
+                  "%u (%s)",
+                  m_task, m_exc_port_info.mask, m_exception_port,
+                  (EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES), THREAD_STATE_NONE,
+                  error.GetError(), error.AsCString());
+    return error;
+  }
+
+  // Create the exception thread.
+  auto pthread_err =
+      ::pthread_create(&m_exception_thread, nullptr, ExceptionThread, this);
+  error.SetError(pthread_err, eErrorTypePOSIX);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): failed to create Mach "
+                  "exception-handling thread: %u (%s)",
+                  __FUNCTION__, error.GetError(), error.AsCString());
+  }
 
-    return error;
+  return error;
 }
 
 lldb::addr_t
-NativeProcessDarwin::GetDYLDAllImageInfosAddress(Error &error) const
-{
-    error.Clear();
-
-    struct hack_task_dyld_info dyld_info;
-    mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
-    // Make sure that COUNT isn't bigger than our hacked up struct
-    // hack_task_dyld_info.  If it is, then make COUNT smaller to match.
-    if (count > (sizeof(struct hack_task_dyld_info) / sizeof(natural_t)))
-    {
-        count = (sizeof(struct hack_task_dyld_info) / sizeof(natural_t));
-    }
+NativeProcessDarwin::GetDYLDAllImageInfosAddress(Error &error) const {
+  error.Clear();
 
-    TaskPortForProcessID(error);
-    if (error.Fail())
-        return LLDB_INVALID_ADDRESS;
+  struct hack_task_dyld_info dyld_info;
+  mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
+  // Make sure that COUNT isn't bigger than our hacked up struct
+  // hack_task_dyld_info.  If it is, then make COUNT smaller to match.
+  if (count > (sizeof(struct hack_task_dyld_info) / sizeof(natural_t))) {
+    count = (sizeof(struct hack_task_dyld_info) / sizeof(natural_t));
+  }
 
-    auto mach_err = ::task_info(m_task, TASK_DYLD_INFO, (task_info_t)&dyld_info,
-                                &count);
-    error.SetError(mach_err, eErrorTypeMachKernel);
-    if (error.Success())
-    {
-        // We now have the address of the all image infos structure.
-        return dyld_info.all_image_info_addr;
-    }
-
-    // We don't have it.
+  TaskPortForProcessID(error);
+  if (error.Fail())
     return LLDB_INVALID_ADDRESS;
-}
 
-uint32_t
-NativeProcessDarwin::GetCPUTypeForLocalProcess(::pid_t pid)
-{
-    int mib[CTL_MAXNAME] = {0, };
-    size_t len = CTL_MAXNAME;
-
-    if (::sysctlnametomib("sysctl.proc_cputype", mib, &len))
-        return 0;
-
-    mib[len] = pid;
-    len++;
-
-    cpu_type_t cpu;
-    size_t cpu_len = sizeof(cpu);
-    if (::sysctl (mib, static_cast<u_int>(len), &cpu, &cpu_len, 0, 0))
-        cpu = 0;
-    return cpu;
-}
-
-uint32_t
-NativeProcessDarwin::GetCPUType() const
-{
-    if (m_cpu_type == 0 && m_pid != 0)
-        m_cpu_type = GetCPUTypeForLocalProcess(m_pid);
-    return m_cpu_type;
-}
-
-task_t
-NativeProcessDarwin::ExceptionMessageBundleComplete()
-{
-    // We have a complete bundle of exceptions for our child process.
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
+  auto mach_err =
+      ::task_info(m_task, TASK_DYLD_INFO, (task_info_t)&dyld_info, &count);
+  error.SetError(mach_err, eErrorTypeMachKernel);
+  if (error.Success()) {
+    // We now have the address of the all image infos structure.
+    return dyld_info.all_image_info_addr;
+  }
+
+  // We don't have it.
+  return LLDB_INVALID_ADDRESS;
+}
+
+uint32_t NativeProcessDarwin::GetCPUTypeForLocalProcess(::pid_t pid) {
+  int mib[CTL_MAXNAME] = {
+      0,
+  };
+  size_t len = CTL_MAXNAME;
 
-    std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
-    if (log)
-        log->Printf("NativeProcessDarwin::%s(): processing %lu exception "
-                    "messages.", __FUNCTION__, m_exception_messages.size());
+  if (::sysctlnametomib("sysctl.proc_cputype", mib, &len))
+    return 0;
 
-    if (m_exception_messages.empty())
-    {
-        // Not particularly useful...
-        return m_task;
-    }
+  mib[len] = pid;
+  len++;
 
-    bool auto_resume = false;
-    m_did_exec = false;
+  cpu_type_t cpu;
+  size_t cpu_len = sizeof(cpu);
+  if (::sysctl(mib, static_cast<u_int>(len), &cpu, &cpu_len, 0, 0))
+    cpu = 0;
+  return cpu;
+}
+
+uint32_t NativeProcessDarwin::GetCPUType() const {
+  if (m_cpu_type == 0 && m_pid != 0)
+    m_cpu_type = GetCPUTypeForLocalProcess(m_pid);
+  return m_cpu_type;
+}
+
+task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
+  // We have a complete bundle of exceptions for our child process.
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+
+  std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(): processing %lu exception "
+                "messages.",
+                __FUNCTION__, m_exception_messages.size());
 
-    // First check for any SIGTRAP and make sure we didn't exec
-    const task_t task = m_task;
-    size_t i;
-    if (m_pid != 0)
-    {
-        bool received_interrupt = false;
-        uint32_t num_task_exceptions = 0;
-        for (i = 0; i < m_exception_messages.size(); ++i)
-        {
-            if (m_exception_messages[i].state.task_port != task)
-            {
-                // This is an exception that is not for our inferior, ignore.
-                continue;
-            }
-
-            // This is an exception for the inferior.
-            ++num_task_exceptions;
-            const int signo = m_exception_messages[i].state.SoftSignal();
-            if (signo == SIGTRAP)
-            {
-                // SIGTRAP could mean that we exec'ed. We need to check the
-                // dyld all_image_infos.infoArray to see if it is NULL and if
-                // so, say that we exec'ed.
-                const addr_t aii_addr =
-                    GetDYLDAllImageInfosAddress(error);
-                if (aii_addr == LLDB_INVALID_ADDRESS)
-                    break;
-
-                const addr_t info_array_count_addr = aii_addr + 4;
-                uint32_t info_array_count = 0;
-                size_t bytes_read = 0;
-                Error read_error;
-                read_error = ReadMemory(info_array_count_addr,   // source addr
-                                        &info_array_count,       // dest addr
-                                        4,                       // byte count
-                                        bytes_read);             // #bytes read
-                if (read_error.Success() && (bytes_read == 4))
-                {
-                    if (info_array_count == 0)
-                    {
-                        // We got the all infos address, and there are zero
-                        // entries.  We think we exec'd.
-                        m_did_exec = true;
-
-                        // Force the task port to update itself in case the
-                        // task port changed after exec
-                        const task_t old_task = m_task;
-                        const bool force_update = true;
-                        const task_t new_task =
-                            TaskPortForProcessID(error, force_update);
-                        if (old_task != new_task)
-                        {
-                            if (log)
-                                log->Printf("exec: inferior task port changed "
-                                            "from 0x%4.4x to 0x%4.4x", old_task,
-                                            new_task);
-                        }
-                    }
-                }
-                else
-                {
-                    if (log)
-                        log->Printf("NativeProcessDarwin::%s() warning: "
-                                    "failed to read all_image_infos."
-                                    "infoArrayCount from 0x%8.8llx",
-                                    __FUNCTION__, info_array_count_addr);
-                }
-            }
-            else if ((m_sent_interrupt_signo != 0) &&
-                     (signo == m_sent_interrupt_signo))
-            {
-                // We just received the interrupt that we sent to ourselves.
-                received_interrupt = true;
-            }
-        }
-
-        if (m_did_exec)
-        {
-            cpu_type_t process_cpu_type = GetCPUTypeForLocalProcess(m_pid);
-            if (m_cpu_type != process_cpu_type)
-            {
-                if (log)
-                    log->Printf("NativeProcessDarwin::%s(): arch changed from "
-                                "0x%8.8x to 0x%8.8x", __FUNCTION__, m_cpu_type,
-                                process_cpu_type);
-                m_cpu_type = process_cpu_type;
-                // TODO figure out if we need to do something here.
-                // DNBArchProtocol::SetArchitecture (process_cpu_type);
-            }
-            m_thread_list.Clear();
+  if (m_exception_messages.empty()) {
+    // Not particularly useful...
+    return m_task;
+  }
 
-            // TODO hook up breakpoints.
-            // m_breakpoints.DisableAll();
-        }
+  bool auto_resume = false;
+  m_did_exec = false;
 
-        if (m_sent_interrupt_signo != 0)
-        {
-            if (received_interrupt)
-            {
-                if (log)
-                    log->Printf("NativeProcessDarwin::%s(): process "
-                                "successfully interrupted with signal %i",
-                                __FUNCTION__, m_sent_interrupt_signo);
-
-                // Mark that we received the interrupt signal
-                m_sent_interrupt_signo = 0;
-                // Now check if we had a case where:
-                // 1 - We called NativeProcessDarwin::Interrupt() but we stopped
-                //     for another reason.
-                // 2 - We called NativeProcessDarwin::Resume() (but still
-                //     haven't gotten the interrupt signal).
-                // 3 - We are now incorrectly stopped because we are handling
-                //     the interrupt signal we missed.
-                // 4 - We might need to resume if we stopped only with the
-                //     interrupt signal that we never handled.
-                if (m_auto_resume_signo != 0)
-                {
-                    // Only auto_resume if we stopped with _only_ the interrupt
-                    // signal.
-                    if (num_task_exceptions == 1)
-                    {
-                        auto_resume = true;
-                        if (log)
-                            log->Printf("NativeProcessDarwin::%s(): auto "
-                                        "resuming due to unhandled interrupt "
-                                        "signal %i", __FUNCTION__,
-                                        m_auto_resume_signo);
-                    }
-                    m_auto_resume_signo = 0;
-                }
+  // First check for any SIGTRAP and make sure we didn't exec
+  const task_t task = m_task;
+  size_t i;
+  if (m_pid != 0) {
+    bool received_interrupt = false;
+    uint32_t num_task_exceptions = 0;
+    for (i = 0; i < m_exception_messages.size(); ++i) {
+      if (m_exception_messages[i].state.task_port != task) {
+        // This is an exception that is not for our inferior, ignore.
+        continue;
+      }
+
+      // This is an exception for the inferior.
+      ++num_task_exceptions;
+      const int signo = m_exception_messages[i].state.SoftSignal();
+      if (signo == SIGTRAP) {
+        // SIGTRAP could mean that we exec'ed. We need to check the
+        // dyld all_image_infos.infoArray to see if it is NULL and if
+        // so, say that we exec'ed.
+        const addr_t aii_addr = GetDYLDAllImageInfosAddress(error);
+        if (aii_addr == LLDB_INVALID_ADDRESS)
+          break;
+
+        const addr_t info_array_count_addr = aii_addr + 4;
+        uint32_t info_array_count = 0;
+        size_t bytes_read = 0;
+        Error read_error;
+        read_error = ReadMemory(info_array_count_addr, // source addr
+                                &info_array_count,     // dest addr
+                                4,                     // byte count
+                                bytes_read);           // #bytes read
+        if (read_error.Success() && (bytes_read == 4)) {
+          if (info_array_count == 0) {
+            // We got the all infos address, and there are zero
+            // entries.  We think we exec'd.
+            m_did_exec = true;
+
+            // Force the task port to update itself in case the
+            // task port changed after exec
+            const task_t old_task = m_task;
+            const bool force_update = true;
+            const task_t new_task = TaskPortForProcessID(error, force_update);
+            if (old_task != new_task) {
+              if (log)
+                log->Printf("exec: inferior task port changed "
+                            "from 0x%4.4x to 0x%4.4x",
+                            old_task, new_task);
             }
-            else
-            {
-                if (log)
-                    log->Printf("NativeProcessDarwin::%s(): didn't get signal "
-                                "%i after MachProcess::Interrupt()",
-                                __FUNCTION__, m_sent_interrupt_signo);
-            }
-        }
-    }
-
-    // Let all threads recover from stopping and do any clean up based
-    // on the previous thread state (if any).
-    m_thread_list.ProcessDidStop(*this);
-
-    // Let each thread know of any exceptions
-    for (i = 0; i < m_exception_messages.size(); ++i)
-    {
-        // Let the thread list forward all exceptions on down to each thread.
-        if (m_exception_messages[i].state.task_port == task)
-        {
-            // This exception is for our inferior.
-            m_thread_list.NotifyException(m_exception_messages[i].state);
-        }
-
-        if (log)
-        {
-            StreamString stream;
-            m_exception_messages[i].Dump(stream);
-            stream.Flush();
-            log->PutCString(stream.GetString().c_str());
-        }
-    }
-
-    if (log)
-    {
-        StreamString stream;
-        m_thread_list.Dump(stream);
-        stream.Flush();
-        log->PutCString(stream.GetString().c_str());
-    }
-
-    bool step_more = false;
-    if (m_thread_list.ShouldStop(step_more) && (auto_resume == false))
-    {
-        // TODO - need to hook up event system here. !!!!
+          }
+        } else {
+          if (log)
+            log->Printf("NativeProcessDarwin::%s() warning: "
+                        "failed to read all_image_infos."
+                        "infoArrayCount from 0x%8.8llx",
+                        __FUNCTION__, info_array_count_addr);
+        }
+      } else if ((m_sent_interrupt_signo != 0) &&
+                 (signo == m_sent_interrupt_signo)) {
+        // We just received the interrupt that we sent to ourselves.
+        received_interrupt = true;
+      }
+    }
+
+    if (m_did_exec) {
+      cpu_type_t process_cpu_type = GetCPUTypeForLocalProcess(m_pid);
+      if (m_cpu_type != process_cpu_type) {
+        if (log)
+          log->Printf("NativeProcessDarwin::%s(): arch changed from "
+                      "0x%8.8x to 0x%8.8x",
+                      __FUNCTION__, m_cpu_type, process_cpu_type);
+        m_cpu_type = process_cpu_type;
+        // TODO figure out if we need to do something here.
+        // DNBArchProtocol::SetArchitecture (process_cpu_type);
+      }
+      m_thread_list.Clear();
+
+      // TODO hook up breakpoints.
+      // m_breakpoints.DisableAll();
+    }
+
+    if (m_sent_interrupt_signo != 0) {
+      if (received_interrupt) {
+        if (log)
+          log->Printf("NativeProcessDarwin::%s(): process "
+                      "successfully interrupted with signal %i",
+                      __FUNCTION__, m_sent_interrupt_signo);
+
+        // Mark that we received the interrupt signal
+        m_sent_interrupt_signo = 0;
+        // Now check if we had a case where:
+        // 1 - We called NativeProcessDarwin::Interrupt() but we stopped
+        //     for another reason.
+        // 2 - We called NativeProcessDarwin::Resume() (but still
+        //     haven't gotten the interrupt signal).
+        // 3 - We are now incorrectly stopped because we are handling
+        //     the interrupt signal we missed.
+        // 4 - We might need to resume if we stopped only with the
+        //     interrupt signal that we never handled.
+        if (m_auto_resume_signo != 0) {
+          // Only auto_resume if we stopped with _only_ the interrupt
+          // signal.
+          if (num_task_exceptions == 1) {
+            auto_resume = true;
+            if (log)
+              log->Printf("NativeProcessDarwin::%s(): auto "
+                          "resuming due to unhandled interrupt "
+                          "signal %i",
+                          __FUNCTION__, m_auto_resume_signo);
+          }
+          m_auto_resume_signo = 0;
+        }
+      } else {
+        if (log)
+          log->Printf("NativeProcessDarwin::%s(): didn't get signal "
+                      "%i after MachProcess::Interrupt()",
+                      __FUNCTION__, m_sent_interrupt_signo);
+      }
+    }
+  }
+
+  // Let all threads recover from stopping and do any clean up based
+  // on the previous thread state (if any).
+  m_thread_list.ProcessDidStop(*this);
+
+  // Let each thread know of any exceptions
+  for (i = 0; i < m_exception_messages.size(); ++i) {
+    // Let the thread list forward all exceptions on down to each thread.
+    if (m_exception_messages[i].state.task_port == task) {
+      // This exception is for our inferior.
+      m_thread_list.NotifyException(m_exception_messages[i].state);
+    }
+
+    if (log) {
+      StreamString stream;
+      m_exception_messages[i].Dump(stream);
+      stream.Flush();
+      log->PutCString(stream.GetString().c_str());
+    }
+  }
+
+  if (log) {
+    StreamString stream;
+    m_thread_list.Dump(stream);
+    stream.Flush();
+    log->PutCString(stream.GetString().c_str());
+  }
+
+  bool step_more = false;
+  if (m_thread_list.ShouldStop(step_more) && (auto_resume == false)) {
+// TODO - need to hook up event system here. !!!!
 #if 0
         // Wait for the eEventProcessRunningStateChanged event to be reset
         // before changing state to stopped to avoid race condition with
@@ -990,836 +870,707 @@ NativeProcessDarwin::ExceptionMessageBun
         m_events.WaitForEventsToReset(eEventProcessRunningStateChanged,
                                       &timeout);
 #endif
-        SetState(eStateStopped);
-    }
-    else
-    {
-        // Resume without checking our current state.
-        PrivateResume();
-    }
+    SetState(eStateStopped);
+  } else {
+    // Resume without checking our current state.
+    PrivateResume();
+  }
 
-    return m_task;
+  return m_task;
 }
 
-void
-NativeProcessDarwin::StartSTDIOThread()
-{
-    // TODO implement
+void NativeProcessDarwin::StartSTDIOThread() {
+  // TODO implement
 }
 
-Error
-NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+Error NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-    // Strategy: create a thread that sits on waitpid(), waiting for the
-    // inferior process to die, reaping it in the process.  Arrange for
-    // the thread to have a pipe file descriptor that it can send a byte
-    // over when the waitpid completes.  Have the main loop have a read
-    // object for the other side of the pipe, and have the callback for
-    // the read do the process termination message sending.
-
-    // Create a single-direction communication channel.
-    const bool child_inherits = false;
-    error = m_waitpid_pipe.CreateNew(child_inherits);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failed to create waitpid "
-                        "communication pipe: %s", __FUNCTION__,
-                        error.AsCString());
-        return error;
-    }
-
-    // Hook up the waitpid reader callback.
-
-    // TODO make PipePOSIX derive from IOObject.  This is goofy here.
-    const bool transfer_ownership = false;
-    auto io_sp = IOObjectSP(new File(m_waitpid_pipe.GetReadFileDescriptor(),
-                                     transfer_ownership));
-    m_waitpid_reader_handle =
-        main_loop.RegisterReadObject(
-                          io_sp,
-                          [this](MainLoopBase &){ HandleWaitpidResult(); },
-                          error);
-
-    // Create the thread.
-    auto pthread_err = ::pthread_create(&m_waitpid_thread, nullptr,
-                                        WaitpidThread, this);
-    error.SetError(pthread_err, eErrorTypePOSIX);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failed to create waitpid "
-                        "handling thread: %u (%s)", __FUNCTION__,
-                        error.GetError(), error.AsCString());
-        return error;
-    }
+  // Strategy: create a thread that sits on waitpid(), waiting for the
+  // inferior process to die, reaping it in the process.  Arrange for
+  // the thread to have a pipe file descriptor that it can send a byte
+  // over when the waitpid completes.  Have the main loop have a read
+  // object for the other side of the pipe, and have the callback for
+  // the read do the process termination message sending.
 
+  // Create a single-direction communication channel.
+  const bool child_inherits = false;
+  error = m_waitpid_pipe.CreateNew(child_inherits);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): failed to create waitpid "
+                  "communication pipe: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
+
+  // Hook up the waitpid reader callback.
+
+  // TODO make PipePOSIX derive from IOObject.  This is goofy here.
+  const bool transfer_ownership = false;
+  auto io_sp = IOObjectSP(
+      new File(m_waitpid_pipe.GetReadFileDescriptor(), transfer_ownership));
+  m_waitpid_reader_handle = main_loop.RegisterReadObject(
+      io_sp, [this](MainLoopBase &) { HandleWaitpidResult(); }, error);
+
+  // Create the thread.
+  auto pthread_err =
+      ::pthread_create(&m_waitpid_thread, nullptr, WaitpidThread, this);
+  error.SetError(pthread_err, eErrorTypePOSIX);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): failed to create waitpid "
+                  "handling thread: %u (%s)",
+                  __FUNCTION__, error.GetError(), error.AsCString());
     return error;
+  }
+
+  return error;
 }
 
-void*
-NativeProcessDarwin::WaitpidThread(void *arg)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-    if (!arg)
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): cannot run waitpid "
-                        "thread, mandatory process arg was null", __FUNCTION__);
-        return nullptr;
-    }
+void *NativeProcessDarwin::WaitpidThread(void *arg) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (!arg) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): cannot run waitpid "
+                  "thread, mandatory process arg was null",
+                  __FUNCTION__);
+    return nullptr;
+  }
 
-    return reinterpret_cast<NativeProcessDarwin*>(arg)->DoWaitpidThread();
+  return reinterpret_cast<NativeProcessDarwin *>(arg)->DoWaitpidThread();
 }
 
-void
-NativeProcessDarwin::MaybeRaiseThreadPriority()
-{
-#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
-    struct sched_param thread_param;
-    int thread_sched_policy;
-    if (pthread_getschedparam(pthread_self(), &thread_sched_policy,
-                              &thread_param) == 0)
-    {
-        thread_param.sched_priority = 47;
-        pthread_setschedparam(pthread_self(), thread_sched_policy,
-                              &thread_param);
-    }
+void NativeProcessDarwin::MaybeRaiseThreadPriority() {
+#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
+  struct sched_param thread_param;
+  int thread_sched_policy;
+  if (pthread_getschedparam(pthread_self(), &thread_sched_policy,
+                            &thread_param) == 0) {
+    thread_param.sched_priority = 47;
+    pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param);
+  }
 #endif
 }
 
-void*
-NativeProcessDarwin::DoWaitpidThread()
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    if (m_pid == LLDB_INVALID_PROCESS_ID)
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): inferior process ID is "
-                        "not set, cannot waitpid on it", __FUNCTION__);
-        return nullptr;
-    }
-
-    // Name the thread.
-    pthread_setname_np("waitpid thread");
-
-    // Ensure we don't get CPU starved.
-    MaybeRaiseThreadPriority();
-
-    Error error;
-    int status = -1;
+void *NativeProcessDarwin::DoWaitpidThread() {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-    while (1)
-    {
-        // Do a waitpid.
-        ::pid_t child_pid = ::waitpid(m_pid, &status, 0);
-        if (child_pid < 0)
-            error.SetErrorToErrno();
-        if (error.Fail())
-        {
-            if (error.GetError() == EINTR)
-            {
-                // This is okay, we can keep going.
-                if (log)
-                    log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %"
-                                PRIu64 ", &status, 0) interrupted, continuing",
-                                __FUNCTION__, m_pid);
-                continue;
-            }
-
-            // This error is not okay, abort.
-            if (log)
-                log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
-                            ", &status, 0) aborting due to error: %u (%s)",
-                            __FUNCTION__, m_pid, error.GetError(),
-                            error.AsCString());
-            break;
-        }
-
-        // Log the successful result.
-        if (log)
-                log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
-                            ", &status, 0) => %i, status = %i", __FUNCTION__,
-                            m_pid, child_pid, status);
-
-        // Handle the result.
-        if (WIFSTOPPED(status))
-        {
-            if (log)
-                log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
-                            ") received a stop, continuing waitpid() loop",
-                            __FUNCTION__, m_pid);
-            continue;
-        }
-        else // if (WIFEXITED(status) || WIFSIGNALED(status))
-        {
-            if (log)
-                log->Printf("NativeProcessDarwin::%s(pid = %" PRIu64 "): "
-                            "waitpid thread is setting exit status for pid = "
-                            "%i to %i", __FUNCTION__, m_pid,
-                            child_pid, status);
-
-            error = SendInferiorExitStatusToMainLoop(child_pid, status);
-            return nullptr;
-        }
-    }
-
-    // We should never exit as long as our child process is alive.  If we
-    // get here, something completely unexpected went wrong and we should exit.
+  if (m_pid == LLDB_INVALID_PROCESS_ID) {
     if (log)
-        log->Printf("NativeProcessDarwin::%s(): internal error: waitpid thread "
-                    "exited out of its main loop in an unexpected way. pid = %"
-                    PRIu64 ". Sending exit status of -1.", __FUNCTION__, m_pid);
-
-    error = SendInferiorExitStatusToMainLoop((::pid_t)m_pid, -1);
+      log->Printf("NativeProcessDarwin::%s(): inferior process ID is "
+                  "not set, cannot waitpid on it",
+                  __FUNCTION__);
     return nullptr;
-}
+  }
 
-Error
-NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid, int status)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  // Name the thread.
+  pthread_setname_np("waitpid thread");
 
-    size_t bytes_written = 0;
+  // Ensure we don't get CPU starved.
+  MaybeRaiseThreadPriority();
 
-    // Send the pid.
-    error = m_waitpid_pipe.Write(&pid, sizeof(pid), bytes_written);
-    if (error.Fail() || (bytes_written < sizeof(pid)))
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() - failed to write "
-                        "waitpid exiting pid to the pipe.  Client will not "
-                        "hear about inferior exit status!",
-                        __FUNCTION__);
-        return error;
+  Error error;
+  int status = -1;
+
+  while (1) {
+    // Do a waitpid.
+    ::pid_t child_pid = ::waitpid(m_pid, &status, 0);
+    if (child_pid < 0)
+      error.SetErrorToErrno();
+    if (error.Fail()) {
+      if (error.GetError() == EINTR) {
+        // This is okay, we can keep going.
+        if (log)
+          log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
+                      ", &status, 0) interrupted, continuing",
+                      __FUNCTION__, m_pid);
+        continue;
+      }
+
+      // This error is not okay, abort.
+      if (log)
+        log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
+                    ", &status, 0) aborting due to error: %u (%s)",
+                    __FUNCTION__, m_pid, error.GetError(), error.AsCString());
+      break;
     }
 
-    // Send the status.
-    bytes_written = 0;
-    error = m_waitpid_pipe.Write(&status, sizeof(status), bytes_written);
-    if (error.Fail() || (bytes_written < sizeof(status)))
+    // Log the successful result.
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
+                  ", &status, 0) => %i, status = %i",
+                  __FUNCTION__, m_pid, child_pid, status);
+
+    // Handle the result.
+    if (WIFSTOPPED(status)) {
+      if (log)
+        log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64
+                    ") received a stop, continuing waitpid() loop",
+                    __FUNCTION__, m_pid);
+      continue;
+    } else // if (WIFEXITED(status) || WIFSIGNALED(status))
     {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() - failed to write "
-                        "waitpid exit result to the pipe.  Client will not "
-                        "hear about inferior exit status!",
-                        __FUNCTION__);
-    }
-    return error;
-}
-
-Error
-NativeProcessDarwin::HandleWaitpidResult()
-{
-    Error error;
+      if (log)
+        log->Printf("NativeProcessDarwin::%s(pid = %" PRIu64 "): "
+                    "waitpid thread is setting exit status for pid = "
+                    "%i to %i",
+                    __FUNCTION__, m_pid, child_pid, status);
+
+      error = SendInferiorExitStatusToMainLoop(child_pid, status);
+      return nullptr;
+    }
+  }
+
+  // We should never exit as long as our child process is alive.  If we
+  // get here, something completely unexpected went wrong and we should exit.
+  if (log)
+    log->Printf(
+        "NativeProcessDarwin::%s(): internal error: waitpid thread "
+        "exited out of its main loop in an unexpected way. pid = %" PRIu64
+        ". Sending exit status of -1.",
+        __FUNCTION__, m_pid);
+
+  error = SendInferiorExitStatusToMainLoop((::pid_t)m_pid, -1);
+  return nullptr;
+}
+
+Error NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid,
+                                                            int status) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  size_t bytes_written = 0;
+
+  // Send the pid.
+  error = m_waitpid_pipe.Write(&pid, sizeof(pid), bytes_written);
+  if (error.Fail() || (bytes_written < sizeof(pid))) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() - failed to write "
+                  "waitpid exiting pid to the pipe.  Client will not "
+                  "hear about inferior exit status!",
+                  __FUNCTION__);
+    return error;
+  }
+
+  // Send the status.
+  bytes_written = 0;
+  error = m_waitpid_pipe.Write(&status, sizeof(status), bytes_written);
+  if (error.Fail() || (bytes_written < sizeof(status))) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() - failed to write "
+                  "waitpid exit result to the pipe.  Client will not "
+                  "hear about inferior exit status!",
+                  __FUNCTION__);
+  }
+  return error;
+}
+
+Error NativeProcessDarwin::HandleWaitpidResult() {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  // Read the pid.
+  const bool notify_status = true;
+
+  ::pid_t pid = -1;
+  size_t bytes_read = 0;
+  error = m_waitpid_pipe.Read(&pid, sizeof(pid), bytes_read);
+  if (error.Fail() || (bytes_read < sizeof(pid))) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() - failed to read "
+                  "waitpid exiting pid from the pipe.  Will notify "
+                  "as if parent process died with exit status -1.",
+                  __FUNCTION__);
+    SetExitStatus(eExitTypeInvalid, -1, "failed to receive waitpid result",
+                  notify_status);
+    return error;
+  }
+
+  // Read the status.
+  int status = -1;
+  error = m_waitpid_pipe.Read(&status, sizeof(status), bytes_read);
+  if (error.Fail() || (bytes_read < sizeof(status))) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() - failed to read "
+                  "waitpid exit status from the pipe.  Will notify "
+                  "as if parent process died with exit status -1.",
+                  __FUNCTION__);
+    SetExitStatus(eExitTypeInvalid, -1, "failed to receive waitpid result",
+                  notify_status);
+    return error;
+  }
+
+  // Notify the monitor that our state has changed.
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(): main loop received waitpid "
+                "exit status info: pid=%i (%s), status=%i",
+                __FUNCTION__, pid,
+                (pid == m_pid) ? "the inferior" : "not the inferior", status);
+
+  ExitType exit_type = eExitTypeInvalid;
+  int exit_status = -1;
+
+  if (WIFEXITED(status)) {
+    exit_type = eExitTypeExit;
+    exit_status = WEXITSTATUS(status);
+  } else if (WIFSIGNALED(status)) {
+    exit_type = eExitTypeSignal;
+    exit_status = WTERMSIG(status);
+  }
+
+  SetExitStatus(exit_type, exit_status, nullptr, notify_status);
+  return error;
+}
+
+task_t NativeProcessDarwin::TaskPortForProcessID(Error &error,
+                                                 bool force) const {
+  if ((m_task == TASK_NULL) || force) {
     Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    // Read the pid.
-    const bool notify_status = true;
-
-    ::pid_t pid = -1;
-    size_t bytes_read = 0;
-    error = m_waitpid_pipe.Read(&pid, sizeof(pid), bytes_read);
-    if (error.Fail() || (bytes_read < sizeof(pid)))
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() - failed to read "
-                        "waitpid exiting pid from the pipe.  Will notify "
-                        "as if parent process died with exit status -1.",
-                        __FUNCTION__);
-        SetExitStatus(eExitTypeInvalid, -1, "failed to receive waitpid result",
-                      notify_status);
-        return error;
+    if (m_pid == LLDB_INVALID_PROCESS_ID) {
+      if (log)
+        log->Printf("NativeProcessDarwin::%s(): cannot get task due "
+                    "to invalid pid",
+                    __FUNCTION__);
+      return TASK_NULL;
     }
 
-    // Read the status.
-    int status = -1;
-    error = m_waitpid_pipe.Read(&status, sizeof(status), bytes_read);
-    if (error.Fail() || (bytes_read < sizeof(status)))
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() - failed to read "
-                        "waitpid exit status from the pipe.  Will notify "
-                        "as if parent process died with exit status -1.",
-                        __FUNCTION__);
-        SetExitStatus(eExitTypeInvalid, -1, "failed to receive waitpid result",
-                      notify_status);
-        return error;
-    }
+    const uint32_t num_retries = 10;
+    const uint32_t usec_interval = 10000;
 
-    // Notify the monitor that our state has changed.
-    if (log)
-        log->Printf("NativeProcessDarwin::%s(): main loop received waitpid "
-                    "exit status info: pid=%i (%s), status=%i",
-                    __FUNCTION__, pid,
-                    (pid == m_pid) ? "the inferior" : "not the inferior",
-                    status);
+    mach_port_t task_self = mach_task_self();
+    task_t task = TASK_NULL;
 
-    ExitType exit_type = eExitTypeInvalid;
-    int exit_status = -1;
+    for (uint32_t i = 0; i < num_retries; i++) {
+      kern_return_t err = ::task_for_pid(task_self, m_pid, &task);
+      if (err == 0) {
+        // Succeeded.  Save and return it.
+        error.Clear();
+        m_task = task;
+        log->Printf("NativeProcessDarwin::%s(): ::task_for_pid("
+                    "stub_port = 0x%4.4x, pid = %llu, &task) "
+                    "succeeded: inferior task port = 0x%4.4x",
+                    __FUNCTION__, task_self, m_pid, m_task);
+        return m_task;
+      } else {
+        // Failed to get the task for the inferior process.
+        error.SetError(err, eErrorTypeMachKernel);
+        if (log) {
+          log->Printf("NativeProcessDarwin::%s(): ::task_for_pid("
+                      "stub_port = 0x%4.4x, pid = %llu, &task) "
+                      "failed, err = 0x%8.8x (%s)",
+                      __FUNCTION__, task_self, m_pid, err, error.AsCString());
+        }
+      }
 
-    if (WIFEXITED(status))
-    {
-        exit_type = eExitTypeExit;
-        exit_status = WEXITSTATUS(status);
-    }
-    else if (WIFSIGNALED(status))
-    {
-        exit_type = eExitTypeSignal;
-        exit_status = WTERMSIG(status);
+      // Sleep a bit and try again
+      ::usleep(usec_interval);
     }
 
-    SetExitStatus(exit_type, exit_status, nullptr, notify_status);
-    return error;
+    // We failed to get the task for the inferior process.
+    // Ensure that it is cleared out.
+    m_task = TASK_NULL;
+  }
+  return m_task;
 }
 
-task_t
-NativeProcessDarwin::TaskPortForProcessID(Error &error, bool force) const
-{
-    if ((m_task == TASK_NULL) || force)
-    {
-        Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-        if (m_pid == LLDB_INVALID_PROCESS_ID)
-        {
-            if (log)
-                log->Printf("NativeProcessDarwin::%s(): cannot get task due "
-                            "to invalid pid", __FUNCTION__);
-            return TASK_NULL;
-        }
-
-        const uint32_t num_retries = 10;
-        const uint32_t usec_interval = 10000;
-
-        mach_port_t task_self = mach_task_self();
-        task_t task = TASK_NULL;
-
-        for (uint32_t i = 0; i < num_retries; i++)
-        {
-            kern_return_t err = ::task_for_pid(task_self, m_pid, &task);
-            if (err == 0)
-            {
-                // Succeeded.  Save and return it.
-                error.Clear();
-                m_task = task;
-                log->Printf("NativeProcessDarwin::%s(): ::task_for_pid("
-                            "stub_port = 0x%4.4x, pid = %llu, &task) "
-                            "succeeded: inferior task port = 0x%4.4x",
-                            __FUNCTION__, task_self, m_pid, m_task);
-                return m_task;
-            }
-            else
-            {
-                // Failed to get the task for the inferior process.
-                error.SetError(err, eErrorTypeMachKernel);
-                if (log)
-                {
-                    log->Printf("NativeProcessDarwin::%s(): ::task_for_pid("
-                                "stub_port = 0x%4.4x, pid = %llu, &task) "
-                                "failed, err = 0x%8.8x (%s)",
-                                __FUNCTION__, task_self,
-                                m_pid,
-                                err,
-                                error.AsCString());
-                }
-            }
-
-            // Sleep a bit and try again
-            ::usleep (usec_interval);
-        }
-
-        // We failed to get the task for the inferior process.
-        // Ensure that it is cleared out.
-        m_task = TASK_NULL;
-    }
-    return m_task;
+void NativeProcessDarwin::AttachToInferior(MainLoop &mainloop, lldb::pid_t pid,
+                                           Error &error) {
+  error.SetErrorString("TODO: implement");
 }
 
-void
-NativeProcessDarwin::AttachToInferior(MainLoop &mainloop, lldb::pid_t pid,
-                                      Error &error)
-{
-    error.SetErrorString("TODO: implement");
-}
+Error NativeProcessDarwin::PrivateResume() {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-Error
-NativeProcessDarwin::PrivateResume()
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
+  m_auto_resume_signo = m_sent_interrupt_signo;
 
-    std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
-    m_auto_resume_signo = m_sent_interrupt_signo;
+  if (log) {
+    if (m_auto_resume_signo)
+      log->Printf("NativeProcessDarwin::%s(): task 0x%x resuming (with "
+                  "unhandled interrupt signal %i)...",
+                  __FUNCTION__, m_task, m_auto_resume_signo);
+    else
+      log->Printf("NativeProcessDarwin::%s(): task 0x%x resuming...",
+                  __FUNCTION__, m_task);
+  }
 
+  error = ReplyToAllExceptions();
+  if (error.Fail()) {
     if (log)
-    {
-        if (m_auto_resume_signo)
-            log->Printf("NativeProcessDarwin::%s(): task 0x%x resuming (with "
-                        "unhandled interrupt signal %i)...", __FUNCTION__,
-                        m_task, m_auto_resume_signo);
-        else
-            log->Printf("NativeProcessDarwin::%s(): task 0x%x resuming...",
-                        __FUNCTION__, m_task);
-    }
-
-    error = ReplyToAllExceptions();
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): aborting, failed to "
-                        "reply to exceptions: %s", __FUNCTION__,
-                        error.AsCString());
-        return error;
-    }
-    //    bool stepOverBreakInstruction = step;
+      log->Printf("NativeProcessDarwin::%s(): aborting, failed to "
+                  "reply to exceptions: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
+  //    bool stepOverBreakInstruction = step;
+
+  // Let the thread prepare to resume and see if any threads want us to
+  // step over a breakpoint instruction (ProcessWillResume will modify
+  // the value of stepOverBreakInstruction).
+  m_thread_list.ProcessWillResume(*this, m_thread_actions);
+
+  // Set our state accordingly
+  if (m_thread_actions.NumActionsWithState(eStateStepping))
+    SetState(eStateStepping);
+  else
+    SetState(eStateRunning);
+
+  // Now resume our task.
+  error = ResumeTask();
+  return error;
+}
+
+Error NativeProcessDarwin::ReplyToAllExceptions() {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
 
-    // Let the thread prepare to resume and see if any threads want us to
-    // step over a breakpoint instruction (ProcessWillResume will modify
-    // the value of stepOverBreakInstruction).
-    m_thread_list.ProcessWillResume(*this, m_thread_actions);
-
-    // Set our state accordingly
-    if (m_thread_actions.NumActionsWithState(eStateStepping))
-        SetState(eStateStepping);
-    else
-        SetState(eStateRunning);
-
-    // Now resume our task.
-    error = ResumeTask();
+  TaskPortForProcessID(error);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): no task port, aborting",
+                  __FUNCTION__);
     return error;
-}
+  }
 
-Error
-NativeProcessDarwin::ReplyToAllExceptions()
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                      LIBLLDB_LOG_VERBOSE));
+  std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
+  if (m_exception_messages.empty()) {
+    // We're done.
+    return error;
+  }
 
-    TaskPortForProcessID(error);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): no task port, aborting",
-                        __FUNCTION__);
-        return error;
+  size_t index = 0;
+  for (auto &message : m_exception_messages) {
+    if (log) {
+      log->Printf("NativeProcessDarwin::%s(): replying to exception "
+                  "%zu...",
+                  __FUNCTION__, index++);
     }
 
-    std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
-    if (m_exception_messages.empty())
-    {
-        // We're done.
-        return error;
-    }
+    int thread_reply_signal = 0;
 
-    size_t index = 0;
-    for (auto &message : m_exception_messages)
-    {
-        if (log)
-        {
-            log->Printf("NativeProcessDarwin::%s(): replying to exception "
-                        "%zu...", __FUNCTION__, index++);
-        }
+    const tid_t tid =
+        m_thread_list.GetThreadIDByMachPortNumber(message.state.thread_port);
+    const ResumeAction *action = nullptr;
+    if (tid != LLDB_INVALID_THREAD_ID)
+      action = m_thread_actions.GetActionForThread(tid, false);
 
-        int thread_reply_signal = 0;
-
-        const tid_t tid =
-            m_thread_list.GetThreadIDByMachPortNumber(message.state
-                                                      .thread_port);
-        const ResumeAction *action = nullptr;
-        if (tid != LLDB_INVALID_THREAD_ID)
-            action = m_thread_actions.GetActionForThread (tid, false);
-
-        if (action)
-        {
-            thread_reply_signal = action->signal;
-            if (thread_reply_signal)
-                m_thread_actions.SetSignalHandledForThread(tid);
-        }
+    if (action) {
+      thread_reply_signal = action->signal;
+      if (thread_reply_signal)
+        m_thread_actions.SetSignalHandledForThread(tid);
+    }
 
-        error = message.Reply(m_pid, m_task, thread_reply_signal);
-        if (error.Fail() && log)
-        {
-            // We log any error here, but we don't stop the exception
-            // response handling.
-            log->Printf("NativeProcessDarwin::%s(): failed to reply to "
-                        "exception: %s", __FUNCTION__, error.AsCString());
-            error.Clear();
-        }
+    error = message.Reply(m_pid, m_task, thread_reply_signal);
+    if (error.Fail() && log) {
+      // We log any error here, but we don't stop the exception
+      // response handling.
+      log->Printf("NativeProcessDarwin::%s(): failed to reply to "
+                  "exception: %s",
+                  __FUNCTION__, error.AsCString());
+      error.Clear();
     }
+  }
 
-    // Erase all exception message as we should have used and replied
-    // to them all already.
-    m_exception_messages.clear();
-    return error;
+  // Erase all exception message as we should have used and replied
+  // to them all already.
+  m_exception_messages.clear();
+  return error;
 }
 
-Error
-NativeProcessDarwin::ResumeTask()
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    TaskPortForProcessID(error);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failed to get task port "
-                        "for process when attempting to resume: %s",
-                        __FUNCTION__, error.AsCString());
-        return error;
-    }
-    if (m_task == TASK_NULL)
-    {
-        error.SetErrorString("task port retrieval succeeded but task port is "
-                             "null when attempting to resume the task");
-        return error;
-    }
+Error NativeProcessDarwin::ResumeTask() {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
+  TaskPortForProcessID(error);
+  if (error.Fail()) {
     if (log)
-        log->Printf("NativeProcessDarwin::%s(): requesting resume of task "
-                    "0x%4.4x", __FUNCTION__, m_task);
-
-    // Get the BasicInfo struct to verify that we're suspended before we try
-    // to resume the task.
-    struct task_basic_info task_info;
-    error = GetTaskBasicInfo(m_task, &task_info);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): failed to get task "
-                        "BasicInfo when attempting to resume: %s",
-                        __FUNCTION__, error.AsCString());
-        return error;
-    }
-
-    // task_resume isn't counted like task_suspend calls are, so if the
-    // task is not suspended, don't try and resume it since it is already
-    // running
-    if (task_info.suspend_count > 0)
-    {
-        auto mach_err = ::task_resume(m_task);
-        error.SetError(mach_err, eErrorTypeMachKernel);
-        if (log)
-        {
-            if (error.Success())
-                log->Printf("::task_resume(target_task = 0x%4.4x): success",
-                            m_task);
-            else
-                log->Printf("::task_resume(target_task = 0x%4.4x) error: %s",
-                            m_task, error.AsCString());
-        }
-    }
-    else
-    {
-        if (log)
-            log->Printf("::task_resume(target_task = 0x%4.4x): ignored, "
-                        "already running", m_task);
+      log->Printf("NativeProcessDarwin::%s(): failed to get task port "
+                  "for process when attempting to resume: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
+  if (m_task == TASK_NULL) {
+    error.SetErrorString("task port retrieval succeeded but task port is "
+                         "null when attempting to resume the task");
+    return error;
+  }
+
+  if (log)
+    log->Printf("NativeProcessDarwin::%s(): requesting resume of task "
+                "0x%4.4x",
+                __FUNCTION__, m_task);
+
+  // Get the BasicInfo struct to verify that we're suspended before we try
+  // to resume the task.
+  struct task_basic_info task_info;
+  error = GetTaskBasicInfo(m_task, &task_info);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): failed to get task "
+                  "BasicInfo when attempting to resume: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
+
+  // task_resume isn't counted like task_suspend calls are, so if the
+  // task is not suspended, don't try and resume it since it is already
+  // running
+  if (task_info.suspend_count > 0) {
+    auto mach_err = ::task_resume(m_task);
+    error.SetError(mach_err, eErrorTypeMachKernel);
+    if (log) {
+      if (error.Success())
+        log->Printf("::task_resume(target_task = 0x%4.4x): success", m_task);
+      else
+        log->Printf("::task_resume(target_task = 0x%4.4x) error: %s", m_task,
+                    error.AsCString());
     }
+  } else {
+    if (log)
+      log->Printf("::task_resume(target_task = 0x%4.4x): ignored, "
+                  "already running",
+                  m_task);
+  }
 
-    return error;
+  return error;
 }
 
-bool
-NativeProcessDarwin::IsTaskValid() const
-{
-    if (m_task == TASK_NULL)
-        return false;
+bool NativeProcessDarwin::IsTaskValid() const {
+  if (m_task == TASK_NULL)
+    return false;
 
-    struct task_basic_info task_info;
-    return GetTaskBasicInfo(m_task, &task_info).Success();
+  struct task_basic_info task_info;
+  return GetTaskBasicInfo(m_task, &task_info).Success();
 }
 
-bool
-NativeProcessDarwin::IsTaskValid(task_t task) const
-{
-    if (task == TASK_NULL)
-        return false;
+bool NativeProcessDarwin::IsTaskValid(task_t task) const {
+  if (task == TASK_NULL)
+    return false;
 
-    struct task_basic_info task_info;
-    return GetTaskBasicInfo(task, &task_info).Success();
+  struct task_basic_info task_info;
+  return GetTaskBasicInfo(task, &task_info).Success();
 }
 
-mach_port_t
-NativeProcessDarwin::GetExceptionPort() const
-{
-    return m_exception_port;
+mach_port_t NativeProcessDarwin::GetExceptionPort() const {
+  return m_exception_port;
 }
 
-bool
-NativeProcessDarwin::IsExceptionPortValid () const
-{
-    return MACH_PORT_VALID(m_exception_port);
+bool NativeProcessDarwin::IsExceptionPortValid() const {
+  return MACH_PORT_VALID(m_exception_port);
 }
 
-Error
-NativeProcessDarwin::GetTaskBasicInfo(task_t task,
-                                      struct task_basic_info *info) const
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
-    // Validate args.
-    if (info == NULL)
-    {
-        error.SetErrorStringWithFormat("NativeProcessDarwin::%s(): mandatory "
-                                       "info arg is null", __FUNCTION__);
-        return error;
-    }
+Error NativeProcessDarwin::GetTaskBasicInfo(
+    task_t task, struct task_basic_info *info) const {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-    // Grab the task if we don't already have it.
-    if (task == TASK_NULL)
-    {
-        error.SetErrorStringWithFormat("NativeProcessDarwin::%s(): given task "
-                                       "is invalid", __FUNCTION__);
-    }
-
-    mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
-    auto err = ::task_info(m_task, TASK_BASIC_INFO, (task_info_t)info, &count);
-    error.SetError(err, eErrorTypeMachKernel);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf("::task_info(target_task = 0x%4.4x, "
-                        "flavor = TASK_BASIC_INFO, task_info_out => %p, "
-                        "task_info_outCnt => %u) failed: %u (%s)", m_task, info,
-                        count, error.GetError(), error.AsCString());
-        return error;
-    }
-
-    Log *verbose_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
-                                              LIBLLDB_LOG_VERBOSE));
-    if (verbose_log)
-    {
-        float user = (float)info->user_time.seconds +
-            (float)info->user_time.microseconds / 1000000.0f;
-        float system = (float)info->user_time.seconds +
-            (float)info->user_time.microseconds / 1000000.0f;
-        verbose_log->Printf("task_basic_info = { suspend_count = %i, "
-                            "virtual_size = 0x%8.8llx, resident_size = "
-                            "0x%8.8llx, user_time = %f, system_time = %f }",
-                            info->suspend_count,
-                            (uint64_t)info->virtual_size,
-                            (uint64_t)info->resident_size,
-                            user, system);
-    }
+  // Validate args.
+  if (info == NULL) {
+    error.SetErrorStringWithFormat("NativeProcessDarwin::%s(): mandatory "
+                                   "info arg is null",
+                                   __FUNCTION__);
     return error;
-}
-
-Error
-NativeProcessDarwin::SuspendTask()
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  }
 
-    if (m_task == TASK_NULL)
-    {
-        error.SetErrorString("task port is null, cannot suspend task");
-        if (log)
-            log->Printf("NativeProcessDarwin::%s() failed: %s",
-                        __FUNCTION__, error.AsCString());
-        return error;
-    }
+  // Grab the task if we don't already have it.
+  if (task == TASK_NULL) {
+    error.SetErrorStringWithFormat("NativeProcessDarwin::%s(): given task "
+                                   "is invalid",
+                                   __FUNCTION__);
+  }
 
-    auto mach_err = ::task_suspend(m_task);
-    error.SetError(mach_err, eErrorTypeMachKernel);
-    if (error.Fail() && log)
-        log->Printf("::task_suspend(target_task = 0x%4.4x)", m_task);
+  mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
+  auto err = ::task_info(m_task, TASK_BASIC_INFO, (task_info_t)info, &count);
+  error.SetError(err, eErrorTypeMachKernel);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("::task_info(target_task = 0x%4.4x, "
+                  "flavor = TASK_BASIC_INFO, task_info_out => %p, "
+                  "task_info_outCnt => %u) failed: %u (%s)",
+                  m_task, info, count, error.GetError(), error.AsCString());
+    return error;
+  }
+
+  Log *verbose_log(
+      GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
+  if (verbose_log) {
+    float user = (float)info->user_time.seconds +
+                 (float)info->user_time.microseconds / 1000000.0f;
+    float system = (float)info->user_time.seconds +
+                   (float)info->user_time.microseconds / 1000000.0f;
+    verbose_log->Printf("task_basic_info = { suspend_count = %i, "
+                        "virtual_size = 0x%8.8llx, resident_size = "
+                        "0x%8.8llx, user_time = %f, system_time = %f }",
+                        info->suspend_count, (uint64_t)info->virtual_size,
+                        (uint64_t)info->resident_size, user, system);
+  }
+  return error;
+}
+
+Error NativeProcessDarwin::SuspendTask() {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
+  if (m_task == TASK_NULL) {
+    error.SetErrorString("task port is null, cannot suspend task");
+    if (log)
+      log->Printf("NativeProcessDarwin::%s() failed: %s", __FUNCTION__,
+                  error.AsCString());
     return error;
-}
+  }
 
-Error
-NativeProcessDarwin::Resume(const ResumeActionList &resume_actions)
-{
-    Error error;
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  auto mach_err = ::task_suspend(m_task);
+  error.SetError(mach_err, eErrorTypeMachKernel);
+  if (error.Fail() && log)
+    log->Printf("::task_suspend(target_task = 0x%4.4x)", m_task);
 
-    if (log)
-        log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__);
+  return error;
+}
 
-    if (CanResume())
-    {
-        m_thread_actions = resume_actions;
-        error = PrivateResume();
-        return error;
-    }
+Error NativeProcessDarwin::Resume(const ResumeActionList &resume_actions) {
+  Error error;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-    auto state = GetState();
-    if (state == eStateRunning)
-    {
-        if (log)
-            log->Printf("NativeProcessDarwin::%s(): task 0x%x is already "
-                        "running, ignoring...", __FUNCTION__,
-                        TaskPortForProcessID(error));
-        return error;
-    }
+  if (log)
+    log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__);
 
-    // We can't resume from this state.
-    error.SetErrorStringWithFormat("task 0x%x has state %s, can't resume",
-                                   TaskPortForProcessID(error),
-                                   StateAsCString(state));
+  if (CanResume()) {
+    m_thread_actions = resume_actions;
+    error = PrivateResume();
     return error;
-}
+  }
 
-Error
-NativeProcessDarwin::Halt()
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
+  auto state = GetState();
+  if (state == eStateRunning) {
+    if (log)
+      log->Printf("NativeProcessDarwin::%s(): task 0x%x is already "
+                  "running, ignoring...",
+                  __FUNCTION__, TaskPortForProcessID(error));
     return error;
-}
+  }
 
-Error
-NativeProcessDarwin::Detach()
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+  // We can't resume from this state.
+  error.SetErrorStringWithFormat("task 0x%x has state %s, can't resume",
+                                 TaskPortForProcessID(error),
+                                 StateAsCString(state));
+  return error;
 }
 
-Error
-NativeProcessDarwin::Signal(int signo)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::Halt() {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::Interrupt()
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::Detach() {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::Kill()
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::Signal(int signo) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::GetMemoryRegionInfo(lldb::addr_t load_addr,
-                                         MemoryRegionInfo &range_info)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::Interrupt() {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
-                                size_t &bytes_read)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::Kill() {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf,
-                                           size_t size, size_t &bytes_read)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::GetMemoryRegionInfo(lldb::addr_t load_addr,
+                                               MemoryRegionInfo &range_info) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::WriteMemory(lldb::addr_t addr, const void *buf,
-                                 size_t size, size_t &bytes_written)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+                                      size_t &bytes_read) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::AllocateMemory(size_t size, uint32_t permissions,
-                                    lldb::addr_t &addr)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf,
+                                                 size_t size,
+                                                 size_t &bytes_read) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::DeallocateMemory(lldb::addr_t addr)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::WriteMemory(lldb::addr_t addr, const void *buf,
+                                       size_t size, size_t &bytes_written) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-lldb::addr_t
-NativeProcessDarwin::GetSharedLibraryInfoAddress()
-{
-    return LLDB_INVALID_ADDRESS;
+Error NativeProcessDarwin::AllocateMemory(size_t size, uint32_t permissions,
+                                          lldb::addr_t &addr) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-size_t
-NativeProcessDarwin::UpdateThreads()
-{
-    return 0;
+Error NativeProcessDarwin::DeallocateMemory(lldb::addr_t addr) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-bool
-NativeProcessDarwin::GetArchitecture(ArchSpec &arch) const
-{
-    return false;
+lldb::addr_t NativeProcessDarwin::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
 }
 
-Error
-NativeProcessDarwin::SetBreakpoint(lldb::addr_t addr, uint32_t size,
-                                   bool hardware)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+size_t NativeProcessDarwin::UpdateThreads() { return 0; }
+
+bool NativeProcessDarwin::GetArchitecture(ArchSpec &arch) const {
+  return false;
 }
 
-void
-NativeProcessDarwin::DoStopIDBumped(uint32_t newBumpId)
-{
+Error NativeProcessDarwin::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+                                         bool hardware) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::GetLoadedModuleFileSpec(const char* module_path,
-                                             FileSpec& file_spec)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+void NativeProcessDarwin::DoStopIDBumped(uint32_t newBumpId) {}
+
+Error NativeProcessDarwin::GetLoadedModuleFileSpec(const char *module_path,
+                                                   FileSpec &file_spec) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
-Error
-NativeProcessDarwin::GetFileLoadAddress(const llvm::StringRef& file_name,
-                                        lldb::addr_t& load_addr)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::GetFileLoadAddress(const llvm::StringRef &file_name,
+                                              lldb::addr_t &load_addr) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }
 
 // -----------------------------------------------------------------
 // NativeProcessProtocol protected interface
 // -----------------------------------------------------------------
-Error
-NativeProcessDarwin::GetSoftwareBreakpointTrapOpcode(size_t
-                                                     trap_opcode_size_hint,
-                                                     size_t &actual_opcode_size,
-                                                     const uint8_t
-                                                     *&trap_opcode_bytes)
-{
-    Error error;
-    error.SetErrorString("TODO: implement");
-    return error;
+Error NativeProcessDarwin::GetSoftwareBreakpointTrapOpcode(
+    size_t trap_opcode_size_hint, size_t &actual_opcode_size,
+    const uint8_t *&trap_opcode_bytes) {
+  Error error;
+  error.SetErrorString("TODO: implement");
+  return error;
 }

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeProcessDarwin.h Tue Sep  6 15:57:50 2016
@@ -23,217 +23,178 @@
 
 // Other libraries and framework includes
 #include "lldb/Core/ArchSpec.h"
-#include "lldb/lldb-types.h"
-#include "lldb/Host/common/NativeProcessProtocol.h"
 #include "lldb/Host/Debug.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/Pipe.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
 #include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/lldb-types.h"
 
-#include "NativeThreadListDarwin.h"
 #include "LaunchFlavor.h"
 #include "MachException.h"
 #include "NativeThreadDarwin.h"
+#include "NativeThreadListDarwin.h"
 
 namespace lldb_private {
-    class Error;
-    class Scalar;
+class Error;
+class Scalar;
+
+namespace process_darwin {
+
+/// @class NativeProcessDarwin
+/// @brief Manages communication with the inferior (debugee) process.
+///
+/// Upon construction, this class prepares and launches an inferior
+/// process for debugging.
+///
+/// Changes in the inferior process state are broadcasted.
+class NativeProcessDarwin : public NativeProcessProtocol {
+  friend Error NativeProcessProtocol::Launch(
+      ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
+      MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
+
+  friend Error NativeProcessProtocol::Attach(
+      lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
+      MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
+
+public:
+  ~NativeProcessDarwin() override;
+
+  // -----------------------------------------------------------------
+  // NativeProcessProtocol Interface
+  // -----------------------------------------------------------------
+  Error Resume(const ResumeActionList &resume_actions) override;
+
+  Error Halt() override;
+
+  Error Detach() override;
+
+  Error Signal(int signo) override;
+
+  Error Interrupt() override;
+
+  Error Kill() override;
+
+  Error GetMemoryRegionInfo(lldb::addr_t load_addr,
+                            MemoryRegionInfo &range_info) override;
+
+  Error ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+                   size_t &bytes_read) override;
+
+  Error ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
+                              size_t &bytes_read) override;
+
+  Error WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
+                    size_t &bytes_written) override;
+
+  Error AllocateMemory(size_t size, uint32_t permissions,
+                       lldb::addr_t &addr) override;
+
+  Error DeallocateMemory(lldb::addr_t addr) override;
+
+  lldb::addr_t GetSharedLibraryInfoAddress() override;
+
+  size_t UpdateThreads() override;
+
+  bool GetArchitecture(ArchSpec &arch) const override;
+
+  Error SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override;
+
+  void DoStopIDBumped(uint32_t newBumpId) override;
+
+  Error GetLoadedModuleFileSpec(const char *module_path,
+                                FileSpec &file_spec) override;
+
+  Error GetFileLoadAddress(const llvm::StringRef &file_name,
+                           lldb::addr_t &load_addr) override;
 
-    namespace process_darwin {
+  NativeThreadDarwinSP GetThreadByID(lldb::tid_t id);
 
-        /// @class NativeProcessDarwin
-        /// @brief Manages communication with the inferior (debugee) process.
-        ///
-        /// Upon construction, this class prepares and launches an inferior
-        /// process for debugging.
-        ///
-        /// Changes in the inferior process state are broadcasted.
-        class NativeProcessDarwin: public NativeProcessProtocol
-        {
-            friend Error
-            NativeProcessProtocol::Launch(ProcessLaunchInfo &launch_info,
-                                          NativeDelegate &native_delegate,
-                                          MainLoop &mainloop,
-                                          NativeProcessProtocolSP &process_sp);
-
-            friend Error
-            NativeProcessProtocol::Attach(lldb::pid_t pid,
-                                          NativeProcessProtocol::NativeDelegate
-                                          &native_delegate,
-                                          MainLoop &mainloop,
-                                          NativeProcessProtocolSP &process_sp);
-
-        public:
-
-            ~NativeProcessDarwin() override;
-
-            // -----------------------------------------------------------------
-            // NativeProcessProtocol Interface
-            // -----------------------------------------------------------------
-            Error
-            Resume(const ResumeActionList &resume_actions) override;
-
-            Error
-            Halt() override;
-
-            Error
-            Detach() override;
-
-            Error
-            Signal(int signo) override;
-
-            Error
-            Interrupt() override;
-
-            Error
-            Kill() override;
-
-            Error
-            GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo
-                                &range_info) override;
-
-            Error
-            ReadMemory(lldb::addr_t addr, void *buf, size_t size,
-                       size_t &bytes_read) override;
-
-            Error
-            ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
-                                  size_t &bytes_read) override;
-
-            Error
-            WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
-                        size_t &bytes_written) override;
-
-            Error
-            AllocateMemory(size_t size, uint32_t permissions,
-                           lldb::addr_t &addr) override;
-
-            Error
-            DeallocateMemory(lldb::addr_t addr) override;
-
-            lldb::addr_t
-            GetSharedLibraryInfoAddress() override;
-
-            size_t
-            UpdateThreads() override;
-
-            bool
-            GetArchitecture(ArchSpec &arch) const override;
-
-            Error
-            SetBreakpoint(lldb::addr_t addr, uint32_t size,
-                          bool hardware) override;
-
-            void
-            DoStopIDBumped(uint32_t newBumpId) override;
-
-            Error
-            GetLoadedModuleFileSpec(const char* module_path,
-                                    FileSpec& file_spec) override;
-
-            Error
-            GetFileLoadAddress(const llvm::StringRef& file_name,
-                               lldb::addr_t& load_addr) override;
-
-            NativeThreadDarwinSP
-            GetThreadByID(lldb::tid_t id);
-
-            task_t
-            GetTask() const
-            {
-                return m_task;
-            }
-
-            // -----------------------------------------------------------------
-            // Interface used by NativeRegisterContext-derived classes.
-            // -----------------------------------------------------------------
-            static Error
-            PtraceWrapper(int req,
-                          lldb::pid_t pid,
-                          void *addr = nullptr,
-                          void *data = nullptr,
-                          size_t data_size = 0,
-                          long *result = nullptr);
-
-            bool
-            SupportHardwareSingleStepping() const;
-
-        protected:
-            // -----------------------------------------------------------------
-            // NativeProcessProtocol protected interface
-            // -----------------------------------------------------------------
-            Error
-            GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
-                                            size_t &actual_opcode_size,
-                                            const uint8_t *&trap_opcode_bytes)
-            override;
-
-        private:
-
-            // -----------------------------------------------------------------
-            /// Mach task-related Member Variables
-            // -----------------------------------------------------------------
-
-            // The task port for the inferior process.
-            mutable task_t  m_task;
-
-            // True if the inferior process did an exec since we started
-            // monitoring it.
-            bool  m_did_exec;
-
-            // The CPU type of this process.
-            mutable cpu_type_t  m_cpu_type;
-
-            // -----------------------------------------------------------------
-            /// Exception/Signal Handling Member Variables
-            // -----------------------------------------------------------------
-
-            // Exception port on which we will receive child exceptions
-            mach_port_t  m_exception_port;
-
-            // Saved state of the child exception port prior to us installing
-            // our own intercepting port.
-            MachException::PortInfo  m_exc_port_info;
-
-            // The thread that runs the Mach exception read and reply handler.
-            pthread_t  m_exception_thread;
-
-            // TODO see if we can remove this if we get the exception collection
-            // and distribution to happen in a single-threaded fashion.
-            std::recursive_mutex  m_exception_messages_mutex;
-
-            // A collection of exception messages caught when listening to the
-            // exception port.
-            MachException::Message::collection  m_exception_messages;
-
-            // When we call MachProcess::Interrupt(), we want to send this
-            // signal (if non-zero).
-            int  m_sent_interrupt_signo;
-
-            // If we resume the process and still haven't received our
-            // interrupt signal (if this is non-zero).
-            int  m_auto_resume_signo;
-
-            // -----------------------------------------------------------------
-            /// Thread-related Member Variables
-            // -----------------------------------------------------------------
-            NativeThreadListDarwin  m_thread_list;
-            ResumeActionList        m_thread_actions;
-
-            // -----------------------------------------------------------------
-            /// Process Lifetime Member Variable
-            // -----------------------------------------------------------------
-
-            // The pipe over which the waitpid thread and the main loop will
-            // communicate.
-            Pipe  m_waitpid_pipe;
+  task_t GetTask() const { return m_task; }
 
-            // The thread that runs the waitpid handler.
-            pthread_t  m_waitpid_thread;
+  // -----------------------------------------------------------------
+  // Interface used by NativeRegisterContext-derived classes.
+  // -----------------------------------------------------------------
+  static Error PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
+                             void *data = nullptr, size_t data_size = 0,
+                             long *result = nullptr);
 
-            // waitpid reader callback handle.
-            MainLoop::ReadHandleUP m_waitpid_reader_handle;
+  bool SupportHardwareSingleStepping() const;
+
+protected:
+  // -----------------------------------------------------------------
+  // NativeProcessProtocol protected interface
+  // -----------------------------------------------------------------
+  Error
+  GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
+                                  size_t &actual_opcode_size,
+                                  const uint8_t *&trap_opcode_bytes) override;
+
+private:
+  // -----------------------------------------------------------------
+  /// Mach task-related Member Variables
+  // -----------------------------------------------------------------
+
+  // The task port for the inferior process.
+  mutable task_t m_task;
+
+  // True if the inferior process did an exec since we started
+  // monitoring it.
+  bool m_did_exec;
+
+  // The CPU type of this process.
+  mutable cpu_type_t m_cpu_type;
+
+  // -----------------------------------------------------------------
+  /// Exception/Signal Handling Member Variables
+  // -----------------------------------------------------------------
+
+  // Exception port on which we will receive child exceptions
+  mach_port_t m_exception_port;
+
+  // Saved state of the child exception port prior to us installing
+  // our own intercepting port.
+  MachException::PortInfo m_exc_port_info;
+
+  // The thread that runs the Mach exception read and reply handler.
+  pthread_t m_exception_thread;
+
+  // TODO see if we can remove this if we get the exception collection
+  // and distribution to happen in a single-threaded fashion.
+  std::recursive_mutex m_exception_messages_mutex;
+
+  // A collection of exception messages caught when listening to the
+  // exception port.
+  MachException::Message::collection m_exception_messages;
+
+  // When we call MachProcess::Interrupt(), we want to send this
+  // signal (if non-zero).
+  int m_sent_interrupt_signo;
+
+  // If we resume the process and still haven't received our
+  // interrupt signal (if this is non-zero).
+  int m_auto_resume_signo;
+
+  // -----------------------------------------------------------------
+  /// Thread-related Member Variables
+  // -----------------------------------------------------------------
+  NativeThreadListDarwin m_thread_list;
+  ResumeActionList m_thread_actions;
+
+  // -----------------------------------------------------------------
+  /// Process Lifetime Member Variable
+  // -----------------------------------------------------------------
+
+  // The pipe over which the waitpid thread and the main loop will
+  // communicate.
+  Pipe m_waitpid_pipe;
+
+  // The thread that runs the waitpid handler.
+  pthread_t m_waitpid_thread;
+
+  // waitpid reader callback handle.
+  MainLoop::ReadHandleUP m_waitpid_reader_handle;
 
 #if 0
             ArchSpec m_arch;
@@ -249,158 +210,116 @@ namespace lldb_private {
             m_threads_stepping_with_breakpoint;
 #endif
 
-            // -----------------------------------------------------------------
-            // Private Instance Methods
-            // -----------------------------------------------------------------
-            NativeProcessDarwin(lldb::pid_t pid, int pty_master_fd);
+  // -----------------------------------------------------------------
+  // Private Instance Methods
+  // -----------------------------------------------------------------
+  NativeProcessDarwin(lldb::pid_t pid, int pty_master_fd);
 
-            // -----------------------------------------------------------------
-            /// Finalize the launch.
-            ///
-            /// This method associates the NativeProcessDarwin instance with
-            /// the host process that was just launched.  It peforms actions
-            /// like attaching a listener to the inferior exception port,
-            /// ptracing the process, and the like.
-            ///
-            /// @param[in] launch_flavor
-            ///     The launch flavor that was used to launch the process.
-            ///
-            /// @param[in] main_loop
-            ///     The main loop that will run the process monitor.  Work
-            ///     that needs to be done (e.g. reading files) gets registered
-            ///     here along with callbacks to process the work.
-            ///
-            /// @return
-            ///     Any error that occurred during the aforementioned
-            ///     operations.  Failure here will force termination of the
-            ///     launched process and debugging session.
-            // -----------------------------------------------------------------
-            Error
-            FinalizeLaunch(LaunchFlavor launch_flavor, MainLoop &main_loop);
+  // -----------------------------------------------------------------
+  /// Finalize the launch.
+  ///
+  /// This method associates the NativeProcessDarwin instance with
+  /// the host process that was just launched.  It peforms actions
+  /// like attaching a listener to the inferior exception port,
+  /// ptracing the process, and the like.
+  ///
+  /// @param[in] launch_flavor
+  ///     The launch flavor that was used to launch the process.
+  ///
+  /// @param[in] main_loop
+  ///     The main loop that will run the process monitor.  Work
+  ///     that needs to be done (e.g. reading files) gets registered
+  ///     here along with callbacks to process the work.
+  ///
+  /// @return
+  ///     Any error that occurred during the aforementioned
+  ///     operations.  Failure here will force termination of the
+  ///     launched process and debugging session.
+  // -----------------------------------------------------------------
+  Error FinalizeLaunch(LaunchFlavor launch_flavor, MainLoop &main_loop);
 
-            Error
-            SaveExceptionPortInfo();
+  Error SaveExceptionPortInfo();
 
-            void
-            ExceptionMessageReceived(const MachException::Message &message);
+  void ExceptionMessageReceived(const MachException::Message &message);
 
-            void
-            MaybeRaiseThreadPriority();
+  void MaybeRaiseThreadPriority();
 
-            Error
-            StartExceptionThread();
+  Error StartExceptionThread();
 
-            Error
-            SendInferiorExitStatusToMainLoop(::pid_t pid, int status);
+  Error SendInferiorExitStatusToMainLoop(::pid_t pid, int status);
 
-            Error
-            HandleWaitpidResult();
+  Error HandleWaitpidResult();
 
-            bool
-            ProcessUsingSpringBoard() const;
+  bool ProcessUsingSpringBoard() const;
 
-            bool
-            ProcessUsingBackBoard() const;
+  bool ProcessUsingBackBoard() const;
 
-            static void*
-            ExceptionThread(void *arg);
+  static void *ExceptionThread(void *arg);
 
-            void*
-            DoExceptionThread();
+  void *DoExceptionThread();
 
-            lldb::addr_t
-            GetDYLDAllImageInfosAddress(Error &error) const;
+  lldb::addr_t GetDYLDAllImageInfosAddress(Error &error) const;
 
-            static uint32_t
-            GetCPUTypeForLocalProcess(::pid_t pid);
+  static uint32_t GetCPUTypeForLocalProcess(::pid_t pid);
 
-            uint32_t
-            GetCPUType() const;
+  uint32_t GetCPUType() const;
 
-            task_t
-            ExceptionMessageBundleComplete();
+  task_t ExceptionMessageBundleComplete();
 
-            void
-            StartSTDIOThread();
+  void StartSTDIOThread();
 
-            Error
-            StartWaitpidThread(MainLoop &main_loop);
+  Error StartWaitpidThread(MainLoop &main_loop);
 
-            static void*
-            WaitpidThread(void *arg);
+  static void *WaitpidThread(void *arg);
 
-            void*
-            DoWaitpidThread();
+  void *DoWaitpidThread();
 
-            task_t
-            TaskPortForProcessID(Error &error, bool force = false) const;
+  task_t TaskPortForProcessID(Error &error, bool force = false) const;
 
-            /// Attaches to an existing process.  Forms the
-            /// implementation of Process::DoAttach.
-            void
-            AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Error &error);
+  /// Attaches to an existing process.  Forms the
+  /// implementation of Process::DoAttach.
+  void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Error &error);
 
-            ::pid_t
-            Attach(lldb::pid_t pid, Error &error);
+  ::pid_t Attach(lldb::pid_t pid, Error &error);
 
-            Error
-            PrivateResume();
+  Error PrivateResume();
 
-            Error
-            ReplyToAllExceptions();
+  Error ReplyToAllExceptions();
 
-            Error
-            ResumeTask();
+  Error ResumeTask();
 
-            bool
-            IsTaskValid() const;
+  bool IsTaskValid() const;
 
-            bool
-            IsTaskValid(task_t task) const;
+  bool IsTaskValid(task_t task) const;
 
-            mach_port_t
-            GetExceptionPort() const;
+  mach_port_t GetExceptionPort() const;
 
-            bool
-            IsExceptionPortValid () const;
+  bool IsExceptionPortValid() const;
 
-            Error
-            GetTaskBasicInfo(task_t task, struct task_basic_info *info) const;
+  Error GetTaskBasicInfo(task_t task, struct task_basic_info *info) const;
 
-            Error
-            SuspendTask();
+  Error SuspendTask();
 
-            static Error
-            SetDefaultPtraceOpts(const lldb::pid_t);
+  static Error SetDefaultPtraceOpts(const lldb::pid_t);
 
-            static void *
-            MonitorThread(void *baton);
+  static void *MonitorThread(void *baton);
 
-            void
-            MonitorCallback(lldb::pid_t pid, bool exited, int signal,
-                            int status);
+  void MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status);
 
-            void
-            WaitForNewThread(::pid_t tid);
+  void WaitForNewThread(::pid_t tid);
 
-            void
-            MonitorSIGTRAP(const siginfo_t &info, NativeThreadDarwin &thread);
+  void MonitorSIGTRAP(const siginfo_t &info, NativeThreadDarwin &thread);
 
-            void
-            MonitorTrace(NativeThreadDarwin &thread);
+  void MonitorTrace(NativeThreadDarwin &thread);
 
-            void
-            MonitorBreakpoint(NativeThreadDarwin &thread);
+  void MonitorBreakpoint(NativeThreadDarwin &thread);
 
-            void
-            MonitorWatchpoint(NativeThreadDarwin &thread, uint32_t wp_index);
+  void MonitorWatchpoint(NativeThreadDarwin &thread, uint32_t wp_index);
 
-            void
-            MonitorSignal(const siginfo_t &info, NativeThreadDarwin &thread,
-                          bool exited);
+  void MonitorSignal(const siginfo_t &info, NativeThreadDarwin &thread,
+                     bool exited);
 
-            Error
-            SetupSoftwareSingleStepping(NativeThreadDarwin &thread);
+  Error SetupSoftwareSingleStepping(NativeThreadDarwin &thread);
 
 #if 0
             static ::ProcessMessage::CrashReason
@@ -416,64 +335,50 @@ namespace lldb_private {
             GetCrashReasonForSIGBUS(const siginfo_t *info);
 #endif
 
-            bool
-            HasThreadNoLock(lldb::tid_t thread_id);
+  bool HasThreadNoLock(lldb::tid_t thread_id);
+
+  bool StopTrackingThread(lldb::tid_t thread_id);
+
+  NativeThreadDarwinSP AddThread(lldb::tid_t thread_id);
+
+  Error GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
+
+  Error FixupBreakpointPCAsNeeded(NativeThreadDarwin &thread);
+
+  /// Writes a siginfo_t structure corresponding to the given thread
+  /// ID to the memory region pointed to by @p siginfo.
+  Error GetSignalInfo(lldb::tid_t tid, void *siginfo);
+
+  /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
+  /// corresponding to the given thread ID to the memory pointed to
+  /// by @p message.
+  Error GetEventMessage(lldb::tid_t tid, unsigned long *message);
+
+  void NotifyThreadDeath(lldb::tid_t tid);
+
+  Error Detach(lldb::tid_t tid);
+
+  // This method is requests a stop on all threads which are still
+  // running. It sets up a deferred delegate notification, which will
+  // fire once threads report as stopped. The triggerring_tid will be
+  // set as the current thread (main stop reason).
+  void StopRunningThreads(lldb::tid_t triggering_tid);
+
+  // Notify the delegate if all threads have stopped.
+  void SignalIfAllThreadsStopped();
+
+  // Resume the given thread, optionally passing it the given signal.
+  // The type of resume operation (continue, single-step) depends on
+  // the state parameter.
+  Error ResumeThread(NativeThreadDarwin &thread, lldb::StateType state,
+                     int signo);
 
-            bool
-            StopTrackingThread(lldb::tid_t thread_id);
+  void ThreadWasCreated(NativeThreadDarwin &thread);
 
-            NativeThreadDarwinSP
-            AddThread(lldb::tid_t thread_id);
+  void SigchldHandler();
+};
 
-            Error
-            GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
-
-            Error
-            FixupBreakpointPCAsNeeded(NativeThreadDarwin &thread);
-
-            /// Writes a siginfo_t structure corresponding to the given thread
-            /// ID to the memory region pointed to by @p siginfo.
-            Error
-            GetSignalInfo(lldb::tid_t tid, void *siginfo);
-            
-            /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
-            /// corresponding to the given thread ID to the memory pointed to
-            /// by @p message.
-            Error
-            GetEventMessage(lldb::tid_t tid, unsigned long *message);
-            
-            void
-            NotifyThreadDeath(lldb::tid_t tid);
-            
-            Error
-            Detach(lldb::tid_t tid);
-            
-            
-            // This method is requests a stop on all threads which are still
-            // running. It sets up a deferred delegate notification, which will
-            // fire once threads report as stopped. The triggerring_tid will be
-            // set as the current thread (main stop reason).
-            void
-            StopRunningThreads(lldb::tid_t triggering_tid);
-            
-            // Notify the delegate if all threads have stopped.
-            void SignalIfAllThreadsStopped();
-            
-            // Resume the given thread, optionally passing it the given signal.
-            // The type of resume operation (continue, single-step) depends on
-            // the state parameter.
-            Error
-            ResumeThread(NativeThreadDarwin &thread, lldb::StateType state,
-                         int signo);
-            
-            void
-            ThreadWasCreated(NativeThreadDarwin &thread);
-            
-            void
-            SigchldHandler();
-        };
-        
-    } // namespace process_darwin
+} // namespace process_darwin
 } // namespace lldb_private
 
 #endif /* NativeProcessDarwin_h */

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp Tue Sep  6 15:57:50 2016
@@ -21,117 +21,94 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_darwin;
 
-uint64_t
-NativeThreadDarwin::GetGloballyUniqueThreadIDForMachPortID(
-                                                        ::thread_t mach_port_id)
-{
-    thread_identifier_info_data_t tident;
-    mach_msg_type_number_t tident_count = THREAD_IDENTIFIER_INFO_COUNT;
-
-    auto mach_err = ::thread_info(mach_port_id, THREAD_IDENTIFIER_INFO,
-                                  (thread_info_t) &tident, &tident_count);
-    if (mach_err != KERN_SUCCESS)
-    {
-        // When we fail to get thread info for the supposed port, assume it is
-        // really a globally unique thread id already, or return the best thing
-        // we can, which is the thread port.
-        return mach_port_id;
-    }
-    return tident.thread_id;
+uint64_t NativeThreadDarwin::GetGloballyUniqueThreadIDForMachPortID(
+    ::thread_t mach_port_id) {
+  thread_identifier_info_data_t tident;
+  mach_msg_type_number_t tident_count = THREAD_IDENTIFIER_INFO_COUNT;
+
+  auto mach_err = ::thread_info(mach_port_id, THREAD_IDENTIFIER_INFO,
+                                (thread_info_t)&tident, &tident_count);
+  if (mach_err != KERN_SUCCESS) {
+    // When we fail to get thread info for the supposed port, assume it is
+    // really a globally unique thread id already, or return the best thing
+    // we can, which is the thread port.
+    return mach_port_id;
+  }
+  return tident.thread_id;
 }
 
 NativeThreadDarwin::NativeThreadDarwin(NativeProcessDarwin *process,
                                        bool is_64_bit,
                                        lldb::tid_t unique_thread_id,
-                                       ::thread_t mach_thread_port) :
-    NativeThreadProtocol(process, unique_thread_id),
-    m_mach_thread_port(mach_thread_port),
-    m_basic_info(),
-    m_proc_threadinfo()
-{
-}
-
-bool
-NativeThreadDarwin::GetIdentifierInfo()
-{
-    // Don't try to get the thread info once and cache it for the life of the thread.  It changes over time, for instance
-    // if the thread name changes, then the thread_handle also changes...  So you have to refetch it every time.
-    mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
-    kern_return_t kret = ::thread_info(m_mach_thread_port,
-                                       THREAD_IDENTIFIER_INFO,
-                                       (thread_info_t) &m_ident_info, &count);
-    return kret == KERN_SUCCESS;
+                                       ::thread_t mach_thread_port)
+    : NativeThreadProtocol(process, unique_thread_id),
+      m_mach_thread_port(mach_thread_port), m_basic_info(),
+      m_proc_threadinfo() {}
+
+bool NativeThreadDarwin::GetIdentifierInfo() {
+  // Don't try to get the thread info once and cache it for the life of the
+  // thread.  It changes over time, for instance
+  // if the thread name changes, then the thread_handle also changes...  So you
+  // have to refetch it every time.
+  mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
+  kern_return_t kret = ::thread_info(m_mach_thread_port, THREAD_IDENTIFIER_INFO,
+                                     (thread_info_t)&m_ident_info, &count);
+  return kret == KERN_SUCCESS;
+
+  return false;
+}
+
+std::string NativeThreadDarwin::GetName() {
+  std::string name;
+
+  if (GetIdentifierInfo()) {
+    auto process_sp = GetProcess();
+    if (!process_sp) {
+      name = "<unavailable>";
+      return name;
+    }
 
-    return false;
-}
+    int len = ::proc_pidinfo(process_sp->GetID(), PROC_PIDTHREADINFO,
+                             m_ident_info.thread_handle, &m_proc_threadinfo,
+                             sizeof(m_proc_threadinfo));
 
-std::string
-NativeThreadDarwin::GetName()
-{
-    std::string name;
+    if (len && m_proc_threadinfo.pth_name[0])
+      name = m_proc_threadinfo.pth_name;
+  }
+  return name;
+}
 
-    if (GetIdentifierInfo())
-    {
-        auto process_sp = GetProcess();
-        if (!process_sp)
-        {
-            name = "<unavailable>";
-            return name;
-        }
+lldb::StateType NativeThreadDarwin::GetState() {
+  // TODO implement
+  return eStateInvalid;
+}
 
-        int len = ::proc_pidinfo(process_sp->GetID(), PROC_PIDTHREADINFO,
-                                 m_ident_info.thread_handle, &m_proc_threadinfo,
-                                 sizeof(m_proc_threadinfo));
+bool NativeThreadDarwin::GetStopReason(ThreadStopInfo &stop_info,
+                                       std::string &description) {
+  // TODO implement
+  return false;
+}
 
-        if (len && m_proc_threadinfo.pth_name[0])
-            name = m_proc_threadinfo.pth_name;
-    }
-    return name;
+NativeRegisterContextSP NativeThreadDarwin::GetRegisterContext() {
+  // TODO implement
+  return NativeRegisterContextSP();
 }
 
-lldb::StateType
-NativeThreadDarwin::GetState()
-{
-    // TODO implement
-    return eStateInvalid;
+Error NativeThreadDarwin::SetWatchpoint(lldb::addr_t addr, size_t size,
+                                        uint32_t watch_flags, bool hardware) {
+  Error error;
+  error.SetErrorString("not yet implemented");
+  return error;
 }
 
-bool
-NativeThreadDarwin::GetStopReason(ThreadStopInfo &stop_info,
-                                  std::string& description)
-{
-    // TODO implement
-    return false;
+Error NativeThreadDarwin::RemoveWatchpoint(lldb::addr_t addr) {
+  Error error;
+  error.SetErrorString("not yet implemented");
+  return error;
 }
 
-NativeRegisterContextSP
-NativeThreadDarwin::GetRegisterContext()
-{
-    // TODO implement
-    return NativeRegisterContextSP();
-}
-
-Error
-NativeThreadDarwin::SetWatchpoint(lldb::addr_t addr, size_t size,
-                                  uint32_t watch_flags, bool hardware)
-{
-    Error error;
-    error.SetErrorString("not yet implemented");
-    return error;
-}
-
-Error
-NativeThreadDarwin::RemoveWatchpoint(lldb::addr_t addr)
-{
-    Error error;
-    error.SetErrorString("not yet implemented");
-    return error;
-}
-
-void
-NativeThreadDarwin::Dump(Stream &stream) const
-{
-    // This is what we really want once we have the thread class wired up.
+void NativeThreadDarwin::Dump(Stream &stream) const {
+// This is what we really want once we have the thread class wired up.
 #if 0
     DNBLogThreaded("[%3u] #%3u tid: 0x%8.8" PRIx64 ", pc: 0x%16.16" PRIx64 ", sp: 0x%16.16" PRIx64 ", user: %d.%6.6d, system: %d.%6.6d, cpu: %2d, policy: %2d, run_state: %2d (%s), flags: %2d, suspend_count: %2d (current %2d), sleep_time: %d",
                    index,
@@ -150,16 +127,14 @@ NativeThreadDarwin::Dump(Stream &stream)
                    m_basic_info.sleep_time);
 
 #else
-    // Here's all we have right now.
-    stream.Printf("tid: 0x%8.8" PRIx64 ", thread port: 0x%4.4x",
-                  GetID(), m_mach_thread_port);
+  // Here's all we have right now.
+  stream.Printf("tid: 0x%8.8" PRIx64 ", thread port: 0x%4.4x", GetID(),
+                m_mach_thread_port);
 #endif
 }
 
-bool
-NativeThreadDarwin::NotifyException(MachException::Data &exc)
-{
-    // TODO implement this.
+bool NativeThreadDarwin::NotifyException(MachException::Data &exc) {
+// TODO implement this.
 #if 0
     // Allow the arch specific protocol to process (MachException::Data &)exc
     // first before possible reassignment of m_stop_exception with exc.
@@ -182,15 +157,13 @@ NativeThreadDarwin::NotifyException(Mach
 
     return handled;
 #else
-    // Pretend we handled it.
-    return true;
+  // Pretend we handled it.
+  return true;
 #endif
 }
 
-bool
-NativeThreadDarwin::ShouldStop(bool &step_more) const
-{
-    // TODO: implement this
+bool NativeThreadDarwin::ShouldStop(bool &step_more) const {
+// TODO: implement this
 #if 0
     // See if this thread is at a breakpoint?
     DNBBreakpoint *bp = CurrentBreakpoint();
@@ -229,14 +202,12 @@ NativeThreadDarwin::ShouldStop(bool &ste
     }
     return false;
 #else
-    return false;
+  return false;
 #endif
 }
 
-void
-NativeThreadDarwin::ThreadDidStop()
-{
-    // TODO implement this.
+void NativeThreadDarwin::ThreadDidStop() {
+// TODO implement this.
 #if 0
     // This thread has existed prior to resuming under debug nub control,
     // and has just been stopped. Do any cleanup that needs to be done
@@ -267,58 +238,47 @@ NativeThreadDarwin::ThreadDidStop()
 #endif
 }
 
-bool
-NativeThreadDarwin::MachPortNumberIsValid(::thread_t thread)
-{
-    return thread != (::thread_t)(0);
-}
-
-const struct thread_basic_info *
-NativeThreadDarwin::GetBasicInfo() const
-{
-    if (GetBasicInfo(m_mach_thread_port, &m_basic_info))
-        return &m_basic_info;
-    return NULL;
-}
-
-bool
-NativeThreadDarwin::GetBasicInfo(::thread_t thread,
-                                 struct thread_basic_info *basicInfoPtr)
-{
-    if (MachPortNumberIsValid(thread))
-    {
-        unsigned int info_count = THREAD_BASIC_INFO_COUNT;
-        kern_return_t err = ::thread_info (thread, THREAD_BASIC_INFO, (thread_info_t) basicInfoPtr, &info_count);
-        if (err == KERN_SUCCESS)
-            return true;
-    }
-    ::memset (basicInfoPtr, 0, sizeof (struct thread_basic_info));
-    return false;
+bool NativeThreadDarwin::MachPortNumberIsValid(::thread_t thread) {
+  return thread != (::thread_t)(0);
 }
 
-bool
-NativeThreadDarwin::IsUserReady() const
-{
-    if (m_basic_info.run_state == 0)
-        GetBasicInfo();
-
-    switch (m_basic_info.run_state)
-    {
-        default:
-        case TH_STATE_UNINTERRUPTIBLE:
-            break;
-
-        case TH_STATE_RUNNING:
-        case TH_STATE_STOPPED:
-        case TH_STATE_WAITING:
-        case TH_STATE_HALTED:
-            return true;
-    }
-    return false;
+const struct thread_basic_info *NativeThreadDarwin::GetBasicInfo() const {
+  if (GetBasicInfo(m_mach_thread_port, &m_basic_info))
+    return &m_basic_info;
+  return NULL;
+}
+
+bool NativeThreadDarwin::GetBasicInfo(::thread_t thread,
+                                      struct thread_basic_info *basicInfoPtr) {
+  if (MachPortNumberIsValid(thread)) {
+    unsigned int info_count = THREAD_BASIC_INFO_COUNT;
+    kern_return_t err = ::thread_info(thread, THREAD_BASIC_INFO,
+                                      (thread_info_t)basicInfoPtr, &info_count);
+    if (err == KERN_SUCCESS)
+      return true;
+  }
+  ::memset(basicInfoPtr, 0, sizeof(struct thread_basic_info));
+  return false;
+}
+
+bool NativeThreadDarwin::IsUserReady() const {
+  if (m_basic_info.run_state == 0)
+    GetBasicInfo();
+
+  switch (m_basic_info.run_state) {
+  default:
+  case TH_STATE_UNINTERRUPTIBLE:
+    break;
+
+  case TH_STATE_RUNNING:
+  case TH_STATE_STOPPED:
+  case TH_STATE_WAITING:
+  case TH_STATE_HALTED:
+    return true;
+  }
+  return false;
 }
 
-NativeProcessDarwinSP
-NativeThreadDarwin::GetNativeProcessDarwinSP()
-{
-    return std::static_pointer_cast<NativeProcessDarwin>(GetProcess());
+NativeProcessDarwinSP NativeThreadDarwin::GetNativeProcessDarwinSP() {
+  return std::static_pointer_cast<NativeProcessDarwin>(GetProcess());
 }

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeThreadDarwin.h Tue Sep  6 15:57:50 2016
@@ -21,8 +21,8 @@
 #include <string>
 
 // LLDB includes
-#include "lldb/lldb-private-forward.h"
 #include "lldb/Host/common/NativeThreadProtocol.h"
+#include "lldb/lldb-private-forward.h"
 
 #include "MachException.h"
 
@@ -34,168 +34,130 @@ using NativeProcessDarwinSP = std::share
 
 class NativeThreadListDarwin;
 
-class NativeThreadDarwin : public NativeThreadProtocol
-{
-    friend class NativeProcessDarwin;
-    friend class NativeThreadListDarwin;
+class NativeThreadDarwin : public NativeThreadProtocol {
+  friend class NativeProcessDarwin;
+  friend class NativeThreadListDarwin;
 
 public:
+  static uint64_t
+  GetGloballyUniqueThreadIDForMachPortID(::thread_t mach_port_id);
+
+  NativeThreadDarwin(NativeProcessDarwin *process, bool is_64_bit,
+                     lldb::tid_t unique_thread_id = 0,
+                     ::thread_t mach_thread_port = 0);
+
+  // -----------------------------------------------------------------
+  // NativeThreadProtocol Interface
+  // -----------------------------------------------------------------
+  std::string GetName() override;
+
+  lldb::StateType GetState() override;
+
+  bool GetStopReason(ThreadStopInfo &stop_info,
+                     std::string &description) override;
+
+  NativeRegisterContextSP GetRegisterContext() override;
+
+  Error SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
+                      bool hardware) override;
 
-    static uint64_t
-    GetGloballyUniqueThreadIDForMachPortID(::thread_t mach_port_id);
+  Error RemoveWatchpoint(lldb::addr_t addr) override;
 
-    NativeThreadDarwin(NativeProcessDarwin *process, bool is_64_bit,
-                       lldb::tid_t unique_thread_id = 0,
-                       ::thread_t mach_thread_port = 0);
-
-    // -----------------------------------------------------------------
-    // NativeThreadProtocol Interface
-    // -----------------------------------------------------------------
-    std::string
-    GetName() override;
-
-    lldb::StateType
-    GetState () override;
-
-    bool
-    GetStopReason(ThreadStopInfo &stop_info,
-                  std::string& description) override;
-
-    NativeRegisterContextSP
-    GetRegisterContext() override;
-
-    Error
-    SetWatchpoint(lldb::addr_t addr, size_t size,
-                  uint32_t watch_flags, bool hardware) override;
-
-    Error
-    RemoveWatchpoint(lldb::addr_t addr) override;
-
-    // -----------------------------------------------------------------
-    // New methods that are fine for others to call.
-    // -----------------------------------------------------------------
-    void
-    Dump(Stream &stream) const;
+  // -----------------------------------------------------------------
+  // New methods that are fine for others to call.
+  // -----------------------------------------------------------------
+  void Dump(Stream &stream) const;
 
 private:
-    // -----------------------------------------------------------------
-    // Interface for friend classes
-    // -----------------------------------------------------------------
+  // -----------------------------------------------------------------
+  // Interface for friend classes
+  // -----------------------------------------------------------------
 
-    /// Resumes the thread.  If @p signo is anything but
-    /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
-    Error
-    Resume(uint32_t signo);
+  /// Resumes the thread.  If @p signo is anything but
+  /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
+  Error Resume(uint32_t signo);
 
-    /// Single steps the thread.  If @p signo is anything but
-    /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
-    Error
-    SingleStep(uint32_t signo);
+  /// Single steps the thread.  If @p signo is anything but
+  /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
+  Error SingleStep(uint32_t signo);
 
-    bool
-    NotifyException(MachException::Data &exc);
+  bool NotifyException(MachException::Data &exc);
 
-    bool
-    ShouldStop(bool &step_more) const;
+  bool ShouldStop(bool &step_more) const;
 
-    void
-    ThreadDidStop();
+  void ThreadDidStop();
 
-    void
-    SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
+  void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
 
-    /// Return true if the thread is stopped.
-    /// If stopped by a signal, indicate the signo in the signo
-    /// argument.  Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
-    bool
-    IsStopped (int *signo);
+  /// Return true if the thread is stopped.
+  /// If stopped by a signal, indicate the signo in the signo
+  /// argument.  Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
+  bool IsStopped(int *signo);
 
-    const struct thread_basic_info *
-    GetBasicInfo() const;
+  const struct thread_basic_info *GetBasicInfo() const;
 
-    static bool
-    GetBasicInfo(::thread_t thread, struct thread_basic_info *basicInfoPtr);
+  static bool GetBasicInfo(::thread_t thread,
+                           struct thread_basic_info *basicInfoPtr);
 
-    bool
-    IsUserReady() const;
+  bool IsUserReady() const;
 
-    void
-    SetStoppedByExec ();
+  void SetStoppedByExec();
 
-    void
-    SetStoppedByBreakpoint ();
+  void SetStoppedByBreakpoint();
 
-    void
-    SetStoppedByWatchpoint (uint32_t wp_index);
+  void SetStoppedByWatchpoint(uint32_t wp_index);
 
-    bool
-    IsStoppedAtBreakpoint ();
+  bool IsStoppedAtBreakpoint();
 
-    bool
-    IsStoppedAtWatchpoint ();
+  bool IsStoppedAtWatchpoint();
 
-    void
-    SetStoppedByTrace ();
+  void SetStoppedByTrace();
 
-    void
-    SetStoppedWithNoReason ();
+  void SetStoppedWithNoReason();
 
-    void
-    SetExited ();
+  void SetExited();
 
-    Error
-    RequestStop ();
+  Error RequestStop();
 
-    // -------------------------------------------------------------------------
-    /// Return the mach thread port number for this thread.
-    ///
-    /// @return
-    ///     The mach port number for this thread.  Returns NULL_THREAD
-    ///     when the thread is invalid.
-    // -------------------------------------------------------------------------
-    thread_t
-    GetMachPortNumber() const
-    {
-        return m_mach_thread_port;
-    }
+  // -------------------------------------------------------------------------
+  /// Return the mach thread port number for this thread.
+  ///
+  /// @return
+  ///     The mach port number for this thread.  Returns NULL_THREAD
+  ///     when the thread is invalid.
+  // -------------------------------------------------------------------------
+  thread_t GetMachPortNumber() const { return m_mach_thread_port; }
 
-    static bool
-    MachPortNumberIsValid(::thread_t thread);
+  static bool MachPortNumberIsValid(::thread_t thread);
 
-    // ---------------------------------------------------------------------
-    // Private interface
-    // ---------------------------------------------------------------------
-    bool
-    GetIdentifierInfo();
+  // ---------------------------------------------------------------------
+  // Private interface
+  // ---------------------------------------------------------------------
+  bool GetIdentifierInfo();
 
-    void
-    MaybeLogStateChange (lldb::StateType new_state);
+  void MaybeLogStateChange(lldb::StateType new_state);
 
-    NativeProcessDarwinSP
-    GetNativeProcessDarwinSP();
+  NativeProcessDarwinSP GetNativeProcessDarwinSP();
 
-    void
-    SetStopped();
+  void SetStopped();
 
-    inline void
-    MaybePrepareSingleStepWorkaround();
+  inline void MaybePrepareSingleStepWorkaround();
 
-    inline void
-    MaybeCleanupSingleStepWorkaround();
+  inline void MaybeCleanupSingleStepWorkaround();
 
-    // -----------------------------------------------------------------
-    // Member Variables
-    // -----------------------------------------------------------------
+  // -----------------------------------------------------------------
+  // Member Variables
+  // -----------------------------------------------------------------
 
-    // The mach thread port for the thread.
-    ::thread_t  m_mach_thread_port;
+  // The mach thread port for the thread.
+  ::thread_t m_mach_thread_port;
 
-    // The most recently-retrieved thread basic info.
-    mutable ::thread_basic_info m_basic_info;
+  // The most recently-retrieved thread basic info.
+  mutable ::thread_basic_info m_basic_info;
 
-    struct proc_threadinfo  m_proc_threadinfo;
+  struct proc_threadinfo m_proc_threadinfo;
 
-    thread_identifier_info_data_t   m_ident_info;
+  thread_identifier_info_data_t m_ident_info;
 
 #if 0
     lldb::StateType m_state;

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- NativeThreadListDarwin.cpp ------------------------------------*- C++ -*-===//
+//===-- NativeThreadListDarwin.cpp ------------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -31,16 +32,10 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_darwin;
 
-NativeThreadListDarwin::NativeThreadListDarwin() :
-    m_threads(),
-    m_threads_mutex(),
-    m_is_64_bit(false)
-{
-}
+NativeThreadListDarwin::NativeThreadListDarwin()
+    : m_threads(), m_threads_mutex(), m_is_64_bit(false) {}
 
-NativeThreadListDarwin::~NativeThreadListDarwin()
-{
-}
+NativeThreadListDarwin::~NativeThreadListDarwin() {}
 
 // These methods will be accessed directly from NativeThreadDarwin
 #if 0
@@ -155,41 +150,33 @@ NativeThreadListDarwin::GetThreadInfo (n
 #endif
 
 NativeThreadDarwinSP
-NativeThreadListDarwin::GetThreadByID(lldb::tid_t tid) const
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    for (auto thread_sp : m_threads)
-    {
-        if (thread_sp && (thread_sp->GetID() == tid))
-            return thread_sp;
-    }
-    return NativeThreadDarwinSP();
-}
-
-NativeThreadDarwinSP
-NativeThreadListDarwin::GetThreadByMachPortNumber(::thread_t mach_port_number)
-    const
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    for (auto thread_sp : m_threads)
-    {
-        if (thread_sp && (thread_sp->GetMachPortNumber() == mach_port_number))
-            return thread_sp;
-    }
-    return NativeThreadDarwinSP();
-}
-
-lldb::tid_t
-NativeThreadListDarwin::GetThreadIDByMachPortNumber(::thread_t mach_port_number)
-    const
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    for (auto thread_sp : m_threads)
-    {
-        if (thread_sp && (thread_sp->GetMachPortNumber() == mach_port_number))
-            return thread_sp->GetID();
-    }
-    return LLDB_INVALID_THREAD_ID;
+NativeThreadListDarwin::GetThreadByID(lldb::tid_t tid) const {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  for (auto thread_sp : m_threads) {
+    if (thread_sp && (thread_sp->GetID() == tid))
+      return thread_sp;
+  }
+  return NativeThreadDarwinSP();
+}
+
+NativeThreadDarwinSP NativeThreadListDarwin::GetThreadByMachPortNumber(
+    ::thread_t mach_port_number) const {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  for (auto thread_sp : m_threads) {
+    if (thread_sp && (thread_sp->GetMachPortNumber() == mach_port_number))
+      return thread_sp;
+  }
+  return NativeThreadDarwinSP();
+}
+
+lldb::tid_t NativeThreadListDarwin::GetThreadIDByMachPortNumber(
+    ::thread_t mach_port_number) const {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  for (auto thread_sp : m_threads) {
+    if (thread_sp && (thread_sp->GetMachPortNumber() == mach_port_number))
+      return thread_sp->GetID();
+  }
+  return LLDB_INVALID_THREAD_ID;
 }
 
 // TODO implement
@@ -267,11 +254,9 @@ NativeThreadListDarwin::RestoreRegisterS
 }
 #endif
 
-size_t
-NativeThreadListDarwin::GetNumberOfThreads() const
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    return static_cast<size_t>(m_threads.size());
+size_t NativeThreadListDarwin::GetNumberOfThreads() const {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  return static_cast<size_t>(m_threads.size());
 }
 
 // TODO implement
@@ -297,149 +282,129 @@ NativeThreadListDarwin::CurrentThreadID
 
 #endif
 
-bool
-NativeThreadListDarwin::NotifyException(MachException::Data &exc)
-{
-    auto thread_sp = GetThreadByMachPortNumber(exc.thread_port);
-    if (thread_sp)
-    {
-        thread_sp->NotifyException(exc);
-        return true;
+bool NativeThreadListDarwin::NotifyException(MachException::Data &exc) {
+  auto thread_sp = GetThreadByMachPortNumber(exc.thread_port);
+  if (thread_sp) {
+    thread_sp->NotifyException(exc);
+    return true;
+  }
+  return false;
+}
+
+void NativeThreadListDarwin::Clear() {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  m_threads.clear();
+}
+
+uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process,
+                                                  bool update,
+                                                  collection *new_threads) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
+
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  if (log)
+    log->Printf("NativeThreadListDarwin::%s() (pid = %" PRIu64 ", update = "
+                "%u) process stop count = %u",
+                __FUNCTION__, process.GetID(), update, process.GetStopID());
+
+  if (process.GetStopID() == 0) {
+    // On our first stop, we'll record details like 32/64 bitness and
+    // select the proper architecture implementation.
+    //
+    int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)process.GetID()};
+
+    struct kinfo_proc processInfo;
+    size_t bufsize = sizeof(processInfo);
+    if ((sysctl(mib, (unsigned)(sizeof(mib) / sizeof(int)), &processInfo,
+                &bufsize, NULL, 0) == 0) &&
+        (bufsize > 0)) {
+      if (processInfo.kp_proc.p_flag & P_LP64)
+        m_is_64_bit = true;
     }
-    return false;
-}
-
-void
-NativeThreadListDarwin::Clear()
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    m_threads.clear();
-}
-
-uint32_t
-NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process,
-                                         bool update,
-                                         collection *new_threads)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
-
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    if (log)
-        log->Printf("NativeThreadListDarwin::%s() (pid = %" PRIu64 ", update = "
-                    "%u) process stop count = %u", __FUNCTION__,
-                    process.GetID(), update, process.GetStopID());
-
-    if (process.GetStopID() == 0)
-    {
-        // On our first stop, we'll record details like 32/64 bitness and
-        // select the proper architecture implementation.
-        //
-        int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID,
-            (int)process.GetID() };
-
-        struct kinfo_proc processInfo;
-        size_t bufsize = sizeof(processInfo);
-        if ((sysctl(mib, (unsigned)(sizeof(mib)/sizeof(int)), &processInfo,
-                    &bufsize, NULL, 0) == 0) && (bufsize > 0))
-        {
-            if (processInfo.kp_proc.p_flag & P_LP64)
-                m_is_64_bit = true;
-        }
 
 // TODO implement architecture selection and abstraction.
 #if 0
-#if defined (__i386__) || defined (__x86_64__)
+#if defined(__i386__) || defined(__x86_64__)
         if (m_is_64_bit)
             DNBArchProtocol::SetArchitecture(CPU_TYPE_X86_64);
         else
             DNBArchProtocol::SetArchitecture(CPU_TYPE_I386);
-#elif defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
+#elif defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
         if (m_is_64_bit)
             DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64);
         else
             DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM);
 #endif
 #endif
-    }
-    
-    if (m_threads.empty() || update)
-    {
-        thread_array_t thread_list = nullptr;
-        mach_msg_type_number_t thread_list_count = 0;
-        task_t task = process.GetTask();
-
-        Error error;
-        auto mach_err = ::task_threads(task, &thread_list, &thread_list_count);
-        error.SetError(mach_err, eErrorTypeMachKernel);
-        if (error.Fail())
-        {
-            if (log)
-                log->Printf("::task_threads(task = 0x%4.4x, thread_list => %p, "
-                            "thread_list_count => %u) failed: %u (%s)", task,
-                            thread_list, thread_list_count, error.GetError(),
-                            error.AsCString());
-            return 0;
-        }
+  }
 
-        if (thread_list_count > 0)
-        {
-            collection currThreads;
-            size_t idx;
-            // Iterator through the current thread list and see which threads
-            // we already have in our list (keep them), which ones we don't
-            // (add them), and which ones are not around anymore (remove them).
-            for (idx = 0; idx < thread_list_count; ++idx)
-            {
-                // Get the Mach thread port.
-                const ::thread_t mach_port_num = thread_list[idx];
+  if (m_threads.empty() || update) {
+    thread_array_t thread_list = nullptr;
+    mach_msg_type_number_t thread_list_count = 0;
+    task_t task = process.GetTask();
+
+    Error error;
+    auto mach_err = ::task_threads(task, &thread_list, &thread_list_count);
+    error.SetError(mach_err, eErrorTypeMachKernel);
+    if (error.Fail()) {
+      if (log)
+        log->Printf("::task_threads(task = 0x%4.4x, thread_list => %p, "
+                    "thread_list_count => %u) failed: %u (%s)",
+                    task, thread_list, thread_list_count, error.GetError(),
+                    error.AsCString());
+      return 0;
+    }
+
+    if (thread_list_count > 0) {
+      collection currThreads;
+      size_t idx;
+      // Iterator through the current thread list and see which threads
+      // we already have in our list (keep them), which ones we don't
+      // (add them), and which ones are not around anymore (remove them).
+      for (idx = 0; idx < thread_list_count; ++idx) {
+        // Get the Mach thread port.
+        const ::thread_t mach_port_num = thread_list[idx];
+
+        // Get the unique thread id for the mach port number.
+        uint64_t unique_thread_id =
+            NativeThreadDarwin::GetGloballyUniqueThreadIDForMachPortID(
+                mach_port_num);
+
+        // Retrieve the thread if it exists.
+        auto thread_sp = GetThreadByID(unique_thread_id);
+        if (thread_sp) {
+          // We are already tracking it. Keep the existing native
+          // thread instance.
+          currThreads.push_back(thread_sp);
+        } else {
+          // We don't have a native thread instance for this thread.
+          // Create it now.
+          thread_sp.reset(new NativeThreadDarwin(
+              &process, m_is_64_bit, unique_thread_id, mach_port_num));
+
+          // Add the new thread regardless of its is user ready state.
+          // Make sure the thread is ready to be displayed and shown
+          // to users before we add this thread to our list...
+          if (thread_sp->IsUserReady()) {
+            if (new_threads)
+              new_threads->push_back(thread_sp);
 
-                // Get the unique thread id for the mach port number.
-                uint64_t unique_thread_id =
-                    NativeThreadDarwin::
-                    GetGloballyUniqueThreadIDForMachPortID(mach_port_num);
-
-                // Retrieve the thread if it exists.
-                auto thread_sp = GetThreadByID(unique_thread_id);
-                if (thread_sp)
-                {
-                    // We are already tracking it. Keep the existing native
-                    // thread instance.
-                    currThreads.push_back(thread_sp);
-                }
-                else
-                {
-                    // We don't have a native thread instance for this thread.
-                    // Create it now.
-                    thread_sp.reset(new NativeThreadDarwin(&process,
-                                                           m_is_64_bit,
-                                                           unique_thread_id,
-                                                           mach_port_num));
-
-                    // Add the new thread regardless of its is user ready state.
-                    // Make sure the thread is ready to be displayed and shown
-                    // to users before we add this thread to our list...
-                    if (thread_sp->IsUserReady())
-                    {
-                        if (new_threads)
-                            new_threads->push_back(thread_sp);
-                    
-                        currThreads.push_back(thread_sp);
-                    }
-                }
-            }
+            currThreads.push_back(thread_sp);
+          }
+        }
+      }
 
-            m_threads.swap(currThreads);
-            m_current_thread.reset();
+      m_threads.swap(currThreads);
+      m_current_thread.reset();
 
-            // Free the vm memory given to us by ::task_threads()
-            vm_size_t thread_list_size = (vm_size_t) (thread_list_count *
-                                                      sizeof (::thread_t));
-            ::vm_deallocate(::mach_task_self(),
-                            (vm_address_t)thread_list,
-                            thread_list_size);
-        }
+      // Free the vm memory given to us by ::task_threads()
+      vm_size_t thread_list_size =
+          (vm_size_t)(thread_list_count * sizeof(::thread_t));
+      ::vm_deallocate(::mach_task_self(), (vm_address_t)thread_list,
+                      thread_list_size);
     }
-    return static_cast<uint32_t>(m_threads.size());
+  }
+  return static_cast<uint32_t>(m_threads.size());
 }
 
 // TODO implement
@@ -470,37 +435,31 @@ NativeThreadListDarwin::CurrentThread (M
 
 #endif
 
-void
-NativeThreadListDarwin::Dump(Stream &stream) const
-{
-    bool first = true;
+void NativeThreadListDarwin::Dump(Stream &stream) const {
+  bool first = true;
 
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    for (auto thread_sp : m_threads)
-    {
-        if (thread_sp)
-        {
-            // Handle newlines between thread entries.
-            if (first)
-                first = false;
-            else
-                stream.PutChar('\n');
-            thread_sp->Dump(stream);
-        }
-    }
-}
-
-void
-NativeThreadListDarwin::ProcessWillResume(NativeProcessDarwin &process,
-                                    const ResumeActionList &thread_actions)
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-
-    // Update our thread list, because sometimes libdispatch or the kernel
-    // will spawn threads while a task is suspended.
-    NativeThreadListDarwin::collection new_threads;
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  for (auto thread_sp : m_threads) {
+    if (thread_sp) {
+      // Handle newlines between thread entries.
+      if (first)
+        first = false;
+      else
+        stream.PutChar('\n');
+      thread_sp->Dump(stream);
+    }
+  }
+}
+
+void NativeThreadListDarwin::ProcessWillResume(
+    NativeProcessDarwin &process, const ResumeActionList &thread_actions) {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+
+  // Update our thread list, because sometimes libdispatch or the kernel
+  // will spawn threads while a task is suspended.
+  NativeThreadListDarwin::collection new_threads;
 
-    // TODO implement this.
+// TODO implement this.
 #if 0
     // First figure out if we were planning on running only one thread, and if
     // so, force that thread to resume.
@@ -526,7 +485,7 @@ NativeThreadListDarwin::ProcessWillResum
         run_one_thread = false;
 #endif
 
-    UpdateThreadList(process, true, &new_threads);
+  UpdateThreadList(process, true, &new_threads);
 
 #if 0
     DNBThreadResumeAction resume_new_threads = { -1U, eStateRunning, 0, INVALID_NUB_ADDRESS };
@@ -576,20 +535,17 @@ NativeThreadListDarwin::ProcessWillResum
 #endif
 }
 
-uint32_t
-NativeThreadListDarwin::ProcessDidStop(NativeProcessDarwin &process)
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+uint32_t NativeThreadListDarwin::ProcessDidStop(NativeProcessDarwin &process) {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
 
-    // Update our thread list.
-    UpdateThreadList(process, true);
+  // Update our thread list.
+  UpdateThreadList(process, true);
 
-    for (auto thread_sp : m_threads)
-    {
-        if (thread_sp)
-            thread_sp->ThreadDidStop();
-    }
-    return (uint32_t)m_threads.size();
+  for (auto thread_sp : m_threads) {
+    if (thread_sp)
+      thread_sp->ThreadDidStop();
+  }
+  return (uint32_t)m_threads.size();
 }
 
 //----------------------------------------------------------------------
@@ -603,16 +559,13 @@ NativeThreadListDarwin::ProcessDidStop(N
 //    true if we should stop and notify our clients
 //    false if we should resume our child process and skip notification
 //----------------------------------------------------------------------
-bool
-NativeThreadListDarwin::ShouldStop(bool &step_more)
-{
-    std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
-    for (auto thread_sp : m_threads)
-    {
-        if (thread_sp && thread_sp->ShouldStop(step_more))
-            return true;
-    }
-    return false;
+bool NativeThreadListDarwin::ShouldStop(bool &step_more) {
+  std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
+  for (auto thread_sp : m_threads) {
+    if (thread_sp && thread_sp->ShouldStop(step_more))
+      return true;
+  }
+  return false;
 }
 
 // Implement.

Modified: lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.h (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/NativeThreadListDarwin.h Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- NativeThreadListDarwin.h --------------------------------------*- C++ -*-===//
+//===-- NativeThreadListDarwin.h --------------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -34,19 +35,16 @@ class NativeProcessDarwin;
 class NativeThreadDarwin;
 using NativeThreadDarwinSP = std::shared_ptr<NativeThreadDarwin>;
 
-class NativeThreadListDarwin
-{
+class NativeThreadListDarwin {
 public:
-    NativeThreadListDarwin();
-    ~NativeThreadListDarwin();
+  NativeThreadListDarwin();
+  ~NativeThreadListDarwin();
 
-    void
-    Clear();
+  void Clear();
 
-    void
-    Dump(Stream &stream) const;
+  void Dump(Stream &stream) const;
 
-    // These methods will be accessed directly from NativeThreadDarwin
+// These methods will be accessed directly from NativeThreadDarwin
 #if 0
     bool            GetRegisterValue (nub_thread_t tid, uint32_t set, uint32_t reg, DNBRegisterValue *reg_value) const;
     bool            SetRegisterValue (nub_thread_t tid, uint32_t set, uint32_t reg, const DNBRegisterValue *reg_value) const;
@@ -56,30 +54,25 @@ public:
     bool            RestoreRegisterState (nub_thread_t tid, uint32_t save_id);
 #endif
 
-    const char *
-    GetThreadInfo(lldb::tid_t tid) const;
+  const char *GetThreadInfo(lldb::tid_t tid) const;
 
-    void
-    ProcessWillResume(NativeProcessDarwin &process,
-                      const ResumeActionList &thread_actions);
+  void ProcessWillResume(NativeProcessDarwin &process,
+                         const ResumeActionList &thread_actions);
 
-    uint32_t
-    ProcessDidStop(NativeProcessDarwin &process);
+  uint32_t ProcessDidStop(NativeProcessDarwin &process);
 
-    bool
-    NotifyException(MachException::Data& exc);
+  bool NotifyException(MachException::Data &exc);
 
-    bool
-    ShouldStop(bool &step_more);
+  bool ShouldStop(bool &step_more);
 
-    // These methods will be accessed directly from NativeThreadDarwin
+// These methods will be accessed directly from NativeThreadDarwin
 #if 0
     const char *    GetName (nub_thread_t tid);
     nub_state_t     GetState (nub_thread_t tid);
     nub_thread_t    SetCurrentThread (nub_thread_t tid);
 #endif
 
-    // TODO: figure out if we need to add this to NativeThreadDarwin yet.
+// TODO: figure out if we need to add this to NativeThreadDarwin yet.
 #if 0
     ThreadInfo::QoS GetRequestedQoS (nub_thread_t tid, nub_addr_t tsd, uint64_t dti_qos_class_index);
     nub_addr_t      GetPThreadT (nub_thread_t tid);
@@ -87,76 +80,60 @@ public:
     nub_addr_t      GetTSDAddressForThread (nub_thread_t tid, uint64_t plo_pthread_tsd_base_address_offset, uint64_t plo_pthread_tsd_base_offset, uint64_t plo_pthread_tsd_entry_size);
 #endif
 
-    // These methods will be accessed directly from NativeThreadDarwin
+// These methods will be accessed directly from NativeThreadDarwin
 #if 0
     bool            GetThreadStoppedReason (nub_thread_t tid, struct DNBThreadStopInfo *stop_info) const;
     void            DumpThreadStoppedReason (nub_thread_t tid) const;
     bool            GetIdentifierInfo (nub_thread_t tid, thread_identifier_info_data_t *ident_info);
 #endif
 
-    size_t
-    GetNumberOfThreads() const;
+  size_t GetNumberOfThreads() const;
 
-    lldb::tid_t
-    ThreadIDAtIndex(size_t idx) const;
+  lldb::tid_t ThreadIDAtIndex(size_t idx) const;
 
-    lldb::tid_t
-    GetCurrentThreadID();
+  lldb::tid_t GetCurrentThreadID();
 
-    NativeThreadDarwinSP
-    GetCurrentThread();
+  NativeThreadDarwinSP GetCurrentThread();
 
-    void
-    NotifyBreakpointChanged(const NativeBreakpointDarwin *bp);
+  void NotifyBreakpointChanged(const NativeBreakpointDarwin *bp);
 
-    uint32_t
-    EnableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
+  uint32_t EnableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
 
-    bool
-    DisableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
+  bool DisableHardwareBreakpoint(const NativeBreakpointDarwin *bp) const;
 
-    uint32_t
-    EnableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
+  uint32_t EnableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
 
-    bool
-    DisableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
+  bool DisableHardwareWatchpoint(const NativeBreakpointDarwin *wp) const;
 
-    uint32_t
-    GetNumberOfSupportedHardwareWatchpoints() const;
+  uint32_t GetNumberOfSupportedHardwareWatchpoints() const;
 
-    size_t
-    GetThreadIndexForThreadStoppedWithSignal(const int signo) const;
+  size_t GetThreadIndexForThreadStoppedWithSignal(const int signo) const;
 
-    NativeThreadDarwinSP
-    GetThreadByID(lldb::tid_t tid) const;
+  NativeThreadDarwinSP GetThreadByID(lldb::tid_t tid) const;
 
-    NativeThreadDarwinSP
-    GetThreadByMachPortNumber(::thread_t mach_port_number) const;
+  NativeThreadDarwinSP
+  GetThreadByMachPortNumber(::thread_t mach_port_number) const;
 
-    lldb::tid_t
-    GetThreadIDByMachPortNumber(::thread_t mach_port_number) const;
+  lldb::tid_t GetThreadIDByMachPortNumber(::thread_t mach_port_number) const;
 
-    thread_t
-    GetMachPortNumberByThreadID(lldb::tid_t globally_unique_id) const;
+  thread_t GetMachPortNumberByThreadID(lldb::tid_t globally_unique_id) const;
 
 protected:
-    typedef std::vector<NativeThreadDarwinSP>  collection;
-    typedef collection::iterator               iterator;
-    typedef collection::const_iterator         const_iterator;
-
-    // Consider having this return an lldb_private::Error.
-    uint32_t
-    UpdateThreadList (NativeProcessDarwin &process, bool update,
-                      collection *num_threads = nullptr);
-
-    collection                    m_threads;
-    mutable std::recursive_mutex  m_threads_mutex;
-    NativeThreadDarwinSP          m_current_thread;
-    bool                          m_is_64_bit;
+  typedef std::vector<NativeThreadDarwinSP> collection;
+  typedef collection::iterator iterator;
+  typedef collection::const_iterator const_iterator;
+
+  // Consider having this return an lldb_private::Error.
+  uint32_t UpdateThreadList(NativeProcessDarwin &process, bool update,
+                            collection *num_threads = nullptr);
+
+  collection m_threads;
+  mutable std::recursive_mutex m_threads_mutex;
+  NativeThreadDarwinSP m_current_thread;
+  bool m_is_64_bit;
 };
 
 } // namespace process_darwin
 } // namespace lldb_private
 
 #endif // #ifndef __NativeThreadListDarwin_h__
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp Tue Sep  6 15:57:50 2016
@@ -16,684 +16,603 @@
 #include "lldb/Target/UnixSignals.h"
 
 // Project includes
-#include "lldb/Breakpoint/Watchpoint.h"
+#include "FreeBSDThread.h"
+#include "POSIXStopInfo.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm64.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
+#include "Plugins/Process/Utility/UnwindLLDB.h"
+#include "ProcessFreeBSD.h"
+#include "ProcessMonitor.h"
+#include "ProcessPOSIXLog.h"
+#include "RegisterContextPOSIXProcessMonitor_arm.h"
+#include "RegisterContextPOSIXProcessMonitor_arm64.h"
+#include "RegisterContextPOSIXProcessMonitor_mips64.h"
+#include "RegisterContextPOSIXProcessMonitor_powerpc.h"
+#include "RegisterContextPOSIXProcessMonitor_x86.h"
 #include "lldb/Breakpoint/BreakpointLocation.h"
+#include "lldb/Breakpoint/Watchpoint.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/State.h"
 #include "lldb/Host/Host.h"
-#include "lldb/Host/HostNativeThread.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/HostNativeThread.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/ThreadSpec.h"
 #include "llvm/ADT/SmallString.h"
-#include "POSIXStopInfo.h"
-#include "FreeBSDThread.h"
-#include "ProcessFreeBSD.h"
-#include "ProcessPOSIXLog.h"
-#include "ProcessMonitor.h"
-#include "RegisterContextPOSIXProcessMonitor_arm.h"
-#include "RegisterContextPOSIXProcessMonitor_arm64.h"
-#include "RegisterContextPOSIXProcessMonitor_mips64.h"
-#include "RegisterContextPOSIXProcessMonitor_powerpc.h"
-#include "RegisterContextPOSIXProcessMonitor_x86.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm64.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
-#include "Plugins/Process/Utility/UnwindLLDB.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
 FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid)
-    : Thread(process, tid),
-      m_frame_ap (),
-      m_breakpoint (),
-      m_thread_name_valid (false),
-      m_thread_name (),
-      m_posix_thread(NULL)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-    if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
-        log->Printf ("FreeBSDThread::%s (tid = %" PRIi64 ")", __FUNCTION__, tid);
+    : Thread(process, tid), m_frame_ap(), m_breakpoint(),
+      m_thread_name_valid(false), m_thread_name(), m_posix_thread(NULL) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+  if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
+    log->Printf("FreeBSDThread::%s (tid = %" PRIi64 ")", __FUNCTION__, tid);
+
+  // Set the current watchpoints for this thread.
+  Target &target = GetProcess()->GetTarget();
+  const WatchpointList &wp_list = target.GetWatchpointList();
+  size_t wp_size = wp_list.GetSize();
+
+  for (uint32_t wp_idx = 0; wp_idx < wp_size; wp_idx++) {
+    lldb::WatchpointSP wp = wp_list.GetByIndex(wp_idx);
+    if (wp.get() && wp->IsEnabled()) {
+      // This watchpoint as been enabled; obviously this "new" thread
+      // has been created since that watchpoint was enabled.  Since
+      // the POSIXBreakpointProtocol has yet to be initialized, its
+      // m_watchpoints_initialized member will be FALSE.  Attempting to
+      // read the debug status register to determine if a watchpoint
+      // has been hit would result in the zeroing of that register.
+      // Since the active debug registers would have been cloned when
+      // this thread was created, simply force the m_watchpoints_initized
+      // member to TRUE and avoid resetting dr6 and dr7.
+      GetPOSIXBreakpointProtocol()->ForceWatchpointsInitialized();
+    }
+  }
+}
+
+FreeBSDThread::~FreeBSDThread() { DestroyThread(); }
+
+ProcessMonitor &FreeBSDThread::GetMonitor() {
+  ProcessSP base = GetProcess();
+  ProcessFreeBSD &process = static_cast<ProcessFreeBSD &>(*base);
+  return process.GetMonitor();
+}
+
+void FreeBSDThread::RefreshStateAfterStop() {
+  // Invalidate all registers in our register context. We don't set "force" to
+  // true because the stop reply packet might have had some register values
+  // that were expedited and these will already be copied into the register
+  // context by the time this function gets called. The KDPRegisterContext
+  // class has been made smart enough to detect when it needs to invalidate
+  // which registers are valid by putting hooks in the register read and
+  // register supply functions where they check the process stop ID and do
+  // the right thing.
+  // if (StateIsStoppedState(GetState())
+  {
+    const bool force = false;
+    GetRegisterContext()->InvalidateIfNeeded(force);
+  }
+}
+
+const char *FreeBSDThread::GetInfo() { return NULL; }
+
+void FreeBSDThread::SetName(const char *name) {
+  m_thread_name_valid = (name && name[0]);
+  if (m_thread_name_valid)
+    m_thread_name.assign(name);
+  else
+    m_thread_name.clear();
+}
+
+const char *FreeBSDThread::GetName() {
+  if (!m_thread_name_valid) {
+    llvm::SmallString<32> thread_name;
+    HostNativeThread::GetName(GetID(), thread_name);
+    m_thread_name = thread_name.c_str();
+    m_thread_name_valid = true;
+  }
 
-    // Set the current watchpoints for this thread.
-    Target &target = GetProcess()->GetTarget();
-    const WatchpointList &wp_list = target.GetWatchpointList();
-    size_t wp_size = wp_list.GetSize();
-
-    for (uint32_t wp_idx = 0; wp_idx < wp_size; wp_idx++)
-    {
-        lldb::WatchpointSP wp = wp_list.GetByIndex(wp_idx);
-        if (wp.get() && wp->IsEnabled())
-        {
-            // This watchpoint as been enabled; obviously this "new" thread
-            // has been created since that watchpoint was enabled.  Since
-            // the POSIXBreakpointProtocol has yet to be initialized, its
-            // m_watchpoints_initialized member will be FALSE.  Attempting to
-            // read the debug status register to determine if a watchpoint
-            // has been hit would result in the zeroing of that register.
-            // Since the active debug registers would have been cloned when
-            // this thread was created, simply force the m_watchpoints_initized
-            // member to TRUE and avoid resetting dr6 and dr7.
-            GetPOSIXBreakpointProtocol()->ForceWatchpointsInitialized();
-        }
-    }
-}
-
-FreeBSDThread::~FreeBSDThread()
-{
-    DestroyThread();
-}
-
-ProcessMonitor &
-FreeBSDThread::GetMonitor()
-{
-    ProcessSP base = GetProcess();
-    ProcessFreeBSD &process = static_cast<ProcessFreeBSD&>(*base);
-    return process.GetMonitor();
-}
-
-void
-FreeBSDThread::RefreshStateAfterStop()
-{
-    // Invalidate all registers in our register context. We don't set "force" to
-    // true because the stop reply packet might have had some register values
-    // that were expedited and these will already be copied into the register
-    // context by the time this function gets called. The KDPRegisterContext
-    // class has been made smart enough to detect when it needs to invalidate
-    // which registers are valid by putting hooks in the register read and 
-    // register supply functions where they check the process stop ID and do
-    // the right thing.
-    //if (StateIsStoppedState(GetState())
-    {
-        const bool force = false;
-        GetRegisterContext()->InvalidateIfNeeded (force);
-    }
-}
-
-const char *
-FreeBSDThread::GetInfo()
-{
+  if (m_thread_name.empty())
     return NULL;
+  return m_thread_name.c_str();
 }
 
-void
-FreeBSDThread::SetName (const char *name)
-{
-    m_thread_name_valid = (name && name[0]);
-    if (m_thread_name_valid)
-        m_thread_name.assign (name);
-    else
-        m_thread_name.clear();
-}
-
-const char *
-FreeBSDThread::GetName ()
-{
-    if (!m_thread_name_valid)
-    {
-        llvm::SmallString<32> thread_name;
-        HostNativeThread::GetName(GetID(), thread_name);
-        m_thread_name = thread_name.c_str();
-        m_thread_name_valid = true;
-    }
-
-    if (m_thread_name.empty())
-        return NULL;
-    return m_thread_name.c_str();
-}
+lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() {
+  if (!m_reg_context_sp) {
+    m_posix_thread = NULL;
 
-lldb::RegisterContextSP
-FreeBSDThread::GetRegisterContext()
-{
-    if (!m_reg_context_sp)
-    {
-        m_posix_thread = NULL;
-
-        RegisterInfoInterface *reg_interface = NULL;
-        const ArchSpec &target_arch = GetProcess()->GetTarget().GetArchitecture();
-
-        assert(target_arch.GetTriple().getOS() == llvm::Triple::FreeBSD);
-        switch (target_arch.GetMachine())
-        {
-            case llvm::Triple::aarch64:
-                reg_interface = new RegisterContextFreeBSD_arm64(target_arch);
-                break;
-            case llvm::Triple::arm:
-                reg_interface = new RegisterContextFreeBSD_arm(target_arch);
-                break;
-            case llvm::Triple::ppc:
+    RegisterInfoInterface *reg_interface = NULL;
+    const ArchSpec &target_arch = GetProcess()->GetTarget().GetArchitecture();
+
+    assert(target_arch.GetTriple().getOS() == llvm::Triple::FreeBSD);
+    switch (target_arch.GetMachine()) {
+    case llvm::Triple::aarch64:
+      reg_interface = new RegisterContextFreeBSD_arm64(target_arch);
+      break;
+    case llvm::Triple::arm:
+      reg_interface = new RegisterContextFreeBSD_arm(target_arch);
+      break;
+    case llvm::Triple::ppc:
 #ifndef __powerpc64__
-                reg_interface = new RegisterContextFreeBSD_powerpc32(target_arch);
-                break;
+      reg_interface = new RegisterContextFreeBSD_powerpc32(target_arch);
+      break;
 #endif
-            case llvm::Triple::ppc64:
-                reg_interface = new RegisterContextFreeBSD_powerpc64(target_arch);
-                break;
-            case llvm::Triple::mips64:
-                reg_interface = new RegisterContextFreeBSD_mips64(target_arch);
-                break;
-            case llvm::Triple::x86:
-                reg_interface = new RegisterContextFreeBSD_i386(target_arch);
-                break;
-            case llvm::Triple::x86_64:
-                reg_interface = new RegisterContextFreeBSD_x86_64(target_arch);
-                break;
-            default:
-                llvm_unreachable("CPU not supported");
-        }
-
-        switch (target_arch.GetMachine())
-        {
-            case llvm::Triple::aarch64:
-                {
-                    RegisterContextPOSIXProcessMonitor_arm64 *reg_ctx = new RegisterContextPOSIXProcessMonitor_arm64(*this, 0, reg_interface);
-                    m_posix_thread = reg_ctx;
-                    m_reg_context_sp.reset(reg_ctx);
-                    break;
-                }
-            case llvm::Triple::arm:
-                {
-                    RegisterContextPOSIXProcessMonitor_arm *reg_ctx = new RegisterContextPOSIXProcessMonitor_arm(*this, 0, reg_interface);
-                    m_posix_thread = reg_ctx;
-                    m_reg_context_sp.reset(reg_ctx);
-                    break;
-                }
-            case llvm::Triple::mips64:
-                {
-                    RegisterContextPOSIXProcessMonitor_mips64 *reg_ctx = new RegisterContextPOSIXProcessMonitor_mips64(*this, 0, reg_interface);
-                    m_posix_thread = reg_ctx;
-                    m_reg_context_sp.reset(reg_ctx);
-                    break;
-                }
-            case llvm::Triple::ppc:
-            case llvm::Triple::ppc64:
-                {
-                    RegisterContextPOSIXProcessMonitor_powerpc *reg_ctx = new RegisterContextPOSIXProcessMonitor_powerpc(*this, 0, reg_interface);
-                    m_posix_thread = reg_ctx;
-                    m_reg_context_sp.reset(reg_ctx);
-                    break;
-                }
-            case llvm::Triple::x86:
-            case llvm::Triple::x86_64:
-                {
-                    RegisterContextPOSIXProcessMonitor_x86_64 *reg_ctx = new RegisterContextPOSIXProcessMonitor_x86_64(*this, 0, reg_interface);
-                    m_posix_thread = reg_ctx;
-                    m_reg_context_sp.reset(reg_ctx);
-                    break;
-                }
-            default:
-                break;
-        }
-    }
-    return m_reg_context_sp;
-}
-
-lldb::RegisterContextSP
-FreeBSDThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame)
-{
-    lldb::RegisterContextSP reg_ctx_sp;
-    uint32_t concrete_frame_idx = 0;
-
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-    if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
-        log->Printf ("FreeBSDThread::%s ()", __FUNCTION__);
-
-    if (frame)
-        concrete_frame_idx = frame->GetConcreteFrameIndex();
-
-    if (concrete_frame_idx == 0)
-        reg_ctx_sp = GetRegisterContext();
-    else
-    {
-        assert(GetUnwinder());
-        reg_ctx_sp = GetUnwinder()->CreateRegisterContextForFrame(frame);
-    }
-
-    return reg_ctx_sp;
-}
-
-lldb::addr_t
-FreeBSDThread::GetThreadPointer ()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    addr_t addr;
-    if (monitor.ReadThreadPointer (GetID(), addr))
-        return addr;
-    else
-        return LLDB_INVALID_ADDRESS;
-}
-
-bool
-FreeBSDThread::CalculateStopInfo()
-{
-    SetStopInfo (m_stop_info_sp);
-    return true;
-}
-
-Unwind *
-FreeBSDThread::GetUnwinder()
-{
-    if (m_unwinder_ap.get() == NULL)
-        m_unwinder_ap.reset(new UnwindLLDB(*this));
-
-    return m_unwinder_ap.get();
-}
-
-void
-FreeBSDThread::DidStop()
-{
-    // Don't set the thread state to stopped unless we really stopped.
-}
-
-void
-FreeBSDThread::WillResume(lldb::StateType resume_state)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-    if (log)
-        log->Printf("tid %lu resume_state = %s", GetID(),
-                    lldb_private::StateAsCString(resume_state));
-    ProcessSP process_sp(GetProcess());
-    ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(process_sp.get());
-    int signo = GetResumeSignal();
-    bool signo_valid = process->GetUnixSignals()->SignalIsValid(signo);
-
-    switch (resume_state)
-    {
-    case eStateSuspended:
-    case eStateStopped:
-        process->m_suspend_tids.push_back(GetID());
-        break;
-    case eStateRunning:
-        process->m_run_tids.push_back(GetID());
-        if (signo_valid)
-            process->m_resume_signo = signo;
-        break;
-    case eStateStepping:
-        process->m_step_tids.push_back(GetID());
-        if (signo_valid)
-            process->m_resume_signo = signo;
-        break; 
+    case llvm::Triple::ppc64:
+      reg_interface = new RegisterContextFreeBSD_powerpc64(target_arch);
+      break;
+    case llvm::Triple::mips64:
+      reg_interface = new RegisterContextFreeBSD_mips64(target_arch);
+      break;
+    case llvm::Triple::x86:
+      reg_interface = new RegisterContextFreeBSD_i386(target_arch);
+      break;
+    case llvm::Triple::x86_64:
+      reg_interface = new RegisterContextFreeBSD_x86_64(target_arch);
+      break;
     default:
-        break;
+      llvm_unreachable("CPU not supported");
     }
-}
-
-bool
-FreeBSDThread::Resume()
-{
-    lldb::StateType resume_state = GetResumeState();
-    ProcessMonitor &monitor = GetMonitor();
-    bool status;
-
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-    if (log)
-        log->Printf ("FreeBSDThread::%s (), resume_state = %s", __FUNCTION__,
-                         StateAsCString(resume_state));
 
-    switch (resume_state)
-    {
+    switch (target_arch.GetMachine()) {
+    case llvm::Triple::aarch64: {
+      RegisterContextPOSIXProcessMonitor_arm64 *reg_ctx =
+          new RegisterContextPOSIXProcessMonitor_arm64(*this, 0, reg_interface);
+      m_posix_thread = reg_ctx;
+      m_reg_context_sp.reset(reg_ctx);
+      break;
+    }
+    case llvm::Triple::arm: {
+      RegisterContextPOSIXProcessMonitor_arm *reg_ctx =
+          new RegisterContextPOSIXProcessMonitor_arm(*this, 0, reg_interface);
+      m_posix_thread = reg_ctx;
+      m_reg_context_sp.reset(reg_ctx);
+      break;
+    }
+    case llvm::Triple::mips64: {
+      RegisterContextPOSIXProcessMonitor_mips64 *reg_ctx =
+          new RegisterContextPOSIXProcessMonitor_mips64(*this, 0,
+                                                        reg_interface);
+      m_posix_thread = reg_ctx;
+      m_reg_context_sp.reset(reg_ctx);
+      break;
+    }
+    case llvm::Triple::ppc:
+    case llvm::Triple::ppc64: {
+      RegisterContextPOSIXProcessMonitor_powerpc *reg_ctx =
+          new RegisterContextPOSIXProcessMonitor_powerpc(*this, 0,
+                                                         reg_interface);
+      m_posix_thread = reg_ctx;
+      m_reg_context_sp.reset(reg_ctx);
+      break;
+    }
+    case llvm::Triple::x86:
+    case llvm::Triple::x86_64: {
+      RegisterContextPOSIXProcessMonitor_x86_64 *reg_ctx =
+          new RegisterContextPOSIXProcessMonitor_x86_64(*this, 0,
+                                                        reg_interface);
+      m_posix_thread = reg_ctx;
+      m_reg_context_sp.reset(reg_ctx);
+      break;
+    }
     default:
-        assert(false && "Unexpected state for resume!");
-        status = false;
-        break;
-
-    case lldb::eStateRunning:
-        SetState(resume_state);
-        status = monitor.Resume(GetID(), GetResumeSignal());
-        break;
-
-    case lldb::eStateStepping:
-        SetState(resume_state);
-        status = monitor.SingleStep(GetID(), GetResumeSignal());
-        break;
-    case lldb::eStateStopped:
-    case lldb::eStateSuspended:
-        status = true;
-        break;
+      break;
     }
-
-    return status;
+  }
+  return m_reg_context_sp;
 }
 
-void
-FreeBSDThread::Notify(const ProcessMessage &message)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-    if (log)
-        log->Printf ("FreeBSDThread::%s () message kind = '%s' for tid %" PRIu64,
-                     __FUNCTION__, message.PrintKind(), GetID());
-
-    switch (message.GetKind())
-    {
-    default:
-        assert(false && "Unexpected message kind!");
-        break;
-
-    case ProcessMessage::eExitMessage:
-        // Nothing to be done.
-        break;
-
-    case ProcessMessage::eLimboMessage:
-        LimboNotify(message);
-        break;
-
-    case ProcessMessage::eSignalMessage:
-        SignalNotify(message);
-        break;
-
-    case ProcessMessage::eSignalDeliveredMessage:
-        SignalDeliveredNotify(message);
-        break;
-
-    case ProcessMessage::eTraceMessage:
-        TraceNotify(message);
-        break;
-
-    case ProcessMessage::eBreakpointMessage:
-        BreakNotify(message);
-        break;
-
-    case ProcessMessage::eWatchpointMessage:
-        WatchNotify(message);
-        break;
-
-    case ProcessMessage::eCrashMessage:
-        CrashNotify(message);
-        break;
-
-    case ProcessMessage::eExecMessage:
-        ExecNotify(message);
-        break;
-    }
+lldb::RegisterContextSP
+FreeBSDThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) {
+  lldb::RegisterContextSP reg_ctx_sp;
+  uint32_t concrete_frame_idx = 0;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+  if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
+    log->Printf("FreeBSDThread::%s ()", __FUNCTION__);
+
+  if (frame)
+    concrete_frame_idx = frame->GetConcreteFrameIndex();
+
+  if (concrete_frame_idx == 0)
+    reg_ctx_sp = GetRegisterContext();
+  else {
+    assert(GetUnwinder());
+    reg_ctx_sp = GetUnwinder()->CreateRegisterContextForFrame(frame);
+  }
+
+  return reg_ctx_sp;
+}
+
+lldb::addr_t FreeBSDThread::GetThreadPointer() {
+  ProcessMonitor &monitor = GetMonitor();
+  addr_t addr;
+  if (monitor.ReadThreadPointer(GetID(), addr))
+    return addr;
+  else
+    return LLDB_INVALID_ADDRESS;
+}
+
+bool FreeBSDThread::CalculateStopInfo() {
+  SetStopInfo(m_stop_info_sp);
+  return true;
+}
+
+Unwind *FreeBSDThread::GetUnwinder() {
+  if (m_unwinder_ap.get() == NULL)
+    m_unwinder_ap.reset(new UnwindLLDB(*this));
+
+  return m_unwinder_ap.get();
+}
+
+void FreeBSDThread::DidStop() {
+  // Don't set the thread state to stopped unless we really stopped.
+}
+
+void FreeBSDThread::WillResume(lldb::StateType resume_state) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+  if (log)
+    log->Printf("tid %lu resume_state = %s", GetID(),
+                lldb_private::StateAsCString(resume_state));
+  ProcessSP process_sp(GetProcess());
+  ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(process_sp.get());
+  int signo = GetResumeSignal();
+  bool signo_valid = process->GetUnixSignals()->SignalIsValid(signo);
+
+  switch (resume_state) {
+  case eStateSuspended:
+  case eStateStopped:
+    process->m_suspend_tids.push_back(GetID());
+    break;
+  case eStateRunning:
+    process->m_run_tids.push_back(GetID());
+    if (signo_valid)
+      process->m_resume_signo = signo;
+    break;
+  case eStateStepping:
+    process->m_step_tids.push_back(GetID());
+    if (signo_valid)
+      process->m_resume_signo = signo;
+    break;
+  default:
+    break;
+  }
+}
+
+bool FreeBSDThread::Resume() {
+  lldb::StateType resume_state = GetResumeState();
+  ProcessMonitor &monitor = GetMonitor();
+  bool status;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+  if (log)
+    log->Printf("FreeBSDThread::%s (), resume_state = %s", __FUNCTION__,
+                StateAsCString(resume_state));
+
+  switch (resume_state) {
+  default:
+    assert(false && "Unexpected state for resume!");
+    status = false;
+    break;
+
+  case lldb::eStateRunning:
+    SetState(resume_state);
+    status = monitor.Resume(GetID(), GetResumeSignal());
+    break;
+
+  case lldb::eStateStepping:
+    SetState(resume_state);
+    status = monitor.SingleStep(GetID(), GetResumeSignal());
+    break;
+  case lldb::eStateStopped:
+  case lldb::eStateSuspended:
+    status = true;
+    break;
+  }
+
+  return status;
+}
+
+void FreeBSDThread::Notify(const ProcessMessage &message) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+  if (log)
+    log->Printf("FreeBSDThread::%s () message kind = '%s' for tid %" PRIu64,
+                __FUNCTION__, message.PrintKind(), GetID());
+
+  switch (message.GetKind()) {
+  default:
+    assert(false && "Unexpected message kind!");
+    break;
+
+  case ProcessMessage::eExitMessage:
+    // Nothing to be done.
+    break;
+
+  case ProcessMessage::eLimboMessage:
+    LimboNotify(message);
+    break;
+
+  case ProcessMessage::eSignalMessage:
+    SignalNotify(message);
+    break;
+
+  case ProcessMessage::eSignalDeliveredMessage:
+    SignalDeliveredNotify(message);
+    break;
+
+  case ProcessMessage::eTraceMessage:
+    TraceNotify(message);
+    break;
+
+  case ProcessMessage::eBreakpointMessage:
+    BreakNotify(message);
+    break;
+
+  case ProcessMessage::eWatchpointMessage:
+    WatchNotify(message);
+    break;
+
+  case ProcessMessage::eCrashMessage:
+    CrashNotify(message);
+    break;
+
+  case ProcessMessage::eExecMessage:
+    ExecNotify(message);
+    break;
+  }
+}
+
+bool FreeBSDThread::EnableHardwareWatchpoint(Watchpoint *wp) {
+  bool wp_set = false;
+  if (wp) {
+    addr_t wp_addr = wp->GetLoadAddress();
+    size_t wp_size = wp->GetByteSize();
+    bool wp_read = wp->WatchpointRead();
+    bool wp_write = wp->WatchpointWrite();
+    uint32_t wp_hw_index = wp->GetHardwareIndex();
+    POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
+    if (reg_ctx)
+      wp_set = reg_ctx->SetHardwareWatchpointWithIndex(
+          wp_addr, wp_size, wp_read, wp_write, wp_hw_index);
+  }
+  return wp_set;
 }
 
-bool
-FreeBSDThread::EnableHardwareWatchpoint(Watchpoint *wp)
-{
-    bool wp_set = false;
-    if (wp)
-    {
-        addr_t wp_addr = wp->GetLoadAddress();
-        size_t wp_size = wp->GetByteSize();
-        bool wp_read = wp->WatchpointRead();
-        bool wp_write = wp->WatchpointWrite();
-        uint32_t wp_hw_index = wp->GetHardwareIndex();
-        POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
-        if (reg_ctx)
-            wp_set = reg_ctx->SetHardwareWatchpointWithIndex(wp_addr, wp_size,
-                                                             wp_read, wp_write,
-                                                             wp_hw_index);
-    }
-    return wp_set;
-}
-
-bool
-FreeBSDThread::DisableHardwareWatchpoint(Watchpoint *wp)
-{
-    bool result = false;
-    if (wp)
-    {
-        lldb::RegisterContextSP reg_ctx_sp = GetRegisterContext();
-        if (reg_ctx_sp.get())
-            result = reg_ctx_sp->ClearHardwareWatchpoint(wp->GetHardwareIndex());
-    }
-    return result;
-}
-
-uint32_t
-FreeBSDThread::NumSupportedHardwareWatchpoints()
-{
+bool FreeBSDThread::DisableHardwareWatchpoint(Watchpoint *wp) {
+  bool result = false;
+  if (wp) {
     lldb::RegisterContextSP reg_ctx_sp = GetRegisterContext();
     if (reg_ctx_sp.get())
-        return reg_ctx_sp->NumSupportedHardwareWatchpoints();
-    return 0;
-}
-
-uint32_t
-FreeBSDThread::FindVacantWatchpointIndex()
-{
-    uint32_t hw_index = LLDB_INVALID_INDEX32;
-    uint32_t num_hw_wps = NumSupportedHardwareWatchpoints();
+      result = reg_ctx_sp->ClearHardwareWatchpoint(wp->GetHardwareIndex());
+  }
+  return result;
+}
+
+uint32_t FreeBSDThread::NumSupportedHardwareWatchpoints() {
+  lldb::RegisterContextSP reg_ctx_sp = GetRegisterContext();
+  if (reg_ctx_sp.get())
+    return reg_ctx_sp->NumSupportedHardwareWatchpoints();
+  return 0;
+}
+
+uint32_t FreeBSDThread::FindVacantWatchpointIndex() {
+  uint32_t hw_index = LLDB_INVALID_INDEX32;
+  uint32_t num_hw_wps = NumSupportedHardwareWatchpoints();
+  uint32_t wp_idx;
+  POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
+  if (reg_ctx) {
+    for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++) {
+      if (reg_ctx->IsWatchpointVacant(wp_idx)) {
+        hw_index = wp_idx;
+        break;
+      }
+    }
+  }
+  return hw_index;
+}
+
+void FreeBSDThread::BreakNotify(const ProcessMessage &message) {
+  bool status;
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+
+  assert(GetRegisterContext());
+  status = GetPOSIXBreakpointProtocol()->UpdateAfterBreakpoint();
+  assert(status && "Breakpoint update failed!");
+
+  // With our register state restored, resolve the breakpoint object
+  // corresponding to our current PC.
+  assert(GetRegisterContext());
+  lldb::addr_t pc = GetRegisterContext()->GetPC();
+  if (log)
+    log->Printf("FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc);
+  lldb::BreakpointSiteSP bp_site(
+      GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
+
+  // If the breakpoint is for this thread, then we'll report the hit, but if it
+  // is for another thread,
+  // we create a stop reason with should_stop=false.  If there is no breakpoint
+  // location, then report
+  // an invalid stop reason. We don't need to worry about stepping over the
+  // breakpoint here, that will
+  // be taken care of when the thread resumes and notices that there's a
+  // breakpoint under the pc.
+  if (bp_site) {
+    lldb::break_id_t bp_id = bp_site->GetID();
+    // If we have an operating system plug-in, we might have set a thread
+    // specific breakpoint using the
+    // operating system thread ID, so we can't make any assumptions about the
+    // thread ID so we must always
+    // report the breakpoint regardless of the thread.
+    if (bp_site->ValidForThisThread(this) ||
+        GetProcess()->GetOperatingSystem() != NULL)
+      SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id));
+    else {
+      const bool should_stop = false;
+      SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id,
+                                                                 should_stop));
+    }
+  } else
+    SetStopInfo(StopInfoSP());
+}
+
+void FreeBSDThread::WatchNotify(const ProcessMessage &message) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+
+  lldb::addr_t halt_addr = message.GetHWAddress();
+  if (log)
+    log->Printf(
+        "FreeBSDThread::%s () Hardware Watchpoint Address = 0x%8.8" PRIx64,
+        __FUNCTION__, halt_addr);
+
+  POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
+  if (reg_ctx) {
+    uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
     uint32_t wp_idx;
-    POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
-    if (reg_ctx)
-    {
-        for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++)
-        {
-            if (reg_ctx->IsWatchpointVacant(wp_idx))
-            {
-                hw_index = wp_idx;
-                break;
-            }
-        }
-    }
-    return hw_index;
-}
-
-void
-FreeBSDThread::BreakNotify(const ProcessMessage &message)
-{
-    bool status;
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-
-    assert(GetRegisterContext());
-    status = GetPOSIXBreakpointProtocol()->UpdateAfterBreakpoint();
-    assert(status && "Breakpoint update failed!");
-
-    // With our register state restored, resolve the breakpoint object
-    // corresponding to our current PC.
-    assert(GetRegisterContext());
-    lldb::addr_t pc = GetRegisterContext()->GetPC();
-    if (log)
-        log->Printf ("FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc);
-    lldb::BreakpointSiteSP bp_site(GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
-
-    // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread,
-    // we create a stop reason with should_stop=false.  If there is no breakpoint location, then report
-    // an invalid stop reason. We don't need to worry about stepping over the breakpoint here, that will
-    // be taken care of when the thread resumes and notices that there's a breakpoint under the pc.
-    if (bp_site)
-    {
-        lldb::break_id_t bp_id = bp_site->GetID();
-        // If we have an operating system plug-in, we might have set a thread specific breakpoint using the
-        // operating system thread ID, so we can't make any assumptions about the thread ID so we must always
-        // report the breakpoint regardless of the thread.
-        if (bp_site->ValidForThisThread(this) || GetProcess()->GetOperatingSystem () != NULL)
-            SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id));
-        else
-        {
-            const bool should_stop = false;
-            SetStopInfo (StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id, should_stop));
-        }
+    for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++) {
+      if (reg_ctx->IsWatchpointHit(wp_idx)) {
+        // Clear the watchpoint hit here
+        reg_ctx->ClearWatchpointHits();
+        break;
+      }
     }
-    else
-        SetStopInfo(StopInfoSP());
-}
-
-void
-FreeBSDThread::WatchNotify(const ProcessMessage &message)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-
-    lldb::addr_t halt_addr = message.GetHWAddress();
-    if (log)
-        log->Printf ("FreeBSDThread::%s () Hardware Watchpoint Address = 0x%8.8"
-                     PRIx64, __FUNCTION__, halt_addr);
 
-    POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
-    if (reg_ctx)
-    {
-        uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
-        uint32_t wp_idx;
-        for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++)
-        {
-            if (reg_ctx->IsWatchpointHit(wp_idx))
-            {
-                // Clear the watchpoint hit here
-                reg_ctx->ClearWatchpointHits();
-                break;
-            }
-        }
-
-        if (wp_idx == num_hw_wps)
-            return;
+    if (wp_idx == num_hw_wps)
+      return;
 
-        Target &target = GetProcess()->GetTarget();
-        lldb::addr_t wp_monitor_addr = reg_ctx->GetWatchpointAddress(wp_idx);
-        const WatchpointList &wp_list = target.GetWatchpointList();
-        lldb::WatchpointSP wp_sp = wp_list.FindByAddress(wp_monitor_addr);
-
-        assert(wp_sp.get() && "No watchpoint found");
-        SetStopInfo (StopInfo::CreateStopReasonWithWatchpointID(*this,
-                                                                wp_sp->GetID()));
-    }
-}
+    Target &target = GetProcess()->GetTarget();
+    lldb::addr_t wp_monitor_addr = reg_ctx->GetWatchpointAddress(wp_idx);
+    const WatchpointList &wp_list = target.GetWatchpointList();
+    lldb::WatchpointSP wp_sp = wp_list.FindByAddress(wp_monitor_addr);
 
-void
-FreeBSDThread::TraceNotify(const ProcessMessage &message)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-
-    // Try to resolve the breakpoint object corresponding to the current PC.
-    assert(GetRegisterContext());
-    lldb::addr_t pc = GetRegisterContext()->GetPC();
-    if (log)
-        log->Printf ("FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc);
-    lldb::BreakpointSiteSP bp_site(GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
-
-    // If the current pc is a breakpoint site then set the StopInfo to Breakpoint.
-    // Otherwise, set the StopInfo to Watchpoint or Trace.
-    // If we have an operating system plug-in, we might have set a thread specific breakpoint using the
-    // operating system thread ID, so we can't make any assumptions about the thread ID so we must always
-    // report the breakpoint regardless of the thread.
-    if (bp_site && (bp_site->ValidForThisThread(this) || GetProcess()->GetOperatingSystem () != NULL))
-        SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_site->GetID()));
-    else
-    {
-        POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
-        if (reg_ctx)
-        {
-            uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
-            uint32_t wp_idx;
-            for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++)
-            {
-                if (reg_ctx->IsWatchpointHit(wp_idx))
-                {
-                    WatchNotify(message);
-                    return;
-                }
-            }
+    assert(wp_sp.get() && "No watchpoint found");
+    SetStopInfo(
+        StopInfo::CreateStopReasonWithWatchpointID(*this, wp_sp->GetID()));
+  }
+}
+
+void FreeBSDThread::TraceNotify(const ProcessMessage &message) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+
+  // Try to resolve the breakpoint object corresponding to the current PC.
+  assert(GetRegisterContext());
+  lldb::addr_t pc = GetRegisterContext()->GetPC();
+  if (log)
+    log->Printf("FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc);
+  lldb::BreakpointSiteSP bp_site(
+      GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
+
+  // If the current pc is a breakpoint site then set the StopInfo to Breakpoint.
+  // Otherwise, set the StopInfo to Watchpoint or Trace.
+  // If we have an operating system plug-in, we might have set a thread specific
+  // breakpoint using the
+  // operating system thread ID, so we can't make any assumptions about the
+  // thread ID so we must always
+  // report the breakpoint regardless of the thread.
+  if (bp_site && (bp_site->ValidForThisThread(this) ||
+                  GetProcess()->GetOperatingSystem() != NULL))
+    SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(
+        *this, bp_site->GetID()));
+  else {
+    POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
+    if (reg_ctx) {
+      uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
+      uint32_t wp_idx;
+      for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++) {
+        if (reg_ctx->IsWatchpointHit(wp_idx)) {
+          WatchNotify(message);
+          return;
         }
-        SetStopInfo (StopInfo::CreateStopReasonToTrace(*this));
+      }
     }
+    SetStopInfo(StopInfo::CreateStopReasonToTrace(*this));
+  }
 }
 
-void
-FreeBSDThread::LimboNotify(const ProcessMessage &message)
-{
-    SetStopInfo (lldb::StopInfoSP(new POSIXLimboStopInfo(*this)));
+void FreeBSDThread::LimboNotify(const ProcessMessage &message) {
+  SetStopInfo(lldb::StopInfoSP(new POSIXLimboStopInfo(*this)));
 }
 
-void
-FreeBSDThread::SignalNotify(const ProcessMessage &message)
-{
-    int signo = message.GetSignal();
-    SetStopInfo (StopInfo::CreateStopReasonWithSignal(*this, signo));
+void FreeBSDThread::SignalNotify(const ProcessMessage &message) {
+  int signo = message.GetSignal();
+  SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
 }
 
-void
-FreeBSDThread::SignalDeliveredNotify(const ProcessMessage &message)
-{
-    int signo = message.GetSignal();
-    SetStopInfo (StopInfo::CreateStopReasonWithSignal(*this, signo));
+void FreeBSDThread::SignalDeliveredNotify(const ProcessMessage &message) {
+  int signo = message.GetSignal();
+  SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
 }
 
-void
-FreeBSDThread::CrashNotify(const ProcessMessage &message)
-{
-    // FIXME: Update stop reason as per bugzilla 14598
-    int signo = message.GetSignal();
+void FreeBSDThread::CrashNotify(const ProcessMessage &message) {
+  // FIXME: Update stop reason as per bugzilla 14598
+  int signo = message.GetSignal();
 
-    assert(message.GetKind() == ProcessMessage::eCrashMessage);
+  assert(message.GetKind() == ProcessMessage::eCrashMessage);
 
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
-    if (log)
-        log->Printf ("FreeBSDThread::%s () signo = %i, reason = '%s'",
-                     __FUNCTION__, signo, message.PrintCrashReason());
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+  if (log)
+    log->Printf("FreeBSDThread::%s () signo = %i, reason = '%s'", __FUNCTION__,
+                signo, message.PrintCrashReason());
 
-    SetStopInfo (lldb::StopInfoSP(new POSIXCrashStopInfo(*this, signo,
-                                                         message.GetCrashReason(),
-                                                         message.GetFaultAddress())));
+  SetStopInfo(lldb::StopInfoSP(new POSIXCrashStopInfo(
+      *this, signo, message.GetCrashReason(), message.GetFaultAddress())));
 }
 
-unsigned
-FreeBSDThread::GetRegisterIndexFromOffset(unsigned offset)
-{
-    unsigned reg = LLDB_INVALID_REGNUM;
-    ArchSpec arch = HostInfo::GetArchitecture();
+unsigned FreeBSDThread::GetRegisterIndexFromOffset(unsigned offset) {
+  unsigned reg = LLDB_INVALID_REGNUM;
+  ArchSpec arch = HostInfo::GetArchitecture();
 
-    switch (arch.GetMachine())
-    {
-    default:
-        llvm_unreachable("CPU type not supported!");
-        break;
+  switch (arch.GetMachine()) {
+  default:
+    llvm_unreachable("CPU type not supported!");
+    break;
 
-    case llvm::Triple::aarch64:
-    case llvm::Triple::arm:
-    case llvm::Triple::mips64:
-    case llvm::Triple::ppc:
-    case llvm::Triple::ppc64:
-    case llvm::Triple::x86:
-    case llvm::Triple::x86_64:
-        {
-            POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
-            reg = reg_ctx->GetRegisterIndexFromOffset(offset);
-        }
-        break;
-    }
-    return reg;
+  case llvm::Triple::aarch64:
+  case llvm::Triple::arm:
+  case llvm::Triple::mips64:
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64: {
+    POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
+    reg = reg_ctx->GetRegisterIndexFromOffset(offset);
+  } break;
+  }
+  return reg;
 }
 
-void
-FreeBSDThread::ExecNotify(const ProcessMessage &message)
-{
-    SetStopInfo (StopInfo::CreateStopReasonWithExec(*this));
+void FreeBSDThread::ExecNotify(const ProcessMessage &message) {
+  SetStopInfo(StopInfo::CreateStopReasonWithExec(*this));
 }
 
-const char *
-FreeBSDThread::GetRegisterName(unsigned reg)
-{
-    const char * name = nullptr;
-    ArchSpec arch = HostInfo::GetArchitecture();
+const char *FreeBSDThread::GetRegisterName(unsigned reg) {
+  const char *name = nullptr;
+  ArchSpec arch = HostInfo::GetArchitecture();
 
-    switch (arch.GetMachine())
-    {
-    default:
-        assert(false && "CPU type not supported!");
-        break;
+  switch (arch.GetMachine()) {
+  default:
+    assert(false && "CPU type not supported!");
+    break;
 
-    case llvm::Triple::aarch64:
-    case llvm::Triple::arm:
-    case llvm::Triple::mips64:
-    case llvm::Triple::ppc:
-    case llvm::Triple::ppc64:
-    case llvm::Triple::x86:
-    case llvm::Triple::x86_64:
-        name = GetRegisterContext()->GetRegisterName(reg);
-        break;
-    }
-    return name;
+  case llvm::Triple::aarch64:
+  case llvm::Triple::arm:
+  case llvm::Triple::mips64:
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+    name = GetRegisterContext()->GetRegisterName(reg);
+    break;
+  }
+  return name;
 }
 
-const char *
-FreeBSDThread::GetRegisterNameFromOffset(unsigned offset)
-{
-    return GetRegisterName(GetRegisterIndexFromOffset(offset));
+const char *FreeBSDThread::GetRegisterNameFromOffset(unsigned offset) {
+  return GetRegisterName(GetRegisterIndexFromOffset(offset));
 }
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/FreeBSDThread.h Tue Sep  6 15:57:50 2016
@@ -15,8 +15,8 @@
 #include <string>
 
 // Other libraries and framework includes
-#include "lldb/Target/Thread.h"
 #include "RegisterContextPOSIX.h"
+#include "lldb/Target/Thread.h"
 
 class ProcessMessage;
 class ProcessMonitor;
@@ -25,118 +25,99 @@ class POSIXBreakpointProtocol;
 //------------------------------------------------------------------------------
 // @class FreeBSDThread
 // @brief Abstraction of a FreeBSD thread.
-class FreeBSDThread
-    : public lldb_private::Thread
-{
+class FreeBSDThread : public lldb_private::Thread {
 public:
+  //------------------------------------------------------------------
+  // Constructors and destructors
+  //------------------------------------------------------------------
+  FreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
 
-    //------------------------------------------------------------------
-    // Constructors and destructors
-    //------------------------------------------------------------------
-    FreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
-
-    virtual ~FreeBSDThread();
+  virtual ~FreeBSDThread();
 
-    // POSIXThread
-    void
-    RefreshStateAfterStop() override;
+  // POSIXThread
+  void RefreshStateAfterStop() override;
 
-    // This notifies the thread when a private stop occurs.
-    void
-    DidStop () override;
+  // This notifies the thread when a private stop occurs.
+  void DidStop() override;
 
-    const char *
-    GetInfo() override;
+  const char *GetInfo() override;
 
-    void
-    SetName (const char *name) override;
+  void SetName(const char *name) override;
 
-    const char *
-    GetName () override;
+  const char *GetName() override;
 
-    lldb::RegisterContextSP
-    GetRegisterContext() override;
+  lldb::RegisterContextSP GetRegisterContext() override;
 
-    lldb::RegisterContextSP
-    CreateRegisterContextForFrame (lldb_private::StackFrame *frame) override;
+  lldb::RegisterContextSP
+  CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
 
-    lldb::addr_t
-    GetThreadPointer () override;
+  lldb::addr_t GetThreadPointer() override;
 
-    //--------------------------------------------------------------------------
-    // These functions provide a mapping from the register offset
-    // back to the register index or name for use in debugging or log
-    // output.
+  //--------------------------------------------------------------------------
+  // These functions provide a mapping from the register offset
+  // back to the register index or name for use in debugging or log
+  // output.
 
-    unsigned
-    GetRegisterIndexFromOffset(unsigned offset);
+  unsigned GetRegisterIndexFromOffset(unsigned offset);
 
-    const char *
-    GetRegisterName(unsigned reg);
+  const char *GetRegisterName(unsigned reg);
 
-    const char *
-    GetRegisterNameFromOffset(unsigned offset);
+  const char *GetRegisterNameFromOffset(unsigned offset);
 
-    //--------------------------------------------------------------------------
-    // These methods form a specialized interface to POSIX threads.
-    //
-    bool Resume();
+  //--------------------------------------------------------------------------
+  // These methods form a specialized interface to POSIX threads.
+  //
+  bool Resume();
 
-    void Notify(const ProcessMessage &message);
+  void Notify(const ProcessMessage &message);
 
-    //--------------------------------------------------------------------------
-    // These methods provide an interface to watchpoints
-    //
-    bool EnableHardwareWatchpoint(lldb_private::Watchpoint *wp);
+  //--------------------------------------------------------------------------
+  // These methods provide an interface to watchpoints
+  //
+  bool EnableHardwareWatchpoint(lldb_private::Watchpoint *wp);
 
-    bool DisableHardwareWatchpoint(lldb_private::Watchpoint *wp);
+  bool DisableHardwareWatchpoint(lldb_private::Watchpoint *wp);
 
-    uint32_t NumSupportedHardwareWatchpoints();
+  uint32_t NumSupportedHardwareWatchpoints();
 
-    uint32_t FindVacantWatchpointIndex();
+  uint32_t FindVacantWatchpointIndex();
 
 protected:
-    POSIXBreakpointProtocol *
-    GetPOSIXBreakpointProtocol ()
-    {
-        if (!m_reg_context_sp)
-            m_reg_context_sp = GetRegisterContext();
-        return m_posix_thread;
-    }
-    
-    std::unique_ptr<lldb_private::StackFrame> m_frame_ap;
-
-    lldb::BreakpointSiteSP m_breakpoint;
-
-    bool m_thread_name_valid;
-    std::string m_thread_name;
-    POSIXBreakpointProtocol *m_posix_thread;
-
-    ProcessMonitor &
-    GetMonitor();
-
-    bool
-    CalculateStopInfo() override;
-
-    void BreakNotify(const ProcessMessage &message);
-    void WatchNotify(const ProcessMessage &message);
-    virtual void TraceNotify(const ProcessMessage &message);
-    void LimboNotify(const ProcessMessage &message);
-    void SignalNotify(const ProcessMessage &message);
-    void SignalDeliveredNotify(const ProcessMessage &message);
-    void CrashNotify(const ProcessMessage &message);
-    void ExitNotify(const ProcessMessage &message);
-    void ExecNotify(const ProcessMessage &message);
-
-    lldb_private::Unwind *
-    GetUnwinder() override;
-
-    //--------------------------------------------------------------------------
-    // FreeBSDThread internal API.
-
-    // POSIXThread override
-    virtual void
-    WillResume(lldb::StateType resume_state) override;
+  POSIXBreakpointProtocol *GetPOSIXBreakpointProtocol() {
+    if (!m_reg_context_sp)
+      m_reg_context_sp = GetRegisterContext();
+    return m_posix_thread;
+  }
+
+  std::unique_ptr<lldb_private::StackFrame> m_frame_ap;
+
+  lldb::BreakpointSiteSP m_breakpoint;
+
+  bool m_thread_name_valid;
+  std::string m_thread_name;
+  POSIXBreakpointProtocol *m_posix_thread;
+
+  ProcessMonitor &GetMonitor();
+
+  bool CalculateStopInfo() override;
+
+  void BreakNotify(const ProcessMessage &message);
+  void WatchNotify(const ProcessMessage &message);
+  virtual void TraceNotify(const ProcessMessage &message);
+  void LimboNotify(const ProcessMessage &message);
+  void SignalNotify(const ProcessMessage &message);
+  void SignalDeliveredNotify(const ProcessMessage &message);
+  void CrashNotify(const ProcessMessage &message);
+  void ExitNotify(const ProcessMessage &message);
+  void ExecNotify(const ProcessMessage &message);
+
+  lldb_private::Unwind *GetUnwinder() override;
+
+  //--------------------------------------------------------------------------
+  // FreeBSDThread internal API.
+
+  // POSIXThread override
+  virtual void WillResume(lldb::StateType resume_state) override;
 };
 
 #endif // #ifndef liblldb_FreeBSDThread_H_

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp Tue Sep  6 15:57:50 2016
@@ -12,81 +12,50 @@
 using namespace lldb;
 using namespace lldb_private;
 
-
 //===----------------------------------------------------------------------===//
 // POSIXLimboStopInfo
 
-POSIXLimboStopInfo::~POSIXLimboStopInfo() { }
+POSIXLimboStopInfo::~POSIXLimboStopInfo() {}
 
-lldb::StopReason
-POSIXLimboStopInfo::GetStopReason() const
-{
-    return lldb::eStopReasonThreadExiting;
+lldb::StopReason POSIXLimboStopInfo::GetStopReason() const {
+  return lldb::eStopReasonThreadExiting;
 }
 
-const char *
-POSIXLimboStopInfo::GetDescription()
-{
-    return "thread exiting";
-}
+const char *POSIXLimboStopInfo::GetDescription() { return "thread exiting"; }
 
-bool
-POSIXLimboStopInfo::ShouldStop(Event *event_ptr)
-{
-    return false;
-}
+bool POSIXLimboStopInfo::ShouldStop(Event *event_ptr) { return false; }
 
-bool
-POSIXLimboStopInfo::ShouldNotify(Event *event_ptr)
-{
-    return false;
-}
+bool POSIXLimboStopInfo::ShouldNotify(Event *event_ptr) { return false; }
 
 //===----------------------------------------------------------------------===//
 // POSIXCrashStopInfo
 
-POSIXCrashStopInfo::POSIXCrashStopInfo(FreeBSDThread &thread,
-                                       uint32_t status,
+POSIXCrashStopInfo::POSIXCrashStopInfo(FreeBSDThread &thread, uint32_t status,
                                        CrashReason reason,
                                        lldb::addr_t fault_addr)
-    : POSIXStopInfo(thread, status)
-{
-    m_description = ::GetCrashReasonString(reason, fault_addr);
+    : POSIXStopInfo(thread, status) {
+  m_description = ::GetCrashReasonString(reason, fault_addr);
 }
 
-POSIXCrashStopInfo::~POSIXCrashStopInfo() { }
+POSIXCrashStopInfo::~POSIXCrashStopInfo() {}
 
-lldb::StopReason
-POSIXCrashStopInfo::GetStopReason() const
-{
-    return lldb::eStopReasonException;
+lldb::StopReason POSIXCrashStopInfo::GetStopReason() const {
+  return lldb::eStopReasonException;
 }
 
 //===----------------------------------------------------------------------===//
 // POSIXNewThreadStopInfo
 
-POSIXNewThreadStopInfo::~POSIXNewThreadStopInfo() { }
+POSIXNewThreadStopInfo::~POSIXNewThreadStopInfo() {}
 
-lldb::StopReason
-POSIXNewThreadStopInfo::GetStopReason() const
-{
-    return lldb::eStopReasonNone;
+lldb::StopReason POSIXNewThreadStopInfo::GetStopReason() const {
+  return lldb::eStopReasonNone;
 }
 
-const char *
-POSIXNewThreadStopInfo::GetDescription()
-{
-    return "thread spawned";
+const char *POSIXNewThreadStopInfo::GetDescription() {
+  return "thread spawned";
 }
 
-bool
-POSIXNewThreadStopInfo::ShouldStop(Event *event_ptr)
-{
-    return false;
-}
+bool POSIXNewThreadStopInfo::ShouldStop(Event *event_ptr) { return false; }
 
-bool
-POSIXNewThreadStopInfo::ShouldNotify(Event *event_ptr)
-{
-    return false;
-}
+bool POSIXNewThreadStopInfo::ShouldNotify(Event *event_ptr) { return false; }

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/POSIXStopInfo.h Tue Sep  6 15:57:50 2016
@@ -25,58 +25,42 @@
 /// @class POSIXStopInfo
 /// @brief Simple base class for all POSIX-specific StopInfo objects.
 ///
-class POSIXStopInfo
-    : public lldb_private::StopInfo
-{
+class POSIXStopInfo : public lldb_private::StopInfo {
 public:
-    POSIXStopInfo(lldb_private::Thread &thread, uint32_t status)
-        : StopInfo(thread, status)
-        { }
+  POSIXStopInfo(lldb_private::Thread &thread, uint32_t status)
+      : StopInfo(thread, status) {}
 };
 
 //===----------------------------------------------------------------------===//
 /// @class POSIXLimboStopInfo
 /// @brief Represents the stop state of a process ready to exit.
 ///
-class POSIXLimboStopInfo
-    : public POSIXStopInfo
-{
+class POSIXLimboStopInfo : public POSIXStopInfo {
 public:
-    POSIXLimboStopInfo(FreeBSDThread &thread)
-        : POSIXStopInfo(thread, 0)
-        { }
+  POSIXLimboStopInfo(FreeBSDThread &thread) : POSIXStopInfo(thread, 0) {}
 
-    ~POSIXLimboStopInfo();
+  ~POSIXLimboStopInfo();
 
-    lldb::StopReason
-    GetStopReason() const;
+  lldb::StopReason GetStopReason() const;
 
-    const char *
-    GetDescription();
+  const char *GetDescription();
 
-    bool
-    ShouldStop(lldb_private::Event *event_ptr);
+  bool ShouldStop(lldb_private::Event *event_ptr);
 
-    bool
-    ShouldNotify(lldb_private::Event *event_ptr);
+  bool ShouldNotify(lldb_private::Event *event_ptr);
 };
 
-
 //===----------------------------------------------------------------------===//
 /// @class POSIXCrashStopInfo
 /// @brief Represents the stop state of process that is ready to crash.
 ///
-class POSIXCrashStopInfo
-    : public POSIXStopInfo
-{
+class POSIXCrashStopInfo : public POSIXStopInfo {
 public:
-    POSIXCrashStopInfo(FreeBSDThread &thread, uint32_t status,
-                       CrashReason reason,
-                       lldb::addr_t fault_addr);
-    ~POSIXCrashStopInfo();
+  POSIXCrashStopInfo(FreeBSDThread &thread, uint32_t status, CrashReason reason,
+                     lldb::addr_t fault_addr);
+  ~POSIXCrashStopInfo();
 
-    lldb::StopReason
-    GetStopReason() const;
+  lldb::StopReason GetStopReason() const;
 };
 
 //===----------------------------------------------------------------------===//
@@ -84,27 +68,19 @@ public:
 /// @brief Represents the stop state of process when a new thread is spawned.
 ///
 
-class POSIXNewThreadStopInfo
-    : public POSIXStopInfo
-{
+class POSIXNewThreadStopInfo : public POSIXStopInfo {
 public:
-    POSIXNewThreadStopInfo (FreeBSDThread &thread)
-        : POSIXStopInfo (thread, 0)
-        { }
+  POSIXNewThreadStopInfo(FreeBSDThread &thread) : POSIXStopInfo(thread, 0) {}
 
-    ~POSIXNewThreadStopInfo();
+  ~POSIXNewThreadStopInfo();
 
-    lldb::StopReason
-    GetStopReason() const;
+  lldb::StopReason GetStopReason() const;
 
-    const char *
-    GetDescription();
+  const char *GetDescription();
 
-    bool
-    ShouldStop(lldb_private::Event *event_ptr);
+  bool ShouldStop(lldb_private::Event *event_ptr);
 
-    bool
-    ShouldNotify(lldb_private::Event *event_ptr);
+  bool ShouldNotify(lldb_private::Event *event_ptr);
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- ProcessFreeBSD.cpp ----------------------------------------*- C++ -*-===//
+//===-- ProcessFreeBSD.cpp ----------------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -21,12 +22,12 @@
 #include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/Target.h"
 
-#include "ProcessFreeBSD.h"
-#include "ProcessPOSIXLog.h"
-#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
+#include "FreeBSDThread.h"
 #include "Plugins/Process/Utility/FreeBSDSignals.h"
+#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
+#include "ProcessFreeBSD.h"
 #include "ProcessMonitor.h"
-#include "FreeBSDThread.h"
+#include "ProcessPOSIXLog.h"
 
 // Other libraries and framework includes
 #include "lldb/Breakpoint/BreakpointLocation.h"
@@ -44,18 +45,14 @@
 
 #include "lldb/Host/posix/Fcntl.h"
 
-
 using namespace lldb;
 using namespace lldb_private;
 
-namespace
-{
-    UnixSignalsSP&
-    GetFreeBSDSignals ()
-    {
-        static UnixSignalsSP s_freebsd_signals_sp (new FreeBSDSignals ());
-        return s_freebsd_signals_sp;
-    }
+namespace {
+UnixSignalsSP &GetFreeBSDSignals() {
+  static UnixSignalsSP s_freebsd_signals_sp(new FreeBSDSignals());
+  return s_freebsd_signals_sp;
+}
 }
 
 //------------------------------------------------------------------------------
@@ -64,869 +61,756 @@ namespace
 lldb::ProcessSP
 ProcessFreeBSD::CreateInstance(lldb::TargetSP target_sp,
                                lldb::ListenerSP listener_sp,
-                               const FileSpec *crash_file_path)
-{
-    lldb::ProcessSP process_sp;
-    if (crash_file_path == NULL)
-        process_sp.reset(new ProcessFreeBSD (target_sp, listener_sp, GetFreeBSDSignals()));
-    return process_sp;
+                               const FileSpec *crash_file_path) {
+  lldb::ProcessSP process_sp;
+  if (crash_file_path == NULL)
+    process_sp.reset(
+        new ProcessFreeBSD(target_sp, listener_sp, GetFreeBSDSignals()));
+  return process_sp;
 }
 
-void
-ProcessFreeBSD::Initialize()
-{
-    static std::once_flag g_once_flag;
+void ProcessFreeBSD::Initialize() {
+  static std::once_flag g_once_flag;
 
-    std::call_once(g_once_flag, []() {
-        PluginManager::RegisterPlugin(GetPluginNameStatic(),
-                                      GetPluginDescriptionStatic(),
-                                      CreateInstance);
-        ProcessPOSIXLog::Initialize(GetPluginNameStatic());
-    });
+  std::call_once(g_once_flag, []() {
+    PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                  GetPluginDescriptionStatic(), CreateInstance);
+    ProcessPOSIXLog::Initialize(GetPluginNameStatic());
+  });
 }
 
-lldb_private::ConstString
-ProcessFreeBSD::GetPluginNameStatic()
-{
-    static ConstString g_name("freebsd");
-    return g_name;
+lldb_private::ConstString ProcessFreeBSD::GetPluginNameStatic() {
+  static ConstString g_name("freebsd");
+  return g_name;
 }
 
-const char *
-ProcessFreeBSD::GetPluginDescriptionStatic()
-{
-    return "Process plugin for FreeBSD";
+const char *ProcessFreeBSD::GetPluginDescriptionStatic() {
+  return "Process plugin for FreeBSD";
 }
 
 //------------------------------------------------------------------------------
 // ProcessInterface protocol.
 
-lldb_private::ConstString
-ProcessFreeBSD::GetPluginName()
-{
-    return GetPluginNameStatic();
+lldb_private::ConstString ProcessFreeBSD::GetPluginName() {
+  return GetPluginNameStatic();
 }
 
-uint32_t
-ProcessFreeBSD::GetPluginVersion()
-{
-    return 1;
-}
-
-void
-ProcessFreeBSD::Terminate()
-{
-}
-
-Error
-ProcessFreeBSD::DoDetach(bool keep_stopped)
-{
-    Error error;
-    if (keep_stopped)
-    {
-        error.SetErrorString("Detaching with keep_stopped true is not currently supported on FreeBSD.");
-        return error;
-    }
-
-    error = m_monitor->Detach(GetID());
+uint32_t ProcessFreeBSD::GetPluginVersion() { return 1; }
 
-    if (error.Success())
-        SetPrivateState(eStateDetached);
+void ProcessFreeBSD::Terminate() {}
 
+Error ProcessFreeBSD::DoDetach(bool keep_stopped) {
+  Error error;
+  if (keep_stopped) {
+    error.SetErrorString("Detaching with keep_stopped true is not currently "
+                         "supported on FreeBSD.");
     return error;
-}
-
-Error
-ProcessFreeBSD::DoResume()
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
+  }
 
-    SetPrivateState(eStateRunning);
+  error = m_monitor->Detach(GetID());
 
-    std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-    bool do_step = false;
+  if (error.Success())
+    SetPrivateState(eStateDetached);
 
-    for (tid_collection::const_iterator t_pos = m_run_tids.begin(), t_end = m_run_tids.end(); t_pos != t_end; ++t_pos)
-    {
-        m_monitor->ThreadSuspend(*t_pos, false);
-    }
-    for (tid_collection::const_iterator t_pos = m_step_tids.begin(), t_end = m_step_tids.end(); t_pos != t_end; ++t_pos)
-    {
-        m_monitor->ThreadSuspend(*t_pos, false);
-        do_step = true;
-    }
-    for (tid_collection::const_iterator t_pos = m_suspend_tids.begin(), t_end = m_suspend_tids.end(); t_pos != t_end; ++t_pos)
-    {
-        m_monitor->ThreadSuspend(*t_pos, true);
-        // XXX Cannot PT_CONTINUE properly with suspended threads.
-        do_step = true;
-    }
-
-    if (log)
-        log->Printf("process %" PRIu64 " resuming (%s)", GetID(), do_step ? "step" : "continue");
-    if (do_step)
-        m_monitor->SingleStep(GetID(), m_resume_signo);
-    else
-        m_monitor->Resume(GetID(), m_resume_signo);
-
-    return Error();
+  return error;
 }
 
-bool
-ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
-    if (log)
-        log->Printf("ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__, GetID());
+Error ProcessFreeBSD::DoResume() {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
 
-    std::vector<lldb::pid_t> tds;
-    if (!GetMonitor().GetCurrentThreadIDs(tds))
-    {
-        return false;
-    }
+  SetPrivateState(eStateRunning);
 
-    ThreadList old_thread_list_copy(old_thread_list);
-    for (size_t i = 0; i < tds.size(); ++i)
-    {
-        tid_t tid = tds[i];
-        ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByID(tid, false));
-        if (!thread_sp)
-        {
-            thread_sp.reset(new FreeBSDThread(*this, tid));
-            if (log)
-                log->Printf("ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, tid);
-        }
-        else
-        {
-            if (log)
-                log->Printf("ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__, tid);
-        }
-        new_thread_list.AddThread(thread_sp);
-    }
-    for (size_t i = 0; i < old_thread_list_copy.GetSize(false); ++i)
-    {
-        ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false));
-        if (old_thread_sp)
-        {
-            if (log)
-                log->Printf("ProcessFreeBSD::%s remove tid", __FUNCTION__);
-        }
-    }
+  std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
+  bool do_step = false;
 
-    return true;
-}
+  for (tid_collection::const_iterator t_pos = m_run_tids.begin(),
+                                      t_end = m_run_tids.end();
+       t_pos != t_end; ++t_pos) {
+    m_monitor->ThreadSuspend(*t_pos, false);
+  }
+  for (tid_collection::const_iterator t_pos = m_step_tids.begin(),
+                                      t_end = m_step_tids.end();
+       t_pos != t_end; ++t_pos) {
+    m_monitor->ThreadSuspend(*t_pos, false);
+    do_step = true;
+  }
+  for (tid_collection::const_iterator t_pos = m_suspend_tids.begin(),
+                                      t_end = m_suspend_tids.end();
+       t_pos != t_end; ++t_pos) {
+    m_monitor->ThreadSuspend(*t_pos, true);
+    // XXX Cannot PT_CONTINUE properly with suspended threads.
+    do_step = true;
+  }
 
-Error
-ProcessFreeBSD::WillResume()
-{
-    m_resume_signo = 0;
-    m_suspend_tids.clear();
-    m_run_tids.clear();
-    m_step_tids.clear();
-    return Process::WillResume();
-}
+  if (log)
+    log->Printf("process %" PRIu64 " resuming (%s)", GetID(),
+                do_step ? "step" : "continue");
+  if (do_step)
+    m_monitor->SingleStep(GetID(), m_resume_signo);
+  else
+    m_monitor->Resume(GetID(), m_resume_signo);
 
-void
-ProcessFreeBSD::SendMessage(const ProcessMessage &message)
-{
-    std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
+  return Error();
+}
 
-    switch (message.GetKind())
-    {
-    case ProcessMessage::eInvalidMessage:
-        return;
+bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list,
+                                      ThreadList &new_thread_list) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+  if (log)
+    log->Printf("ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__,
+                GetID());
 
-    case ProcessMessage::eAttachMessage:
-        SetPrivateState(eStateStopped);
-        return;
+  std::vector<lldb::pid_t> tds;
+  if (!GetMonitor().GetCurrentThreadIDs(tds)) {
+    return false;
+  }
 
-    case ProcessMessage::eLimboMessage:
-    case ProcessMessage::eExitMessage:
-        SetExitStatus(message.GetExitStatus(), NULL);
-        break;
-
-    case ProcessMessage::eSignalMessage:
-    case ProcessMessage::eSignalDeliveredMessage:
-    case ProcessMessage::eBreakpointMessage:
-    case ProcessMessage::eTraceMessage:
-    case ProcessMessage::eWatchpointMessage:
-    case ProcessMessage::eCrashMessage:
-        SetPrivateState(eStateStopped);
-        break;
-
-    case ProcessMessage::eNewThreadMessage:
-        llvm_unreachable("eNewThreadMessage unexpected on FreeBSD");
-        break;
-
-    case ProcessMessage::eExecMessage:
-        SetPrivateState(eStateStopped);
-        break;
+  ThreadList old_thread_list_copy(old_thread_list);
+  for (size_t i = 0; i < tds.size(); ++i) {
+    tid_t tid = tds[i];
+    ThreadSP thread_sp(old_thread_list_copy.RemoveThreadByID(tid, false));
+    if (!thread_sp) {
+      thread_sp.reset(new FreeBSDThread(*this, tid));
+      if (log)
+        log->Printf("ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, tid);
+    } else {
+      if (log)
+        log->Printf("ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__,
+                    tid);
     }
+    new_thread_list.AddThread(thread_sp);
+  }
+  for (size_t i = 0; i < old_thread_list_copy.GetSize(false); ++i) {
+    ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false));
+    if (old_thread_sp) {
+      if (log)
+        log->Printf("ProcessFreeBSD::%s remove tid", __FUNCTION__);
+    }
+  }
+
+  return true;
+}
+
+Error ProcessFreeBSD::WillResume() {
+  m_resume_signo = 0;
+  m_suspend_tids.clear();
+  m_run_tids.clear();
+  m_step_tids.clear();
+  return Process::WillResume();
+}
+
+void ProcessFreeBSD::SendMessage(const ProcessMessage &message) {
+  std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
+
+  switch (message.GetKind()) {
+  case ProcessMessage::eInvalidMessage:
+    return;
+
+  case ProcessMessage::eAttachMessage:
+    SetPrivateState(eStateStopped);
+    return;
+
+  case ProcessMessage::eLimboMessage:
+  case ProcessMessage::eExitMessage:
+    SetExitStatus(message.GetExitStatus(), NULL);
+    break;
+
+  case ProcessMessage::eSignalMessage:
+  case ProcessMessage::eSignalDeliveredMessage:
+  case ProcessMessage::eBreakpointMessage:
+  case ProcessMessage::eTraceMessage:
+  case ProcessMessage::eWatchpointMessage:
+  case ProcessMessage::eCrashMessage:
+    SetPrivateState(eStateStopped);
+    break;
+
+  case ProcessMessage::eNewThreadMessage:
+    llvm_unreachable("eNewThreadMessage unexpected on FreeBSD");
+    break;
+
+  case ProcessMessage::eExecMessage:
+    SetPrivateState(eStateStopped);
+    break;
+  }
 
-    m_message_queue.push(message);
+  m_message_queue.push(message);
 }
 
 //------------------------------------------------------------------------------
 // Constructors and destructors.
 
-ProcessFreeBSD::ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, UnixSignalsSP &unix_signals_sp)
+ProcessFreeBSD::ProcessFreeBSD(lldb::TargetSP target_sp,
+                               lldb::ListenerSP listener_sp,
+                               UnixSignalsSP &unix_signals_sp)
     : Process(target_sp, listener_sp, unix_signals_sp),
-      m_byte_order(endian::InlHostByteOrder()),
-      m_monitor(NULL),
-      m_module(NULL),
-      m_message_mutex(),
-      m_exit_now(false),
-      m_seen_initial_stop(),
-      m_resume_signo(0)
-{
-    // FIXME: Putting this code in the ctor and saving the byte order in a
-    // member variable is a hack to avoid const qual issues in GetByteOrder.
-    lldb::ModuleSP module = GetTarget().GetExecutableModule();
-    if (module && module->GetObjectFile())
-        m_byte_order = module->GetObjectFile()->GetByteOrder();
+      m_byte_order(endian::InlHostByteOrder()), m_monitor(NULL), m_module(NULL),
+      m_message_mutex(), m_exit_now(false), m_seen_initial_stop(),
+      m_resume_signo(0) {
+  // FIXME: Putting this code in the ctor and saving the byte order in a
+  // member variable is a hack to avoid const qual issues in GetByteOrder.
+  lldb::ModuleSP module = GetTarget().GetExecutableModule();
+  if (module && module->GetObjectFile())
+    m_byte_order = module->GetObjectFile()->GetByteOrder();
 }
 
-ProcessFreeBSD::~ProcessFreeBSD()
-{
-    delete m_monitor;
-}
+ProcessFreeBSD::~ProcessFreeBSD() { delete m_monitor; }
 
 //------------------------------------------------------------------------------
 // Process protocol.
-void
-ProcessFreeBSD::Finalize()
-{
+void ProcessFreeBSD::Finalize() {
   Process::Finalize();
 
   if (m_monitor)
     m_monitor->StopMonitor();
 }
 
-bool
-ProcessFreeBSD::CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name)
-{
-    // For now we are just making sure the file exists for a given module
-    ModuleSP exe_module_sp(target_sp->GetExecutableModule());
-    if (exe_module_sp.get())
-        return exe_module_sp->GetFileSpec().Exists();
-    // If there is no executable module, we return true since we might be preparing to attach.
-    return true;
+bool ProcessFreeBSD::CanDebug(lldb::TargetSP target_sp,
+                              bool plugin_specified_by_name) {
+  // For now we are just making sure the file exists for a given module
+  ModuleSP exe_module_sp(target_sp->GetExecutableModule());
+  if (exe_module_sp.get())
+    return exe_module_sp->GetFileSpec().Exists();
+  // If there is no executable module, we return true since we might be
+  // preparing to attach.
+  return true;
 }
 
-Error
-ProcessFreeBSD::DoAttachToProcessWithID (lldb::pid_t pid,  const ProcessAttachInfo &attach_info)
-{
-    Error error;
-    assert(m_monitor == NULL);
+Error ProcessFreeBSD::DoAttachToProcessWithID(
+    lldb::pid_t pid, const ProcessAttachInfo &attach_info) {
+  Error error;
+  assert(m_monitor == NULL);
 
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
-    if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
-        log->Printf ("ProcessFreeBSD::%s(pid = %" PRIi64 ")", __FUNCTION__, GetID());
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+  if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
+    log->Printf("ProcessFreeBSD::%s(pid = %" PRIi64 ")", __FUNCTION__, GetID());
 
-    m_monitor = new ProcessMonitor(this, pid, error);
+  m_monitor = new ProcessMonitor(this, pid, error);
 
-    if (!error.Success())
-        return error;
+  if (!error.Success())
+    return error;
 
-    PlatformSP platform_sp (GetTarget().GetPlatform ());
-    assert (platform_sp.get());
-    if (!platform_sp)
-        return error;  // FIXME: Detatch?
-
-    // Find out what we can about this process
-    ProcessInstanceInfo process_info;
-    platform_sp->GetProcessInfo (pid, process_info);
-
-    // Resolve the executable module
-    ModuleSP exe_module_sp;
-    FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
-    ModuleSpec exe_module_spec(process_info.GetExecutableFile(), GetTarget().GetArchitecture());
-    error = platform_sp->ResolveExecutable(exe_module_spec,
-                                           exe_module_sp,
-                                           executable_search_paths.GetSize() ? &executable_search_paths : NULL);
-    if (!error.Success())
-        return error;
+  PlatformSP platform_sp(GetTarget().GetPlatform());
+  assert(platform_sp.get());
+  if (!platform_sp)
+    return error; // FIXME: Detatch?
 
-    // Fix the target architecture if necessary
-    const ArchSpec &module_arch = exe_module_sp->GetArchitecture();
-    if (module_arch.IsValid() && !GetTarget().GetArchitecture().IsExactMatch(module_arch))
-        GetTarget().SetArchitecture(module_arch);
+  // Find out what we can about this process
+  ProcessInstanceInfo process_info;
+  platform_sp->GetProcessInfo(pid, process_info);
 
-    // Initialize the target module list
-    GetTarget().SetExecutableModule (exe_module_sp, true);
+  // Resolve the executable module
+  ModuleSP exe_module_sp;
+  FileSpecList executable_search_paths(
+      Target::GetDefaultExecutableSearchPaths());
+  ModuleSpec exe_module_spec(process_info.GetExecutableFile(),
+                             GetTarget().GetArchitecture());
+  error = platform_sp->ResolveExecutable(
+      exe_module_spec, exe_module_sp,
+      executable_search_paths.GetSize() ? &executable_search_paths : NULL);
+  if (!error.Success())
+    return error;
 
-    SetSTDIOFileDescriptor(m_monitor->GetTerminalFD());
+  // Fix the target architecture if necessary
+  const ArchSpec &module_arch = exe_module_sp->GetArchitecture();
+  if (module_arch.IsValid() &&
+      !GetTarget().GetArchitecture().IsExactMatch(module_arch))
+    GetTarget().SetArchitecture(module_arch);
 
-    SetID(pid);
+  // Initialize the target module list
+  GetTarget().SetExecutableModule(exe_module_sp, true);
 
-    return error;
+  SetSTDIOFileDescriptor(m_monitor->GetTerminalFD());
+
+  SetID(pid);
+
+  return error;
 }
 
-Error
-ProcessFreeBSD::WillLaunch(Module* module)
-{
-    Error error;
-    return error;
+Error ProcessFreeBSD::WillLaunch(Module *module) {
+  Error error;
+  return error;
 }
 
 FileSpec
 ProcessFreeBSD::GetFileSpec(const lldb_private::FileAction *file_action,
-                          const FileSpec &default_file_spec,
-                          const FileSpec &dbg_pts_file_spec)
-{
-    FileSpec file_spec{};
-
-    if (file_action && file_action->GetAction() == FileAction::eFileActionOpen)
-    {
-        file_spec = file_action->GetFileSpec();
-        // By default the stdio paths passed in will be pseudo-terminal
-        // (/dev/pts). If so, convert to using a different default path
-        // instead to redirect I/O to the debugger console. This should
-        // also handle user overrides to /dev/null or a different file.
-        if (!file_spec || file_spec == dbg_pts_file_spec)
-            file_spec = default_file_spec;
-    }
-    return file_spec;
-}
-
-Error
-ProcessFreeBSD::DoLaunch (Module *module,
-                        ProcessLaunchInfo &launch_info)
-{
-    Error error;
-    assert(m_monitor == NULL);
-
-    FileSpec working_dir = launch_info.GetWorkingDirectory();
-    if (working_dir &&
-            (!working_dir.ResolvePath() ||
-             working_dir.GetFileType() != FileSpec::eFileTypeDirectory))
-    {
-        error.SetErrorStringWithFormat("No such file or directory: %s",
-                working_dir.GetCString());
-        return error;
-    }
-
-    SetPrivateState(eStateLaunching);
-
-    const lldb_private::FileAction *file_action;
-
-    // Default of empty will mean to use existing open file descriptors
-    FileSpec stdin_file_spec{};
-    FileSpec stdout_file_spec{};
-    FileSpec stderr_file_spec{};
-
-    const FileSpec dbg_pts_file_spec{launch_info.GetPTY().GetSlaveName(NULL,0), false};
-
-    file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
-    stdin_file_spec = GetFileSpec(file_action, stdin_file_spec, dbg_pts_file_spec);
-
-    file_action = launch_info.GetFileActionForFD (STDOUT_FILENO);
-    stdout_file_spec = GetFileSpec(file_action, stdout_file_spec, dbg_pts_file_spec);
-
-    file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
-    stderr_file_spec = GetFileSpec(file_action, stderr_file_spec, dbg_pts_file_spec);
-
-    m_monitor = new ProcessMonitor(this,
-                                   module,
-                                   launch_info.GetArguments().GetConstArgumentVector(),
-                                   launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
-                                   stdin_file_spec,
-                                   stdout_file_spec,
-                                   stderr_file_spec,
-                                   working_dir,
-                                   launch_info,
-                                   error);
-
-    m_module = module;
-
-    if (!error.Success())
-        return error;
-
-    int terminal = m_monitor->GetTerminalFD();
-    if (terminal >= 0) {
-        // The reader thread will close the file descriptor when done, so we pass it a copy.
+                            const FileSpec &default_file_spec,
+                            const FileSpec &dbg_pts_file_spec) {
+  FileSpec file_spec{};
+
+  if (file_action && file_action->GetAction() == FileAction::eFileActionOpen) {
+    file_spec = file_action->GetFileSpec();
+    // By default the stdio paths passed in will be pseudo-terminal
+    // (/dev/pts). If so, convert to using a different default path
+    // instead to redirect I/O to the debugger console. This should
+    // also handle user overrides to /dev/null or a different file.
+    if (!file_spec || file_spec == dbg_pts_file_spec)
+      file_spec = default_file_spec;
+  }
+  return file_spec;
+}
+
+Error ProcessFreeBSD::DoLaunch(Module *module, ProcessLaunchInfo &launch_info) {
+  Error error;
+  assert(m_monitor == NULL);
+
+  FileSpec working_dir = launch_info.GetWorkingDirectory();
+  if (working_dir &&
+      (!working_dir.ResolvePath() ||
+       working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) {
+    error.SetErrorStringWithFormat("No such file or directory: %s",
+                                   working_dir.GetCString());
+    return error;
+  }
+
+  SetPrivateState(eStateLaunching);
+
+  const lldb_private::FileAction *file_action;
+
+  // Default of empty will mean to use existing open file descriptors
+  FileSpec stdin_file_spec{};
+  FileSpec stdout_file_spec{};
+  FileSpec stderr_file_spec{};
+
+  const FileSpec dbg_pts_file_spec{launch_info.GetPTY().GetSlaveName(NULL, 0),
+                                   false};
+
+  file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
+  stdin_file_spec =
+      GetFileSpec(file_action, stdin_file_spec, dbg_pts_file_spec);
+
+  file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
+  stdout_file_spec =
+      GetFileSpec(file_action, stdout_file_spec, dbg_pts_file_spec);
+
+  file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
+  stderr_file_spec =
+      GetFileSpec(file_action, stderr_file_spec, dbg_pts_file_spec);
+
+  m_monitor = new ProcessMonitor(
+      this, module, launch_info.GetArguments().GetConstArgumentVector(),
+      launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
+      stdin_file_spec, stdout_file_spec, stderr_file_spec, working_dir,
+      launch_info, error);
+
+  m_module = module;
+
+  if (!error.Success())
+    return error;
+
+  int terminal = m_monitor->GetTerminalFD();
+  if (terminal >= 0) {
+// The reader thread will close the file descriptor when done, so we pass it a
+// copy.
 #ifdef F_DUPFD_CLOEXEC
-        int stdio = fcntl(terminal, F_DUPFD_CLOEXEC, 0);
-        if (stdio == -1) {
-            error.SetErrorToErrno();
-            return error;
-        }
+    int stdio = fcntl(terminal, F_DUPFD_CLOEXEC, 0);
+    if (stdio == -1) {
+      error.SetErrorToErrno();
+      return error;
+    }
 #else
-        // Special case when F_DUPFD_CLOEXEC does not exist (Debian kFreeBSD)
-        int stdio = fcntl(terminal, F_DUPFD, 0);
-        if (stdio == -1) {
-            error.SetErrorToErrno();
-            return error;
-        }
-        stdio = fcntl(terminal, F_SETFD, FD_CLOEXEC);
-        if (stdio == -1) {
-            error.SetErrorToErrno();
-            return error;
-        }
-#endif
-        SetSTDIOFileDescriptor(stdio);
+    // Special case when F_DUPFD_CLOEXEC does not exist (Debian kFreeBSD)
+    int stdio = fcntl(terminal, F_DUPFD, 0);
+    if (stdio == -1) {
+      error.SetErrorToErrno();
+      return error;
+    }
+    stdio = fcntl(terminal, F_SETFD, FD_CLOEXEC);
+    if (stdio == -1) {
+      error.SetErrorToErrno();
+      return error;
     }
+#endif
+    SetSTDIOFileDescriptor(stdio);
+  }
 
-    SetID(m_monitor->GetPID());
-    return error;
+  SetID(m_monitor->GetPID());
+  return error;
 }
 
-void
-ProcessFreeBSD::DidLaunch()
-{
-}
+void ProcessFreeBSD::DidLaunch() {}
 
-addr_t
-ProcessFreeBSD::GetImageInfoAddress()
-{
-    Target *target = &GetTarget();
-    ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile();
-    Address addr = obj_file->GetImageInfoAddress(target);
+addr_t ProcessFreeBSD::GetImageInfoAddress() {
+  Target *target = &GetTarget();
+  ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile();
+  Address addr = obj_file->GetImageInfoAddress(target);
 
-    if (addr.IsValid())
-        return addr.GetLoadAddress(target);
-    return LLDB_INVALID_ADDRESS;
+  if (addr.IsValid())
+    return addr.GetLoadAddress(target);
+  return LLDB_INVALID_ADDRESS;
 }
 
-Error
-ProcessFreeBSD::DoHalt(bool &caused_stop)
-{
-    Error error;
+Error ProcessFreeBSD::DoHalt(bool &caused_stop) {
+  Error error;
 
-    if (IsStopped())
-    {
-        caused_stop = false;
-    }
-    else if (kill(GetID(), SIGSTOP))
-    {
-        caused_stop = false;
-        error.SetErrorToErrno();
-    }
-    else
-    {
-        caused_stop = true;
-    }
-    return error;
+  if (IsStopped()) {
+    caused_stop = false;
+  } else if (kill(GetID(), SIGSTOP)) {
+    caused_stop = false;
+    error.SetErrorToErrno();
+  } else {
+    caused_stop = true;
+  }
+  return error;
 }
 
-Error
-ProcessFreeBSD::DoSignal(int signal)
-{
-    Error error;
+Error ProcessFreeBSD::DoSignal(int signal) {
+  Error error;
 
-    if (kill(GetID(), signal))
-        error.SetErrorToErrno();
+  if (kill(GetID(), signal))
+    error.SetErrorToErrno();
 
-    return error;
+  return error;
 }
 
-Error
-ProcessFreeBSD::DoDestroy()
-{
-    Error error;
-
-    if (!HasExited())
-    {
-        assert(m_monitor);
-        m_exit_now = true;
-        if (GetID() == LLDB_INVALID_PROCESS_ID)
-        {
-            error.SetErrorString("invalid process id");
-            return error;
-        }
-        if (!m_monitor->Kill())
-        {
-            error.SetErrorToErrno();
-            return error;
-        }
-
-        SetPrivateState(eStateExited);
-    }
-
-    return error;
-}
+Error ProcessFreeBSD::DoDestroy() {
+  Error error;
 
-void
-ProcessFreeBSD::DoDidExec()
-{
-    Target *target = &GetTarget();
-    if (target)
-    {
-        PlatformSP platform_sp (target->GetPlatform());
-        assert (platform_sp.get());
-        if (platform_sp)
-        {
-            ProcessInstanceInfo process_info;
-            platform_sp->GetProcessInfo(GetID(), process_info);
-            ModuleSP exe_module_sp;
-            ModuleSpec exe_module_spec(process_info.GetExecutableFile(), target->GetArchitecture());
-            FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
-            Error error = platform_sp->ResolveExecutable(exe_module_spec,
-                                                         exe_module_sp,
-                                                         executable_search_paths.GetSize() ? &executable_search_paths : NULL);
-            if (!error.Success())
-                return;
-            target->SetExecutableModule(exe_module_sp, true);
-        }
+  if (!HasExited()) {
+    assert(m_monitor);
+    m_exit_now = true;
+    if (GetID() == LLDB_INVALID_PROCESS_ID) {
+      error.SetErrorString("invalid process id");
+      return error;
+    }
+    if (!m_monitor->Kill()) {
+      error.SetErrorToErrno();
+      return error;
+    }
+
+    SetPrivateState(eStateExited);
+  }
+
+  return error;
+}
+
+void ProcessFreeBSD::DoDidExec() {
+  Target *target = &GetTarget();
+  if (target) {
+    PlatformSP platform_sp(target->GetPlatform());
+    assert(platform_sp.get());
+    if (platform_sp) {
+      ProcessInstanceInfo process_info;
+      platform_sp->GetProcessInfo(GetID(), process_info);
+      ModuleSP exe_module_sp;
+      ModuleSpec exe_module_spec(process_info.GetExecutableFile(),
+                                 target->GetArchitecture());
+      FileSpecList executable_search_paths(
+          Target::GetDefaultExecutableSearchPaths());
+      Error error = platform_sp->ResolveExecutable(
+          exe_module_spec, exe_module_sp,
+          executable_search_paths.GetSize() ? &executable_search_paths : NULL);
+      if (!error.Success())
+        return;
+      target->SetExecutableModule(exe_module_sp, true);
     }
+  }
 }
 
-bool
-ProcessFreeBSD::AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid)
-{
-    bool added_to_set = false;
-    ThreadStopSet::iterator it = m_seen_initial_stop.find(stop_tid);
-    if (it == m_seen_initial_stop.end())
-    {
-        m_seen_initial_stop.insert(stop_tid);
-        added_to_set = true;
-    }
-    return added_to_set;
+bool ProcessFreeBSD::AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid) {
+  bool added_to_set = false;
+  ThreadStopSet::iterator it = m_seen_initial_stop.find(stop_tid);
+  if (it == m_seen_initial_stop.end()) {
+    m_seen_initial_stop.insert(stop_tid);
+    added_to_set = true;
+  }
+  return added_to_set;
 }
 
-bool
-ProcessFreeBSD::WaitingForInitialStop(lldb::tid_t stop_tid)
-{
-    return (m_seen_initial_stop.find(stop_tid) == m_seen_initial_stop.end());
+bool ProcessFreeBSD::WaitingForInitialStop(lldb::tid_t stop_tid) {
+  return (m_seen_initial_stop.find(stop_tid) == m_seen_initial_stop.end());
 }
 
 FreeBSDThread *
-ProcessFreeBSD::CreateNewFreeBSDThread(lldb_private::Process &process, lldb::tid_t tid)
-{
-    return new FreeBSDThread(process, tid);
-}
-
-void
-ProcessFreeBSD::RefreshStateAfterStop()
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
-    if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
-        log->Printf ("ProcessFreeBSD::%s(), message_queue size = %d", __FUNCTION__, (int)m_message_queue.size());
+ProcessFreeBSD::CreateNewFreeBSDThread(lldb_private::Process &process,
+                                       lldb::tid_t tid) {
+  return new FreeBSDThread(process, tid);
+}
+
+void ProcessFreeBSD::RefreshStateAfterStop() {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+  if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
+    log->Printf("ProcessFreeBSD::%s(), message_queue size = %d", __FUNCTION__,
+                (int)m_message_queue.size());
+
+  std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
+
+  // This method used to only handle one message.  Changing it to loop allows
+  // it to handle the case where we hit a breakpoint while handling a different
+  // breakpoint.
+  while (!m_message_queue.empty()) {
+    ProcessMessage &message = m_message_queue.front();
 
-    std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
+    // Resolve the thread this message corresponds to and pass it along.
+    lldb::tid_t tid = message.GetTID();
+    if (log)
+      log->Printf(
+          "ProcessFreeBSD::%s(), message_queue size = %d, pid = %" PRIi64,
+          __FUNCTION__, (int)m_message_queue.size(), tid);
 
-    // This method used to only handle one message.  Changing it to loop allows
-    // it to handle the case where we hit a breakpoint while handling a different
-    // breakpoint.
-    while (!m_message_queue.empty())
-    {
-        ProcessMessage &message = m_message_queue.front();
-
-        // Resolve the thread this message corresponds to and pass it along.
-        lldb::tid_t tid = message.GetTID();
-        if (log)
-            log->Printf ("ProcessFreeBSD::%s(), message_queue size = %d, pid = %" PRIi64, __FUNCTION__, (int)m_message_queue.size(), tid);
+    m_thread_list.RefreshStateAfterStop();
 
-        m_thread_list.RefreshStateAfterStop();
+    FreeBSDThread *thread = static_cast<FreeBSDThread *>(
+        GetThreadList().FindThreadByID(tid, false).get());
+    if (thread)
+      thread->Notify(message);
 
-        FreeBSDThread *thread = static_cast<FreeBSDThread*>(
-            GetThreadList().FindThreadByID(tid, false).get());
-        if (thread)
-            thread->Notify(message);
+    if (message.GetKind() == ProcessMessage::eExitMessage) {
+      // FIXME: We should tell the user about this, but the limbo message is
+      // probably better for that.
+      if (log)
+        log->Printf("ProcessFreeBSD::%s() removing thread, tid = %" PRIi64,
+                    __FUNCTION__, tid);
 
-        if (message.GetKind() == ProcessMessage::eExitMessage)
-        {
-            // FIXME: We should tell the user about this, but the limbo message is probably better for that.
-            if (log)
-                log->Printf ("ProcessFreeBSD::%s() removing thread, tid = %" PRIi64, __FUNCTION__, tid);
-
-            std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-
-            ThreadSP thread_sp = m_thread_list.RemoveThreadByID(tid, false);
-            thread_sp.reset();
-            m_seen_initial_stop.erase(tid);
-        }
+      std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
 
-        m_message_queue.pop();
+      ThreadSP thread_sp = m_thread_list.RemoveThreadByID(tid, false);
+      thread_sp.reset();
+      m_seen_initial_stop.erase(tid);
     }
+
+    m_message_queue.pop();
+  }
 }
 
-bool
-ProcessFreeBSD::IsAlive()
-{
-    StateType state = GetPrivateState();
-    return state != eStateDetached
-        && state != eStateExited
-        && state != eStateInvalid
-        && state != eStateUnloaded;
+bool ProcessFreeBSD::IsAlive() {
+  StateType state = GetPrivateState();
+  return state != eStateDetached && state != eStateExited &&
+         state != eStateInvalid && state != eStateUnloaded;
 }
 
-size_t
-ProcessFreeBSD::DoReadMemory(addr_t vm_addr,
-                           void *buf, size_t size, Error &error)
-{
-    assert(m_monitor);
-    return m_monitor->ReadMemory(vm_addr, buf, size, error);
+size_t ProcessFreeBSD::DoReadMemory(addr_t vm_addr, void *buf, size_t size,
+                                    Error &error) {
+  assert(m_monitor);
+  return m_monitor->ReadMemory(vm_addr, buf, size, error);
 }
 
-size_t
-ProcessFreeBSD::DoWriteMemory(addr_t vm_addr, const void *buf, size_t size,
-                            Error &error)
-{
-    assert(m_monitor);
-    return m_monitor->WriteMemory(vm_addr, buf, size, error);
+size_t ProcessFreeBSD::DoWriteMemory(addr_t vm_addr, const void *buf,
+                                     size_t size, Error &error) {
+  assert(m_monitor);
+  return m_monitor->WriteMemory(vm_addr, buf, size, error);
 }
 
-addr_t
-ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions,
-                               Error &error)
-{
-    addr_t allocated_addr = LLDB_INVALID_ADDRESS;
+addr_t ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions,
+                                        Error &error) {
+  addr_t allocated_addr = LLDB_INVALID_ADDRESS;
 
-    unsigned prot = 0;
-    if (permissions & lldb::ePermissionsReadable)
-        prot |= eMmapProtRead;
-    if (permissions & lldb::ePermissionsWritable)
-        prot |= eMmapProtWrite;
-    if (permissions & lldb::ePermissionsExecutable)
-        prot |= eMmapProtExec;
-
-    if (InferiorCallMmap(this, allocated_addr, 0, size, prot,
-                         eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
-        m_addr_to_mmap_size[allocated_addr] = size;
-        error.Clear();
-    } else {
-        allocated_addr = LLDB_INVALID_ADDRESS;
-        error.SetErrorStringWithFormat("unable to allocate %zu bytes of memory with permissions %s", size, GetPermissionsAsCString (permissions));
-    }
+  unsigned prot = 0;
+  if (permissions & lldb::ePermissionsReadable)
+    prot |= eMmapProtRead;
+  if (permissions & lldb::ePermissionsWritable)
+    prot |= eMmapProtWrite;
+  if (permissions & lldb::ePermissionsExecutable)
+    prot |= eMmapProtExec;
 
-    return allocated_addr;
+  if (InferiorCallMmap(this, allocated_addr, 0, size, prot,
+                       eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
+    m_addr_to_mmap_size[allocated_addr] = size;
+    error.Clear();
+  } else {
+    allocated_addr = LLDB_INVALID_ADDRESS;
+    error.SetErrorStringWithFormat(
+        "unable to allocate %zu bytes of memory with permissions %s", size,
+        GetPermissionsAsCString(permissions));
+  }
+
+  return allocated_addr;
 }
 
-Error
-ProcessFreeBSD::DoDeallocateMemory(lldb::addr_t addr)
-{
-    Error error;
-    MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
-    if (pos != m_addr_to_mmap_size.end() &&
-        InferiorCallMunmap(this, addr, pos->second))
-        m_addr_to_mmap_size.erase (pos);
-    else
-        error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64, addr);
+Error ProcessFreeBSD::DoDeallocateMemory(lldb::addr_t addr) {
+  Error error;
+  MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
+  if (pos != m_addr_to_mmap_size.end() &&
+      InferiorCallMunmap(this, addr, pos->second))
+    m_addr_to_mmap_size.erase(pos);
+  else
+    error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64,
+                                   addr);
 
-    return error;
+  return error;
 }
 
 size_t
-ProcessFreeBSD::GetSoftwareBreakpointTrapOpcode(BreakpointSite* bp_site)
-{
-    static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xD4 };
-    static const uint8_t g_i386_opcode[] = { 0xCC };
-
-    ArchSpec arch = GetTarget().GetArchitecture();
-    const uint8_t *opcode = NULL;
-    size_t opcode_size = 0;
-
-    switch (arch.GetMachine())
-    {
-    default:
-        assert(false && "CPU type not supported!");
-        break;
-
-    case llvm::Triple::arm:
-        {
-            // The ARM reference recommends the use of 0xe7fddefe and 0xdefe
-            // but the linux kernel does otherwise.
-            static const uint8_t g_arm_breakpoint_opcode[] = { 0xf0, 0x01, 0xf0, 0xe7 };
-            static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde };
-
-            lldb::BreakpointLocationSP bp_loc_sp (bp_site->GetOwnerAtIndex (0));
-            AddressClass addr_class = eAddressClassUnknown;
-
-            if (bp_loc_sp)
-                addr_class = bp_loc_sp->GetAddress ().GetAddressClass ();
-
-            if (addr_class == eAddressClassCodeAlternateISA
-                || (addr_class == eAddressClassUnknown
-                    && bp_loc_sp->GetAddress().GetOffset() & 1))
-            {
-                opcode = g_thumb_breakpoint_opcode;
-                opcode_size = sizeof(g_thumb_breakpoint_opcode);
-            }
-            else
-            {
-                opcode = g_arm_breakpoint_opcode;
-                opcode_size = sizeof(g_arm_breakpoint_opcode);
-            }
-        }
-        break;
-    case llvm::Triple::aarch64:
-        opcode = g_aarch64_opcode;
-        opcode_size = sizeof(g_aarch64_opcode);
-        break;
-
-    case llvm::Triple::x86:
-    case llvm::Triple::x86_64:
-        opcode = g_i386_opcode;
-        opcode_size = sizeof(g_i386_opcode);
-        break;
+ProcessFreeBSD::GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site) {
+  static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xD4};
+  static const uint8_t g_i386_opcode[] = {0xCC};
+
+  ArchSpec arch = GetTarget().GetArchitecture();
+  const uint8_t *opcode = NULL;
+  size_t opcode_size = 0;
+
+  switch (arch.GetMachine()) {
+  default:
+    assert(false && "CPU type not supported!");
+    break;
+
+  case llvm::Triple::arm: {
+    // The ARM reference recommends the use of 0xe7fddefe and 0xdefe
+    // but the linux kernel does otherwise.
+    static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
+    static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
+
+    lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0));
+    AddressClass addr_class = eAddressClassUnknown;
+
+    if (bp_loc_sp)
+      addr_class = bp_loc_sp->GetAddress().GetAddressClass();
+
+    if (addr_class == eAddressClassCodeAlternateISA ||
+        (addr_class == eAddressClassUnknown &&
+         bp_loc_sp->GetAddress().GetOffset() & 1)) {
+      opcode = g_thumb_breakpoint_opcode;
+      opcode_size = sizeof(g_thumb_breakpoint_opcode);
+    } else {
+      opcode = g_arm_breakpoint_opcode;
+      opcode_size = sizeof(g_arm_breakpoint_opcode);
     }
+  } break;
+  case llvm::Triple::aarch64:
+    opcode = g_aarch64_opcode;
+    opcode_size = sizeof(g_aarch64_opcode);
+    break;
 
-    bp_site->SetTrapOpcode(opcode, opcode_size);
-    return opcode_size;
-}
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+    opcode = g_i386_opcode;
+    opcode_size = sizeof(g_i386_opcode);
+    break;
+  }
 
-Error
-ProcessFreeBSD::EnableBreakpointSite(BreakpointSite *bp_site)
-{
-    return EnableSoftwareBreakpoint(bp_site);
+  bp_site->SetTrapOpcode(opcode, opcode_size);
+  return opcode_size;
 }
 
-Error
-ProcessFreeBSD::DisableBreakpointSite(BreakpointSite *bp_site)
-{
-    return DisableSoftwareBreakpoint(bp_site);
+Error ProcessFreeBSD::EnableBreakpointSite(BreakpointSite *bp_site) {
+  return EnableSoftwareBreakpoint(bp_site);
 }
 
-Error
-ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify)
-{
-    Error error;
-    if (wp)
-    {
-        user_id_t watchID = wp->GetID();
-        addr_t addr = wp->GetLoadAddress();
-        Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
-        if (log)
-            log->Printf ("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 ")",
-                         watchID);
-        if (wp->IsEnabled())
-        {
-            if (log)
-                log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64
-                            ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
-                            watchID, (uint64_t)addr);
-            return error;
-        }
-
-        // Try to find a vacant watchpoint slot in the inferiors' main thread
-        uint32_t wp_hw_index = LLDB_INVALID_INDEX32;
-        std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-        FreeBSDThread *thread = static_cast<FreeBSDThread*>(
-                               m_thread_list.GetThreadAtIndex(0, false).get());
-
-        if (thread)
-            wp_hw_index = thread->FindVacantWatchpointIndex();
-
-        if (wp_hw_index == LLDB_INVALID_INDEX32)
-        {
-            error.SetErrorString("Setting hardware watchpoint failed.");
-        }
-        else
-        {
-            wp->SetHardwareIndex(wp_hw_index);
-            bool wp_enabled = true;
-            uint32_t thread_count = m_thread_list.GetSize(false);
-            for (uint32_t i = 0; i < thread_count; ++i)
-            {
-                thread = static_cast<FreeBSDThread*>(
-                         m_thread_list.GetThreadAtIndex(i, false).get());
-                if (thread)
-                    wp_enabled &= thread->EnableHardwareWatchpoint(wp);
-                else
-                    wp_enabled = false;
-            }
-            if (wp_enabled)
-            {
-                wp->SetEnabled(true, notify);
-                return error;
-            }
-            else
-            {
-                // Watchpoint enabling failed on at least one
-                // of the threads so roll back all of them
-                DisableWatchpoint(wp, false);
-                error.SetErrorString("Setting hardware watchpoint failed");
-            }
-        }
-    }
-    else
-        error.SetErrorString("Watchpoint argument was NULL.");
-    return error;
+Error ProcessFreeBSD::DisableBreakpointSite(BreakpointSite *bp_site) {
+  return DisableSoftwareBreakpoint(bp_site);
 }
 
-Error
-ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify)
-{
-    Error error;
-    if (wp)
-    {
-        user_id_t watchID = wp->GetID();
-        addr_t addr = wp->GetLoadAddress();
-        Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
-        if (log)
-            log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 ")",
-                        watchID);
-        if (!wp->IsEnabled())
-        {
-            if (log)
-                log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64
-                            ") addr = 0x%8.8" PRIx64 ": watchpoint already disabled.",
-                            watchID, (uint64_t)addr);
-            // This is needed (for now) to keep watchpoints disabled correctly
-            wp->SetEnabled(false, notify);
-            return error;
-        }
-
-        if (wp->IsHardware())
-        {
-            bool wp_disabled = true;
-            std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-            uint32_t thread_count = m_thread_list.GetSize(false);
-            for (uint32_t i = 0; i < thread_count; ++i)
-            {
-                FreeBSDThread *thread = static_cast<FreeBSDThread*>(
-                                      m_thread_list.GetThreadAtIndex(i, false).get());
-                if (thread)
-                    wp_disabled &= thread->DisableHardwareWatchpoint(wp);
-                else
-                    wp_disabled = false;
-            }
-            if (wp_disabled)
-            {
-                wp->SetHardwareIndex(LLDB_INVALID_INDEX32);
-                wp->SetEnabled(false, notify);
-                return error;
-            }
-            else
-                error.SetErrorString("Disabling hardware watchpoint failed");
-        }
+Error ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) {
+  Error error;
+  if (wp) {
+    user_id_t watchID = wp->GetID();
+    addr_t addr = wp->GetLoadAddress();
+    Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
+    if (log)
+      log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 ")",
+                  watchID);
+    if (wp->IsEnabled()) {
+      if (log)
+        log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64
+                    ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
+                    watchID, (uint64_t)addr);
+      return error;
     }
-    else
-        error.SetErrorString("Watchpoint argument was NULL.");
-    return error;
-}
 
-Error
-ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num)
-{
-    Error error;
+    // Try to find a vacant watchpoint slot in the inferiors' main thread
+    uint32_t wp_hw_index = LLDB_INVALID_INDEX32;
     std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-    FreeBSDThread *thread = static_cast<FreeBSDThread*>(
-                          m_thread_list.GetThreadAtIndex(0, false).get());
-    if (thread)
-        num = thread->NumSupportedHardwareWatchpoints();
-    else
-        error.SetErrorString("Process does not exist.");
-    return error;
-}
+    FreeBSDThread *thread = static_cast<FreeBSDThread *>(
+        m_thread_list.GetThreadAtIndex(0, false).get());
 
-Error
-ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after)
-{
-    Error error = GetWatchpointSupportInfo(num);
-    // Watchpoints trigger and halt the inferior after
-    // the corresponding instruction has been executed.
-    after = true;
-    return error;
-}
+    if (thread)
+      wp_hw_index = thread->FindVacantWatchpointIndex();
 
-uint32_t
-ProcessFreeBSD::UpdateThreadListIfNeeded()
-{
-    std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-    // Do not allow recursive updates.
-    return m_thread_list.GetSize(false);
+    if (wp_hw_index == LLDB_INVALID_INDEX32) {
+      error.SetErrorString("Setting hardware watchpoint failed.");
+    } else {
+      wp->SetHardwareIndex(wp_hw_index);
+      bool wp_enabled = true;
+      uint32_t thread_count = m_thread_list.GetSize(false);
+      for (uint32_t i = 0; i < thread_count; ++i) {
+        thread = static_cast<FreeBSDThread *>(
+            m_thread_list.GetThreadAtIndex(i, false).get());
+        if (thread)
+          wp_enabled &= thread->EnableHardwareWatchpoint(wp);
+        else
+          wp_enabled = false;
+      }
+      if (wp_enabled) {
+        wp->SetEnabled(true, notify);
+        return error;
+      } else {
+        // Watchpoint enabling failed on at least one
+        // of the threads so roll back all of them
+        DisableWatchpoint(wp, false);
+        error.SetErrorString("Setting hardware watchpoint failed");
+      }
+    }
+  } else
+    error.SetErrorString("Watchpoint argument was NULL.");
+  return error;
+}
+
+Error ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify) {
+  Error error;
+  if (wp) {
+    user_id_t watchID = wp->GetID();
+    addr_t addr = wp->GetLoadAddress();
+    Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
+    if (log)
+      log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 ")",
+                  watchID);
+    if (!wp->IsEnabled()) {
+      if (log)
+        log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64
+                    ") addr = 0x%8.8" PRIx64 ": watchpoint already disabled.",
+                    watchID, (uint64_t)addr);
+      // This is needed (for now) to keep watchpoints disabled correctly
+      wp->SetEnabled(false, notify);
+      return error;
+    }
+
+    if (wp->IsHardware()) {
+      bool wp_disabled = true;
+      std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
+      uint32_t thread_count = m_thread_list.GetSize(false);
+      for (uint32_t i = 0; i < thread_count; ++i) {
+        FreeBSDThread *thread = static_cast<FreeBSDThread *>(
+            m_thread_list.GetThreadAtIndex(i, false).get());
+        if (thread)
+          wp_disabled &= thread->DisableHardwareWatchpoint(wp);
+        else
+          wp_disabled = false;
+      }
+      if (wp_disabled) {
+        wp->SetHardwareIndex(LLDB_INVALID_INDEX32);
+        wp->SetEnabled(false, notify);
+        return error;
+      } else
+        error.SetErrorString("Disabling hardware watchpoint failed");
+    }
+  } else
+    error.SetErrorString("Watchpoint argument was NULL.");
+  return error;
+}
+
+Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num) {
+  Error error;
+  std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
+  FreeBSDThread *thread = static_cast<FreeBSDThread *>(
+      m_thread_list.GetThreadAtIndex(0, false).get());
+  if (thread)
+    num = thread->NumSupportedHardwareWatchpoints();
+  else
+    error.SetErrorString("Process does not exist.");
+  return error;
+}
+
+Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
+  Error error = GetWatchpointSupportInfo(num);
+  // Watchpoints trigger and halt the inferior after
+  // the corresponding instruction has been executed.
+  after = true;
+  return error;
+}
+
+uint32_t ProcessFreeBSD::UpdateThreadListIfNeeded() {
+  std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
+  // Do not allow recursive updates.
+  return m_thread_list.GetSize(false);
 }
 
 #if 0
@@ -955,91 +839,77 @@ ProcessFreeBSD::UpdateThreadList(ThreadL
 }
 #endif
 
-ByteOrder
-ProcessFreeBSD::GetByteOrder() const
-{
-    // FIXME: We should be able to extract this value directly.  See comment in
-    // ProcessFreeBSD().
-    return m_byte_order;
+ByteOrder ProcessFreeBSD::GetByteOrder() const {
+  // FIXME: We should be able to extract this value directly.  See comment in
+  // ProcessFreeBSD().
+  return m_byte_order;
 }
 
-size_t
-ProcessFreeBSD::PutSTDIN(const char *buf, size_t len, Error &error)
-{
-    ssize_t status;
-    if ((status = write(m_monitor->GetTerminalFD(), buf, len)) < 0) 
-    {
-        error.SetErrorToErrno();
-        return 0;
-    }
-    return status;
+size_t ProcessFreeBSD::PutSTDIN(const char *buf, size_t len, Error &error) {
+  ssize_t status;
+  if ((status = write(m_monitor->GetTerminalFD(), buf, len)) < 0) {
+    error.SetErrorToErrno();
+    return 0;
+  }
+  return status;
 }
 
 //------------------------------------------------------------------------------
 // Utility functions.
 
-bool
-ProcessFreeBSD::HasExited()
-{
-    switch (GetPrivateState())
-    {
-    default:
-        break;
-
-    case eStateDetached:
-    case eStateExited:
-        return true;
-    }
+bool ProcessFreeBSD::HasExited() {
+  switch (GetPrivateState()) {
+  default:
+    break;
 
-    return false;
+  case eStateDetached:
+  case eStateExited:
+    return true;
+  }
+
+  return false;
 }
 
-bool
-ProcessFreeBSD::IsStopped()
-{
-    switch (GetPrivateState())
-    {
-    default:
-        break;
-
-    case eStateStopped:
-    case eStateCrashed:
-    case eStateSuspended:
-        return true;
-    }
+bool ProcessFreeBSD::IsStopped() {
+  switch (GetPrivateState()) {
+  default:
+    break;
 
-    return false;
-}
+  case eStateStopped:
+  case eStateCrashed:
+  case eStateSuspended:
+    return true;
+  }
 
-bool
-ProcessFreeBSD::IsAThreadRunning()
-{
-    bool is_running = false;
-    std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
-    uint32_t thread_count = m_thread_list.GetSize(false);
-    for (uint32_t i = 0; i < thread_count; ++i)
-    {
-        FreeBSDThread *thread = static_cast<FreeBSDThread*>(
-            m_thread_list.GetThreadAtIndex(i, false).get());
-        StateType thread_state = thread->GetState();
-        if (thread_state == eStateRunning || thread_state == eStateStepping)
-        {
-            is_running = true;
-            break;
-        }
-    }
-    return is_running;
+  return false;
 }
 
-const DataBufferSP
-ProcessFreeBSD::GetAuxvData ()
-{
-    // If we're the local platform, we can ask the host for auxv data.
-    PlatformSP platform_sp = GetTarget().GetPlatform ();
-    if (platform_sp && platform_sp->IsHost ())
-        return lldb_private::Host::GetAuxvData(this);
-
-    // Somewhat unexpected - the process is not running locally or we don't have a platform.
-    assert (false && "no platform or not the host - how did we get here with ProcessFreeBSD?");
-    return DataBufferSP ();
+bool ProcessFreeBSD::IsAThreadRunning() {
+  bool is_running = false;
+  std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
+  uint32_t thread_count = m_thread_list.GetSize(false);
+  for (uint32_t i = 0; i < thread_count; ++i) {
+    FreeBSDThread *thread = static_cast<FreeBSDThread *>(
+        m_thread_list.GetThreadAtIndex(i, false).get());
+    StateType thread_state = thread->GetState();
+    if (thread_state == eStateRunning || thread_state == eStateStepping) {
+      is_running = true;
+      break;
+    }
+  }
+  return is_running;
+}
+
+const DataBufferSP ProcessFreeBSD::GetAuxvData() {
+  // If we're the local platform, we can ask the host for auxv data.
+  PlatformSP platform_sp = GetTarget().GetPlatform();
+  if (platform_sp && platform_sp->IsHost())
+    return lldb_private::Host::GetAuxvData(this);
+
+  // Somewhat unexpected - the process is not running locally or we don't have a
+  // platform.
+  assert(
+      false &&
+      "no platform or not the host - how did we get here with ProcessFreeBSD?");
+  return DataBufferSP();
 }

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- ProcessFreeBSD.h ------------------------------------------*- C++ -*-===//
+//===-- ProcessFreeBSD.h ------------------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -18,233 +19,200 @@
 #include <set>
 
 // Other libraries and framework includes
+#include "ProcessFreeBSD.h"
+#include "ProcessMessage.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/ThreadList.h"
-#include "ProcessMessage.h"
-#include "ProcessFreeBSD.h"
 
 class ProcessMonitor;
 class FreeBSDThread;
 
-class ProcessFreeBSD :
-    public lldb_private::Process
-{
+class ProcessFreeBSD : public lldb_private::Process {
 
 public:
-    //------------------------------------------------------------------
-    // Static functions.
-    //------------------------------------------------------------------
-    static lldb::ProcessSP
-    CreateInstance(lldb::TargetSP target_sp,
-                   lldb::ListenerSP listener_sp,
-                   const lldb_private::FileSpec *crash_file_path);
-
-    static void
-    Initialize();
-
-    static void
-    Terminate();
-
-    static lldb_private::ConstString
-    GetPluginNameStatic();
-
-    static const char *
-    GetPluginDescriptionStatic();
-
-    //------------------------------------------------------------------
-    // Constructors and destructors
-    //------------------------------------------------------------------
-    ProcessFreeBSD(lldb::TargetSP target_sp,
-                   lldb::ListenerSP listener_sp,
-                   lldb::UnixSignalsSP &unix_signals_sp);
-
-    ~ProcessFreeBSD();
-
-    virtual lldb_private::Error
-    WillResume() override;
-
-    //------------------------------------------------------------------
-    // PluginInterface protocol
-    //------------------------------------------------------------------
-    virtual lldb_private::ConstString
-    GetPluginName() override;
+  //------------------------------------------------------------------
+  // Static functions.
+  //------------------------------------------------------------------
+  static lldb::ProcessSP
+  CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+                 const lldb_private::FileSpec *crash_file_path);
 
-    virtual uint32_t
-    GetPluginVersion() override;
+  static void Initialize();
 
-public:
-    //------------------------------------------------------------------
-    // Process protocol.
-    //------------------------------------------------------------------
-    void
-    Finalize() override;
+  static void Terminate();
 
-    bool
-    CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override;
+  static lldb_private::ConstString GetPluginNameStatic();
 
-    lldb_private::Error
-    WillLaunch(lldb_private::Module *module) override;
+  static const char *GetPluginDescriptionStatic();
 
-    lldb_private::Error
-    DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override;
+  //------------------------------------------------------------------
+  // Constructors and destructors
+  //------------------------------------------------------------------
+  ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+                 lldb::UnixSignalsSP &unix_signals_sp);
 
-    lldb_private::Error
-    DoLaunch (lldb_private::Module *exe_module,
-              lldb_private::ProcessLaunchInfo &launch_info) override;
+  ~ProcessFreeBSD();
 
-    void
-    DidLaunch() override;
+  virtual lldb_private::Error WillResume() override;
 
-    lldb_private::Error
-    DoResume() override;
+  //------------------------------------------------------------------
+  // PluginInterface protocol
+  //------------------------------------------------------------------
+  virtual lldb_private::ConstString GetPluginName() override;
 
-    lldb_private::Error
-    DoHalt(bool &caused_stop) override;
+  virtual uint32_t GetPluginVersion() override;
 
-    lldb_private::Error
-    DoDetach(bool keep_stopped) override;
+public:
+  //------------------------------------------------------------------
+  // Process protocol.
+  //------------------------------------------------------------------
+  void Finalize() override;
 
-    lldb_private::Error
-    DoSignal(int signal) override;
+  bool CanDebug(lldb::TargetSP target_sp,
+                bool plugin_specified_by_name) override;
 
-    lldb_private::Error
-    DoDestroy() override;
+  lldb_private::Error WillLaunch(lldb_private::Module *module) override;
 
-    void
-    DoDidExec() override;
+  lldb_private::Error DoAttachToProcessWithID(
+      lldb::pid_t pid,
+      const lldb_private::ProcessAttachInfo &attach_info) override;
 
-    void
-    RefreshStateAfterStop() override;
+  lldb_private::Error
+  DoLaunch(lldb_private::Module *exe_module,
+           lldb_private::ProcessLaunchInfo &launch_info) override;
 
-    bool
-    IsAlive() override;
+  void DidLaunch() override;
 
-    size_t
-    DoReadMemory(lldb::addr_t vm_addr,
-                 void *buf,
-                 size_t size,
-                 lldb_private::Error &error) override;
+  lldb_private::Error DoResume() override;
 
-    size_t
-    DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
-                  lldb_private::Error &error) override;
+  lldb_private::Error DoHalt(bool &caused_stop) override;
 
-    lldb::addr_t
-    DoAllocateMemory(size_t size, uint32_t permissions,
-                     lldb_private::Error &error) override;
+  lldb_private::Error DoDetach(bool keep_stopped) override;
 
-    lldb_private::Error
-    DoDeallocateMemory(lldb::addr_t ptr) override;
+  lldb_private::Error DoSignal(int signal) override;
 
-    virtual size_t
-    GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
+  lldb_private::Error DoDestroy() override;
 
-    lldb_private::Error
-    EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
+  void DoDidExec() override;
 
-    lldb_private::Error
-    DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
+  void RefreshStateAfterStop() override;
 
-    lldb_private::Error
-    EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true) override;
+  bool IsAlive() override;
 
-    lldb_private::Error
-    DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true) override;
+  size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+                      lldb_private::Error &error) override;
 
-    lldb_private::Error
-    GetWatchpointSupportInfo(uint32_t &num) override;
+  size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
+                       lldb_private::Error &error) override;
 
-    lldb_private::Error
-    GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
+  lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
+                                lldb_private::Error &error) override;
 
-    virtual uint32_t
-    UpdateThreadListIfNeeded();
+  lldb_private::Error DoDeallocateMemory(lldb::addr_t ptr) override;
 
-    bool
-    UpdateThreadList(lldb_private::ThreadList &old_thread_list,
-                     lldb_private::ThreadList &new_thread_list) override;
+  virtual size_t
+  GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite *bp_site);
 
-    virtual lldb::ByteOrder
-    GetByteOrder() const;
+  lldb_private::Error
+  EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
 
-    lldb::addr_t
-    GetImageInfoAddress() override;
+  lldb_private::Error
+  DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
 
-    size_t
-    PutSTDIN(const char *buf, size_t len, lldb_private::Error &error) override;
+  lldb_private::Error EnableWatchpoint(lldb_private::Watchpoint *wp,
+                                       bool notify = true) override;
 
-    const lldb::DataBufferSP
-    GetAuxvData () override;
+  lldb_private::Error DisableWatchpoint(lldb_private::Watchpoint *wp,
+                                        bool notify = true) override;
 
-    //--------------------------------------------------------------------------
-    // ProcessFreeBSD internal API.
+  lldb_private::Error GetWatchpointSupportInfo(uint32_t &num) override;
 
-    /// Registers the given message with this process.
-    virtual void
-    SendMessage(const ProcessMessage &message);
+  lldb_private::Error GetWatchpointSupportInfo(uint32_t &num,
+                                               bool &after) override;
 
-    ProcessMonitor &
-    GetMonitor() { assert(m_monitor); return *m_monitor; }
+  virtual uint32_t UpdateThreadListIfNeeded();
 
-    lldb_private::FileSpec
-    GetFileSpec(const lldb_private::FileAction *file_action,
-                const lldb_private::FileSpec &default_file_spec,
-                const lldb_private::FileSpec &dbg_pts_file_spec);
+  bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
+                        lldb_private::ThreadList &new_thread_list) override;
 
-    /// Adds the thread to the list of threads for which we have received the initial stopping signal.
-    /// The \p stop_tid parameter indicates the thread which the stop happened for.
-    bool
-    AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
+  virtual lldb::ByteOrder GetByteOrder() const;
 
-    bool
-    WaitingForInitialStop(lldb::tid_t stop_tid);
+  lldb::addr_t GetImageInfoAddress() override;
 
-    virtual FreeBSDThread *
-    CreateNewFreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
+  size_t PutSTDIN(const char *buf, size_t len,
+                  lldb_private::Error &error) override;
 
-protected:
-    /// Target byte order.
-    lldb::ByteOrder m_byte_order;
+  const lldb::DataBufferSP GetAuxvData() override;
+
+  //--------------------------------------------------------------------------
+  // ProcessFreeBSD internal API.
+
+  /// Registers the given message with this process.
+  virtual void SendMessage(const ProcessMessage &message);
+
+  ProcessMonitor &GetMonitor() {
+    assert(m_monitor);
+    return *m_monitor;
+  }
+
+  lldb_private::FileSpec
+  GetFileSpec(const lldb_private::FileAction *file_action,
+              const lldb_private::FileSpec &default_file_spec,
+              const lldb_private::FileSpec &dbg_pts_file_spec);
+
+  /// Adds the thread to the list of threads for which we have received the
+  /// initial stopping signal.
+  /// The \p stop_tid parameter indicates the thread which the stop happened
+  /// for.
+  bool AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
 
-    /// Process monitor;
-    ProcessMonitor *m_monitor;
+  bool WaitingForInitialStop(lldb::tid_t stop_tid);
+
+  virtual FreeBSDThread *CreateNewFreeBSDThread(lldb_private::Process &process,
+                                                lldb::tid_t tid);
+
+protected:
+  /// Target byte order.
+  lldb::ByteOrder m_byte_order;
 
-    /// The module we are executing.
-    lldb_private::Module *m_module;
+  /// Process monitor;
+  ProcessMonitor *m_monitor;
 
-    /// Message queue notifying this instance of inferior process state changes.
-    std::recursive_mutex m_message_mutex;
-    std::queue<ProcessMessage> m_message_queue;
+  /// The module we are executing.
+  lldb_private::Module *m_module;
 
-    /// Drive any exit events to completion.
-    bool m_exit_now;
+  /// Message queue notifying this instance of inferior process state changes.
+  std::recursive_mutex m_message_mutex;
+  std::queue<ProcessMessage> m_message_queue;
 
-    /// Returns true if the process has exited.
-    bool HasExited();
+  /// Drive any exit events to completion.
+  bool m_exit_now;
 
-    /// Returns true if the process is stopped.
-    bool IsStopped();
+  /// Returns true if the process has exited.
+  bool HasExited();
 
-    /// Returns true if at least one running is currently running
-    bool IsAThreadRunning();
+  /// Returns true if the process is stopped.
+  bool IsStopped();
 
-    typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
-    MMapMap m_addr_to_mmap_size;
+  /// Returns true if at least one running is currently running
+  bool IsAThreadRunning();
 
-    typedef std::set<lldb::tid_t> ThreadStopSet;
-    /// Every thread begins with a stop signal. This keeps track
-    /// of the threads for which we have received the stop signal.
-    ThreadStopSet m_seen_initial_stop;
+  typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
+  MMapMap m_addr_to_mmap_size;
 
-    friend class FreeBSDThread;
+  typedef std::set<lldb::tid_t> ThreadStopSet;
+  /// Every thread begins with a stop signal. This keeps track
+  /// of the threads for which we have received the stop signal.
+  ThreadStopSet m_seen_initial_stop;
 
-    typedef std::vector<lldb::tid_t> tid_collection;
-    tid_collection m_suspend_tids;
-    tid_collection m_run_tids;
-    tid_collection m_step_tids;
+  friend class FreeBSDThread;
 
-    int m_resume_signo;
+  typedef std::vector<lldb::tid_t> tid_collection;
+  tid_collection m_suspend_tids;
+  tid_collection m_run_tids;
+  tid_collection m_step_tids;
 
+  int m_resume_signo;
 };
 
-#endif  // liblldb_ProcessFreeBSD_H_
+#endif // liblldb_ProcessFreeBSD_H_

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Tue Sep  6 15:57:50 2016
@@ -10,14 +10,14 @@
 // C Includes
 #include <errno.h>
 #include <poll.h>
-#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
 #include <signal.h>
+#include <stdint.h>
+#include <string.h>
 #include <sys/ptrace.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 // C++ Includes
 // Other libraries and framework includes
@@ -26,20 +26,20 @@
 #include "lldb/Core/Scalar.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/ThreadLauncher.h"
-#include "lldb/Target/Thread.h"
 #include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Thread.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/PseudoTerminal.h"
 
-#include "Plugins/Process/POSIX/CrashReason.h"
 #include "FreeBSDThread.h"
+#include "Plugins/Process/POSIX/CrashReason.h"
 #include "ProcessFreeBSD.h"
-#include "ProcessPOSIXLog.h"
 #include "ProcessMonitor.h"
+#include "ProcessPOSIXLog.h"
 
 extern "C" {
-      extern char ** environ;
- }
+extern char **environ;
+}
 
 using namespace lldb;
 using namespace lldb_private;
@@ -49,96 +49,103 @@ using namespace lldb_private;
 #ifndef LLDB_CONFIGURATION_BUILDANDINTEGRATION
 // Wrapper for ptrace to catch errors and log calls.
 
-const char *
-Get_PT_IO_OP(int op)
-{
-    switch (op) {
-        case PIOD_READ_D:  return "READ_D";
-        case PIOD_WRITE_D: return "WRITE_D";
-        case PIOD_READ_I:  return "READ_I";
-        case PIOD_WRITE_I: return "WRITE_I";
-        default:           return "Unknown op";
-    }
+const char *Get_PT_IO_OP(int op) {
+  switch (op) {
+  case PIOD_READ_D:
+    return "READ_D";
+  case PIOD_WRITE_D:
+    return "WRITE_D";
+  case PIOD_READ_I:
+    return "READ_I";
+  case PIOD_WRITE_I:
+    return "WRITE_I";
+  default:
+    return "Unknown op";
+  }
 }
 
 // Wrapper for ptrace to catch errors and log calls.
-// Note that ptrace sets errno on error because -1 is reserved as a valid result.
-extern long
-PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
-              const char* reqName, const char* file, int line)
-{
-    long int result;
-
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE));
-
-    if (log) {
-        log->Printf("ptrace(%s, %" PRIu64 ", %p, %x) called from file %s line %d",
-                    reqName, pid, addr, data, file, line);
-        if (req == PT_IO) {
-            struct ptrace_io_desc *pi = (struct ptrace_io_desc *) addr;
-            
-            log->Printf("PT_IO: op=%s offs=%zx size=%zu",
-                     Get_PT_IO_OP(pi->piod_op), (size_t)pi->piod_offs, pi->piod_len);
-        }
+// Note that ptrace sets errno on error because -1 is reserved as a valid
+// result.
+extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
+                          const char *reqName, const char *file, int line) {
+  long int result;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE));
+
+  if (log) {
+    log->Printf("ptrace(%s, %" PRIu64 ", %p, %x) called from file %s line %d",
+                reqName, pid, addr, data, file, line);
+    if (req == PT_IO) {
+      struct ptrace_io_desc *pi = (struct ptrace_io_desc *)addr;
+
+      log->Printf("PT_IO: op=%s offs=%zx size=%zu", Get_PT_IO_OP(pi->piod_op),
+                  (size_t)pi->piod_offs, pi->piod_len);
+    }
+  }
+
+  // PtraceDisplayBytes(req, data);
+
+  errno = 0;
+  result = ptrace(req, pid, (caddr_t)addr, data);
+
+  // PtraceDisplayBytes(req, data);
+
+  if (log && errno != 0) {
+    const char *str;
+    switch (errno) {
+    case ESRCH:
+      str = "ESRCH";
+      break;
+    case EINVAL:
+      str = "EINVAL";
+      break;
+    case EBUSY:
+      str = "EBUSY";
+      break;
+    case EPERM:
+      str = "EPERM";
+      break;
+    default:
+      str = "<unknown>";
     }
+    log->Printf("ptrace() failed; errno=%d (%s)", errno, str);
+  }
 
-    //PtraceDisplayBytes(req, data);
-
-    errno = 0;
-    result = ptrace(req, pid, (caddr_t) addr, data);
-
-    //PtraceDisplayBytes(req, data);
+  if (log) {
+#ifdef __amd64__
+    if (req == PT_GETREGS) {
+      struct reg *r = (struct reg *)addr;
 
-    if (log && errno != 0)
-    {
-        const char* str;
-        switch (errno)
-        {
-        case ESRCH:  str = "ESRCH"; break;
-        case EINVAL: str = "EINVAL"; break;
-        case EBUSY:  str = "EBUSY"; break;
-        case EPERM:  str = "EPERM"; break;
-        default:     str = "<unknown>";
-        }
-        log->Printf("ptrace() failed; errno=%d (%s)", errno, str);
+      log->Printf("PT_GETREGS: rip=0x%lx rsp=0x%lx rbp=0x%lx rax=0x%lx",
+                  r->r_rip, r->r_rsp, r->r_rbp, r->r_rax);
     }
+    if (req == PT_GETDBREGS || req == PT_SETDBREGS) {
+      struct dbreg *r = (struct dbreg *)addr;
+      char setget = (req == PT_GETDBREGS) ? 'G' : 'S';
 
-    if (log) {
-#ifdef __amd64__
-        if (req == PT_GETREGS) {
-            struct reg *r = (struct reg *) addr;
-
-            log->Printf("PT_GETREGS: rip=0x%lx rsp=0x%lx rbp=0x%lx rax=0x%lx",
-                        r->r_rip, r->r_rsp, r->r_rbp, r->r_rax);
-        }
-        if (req == PT_GETDBREGS || req == PT_SETDBREGS) {
-            struct dbreg *r = (struct dbreg *) addr;
-            char setget = (req == PT_GETDBREGS) ? 'G' : 'S';
-
-            for (int i = 0; i <= 7; i++)
-                log->Printf("PT_%cETDBREGS: dr[%d]=0x%lx", setget, i, r->dr[i]);
-        }
-#endif
+      for (int i = 0; i <= 7; i++)
+        log->Printf("PT_%cETDBREGS: dr[%d]=0x%lx", setget, i, r->dr[i]);
     }
-     
-    return result;
+#endif
+  }
+
+  return result;
 }
 
 // Wrapper for ptrace when logging is not required.
 // Sets errno to 0 prior to calling ptrace.
-extern long
-PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data)
-{
-    long result = 0;
-    errno = 0;
-    result = ptrace(req, pid, (caddr_t)addr, data);
-    return result;
+extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data) {
+  long result = 0;
+  errno = 0;
+  result = ptrace(req, pid, (caddr_t)addr, data);
+  return result;
 }
 
-#define PTRACE(req, pid, addr, data) \
-    PtraceWrapper((req), (pid), (addr), (data), #req, __FILE__, __LINE__)
+#define PTRACE(req, pid, addr, data)                                           \
+  PtraceWrapper((req), (pid), (addr), (data), #req, __FILE__, __LINE__)
 #else
-    PtraceWrapper((req), (pid), (addr), (data))
+PtraceWrapper((req), (pid), (addr), (data))
 #endif
 
 //------------------------------------------------------------------------------
@@ -146,58 +153,50 @@ PtraceWrapper(int req, lldb::pid_t pid,
 // ProcessMonitor::WriteMemory.  This enables mutual recursion between these
 // functions without needed to go thru the thread funnel.
 
-static size_t
-DoReadMemory(lldb::pid_t pid, lldb::addr_t vm_addr, void *buf, size_t size, 
-             Error &error)
-{
-    struct ptrace_io_desc pi_desc;
-
-    pi_desc.piod_op = PIOD_READ_D;
-    pi_desc.piod_offs = (void *)vm_addr;
-    pi_desc.piod_addr = buf;
-    pi_desc.piod_len = size;
-
-    if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0)
-        error.SetErrorToErrno();
-    return pi_desc.piod_len;
-}
-
-static size_t
-DoWriteMemory(lldb::pid_t pid, lldb::addr_t vm_addr, const void *buf, 
-              size_t size, Error &error)
-{
-    struct ptrace_io_desc pi_desc;
-
-    pi_desc.piod_op = PIOD_WRITE_D;
-    pi_desc.piod_offs = (void *)vm_addr;
-    pi_desc.piod_addr = (void *)buf;
-    pi_desc.piod_len = size;
-
-    if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0)
-        error.SetErrorToErrno();
-    return pi_desc.piod_len;
+static size_t DoReadMemory(lldb::pid_t pid, lldb::addr_t vm_addr, void *buf,
+                           size_t size, Error &error) {
+  struct ptrace_io_desc pi_desc;
+
+  pi_desc.piod_op = PIOD_READ_D;
+  pi_desc.piod_offs = (void *)vm_addr;
+  pi_desc.piod_addr = buf;
+  pi_desc.piod_len = size;
+
+  if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0)
+    error.SetErrorToErrno();
+  return pi_desc.piod_len;
+}
+
+static size_t DoWriteMemory(lldb::pid_t pid, lldb::addr_t vm_addr,
+                            const void *buf, size_t size, Error &error) {
+  struct ptrace_io_desc pi_desc;
+
+  pi_desc.piod_op = PIOD_WRITE_D;
+  pi_desc.piod_offs = (void *)vm_addr;
+  pi_desc.piod_addr = (void *)buf;
+  pi_desc.piod_len = size;
+
+  if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0)
+    error.SetErrorToErrno();
+  return pi_desc.piod_len;
 }
 
 // Simple helper function to ensure flags are enabled on the given file
 // descriptor.
-static bool
-EnsureFDFlags(int fd, int flags, Error &error)
-{
-    int status;
-
-    if ((status = fcntl(fd, F_GETFL)) == -1)
-    {
-        error.SetErrorToErrno();
-        return false;
-    }
+static bool EnsureFDFlags(int fd, int flags, Error &error) {
+  int status;
 
-    if (fcntl(fd, F_SETFL, status | flags) == -1)
-    {
-        error.SetErrorToErrno();
-        return false;
-    }
+  if ((status = fcntl(fd, F_GETFL)) == -1) {
+    error.SetErrorToErrno();
+    return false;
+  }
 
-    return true;
+  if (fcntl(fd, F_SETFL, status | flags) == -1) {
+    error.SetErrorToErrno();
+    return false;
+  }
+
+  return true;
 }
 
 //------------------------------------------------------------------------------
@@ -211,1383 +210,1216 @@ EnsureFDFlags(int fd, int flags, Error &
 /// task.  The Operation class provides an abstract base for all services the
 /// ProcessMonitor must perform via the single virtual function Execute, thus
 /// encapsulating the code that needs to run in the privileged context.
-class Operation
-{
+class Operation {
 public:
-    virtual ~Operation() {}
-    virtual void Execute(ProcessMonitor *monitor) = 0;
+  virtual ~Operation() {}
+  virtual void Execute(ProcessMonitor *monitor) = 0;
 };
 
 //------------------------------------------------------------------------------
 /// @class ReadOperation
 /// @brief Implements ProcessMonitor::ReadMemory.
-class ReadOperation : public Operation
-{
+class ReadOperation : public Operation {
 public:
-    ReadOperation(lldb::addr_t addr, void *buff, size_t size,
-                  Error &error, size_t &result)
-        : m_addr(addr), m_buff(buff), m_size(size),
-          m_error(error), m_result(result)
-        { }
+  ReadOperation(lldb::addr_t addr, void *buff, size_t size, Error &error,
+                size_t &result)
+      : m_addr(addr), m_buff(buff), m_size(size), m_error(error),
+        m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::addr_t m_addr;
-    void *m_buff;
-    size_t m_size;
-    Error &m_error;
-    size_t &m_result;
+  lldb::addr_t m_addr;
+  void *m_buff;
+  size_t m_size;
+  Error &m_error;
+  size_t &m_result;
 };
 
-void
-ReadOperation::Execute(ProcessMonitor *monitor)
-{
-    lldb::pid_t pid = monitor->GetPID();
+void ReadOperation::Execute(ProcessMonitor *monitor) {
+  lldb::pid_t pid = monitor->GetPID();
 
-    m_result = DoReadMemory(pid, m_addr, m_buff, m_size, m_error);
+  m_result = DoReadMemory(pid, m_addr, m_buff, m_size, m_error);
 }
 
 //------------------------------------------------------------------------------
 /// @class WriteOperation
 /// @brief Implements ProcessMonitor::WriteMemory.
-class WriteOperation : public Operation
-{
+class WriteOperation : public Operation {
 public:
-    WriteOperation(lldb::addr_t addr, const void *buff, size_t size,
-                   Error &error, size_t &result)
-        : m_addr(addr), m_buff(buff), m_size(size),
-          m_error(error), m_result(result)
-        { }
+  WriteOperation(lldb::addr_t addr, const void *buff, size_t size, Error &error,
+                 size_t &result)
+      : m_addr(addr), m_buff(buff), m_size(size), m_error(error),
+        m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::addr_t m_addr;
-    const void *m_buff;
-    size_t m_size;
-    Error &m_error;
-    size_t &m_result;
+  lldb::addr_t m_addr;
+  const void *m_buff;
+  size_t m_size;
+  Error &m_error;
+  size_t &m_result;
 };
 
-void
-WriteOperation::Execute(ProcessMonitor *monitor)
-{
-    lldb::pid_t pid = monitor->GetPID();
+void WriteOperation::Execute(ProcessMonitor *monitor) {
+  lldb::pid_t pid = monitor->GetPID();
 
-    m_result = DoWriteMemory(pid, m_addr, m_buff, m_size, m_error);
+  m_result = DoWriteMemory(pid, m_addr, m_buff, m_size, m_error);
 }
 
 //------------------------------------------------------------------------------
 /// @class ReadRegOperation
 /// @brief Implements ProcessMonitor::ReadRegisterValue.
-class ReadRegOperation : public Operation
-{
+class ReadRegOperation : public Operation {
 public:
-    ReadRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
-                     RegisterValue &value, bool &result)
-        : m_tid(tid), m_offset(offset), m_size(size),
-          m_value(value), m_result(result)
-        { }
+  ReadRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
+                   RegisterValue &value, bool &result)
+      : m_tid(tid), m_offset(offset), m_size(size), m_value(value),
+        m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    unsigned m_offset;
-    unsigned m_size;
-    RegisterValue &m_value;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  unsigned m_offset;
+  unsigned m_size;
+  RegisterValue &m_value;
+  bool &m_result;
 };
 
-void
-ReadRegOperation::Execute(ProcessMonitor *monitor)
-{
-    struct reg regs;
-    int rc;
-
-    if ((rc = PTRACE(PT_GETREGS, m_tid, (caddr_t)&regs, 0)) < 0) {
-        m_result = false;
-    } else {
-        // 'struct reg' contains only 32- or 64-bit register values.  Punt on
-        // others.  Also, not all entries may be uintptr_t sized, such as 32-bit
-        // processes on powerpc64 (probably the same for i386 on amd64)
-        if (m_size == sizeof(uint32_t))
-            m_value = *(uint32_t *)(((caddr_t)&regs) + m_offset);
-        else if (m_size == sizeof(uint64_t))
-            m_value = *(uint64_t *)(((caddr_t)&regs) + m_offset);
-        else
-            memcpy((void *)&m_value, (((caddr_t)&regs) + m_offset), m_size);
-        m_result = true;
-    }
+void ReadRegOperation::Execute(ProcessMonitor *monitor) {
+  struct reg regs;
+  int rc;
+
+  if ((rc = PTRACE(PT_GETREGS, m_tid, (caddr_t)&regs, 0)) < 0) {
+    m_result = false;
+  } else {
+    // 'struct reg' contains only 32- or 64-bit register values.  Punt on
+    // others.  Also, not all entries may be uintptr_t sized, such as 32-bit
+    // processes on powerpc64 (probably the same for i386 on amd64)
+    if (m_size == sizeof(uint32_t))
+      m_value = *(uint32_t *)(((caddr_t)&regs) + m_offset);
+    else if (m_size == sizeof(uint64_t))
+      m_value = *(uint64_t *)(((caddr_t)&regs) + m_offset);
+    else
+      memcpy((void *)&m_value, (((caddr_t)&regs) + m_offset), m_size);
+    m_result = true;
+  }
 }
 
 //------------------------------------------------------------------------------
 /// @class WriteRegOperation
 /// @brief Implements ProcessMonitor::WriteRegisterValue.
-class WriteRegOperation : public Operation
-{
+class WriteRegOperation : public Operation {
 public:
-    WriteRegOperation(lldb::tid_t tid, unsigned offset,
-                      const RegisterValue &value, bool &result)
-        : m_tid(tid), m_offset(offset),
-          m_value(value), m_result(result)
-        { }
+  WriteRegOperation(lldb::tid_t tid, unsigned offset,
+                    const RegisterValue &value, bool &result)
+      : m_tid(tid), m_offset(offset), m_value(value), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    unsigned m_offset;
-    const RegisterValue &m_value;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  unsigned m_offset;
+  const RegisterValue &m_value;
+  bool &m_result;
 };
 
-void
-WriteRegOperation::Execute(ProcessMonitor *monitor)
-{
-    struct reg regs;
-
-    if (PTRACE(PT_GETREGS, m_tid, (caddr_t)&regs, 0) < 0) {
-        m_result = false;
-        return;
-    }
-    *(uintptr_t *)(((caddr_t)&regs) + m_offset) = (uintptr_t)m_value.GetAsUInt64();
-    if (PTRACE(PT_SETREGS, m_tid, (caddr_t)&regs, 0) < 0)
-        m_result = false;
-    else
-        m_result = true;
+void WriteRegOperation::Execute(ProcessMonitor *monitor) {
+  struct reg regs;
+
+  if (PTRACE(PT_GETREGS, m_tid, (caddr_t)&regs, 0) < 0) {
+    m_result = false;
+    return;
+  }
+  *(uintptr_t *)(((caddr_t)&regs) + m_offset) =
+      (uintptr_t)m_value.GetAsUInt64();
+  if (PTRACE(PT_SETREGS, m_tid, (caddr_t)&regs, 0) < 0)
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class ReadDebugRegOperation
 /// @brief Implements ProcessMonitor::ReadDebugRegisterValue.
-class ReadDebugRegOperation : public Operation
-{
+class ReadDebugRegOperation : public Operation {
 public:
-    ReadDebugRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
-                          RegisterValue &value, bool &result)
-        : m_tid(tid), m_offset(offset), m_size(size),
-          m_value(value), m_result(result)
-        { }
+  ReadDebugRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
+                        RegisterValue &value, bool &result)
+      : m_tid(tid), m_offset(offset), m_size(size), m_value(value),
+        m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    unsigned m_offset;
-    unsigned m_size;
-    RegisterValue &m_value;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  unsigned m_offset;
+  unsigned m_size;
+  RegisterValue &m_value;
+  bool &m_result;
 };
 
-void
-ReadDebugRegOperation::Execute(ProcessMonitor *monitor)
-{
-    struct dbreg regs;
-    int rc;
-
-    if ((rc = PTRACE(PT_GETDBREGS, m_tid, (caddr_t)&regs, 0)) < 0) {
-        m_result = false;
-    } else {
-        if (m_size == sizeof(uintptr_t))
-            m_value = *(uintptr_t *)(((caddr_t)&regs) + m_offset);
-        else
-            memcpy((void *)&m_value, (((caddr_t)&regs) + m_offset), m_size);
-        m_result = true;
-    }
+void ReadDebugRegOperation::Execute(ProcessMonitor *monitor) {
+  struct dbreg regs;
+  int rc;
+
+  if ((rc = PTRACE(PT_GETDBREGS, m_tid, (caddr_t)&regs, 0)) < 0) {
+    m_result = false;
+  } else {
+    if (m_size == sizeof(uintptr_t))
+      m_value = *(uintptr_t *)(((caddr_t)&regs) + m_offset);
+    else
+      memcpy((void *)&m_value, (((caddr_t)&regs) + m_offset), m_size);
+    m_result = true;
+  }
 }
 
 //------------------------------------------------------------------------------
 /// @class WriteDebugRegOperation
 /// @brief Implements ProcessMonitor::WriteDebugRegisterValue.
-class WriteDebugRegOperation : public Operation
-{
+class WriteDebugRegOperation : public Operation {
 public:
-    WriteDebugRegOperation(lldb::tid_t tid, unsigned offset,
-                           const RegisterValue &value, bool &result)
-        : m_tid(tid), m_offset(offset),
-          m_value(value), m_result(result)
-        { }
+  WriteDebugRegOperation(lldb::tid_t tid, unsigned offset,
+                         const RegisterValue &value, bool &result)
+      : m_tid(tid), m_offset(offset), m_value(value), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    unsigned m_offset;
-    const RegisterValue &m_value;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  unsigned m_offset;
+  const RegisterValue &m_value;
+  bool &m_result;
 };
 
-void
-WriteDebugRegOperation::Execute(ProcessMonitor *monitor)
-{
-    struct dbreg regs;
-
-    if (PTRACE(PT_GETDBREGS, m_tid, (caddr_t)&regs, 0) < 0) {
-        m_result = false;
-        return;
-    }
-    *(uintptr_t *)(((caddr_t)&regs) + m_offset) = (uintptr_t)m_value.GetAsUInt64();
-    if (PTRACE(PT_SETDBREGS, m_tid, (caddr_t)&regs, 0) < 0)
-        m_result = false;
-    else
-        m_result = true;
+void WriteDebugRegOperation::Execute(ProcessMonitor *monitor) {
+  struct dbreg regs;
+
+  if (PTRACE(PT_GETDBREGS, m_tid, (caddr_t)&regs, 0) < 0) {
+    m_result = false;
+    return;
+  }
+  *(uintptr_t *)(((caddr_t)&regs) + m_offset) =
+      (uintptr_t)m_value.GetAsUInt64();
+  if (PTRACE(PT_SETDBREGS, m_tid, (caddr_t)&regs, 0) < 0)
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class ReadGPROperation
 /// @brief Implements ProcessMonitor::ReadGPR.
-class ReadGPROperation : public Operation
-{
+class ReadGPROperation : public Operation {
 public:
-    ReadGPROperation(lldb::tid_t tid, void *buf, bool &result)
-        : m_tid(tid), m_buf(buf), m_result(result)
-        { }
+  ReadGPROperation(lldb::tid_t tid, void *buf, bool &result)
+      : m_tid(tid), m_buf(buf), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    void *m_buf;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  void *m_buf;
+  bool &m_result;
 };
 
-void
-ReadGPROperation::Execute(ProcessMonitor *monitor)
-{
-    int rc;
-
-    errno = 0;
-    rc = PTRACE(PT_GETREGS, m_tid, (caddr_t)m_buf, 0);
-    if (errno != 0)
-        m_result = false;
-    else
-        m_result = true;
+void ReadGPROperation::Execute(ProcessMonitor *monitor) {
+  int rc;
+
+  errno = 0;
+  rc = PTRACE(PT_GETREGS, m_tid, (caddr_t)m_buf, 0);
+  if (errno != 0)
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class ReadFPROperation
 /// @brief Implements ProcessMonitor::ReadFPR.
-class ReadFPROperation : public Operation
-{
+class ReadFPROperation : public Operation {
 public:
-    ReadFPROperation(lldb::tid_t tid, void *buf, bool &result)
-        : m_tid(tid), m_buf(buf), m_result(result)
-        { }
+  ReadFPROperation(lldb::tid_t tid, void *buf, bool &result)
+      : m_tid(tid), m_buf(buf), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    void *m_buf;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  void *m_buf;
+  bool &m_result;
 };
 
-void
-ReadFPROperation::Execute(ProcessMonitor *monitor)
-{
-    if (PTRACE(PT_GETFPREGS, m_tid, (caddr_t)m_buf, 0) < 0)
-        m_result = false;
-    else
-        m_result = true;
+void ReadFPROperation::Execute(ProcessMonitor *monitor) {
+  if (PTRACE(PT_GETFPREGS, m_tid, (caddr_t)m_buf, 0) < 0)
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class WriteGPROperation
 /// @brief Implements ProcessMonitor::WriteGPR.
-class WriteGPROperation : public Operation
-{
+class WriteGPROperation : public Operation {
 public:
-    WriteGPROperation(lldb::tid_t tid, void *buf, bool &result)
-        : m_tid(tid), m_buf(buf), m_result(result)
-        { }
+  WriteGPROperation(lldb::tid_t tid, void *buf, bool &result)
+      : m_tid(tid), m_buf(buf), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    void *m_buf;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  void *m_buf;
+  bool &m_result;
 };
 
-void
-WriteGPROperation::Execute(ProcessMonitor *monitor)
-{
-    if (PTRACE(PT_SETREGS, m_tid, (caddr_t)m_buf, 0) < 0)
-        m_result = false;
-    else
-        m_result = true;
+void WriteGPROperation::Execute(ProcessMonitor *monitor) {
+  if (PTRACE(PT_SETREGS, m_tid, (caddr_t)m_buf, 0) < 0)
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class WriteFPROperation
 /// @brief Implements ProcessMonitor::WriteFPR.
-class WriteFPROperation : public Operation
-{
+class WriteFPROperation : public Operation {
 public:
-    WriteFPROperation(lldb::tid_t tid, void *buf, bool &result)
-        : m_tid(tid), m_buf(buf), m_result(result)
-        { }
+  WriteFPROperation(lldb::tid_t tid, void *buf, bool &result)
+      : m_tid(tid), m_buf(buf), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    void *m_buf;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  void *m_buf;
+  bool &m_result;
 };
 
-void
-WriteFPROperation::Execute(ProcessMonitor *monitor)
-{
-    if (PTRACE(PT_SETFPREGS, m_tid, (caddr_t)m_buf, 0) < 0)
-        m_result = false;
-    else
-        m_result = true;
+void WriteFPROperation::Execute(ProcessMonitor *monitor) {
+  if (PTRACE(PT_SETFPREGS, m_tid, (caddr_t)m_buf, 0) < 0)
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class ResumeOperation
 /// @brief Implements ProcessMonitor::Resume.
-class ResumeOperation : public Operation
-{
+class ResumeOperation : public Operation {
 public:
-    ResumeOperation(uint32_t signo, bool &result) :
-        m_signo(signo), m_result(result) { }
+  ResumeOperation(uint32_t signo, bool &result)
+      : m_signo(signo), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    uint32_t m_signo;
-    bool &m_result;
+  uint32_t m_signo;
+  bool &m_result;
 };
 
-void
-ResumeOperation::Execute(ProcessMonitor *monitor)
-{
-    lldb::pid_t pid = monitor->GetPID();
-    int data = 0;
-
-    if (m_signo != LLDB_INVALID_SIGNAL_NUMBER)
-        data = m_signo;
-
-    if (PTRACE(PT_CONTINUE, pid, (caddr_t)1, data))
-    {
-        Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
-
-        if (log)
-            log->Printf ("ResumeOperation (%"  PRIu64 ") failed: %s", pid, strerror(errno));
-        m_result = false;
-    }
-    else
-        m_result = true;
+void ResumeOperation::Execute(ProcessMonitor *monitor) {
+  lldb::pid_t pid = monitor->GetPID();
+  int data = 0;
+
+  if (m_signo != LLDB_INVALID_SIGNAL_NUMBER)
+    data = m_signo;
+
+  if (PTRACE(PT_CONTINUE, pid, (caddr_t)1, data)) {
+    Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+
+    if (log)
+      log->Printf("ResumeOperation (%" PRIu64 ") failed: %s", pid,
+                  strerror(errno));
+    m_result = false;
+  } else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class SingleStepOperation
 /// @brief Implements ProcessMonitor::SingleStep.
-class SingleStepOperation : public Operation
-{
+class SingleStepOperation : public Operation {
 public:
-    SingleStepOperation(uint32_t signo, bool &result)
-        : m_signo(signo), m_result(result) { }
+  SingleStepOperation(uint32_t signo, bool &result)
+      : m_signo(signo), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    uint32_t m_signo;
-    bool &m_result;
+  uint32_t m_signo;
+  bool &m_result;
 };
 
-void
-SingleStepOperation::Execute(ProcessMonitor *monitor)
-{
-    lldb::pid_t pid = monitor->GetPID();
-    int data = 0;
-
-    if (m_signo != LLDB_INVALID_SIGNAL_NUMBER)
-        data = m_signo;
-
-    if (PTRACE(PT_STEP, pid, NULL, data))
-        m_result = false;
-    else
-        m_result = true;
+void SingleStepOperation::Execute(ProcessMonitor *monitor) {
+  lldb::pid_t pid = monitor->GetPID();
+  int data = 0;
+
+  if (m_signo != LLDB_INVALID_SIGNAL_NUMBER)
+    data = m_signo;
+
+  if (PTRACE(PT_STEP, pid, NULL, data))
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class LwpInfoOperation
 /// @brief Implements ProcessMonitor::GetLwpInfo.
-class LwpInfoOperation : public Operation
-{
+class LwpInfoOperation : public Operation {
 public:
-    LwpInfoOperation(lldb::tid_t tid, void *info, bool &result, int &ptrace_err)
-        : m_tid(tid), m_info(info), m_result(result), m_err(ptrace_err) { }
+  LwpInfoOperation(lldb::tid_t tid, void *info, bool &result, int &ptrace_err)
+      : m_tid(tid), m_info(info), m_result(result), m_err(ptrace_err) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    void *m_info;
-    bool &m_result;
-    int &m_err;
+  lldb::tid_t m_tid;
+  void *m_info;
+  bool &m_result;
+  int &m_err;
 };
 
-void
-LwpInfoOperation::Execute(ProcessMonitor *monitor)
-{
-    struct ptrace_lwpinfo plwp;
-
-    if (PTRACE(PT_LWPINFO, m_tid, (caddr_t)&plwp, sizeof(plwp))) {
-        m_result = false;
-        m_err = errno;
-    } else {
-        memcpy(m_info, &plwp, sizeof(plwp));
-        m_result = true;
-    }
+void LwpInfoOperation::Execute(ProcessMonitor *monitor) {
+  struct ptrace_lwpinfo plwp;
+
+  if (PTRACE(PT_LWPINFO, m_tid, (caddr_t)&plwp, sizeof(plwp))) {
+    m_result = false;
+    m_err = errno;
+  } else {
+    memcpy(m_info, &plwp, sizeof(plwp));
+    m_result = true;
+  }
 }
 
 //------------------------------------------------------------------------------
 /// @class ThreadSuspendOperation
 /// @brief Implements ProcessMonitor::ThreadSuspend.
-class ThreadSuspendOperation : public Operation
-{
+class ThreadSuspendOperation : public Operation {
 public:
-    ThreadSuspendOperation(lldb::tid_t tid, bool suspend, bool &result)
-        : m_tid(tid), m_suspend(suspend), m_result(result) { }
+  ThreadSuspendOperation(lldb::tid_t tid, bool suspend, bool &result)
+      : m_tid(tid), m_suspend(suspend), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    bool m_suspend;
-    bool &m_result;
-} ;
-
-void
-ThreadSuspendOperation::Execute(ProcessMonitor *monitor)
-{
-    m_result = !PTRACE(m_suspend ? PT_SUSPEND : PT_RESUME, m_tid, NULL, 0);
-}
-
+  lldb::tid_t m_tid;
+  bool m_suspend;
+  bool &m_result;
+};
 
+void ThreadSuspendOperation::Execute(ProcessMonitor *monitor) {
+  m_result = !PTRACE(m_suspend ? PT_SUSPEND : PT_RESUME, m_tid, NULL, 0);
+}
 
 //------------------------------------------------------------------------------
 /// @class EventMessageOperation
 /// @brief Implements ProcessMonitor::GetEventMessage.
-class EventMessageOperation : public Operation
-{
+class EventMessageOperation : public Operation {
 public:
-    EventMessageOperation(lldb::tid_t tid, unsigned long *message, bool &result)
-        : m_tid(tid), m_message(message), m_result(result) { }
+  EventMessageOperation(lldb::tid_t tid, unsigned long *message, bool &result)
+      : m_tid(tid), m_message(message), m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    lldb::tid_t m_tid;
-    unsigned long *m_message;
-    bool &m_result;
+  lldb::tid_t m_tid;
+  unsigned long *m_message;
+  bool &m_result;
 };
 
-void
-EventMessageOperation::Execute(ProcessMonitor *monitor)
-{
-    struct ptrace_lwpinfo plwp;
+void EventMessageOperation::Execute(ProcessMonitor *monitor) {
+  struct ptrace_lwpinfo plwp;
 
-    if (PTRACE(PT_LWPINFO, m_tid, (caddr_t)&plwp, sizeof(plwp)))
-        m_result = false;
-    else {
-        if (plwp.pl_flags & PL_FLAG_FORKED) {
-            *m_message = plwp.pl_child_pid;
-            m_result = true;
-        } else
-            m_result = false;
-    }
+  if (PTRACE(PT_LWPINFO, m_tid, (caddr_t)&plwp, sizeof(plwp)))
+    m_result = false;
+  else {
+    if (plwp.pl_flags & PL_FLAG_FORKED) {
+      *m_message = plwp.pl_child_pid;
+      m_result = true;
+    } else
+      m_result = false;
+  }
 }
 
 //------------------------------------------------------------------------------
 /// @class KillOperation
 /// @brief Implements ProcessMonitor::Kill.
-class KillOperation : public Operation
-{
+class KillOperation : public Operation {
 public:
-    KillOperation(bool &result) : m_result(result) { }
+  KillOperation(bool &result) : m_result(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    bool &m_result;
+  bool &m_result;
 };
 
-void
-KillOperation::Execute(ProcessMonitor *monitor)
-{
-    lldb::pid_t pid = monitor->GetPID();
+void KillOperation::Execute(ProcessMonitor *monitor) {
+  lldb::pid_t pid = monitor->GetPID();
 
-    if (PTRACE(PT_KILL, pid, NULL, 0))
-        m_result = false;
-    else
-        m_result = true;
+  if (PTRACE(PT_KILL, pid, NULL, 0))
+    m_result = false;
+  else
+    m_result = true;
 }
 
 //------------------------------------------------------------------------------
 /// @class DetachOperation
 /// @brief Implements ProcessMonitor::Detach.
-class DetachOperation : public Operation
-{
+class DetachOperation : public Operation {
 public:
-    DetachOperation(Error &result) : m_error(result) { }
+  DetachOperation(Error &result) : m_error(result) {}
 
-    void Execute(ProcessMonitor *monitor);
+  void Execute(ProcessMonitor *monitor);
 
 private:
-    Error &m_error;
+  Error &m_error;
 };
 
-void
-DetachOperation::Execute(ProcessMonitor *monitor)
-{
-    lldb::pid_t pid = monitor->GetPID();
-
-    if (PTRACE(PT_DETACH, pid, NULL, 0) < 0)
-        m_error.SetErrorToErrno();
-  
+void DetachOperation::Execute(ProcessMonitor *monitor) {
+  lldb::pid_t pid = monitor->GetPID();
+
+  if (PTRACE(PT_DETACH, pid, NULL, 0) < 0)
+    m_error.SetErrorToErrno();
 }
 
 ProcessMonitor::OperationArgs::OperationArgs(ProcessMonitor *monitor)
-    : m_monitor(monitor)
-{
-    sem_init(&m_semaphore, 0, 0);
+    : m_monitor(monitor) {
+  sem_init(&m_semaphore, 0, 0);
 }
 
-ProcessMonitor::OperationArgs::~OperationArgs()
-{
-    sem_destroy(&m_semaphore);
-}
+ProcessMonitor::OperationArgs::~OperationArgs() { sem_destroy(&m_semaphore); }
 
 ProcessMonitor::LaunchArgs::LaunchArgs(ProcessMonitor *monitor,
                                        lldb_private::Module *module,
-                                       char const **argv,
-                                       char const **envp,
+                                       char const **argv, char const **envp,
                                        const FileSpec &stdin_file_spec,
                                        const FileSpec &stdout_file_spec,
                                        const FileSpec &stderr_file_spec,
                                        const FileSpec &working_dir)
-    : OperationArgs(monitor),
-      m_module(module),
-      m_argv(argv),
-      m_envp(envp),
-      m_stdin_file_spec(stdin_file_spec),
-      m_stdout_file_spec(stdout_file_spec),
-      m_stderr_file_spec(stderr_file_spec),
-      m_working_dir(working_dir) { }
-
-ProcessMonitor::LaunchArgs::~LaunchArgs()
-{ }
-
-ProcessMonitor::AttachArgs::AttachArgs(ProcessMonitor *monitor,
-                                       lldb::pid_t pid)
-    : OperationArgs(monitor), m_pid(pid) { }
+    : OperationArgs(monitor), m_module(module), m_argv(argv), m_envp(envp),
+      m_stdin_file_spec(stdin_file_spec), m_stdout_file_spec(stdout_file_spec),
+      m_stderr_file_spec(stderr_file_spec), m_working_dir(working_dir) {}
+
+ProcessMonitor::LaunchArgs::~LaunchArgs() {}
+
+ProcessMonitor::AttachArgs::AttachArgs(ProcessMonitor *monitor, lldb::pid_t pid)
+    : OperationArgs(monitor), m_pid(pid) {}
 
-ProcessMonitor::AttachArgs::~AttachArgs()
-{ }
+ProcessMonitor::AttachArgs::~AttachArgs() {}
 
 //------------------------------------------------------------------------------
 /// The basic design of the ProcessMonitor is built around two threads.
 ///
 /// One thread (@see SignalThread) simply blocks on a call to waitpid() looking
 /// for changes in the debugee state.  When a change is detected a
-/// ProcessMessage is sent to the associated ProcessFreeBSD instance.  This thread
+/// ProcessMessage is sent to the associated ProcessFreeBSD instance.  This
+/// thread
 /// "drives" state changes in the debugger.
 ///
 /// The second thread (@see OperationThread) is responsible for two things 1)
 /// launching or attaching to the inferior process, and then 2) servicing
 /// operations such as register reads/writes, stepping, etc.  See the comments
 /// on the Operation class for more info as to why this is needed.
-ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process,
-                               Module *module,
-                               const char *argv[],
-                               const char *envp[],
-                               const FileSpec &stdin_file_spec,
-                               const FileSpec &stdout_file_spec,
-                               const FileSpec &stderr_file_spec,
-                               const FileSpec &working_dir,
-                               const lldb_private::ProcessLaunchInfo & /* launch_info */,
-                               lldb_private::Error &error)
+ProcessMonitor::ProcessMonitor(
+    ProcessFreeBSD *process, Module *module, const char *argv[],
+    const char *envp[], const FileSpec &stdin_file_spec,
+    const FileSpec &stdout_file_spec, const FileSpec &stderr_file_spec,
+    const FileSpec &working_dir,
+    const lldb_private::ProcessLaunchInfo & /* launch_info */,
+    lldb_private::Error &error)
     : m_process(static_cast<ProcessFreeBSD *>(process)),
-      m_pid(LLDB_INVALID_PROCESS_ID),
-      m_terminal_fd(-1),
-      m_operation(0)
-{
-    using namespace std::placeholders;
-
-    std::unique_ptr<LaunchArgs> args(new LaunchArgs(this, module, argv, envp,
-                                                    stdin_file_spec,
-                                                    stdout_file_spec,
-                                                    stderr_file_spec,
-                                                    working_dir));
-    
-
-    sem_init(&m_operation_pending, 0, 0);
-    sem_init(&m_operation_done, 0, 0);
-
-    StartLaunchOpThread(args.get(), error);
-    if (!error.Success())
-        return;
+      m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
+  using namespace std::placeholders;
 
-WAIT_AGAIN:
-    // Wait for the operation thread to initialize.
-    if (sem_wait(&args->m_semaphore))
-    {
-        if (errno == EINTR)
-            goto WAIT_AGAIN;
-        else
-        {
-            error.SetErrorToErrno();
-            return;
-        }
-    }
+  std::unique_ptr<LaunchArgs> args(
+      new LaunchArgs(this, module, argv, envp, stdin_file_spec,
+                     stdout_file_spec, stderr_file_spec, working_dir));
+
+  sem_init(&m_operation_pending, 0, 0);
+  sem_init(&m_operation_done, 0, 0);
+
+  StartLaunchOpThread(args.get(), error);
+  if (!error.Success())
+    return;
 
-    // Check that the launch was a success.
-    if (!args->m_error.Success())
-    {
-        StopOpThread();
-        error = args->m_error;
-        return;
+WAIT_AGAIN:
+  // Wait for the operation thread to initialize.
+  if (sem_wait(&args->m_semaphore)) {
+    if (errno == EINTR)
+      goto WAIT_AGAIN;
+    else {
+      error.SetErrorToErrno();
+      return;
     }
+  }
 
-    // Finally, start monitoring the child process for change in state.
-    m_monitor_thread = Host::StartMonitoringChildProcess(
-        std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4), GetPID(), true);
-    if (!m_monitor_thread.IsJoinable())
-    {
-        error.SetErrorToGenericError();
-        error.SetErrorString("Process launch failed.");
-        return;
-    }
+  // Check that the launch was a success.
+  if (!args->m_error.Success()) {
+    StopOpThread();
+    error = args->m_error;
+    return;
+  }
+
+  // Finally, start monitoring the child process for change in state.
+  m_monitor_thread = Host::StartMonitoringChildProcess(
+      std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
+      GetPID(), true);
+  if (!m_monitor_thread.IsJoinable()) {
+    error.SetErrorToGenericError();
+    error.SetErrorString("Process launch failed.");
+    return;
+  }
 }
 
-ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process,
-                               lldb::pid_t pid,
+ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
                                lldb_private::Error &error)
-    : m_process(static_cast<ProcessFreeBSD *>(process)),
-      m_pid(pid),
-      m_terminal_fd(-1),
-      m_operation(0)
-{
-    using namespace std::placeholders;
-
-    sem_init(&m_operation_pending, 0, 0);
-    sem_init(&m_operation_done, 0, 0);
-
-
-    std::unique_ptr<AttachArgs> args(new AttachArgs(this, pid));
-
-    StartAttachOpThread(args.get(), error);
-    if (!error.Success())
-        return;
+    : m_process(static_cast<ProcessFreeBSD *>(process)), m_pid(pid),
+      m_terminal_fd(-1), m_operation(0) {
+  using namespace std::placeholders;
+
+  sem_init(&m_operation_pending, 0, 0);
+  sem_init(&m_operation_done, 0, 0);
+
+  std::unique_ptr<AttachArgs> args(new AttachArgs(this, pid));
+
+  StartAttachOpThread(args.get(), error);
+  if (!error.Success())
+    return;
 
 WAIT_AGAIN:
-    // Wait for the operation thread to initialize.
-    if (sem_wait(&args->m_semaphore))
-    {
-        if (errno == EINTR)
-            goto WAIT_AGAIN;
-        else
-        {
-            error.SetErrorToErrno();
-            return;
-        }
-    }
-
-    // Check that the attach was a success.
-    if (!args->m_error.Success())
-    {
-        StopOpThread();
-        error = args->m_error;
-        return;
+  // Wait for the operation thread to initialize.
+  if (sem_wait(&args->m_semaphore)) {
+    if (errno == EINTR)
+      goto WAIT_AGAIN;
+    else {
+      error.SetErrorToErrno();
+      return;
     }
+  }
 
-    // Finally, start monitoring the child process for change in state.
-    m_monitor_thread = Host::StartMonitoringChildProcess(
-        std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4), GetPID(), true);
-    if (!m_monitor_thread.IsJoinable())
-    {
-        error.SetErrorToGenericError();
-        error.SetErrorString("Process attach failed.");
-        return;
-    }
+  // Check that the attach was a success.
+  if (!args->m_error.Success()) {
+    StopOpThread();
+    error = args->m_error;
+    return;
+  }
+
+  // Finally, start monitoring the child process for change in state.
+  m_monitor_thread = Host::StartMonitoringChildProcess(
+      std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
+      GetPID(), true);
+  if (!m_monitor_thread.IsJoinable()) {
+    error.SetErrorToGenericError();
+    error.SetErrorString("Process attach failed.");
+    return;
+  }
 }
 
-ProcessMonitor::~ProcessMonitor()
-{
-    StopMonitor();
-}
+ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
 
 //------------------------------------------------------------------------------
 // Thread setup and tear down.
-void
-ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Error &error)
-{
-    static const char *g_thread_name = "lldb.process.freebsd.operation";
+void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Error &error) {
+  static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-    if (m_operation_thread.IsJoinable())
-        return;
+  if (m_operation_thread.IsJoinable())
+    return;
 
-    m_operation_thread = ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args, &error);
+  m_operation_thread =
+      ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args, &error);
 }
 
-void *
-ProcessMonitor::LaunchOpThread(void *arg)
-{
-    LaunchArgs *args = static_cast<LaunchArgs*>(arg);
-
-    if (!Launch(args)) {
-        sem_post(&args->m_semaphore);
-        return NULL;
-    }
+void *ProcessMonitor::LaunchOpThread(void *arg) {
+  LaunchArgs *args = static_cast<LaunchArgs *>(arg);
 
-    ServeOperation(args);
+  if (!Launch(args)) {
+    sem_post(&args->m_semaphore);
     return NULL;
+  }
+
+  ServeOperation(args);
+  return NULL;
 }
 
-bool
-ProcessMonitor::Launch(LaunchArgs *args)
-{
-    ProcessMonitor *monitor = args->m_monitor;
-    ProcessFreeBSD &process = monitor->GetProcess();
-    const char **argv = args->m_argv;
-    const char **envp = args->m_envp;
-    const FileSpec &stdin_file_spec = args->m_stdin_file_spec;
-    const FileSpec &stdout_file_spec = args->m_stdout_file_spec;
-    const FileSpec &stderr_file_spec = args->m_stderr_file_spec;
-    const FileSpec &working_dir = args->m_working_dir;
-
-    lldb_utility::PseudoTerminal terminal;
-    const size_t err_len = 1024;
-    char err_str[err_len];
-    ::pid_t pid;
-
-    // Propagate the environment if one is not supplied.
-    if (envp == NULL || envp[0] == NULL)
-        envp = const_cast<const char **>(environ);
-
-    if ((pid = terminal.Fork(err_str, err_len)) == -1)
-    {
-        args->m_error.SetErrorToGenericError();
-        args->m_error.SetErrorString("Process fork failed.");
-        goto FINISH;
-    }
+bool ProcessMonitor::Launch(LaunchArgs *args) {
+  ProcessMonitor *monitor = args->m_monitor;
+  ProcessFreeBSD &process = monitor->GetProcess();
+  const char **argv = args->m_argv;
+  const char **envp = args->m_envp;
+  const FileSpec &stdin_file_spec = args->m_stdin_file_spec;
+  const FileSpec &stdout_file_spec = args->m_stdout_file_spec;
+  const FileSpec &stderr_file_spec = args->m_stderr_file_spec;
+  const FileSpec &working_dir = args->m_working_dir;
+
+  lldb_utility::PseudoTerminal terminal;
+  const size_t err_len = 1024;
+  char err_str[err_len];
+  ::pid_t pid;
+
+  // Propagate the environment if one is not supplied.
+  if (envp == NULL || envp[0] == NULL)
+    envp = const_cast<const char **>(environ);
+
+  if ((pid = terminal.Fork(err_str, err_len)) == -1) {
+    args->m_error.SetErrorToGenericError();
+    args->m_error.SetErrorString("Process fork failed.");
+    goto FINISH;
+  }
+
+  // Recognized child exit status codes.
+  enum {
+    ePtraceFailed = 1,
+    eDupStdinFailed,
+    eDupStdoutFailed,
+    eDupStderrFailed,
+    eChdirFailed,
+    eExecFailed,
+    eSetGidFailed
+  };
+
+  // Child process.
+  if (pid == 0) {
+    // Trace this process.
+    if (PTRACE(PT_TRACE_ME, 0, NULL, 0) < 0)
+      exit(ePtraceFailed);
+
+    // terminal has already dupped the tty descriptors to stdin/out/err.
+    // This closes original fd from which they were copied (and avoids
+    // leaking descriptors to the debugged process.
+    terminal.CloseSlaveFileDescriptor();
+
+    // Do not inherit setgid powers.
+    if (setgid(getgid()) != 0)
+      exit(eSetGidFailed);
 
-    // Recognized child exit status codes.
-    enum {
-        ePtraceFailed = 1,
-        eDupStdinFailed,
-        eDupStdoutFailed,
-        eDupStderrFailed,
-        eChdirFailed,
-        eExecFailed,
-        eSetGidFailed
-    };
-
-    // Child process.
-    if (pid == 0)
-    {
-        // Trace this process.
-        if (PTRACE(PT_TRACE_ME, 0, NULL, 0) < 0)
-            exit(ePtraceFailed);
-
-        // terminal has already dupped the tty descriptors to stdin/out/err.
-        // This closes original fd from which they were copied (and avoids
-        // leaking descriptors to the debugged process.
-        terminal.CloseSlaveFileDescriptor();
-
-        // Do not inherit setgid powers.
-        if (setgid(getgid()) != 0)
-            exit(eSetGidFailed);
-
-        // Let us have our own process group.
-        setpgid(0, 0);
-
-        // Dup file descriptors if needed.
-        //
-        // FIXME: If two or more of the paths are the same we needlessly open
-        // the same file multiple times.
-        if (stdin_file_spec)
-            if (!DupDescriptor(stdin_file_spec, STDIN_FILENO, O_RDONLY))
-                exit(eDupStdinFailed);
-
-        if (stdout_file_spec)
-            if (!DupDescriptor(stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT))
-                exit(eDupStdoutFailed);
-
-        if (stderr_file_spec)
-            if (!DupDescriptor(stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT))
-                exit(eDupStderrFailed);
-
-        // Change working directory
-        if (working_dir && 0 != ::chdir(working_dir.GetCString()))
-            exit(eChdirFailed);
-
-        // Execute.  We should never return.
-        execve(argv[0],
-               const_cast<char *const *>(argv),
-               const_cast<char *const *>(envp));
-        exit(eExecFailed);
-    }
+    // Let us have our own process group.
+    setpgid(0, 0);
 
-    // Wait for the child process to to trap on its call to execve.
-    ::pid_t wpid;
-    int status;
-    if ((wpid = waitpid(pid, &status, 0)) < 0)
-    {
-        args->m_error.SetErrorToErrno();
-        goto FINISH;
-    }
-    else if (WIFEXITED(status))
-    {
-        // open, dup or execve likely failed for some reason.
-        args->m_error.SetErrorToGenericError();
-        switch (WEXITSTATUS(status))
-        {
-            case ePtraceFailed:
-                args->m_error.SetErrorString("Child ptrace failed.");
-                break;
-            case eDupStdinFailed:
-                args->m_error.SetErrorString("Child open stdin failed.");
-                break;
-            case eDupStdoutFailed:
-                args->m_error.SetErrorString("Child open stdout failed.");
-                break;
-            case eDupStderrFailed:
-                args->m_error.SetErrorString("Child open stderr failed.");
-                break;
-            case eChdirFailed:
-                args->m_error.SetErrorString("Child failed to set working directory.");
-                break;
-            case eExecFailed:
-                args->m_error.SetErrorString("Child exec failed.");
-                break;
-            case eSetGidFailed:
-                args->m_error.SetErrorString("Child setgid failed.");
-                break;
-            default:
-                args->m_error.SetErrorString("Child returned unknown exit status.");
-                break;
-        }
-        goto FINISH;
+    // Dup file descriptors if needed.
+    //
+    // FIXME: If two or more of the paths are the same we needlessly open
+    // the same file multiple times.
+    if (stdin_file_spec)
+      if (!DupDescriptor(stdin_file_spec, STDIN_FILENO, O_RDONLY))
+        exit(eDupStdinFailed);
+
+    if (stdout_file_spec)
+      if (!DupDescriptor(stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT))
+        exit(eDupStdoutFailed);
+
+    if (stderr_file_spec)
+      if (!DupDescriptor(stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT))
+        exit(eDupStderrFailed);
+
+    // Change working directory
+    if (working_dir && 0 != ::chdir(working_dir.GetCString()))
+      exit(eChdirFailed);
+
+    // Execute.  We should never return.
+    execve(argv[0], const_cast<char *const *>(argv),
+           const_cast<char *const *>(envp));
+    exit(eExecFailed);
+  }
+
+  // Wait for the child process to to trap on its call to execve.
+  ::pid_t wpid;
+  int status;
+  if ((wpid = waitpid(pid, &status, 0)) < 0) {
+    args->m_error.SetErrorToErrno();
+    goto FINISH;
+  } else if (WIFEXITED(status)) {
+    // open, dup or execve likely failed for some reason.
+    args->m_error.SetErrorToGenericError();
+    switch (WEXITSTATUS(status)) {
+    case ePtraceFailed:
+      args->m_error.SetErrorString("Child ptrace failed.");
+      break;
+    case eDupStdinFailed:
+      args->m_error.SetErrorString("Child open stdin failed.");
+      break;
+    case eDupStdoutFailed:
+      args->m_error.SetErrorString("Child open stdout failed.");
+      break;
+    case eDupStderrFailed:
+      args->m_error.SetErrorString("Child open stderr failed.");
+      break;
+    case eChdirFailed:
+      args->m_error.SetErrorString("Child failed to set working directory.");
+      break;
+    case eExecFailed:
+      args->m_error.SetErrorString("Child exec failed.");
+      break;
+    case eSetGidFailed:
+      args->m_error.SetErrorString("Child setgid failed.");
+      break;
+    default:
+      args->m_error.SetErrorString("Child returned unknown exit status.");
+      break;
     }
-    assert(WIFSTOPPED(status) && wpid == (::pid_t)pid &&
-           "Could not sync with inferior process.");
+    goto FINISH;
+  }
+  assert(WIFSTOPPED(status) && wpid == (::pid_t)pid &&
+         "Could not sync with inferior process.");
 
 #ifdef notyet
-    // Have the child raise an event on exit.  This is used to keep the child in
-    // limbo until it is destroyed.
-    if (PTRACE(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACEEXIT) < 0)
-    {
-        args->m_error.SetErrorToErrno();
-        goto FINISH;
-    }
+  // Have the child raise an event on exit.  This is used to keep the child in
+  // limbo until it is destroyed.
+  if (PTRACE(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACEEXIT) < 0) {
+    args->m_error.SetErrorToErrno();
+    goto FINISH;
+  }
 #endif
-    // Release the master terminal descriptor and pass it off to the
-    // ProcessMonitor instance.  Similarly stash the inferior pid.
-    monitor->m_terminal_fd = terminal.ReleaseMasterFileDescriptor();
-    monitor->m_pid = pid;
-
-    // Set the terminal fd to be in non blocking mode (it simplifies the
-    // implementation of ProcessFreeBSD::GetSTDOUT to have a non-blocking
-    // descriptor to read from).
-    if (!EnsureFDFlags(monitor->m_terminal_fd, O_NONBLOCK, args->m_error))
-        goto FINISH;
+  // Release the master terminal descriptor and pass it off to the
+  // ProcessMonitor instance.  Similarly stash the inferior pid.
+  monitor->m_terminal_fd = terminal.ReleaseMasterFileDescriptor();
+  monitor->m_pid = pid;
+
+  // Set the terminal fd to be in non blocking mode (it simplifies the
+  // implementation of ProcessFreeBSD::GetSTDOUT to have a non-blocking
+  // descriptor to read from).
+  if (!EnsureFDFlags(monitor->m_terminal_fd, O_NONBLOCK, args->m_error))
+    goto FINISH;
 
-    process.SendMessage(ProcessMessage::Attach(pid));
+  process.SendMessage(ProcessMessage::Attach(pid));
 
 FINISH:
-    return args->m_error.Success();
+  return args->m_error.Success();
 }
 
-void
-ProcessMonitor::StartAttachOpThread(AttachArgs *args, lldb_private::Error &error)
-{
-    static const char *g_thread_name = "lldb.process.freebsd.operation";
+void ProcessMonitor::StartAttachOpThread(AttachArgs *args,
+                                         lldb_private::Error &error) {
+  static const char *g_thread_name = "lldb.process.freebsd.operation";
 
-    if (m_operation_thread.IsJoinable())
-        return;
+  if (m_operation_thread.IsJoinable())
+    return;
 
-    m_operation_thread = ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args, &error);
+  m_operation_thread =
+      ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args, &error);
 }
 
-void *
-ProcessMonitor::AttachOpThread(void *arg)
-{
-    AttachArgs *args = static_cast<AttachArgs*>(arg);
+void *ProcessMonitor::AttachOpThread(void *arg) {
+  AttachArgs *args = static_cast<AttachArgs *>(arg);
 
-    Attach(args);
+  Attach(args);
 
-    ServeOperation(args);
-    return NULL;
+  ServeOperation(args);
+  return NULL;
 }
 
-void
-ProcessMonitor::Attach(AttachArgs *args)
-{
-    lldb::pid_t pid = args->m_pid;
-
-    ProcessMonitor *monitor = args->m_monitor;
-    ProcessFreeBSD &process = monitor->GetProcess();
-
-    if (pid <= 1)
-    {
-        args->m_error.SetErrorToGenericError();
-        args->m_error.SetErrorString("Attaching to process 1 is not allowed.");
-        return;
-    }
+void ProcessMonitor::Attach(AttachArgs *args) {
+  lldb::pid_t pid = args->m_pid;
 
-    // Attach to the requested process.
-    if (PTRACE(PT_ATTACH, pid, NULL, 0) < 0)
-    {
-        args->m_error.SetErrorToErrno();
-        return;
-    }
+  ProcessMonitor *monitor = args->m_monitor;
+  ProcessFreeBSD &process = monitor->GetProcess();
 
-    int status;
-    if ((status = waitpid(pid, NULL, 0)) < 0)
-    {
-        args->m_error.SetErrorToErrno();
-        return;
-    }
+  if (pid <= 1) {
+    args->m_error.SetErrorToGenericError();
+    args->m_error.SetErrorString("Attaching to process 1 is not allowed.");
+    return;
+  }
+
+  // Attach to the requested process.
+  if (PTRACE(PT_ATTACH, pid, NULL, 0) < 0) {
+    args->m_error.SetErrorToErrno();
+    return;
+  }
 
-    process.SendMessage(ProcessMessage::Attach(pid));
+  int status;
+  if ((status = waitpid(pid, NULL, 0)) < 0) {
+    args->m_error.SetErrorToErrno();
+    return;
+  }
+
+  process.SendMessage(ProcessMessage::Attach(pid));
 }
 
 size_t
-ProcessMonitor::GetCurrentThreadIDs(std::vector<lldb::tid_t>&thread_ids)
-{
-    lwpid_t *tids;
-    int tdcnt;
-
-    thread_ids.clear();
-
-    tdcnt = PTRACE(PT_GETNUMLWPS, m_pid, NULL, 0);
-    if (tdcnt <= 0)
-        return 0;
-    tids = (lwpid_t *)malloc(tdcnt * sizeof(*tids));
-    if (tids == NULL)
-        return 0;
-    if (PTRACE(PT_GETLWPLIST, m_pid, (void *)tids, tdcnt) < 0) {
-        free(tids);
-        return 0;
-    }
-    thread_ids = std::vector<lldb::tid_t>(tids, tids + tdcnt);
+ProcessMonitor::GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids) {
+  lwpid_t *tids;
+  int tdcnt;
+
+  thread_ids.clear();
+
+  tdcnt = PTRACE(PT_GETNUMLWPS, m_pid, NULL, 0);
+  if (tdcnt <= 0)
+    return 0;
+  tids = (lwpid_t *)malloc(tdcnt * sizeof(*tids));
+  if (tids == NULL)
+    return 0;
+  if (PTRACE(PT_GETLWPLIST, m_pid, (void *)tids, tdcnt) < 0) {
     free(tids);
-    return thread_ids.size();
-}
+    return 0;
+  }
+  thread_ids = std::vector<lldb::tid_t>(tids, tids + tdcnt);
+  free(tids);
+  return thread_ids.size();
+}
+
+bool ProcessMonitor::MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid,
+                                     bool exited, int signal, int status) {
+  ProcessMessage message;
+  ProcessFreeBSD *process = monitor->m_process;
+  assert(process);
+  bool stop_monitoring;
+  struct ptrace_lwpinfo plwp;
+  int ptrace_err;
 
-bool
-ProcessMonitor::MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid, bool exited, int signal, int status)
-{
-    ProcessMessage message;
-    ProcessFreeBSD *process = monitor->m_process;
-    assert(process);
-    bool stop_monitoring;
-    struct ptrace_lwpinfo plwp;
-    int ptrace_err;
-
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
-
-    if (exited)
-    {
-        if (log)
-            log->Printf ("ProcessMonitor::%s() got exit signal, tid = %"  PRIu64, __FUNCTION__, pid);
-        message = ProcessMessage::Exit(pid, status);
-        process->SendMessage(message);
-        return pid == process->GetID();
-    }
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
 
-    if (!monitor->GetLwpInfo(pid, &plwp, ptrace_err))
-        stop_monitoring = true; // pid is gone.  Bail.
-    else {
-        switch (plwp.pl_siginfo.si_signo)
-        {
-        case SIGTRAP:
-            message = MonitorSIGTRAP(monitor, &plwp.pl_siginfo, plwp.pl_lwpid);
-            break;
-            
-        default:
-            message = MonitorSignal(monitor, &plwp.pl_siginfo, plwp.pl_lwpid);
-            break;
-        }
+  if (exited) {
+    if (log)
+      log->Printf("ProcessMonitor::%s() got exit signal, tid = %" PRIu64,
+                  __FUNCTION__, pid);
+    message = ProcessMessage::Exit(pid, status);
+    process->SendMessage(message);
+    return pid == process->GetID();
+  }
+
+  if (!monitor->GetLwpInfo(pid, &plwp, ptrace_err))
+    stop_monitoring = true; // pid is gone.  Bail.
+  else {
+    switch (plwp.pl_siginfo.si_signo) {
+    case SIGTRAP:
+      message = MonitorSIGTRAP(monitor, &plwp.pl_siginfo, plwp.pl_lwpid);
+      break;
 
-        process->SendMessage(message);
-        stop_monitoring = message.GetKind() == ProcessMessage::eExitMessage;
+    default:
+      message = MonitorSignal(monitor, &plwp.pl_siginfo, plwp.pl_lwpid);
+      break;
     }
 
-    return stop_monitoring;
-}
-
-ProcessMessage
-ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
-                               const siginfo_t *info, lldb::tid_t tid)
-{
-    ProcessMessage message;
-
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
+    process->SendMessage(message);
+    stop_monitoring = message.GetKind() == ProcessMessage::eExitMessage;
+  }
 
-    assert(monitor);
-    assert(info && info->si_signo == SIGTRAP && "Unexpected child signal!");
+  return stop_monitoring;
+}
 
-    switch (info->si_code)
-    {
-    default:
-        assert(false && "Unexpected SIGTRAP code!");
-        break;
+ProcessMessage ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
+                                              const siginfo_t *info,
+                                              lldb::tid_t tid) {
+  ProcessMessage message;
 
-    case (SIGTRAP /* | (PTRACE_EVENT_EXIT << 8) */):
-    {
-        // The inferior process is about to exit.  Maintain the process in a
-        // state of "limbo" until we are explicitly commanded to detach,
-        // destroy, resume, etc.
-        unsigned long data = 0;
-        if (!monitor->GetEventMessage(tid, &data))
-            data = -1;
-        if (log)
-            log->Printf ("ProcessMonitor::%s() received exit? event, data = %lx, tid = %" PRIu64, __FUNCTION__, data, tid);
-        message = ProcessMessage::Limbo(tid, (data >> 8));
-        break;
-    }
-
-    case 0:
-    case TRAP_TRACE:
-        if (log)
-            log->Printf ("ProcessMonitor::%s() received trace event, tid = %" PRIu64 "  : si_code = %d", __FUNCTION__, tid, info->si_code);
-        message = ProcessMessage::Trace(tid);
-        break;
-
-    case SI_KERNEL:
-    case TRAP_BRKPT:
-        if (log)
-            log->Printf ("ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64, __FUNCTION__, tid);
-        message = ProcessMessage::Break(tid);
-        break;
-    }
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
 
-    return message;
-}
+  assert(monitor);
+  assert(info && info->si_signo == SIGTRAP && "Unexpected child signal!");
 
-ProcessMessage
-ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
-                              const siginfo_t *info, lldb::tid_t tid)
-{
-    ProcessMessage message;
-    int signo = info->si_signo;
+  switch (info->si_code) {
+  default:
+    assert(false && "Unexpected SIGTRAP code!");
+    break;
 
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
+  case (SIGTRAP /* | (PTRACE_EVENT_EXIT << 8) */): {
+    // The inferior process is about to exit.  Maintain the process in a
+    // state of "limbo" until we are explicitly commanded to detach,
+    // destroy, resume, etc.
+    unsigned long data = 0;
+    if (!monitor->GetEventMessage(tid, &data))
+      data = -1;
+    if (log)
+      log->Printf("ProcessMonitor::%s() received exit? event, data = %lx, tid "
+                  "= %" PRIu64,
+                  __FUNCTION__, data, tid);
+    message = ProcessMessage::Limbo(tid, (data >> 8));
+    break;
+  }
 
-    // POSIX says that process behaviour is undefined after it ignores a SIGFPE,
-    // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a
-    // kill(2) or raise(3).  Similarly for tgkill(2) on FreeBSD.
-    //
-    // IOW, user generated signals never generate what we consider to be a
-    // "crash".
-    //
-    // Similarly, ACK signals generated by this monitor.
-    if (info->si_code == SI_USER)
-    {
-        if (log)
-            log->Printf ("ProcessMonitor::%s() received signal %s with code %s, pid = %d",
-                            __FUNCTION__,
-                            monitor->m_process->GetUnixSignals()->GetSignalAsCString (signo),
-                            "SI_USER",
-                            info->si_pid);
-        if (info->si_pid == getpid())
-            return ProcessMessage::SignalDelivered(tid, signo);
-        else
-            return ProcessMessage::Signal(tid, signo);
-    }
+  case 0:
+  case TRAP_TRACE:
+    if (log)
+      log->Printf("ProcessMonitor::%s() received trace event, tid = %" PRIu64
+                  "  : si_code = %d",
+                  __FUNCTION__, tid, info->si_code);
+    message = ProcessMessage::Trace(tid);
+    break;
 
+  case SI_KERNEL:
+  case TRAP_BRKPT:
+    if (log)
+      log->Printf(
+          "ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64,
+          __FUNCTION__, tid);
+    message = ProcessMessage::Break(tid);
+    break;
+  }
+
+  return message;
+}
+
+ProcessMessage ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
+                                             const siginfo_t *info,
+                                             lldb::tid_t tid) {
+  ProcessMessage message;
+  int signo = info->si_signo;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+
+  // POSIX says that process behaviour is undefined after it ignores a SIGFPE,
+  // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a
+  // kill(2) or raise(3).  Similarly for tgkill(2) on FreeBSD.
+  //
+  // IOW, user generated signals never generate what we consider to be a
+  // "crash".
+  //
+  // Similarly, ACK signals generated by this monitor.
+  if (info->si_code == SI_USER) {
     if (log)
-        log->Printf ("ProcessMonitor::%s() received signal %s", __FUNCTION__, monitor->m_process->GetUnixSignals()->GetSignalAsCString (signo));
+      log->Printf(
+          "ProcessMonitor::%s() received signal %s with code %s, pid = %d",
+          __FUNCTION__,
+          monitor->m_process->GetUnixSignals()->GetSignalAsCString(signo),
+          "SI_USER", info->si_pid);
+    if (info->si_pid == getpid())
+      return ProcessMessage::SignalDelivered(tid, signo);
+    else
+      return ProcessMessage::Signal(tid, signo);
+  }
 
-    switch (signo)
-    {
-    case SIGSEGV:
-    case SIGILL:
-    case SIGFPE:
-    case SIGBUS:
-        lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
-        const auto reason = GetCrashReason(*info);
-        return ProcessMessage::Crash(tid, reason, signo, fault_addr);
-    }
+  if (log)
+    log->Printf(
+        "ProcessMonitor::%s() received signal %s", __FUNCTION__,
+        monitor->m_process->GetUnixSignals()->GetSignalAsCString(signo));
+
+  switch (signo) {
+  case SIGSEGV:
+  case SIGILL:
+  case SIGFPE:
+  case SIGBUS:
+    lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
+    const auto reason = GetCrashReason(*info);
+    return ProcessMessage::Crash(tid, reason, signo, fault_addr);
+  }
 
-    // Everything else is "normal" and does not require any special action on
-    // our part.
-    return ProcessMessage::Signal(tid, signo);
+  // Everything else is "normal" and does not require any special action on
+  // our part.
+  return ProcessMessage::Signal(tid, signo);
 }
 
-void
-ProcessMonitor::ServeOperation(OperationArgs *args)
-{
-    ProcessMonitor *monitor = args->m_monitor;
+void ProcessMonitor::ServeOperation(OperationArgs *args) {
+  ProcessMonitor *monitor = args->m_monitor;
 
-    // We are finised with the arguments and are ready to go.  Sync with the
-    // parent thread and start serving operations on the inferior.
-    sem_post(&args->m_semaphore);
+  // We are finised with the arguments and are ready to go.  Sync with the
+  // parent thread and start serving operations on the inferior.
+  sem_post(&args->m_semaphore);
 
-    for (;;)
-    {
-        // wait for next pending operation
-        sem_wait(&monitor->m_operation_pending);
+  for (;;) {
+    // wait for next pending operation
+    sem_wait(&monitor->m_operation_pending);
 
-        monitor->m_operation->Execute(monitor);
+    monitor->m_operation->Execute(monitor);
 
-        // notify calling thread that operation is complete
-        sem_post(&monitor->m_operation_done);
-    }
+    // notify calling thread that operation is complete
+    sem_post(&monitor->m_operation_done);
+  }
 }
 
-void
-ProcessMonitor::DoOperation(Operation *op)
-{
-    std::lock_guard<std::mutex> guard(m_operation_mutex);
+void ProcessMonitor::DoOperation(Operation *op) {
+  std::lock_guard<std::mutex> guard(m_operation_mutex);
 
-    m_operation = op;
+  m_operation = op;
 
-    // notify operation thread that an operation is ready to be processed
-    sem_post(&m_operation_pending);
+  // notify operation thread that an operation is ready to be processed
+  sem_post(&m_operation_pending);
 
-    // wait for operation to complete
-    sem_wait(&m_operation_done);
+  // wait for operation to complete
+  sem_wait(&m_operation_done);
 }
 
-size_t
-ProcessMonitor::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
-                           Error &error)
-{
-    size_t result;
-    ReadOperation op(vm_addr, buf, size, error, result);
-    DoOperation(&op);
-    return result;
+size_t ProcessMonitor::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+                                  Error &error) {
+  size_t result;
+  ReadOperation op(vm_addr, buf, size, error, result);
+  DoOperation(&op);
+  return result;
 }
 
-size_t
-ProcessMonitor::WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
-                            lldb_private::Error &error)
-{
-    size_t result;
-    WriteOperation op(vm_addr, buf, size, error, result);
-    DoOperation(&op);
-    return result;
+size_t ProcessMonitor::WriteMemory(lldb::addr_t vm_addr, const void *buf,
+                                   size_t size, lldb_private::Error &error) {
+  size_t result;
+  WriteOperation op(vm_addr, buf, size, error, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char* reg_name,
-                                  unsigned size, RegisterValue &value)
-{
-    bool result;
-    ReadRegOperation op(tid, offset, size, value, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::ReadRegisterValue(lldb::tid_t tid, unsigned offset,
+                                       const char *reg_name, unsigned size,
+                                       RegisterValue &value) {
+  bool result;
+  ReadRegOperation op(tid, offset, size, value, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::WriteRegisterValue(lldb::tid_t tid, unsigned offset,
-                                   const char* reg_name, const RegisterValue &value)
-{
-    bool result;
-    WriteRegOperation op(tid, offset, value, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::WriteRegisterValue(lldb::tid_t tid, unsigned offset,
+                                        const char *reg_name,
+                                        const RegisterValue &value) {
+  bool result;
+  WriteRegOperation op(tid, offset, value, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::ReadDebugRegisterValue(lldb::tid_t tid, unsigned offset,
-                                       const char *reg_name, unsigned size,
-                                       lldb_private::RegisterValue &value)
-{
-    bool result;
-    ReadDebugRegOperation op(tid, offset, size, value, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::ReadDebugRegisterValue(
+    lldb::tid_t tid, unsigned offset, const char *reg_name, unsigned size,
+    lldb_private::RegisterValue &value) {
+  bool result;
+  ReadDebugRegOperation op(tid, offset, size, value, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::WriteDebugRegisterValue(lldb::tid_t tid, unsigned offset,
-                                        const char *reg_name,
-                                        const lldb_private::RegisterValue &value)
-{
-    bool result;
-    WriteDebugRegOperation op(tid, offset, value, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::WriteDebugRegisterValue(
+    lldb::tid_t tid, unsigned offset, const char *reg_name,
+    const lldb_private::RegisterValue &value) {
+  bool result;
+  WriteDebugRegOperation op(tid, offset, value, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size)
-{
-    bool result;
-    ReadGPROperation op(tid, buf, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size) {
+  bool result;
+  ReadGPROperation op(tid, buf, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size)
-{
-    bool result;
-    ReadFPROperation op(tid, buf, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size) {
+  bool result;
+  ReadFPROperation op(tid, buf, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::ReadRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset)
-{
-    return false;
+bool ProcessMonitor::ReadRegisterSet(lldb::tid_t tid, void *buf,
+                                     size_t buf_size, unsigned int regset) {
+  return false;
 }
 
-bool
-ProcessMonitor::WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size)
-{
-    bool result;
-    WriteGPROperation op(tid, buf, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size) {
+  bool result;
+  WriteGPROperation op(tid, buf, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size)
-{
-    bool result;
-    WriteFPROperation op(tid, buf, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size) {
+  bool result;
+  WriteFPROperation op(tid, buf, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::WriteRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset)
-{
-    return false;
+bool ProcessMonitor::WriteRegisterSet(lldb::tid_t tid, void *buf,
+                                      size_t buf_size, unsigned int regset) {
+  return false;
 }
 
-bool
-ProcessMonitor::ReadThreadPointer(lldb::tid_t tid, lldb::addr_t &value)
-{
-    return false;
+bool ProcessMonitor::ReadThreadPointer(lldb::tid_t tid, lldb::addr_t &value) {
+  return false;
 }
 
-bool
-ProcessMonitor::Resume(lldb::tid_t unused, uint32_t signo)
-{
-    bool result;
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
-
-    if (log) {
-        const char *signame = m_process->GetUnixSignals()->GetSignalAsCString (signo);
-        if (signame == nullptr)
-            signame = "<none>";
-        log->Printf("ProcessMonitor::%s() resuming pid %"  PRIu64 " with signal %s",
-                    __FUNCTION__, GetPID(), signame);
-    }
-    ResumeOperation op(signo, result);
-    DoOperation(&op);
-    if (log)
-        log->Printf ("ProcessMonitor::%s() resuming result = %s", __FUNCTION__, result ? "true" : "false");
-    return result;
+bool ProcessMonitor::Resume(lldb::tid_t unused, uint32_t signo) {
+  bool result;
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+
+  if (log) {
+    const char *signame =
+        m_process->GetUnixSignals()->GetSignalAsCString(signo);
+    if (signame == nullptr)
+      signame = "<none>";
+    log->Printf("ProcessMonitor::%s() resuming pid %" PRIu64 " with signal %s",
+                __FUNCTION__, GetPID(), signame);
+  }
+  ResumeOperation op(signo, result);
+  DoOperation(&op);
+  if (log)
+    log->Printf("ProcessMonitor::%s() resuming result = %s", __FUNCTION__,
+                result ? "true" : "false");
+  return result;
 }
 
-bool
-ProcessMonitor::SingleStep(lldb::tid_t unused, uint32_t signo)
-{
-    bool result;
-    SingleStepOperation op(signo, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::SingleStep(lldb::tid_t unused, uint32_t signo) {
+  bool result;
+  SingleStepOperation op(signo, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::Kill()
-{
-    bool result;
-    KillOperation op(result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::Kill() {
+  bool result;
+  KillOperation op(result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::GetLwpInfo(lldb::tid_t tid, void *lwpinfo, int &ptrace_err)
-{
-    bool result;
-    LwpInfoOperation op(tid, lwpinfo, result, ptrace_err);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::GetLwpInfo(lldb::tid_t tid, void *lwpinfo,
+                                int &ptrace_err) {
+  bool result;
+  LwpInfoOperation op(tid, lwpinfo, result, ptrace_err);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::ThreadSuspend(lldb::tid_t tid, bool suspend)
-{
-    bool result;
-    ThreadSuspendOperation op(tid, suspend, result);
-    DoOperation(&op);
-    return result;
+bool ProcessMonitor::ThreadSuspend(lldb::tid_t tid, bool suspend) {
+  bool result;
+  ThreadSuspendOperation op(tid, suspend, result);
+  DoOperation(&op);
+  return result;
+}
+
+bool ProcessMonitor::GetEventMessage(lldb::tid_t tid, unsigned long *message) {
+  bool result;
+  EventMessageOperation op(tid, message, result);
+  DoOperation(&op);
+  return result;
 }
 
-bool
-ProcessMonitor::GetEventMessage(lldb::tid_t tid, unsigned long *message)
-{
-    bool result;
-    EventMessageOperation op(tid, message, result);
+lldb_private::Error ProcessMonitor::Detach(lldb::tid_t tid) {
+  lldb_private::Error error;
+  if (tid != LLDB_INVALID_THREAD_ID) {
+    DetachOperation op(error);
     DoOperation(&op);
-    return result;
+  }
+  return error;
 }
 
-lldb_private::Error
-ProcessMonitor::Detach(lldb::tid_t tid)
-{
-    lldb_private::Error error;
-    if (tid != LLDB_INVALID_THREAD_ID)
-    {
-        DetachOperation op(error);
-        DoOperation(&op);
-    }
-    return error;
-}    
+bool ProcessMonitor::DupDescriptor(const FileSpec &file_spec, int fd,
+                                   int flags) {
+  int target_fd = open(file_spec.GetCString(), flags, 0666);
 
-bool
-ProcessMonitor::DupDescriptor(const FileSpec &file_spec, int fd, int flags)
-{
-    int target_fd = open(file_spec.GetCString(), flags, 0666);
-
-    if (target_fd == -1)
-        return false;
-
-    if (dup2(target_fd, fd) == -1)
-        return false;
-
-    return (close(target_fd) == -1) ? false : true;
-}
-
-void
-ProcessMonitor::StopMonitoringChildProcess()
-{
-    if (m_monitor_thread.IsJoinable())
-    {
-        m_monitor_thread.Cancel();
-        m_monitor_thread.Join(nullptr);
-        m_monitor_thread.Reset();
-    }
+  if (target_fd == -1)
+    return false;
+
+  if (dup2(target_fd, fd) == -1)
+    return false;
+
+  return (close(target_fd) == -1) ? false : true;
 }
 
-void
-ProcessMonitor::StopMonitor()
-{
-    StopMonitoringChildProcess();
-    StopOpThread();
-    sem_destroy(&m_operation_pending);
-    sem_destroy(&m_operation_done);
-    if (m_terminal_fd >= 0) {
-        close(m_terminal_fd);
-        m_terminal_fd = -1;
-    }
+void ProcessMonitor::StopMonitoringChildProcess() {
+  if (m_monitor_thread.IsJoinable()) {
+    m_monitor_thread.Cancel();
+    m_monitor_thread.Join(nullptr);
+    m_monitor_thread.Reset();
+  }
+}
+
+void ProcessMonitor::StopMonitor() {
+  StopMonitoringChildProcess();
+  StopOpThread();
+  sem_destroy(&m_operation_pending);
+  sem_destroy(&m_operation_done);
+  if (m_terminal_fd >= 0) {
+    close(m_terminal_fd);
+    m_terminal_fd = -1;
+  }
 }
 
 // FIXME: On Linux, when a new thread is created, we receive to notifications,
@@ -1607,19 +1439,13 @@ ProcessMonitor::StopMonitor()
 // We really should figure out what actually happens on FreeBSD and move the
 // Linux-specific logic out of ProcessPOSIX as needed.
 
-bool
-ProcessMonitor::WaitForInitialTIDStop(lldb::tid_t tid)
-{
-    return true;
-}
+bool ProcessMonitor::WaitForInitialTIDStop(lldb::tid_t tid) { return true; }
 
-void
-ProcessMonitor::StopOpThread()
-{
-    if (!m_operation_thread.IsJoinable())
-        return;
-
-    m_operation_thread.Cancel();
-    m_operation_thread.Join(nullptr);
-    m_operation_thread.Reset();
+void ProcessMonitor::StopOpThread() {
+  if (!m_operation_thread.IsJoinable())
+    return;
+
+  m_operation_thread.Cancel();
+  m_operation_thread.Join(nullptr);
+  m_operation_thread.Reset();
 }

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h Tue Sep  6 15:57:50 2016
@@ -18,12 +18,11 @@
 #include <mutex>
 
 // Other libraries and framework includes
-#include "lldb/lldb-types.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Host/HostThread.h"
+#include "lldb/lldb-types.h"
 
-namespace lldb_private
-{
+namespace lldb_private {
 class Error;
 class Module;
 class Scalar;
@@ -44,285 +43,242 @@ class Operation;
 ///
 /// A purposely minimal set of operations are provided to interrogate and change
 /// the inferior process state.
-class ProcessMonitor
-{
+class ProcessMonitor {
 public:
+  /// Launches an inferior process ready for debugging.  Forms the
+  /// implementation of Process::DoLaunch.
+  ProcessMonitor(ProcessFreeBSD *process, lldb_private::Module *module,
+                 char const *argv[], char const *envp[],
+                 const lldb_private::FileSpec &stdin_file_spec,
+                 const lldb_private::FileSpec &stdout_file_spec,
+                 const lldb_private::FileSpec &stderr_file_spec,
+                 const lldb_private::FileSpec &working_dir,
+                 const lldb_private::ProcessLaunchInfo &launch_info,
+                 lldb_private::Error &error);
+
+  ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
+                 lldb_private::Error &error);
+
+  ~ProcessMonitor();
+
+  /// Provides the process number of debugee.
+  lldb::pid_t GetPID() const { return m_pid; }
+
+  /// Returns the process associated with this ProcessMonitor.
+  ProcessFreeBSD &GetProcess() { return *m_process; }
+
+  /// Returns a file descriptor to the controlling terminal of the inferior
+  /// process.
+  ///
+  /// Reads from this file descriptor yield both the standard output and
+  /// standard error of this debugee.  Even if stderr and stdout were
+  /// redirected on launch it may still happen that data is available on this
+  /// descriptor (if the inferior process opens /dev/tty, for example). This
+  /// descriptor is
+  /// closed after a call to StopMonitor().
+  ///
+  /// If this monitor was attached to an existing process this method returns
+  /// -1.
+  int GetTerminalFD() const { return m_terminal_fd; }
+
+  /// Reads @p size bytes from address @vm_adder in the inferior process
+  /// address space.
+  ///
+  /// This method is provided to implement Process::DoReadMemory.
+  size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+                    lldb_private::Error &error);
+
+  /// Writes @p size bytes from address @p vm_adder in the inferior process
+  /// address space.
+  ///
+  /// This method is provided to implement Process::DoWriteMemory.
+  size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
+                     lldb_private::Error &error);
+
+  /// Reads the contents from the register identified by the given (architecture
+  /// dependent) offset.
+  ///
+  /// This method is provided for use by RegisterContextFreeBSD derivatives.
+  bool ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
+                         unsigned size, lldb_private::RegisterValue &value);
+
+  /// Writes the given value to the register identified by the given
+  /// (architecture dependent) offset.
+  ///
+  /// This method is provided for use by RegisterContextFreeBSD derivatives.
+  bool WriteRegisterValue(lldb::tid_t tid, unsigned offset,
+                          const char *reg_name,
+                          const lldb_private::RegisterValue &value);
+
+  /// Reads the contents from the debug register identified by the given
+  /// (architecture dependent) offset.
+  ///
+  /// This method is provided for use by RegisterContextFreeBSD derivatives.
+  bool ReadDebugRegisterValue(lldb::tid_t tid, unsigned offset,
+                              const char *reg_name, unsigned size,
+                              lldb_private::RegisterValue &value);
+
+  /// Writes the given value to the debug register identified by the given
+  /// (architecture dependent) offset.
+  ///
+  /// This method is provided for use by RegisterContextFreeBSD derivatives.
+  bool WriteDebugRegisterValue(lldb::tid_t tid, unsigned offset,
+                               const char *reg_name,
+                               const lldb_private::RegisterValue &value);
+  /// Reads all general purpose registers into the specified buffer.
+  bool ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size);
+
+  /// Reads all floating point registers into the specified buffer.
+  bool ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size);
+
+  /// Reads the specified register set into the specified buffer.
+  ///
+  /// This method is provided for use by RegisterContextFreeBSD derivatives.
+  bool ReadRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size,
+                       unsigned int regset);
+
+  /// Writes all general purpose registers into the specified buffer.
+  bool WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size);
+
+  /// Writes all floating point registers into the specified buffer.
+  bool WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size);
+
+  /// Writes the specified register set into the specified buffer.
+  ///
+  /// This method is provided for use by RegisterContextFreeBSD derivatives.
+  bool WriteRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size,
+                        unsigned int regset);
+
+  /// Reads the value of the thread-specific pointer for a given thread ID.
+  bool ReadThreadPointer(lldb::tid_t tid, lldb::addr_t &value);
+
+  /// Returns current thread IDs in process
+  size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids);
+
+  /// Writes a ptrace_lwpinfo structure corresponding to the given thread ID
+  /// to the memory region pointed to by @p lwpinfo.
+  bool GetLwpInfo(lldb::tid_t tid, void *lwpinfo, int &error_no);
+
+  /// Suspends or unsuspends a thread prior to process resume or step.
+  bool ThreadSuspend(lldb::tid_t tid, bool suspend);
+
+  /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
+  /// corresponding to the given thread IDto the memory pointed to by @p
+  /// message.
+  bool GetEventMessage(lldb::tid_t tid, unsigned long *message);
+
+  /// Resumes the process.  If @p signo is anything but
+  /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process.
+  bool Resume(lldb::tid_t unused, uint32_t signo);
+
+  /// Single steps the process.  If @p signo is anything but
+  /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process.
+  bool SingleStep(lldb::tid_t unused, uint32_t signo);
+
+  /// Terminate the traced process.
+  bool Kill();
+
+  lldb_private::Error Detach(lldb::tid_t tid);
+
+  void StopMonitor();
 
-    /// Launches an inferior process ready for debugging.  Forms the
-    /// implementation of Process::DoLaunch.
-    ProcessMonitor(ProcessFreeBSD *process,
-                   lldb_private::Module *module,
-                   char const *argv[],
-                   char const *envp[],
-                   const lldb_private::FileSpec &stdin_file_spec,
-                   const lldb_private::FileSpec &stdout_file_spec,
-                   const lldb_private::FileSpec &stderr_file_spec,
-                   const lldb_private::FileSpec &working_dir,
-                   const lldb_private::ProcessLaunchInfo &launch_info,
-                   lldb_private::Error &error);
-
-    ProcessMonitor(ProcessFreeBSD *process,
-                   lldb::pid_t pid,
-                   lldb_private::Error &error);
-
-    ~ProcessMonitor();
-
-    /// Provides the process number of debugee.
-    lldb::pid_t
-    GetPID() const { return m_pid; }
-
-    /// Returns the process associated with this ProcessMonitor.
-    ProcessFreeBSD &
-    GetProcess() { return *m_process; }
-
-    /// Returns a file descriptor to the controlling terminal of the inferior
-    /// process.
-    ///
-    /// Reads from this file descriptor yield both the standard output and
-    /// standard error of this debugee.  Even if stderr and stdout were
-    /// redirected on launch it may still happen that data is available on this
-    /// descriptor (if the inferior process opens /dev/tty, for example). This descriptor is
-    /// closed after a call to StopMonitor().
-    ///
-    /// If this monitor was attached to an existing process this method returns
-    /// -1.
-    int
-    GetTerminalFD() const { return m_terminal_fd; }
-
-    /// Reads @p size bytes from address @vm_adder in the inferior process
-    /// address space.
-    ///
-    /// This method is provided to implement Process::DoReadMemory.
-    size_t
-    ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
-               lldb_private::Error &error);
-
-    /// Writes @p size bytes from address @p vm_adder in the inferior process
-    /// address space.
-    ///
-    /// This method is provided to implement Process::DoWriteMemory.
-    size_t
-    WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
-                lldb_private::Error &error);
-
-    /// Reads the contents from the register identified by the given (architecture
-    /// dependent) offset.
-    ///
-    /// This method is provided for use by RegisterContextFreeBSD derivatives.
-    bool
-    ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
-                      unsigned size, lldb_private::RegisterValue &value);
-
-    /// Writes the given value to the register identified by the given
-    /// (architecture dependent) offset.
-    ///
-    /// This method is provided for use by RegisterContextFreeBSD derivatives.
-    bool
-    WriteRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
-                       const lldb_private::RegisterValue &value);
-
-    /// Reads the contents from the debug register identified by the given
-    /// (architecture dependent) offset.
-    ///
-    /// This method is provided for use by RegisterContextFreeBSD derivatives.
-    bool
-    ReadDebugRegisterValue(lldb::tid_t tid, unsigned offset,
-                           const char *reg_name, unsigned size,
-                           lldb_private::RegisterValue &value);
-
-    /// Writes the given value to the debug register identified by the given
-    /// (architecture dependent) offset.
-    ///
-    /// This method is provided for use by RegisterContextFreeBSD derivatives.
-    bool
-    WriteDebugRegisterValue(lldb::tid_t tid, unsigned offset,
-                            const char *reg_name,
-                            const lldb_private::RegisterValue &value);
-    /// Reads all general purpose registers into the specified buffer.
-    bool
-    ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size);
-
-    /// Reads all floating point registers into the specified buffer.
-    bool
-    ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size);
-
-    /// Reads the specified register set into the specified buffer.
-    ///
-    /// This method is provided for use by RegisterContextFreeBSD derivatives.
-    bool
-    ReadRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset);
-
-    /// Writes all general purpose registers into the specified buffer.
-    bool
-    WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size);
-
-    /// Writes all floating point registers into the specified buffer.
-    bool
-    WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size);
-
-    /// Writes the specified register set into the specified buffer.
-    ///
-    /// This method is provided for use by RegisterContextFreeBSD derivatives.
-    bool
-    WriteRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset);
-
-    /// Reads the value of the thread-specific pointer for a given thread ID.
-    bool
-    ReadThreadPointer(lldb::tid_t tid, lldb::addr_t &value);
-
-    /// Returns current thread IDs in process
-    size_t
-    GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids);
-
-    /// Writes a ptrace_lwpinfo structure corresponding to the given thread ID
-    /// to the memory region pointed to by @p lwpinfo.
-    bool
-    GetLwpInfo(lldb::tid_t tid, void *lwpinfo, int &error_no);
-
-    /// Suspends or unsuspends a thread prior to process resume or step.
-    bool
-    ThreadSuspend(lldb::tid_t tid, bool suspend);
-
-    /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
-    /// corresponding to the given thread IDto the memory pointed to by @p
-    /// message.
-    bool
-    GetEventMessage(lldb::tid_t tid, unsigned long *message);
-
-    /// Resumes the process.  If @p signo is anything but
-    /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process.
-    bool
-    Resume(lldb::tid_t unused, uint32_t signo);
-
-    /// Single steps the process.  If @p signo is anything but
-    /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process.
-    bool
-    SingleStep(lldb::tid_t unused, uint32_t signo);
-
-    /// Terminate the traced process.
-    bool
-    Kill();
-
-    lldb_private::Error
-    Detach(lldb::tid_t tid);
-
-    void
-    StopMonitor();
-
-    // Waits for the initial stop message from a new thread.
-    bool
-    WaitForInitialTIDStop(lldb::tid_t tid);
+  // Waits for the initial stop message from a new thread.
+  bool WaitForInitialTIDStop(lldb::tid_t tid);
 
 private:
-    ProcessFreeBSD *m_process;
+  ProcessFreeBSD *m_process;
+
+  lldb_private::HostThread m_operation_thread;
+  lldb_private::HostThread m_monitor_thread;
+  lldb::pid_t m_pid;
+
+  int m_terminal_fd;
+
+  // current operation which must be executed on the privileged thread
+  Operation *m_operation;
+  std::mutex m_operation_mutex;
+
+  // semaphores notified when Operation is ready to be processed and when
+  // the operation is complete.
+  sem_t m_operation_pending;
+  sem_t m_operation_done;
+
+  struct OperationArgs {
+    OperationArgs(ProcessMonitor *monitor);
+
+    ~OperationArgs();
+
+    ProcessMonitor *m_monitor;   // The monitor performing the attach.
+    sem_t m_semaphore;           // Posted to once operation complete.
+    lldb_private::Error m_error; // Set if process operation failed.
+  };
+
+  /// @class LauchArgs
+  ///
+  /// @brief Simple structure to pass data to the thread responsible for
+  /// launching a child process.
+  struct LaunchArgs : OperationArgs {
+    LaunchArgs(ProcessMonitor *monitor, lldb_private::Module *module,
+               char const **argv, char const **envp,
+               const lldb_private::FileSpec &stdin_file_spec,
+               const lldb_private::FileSpec &stdout_file_spec,
+               const lldb_private::FileSpec &stderr_file_spec,
+               const lldb_private::FileSpec &working_dir);
+
+    ~LaunchArgs();
+
+    lldb_private::Module *m_module; // The executable image to launch.
+    char const **m_argv;            // Process arguments.
+    char const **m_envp;            // Process environment.
+    const lldb_private::FileSpec m_stdin_file_spec; // Redirect stdin or empty.
+    const lldb_private::FileSpec
+        m_stdout_file_spec; // Redirect stdout or empty.
+    const lldb_private::FileSpec
+        m_stderr_file_spec;                     // Redirect stderr or empty.
+    const lldb_private::FileSpec m_working_dir; // Working directory or empty.
+  };
+
+  void StartLaunchOpThread(LaunchArgs *args, lldb_private::Error &error);
+
+  static void *LaunchOpThread(void *arg);
+
+  static bool Launch(LaunchArgs *args);
+
+  struct AttachArgs : OperationArgs {
+    AttachArgs(ProcessMonitor *monitor, lldb::pid_t pid);
+
+    ~AttachArgs();
+
+    lldb::pid_t m_pid; // pid of the process to be attached.
+  };
+
+  void StartAttachOpThread(AttachArgs *args, lldb_private::Error &error);
+
+  static void *AttachOpThread(void *args);
+
+  static void Attach(AttachArgs *args);
+
+  static void ServeOperation(OperationArgs *args);
+
+  static bool DupDescriptor(const lldb_private::FileSpec &file_spec, int fd,
+                            int flags);
+
+  static bool MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid,
+                              bool exited, int signal, int status);
+
+  static ProcessMessage MonitorSIGTRAP(ProcessMonitor *monitor,
+                                       const siginfo_t *info, lldb::pid_t pid);
+
+  static ProcessMessage MonitorSignal(ProcessMonitor *monitor,
+                                      const siginfo_t *info, lldb::pid_t pid);
+
+  void DoOperation(Operation *op);
+
+  /// Stops the child monitor thread.
+  void StopMonitoringChildProcess();
 
-    lldb_private::HostThread m_operation_thread;
-    lldb_private::HostThread m_monitor_thread;
-    lldb::pid_t m_pid;
-
-    int m_terminal_fd;
-
-    // current operation which must be executed on the privileged thread
-    Operation *m_operation;
-    std::mutex m_operation_mutex;
-
-    // semaphores notified when Operation is ready to be processed and when
-    // the operation is complete.
-    sem_t m_operation_pending;
-    sem_t m_operation_done;
-
-    struct OperationArgs
-    {
-        OperationArgs(ProcessMonitor *monitor);
-
-        ~OperationArgs();
-
-        ProcessMonitor *m_monitor;      // The monitor performing the attach.
-        sem_t m_semaphore;              // Posted to once operation complete.
-        lldb_private::Error m_error;    // Set if process operation failed.
-    };
-
-    /// @class LauchArgs
-    ///
-    /// @brief Simple structure to pass data to the thread responsible for
-    /// launching a child process.
-    struct LaunchArgs : OperationArgs
-    {
-        LaunchArgs(ProcessMonitor *monitor,
-                   lldb_private::Module *module,
-                   char const **argv,
-                   char const **envp,
-                   const lldb_private::FileSpec &stdin_file_spec,
-                   const lldb_private::FileSpec &stdout_file_spec,
-                   const lldb_private::FileSpec &stderr_file_spec,
-                   const lldb_private::FileSpec &working_dir);
-
-        ~LaunchArgs();
-
-        lldb_private::Module *m_module;                  // The executable image to launch.
-        char const **m_argv;                             // Process arguments.
-        char const **m_envp;                             // Process environment.
-        const lldb_private::FileSpec m_stdin_file_spec;  // Redirect stdin or empty.
-        const lldb_private::FileSpec m_stdout_file_spec; // Redirect stdout or empty.
-        const lldb_private::FileSpec m_stderr_file_spec; // Redirect stderr or empty.
-        const lldb_private::FileSpec m_working_dir;      // Working directory or empty.
-    };
-
-    void
-    StartLaunchOpThread(LaunchArgs *args, lldb_private::Error &error);
-
-    static void *
-    LaunchOpThread(void *arg);
-
-    static bool
-    Launch(LaunchArgs *args);
-
-    struct AttachArgs : OperationArgs
-    {
-        AttachArgs(ProcessMonitor *monitor,
-                   lldb::pid_t pid);
-
-        ~AttachArgs();
-
-        lldb::pid_t m_pid;              // pid of the process to be attached.
-    };
-
-    void
-    StartAttachOpThread(AttachArgs *args, lldb_private::Error &error);
-
-    static void *
-    AttachOpThread(void *args);
-
-    static void
-    Attach(AttachArgs *args);
-
-    static void
-    ServeOperation(OperationArgs *args);
-
-    static bool
-    DupDescriptor(const lldb_private::FileSpec &file_spec, int fd, int flags);
-
-    static bool
-    MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid, bool exited, int signal, int status);
-
-    static ProcessMessage
-    MonitorSIGTRAP(ProcessMonitor *monitor,
-                   const siginfo_t *info, lldb::pid_t pid);
-
-    static ProcessMessage
-    MonitorSignal(ProcessMonitor *monitor, 
-                  const siginfo_t *info, lldb::pid_t pid);
-
-    void
-    DoOperation(Operation *op);
-
-    /// Stops the child monitor thread.
-    void
-    StopMonitoringChildProcess();
-
-    /// Stops the operation thread used to attach/launch a process.
-    void
-    StopOpThread();
+  /// Stops the operation thread used to attach/launch a process.
+  void StopOpThread();
 };
 
 #endif // #ifndef liblldb_ProcessMonitor_H_

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h Tue Sep  6 15:57:50 2016
@@ -13,67 +13,56 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
+#include "RegisterInfoInterface.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Target/RegisterContext.h"
-#include "RegisterInfoInterface.h"
 
 //------------------------------------------------------------------------------
 /// @class POSIXBreakpointProtocol
 ///
 /// @brief Extends RegisterClass with a few virtual operations useful on POSIX.
-class POSIXBreakpointProtocol
-{
+class POSIXBreakpointProtocol {
 public:
-    POSIXBreakpointProtocol()
-        { m_watchpoints_initialized = false; }
-    virtual ~POSIXBreakpointProtocol() {}
-
-    /// Updates the register state of the associated thread after hitting a
-    /// breakpoint (if that make sense for the architecture).  Default
-    /// implementation simply returns true for architectures which do not
-    /// require any update.
-    ///
-    /// @return
-    ///    True if the operation succeeded and false otherwise.
-    virtual bool UpdateAfterBreakpoint() = 0;
-
-    /// Determines the index in lldb's register file given a kernel byte offset.
-    virtual unsigned
-    GetRegisterIndexFromOffset(unsigned offset) = 0;
-
-    // Checks to see if a watchpoint specified by hw_index caused the inferior
-    // to stop.
-    virtual bool
-    IsWatchpointHit (uint32_t hw_index) = 0;
-
-    // Resets any watchpoints that have been hit.
-    virtual bool
-    ClearWatchpointHits () = 0;
-
-    // Returns the watchpoint address associated with a watchpoint hardware
-    // index.
-    virtual lldb::addr_t
-    GetWatchpointAddress (uint32_t hw_index) = 0;
-
-    virtual bool
-    IsWatchpointVacant (uint32_t hw_index) = 0;
-
-    virtual bool
-    SetHardwareWatchpointWithIndex (lldb::addr_t addr, size_t size,
-                                    bool read, bool write,
-                                    uint32_t hw_index) = 0;
-
-    // From lldb_private::RegisterContext
-    virtual uint32_t
-    NumSupportedHardwareWatchpoints () = 0;
-
-    // Force m_watchpoints_initialized to TRUE
-    void
-    ForceWatchpointsInitialized () {m_watchpoints_initialized = true;}
+  POSIXBreakpointProtocol() { m_watchpoints_initialized = false; }
+  virtual ~POSIXBreakpointProtocol() {}
+
+  /// Updates the register state of the associated thread after hitting a
+  /// breakpoint (if that make sense for the architecture).  Default
+  /// implementation simply returns true for architectures which do not
+  /// require any update.
+  ///
+  /// @return
+  ///    True if the operation succeeded and false otherwise.
+  virtual bool UpdateAfterBreakpoint() = 0;
+
+  /// Determines the index in lldb's register file given a kernel byte offset.
+  virtual unsigned GetRegisterIndexFromOffset(unsigned offset) = 0;
+
+  // Checks to see if a watchpoint specified by hw_index caused the inferior
+  // to stop.
+  virtual bool IsWatchpointHit(uint32_t hw_index) = 0;
+
+  // Resets any watchpoints that have been hit.
+  virtual bool ClearWatchpointHits() = 0;
+
+  // Returns the watchpoint address associated with a watchpoint hardware
+  // index.
+  virtual lldb::addr_t GetWatchpointAddress(uint32_t hw_index) = 0;
+
+  virtual bool IsWatchpointVacant(uint32_t hw_index) = 0;
+
+  virtual bool SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
+                                              bool read, bool write,
+                                              uint32_t hw_index) = 0;
+
+  // From lldb_private::RegisterContext
+  virtual uint32_t NumSupportedHardwareWatchpoints() = 0;
+
+  // Force m_watchpoints_initialized to TRUE
+  void ForceWatchpointsInitialized() { m_watchpoints_initialized = true; }
 
 protected:
-    bool m_watchpoints_initialized;
+  bool m_watchpoints_initialized;
 };
 
 #endif // #ifndef liblldb_RegisterContextPOSIX_H_
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp Tue Sep  6 15:57:50 2016
@@ -11,312 +11,250 @@
 #include "lldb/Core/RegisterValue.h"
 #include "lldb/Target/Thread.h"
 
-#include "RegisterContextPOSIX_arm.h"
 #include "ProcessFreeBSD.h"
-#include "RegisterContextPOSIXProcessMonitor_arm.h"
 #include "ProcessMonitor.h"
+#include "RegisterContextPOSIXProcessMonitor_arm.h"
+#include "RegisterContextPOSIX_arm.h"
 
 using namespace lldb_private;
 using namespace lldb;
 
 #define REG_CONTEXT_SIZE (GetGPRSize())
 
-RegisterContextPOSIXProcessMonitor_arm::RegisterContextPOSIXProcessMonitor_arm(Thread &thread,
-                                                                                     uint32_t concrete_frame_idx,
-                                                                                     lldb_private::RegisterInfoInterface *register_info)
-    : RegisterContextPOSIX_arm(thread, concrete_frame_idx, register_info)
-{
-}
-
-ProcessMonitor &
-RegisterContextPOSIXProcessMonitor_arm::GetMonitor()
-{
-    ProcessSP base = CalculateProcess();
-    ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get());
-    return process->GetMonitor();
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::ReadGPR()
-{
-     ProcessMonitor &monitor = GetMonitor();
-     return monitor.ReadGPR(m_thread.GetID(), &m_gpr_arm, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::ReadFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadFPR(m_thread.GetID(), &m_fpr, sizeof(m_fpr));
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::WriteGPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteGPR(m_thread.GetID(), &m_gpr_arm, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::WriteFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteFPR(m_thread.GetID(), &m_fpr, sizeof(m_fpr));
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::ReadRegister(const unsigned reg,
-                                                       RegisterValue &value)
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadRegisterValue(m_thread.GetID(),
-                                     GetRegisterOffset(reg),
-                                     GetRegisterName(reg),
-                                     GetRegisterSize(reg),
-                                     value);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::WriteRegister(const unsigned reg,
-                                                         const RegisterValue &value)
-{
-    unsigned reg_to_write = reg;
-    RegisterValue value_to_write = value;
-
-    // Check if this is a subregister of a full register.
-    const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
-    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
-    {
-        RegisterValue full_value;
-        uint32_t full_reg = reg_info->invalidate_regs[0];
-        const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
-
-        // Read the full register.
-        if (ReadRegister(full_reg_info, full_value))
-        {
-            Error error;
-            ByteOrder byte_order = GetByteOrder();
-            uint8_t dst[RegisterValue::kMaxRegisterByteSize];
-
-            // Get the bytes for the full register.
-            const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
-                                                                   dst,
-                                                                   sizeof(dst),
-                                                                   byte_order,
-                                                                   error);
-            if (error.Success() && dest_size)
-            {
-                uint8_t src[RegisterValue::kMaxRegisterByteSize];
-
-                // Get the bytes for the source data.
-                const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
-                if (error.Success() && src_size && (src_size < dest_size))
-                {
-                    // Copy the src bytes to the destination.
-                    memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
-                    // Set this full register as the value to write.
-                    value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
-                    value_to_write.SetType(full_reg_info);
-                    reg_to_write = full_reg;
-                }
-            }
+RegisterContextPOSIXProcessMonitor_arm::RegisterContextPOSIXProcessMonitor_arm(
+    Thread &thread, uint32_t concrete_frame_idx,
+    lldb_private::RegisterInfoInterface *register_info)
+    : RegisterContextPOSIX_arm(thread, concrete_frame_idx, register_info) {}
+
+ProcessMonitor &RegisterContextPOSIXProcessMonitor_arm::GetMonitor() {
+  ProcessSP base = CalculateProcess();
+  ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
+  return process->GetMonitor();
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm::ReadGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadGPR(m_thread.GetID(), &m_gpr_arm, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm::ReadFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadFPR(m_thread.GetID(), &m_fpr, sizeof(m_fpr));
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm::WriteGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteGPR(m_thread.GetID(), &m_gpr_arm, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm::WriteFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteFPR(m_thread.GetID(), &m_fpr, sizeof(m_fpr));
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm::ReadRegister(
+    const unsigned reg, RegisterValue &value) {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
+                                   GetRegisterName(reg), GetRegisterSize(reg),
+                                   value);
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm::WriteRegister(
+    const unsigned reg, const RegisterValue &value) {
+  unsigned reg_to_write = reg;
+  RegisterValue value_to_write = value;
+
+  // Check if this is a subregister of a full register.
+  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
+  if (reg_info->invalidate_regs &&
+      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
+    RegisterValue full_value;
+    uint32_t full_reg = reg_info->invalidate_regs[0];
+    const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
+
+    // Read the full register.
+    if (ReadRegister(full_reg_info, full_value)) {
+      Error error;
+      ByteOrder byte_order = GetByteOrder();
+      uint8_t dst[RegisterValue::kMaxRegisterByteSize];
+
+      // Get the bytes for the full register.
+      const uint32_t dest_size = full_value.GetAsMemoryData(
+          full_reg_info, dst, sizeof(dst), byte_order, error);
+      if (error.Success() && dest_size) {
+        uint8_t src[RegisterValue::kMaxRegisterByteSize];
+
+        // Get the bytes for the source data.
+        const uint32_t src_size = value.GetAsMemoryData(
+            reg_info, src, sizeof(src), byte_order, error);
+        if (error.Success() && src_size && (src_size < dest_size)) {
+          // Copy the src bytes to the destination.
+          memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
+          // Set this full register as the value to write.
+          value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
+          value_to_write.SetType(full_reg_info);
+          reg_to_write = full_reg;
         }
+      }
     }
+  }
 
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteRegisterValue(m_thread.GetID(),
-                                      GetRegisterOffset(reg_to_write),
-                                      GetRegisterName(reg_to_write),
-                                      value_to_write);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
-{
-    if (!reg_info)
-        return false;
-
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsFPR(reg))
-    {
-        if (!ReadFPR())
-            return false;
-    }
-    else
-    {
-        return ReadRegister(reg, value);
-    }
-
-    // Get pointer to m_fpr variable and set the data from it.
-    assert (reg_info->byte_offset < sizeof m_fpr);
-    uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset;
-    switch (reg_info->byte_size)
-    {
-        case 2:
-            value.SetUInt16(*(uint16_t *)src);
-            return true;
-        case 4:
-            value.SetUInt32(*(uint32_t *)src);
-            return true;
-        case 8:
-            value.SetUInt64(*(uint64_t *)src);
-            return true;
-        default:
-            assert(false && "Unhandled data size.");
-            return false;
-    }
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteRegisterValue(
+      m_thread.GetID(), GetRegisterOffset(reg_to_write),
+      GetRegisterName(reg_to_write), value_to_write);
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value)
-{
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsGPR(reg))
-    {
-        return WriteRegister(reg, value);
-    }
-    else if (IsFPR(reg))
-    {
-        return WriteFPR();
-    }
+bool RegisterContextPOSIXProcessMonitor_arm::ReadRegister(
+    const RegisterInfo *reg_info, RegisterValue &value) {
+  if (!reg_info)
+    return false;
+
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
+
+  if (IsFPR(reg)) {
+    if (!ReadFPR())
+      return false;
+  } else {
+    return ReadRegister(reg, value);
+  }
 
+  // Get pointer to m_fpr variable and set the data from it.
+  assert(reg_info->byte_offset < sizeof m_fpr);
+  uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset;
+  switch (reg_info->byte_size) {
+  case 2:
+    value.SetUInt16(*(uint16_t *)src);
+    return true;
+  case 4:
+    value.SetUInt32(*(uint32_t *)src);
+    return true;
+  case 8:
+    value.SetUInt64(*(uint64_t *)src);
+    return true;
+  default:
+    assert(false && "Unhandled data size.");
     return false;
+  }
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::ReadAllRegisterValues(DataBufferSP &data_sp)
-{
-    bool success = false;
-    data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
-    if (data_sp && ReadGPR () && ReadFPR ())
-    {
-        uint8_t *dst = data_sp->GetBytes();
-        success = dst != 0;
-
-        if (success)
-        {
-            ::memcpy (dst, &m_gpr_arm, GetGPRSize());
-            dst += GetGPRSize();
-            ::memcpy (dst, &m_fpr, sizeof(m_fpr));
-        }
-    }
-    return success;
+bool RegisterContextPOSIXProcessMonitor_arm::WriteRegister(
+    const RegisterInfo *reg_info, const RegisterValue &value) {
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
+
+  if (IsGPR(reg)) {
+    return WriteRegister(reg, value);
+  } else if (IsFPR(reg)) {
+    return WriteFPR();
+  }
+
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::WriteAllRegisterValues(const DataBufferSP &data_sp)
-{
-    bool success = false;
-    if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
-    {
-        uint8_t *src = data_sp->GetBytes();
-        if (src)
-        {
-            ::memcpy (&m_gpr_arm, src, GetGPRSize());
-
-            if (WriteGPR())
-            {
-                src += GetGPRSize();
-                ::memcpy (&m_fpr, src, sizeof(m_fpr));
+bool RegisterContextPOSIXProcessMonitor_arm::ReadAllRegisterValues(
+    DataBufferSP &data_sp) {
+  bool success = false;
+  data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
+  if (data_sp && ReadGPR() && ReadFPR()) {
+    uint8_t *dst = data_sp->GetBytes();
+    success = dst != 0;
 
-                success = WriteFPR();
-            }
-        }
+    if (success) {
+      ::memcpy(dst, &m_gpr_arm, GetGPRSize());
+      dst += GetGPRSize();
+      ::memcpy(dst, &m_fpr, sizeof(m_fpr));
     }
-    return success;
+  }
+  return success;
 }
 
-uint32_t
-RegisterContextPOSIXProcessMonitor_arm::SetHardwareWatchpoint(addr_t addr, size_t size,
-                                                                bool read, bool write)
-{
-    const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
-    uint32_t hw_index;
-
-    for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index)
-    {
-        if (IsWatchpointVacant(hw_index))
-            return SetHardwareWatchpointWithIndex(addr, size,
-                                                  read, write,
-                                                  hw_index);
+bool RegisterContextPOSIXProcessMonitor_arm::WriteAllRegisterValues(
+    const DataBufferSP &data_sp) {
+  bool success = false;
+  if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
+    uint8_t *src = data_sp->GetBytes();
+    if (src) {
+      ::memcpy(&m_gpr_arm, src, GetGPRSize());
+
+      if (WriteGPR()) {
+        src += GetGPRSize();
+        ::memcpy(&m_fpr, src, sizeof(m_fpr));
+
+        success = WriteFPR();
+      }
     }
+  }
+  return success;
+}
+
+uint32_t RegisterContextPOSIXProcessMonitor_arm::SetHardwareWatchpoint(
+    addr_t addr, size_t size, bool read, bool write) {
+  const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+  uint32_t hw_index;
 
-    return LLDB_INVALID_INDEX32;
+  for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
+    if (IsWatchpointVacant(hw_index))
+      return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
+  }
+
+  return LLDB_INVALID_INDEX32;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::ClearHardwareWatchpoint(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm::ClearHardwareWatchpoint(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::HardwareSingleStep(bool enable)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm::HardwareSingleStep(bool enable) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::UpdateAfterBreakpoint()
-{
-    lldb::addr_t pc;
+bool RegisterContextPOSIXProcessMonitor_arm::UpdateAfterBreakpoint() {
+  lldb::addr_t pc;
 
-    if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
-        return false;
+  if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
+    return false;
 
-    return true;
+  return true;
 }
 
-unsigned
-RegisterContextPOSIXProcessMonitor_arm::GetRegisterIndexFromOffset(unsigned offset)
-{
-    unsigned reg;
-    for (reg = 0; reg < k_num_registers_arm; reg++)
-    {
-        if (GetRegisterInfo()[reg].byte_offset == offset)
-            break;
-    }
-    assert(reg < k_num_registers_arm && "Invalid register offset.");
-    return reg;
+unsigned RegisterContextPOSIXProcessMonitor_arm::GetRegisterIndexFromOffset(
+    unsigned offset) {
+  unsigned reg;
+  for (reg = 0; reg < k_num_registers_arm; reg++) {
+    if (GetRegisterInfo()[reg].byte_offset == offset)
+      break;
+  }
+  assert(reg < k_num_registers_arm && "Invalid register offset.");
+  return reg;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::IsWatchpointHit(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm::IsWatchpointHit(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::ClearWatchpointHits()
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm::ClearWatchpointHits() {
+  return false;
 }
 
-addr_t
-RegisterContextPOSIXProcessMonitor_arm::GetWatchpointAddress(uint32_t hw_index)
-{
-    return LLDB_INVALID_ADDRESS;
+addr_t RegisterContextPOSIXProcessMonitor_arm::GetWatchpointAddress(
+    uint32_t hw_index) {
+  return LLDB_INVALID_ADDRESS;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::IsWatchpointVacant(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm::IsWatchpointVacant(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm::SetHardwareWatchpointWithIndex(addr_t addr, size_t size,
-                                                                         bool read, bool write,
-                                                                         uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm::SetHardwareWatchpointWithIndex(
+    addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
+  return false;
 }
 
 uint32_t
-RegisterContextPOSIXProcessMonitor_arm::NumSupportedHardwareWatchpoints()
-{
-    return 0;
+RegisterContextPOSIXProcessMonitor_arm::NumSupportedHardwareWatchpoints() {
+  return 0;
 }
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.h Tue Sep  6 15:57:50 2016
@@ -10,87 +10,68 @@
 #ifndef liblldb_RegisterContextPOSIXProcessMonitor_arm_H_
 #define liblldb_RegisterContextPOSIXProcessMonitor_arm_H_
 
-#include "RegisterContextPOSIX.h"
 #include "Plugins/Process/Utility/RegisterContextPOSIX_arm.h"
+#include "RegisterContextPOSIX.h"
 
-class RegisterContextPOSIXProcessMonitor_arm:
-    public RegisterContextPOSIX_arm,
-    public POSIXBreakpointProtocol
-{
+class RegisterContextPOSIXProcessMonitor_arm : public RegisterContextPOSIX_arm,
+                                               public POSIXBreakpointProtocol {
 public:
-    RegisterContextPOSIXProcessMonitor_arm(lldb_private::Thread &thread,
-                                             uint32_t concrete_frame_idx,
-                                             lldb_private::RegisterInfoInterface *register_info);
+  RegisterContextPOSIXProcessMonitor_arm(
+      lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+      lldb_private::RegisterInfoInterface *register_info);
 
 protected:
-    bool
-    ReadGPR();
+  bool ReadGPR();
 
-    bool
-    ReadFPR();
+  bool ReadFPR();
 
-    bool
-    WriteGPR();
+  bool WriteGPR();
 
-    bool
-    WriteFPR();
+  bool WriteFPR();
 
-    // lldb_private::RegisterContext
-    bool
-    ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
+  // lldb_private::RegisterContext
+  bool ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const unsigned reg, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const unsigned reg,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
+  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
+                    lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
+  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
 
-    bool
-    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
+  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
 
-    uint32_t
-    SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write);
+  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
+                                 bool write);
 
-    bool
-    ClearHardwareWatchpoint(uint32_t hw_index);
+  bool ClearHardwareWatchpoint(uint32_t hw_index);
 
-    bool
-    HardwareSingleStep(bool enable);
+  bool HardwareSingleStep(bool enable);
 
-    // POSIXBreakpointProtocol
-    bool
-    UpdateAfterBreakpoint();
+  // POSIXBreakpointProtocol
+  bool UpdateAfterBreakpoint();
 
-    unsigned
-    GetRegisterIndexFromOffset(unsigned offset);
+  unsigned GetRegisterIndexFromOffset(unsigned offset);
 
-    bool
-    IsWatchpointHit(uint32_t hw_index);
+  bool IsWatchpointHit(uint32_t hw_index);
 
-    bool
-    ClearWatchpointHits();
+  bool ClearWatchpointHits();
 
-    lldb::addr_t
-    GetWatchpointAddress(uint32_t hw_index);
+  lldb::addr_t GetWatchpointAddress(uint32_t hw_index);
 
-    bool
-    IsWatchpointVacant(uint32_t hw_index);
+  bool IsWatchpointVacant(uint32_t hw_index);
 
-    bool
-    SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read, bool write, uint32_t hw_index);
+  bool SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read,
+                                      bool write, uint32_t hw_index);
 
-    uint32_t
-    NumSupportedHardwareWatchpoints();
+  uint32_t NumSupportedHardwareWatchpoints();
 
 private:
-    ProcessMonitor &
-    GetMonitor();
+  ProcessMonitor &GetMonitor();
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp Tue Sep  6 15:57:50 2016
@@ -21,298 +21,245 @@
 using namespace lldb;
 using namespace lldb_private;
 
-RegisterContextPOSIXProcessMonitor_arm64::RegisterContextPOSIXProcessMonitor_arm64(lldb_private::Thread &thread,
-                                                                                   uint32_t concrete_frame_idx,
-                                                                                   lldb_private::RegisterInfoInterface *register_info)
-    : RegisterContextPOSIX_arm64(thread, concrete_frame_idx, register_info)
-{
-}
-
-ProcessMonitor &
-RegisterContextPOSIXProcessMonitor_arm64::GetMonitor()
-{
-    lldb::ProcessSP base = CalculateProcess();
-    ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get());
-    return process->GetMonitor();
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ReadGPR()
-{
-     ProcessMonitor &monitor = GetMonitor();
-     return monitor.ReadGPR(m_thread.GetID(), &m_gpr_arm64, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ReadFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadFPR(m_thread.GetID(), &m_fpr, sizeof m_fpr);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::WriteGPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteGPR(m_thread.GetID(), &m_gpr_arm64, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::WriteFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteFPR(m_thread.GetID(), &m_fpr, sizeof m_fpr);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ReadRegister(const unsigned reg,
-                                                       lldb_private::RegisterValue &value)
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadRegisterValue(m_thread.GetID(),
-                                     GetRegisterOffset(reg),
-                                     GetRegisterName(reg),
-                                     GetRegisterSize(reg),
-                                     value);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(const unsigned reg,
-                                                         const lldb_private::RegisterValue &value)
-{
-    unsigned reg_to_write = reg;
-    lldb_private::RegisterValue value_to_write = value;
-
-    // Check if this is a subregister of a full register.
-    const lldb_private::RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
-    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
-    {
-        lldb_private::RegisterValue full_value;
-        uint32_t full_reg = reg_info->invalidate_regs[0];
-        const lldb_private::RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
-
-        // Read the full register.
-        if (ReadRegister(full_reg_info, full_value))
-        {
-            lldb_private::Error error;
-            lldb::ByteOrder byte_order = GetByteOrder();
-            uint8_t dst[lldb_private::RegisterValue::kMaxRegisterByteSize];
-
-            // Get the bytes for the full register.
-            const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
-                                                                   dst,
-                                                                   sizeof(dst),
-                                                                   byte_order,
-                                                                   error);
-            if (error.Success() && dest_size)
-            {
-                uint8_t src[lldb_private::RegisterValue::kMaxRegisterByteSize];
-
-                // Get the bytes for the source data.
-                const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
-                if (error.Success() && src_size && (src_size < dest_size))
-                {
-                    // Copy the src bytes to the destination.
-                    ::memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
-                    // Set this full register as the value to write.
-                    value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
-                    value_to_write.SetType(full_reg_info);
-                    reg_to_write = full_reg;
-                }
-            }
+RegisterContextPOSIXProcessMonitor_arm64::
+    RegisterContextPOSIXProcessMonitor_arm64(
+        lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+        lldb_private::RegisterInfoInterface *register_info)
+    : RegisterContextPOSIX_arm64(thread, concrete_frame_idx, register_info) {}
+
+ProcessMonitor &RegisterContextPOSIXProcessMonitor_arm64::GetMonitor() {
+  lldb::ProcessSP base = CalculateProcess();
+  ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
+  return process->GetMonitor();
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::ReadGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadGPR(m_thread.GetID(), &m_gpr_arm64, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::ReadFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadFPR(m_thread.GetID(), &m_fpr, sizeof m_fpr);
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::WriteGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteGPR(m_thread.GetID(), &m_gpr_arm64, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::WriteFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteFPR(m_thread.GetID(), &m_fpr, sizeof m_fpr);
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::ReadRegister(
+    const unsigned reg, lldb_private::RegisterValue &value) {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
+                                   GetRegisterName(reg), GetRegisterSize(reg),
+                                   value);
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(
+    const unsigned reg, const lldb_private::RegisterValue &value) {
+  unsigned reg_to_write = reg;
+  lldb_private::RegisterValue value_to_write = value;
+
+  // Check if this is a subregister of a full register.
+  const lldb_private::RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
+  if (reg_info->invalidate_regs &&
+      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
+    lldb_private::RegisterValue full_value;
+    uint32_t full_reg = reg_info->invalidate_regs[0];
+    const lldb_private::RegisterInfo *full_reg_info =
+        GetRegisterInfoAtIndex(full_reg);
+
+    // Read the full register.
+    if (ReadRegister(full_reg_info, full_value)) {
+      lldb_private::Error error;
+      lldb::ByteOrder byte_order = GetByteOrder();
+      uint8_t dst[lldb_private::RegisterValue::kMaxRegisterByteSize];
+
+      // Get the bytes for the full register.
+      const uint32_t dest_size = full_value.GetAsMemoryData(
+          full_reg_info, dst, sizeof(dst), byte_order, error);
+      if (error.Success() && dest_size) {
+        uint8_t src[lldb_private::RegisterValue::kMaxRegisterByteSize];
+
+        // Get the bytes for the source data.
+        const uint32_t src_size = value.GetAsMemoryData(
+            reg_info, src, sizeof(src), byte_order, error);
+        if (error.Success() && src_size && (src_size < dest_size)) {
+          // Copy the src bytes to the destination.
+          ::memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
+          // Set this full register as the value to write.
+          value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
+          value_to_write.SetType(full_reg_info);
+          reg_to_write = full_reg;
         }
+      }
     }
+  }
 
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteRegisterValue(m_thread.GetID(),
-                                      GetRegisterOffset(reg_to_write),
-                                      GetRegisterName(reg_to_write),
-                                      value_to_write);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value)
-{
-    if (!reg_info)
-        return false;
-
-    const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
-
-    if (IsFPR(reg))
-    {
-        if (!ReadFPR())
-            return false;
-    }
-    else
-    {
-        uint32_t full_reg = reg;
-        bool is_subreg = reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
-
-        if (is_subreg)
-        {
-            // Read the full aligned 64-bit register.
-            full_reg = reg_info->invalidate_regs[0];
-        }
-        return ReadRegister(full_reg, value);
-    }
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteRegisterValue(
+      m_thread.GetID(), GetRegisterOffset(reg_to_write),
+      GetRegisterName(reg_to_write), value_to_write);
+}
+
+bool RegisterContextPOSIXProcessMonitor_arm64::ReadRegister(
+    const lldb_private::RegisterInfo *reg_info,
+    lldb_private::RegisterValue &value) {
+  if (!reg_info)
+    return false;
+
+  const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
+
+  if (IsFPR(reg)) {
+    if (!ReadFPR())
+      return false;
+  } else {
+    uint32_t full_reg = reg;
+    bool is_subreg = reg_info->invalidate_regs &&
+                     (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
 
-    // Get pointer to m_fpr variable and set the data from it.
-    assert (reg_info->byte_offset < sizeof m_fpr);
-    uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset;
-    switch (reg_info->byte_size)
-    {
-        case 2:
-            value.SetUInt16(*(uint16_t *)src);
-            return true;
-        case 4:
-            value.SetUInt32(*(uint32_t *)src);
-            return true;
-        case 8:
-            value.SetUInt64(*(uint64_t *)src);
-            return true;
-        default:
-            assert(false && "Unhandled data size.");
-            return false;
+    if (is_subreg) {
+      // Read the full aligned 64-bit register.
+      full_reg = reg_info->invalidate_regs[0];
     }
+    return ReadRegister(full_reg, value);
+  }
+
+  // Get pointer to m_fpr variable and set the data from it.
+  assert(reg_info->byte_offset < sizeof m_fpr);
+  uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset;
+  switch (reg_info->byte_size) {
+  case 2:
+    value.SetUInt16(*(uint16_t *)src);
+    return true;
+  case 4:
+    value.SetUInt32(*(uint32_t *)src);
+    return true;
+  case 8:
+    value.SetUInt64(*(uint64_t *)src);
+    return true;
+  default:
+    assert(false && "Unhandled data size.");
+    return false;
+  }
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value)
-{
-    const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
+bool RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(
+    const lldb_private::RegisterInfo *reg_info,
+    const lldb_private::RegisterValue &value) {
+  const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
 
-    if (IsGPR(reg))
-        return WriteRegister(reg, value);
+  if (IsGPR(reg))
+    return WriteRegister(reg, value);
 
-    return false;
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ReadAllRegisterValues(lldb::DataBufferSP &data_sp)
-{
-    bool success = false;
-    data_sp.reset (new lldb_private::DataBufferHeap (REG_CONTEXT_SIZE, 0));
-    if (data_sp && ReadGPR () && ReadFPR ())
-    {
-        uint8_t *dst = data_sp->GetBytes();
-        success = dst != 0;
-
-        if (success)
-        {
-            ::memcpy (dst, &m_gpr_arm64, GetGPRSize());
-            dst += GetGPRSize();
-            ::memcpy (dst, &m_fpr, sizeof m_fpr);
-        }
+bool RegisterContextPOSIXProcessMonitor_arm64::ReadAllRegisterValues(
+    lldb::DataBufferSP &data_sp) {
+  bool success = false;
+  data_sp.reset(new lldb_private::DataBufferHeap(REG_CONTEXT_SIZE, 0));
+  if (data_sp && ReadGPR() && ReadFPR()) {
+    uint8_t *dst = data_sp->GetBytes();
+    success = dst != 0;
+
+    if (success) {
+      ::memcpy(dst, &m_gpr_arm64, GetGPRSize());
+      dst += GetGPRSize();
+      ::memcpy(dst, &m_fpr, sizeof m_fpr);
     }
-    return success;
+  }
+  return success;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)
-{
-    bool success = false;
-    if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
-    {
-        uint8_t *src = data_sp->GetBytes();
-        if (src)
-        {
-            ::memcpy (&m_gpr_arm64, src, GetGPRSize());
-            if (WriteGPR()) {
-                src += GetGPRSize();
-                ::memcpy (&m_fpr, src, sizeof m_fpr);
-                success = WriteFPR();
-            }
-        }
+bool RegisterContextPOSIXProcessMonitor_arm64::WriteAllRegisterValues(
+    const lldb::DataBufferSP &data_sp) {
+  bool success = false;
+  if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
+    uint8_t *src = data_sp->GetBytes();
+    if (src) {
+      ::memcpy(&m_gpr_arm64, src, GetGPRSize());
+      if (WriteGPR()) {
+        src += GetGPRSize();
+        ::memcpy(&m_fpr, src, sizeof m_fpr);
+        success = WriteFPR();
+      }
     }
-    return success;
+  }
+  return success;
 }
 
-uint32_t
-RegisterContextPOSIXProcessMonitor_arm64::SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
-                                                                bool read, bool write)
-{
-    const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
-    uint32_t hw_index;
-
-    for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index)
-    {
-        if (IsWatchpointVacant(hw_index))
-            return SetHardwareWatchpointWithIndex(addr, size,
-                                                  read, write,
-                                                  hw_index);
-    }
+uint32_t RegisterContextPOSIXProcessMonitor_arm64::SetHardwareWatchpoint(
+    lldb::addr_t addr, size_t size, bool read, bool write) {
+  const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+  uint32_t hw_index;
 
-    return LLDB_INVALID_INDEX32;
+  for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
+    if (IsWatchpointVacant(hw_index))
+      return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
+  }
+
+  return LLDB_INVALID_INDEX32;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ClearHardwareWatchpoint(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::ClearHardwareWatchpoint(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::HardwareSingleStep(bool enable)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::HardwareSingleStep(bool enable) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::UpdateAfterBreakpoint()
-{
-    if (GetPC() == LLDB_INVALID_ADDRESS)
-        return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::UpdateAfterBreakpoint() {
+  if (GetPC() == LLDB_INVALID_ADDRESS)
+    return false;
 
-    return true;
+  return true;
 }
 
-unsigned
-RegisterContextPOSIXProcessMonitor_arm64::GetRegisterIndexFromOffset(unsigned offset)
-{
-    unsigned reg;
-    for (reg = 0; reg < k_num_registers_arm64; reg++)
-    {
-        if (GetRegisterInfo()[reg].byte_offset == offset)
-            break;
-    }
-    assert(reg < k_num_registers_arm64 && "Invalid register offset.");
-    return reg;
+unsigned RegisterContextPOSIXProcessMonitor_arm64::GetRegisterIndexFromOffset(
+    unsigned offset) {
+  unsigned reg;
+  for (reg = 0; reg < k_num_registers_arm64; reg++) {
+    if (GetRegisterInfo()[reg].byte_offset == offset)
+      break;
+  }
+  assert(reg < k_num_registers_arm64 && "Invalid register offset.");
+  return reg;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::IsWatchpointHit(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::IsWatchpointHit(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::ClearWatchpointHits()
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::ClearWatchpointHits() {
+  return false;
 }
 
-lldb::addr_t
-RegisterContextPOSIXProcessMonitor_arm64::GetWatchpointAddress(uint32_t hw_index)
-{
-    return LLDB_INVALID_ADDRESS;
+lldb::addr_t RegisterContextPOSIXProcessMonitor_arm64::GetWatchpointAddress(
+    uint32_t hw_index) {
+  return LLDB_INVALID_ADDRESS;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::IsWatchpointVacant(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::IsWatchpointVacant(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_arm64::SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
-                                                                         bool read, bool write,
-                                                                         uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_arm64::SetHardwareWatchpointWithIndex(
+    lldb::addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
+  return false;
 }
 
 uint32_t
-RegisterContextPOSIXProcessMonitor_arm64::NumSupportedHardwareWatchpoints()
-{
-    return 0;
+RegisterContextPOSIXProcessMonitor_arm64::NumSupportedHardwareWatchpoints() {
+  return 0;
 }

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.h Tue Sep  6 15:57:50 2016
@@ -10,87 +10,69 @@
 #ifndef liblldb_RegisterContextPOSIXProcessMonitor_arm64_H_
 #define liblldb_RegisterContextPOSIXProcessMonitor_arm64_H_
 
-#include "RegisterContextPOSIX.h"
 #include "Plugins/Process/Utility/RegisterContextPOSIX_arm64.h"
+#include "RegisterContextPOSIX.h"
 
-class RegisterContextPOSIXProcessMonitor_arm64:
-    public RegisterContextPOSIX_arm64,
-    public POSIXBreakpointProtocol
-{
+class RegisterContextPOSIXProcessMonitor_arm64
+    : public RegisterContextPOSIX_arm64,
+      public POSIXBreakpointProtocol {
 public:
-    RegisterContextPOSIXProcessMonitor_arm64(lldb_private::Thread &thread,
-                                             uint32_t concrete_frame_idx,
-                                             lldb_private::RegisterInfoInterface *register_info);
+  RegisterContextPOSIXProcessMonitor_arm64(
+      lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+      lldb_private::RegisterInfoInterface *register_info);
 
 protected:
-    bool
-    ReadGPR();
+  bool ReadGPR();
 
-    bool
-    ReadFPR();
+  bool ReadFPR();
 
-    bool
-    WriteGPR();
+  bool WriteGPR();
 
-    bool
-    WriteFPR();
+  bool WriteFPR();
 
-    // lldb_private::RegisterContext
-    bool
-    ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
+  // lldb_private::RegisterContext
+  bool ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const unsigned reg, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const unsigned reg,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
+  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
+                    lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
+  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
 
-    bool
-    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
+  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
 
-    uint32_t
-    SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write);
+  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
+                                 bool write);
 
-    bool
-    ClearHardwareWatchpoint(uint32_t hw_index);
+  bool ClearHardwareWatchpoint(uint32_t hw_index);
 
-    bool
-    HardwareSingleStep(bool enable);
+  bool HardwareSingleStep(bool enable);
 
-    // POSIXBreakpointProtocol
-    bool
-    UpdateAfterBreakpoint();
+  // POSIXBreakpointProtocol
+  bool UpdateAfterBreakpoint();
 
-    unsigned
-    GetRegisterIndexFromOffset(unsigned offset);
+  unsigned GetRegisterIndexFromOffset(unsigned offset);
 
-    bool
-    IsWatchpointHit(uint32_t hw_index);
+  bool IsWatchpointHit(uint32_t hw_index);
 
-    bool
-    ClearWatchpointHits();
+  bool ClearWatchpointHits();
 
-    lldb::addr_t
-    GetWatchpointAddress(uint32_t hw_index);
+  lldb::addr_t GetWatchpointAddress(uint32_t hw_index);
 
-    bool
-    IsWatchpointVacant(uint32_t hw_index);
+  bool IsWatchpointVacant(uint32_t hw_index);
 
-    bool
-    SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read, bool write, uint32_t hw_index);
+  bool SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read,
+                                      bool write, uint32_t hw_index);
 
-    uint32_t
-    NumSupportedHardwareWatchpoints();
+  uint32_t NumSupportedHardwareWatchpoints();
 
 private:
-    ProcessMonitor &
-    GetMonitor();
+  ProcessMonitor &GetMonitor();
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp Tue Sep  6 15:57:50 2016
@@ -21,298 +21,243 @@ using namespace lldb;
 
 #define REG_CONTEXT_SIZE (GetGPRSize())
 
-RegisterContextPOSIXProcessMonitor_mips64::RegisterContextPOSIXProcessMonitor_mips64(Thread &thread,
-                                                                                     uint32_t concrete_frame_idx,
-                                                                                     lldb_private::RegisterInfoInterface *register_info)
-    : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info)
-{
-}
-
-ProcessMonitor &
-RegisterContextPOSIXProcessMonitor_mips64::GetMonitor()
-{
-    ProcessSP base = CalculateProcess();
-    ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get());
-    return process->GetMonitor();
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ReadGPR()
-{
-     ProcessMonitor &monitor = GetMonitor();
-     return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ReadFPR()
-{
-    // XXX not yet implemented
-    return false;
-}
+RegisterContextPOSIXProcessMonitor_mips64::
+    RegisterContextPOSIXProcessMonitor_mips64(
+        Thread &thread, uint32_t concrete_frame_idx,
+        lldb_private::RegisterInfoInterface *register_info)
+    : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info) {}
+
+ProcessMonitor &RegisterContextPOSIXProcessMonitor_mips64::GetMonitor() {
+  ProcessSP base = CalculateProcess();
+  ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
+  return process->GetMonitor();
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::ReadGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::ReadFPR() {
+  // XXX not yet implemented
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::WriteGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::WriteFPR() {
+  // XXX not yet implemented
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
+    const unsigned reg, RegisterValue &value) {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
+                                   GetRegisterName(reg), GetRegisterSize(reg),
+                                   value);
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
+    const unsigned reg, const RegisterValue &value) {
+  unsigned reg_to_write = reg;
+  RegisterValue value_to_write = value;
+
+  // Check if this is a subregister of a full register.
+  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
+  if (reg_info->invalidate_regs &&
+      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
+    RegisterValue full_value;
+    uint32_t full_reg = reg_info->invalidate_regs[0];
+    const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
+
+    // Read the full register.
+    if (ReadRegister(full_reg_info, full_value)) {
+      Error error;
+      ByteOrder byte_order = GetByteOrder();
+      uint8_t dst[RegisterValue::kMaxRegisterByteSize];
+
+      // Get the bytes for the full register.
+      const uint32_t dest_size = full_value.GetAsMemoryData(
+          full_reg_info, dst, sizeof(dst), byte_order, error);
+      if (error.Success() && dest_size) {
+        uint8_t src[RegisterValue::kMaxRegisterByteSize];
+
+        // Get the bytes for the source data.
+        const uint32_t src_size = value.GetAsMemoryData(
+            reg_info, src, sizeof(src), byte_order, error);
+        if (error.Success() && src_size && (src_size < dest_size)) {
+          // Copy the src bytes to the destination.
+          memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
+          // Set this full register as the value to write.
+          value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
+          value_to_write.SetType(full_reg_info);
+          reg_to_write = full_reg;
+        }
+      }
+    }
+  }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::WriteGPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteRegisterValue(
+      m_thread.GetID(), GetRegisterOffset(reg_to_write),
+      GetRegisterName(reg_to_write), value_to_write);
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::WriteFPR()
-{
-    // XXX not yet implemented
+bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
+    const RegisterInfo *reg_info, RegisterValue &value) {
+  if (!reg_info)
     return false;
-}
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(const unsigned reg,
-                                                        RegisterValue &value)
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadRegisterValue(m_thread.GetID(),
-                                     GetRegisterOffset(reg),
-                                     GetRegisterName(reg),
-                                     GetRegisterSize(reg),
-                                     value);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(const unsigned reg,
-                                                         const RegisterValue &value)
-{
-    unsigned reg_to_write = reg;
-    RegisterValue value_to_write = value;
-
-    // Check if this is a subregister of a full register.
-    const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
-    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
-    {
-        RegisterValue full_value;
-        uint32_t full_reg = reg_info->invalidate_regs[0];
-        const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
-
-        // Read the full register.
-        if (ReadRegister(full_reg_info, full_value))
-        {
-            Error error;
-            ByteOrder byte_order = GetByteOrder();
-            uint8_t dst[RegisterValue::kMaxRegisterByteSize];
-
-            // Get the bytes for the full register.
-            const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info, 
-                                                                   dst, 
-                                                                   sizeof(dst), 
-                                                                   byte_order, 
-                                                                   error);
-            if (error.Success() && dest_size)
-            {
-                uint8_t src[RegisterValue::kMaxRegisterByteSize];
-
-                // Get the bytes for the source data.
-                const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
-                if (error.Success() && src_size && (src_size < dest_size))
-                {
-                    // Copy the src bytes to the destination.
-                    memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
-                    // Set this full register as the value to write.
-                    value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
-                    value_to_write.SetType(full_reg_info);
-                    reg_to_write = full_reg;
-                }
-            }
-        }
-    }
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
 
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteRegisterValue(m_thread.GetID(),
-                                      GetRegisterOffset(reg_to_write),
-                                      GetRegisterName(reg_to_write),
-                                      value_to_write);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
-{
-    if (!reg_info)
-        return false;
-
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsFPR(reg))
-    {
-        if (!ReadFPR())
-            return false;
+  if (IsFPR(reg)) {
+    if (!ReadFPR())
+      return false;
+  } else {
+    uint32_t full_reg = reg;
+    bool is_subreg = reg_info->invalidate_regs &&
+                     (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
+
+    if (is_subreg) {
+      // Read the full aligned 64-bit register.
+      full_reg = reg_info->invalidate_regs[0];
     }
-    else
-    {
-        uint32_t full_reg = reg;
-        bool is_subreg = reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
-
-        if (is_subreg)
-        {
-            // Read the full aligned 64-bit register.
-            full_reg = reg_info->invalidate_regs[0];
-        }
 
-        bool success = ReadRegister(full_reg, value);
+    bool success = ReadRegister(full_reg, value);
 
-        if (success)
-        {
-            // If our read was not aligned (for ah,bh,ch,dh), shift our returned value one byte to the right.
-            if (is_subreg && (reg_info->byte_offset & 0x1))
-                value.SetUInt64(value.GetAsUInt64() >> 8);
-
-            // If our return byte size was greater than the return value reg size, then
-            // use the type specified by reg_info rather than the uint64_t default
-            if (value.GetByteSize() > reg_info->byte_size)
-                value.SetType(reg_info);
-        }
-        return success; 
+    if (success) {
+      // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
+      // one byte to the right.
+      if (is_subreg && (reg_info->byte_offset & 0x1))
+        value.SetUInt64(value.GetAsUInt64() >> 8);
+
+      // If our return byte size was greater than the return value reg size,
+      // then
+      // use the type specified by reg_info rather than the uint64_t default
+      if (value.GetByteSize() > reg_info->byte_size)
+        value.SetType(reg_info);
     }
+    return success;
+  }
 
-    return false;
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value)
-{
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
+bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
+    const RegisterInfo *reg_info, const RegisterValue &value) {
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
 
-    if (IsGPR(reg))
-        return WriteRegister(reg, value);
+  if (IsGPR(reg))
+    return WriteRegister(reg, value);
 
-    return false;
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(DataBufferSP &data_sp)
-{
-    bool success = false;
-    data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
-    if (data_sp && ReadGPR () && ReadFPR ())
-    {
-        uint8_t *dst = data_sp->GetBytes();
-        success = dst != 0;
-
-        if (success)
-        {
-            ::memcpy (dst, &m_gpr_mips64, GetGPRSize());
-        }
+bool RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(
+    DataBufferSP &data_sp) {
+  bool success = false;
+  data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
+  if (data_sp && ReadGPR() && ReadFPR()) {
+    uint8_t *dst = data_sp->GetBytes();
+    success = dst != 0;
+
+    if (success) {
+      ::memcpy(dst, &m_gpr_mips64, GetGPRSize());
     }
-    return success;
+  }
+  return success;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::WriteAllRegisterValues(const DataBufferSP &data_sp)
-{
-    bool success = false;
-    if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
-    {
-        uint8_t *src = data_sp->GetBytes();
-        if (src)
-        {
-            ::memcpy (&m_gpr_mips64, src, GetGPRSize());
-
-            if (WriteGPR())
-            {
-                src += GetGPRSize();
-            }
-        }
+bool RegisterContextPOSIXProcessMonitor_mips64::WriteAllRegisterValues(
+    const DataBufferSP &data_sp) {
+  bool success = false;
+  if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
+    uint8_t *src = data_sp->GetBytes();
+    if (src) {
+      ::memcpy(&m_gpr_mips64, src, GetGPRSize());
+
+      if (WriteGPR()) {
+        src += GetGPRSize();
+      }
     }
-    return success;
+  }
+  return success;
 }
 
-uint32_t
-RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpoint(addr_t addr, size_t size,
-                                              bool read, bool write)
-{
-    const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
-    uint32_t hw_index;
-
-    for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index)
-    {
-        if (IsWatchpointVacant(hw_index))
-            return SetHardwareWatchpointWithIndex(addr, size,
-                                                  read, write,
-                                                  hw_index);
-    }
+uint32_t RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpoint(
+    addr_t addr, size_t size, bool read, bool write) {
+  const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+  uint32_t hw_index;
 
-    return LLDB_INVALID_INDEX32;
+  for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
+    if (IsWatchpointVacant(hw_index))
+      return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
+  }
+
+  return LLDB_INVALID_INDEX32;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ClearHardwareWatchpoint(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_mips64::ClearHardwareWatchpoint(
+    uint32_t hw_index) {
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_mips64::HardwareSingleStep(
+    bool enable) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::HardwareSingleStep(bool enable)
-{
+bool RegisterContextPOSIXProcessMonitor_mips64::UpdateAfterBreakpoint() {
+  // PC points one byte past the int3 responsible for the breakpoint.
+  lldb::addr_t pc;
+
+  if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
     return false;
+
+  SetPC(pc - 1);
+  return true;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::UpdateAfterBreakpoint()
-{
-    // PC points one byte past the int3 responsible for the breakpoint.
-    lldb::addr_t pc;
-
-    if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
-        return false;
-
-    SetPC(pc - 1);
-    return true;
-}
-
-unsigned
-RegisterContextPOSIXProcessMonitor_mips64::GetRegisterIndexFromOffset(unsigned offset)
-{
-    unsigned reg;
-    for (reg = 0; reg < k_num_registers_mips64; reg++)
-    {
-        if (GetRegisterInfo()[reg].byte_offset == offset)
-            break;
-    }
-    assert(reg < k_num_registers_mips64 && "Invalid register offset.");
-    return reg;
+unsigned RegisterContextPOSIXProcessMonitor_mips64::GetRegisterIndexFromOffset(
+    unsigned offset) {
+  unsigned reg;
+  for (reg = 0; reg < k_num_registers_mips64; reg++) {
+    if (GetRegisterInfo()[reg].byte_offset == offset)
+      break;
+  }
+  assert(reg < k_num_registers_mips64 && "Invalid register offset.");
+  return reg;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointHit(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointHit(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::ClearWatchpointHits()
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_mips64::ClearWatchpointHits() {
+  return false;
 }
 
-addr_t
-RegisterContextPOSIXProcessMonitor_mips64::GetWatchpointAddress(uint32_t hw_index)
-{
-    return LLDB_INVALID_ADDRESS;
+addr_t RegisterContextPOSIXProcessMonitor_mips64::GetWatchpointAddress(
+    uint32_t hw_index) {
+  return LLDB_INVALID_ADDRESS;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointVacant(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointVacant(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpointWithIndex(addr_t addr, size_t size,
-                                                       bool read, bool write,
-                                                       uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpointWithIndex(
+    addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
+  return false;
 }
 
 uint32_t
-RegisterContextPOSIXProcessMonitor_mips64::NumSupportedHardwareWatchpoints()
-{
-    return 0;
+RegisterContextPOSIXProcessMonitor_mips64::NumSupportedHardwareWatchpoints() {
+  return 0;
 }
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h Tue Sep  6 15:57:50 2016
@@ -10,87 +10,69 @@
 #ifndef liblldb_RegisterContextPOSIXProcessMonitor_mips64_H_
 #define liblldb_RegisterContextPOSIXProcessMonitor_mips64_H_
 
-#include "RegisterContextPOSIX.h"
 #include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
+#include "RegisterContextPOSIX.h"
 
-class RegisterContextPOSIXProcessMonitor_mips64:
-    public RegisterContextPOSIX_mips64,
-    public POSIXBreakpointProtocol
-{
+class RegisterContextPOSIXProcessMonitor_mips64
+    : public RegisterContextPOSIX_mips64,
+      public POSIXBreakpointProtocol {
 public:
-    RegisterContextPOSIXProcessMonitor_mips64(lldb_private::Thread &thread,
-                                              uint32_t concrete_frame_idx,
-                                              lldb_private::RegisterInfoInterface *register_info);
+  RegisterContextPOSIXProcessMonitor_mips64(
+      lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+      lldb_private::RegisterInfoInterface *register_info);
 
 protected:
-    bool
-    ReadGPR();
+  bool ReadGPR();
 
-    bool
-    ReadFPR();
+  bool ReadFPR();
 
-    bool
-    WriteGPR();
+  bool WriteGPR();
 
-    bool
-    WriteFPR();
+  bool WriteFPR();
 
-    // lldb_private::RegisterContext
-    bool
-    ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
+  // lldb_private::RegisterContext
+  bool ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const unsigned reg, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const unsigned reg,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
+  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
+                    lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
+  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
 
-    bool
-    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
+  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
 
-    uint32_t
-    SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write);
+  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
+                                 bool write);
 
-    bool
-    ClearHardwareWatchpoint(uint32_t hw_index);
+  bool ClearHardwareWatchpoint(uint32_t hw_index);
 
-    bool
-    HardwareSingleStep(bool enable);
+  bool HardwareSingleStep(bool enable);
 
-    // POSIXBreakpointProtocol
-    bool
-    UpdateAfterBreakpoint();
+  // POSIXBreakpointProtocol
+  bool UpdateAfterBreakpoint();
 
-    unsigned
-    GetRegisterIndexFromOffset(unsigned offset);
+  unsigned GetRegisterIndexFromOffset(unsigned offset);
 
-    bool
-    IsWatchpointHit(uint32_t hw_index);
+  bool IsWatchpointHit(uint32_t hw_index);
 
-    bool
-    ClearWatchpointHits();
+  bool ClearWatchpointHits();
 
-    lldb::addr_t
-    GetWatchpointAddress(uint32_t hw_index);
+  lldb::addr_t GetWatchpointAddress(uint32_t hw_index);
 
-    bool
-    IsWatchpointVacant(uint32_t hw_index);
+  bool IsWatchpointVacant(uint32_t hw_index);
 
-    bool
-    SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read, bool write, uint32_t hw_index);
+  bool SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read,
+                                      bool write, uint32_t hw_index);
 
-    uint32_t
-    NumSupportedHardwareWatchpoints();
+  uint32_t NumSupportedHardwareWatchpoints();
 
 private:
-    ProcessMonitor &
-    GetMonitor();
+  ProcessMonitor &GetMonitor();
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp Tue Sep  6 15:57:50 2016
@@ -11,327 +11,265 @@
 #include "lldb/Core/RegisterValue.h"
 #include "lldb/Target/Thread.h"
 
-#include "RegisterContextPOSIX_powerpc.h"
 #include "ProcessFreeBSD.h"
-#include "RegisterContextPOSIXProcessMonitor_powerpc.h"
 #include "ProcessMonitor.h"
+#include "RegisterContextPOSIXProcessMonitor_powerpc.h"
+#include "RegisterContextPOSIX_powerpc.h"
 
 using namespace lldb_private;
 using namespace lldb;
 
 #define REG_CONTEXT_SIZE (GetGPRSize())
 
-RegisterContextPOSIXProcessMonitor_powerpc::RegisterContextPOSIXProcessMonitor_powerpc(Thread &thread,
-                                                                                     uint32_t concrete_frame_idx,
-                                                                                     lldb_private::RegisterInfoInterface *register_info)
-    : RegisterContextPOSIX_powerpc(thread, concrete_frame_idx, register_info)
-{
-}
-
-ProcessMonitor &
-RegisterContextPOSIXProcessMonitor_powerpc::GetMonitor()
-{
-    ProcessSP base = CalculateProcess();
-    ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get());
-    return process->GetMonitor();
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ReadGPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadGPR(m_thread.GetID(), &m_gpr_powerpc, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ReadFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadFPR(m_thread.GetID(), &m_fpr_powerpc, sizeof(m_fpr_powerpc));
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ReadVMX()
-{
-    // XXX: Need a way to read/write process VMX registers with ptrace.
-    return false;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::WriteGPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteGPR(m_thread.GetID(), &m_gpr_powerpc, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::WriteFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteFPR(m_thread.GetID(), &m_fpr_powerpc, sizeof(m_fpr_powerpc));
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::WriteVMX()
-{
-    // XXX: Need a way to read/write process VMX registers with ptrace.
-    return false;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ReadRegister(const unsigned reg,
-                                                        RegisterValue &value)
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.ReadRegisterValue(m_thread.GetID(),
-                                     GetRegisterOffset(reg),
-                                     GetRegisterName(reg),
-                                     GetRegisterSize(reg),
-                                     value);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::WriteRegister(const unsigned reg,
-                                                         const RegisterValue &value)
-{
-    unsigned reg_to_write = reg;
-    RegisterValue value_to_write = value;
-
-    // Check if this is a subregister of a full register.
-    const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
-    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
-    {
-        RegisterValue full_value;
-        uint32_t full_reg = reg_info->invalidate_regs[0];
-        const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
-
-        // Read the full register.
-        if (ReadRegister(full_reg_info, full_value))
-        {
-            Error error;
-            ByteOrder byte_order = GetByteOrder();
-            uint8_t dst[RegisterValue::kMaxRegisterByteSize];
-
-            // Get the bytes for the full register.
-            const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
-                                                                   dst,
-                                                                   sizeof(dst),
-                                                                   byte_order,
-                                                                   error);
-            if (error.Success() && dest_size)
-            {
-                uint8_t src[RegisterValue::kMaxRegisterByteSize];
-
-                // Get the bytes for the source data.
-                const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
-                if (error.Success() && src_size && (src_size < dest_size))
-                {
-                    // Copy the src bytes to the destination.
-                    memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
-                    // Set this full register as the value to write.
-                    value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
-                    value_to_write.SetType(full_reg_info);
-                    reg_to_write = full_reg;
-                }
-            }
+RegisterContextPOSIXProcessMonitor_powerpc::
+    RegisterContextPOSIXProcessMonitor_powerpc(
+        Thread &thread, uint32_t concrete_frame_idx,
+        lldb_private::RegisterInfoInterface *register_info)
+    : RegisterContextPOSIX_powerpc(thread, concrete_frame_idx, register_info) {}
+
+ProcessMonitor &RegisterContextPOSIXProcessMonitor_powerpc::GetMonitor() {
+  ProcessSP base = CalculateProcess();
+  ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
+  return process->GetMonitor();
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::ReadGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadGPR(m_thread.GetID(), &m_gpr_powerpc, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::ReadFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadFPR(m_thread.GetID(), &m_fpr_powerpc,
+                         sizeof(m_fpr_powerpc));
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::ReadVMX() {
+  // XXX: Need a way to read/write process VMX registers with ptrace.
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::WriteGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteGPR(m_thread.GetID(), &m_gpr_powerpc, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::WriteFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteFPR(m_thread.GetID(), &m_fpr_powerpc,
+                          sizeof(m_fpr_powerpc));
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::WriteVMX() {
+  // XXX: Need a way to read/write process VMX registers with ptrace.
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::ReadRegister(
+    const unsigned reg, RegisterValue &value) {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
+                                   GetRegisterName(reg), GetRegisterSize(reg),
+                                   value);
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::WriteRegister(
+    const unsigned reg, const RegisterValue &value) {
+  unsigned reg_to_write = reg;
+  RegisterValue value_to_write = value;
+
+  // Check if this is a subregister of a full register.
+  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
+  if (reg_info->invalidate_regs &&
+      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
+    RegisterValue full_value;
+    uint32_t full_reg = reg_info->invalidate_regs[0];
+    const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
+
+    // Read the full register.
+    if (ReadRegister(full_reg_info, full_value)) {
+      Error error;
+      ByteOrder byte_order = GetByteOrder();
+      uint8_t dst[RegisterValue::kMaxRegisterByteSize];
+
+      // Get the bytes for the full register.
+      const uint32_t dest_size = full_value.GetAsMemoryData(
+          full_reg_info, dst, sizeof(dst), byte_order, error);
+      if (error.Success() && dest_size) {
+        uint8_t src[RegisterValue::kMaxRegisterByteSize];
+
+        // Get the bytes for the source data.
+        const uint32_t src_size = value.GetAsMemoryData(
+            reg_info, src, sizeof(src), byte_order, error);
+        if (error.Success() && src_size && (src_size < dest_size)) {
+          // Copy the src bytes to the destination.
+          memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
+          // Set this full register as the value to write.
+          value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
+          value_to_write.SetType(full_reg_info);
+          reg_to_write = full_reg;
         }
+      }
     }
+  }
 
-    ProcessMonitor &monitor = GetMonitor();
-    // Account for the fact that 32-bit targets on powerpc64 really use 64-bit
-    // registers in ptrace, but expose here 32-bit registers with a higher
-    // offset.
-    uint64_t offset = GetRegisterOffset(reg_to_write);
-    offset &= ~(sizeof(uintptr_t) - 1);
-    return monitor.WriteRegisterValue(m_thread.GetID(),
-                                      offset,
-                                      GetRegisterName(reg_to_write),
-                                      value_to_write);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
-{
-    if (!reg_info)
-        return false;
-
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsFPR(reg))
-    {
-        if (!ReadFPR())
-            return false;
-        uint8_t *src = (uint8_t *)&m_fpr_powerpc + reg_info->byte_offset;
-        value.SetUInt64(*(uint64_t*)src);
-    }
-    else if (IsGPR(reg))
-    {
-        bool success = ReadRegister(reg, value);
-
-        if (success)
-        {
-            // If our return byte size was greater than the return value reg size, then
-            // use the type specified by reg_info rather than the uint64_t default
-            if (value.GetByteSize() > reg_info->byte_size)
-                value.SetType(reg_info);
-        }
-        return success;
-    }
+  ProcessMonitor &monitor = GetMonitor();
+  // Account for the fact that 32-bit targets on powerpc64 really use 64-bit
+  // registers in ptrace, but expose here 32-bit registers with a higher
+  // offset.
+  uint64_t offset = GetRegisterOffset(reg_to_write);
+  offset &= ~(sizeof(uintptr_t) - 1);
+  return monitor.WriteRegisterValue(
+      m_thread.GetID(), offset, GetRegisterName(reg_to_write), value_to_write);
+}
 
+bool RegisterContextPOSIXProcessMonitor_powerpc::ReadRegister(
+    const RegisterInfo *reg_info, RegisterValue &value) {
+  if (!reg_info)
     return false;
-}
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value)
-{
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsGPR(reg))
-    {
-        return WriteRegister(reg, value);
-    }
-    else if (IsFPR(reg))
-    {
-        assert (reg_info->byte_offset < sizeof(m_fpr_powerpc));
-        uint8_t *dst = (uint8_t *)&m_fpr_powerpc + reg_info->byte_offset;
-        *(uint64_t *)dst = value.GetAsUInt64();
-        return WriteFPR();
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
+
+  if (IsFPR(reg)) {
+    if (!ReadFPR())
+      return false;
+    uint8_t *src = (uint8_t *)&m_fpr_powerpc + reg_info->byte_offset;
+    value.SetUInt64(*(uint64_t *)src);
+  } else if (IsGPR(reg)) {
+    bool success = ReadRegister(reg, value);
+
+    if (success) {
+      // If our return byte size was greater than the return value reg size,
+      // then
+      // use the type specified by reg_info rather than the uint64_t default
+      if (value.GetByteSize() > reg_info->byte_size)
+        value.SetType(reg_info);
     }
+    return success;
+  }
 
-    return false;
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ReadAllRegisterValues(DataBufferSP &data_sp)
-{
-    bool success = false;
-    data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
-    if (data_sp && ReadGPR () && ReadFPR ())
-    {
-        uint8_t *dst = data_sp->GetBytes();
-        success = dst != 0;
-
-        if (success)
-        {
-            ::memcpy (dst, &m_gpr_powerpc, GetGPRSize());
-            dst += GetGPRSize();
-        }
+bool RegisterContextPOSIXProcessMonitor_powerpc::WriteRegister(
+    const RegisterInfo *reg_info, const RegisterValue &value) {
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
+
+  if (IsGPR(reg)) {
+    return WriteRegister(reg, value);
+  } else if (IsFPR(reg)) {
+    assert(reg_info->byte_offset < sizeof(m_fpr_powerpc));
+    uint8_t *dst = (uint8_t *)&m_fpr_powerpc + reg_info->byte_offset;
+    *(uint64_t *)dst = value.GetAsUInt64();
+    return WriteFPR();
+  }
+
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::ReadAllRegisterValues(
+    DataBufferSP &data_sp) {
+  bool success = false;
+  data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
+  if (data_sp && ReadGPR() && ReadFPR()) {
+    uint8_t *dst = data_sp->GetBytes();
+    success = dst != 0;
+
+    if (success) {
+      ::memcpy(dst, &m_gpr_powerpc, GetGPRSize());
+      dst += GetGPRSize();
     }
-    return success;
+  }
+  return success;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::WriteAllRegisterValues(const DataBufferSP &data_sp)
-{
-    bool success = false;
-    if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
-    {
-        uint8_t *src = data_sp->GetBytes();
-        if (src)
-        {
-            ::memcpy (&m_gpr_powerpc, src, GetGPRSize());
-
-            if (WriteGPR())
-            {
-                src += GetGPRSize();
-                ::memcpy (&m_fpr_powerpc, src, sizeof(m_fpr_powerpc));
+bool RegisterContextPOSIXProcessMonitor_powerpc::WriteAllRegisterValues(
+    const DataBufferSP &data_sp) {
+  bool success = false;
+  if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
+    uint8_t *src = data_sp->GetBytes();
+    if (src) {
+      ::memcpy(&m_gpr_powerpc, src, GetGPRSize());
+
+      if (WriteGPR()) {
+        src += GetGPRSize();
+        ::memcpy(&m_fpr_powerpc, src, sizeof(m_fpr_powerpc));
 
-                success = WriteFPR();
-            }
-        }
+        success = WriteFPR();
+      }
     }
-    return success;
+  }
+  return success;
 }
 
-uint32_t
-RegisterContextPOSIXProcessMonitor_powerpc::SetHardwareWatchpoint(addr_t addr, size_t size,
-                                              bool read, bool write)
-{
-    const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
-    uint32_t hw_index;
-
-    for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index)
-    {
-        if (IsWatchpointVacant(hw_index))
-            return SetHardwareWatchpointWithIndex(addr, size,
-                                                  read, write,
-                                                  hw_index);
-    }
+uint32_t RegisterContextPOSIXProcessMonitor_powerpc::SetHardwareWatchpoint(
+    addr_t addr, size_t size, bool read, bool write) {
+  const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+  uint32_t hw_index;
+
+  for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
+    if (IsWatchpointVacant(hw_index))
+      return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
+  }
 
-    return LLDB_INVALID_INDEX32;
+  return LLDB_INVALID_INDEX32;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ClearHardwareWatchpoint(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_powerpc::ClearHardwareWatchpoint(
+    uint32_t hw_index) {
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_powerpc::HardwareSingleStep(
+    bool enable) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::HardwareSingleStep(bool enable)
-{
+bool RegisterContextPOSIXProcessMonitor_powerpc::UpdateAfterBreakpoint() {
+  lldb::addr_t pc;
+
+  if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
     return false;
+
+  return true;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::UpdateAfterBreakpoint()
-{
-    lldb::addr_t pc;
-
-    if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
-        return false;
-
-    return true;
-}
-
-unsigned
-RegisterContextPOSIXProcessMonitor_powerpc::GetRegisterIndexFromOffset(unsigned offset)
-{
-    unsigned reg;
-    for (reg = 0; reg < k_num_registers_powerpc; reg++)
-    {
-        if (GetRegisterInfo()[reg].byte_offset == offset)
-            break;
-    }
-    assert(reg < k_num_registers_powerpc && "Invalid register offset.");
-    return reg;
+unsigned RegisterContextPOSIXProcessMonitor_powerpc::GetRegisterIndexFromOffset(
+    unsigned offset) {
+  unsigned reg;
+  for (reg = 0; reg < k_num_registers_powerpc; reg++) {
+    if (GetRegisterInfo()[reg].byte_offset == offset)
+      break;
+  }
+  assert(reg < k_num_registers_powerpc && "Invalid register offset.");
+  return reg;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::IsWatchpointHit(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_powerpc::IsWatchpointHit(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::ClearWatchpointHits()
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_powerpc::ClearWatchpointHits() {
+  return false;
 }
 
-addr_t
-RegisterContextPOSIXProcessMonitor_powerpc::GetWatchpointAddress(uint32_t hw_index)
-{
-    return LLDB_INVALID_ADDRESS;
+addr_t RegisterContextPOSIXProcessMonitor_powerpc::GetWatchpointAddress(
+    uint32_t hw_index) {
+  return LLDB_INVALID_ADDRESS;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::IsWatchpointVacant(uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_powerpc::IsWatchpointVacant(
+    uint32_t hw_index) {
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_powerpc::SetHardwareWatchpointWithIndex(addr_t addr, size_t size,
-                                                       bool read, bool write,
-                                                       uint32_t hw_index)
-{
-    return false;
+bool RegisterContextPOSIXProcessMonitor_powerpc::SetHardwareWatchpointWithIndex(
+    addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
+  return false;
 }
 
 uint32_t
-RegisterContextPOSIXProcessMonitor_powerpc::NumSupportedHardwareWatchpoints()
-{
-    return 0;
+RegisterContextPOSIXProcessMonitor_powerpc::NumSupportedHardwareWatchpoints() {
+  return 0;
 }
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.h Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- RegisterContextPOSIXProcessMonitor_powerpc.h -------------*- C++ -*-===//
+//===-- RegisterContextPOSIXProcessMonitor_powerpc.h -------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -10,96 +11,75 @@
 #ifndef liblldb_RegisterContextPOSIXProcessMonitor_powerpc_H_
 #define liblldb_RegisterContextPOSIXProcessMonitor_powerpc_H_
 
-#include "RegisterContextPOSIX.h"
 #include "Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h"
+#include "RegisterContextPOSIX.h"
 
-class RegisterContextPOSIXProcessMonitor_powerpc:
-    public RegisterContextPOSIX_powerpc,
-    public POSIXBreakpointProtocol
-{
+class RegisterContextPOSIXProcessMonitor_powerpc
+    : public RegisterContextPOSIX_powerpc,
+      public POSIXBreakpointProtocol {
 public:
-    RegisterContextPOSIXProcessMonitor_powerpc(lldb_private::Thread &thread,
-                                              uint32_t concrete_frame_idx,
-                                              lldb_private::RegisterInfoInterface *register_info);
+  RegisterContextPOSIXProcessMonitor_powerpc(
+      lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+      lldb_private::RegisterInfoInterface *register_info);
 
 protected:
-    bool
-    IsVMX();
+  bool IsVMX();
 
-    bool
-    ReadGPR();
+  bool ReadGPR();
 
-    bool
-    ReadFPR();
+  bool ReadFPR();
 
-    bool
-    ReadVMX();
+  bool ReadVMX();
 
-    bool
-    WriteGPR();
+  bool WriteGPR();
 
-    bool
-    WriteFPR();
+  bool WriteFPR();
 
-    bool
-    WriteVMX();
+  bool WriteVMX();
 
-    // lldb_private::RegisterContext
-    bool
-    ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
+  // lldb_private::RegisterContext
+  bool ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const unsigned reg, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const unsigned reg,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
+  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
+                    lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
+  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
 
-    bool
-    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
+  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
 
-    uint32_t
-    SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write);
+  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
+                                 bool write);
 
-    bool
-    ClearHardwareWatchpoint(uint32_t hw_index);
+  bool ClearHardwareWatchpoint(uint32_t hw_index);
 
-    bool
-    HardwareSingleStep(bool enable);
+  bool HardwareSingleStep(bool enable);
 
-    // POSIXBreakpointProtocol
-    bool
-    UpdateAfterBreakpoint();
+  // POSIXBreakpointProtocol
+  bool UpdateAfterBreakpoint();
 
-    unsigned
-    GetRegisterIndexFromOffset(unsigned offset);
+  unsigned GetRegisterIndexFromOffset(unsigned offset);
 
-    bool
-    IsWatchpointHit(uint32_t hw_index);
+  bool IsWatchpointHit(uint32_t hw_index);
 
-    bool
-    ClearWatchpointHits();
+  bool ClearWatchpointHits();
 
-    lldb::addr_t
-    GetWatchpointAddress(uint32_t hw_index);
+  lldb::addr_t GetWatchpointAddress(uint32_t hw_index);
 
-    bool
-    IsWatchpointVacant(uint32_t hw_index);
+  bool IsWatchpointVacant(uint32_t hw_index);
 
-    bool
-    SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read, bool write, uint32_t hw_index);
+  bool SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read,
+                                      bool write, uint32_t hw_index);
 
-    uint32_t
-    NumSupportedHardwareWatchpoints();
+  uint32_t NumSupportedHardwareWatchpoints();
 
 private:
-    ProcessMonitor &
-    GetMonitor();
+  ProcessMonitor &GetMonitor();
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp Tue Sep  6 15:57:50 2016
@@ -12,662 +12,603 @@
 #include "lldb/Target/Thread.h"
 
 #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
-#include "RegisterContextPOSIXProcessMonitor_x86.h"
 #include "Plugins/Process/FreeBSD/ProcessMonitor.h"
+#include "RegisterContextPOSIXProcessMonitor_x86.h"
 
 using namespace lldb_private;
 using namespace lldb;
 
 // Support ptrace extensions even when compiled without required kernel support
 #ifndef NT_X86_XSTATE
-  #define NT_X86_XSTATE 0x202
+#define NT_X86_XSTATE 0x202
 #endif
 
 #define REG_CONTEXT_SIZE (GetGPRSize() + sizeof(FPR))
 
-static uint32_t
-size_and_rw_bits(size_t size, bool read, bool write)
-{
-    uint32_t rw;
-
-    if (read)
-        rw = 0x3; // READ or READ/WRITE
-    else if (write)
-        rw = 0x1; // WRITE
-    else
-        assert(0 && "read and write cannot both be false");
-
-    switch (size)
-    {
-    case 1:
-        return rw;
-    case 2:
-        return (0x1 << 2) | rw;
-    case 4:
-        return (0x3 << 2) | rw;
-    case 8:
-        return (0x2 << 2) | rw;
-    default:
-        assert(0 && "invalid size, must be one of 1, 2, 4, or 8");
-        return 0; // Unreachable. Just to silence compiler.
-    }
-}
-
-RegisterContextPOSIXProcessMonitor_x86_64::RegisterContextPOSIXProcessMonitor_x86_64(Thread &thread,
-                                                                                     uint32_t concrete_frame_idx,
-                                                                                     lldb_private::RegisterInfoInterface *register_info)
-    : RegisterContextPOSIX_x86(thread, concrete_frame_idx, register_info)
-{
-    // Store byte offset of fctrl (i.e. first register of FPR) wrt 'UserArea'
-    const RegisterInfo *reg_info_fctrl = GetRegisterInfoByName("fctrl");
-    m_fctrl_offset_in_userarea = reg_info_fctrl->byte_offset;
-}
-
-ProcessMonitor &
-RegisterContextPOSIXProcessMonitor_x86_64::GetMonitor()
-{
-    ProcessSP base = CalculateProcess();
-    ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get());
-    return process->GetMonitor();
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ReadGPR()
-{
-     ProcessMonitor &monitor = GetMonitor();
-     return monitor.ReadGPR(m_thread.GetID(), &m_gpr_x86_64, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ReadFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    if (GetFPRType() == eFXSAVE)
-        return monitor.ReadFPR(m_thread.GetID(), &m_fpr.xstate.fxsave, sizeof(m_fpr.xstate.fxsave));
+static uint32_t size_and_rw_bits(size_t size, bool read, bool write) {
+  uint32_t rw;
 
-    if (GetFPRType() == eXSAVE)
-        return monitor.ReadRegisterSet(m_thread.GetID(), &m_iovec, sizeof(m_fpr.xstate.xsave), NT_X86_XSTATE);
-    return false;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::WriteGPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    return monitor.WriteGPR(m_thread.GetID(), &m_gpr_x86_64, GetGPRSize());
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::WriteFPR()
-{
-    ProcessMonitor &monitor = GetMonitor();
-    if (GetFPRType() == eFXSAVE)
-        return monitor.WriteFPR(m_thread.GetID(), &m_fpr.xstate.fxsave, sizeof(m_fpr.xstate.fxsave));
-
-    if (GetFPRType() == eXSAVE)
-        return monitor.WriteRegisterSet(m_thread.GetID(), &m_iovec, sizeof(m_fpr.xstate.xsave), NT_X86_XSTATE);
-    return false;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(const unsigned reg,
-                                                        RegisterValue &value)
-{
-    ProcessMonitor &monitor = GetMonitor();
+  if (read)
+    rw = 0x3; // READ or READ/WRITE
+  else if (write)
+    rw = 0x1; // WRITE
+  else
+    assert(0 && "read and write cannot both be false");
+
+  switch (size) {
+  case 1:
+    return rw;
+  case 2:
+    return (0x1 << 2) | rw;
+  case 4:
+    return (0x3 << 2) | rw;
+  case 8:
+    return (0x2 << 2) | rw;
+  default:
+    assert(0 && "invalid size, must be one of 1, 2, 4, or 8");
+    return 0; // Unreachable. Just to silence compiler.
+  }
+}
+
+RegisterContextPOSIXProcessMonitor_x86_64::
+    RegisterContextPOSIXProcessMonitor_x86_64(
+        Thread &thread, uint32_t concrete_frame_idx,
+        lldb_private::RegisterInfoInterface *register_info)
+    : RegisterContextPOSIX_x86(thread, concrete_frame_idx, register_info) {
+  // Store byte offset of fctrl (i.e. first register of FPR) wrt 'UserArea'
+  const RegisterInfo *reg_info_fctrl = GetRegisterInfoByName("fctrl");
+  m_fctrl_offset_in_userarea = reg_info_fctrl->byte_offset;
+}
+
+ProcessMonitor &RegisterContextPOSIXProcessMonitor_x86_64::GetMonitor() {
+  ProcessSP base = CalculateProcess();
+  ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
+  return process->GetMonitor();
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::ReadGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.ReadGPR(m_thread.GetID(), &m_gpr_x86_64, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::ReadFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  if (GetFPRType() == eFXSAVE)
+    return monitor.ReadFPR(m_thread.GetID(), &m_fpr.xstate.fxsave,
+                           sizeof(m_fpr.xstate.fxsave));
+
+  if (GetFPRType() == eXSAVE)
+    return monitor.ReadRegisterSet(m_thread.GetID(), &m_iovec,
+                                   sizeof(m_fpr.xstate.xsave), NT_X86_XSTATE);
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::WriteGPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  return monitor.WriteGPR(m_thread.GetID(), &m_gpr_x86_64, GetGPRSize());
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::WriteFPR() {
+  ProcessMonitor &monitor = GetMonitor();
+  if (GetFPRType() == eFXSAVE)
+    return monitor.WriteFPR(m_thread.GetID(), &m_fpr.xstate.fxsave,
+                            sizeof(m_fpr.xstate.fxsave));
+
+  if (GetFPRType() == eXSAVE)
+    return monitor.WriteRegisterSet(m_thread.GetID(), &m_iovec,
+                                    sizeof(m_fpr.xstate.xsave), NT_X86_XSTATE);
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(
+    const unsigned reg, RegisterValue &value) {
+  ProcessMonitor &monitor = GetMonitor();
 
 #if defined(__FreeBSD__)
-    if (reg >= m_reg_info.first_dr)
-        return monitor.ReadDebugRegisterValue(m_thread.GetID(),
-                                              GetRegisterOffset(reg),
-                                              GetRegisterName(reg),
-                                              GetRegisterSize(reg),
-                                              value);
+  if (reg >= m_reg_info.first_dr)
+    return monitor.ReadDebugRegisterValue(
+        m_thread.GetID(), GetRegisterOffset(reg), GetRegisterName(reg),
+        GetRegisterSize(reg), value);
 #endif
-    return monitor.ReadRegisterValue(m_thread.GetID(),
-                                     GetRegisterOffset(reg),
-                                     GetRegisterName(reg),
-                                     GetRegisterSize(reg),
-                                     value);
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(const unsigned reg,
-                                                         const RegisterValue &value)
-{
-    unsigned reg_to_write = reg;
-    RegisterValue value_to_write = value;
-
-    // Check if this is a subregister of a full register.
-    const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
-    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
-    {
-        RegisterValue full_value;
-        uint32_t full_reg = reg_info->invalidate_regs[0];
-        const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
-
-        // Read the full register.
-        if (ReadRegister(full_reg_info, full_value))
-        {
-            Error error;
-            ByteOrder byte_order = GetByteOrder();
-            uint8_t dst[RegisterValue::kMaxRegisterByteSize];
-
-            // Get the bytes for the full register.
-            const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info, 
-                                                                   dst, 
-                                                                   sizeof(dst), 
-                                                                   byte_order, 
-                                                                   error);
-            if (error.Success() && dest_size)
-            {
-                uint8_t src[RegisterValue::kMaxRegisterByteSize];
-
-                // Get the bytes for the source data.
-                const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
-                if (error.Success() && src_size && (src_size < dest_size))
-                {
-                    // Copy the src bytes to the destination.
-                    memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
-                    // Set this full register as the value to write.
-                    value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
-                    value_to_write.SetType(full_reg_info);
-                    reg_to_write = full_reg;
-                }
-            }
+  return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
+                                   GetRegisterName(reg), GetRegisterSize(reg),
+                                   value);
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(
+    const unsigned reg, const RegisterValue &value) {
+  unsigned reg_to_write = reg;
+  RegisterValue value_to_write = value;
+
+  // Check if this is a subregister of a full register.
+  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
+  if (reg_info->invalidate_regs &&
+      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
+    RegisterValue full_value;
+    uint32_t full_reg = reg_info->invalidate_regs[0];
+    const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
+
+    // Read the full register.
+    if (ReadRegister(full_reg_info, full_value)) {
+      Error error;
+      ByteOrder byte_order = GetByteOrder();
+      uint8_t dst[RegisterValue::kMaxRegisterByteSize];
+
+      // Get the bytes for the full register.
+      const uint32_t dest_size = full_value.GetAsMemoryData(
+          full_reg_info, dst, sizeof(dst), byte_order, error);
+      if (error.Success() && dest_size) {
+        uint8_t src[RegisterValue::kMaxRegisterByteSize];
+
+        // Get the bytes for the source data.
+        const uint32_t src_size = value.GetAsMemoryData(
+            reg_info, src, sizeof(src), byte_order, error);
+        if (error.Success() && src_size && (src_size < dest_size)) {
+          // Copy the src bytes to the destination.
+          memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
+          // Set this full register as the value to write.
+          value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
+          value_to_write.SetType(full_reg_info);
+          reg_to_write = full_reg;
         }
+      }
     }
+  }
 
-    ProcessMonitor &monitor = GetMonitor();
+  ProcessMonitor &monitor = GetMonitor();
 #if defined(__FreeBSD__)
-    if (reg >= m_reg_info.first_dr)
-        return monitor.WriteDebugRegisterValue(m_thread.GetID(),
-                                               GetRegisterOffset(reg_to_write),
-                                               GetRegisterName(reg_to_write),
-                                               value_to_write);
+  if (reg >= m_reg_info.first_dr)
+    return monitor.WriteDebugRegisterValue(
+        m_thread.GetID(), GetRegisterOffset(reg_to_write),
+        GetRegisterName(reg_to_write), value_to_write);
 #endif
-    return monitor.WriteRegisterValue(m_thread.GetID(),
-                                      GetRegisterOffset(reg_to_write),
-                                      GetRegisterName(reg_to_write),
-                                      value_to_write);
+  return monitor.WriteRegisterValue(
+      m_thread.GetID(), GetRegisterOffset(reg_to_write),
+      GetRegisterName(reg_to_write), value_to_write);
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
-{
-    if (!reg_info)
-        return false;
-
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsFPR(reg, GetFPRType()))
-    {
-        if (!ReadFPR())
-            return false;
-    }
-    else
-    {
-        uint32_t full_reg = reg;
-        bool is_subreg = reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
-
-        if (is_subreg)
-        {
-            // Read the full aligned 64-bit register.
-            full_reg = reg_info->invalidate_regs[0];
-        }
+bool RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(
+    const RegisterInfo *reg_info, RegisterValue &value) {
+  if (!reg_info)
+    return false;
 
-        bool success = ReadRegister(full_reg, value);
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
 
-        if (success)
-        {
-            // If our read was not aligned (for ah,bh,ch,dh), shift our returned value one byte to the right.
-            if (is_subreg && (reg_info->byte_offset & 0x1))
-                value.SetUInt64(value.GetAsUInt64() >> 8);
-
-            // If our return byte size was greater than the return value reg size, then
-            // use the type specified by reg_info rather than the uint64_t default
-            if (value.GetByteSize() > reg_info->byte_size)
-                value.SetType(reg_info);
-        }
-        return success; 
-    }
-
-    if (reg_info->encoding == eEncodingVector)
-    {
-        ByteOrder byte_order = GetByteOrder();
-
-        if (byte_order != ByteOrder::eByteOrderInvalid)
-        {
-            if (reg >= m_reg_info.first_st && reg <= m_reg_info.last_st)
-               value.SetBytes(m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_st].bytes, reg_info->byte_size, byte_order);
-            if (reg >= m_reg_info.first_mm && reg <= m_reg_info.last_mm)
-               value.SetBytes(m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_mm].bytes, reg_info->byte_size, byte_order);
-            if (reg >= m_reg_info.first_xmm && reg <= m_reg_info.last_xmm)
-                value.SetBytes(m_fpr.xstate.fxsave.xmm[reg - m_reg_info.first_xmm].bytes, reg_info->byte_size, byte_order);
-            if (reg >= m_reg_info.first_ymm && reg <= m_reg_info.last_ymm)
-            {
-                // Concatenate ymm using the register halves in xmm.bytes and ymmh.bytes
-                if (GetFPRType() == eXSAVE && CopyXSTATEtoYMM(reg, byte_order))
-                    value.SetBytes(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, reg_info->byte_size, byte_order);
-                else
-                    return false;
-            }
-            return value.GetType() == RegisterValue::eTypeBytes;
-        }
-        return false;
+  if (IsFPR(reg, GetFPRType())) {
+    if (!ReadFPR())
+      return false;
+  } else {
+    uint32_t full_reg = reg;
+    bool is_subreg = reg_info->invalidate_regs &&
+                     (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
+
+    if (is_subreg) {
+      // Read the full aligned 64-bit register.
+      full_reg = reg_info->invalidate_regs[0];
+    }
+
+    bool success = ReadRegister(full_reg, value);
+
+    if (success) {
+      // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
+      // one byte to the right.
+      if (is_subreg && (reg_info->byte_offset & 0x1))
+        value.SetUInt64(value.GetAsUInt64() >> 8);
+
+      // If our return byte size was greater than the return value reg size,
+      // then
+      // use the type specified by reg_info rather than the uint64_t default
+      if (value.GetByteSize() > reg_info->byte_size)
+        value.SetType(reg_info);
     }
+    return success;
+  }
 
-    // Get pointer to m_fpr.xstate.fxsave variable and set the data from it.
-    // Byte offsets of all registers are calculated wrt 'UserArea' structure.
-    // However, ReadFPR() reads fpu registers {using ptrace(PT_GETFPREGS,..)}
-    // and stores them in 'm_fpr' (of type FPR structure). To extract values of fpu
-    // registers, m_fpr should be read at byte offsets calculated wrt to FPR structure.
-
-    // Since, FPR structure is also one of the member of UserArea structure.
-    // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) - byte_offset(fctrl wrt UserArea)
-    assert ( (reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr));
-    uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea;
-    switch (reg_info->byte_size)
-    {
-        case 1:
-            value.SetUInt8(*(uint8_t *)src);
-            return true;
-        case 2:
-            value.SetUInt16(*(uint16_t *)src);
-            return true;
-        case 4:
-            value.SetUInt32(*(uint32_t *)src);
-            return true;
-        case 8:
-            value.SetUInt64(*(uint64_t *)src);
-            return true;
-        default:
-            assert(false && "Unhandled data size.");
-            return false;
-    }
-}
+  if (reg_info->encoding == eEncodingVector) {
+    ByteOrder byte_order = GetByteOrder();
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value)
-{
-    const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
-
-    if (IsGPR(reg))
-        return WriteRegister(reg, value);
-
-    if (IsFPR(reg, GetFPRType()))
-    {
-        if (reg_info->encoding == eEncodingVector)
-        {
-            if (reg >= m_reg_info.first_st && reg <= m_reg_info.last_st)
-               ::memcpy (m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_st].bytes, value.GetBytes(), value.GetByteSize());
-
-            if (reg >= m_reg_info.first_mm && reg <= m_reg_info.last_mm)
-               ::memcpy (m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_mm].bytes, value.GetBytes(), value.GetByteSize());
- 
-            if (reg >= m_reg_info.first_xmm && reg <= m_reg_info.last_xmm)
-               ::memcpy (m_fpr.xstate.fxsave.xmm[reg - m_reg_info.first_xmm].bytes, value.GetBytes(), value.GetByteSize());
-            
-            if (reg >= m_reg_info.first_ymm && reg <= m_reg_info.last_ymm)
-            {
-               if (GetFPRType() != eXSAVE)
-                   return false; // the target processor does not support AVX
-
-               // Store ymm register content, and split into the register halves in xmm.bytes and ymmh.bytes
-               ::memcpy (m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, value.GetBytes(), value.GetByteSize());
-               if (false == CopyYMMtoXSTATE(reg, GetByteOrder()))
-                   return false;
-            }
-        }
+    if (byte_order != ByteOrder::eByteOrderInvalid) {
+      if (reg >= m_reg_info.first_st && reg <= m_reg_info.last_st)
+        value.SetBytes(
+            m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_st].bytes,
+            reg_info->byte_size, byte_order);
+      if (reg >= m_reg_info.first_mm && reg <= m_reg_info.last_mm)
+        value.SetBytes(
+            m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_mm].bytes,
+            reg_info->byte_size, byte_order);
+      if (reg >= m_reg_info.first_xmm && reg <= m_reg_info.last_xmm)
+        value.SetBytes(
+            m_fpr.xstate.fxsave.xmm[reg - m_reg_info.first_xmm].bytes,
+            reg_info->byte_size, byte_order);
+      if (reg >= m_reg_info.first_ymm && reg <= m_reg_info.last_ymm) {
+        // Concatenate ymm using the register halves in xmm.bytes and ymmh.bytes
+        if (GetFPRType() == eXSAVE && CopyXSTATEtoYMM(reg, byte_order))
+          value.SetBytes(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes,
+                         reg_info->byte_size, byte_order);
         else
-        {
-            // Get pointer to m_fpr.xstate.fxsave variable and set the data to it.
-            // Byte offsets of all registers are calculated wrt 'UserArea' structure.
-            // However, WriteFPR() takes m_fpr (of type FPR structure) and writes only fpu
-            // registers using ptrace(PT_SETFPREGS,..) API. Hence fpu registers should
-            // be written in m_fpr at byte offsets calculated wrt FPR structure.
-
-            // Since, FPR structure is also one of the member of UserArea structure.
-            // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) - byte_offset(fctrl wrt UserArea)
-            assert ( (reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr));
-            uint8_t *dst = (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea;
-            switch (reg_info->byte_size)
-            {
-                case 1:
-                    *(uint8_t *)dst = value.GetAsUInt8();
-                    break;
-                case 2:
-                    *(uint16_t *)dst = value.GetAsUInt16();
-                    break;
-                case 4:
-                    *(uint32_t *)dst = value.GetAsUInt32();
-                    break;
-                case 8:
-                    *(uint64_t *)dst = value.GetAsUInt64();
-                    break;
-                default:
-                    assert(false && "Unhandled data size.");
-                    return false;
-            }
-        }
-
-        if (WriteFPR())
-        {
-            if (IsAVX(reg))
-                return CopyYMMtoXSTATE(reg, GetByteOrder());
-            return true;
-        }
+          return false;
+      }
+      return value.GetType() == RegisterValue::eTypeBytes;
     }
     return false;
+  }
+
+  // Get pointer to m_fpr.xstate.fxsave variable and set the data from it.
+  // Byte offsets of all registers are calculated wrt 'UserArea' structure.
+  // However, ReadFPR() reads fpu registers {using ptrace(PT_GETFPREGS,..)}
+  // and stores them in 'm_fpr' (of type FPR structure). To extract values of
+  // fpu
+  // registers, m_fpr should be read at byte offsets calculated wrt to FPR
+  // structure.
+
+  // Since, FPR structure is also one of the member of UserArea structure.
+  // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) -
+  // byte_offset(fctrl wrt UserArea)
+  assert((reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr));
+  uint8_t *src =
+      (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea;
+  switch (reg_info->byte_size) {
+  case 1:
+    value.SetUInt8(*(uint8_t *)src);
+    return true;
+  case 2:
+    value.SetUInt16(*(uint16_t *)src);
+    return true;
+  case 4:
+    value.SetUInt32(*(uint32_t *)src);
+    return true;
+  case 8:
+    value.SetUInt64(*(uint64_t *)src);
+    return true;
+  default:
+    assert(false && "Unhandled data size.");
+    return false;
+  }
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ReadAllRegisterValues(DataBufferSP &data_sp)
-{
-    bool success = false;
-    data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
-    if (data_sp && ReadGPR () && ReadFPR ())
-    {
-        uint8_t *dst = data_sp->GetBytes();
-        success = dst != 0;
-
-        if (success)
-        {
-          ::memcpy (dst, &m_gpr_x86_64, GetGPRSize());
-          dst += GetGPRSize();
-          if (GetFPRType() == eFXSAVE)
-              ::memcpy (dst, &m_fpr.xstate.fxsave, sizeof(m_fpr.xstate.fxsave));
-        }
+bool RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(
+    const RegisterInfo *reg_info, const RegisterValue &value) {
+  const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
+
+  if (IsGPR(reg))
+    return WriteRegister(reg, value);
+
+  if (IsFPR(reg, GetFPRType())) {
+    if (reg_info->encoding == eEncodingVector) {
+      if (reg >= m_reg_info.first_st && reg <= m_reg_info.last_st)
+        ::memcpy(m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_st].bytes,
+                 value.GetBytes(), value.GetByteSize());
+
+      if (reg >= m_reg_info.first_mm && reg <= m_reg_info.last_mm)
+        ::memcpy(m_fpr.xstate.fxsave.stmm[reg - m_reg_info.first_mm].bytes,
+                 value.GetBytes(), value.GetByteSize());
+
+      if (reg >= m_reg_info.first_xmm && reg <= m_reg_info.last_xmm)
+        ::memcpy(m_fpr.xstate.fxsave.xmm[reg - m_reg_info.first_xmm].bytes,
+                 value.GetBytes(), value.GetByteSize());
+
+      if (reg >= m_reg_info.first_ymm && reg <= m_reg_info.last_ymm) {
+        if (GetFPRType() != eXSAVE)
+          return false; // the target processor does not support AVX
+
+        // Store ymm register content, and split into the register halves in
+        // xmm.bytes and ymmh.bytes
+        ::memcpy(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes,
+                 value.GetBytes(), value.GetByteSize());
+        if (false == CopyYMMtoXSTATE(reg, GetByteOrder()))
+          return false;
+      }
+    } else {
+      // Get pointer to m_fpr.xstate.fxsave variable and set the data to it.
+      // Byte offsets of all registers are calculated wrt 'UserArea' structure.
+      // However, WriteFPR() takes m_fpr (of type FPR structure) and writes only
+      // fpu
+      // registers using ptrace(PT_SETFPREGS,..) API. Hence fpu registers should
+      // be written in m_fpr at byte offsets calculated wrt FPR structure.
+
+      // Since, FPR structure is also one of the member of UserArea structure.
+      // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) -
+      // byte_offset(fctrl wrt UserArea)
+      assert((reg_info->byte_offset - m_fctrl_offset_in_userarea) <
+             sizeof(m_fpr));
+      uint8_t *dst = (uint8_t *)&m_fpr + reg_info->byte_offset -
+                     m_fctrl_offset_in_userarea;
+      switch (reg_info->byte_size) {
+      case 1:
+        *(uint8_t *)dst = value.GetAsUInt8();
+        break;
+      case 2:
+        *(uint16_t *)dst = value.GetAsUInt16();
+        break;
+      case 4:
+        *(uint32_t *)dst = value.GetAsUInt32();
+        break;
+      case 8:
+        *(uint64_t *)dst = value.GetAsUInt64();
+        break;
+      default:
+        assert(false && "Unhandled data size.");
+        return false;
+      }
+    }
 
+    if (WriteFPR()) {
+      if (IsAVX(reg))
+        return CopyYMMtoXSTATE(reg, GetByteOrder());
+      return true;
+    }
+  }
+  return false;
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::ReadAllRegisterValues(
+    DataBufferSP &data_sp) {
+  bool success = false;
+  data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
+  if (data_sp && ReadGPR() && ReadFPR()) {
+    uint8_t *dst = data_sp->GetBytes();
+    success = dst != 0;
+
+    if (success) {
+      ::memcpy(dst, &m_gpr_x86_64, GetGPRSize());
+      dst += GetGPRSize();
+      if (GetFPRType() == eFXSAVE)
+        ::memcpy(dst, &m_fpr.xstate.fxsave, sizeof(m_fpr.xstate.fxsave));
+    }
+
+    if (GetFPRType() == eXSAVE) {
+      ByteOrder byte_order = GetByteOrder();
+
+      // Assemble the YMM register content from the register halves.
+      for (uint32_t reg = m_reg_info.first_ymm;
+           success && reg <= m_reg_info.last_ymm; ++reg)
+        success = CopyXSTATEtoYMM(reg, byte_order);
+
+      if (success) {
+        // Copy the extended register state including the assembled ymm
+        // registers.
+        ::memcpy(dst, &m_fpr, sizeof(m_fpr));
+      }
+    }
+  }
+  return success;
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::WriteAllRegisterValues(
+    const DataBufferSP &data_sp) {
+  bool success = false;
+  if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
+    uint8_t *src = data_sp->GetBytes();
+    if (src) {
+      ::memcpy(&m_gpr_x86_64, src, GetGPRSize());
+
+      if (WriteGPR()) {
+        src += GetGPRSize();
+        if (GetFPRType() == eFXSAVE)
+          ::memcpy(&m_fpr.xstate.fxsave, src, sizeof(m_fpr.xstate.fxsave));
         if (GetFPRType() == eXSAVE)
-        {
+          ::memcpy(&m_fpr.xstate.xsave, src, sizeof(m_fpr.xstate.xsave));
+
+        success = WriteFPR();
+        if (success) {
+          if (GetFPRType() == eXSAVE) {
             ByteOrder byte_order = GetByteOrder();
 
-            // Assemble the YMM register content from the register halves.
-            for (uint32_t reg  = m_reg_info.first_ymm; success && reg <= m_reg_info.last_ymm; ++reg)
-                success = CopyXSTATEtoYMM(reg, byte_order);
-
-            if (success)
-            {
-                // Copy the extended register state including the assembled ymm registers.
-                ::memcpy (dst, &m_fpr, sizeof(m_fpr));
-            }
+            // Parse the YMM register content from the register halves.
+            for (uint32_t reg = m_reg_info.first_ymm;
+                 success && reg <= m_reg_info.last_ymm; ++reg)
+              success = CopyYMMtoXSTATE(reg, byte_order);
+          }
         }
+      }
     }
-    return success;
+  }
+  return success;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::WriteAllRegisterValues(const DataBufferSP &data_sp)
-{
-    bool success = false;
-    if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
-    {
-        uint8_t *src = data_sp->GetBytes();
-        if (src)
-        {
-            ::memcpy (&m_gpr_x86_64, src, GetGPRSize());
-
-            if (WriteGPR())
-            {
-                src += GetGPRSize();
-                if (GetFPRType() == eFXSAVE)
-                    ::memcpy (&m_fpr.xstate.fxsave, src, sizeof(m_fpr.xstate.fxsave));
-                if (GetFPRType() == eXSAVE)
-                    ::memcpy (&m_fpr.xstate.xsave, src, sizeof(m_fpr.xstate.xsave));
-
-                success = WriteFPR();
-                if (success)
-                {
-                    if (GetFPRType() == eXSAVE)
-                    {
-                        ByteOrder byte_order = GetByteOrder();
-
-                        // Parse the YMM register content from the register halves.
-                        for (uint32_t reg = m_reg_info.first_ymm; success && reg <= m_reg_info.last_ymm; ++reg)
-                            success = CopyYMMtoXSTATE(reg, byte_order);
-                    }
-                }
-            }
-        }
-    }
-    return success;
+uint32_t RegisterContextPOSIXProcessMonitor_x86_64::SetHardwareWatchpoint(
+    addr_t addr, size_t size, bool read, bool write) {
+  const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+  uint32_t hw_index;
+
+  for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
+    if (IsWatchpointVacant(hw_index))
+      return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
+  }
+
+  return LLDB_INVALID_INDEX32;
 }
 
-uint32_t
-RegisterContextPOSIXProcessMonitor_x86_64::SetHardwareWatchpoint(addr_t addr, size_t size,
-                                              bool read, bool write)
-{
-    const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
-    uint32_t hw_index;
-
-    for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index)
-    {
-        if (IsWatchpointVacant(hw_index))
-            return SetHardwareWatchpointWithIndex(addr, size,
-                                                  read, write,
-                                                  hw_index);
-    }
-
-    return LLDB_INVALID_INDEX32;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ClearHardwareWatchpoint(uint32_t hw_index)
-{
-    if (hw_index < NumSupportedHardwareWatchpoints())
-    {
-        RegisterValue current_dr7_bits;
-
-        if (ReadRegister(m_reg_info.first_dr + 7, current_dr7_bits))
-        {
-            uint64_t new_dr7_bits = current_dr7_bits.GetAsUInt64() & ~(3 << (2*hw_index));
+bool RegisterContextPOSIXProcessMonitor_x86_64::ClearHardwareWatchpoint(
+    uint32_t hw_index) {
+  if (hw_index < NumSupportedHardwareWatchpoints()) {
+    RegisterValue current_dr7_bits;
 
-            if (WriteRegister(m_reg_info.first_dr + 7, RegisterValue(new_dr7_bits)))
-                return true;
-        }
+    if (ReadRegister(m_reg_info.first_dr + 7, current_dr7_bits)) {
+      uint64_t new_dr7_bits =
+          current_dr7_bits.GetAsUInt64() & ~(3 << (2 * hw_index));
+
+      if (WriteRegister(m_reg_info.first_dr + 7, RegisterValue(new_dr7_bits)))
+        return true;
     }
+  }
 
-    return false;
+  return false;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::HardwareSingleStep(bool enable)
-{
-    enum { TRACE_BIT = 0x100 };
-    uint64_t rflags;
+bool RegisterContextPOSIXProcessMonitor_x86_64::HardwareSingleStep(
+    bool enable) {
+  enum { TRACE_BIT = 0x100 };
+  uint64_t rflags;
 
-    if ((rflags = ReadRegisterAsUnsigned(m_reg_info.gpr_flags, -1UL)) == -1UL)
-        return false;
-    
-    if (enable)
-    {
-        if (rflags & TRACE_BIT)
-            return true;
+  if ((rflags = ReadRegisterAsUnsigned(m_reg_info.gpr_flags, -1UL)) == -1UL)
+    return false;
 
-        rflags |= TRACE_BIT;
-    }
-    else
-    {
-        if (!(rflags & TRACE_BIT))
-            return false;
+  if (enable) {
+    if (rflags & TRACE_BIT)
+      return true;
 
-        rflags &= ~TRACE_BIT;
-    }
+    rflags |= TRACE_BIT;
+  } else {
+    if (!(rflags & TRACE_BIT))
+      return false;
 
-    return WriteRegisterFromUnsigned(m_reg_info.gpr_flags, rflags);
+    rflags &= ~TRACE_BIT;
+  }
+
+  return WriteRegisterFromUnsigned(m_reg_info.gpr_flags, rflags);
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::UpdateAfterBreakpoint()
-{
-    // PC points one byte past the int3 responsible for the breakpoint.
-    lldb::addr_t pc;
+bool RegisterContextPOSIXProcessMonitor_x86_64::UpdateAfterBreakpoint() {
+  // PC points one byte past the int3 responsible for the breakpoint.
+  lldb::addr_t pc;
 
-    if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
-        return false;
+  if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
+    return false;
 
-    SetPC(pc - 1);
-    return true;
+  SetPC(pc - 1);
+  return true;
 }
 
-unsigned
-RegisterContextPOSIXProcessMonitor_x86_64::GetRegisterIndexFromOffset(unsigned offset)
-{
-    unsigned reg;
-    for (reg = 0; reg < m_reg_info.num_registers; reg++)
-    {
-        if (GetRegisterInfo()[reg].byte_offset == offset)
-            break;
-    }
-    assert(reg < m_reg_info.num_registers && "Invalid register offset.");
-    return reg;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::IsWatchpointHit(uint32_t hw_index)
-{
-    bool is_hit = false;
-
-    if (m_watchpoints_initialized == false)
-    {    
-        // Reset the debug status and debug control registers
-        RegisterValue zero_bits = RegisterValue(uint64_t(0));
-        if (!WriteRegister(m_reg_info.first_dr + 6, zero_bits) || !WriteRegister(m_reg_info.first_dr + 7, zero_bits))
-            assert(false && "Could not initialize watchpoint registers");
-        m_watchpoints_initialized = true;
-    }    
-
-    if (hw_index < NumSupportedHardwareWatchpoints())
-    {    
-        RegisterValue value;
-
-        if (ReadRegister(m_reg_info.first_dr + 6, value))
-        {    
-            uint64_t val = value.GetAsUInt64();
-            is_hit = val & (1 << hw_index);
-        }    
-    }    
-
-    return is_hit;
-}
-
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::ClearWatchpointHits()
-{
-    return WriteRegister(m_reg_info.first_dr + 6, RegisterValue((uint64_t)0));
-}
-
-addr_t
-RegisterContextPOSIXProcessMonitor_x86_64::GetWatchpointAddress(uint32_t hw_index)
-{
-    addr_t wp_monitor_addr = LLDB_INVALID_ADDRESS;
-
-    if (hw_index < NumSupportedHardwareWatchpoints())
-    {
-        if (!IsWatchpointVacant(hw_index))
-        {
-            RegisterValue value;
+unsigned RegisterContextPOSIXProcessMonitor_x86_64::GetRegisterIndexFromOffset(
+    unsigned offset) {
+  unsigned reg;
+  for (reg = 0; reg < m_reg_info.num_registers; reg++) {
+    if (GetRegisterInfo()[reg].byte_offset == offset)
+      break;
+  }
+  assert(reg < m_reg_info.num_registers && "Invalid register offset.");
+  return reg;
+}
+
+bool RegisterContextPOSIXProcessMonitor_x86_64::IsWatchpointHit(
+    uint32_t hw_index) {
+  bool is_hit = false;
+
+  if (m_watchpoints_initialized == false) {
+    // Reset the debug status and debug control registers
+    RegisterValue zero_bits = RegisterValue(uint64_t(0));
+    if (!WriteRegister(m_reg_info.first_dr + 6, zero_bits) ||
+        !WriteRegister(m_reg_info.first_dr + 7, zero_bits))
+      assert(false && "Could not initialize watchpoint registers");
+    m_watchpoints_initialized = true;
+  }
 
-            if (ReadRegister(m_reg_info.first_dr + hw_index, value))
-                wp_monitor_addr = value.GetAsUInt64();
-        }
+  if (hw_index < NumSupportedHardwareWatchpoints()) {
+    RegisterValue value;
+
+    if (ReadRegister(m_reg_info.first_dr + 6, value)) {
+      uint64_t val = value.GetAsUInt64();
+      is_hit = val & (1 << hw_index);
     }
+  }
 
-    return wp_monitor_addr;
+  return is_hit;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::IsWatchpointVacant(uint32_t hw_index)
-{
-    bool is_vacant = false;
-    RegisterValue value;
+bool RegisterContextPOSIXProcessMonitor_x86_64::ClearWatchpointHits() {
+  return WriteRegister(m_reg_info.first_dr + 6, RegisterValue((uint64_t)0));
+}
 
-    assert(hw_index < NumSupportedHardwareWatchpoints());
+addr_t RegisterContextPOSIXProcessMonitor_x86_64::GetWatchpointAddress(
+    uint32_t hw_index) {
+  addr_t wp_monitor_addr = LLDB_INVALID_ADDRESS;
 
-    if (m_watchpoints_initialized == false)
-    {
-        // Reset the debug status and debug control registers
-        RegisterValue zero_bits = RegisterValue(uint64_t(0));
-        if (!WriteRegister(m_reg_info.first_dr + 6, zero_bits) || !WriteRegister(m_reg_info.first_dr + 7, zero_bits))
-            assert(false && "Could not initialize watchpoint registers");
-        m_watchpoints_initialized = true;
-    }
+  if (hw_index < NumSupportedHardwareWatchpoints()) {
+    if (!IsWatchpointVacant(hw_index)) {
+      RegisterValue value;
 
-    if (ReadRegister(m_reg_info.first_dr + 7, value))
-    {
-        uint64_t val = value.GetAsUInt64();
-        is_vacant = (val & (3 << 2*hw_index)) == 0;
+      if (ReadRegister(m_reg_info.first_dr + hw_index, value))
+        wp_monitor_addr = value.GetAsUInt64();
     }
+  }
 
-    return is_vacant;
+  return wp_monitor_addr;
 }
 
-bool
-RegisterContextPOSIXProcessMonitor_x86_64::SetHardwareWatchpointWithIndex(addr_t addr, size_t size,
-                                                       bool read, bool write,
-                                                       uint32_t hw_index)
-{
-    const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+bool RegisterContextPOSIXProcessMonitor_x86_64::IsWatchpointVacant(
+    uint32_t hw_index) {
+  bool is_vacant = false;
+  RegisterValue value;
 
-    if (num_hw_watchpoints == 0 || hw_index >= num_hw_watchpoints)
-        return false;
+  assert(hw_index < NumSupportedHardwareWatchpoints());
 
-    if (!(size == 1 || size == 2 || size == 4 || size == 8))
-        return false;
+  if (m_watchpoints_initialized == false) {
+    // Reset the debug status and debug control registers
+    RegisterValue zero_bits = RegisterValue(uint64_t(0));
+    if (!WriteRegister(m_reg_info.first_dr + 6, zero_bits) ||
+        !WriteRegister(m_reg_info.first_dr + 7, zero_bits))
+      assert(false && "Could not initialize watchpoint registers");
+    m_watchpoints_initialized = true;
+  }
 
-    if (read == false && write == false)
-        return false;
+  if (ReadRegister(m_reg_info.first_dr + 7, value)) {
+    uint64_t val = value.GetAsUInt64();
+    is_vacant = (val & (3 << 2 * hw_index)) == 0;
+  }
 
-    if (!IsWatchpointVacant(hw_index))
-        return false;
+  return is_vacant;
+}
 
-    // Set both dr7 (debug control register) and dri (debug address register).
+bool RegisterContextPOSIXProcessMonitor_x86_64::SetHardwareWatchpointWithIndex(
+    addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
+  const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
 
-    // dr7{7-0} encodes the local/global enable bits:
-    //  global enable --. .-- local enable
-    //                  | |
-    //                  v v
-    //      dr0 -> bits{1-0}
-    //      dr1 -> bits{3-2}
-    //      dr2 -> bits{5-4}
-    //      dr3 -> bits{7-6}
-    //
-    // dr7{31-16} encodes the rw/len bits:
-    //  b_x+3, b_x+2, b_x+1, b_x
-    //      where bits{x+1, x} => rw
-    //            0b00: execute, 0b01: write, 0b11: read-or-write,
-    //            0b10: io read-or-write (unused)
-    //      and bits{x+3, x+2} => len
-    //            0b00: 1-byte, 0b01: 2-byte, 0b11: 4-byte, 0b10: 8-byte
-    //
-    //      dr0 -> bits{19-16}
-    //      dr1 -> bits{23-20}
-    //      dr2 -> bits{27-24}
-    //      dr3 -> bits{31-28}
-    if (hw_index < num_hw_watchpoints)
-    {
-        RegisterValue current_dr7_bits;
-
-        if (ReadRegister(m_reg_info.first_dr + 7, current_dr7_bits))
-        {
-            uint64_t new_dr7_bits = current_dr7_bits.GetAsUInt64() |
-                                    (1 << (2*hw_index) |
-                                    size_and_rw_bits(size, read, write) <<
-                                    (16+4*hw_index));
-
-            if (WriteRegister(m_reg_info.first_dr + hw_index, RegisterValue(addr)) &&
-                WriteRegister(m_reg_info.first_dr + 7, RegisterValue(new_dr7_bits)))
-                return true;
-        }
-    }
+  if (num_hw_watchpoints == 0 || hw_index >= num_hw_watchpoints)
+    return false;
+
+  if (!(size == 1 || size == 2 || size == 4 || size == 8))
+    return false;
+
+  if (read == false && write == false)
+    return false;
 
+  if (!IsWatchpointVacant(hw_index))
     return false;
+
+  // Set both dr7 (debug control register) and dri (debug address register).
+
+  // dr7{7-0} encodes the local/global enable bits:
+  //  global enable --. .-- local enable
+  //                  | |
+  //                  v v
+  //      dr0 -> bits{1-0}
+  //      dr1 -> bits{3-2}
+  //      dr2 -> bits{5-4}
+  //      dr3 -> bits{7-6}
+  //
+  // dr7{31-16} encodes the rw/len bits:
+  //  b_x+3, b_x+2, b_x+1, b_x
+  //      where bits{x+1, x} => rw
+  //            0b00: execute, 0b01: write, 0b11: read-or-write,
+  //            0b10: io read-or-write (unused)
+  //      and bits{x+3, x+2} => len
+  //            0b00: 1-byte, 0b01: 2-byte, 0b11: 4-byte, 0b10: 8-byte
+  //
+  //      dr0 -> bits{19-16}
+  //      dr1 -> bits{23-20}
+  //      dr2 -> bits{27-24}
+  //      dr3 -> bits{31-28}
+  if (hw_index < num_hw_watchpoints) {
+    RegisterValue current_dr7_bits;
+
+    if (ReadRegister(m_reg_info.first_dr + 7, current_dr7_bits)) {
+      uint64_t new_dr7_bits =
+          current_dr7_bits.GetAsUInt64() |
+          (1 << (2 * hw_index) |
+           size_and_rw_bits(size, read, write) << (16 + 4 * hw_index));
+
+      if (WriteRegister(m_reg_info.first_dr + hw_index, RegisterValue(addr)) &&
+          WriteRegister(m_reg_info.first_dr + 7, RegisterValue(new_dr7_bits)))
+        return true;
+    }
+  }
+
+  return false;
 }
 
 uint32_t
-RegisterContextPOSIXProcessMonitor_x86_64::NumSupportedHardwareWatchpoints()
-{
-    // Available debug address registers: dr0, dr1, dr2, dr3
-    return 4;
+RegisterContextPOSIXProcessMonitor_x86_64::NumSupportedHardwareWatchpoints() {
+  // Available debug address registers: dr0, dr1, dr2, dr3
+  return 4;
 }
-

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h Tue Sep  6 15:57:50 2016
@@ -10,88 +10,71 @@
 #ifndef liblldb_RegisterContextPOSIXProcessMonitor_x86_H_
 #define liblldb_RegisterContextPOSIXProcessMonitor_x86_H_
 
-#include "RegisterContextPOSIX.h"
 #include "Plugins/Process/Utility/RegisterContextPOSIX_x86.h"
+#include "RegisterContextPOSIX.h"
 
-class RegisterContextPOSIXProcessMonitor_x86_64:
-    public RegisterContextPOSIX_x86,
-    public POSIXBreakpointProtocol
-{
+class RegisterContextPOSIXProcessMonitor_x86_64
+    : public RegisterContextPOSIX_x86,
+      public POSIXBreakpointProtocol {
 public:
-    RegisterContextPOSIXProcessMonitor_x86_64(lldb_private::Thread &thread,
-                                              uint32_t concrete_frame_idx,
-                                              lldb_private::RegisterInfoInterface *register_info);
+  RegisterContextPOSIXProcessMonitor_x86_64(
+      lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+      lldb_private::RegisterInfoInterface *register_info);
 
 protected:
-    bool
-    ReadGPR();
+  bool ReadGPR();
 
-    bool
-    ReadFPR();
+  bool ReadFPR();
 
-    bool
-    WriteGPR();
+  bool WriteGPR();
 
-    bool
-    WriteFPR();
+  bool WriteFPR();
 
-    // lldb_private::RegisterContext
-    bool
-    ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
+  // lldb_private::RegisterContext
+  bool ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const unsigned reg, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const unsigned reg,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
+  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
+                    lldb_private::RegisterValue &value);
 
-    bool
-    WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
+  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
+                     const lldb_private::RegisterValue &value);
 
-    bool
-    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
+  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
 
-    bool
-    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
+  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
 
-    uint32_t
-    SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write);
+  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
+                                 bool write);
 
-    bool
-    ClearHardwareWatchpoint(uint32_t hw_index);
+  bool ClearHardwareWatchpoint(uint32_t hw_index);
 
-    bool
-    HardwareSingleStep(bool enable);
+  bool HardwareSingleStep(bool enable);
 
-    // POSIXBreakpointProtocol
-    bool
-    UpdateAfterBreakpoint();
+  // POSIXBreakpointProtocol
+  bool UpdateAfterBreakpoint();
 
-    unsigned
-    GetRegisterIndexFromOffset(unsigned offset);
+  unsigned GetRegisterIndexFromOffset(unsigned offset);
 
-    bool
-    IsWatchpointHit(uint32_t hw_index);
+  bool IsWatchpointHit(uint32_t hw_index);
 
-    bool
-    ClearWatchpointHits();
+  bool ClearWatchpointHits();
 
-    lldb::addr_t
-    GetWatchpointAddress(uint32_t hw_index);
+  lldb::addr_t GetWatchpointAddress(uint32_t hw_index);
 
-    bool
-    IsWatchpointVacant(uint32_t hw_index);
+  bool IsWatchpointVacant(uint32_t hw_index);
 
-    bool
-    SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read, bool write, uint32_t hw_index);
+  bool SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, bool read,
+                                      bool write, uint32_t hw_index);
 
-    uint32_t
-    NumSupportedHardwareWatchpoints();
+  uint32_t NumSupportedHardwareWatchpoints();
 
 private:
-    ProcessMonitor &
-    GetMonitor();
-    uint32_t m_fctrl_offset_in_userarea;  // Offset of 'fctrl' in 'UserArea' Structure
+  ProcessMonitor &GetMonitor();
+  uint32_t
+      m_fctrl_offset_in_userarea; // Offset of 'fctrl' in 'UserArea' Structure
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Tue Sep  6 15:57:50 2016
@@ -11,8 +11,8 @@
 
 // C Includes
 #include <errno.h>
-#include <string.h>
 #include <stdint.h>
+#include <string.h>
 #include <unistd.h>
 
 // C++ Includes
@@ -42,12 +42,13 @@
 #include "lldb/Utility/PseudoTerminal.h"
 #include "lldb/Utility/StringExtractor.h"
 
-#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
 #include "NativeThreadLinux.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
 #include "ProcFileReader.h"
 #include "Procfs.h"
 
-// System includes - They have to be included after framework includes because they define some
+// System includes - They have to be included after framework includes because
+// they define some
 // macros which collide with variable names in other modules
 #include <linux/unistd.h>
 #include <sys/socket.h>
@@ -63,7 +64,7 @@
 
 // Support hardware breakpoints in case it has not been defined
 #ifndef TRAP_HWBKPT
-  #define TRAP_HWBKPT 4
+#define TRAP_HWBKPT 4
 #endif
 
 using namespace lldb;
@@ -73,1911 +74,1907 @@ using namespace llvm;
 
 // Private bits we only need internally.
 
-static bool ProcessVmReadvSupported()
-{
-    static bool is_supported;
-    static std::once_flag flag;
-
-    std::call_once(flag, [] {
-        Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-        uint32_t source = 0x47424742;
-        uint32_t dest = 0;
-
-        struct iovec local, remote;
-        remote.iov_base = &source;
-        local.iov_base = &dest;
-        remote.iov_len = local.iov_len = sizeof source;
-
-        // We shall try if cross-process-memory reads work by attempting to read a value from our own process.
-        ssize_t res = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
-        is_supported = (res == sizeof(source) && source == dest);
-        if (log)
-        {
-            if (is_supported)
-                log->Printf("%s: Detected kernel support for process_vm_readv syscall. Fast memory reads enabled.",
-                        __FUNCTION__);
-            else
-                log->Printf("%s: syscall process_vm_readv failed (error: %s). Fast memory reads disabled.",
-                        __FUNCTION__, strerror(errno));
-        }
-    });
-
-    return is_supported;
-}
+static bool ProcessVmReadvSupported() {
+  static bool is_supported;
+  static std::once_flag flag;
 
-namespace
-{
-void
-MaybeLogLaunchInfo(const ProcessLaunchInfo &info)
-{
+  std::call_once(flag, [] {
     Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-    if (!log)
-        return;
 
-    if (const FileAction *action = info.GetFileActionForFD(STDIN_FILENO))
-        log->Printf("%s: setting STDIN to '%s'", __FUNCTION__, action->GetFileSpec().GetCString());
-    else
-        log->Printf("%s leaving STDIN as is", __FUNCTION__);
+    uint32_t source = 0x47424742;
+    uint32_t dest = 0;
 
-    if (const FileAction *action = info.GetFileActionForFD(STDOUT_FILENO))
-        log->Printf("%s setting STDOUT to '%s'", __FUNCTION__, action->GetFileSpec().GetCString());
-    else
-        log->Printf("%s leaving STDOUT as is", __FUNCTION__);
-
-    if (const FileAction *action = info.GetFileActionForFD(STDERR_FILENO))
-        log->Printf("%s setting STDERR to '%s'", __FUNCTION__, action->GetFileSpec().GetCString());
-    else
-        log->Printf("%s leaving STDERR as is", __FUNCTION__);
-
-    int i = 0;
-    for (const char **args = info.GetArguments().GetConstArgumentVector(); *args; ++args, ++i)
-        log->Printf("%s arg %d: \"%s\"", __FUNCTION__, i, *args ? *args : "nullptr");
-}
-
-void
-DisplayBytes(StreamString &s, void *bytes, uint32_t count)
-{
-    uint8_t *ptr = (uint8_t *)bytes;
-    const uint32_t loop_count = std::min<uint32_t>(DEBUG_PTRACE_MAXBYTES, count);
-    for (uint32_t i = 0; i < loop_count; i++)
-    {
-        s.Printf("[%x]", *ptr);
-        ptr++;
+    struct iovec local, remote;
+    remote.iov_base = &source;
+    local.iov_base = &dest;
+    remote.iov_len = local.iov_len = sizeof source;
+
+    // We shall try if cross-process-memory reads work by attempting to read a
+    // value from our own process.
+    ssize_t res = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
+    is_supported = (res == sizeof(source) && source == dest);
+    if (log) {
+      if (is_supported)
+        log->Printf("%s: Detected kernel support for process_vm_readv syscall. "
+                    "Fast memory reads enabled.",
+                    __FUNCTION__);
+      else
+        log->Printf("%s: syscall process_vm_readv failed (error: %s). Fast "
+                    "memory reads disabled.",
+                    __FUNCTION__, strerror(errno));
     }
-}
+  });
 
-    void
-    PtraceDisplayBytes(int &req, void *data, size_t data_size)
-    {
-        StreamString buf;
-        Log *verbose_log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (
-                    POSIX_LOG_PTRACE | POSIX_LOG_VERBOSE));
-
-        if (verbose_log)
-        {
-            switch(req)
-            {
-            case PTRACE_POKETEXT:
-            {
-                DisplayBytes(buf, &data, 8);
-                verbose_log->Printf("PTRACE_POKETEXT %s", buf.GetData());
-                break;
-            }
-            case PTRACE_POKEDATA:
-            {
-                DisplayBytes(buf, &data, 8);
-                verbose_log->Printf("PTRACE_POKEDATA %s", buf.GetData());
-                break;
-            }
-            case PTRACE_POKEUSER:
-            {
-                DisplayBytes(buf, &data, 8);
-                verbose_log->Printf("PTRACE_POKEUSER %s", buf.GetData());
-                break;
-            }
-            case PTRACE_SETREGS:
-            {
-                DisplayBytes(buf, data, data_size);
-                verbose_log->Printf("PTRACE_SETREGS %s", buf.GetData());
-                break;
-            }
-            case PTRACE_SETFPREGS:
-            {
-                DisplayBytes(buf, data, data_size);
-                verbose_log->Printf("PTRACE_SETFPREGS %s", buf.GetData());
-                break;
-            }
-            case PTRACE_SETSIGINFO:
-            {
-                DisplayBytes(buf, data, sizeof(siginfo_t));
-                verbose_log->Printf("PTRACE_SETSIGINFO %s", buf.GetData());
-                break;
-            }
-            case PTRACE_SETREGSET:
-            {
-                // Extract iov_base from data, which is a pointer to the struct IOVEC
-                DisplayBytes(buf, *(void **)data, data_size);
-                verbose_log->Printf("PTRACE_SETREGSET %s", buf.GetData());
-                break;
-            }
-            default:
-            {
-            }
-            }
-        }
-    }
+  return is_supported;
+}
 
-    static constexpr unsigned k_ptrace_word_size = sizeof(void*);
-    static_assert(sizeof(long) >= k_ptrace_word_size, "Size of long must be larger than ptrace word size");
+namespace {
+void MaybeLogLaunchInfo(const ProcessLaunchInfo &info) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (!log)
+    return;
+
+  if (const FileAction *action = info.GetFileActionForFD(STDIN_FILENO))
+    log->Printf("%s: setting STDIN to '%s'", __FUNCTION__,
+                action->GetFileSpec().GetCString());
+  else
+    log->Printf("%s leaving STDIN as is", __FUNCTION__);
+
+  if (const FileAction *action = info.GetFileActionForFD(STDOUT_FILENO))
+    log->Printf("%s setting STDOUT to '%s'", __FUNCTION__,
+                action->GetFileSpec().GetCString());
+  else
+    log->Printf("%s leaving STDOUT as is", __FUNCTION__);
+
+  if (const FileAction *action = info.GetFileActionForFD(STDERR_FILENO))
+    log->Printf("%s setting STDERR to '%s'", __FUNCTION__,
+                action->GetFileSpec().GetCString());
+  else
+    log->Printf("%s leaving STDERR as is", __FUNCTION__);
+
+  int i = 0;
+  for (const char **args = info.GetArguments().GetConstArgumentVector(); *args;
+       ++args, ++i)
+    log->Printf("%s arg %d: \"%s\"", __FUNCTION__, i,
+                *args ? *args : "nullptr");
+}
+
+void DisplayBytes(StreamString &s, void *bytes, uint32_t count) {
+  uint8_t *ptr = (uint8_t *)bytes;
+  const uint32_t loop_count = std::min<uint32_t>(DEBUG_PTRACE_MAXBYTES, count);
+  for (uint32_t i = 0; i < loop_count; i++) {
+    s.Printf("[%x]", *ptr);
+    ptr++;
+  }
+}
+
+void PtraceDisplayBytes(int &req, void *data, size_t data_size) {
+  StreamString buf;
+  Log *verbose_log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(
+      POSIX_LOG_PTRACE | POSIX_LOG_VERBOSE));
+
+  if (verbose_log) {
+    switch (req) {
+    case PTRACE_POKETEXT: {
+      DisplayBytes(buf, &data, 8);
+      verbose_log->Printf("PTRACE_POKETEXT %s", buf.GetData());
+      break;
+    }
+    case PTRACE_POKEDATA: {
+      DisplayBytes(buf, &data, 8);
+      verbose_log->Printf("PTRACE_POKEDATA %s", buf.GetData());
+      break;
+    }
+    case PTRACE_POKEUSER: {
+      DisplayBytes(buf, &data, 8);
+      verbose_log->Printf("PTRACE_POKEUSER %s", buf.GetData());
+      break;
+    }
+    case PTRACE_SETREGS: {
+      DisplayBytes(buf, data, data_size);
+      verbose_log->Printf("PTRACE_SETREGS %s", buf.GetData());
+      break;
+    }
+    case PTRACE_SETFPREGS: {
+      DisplayBytes(buf, data, data_size);
+      verbose_log->Printf("PTRACE_SETFPREGS %s", buf.GetData());
+      break;
+    }
+    case PTRACE_SETSIGINFO: {
+      DisplayBytes(buf, data, sizeof(siginfo_t));
+      verbose_log->Printf("PTRACE_SETSIGINFO %s", buf.GetData());
+      break;
+    }
+    case PTRACE_SETREGSET: {
+      // Extract iov_base from data, which is a pointer to the struct IOVEC
+      DisplayBytes(buf, *(void **)data, data_size);
+      verbose_log->Printf("PTRACE_SETREGSET %s", buf.GetData());
+      break;
+    }
+    default: {}
+    }
+  }
+}
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+              "Size of long must be larger than ptrace word size");
 } // end of anonymous namespace
 
 // Simple helper function to ensure flags are enabled on the given file
 // descriptor.
-static Error
-EnsureFDFlags(int fd, int flags)
-{
-    Error error;
+static Error EnsureFDFlags(int fd, int flags) {
+  Error error;
 
-    int status = fcntl(fd, F_GETFL);
-    if (status == -1)
-    {
-        error.SetErrorToErrno();
-        return error;
-    }
-
-    if (fcntl(fd, F_SETFL, status | flags) == -1)
-    {
-        error.SetErrorToErrno();
-        return error;
-    }
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1) {
+    error.SetErrorToErrno();
+    return error;
+  }
 
+  if (fcntl(fd, F_SETFL, status | flags) == -1) {
+    error.SetErrorToErrno();
     return error;
+  }
+
+  return error;
 }
 
 // -----------------------------------------------------------------------------
 // Public Static Methods
 // -----------------------------------------------------------------------------
 
-Error
-NativeProcessProtocol::Launch (
+Error NativeProcessProtocol::Launch(
     ProcessLaunchInfo &launch_info,
-    NativeProcessProtocol::NativeDelegate &native_delegate,
-    MainLoop &mainloop,
-    NativeProcessProtocolSP &native_process_sp)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-    Error error;
-
-    // Verify the working directory is valid if one was specified.
-    FileSpec working_dir{launch_info.GetWorkingDirectory()};
-    if (working_dir &&
-            (!working_dir.ResolvePath() ||
-             working_dir.GetFileType() != FileSpec::eFileTypeDirectory))
-    {
-        error.SetErrorStringWithFormat ("No such file or directory: %s",
-                working_dir.GetCString());
-        return error;
-    }
+    NativeProcessProtocol::NativeDelegate &native_delegate, MainLoop &mainloop,
+    NativeProcessProtocolSP &native_process_sp) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  Error error;
+
+  // Verify the working directory is valid if one was specified.
+  FileSpec working_dir{launch_info.GetWorkingDirectory()};
+  if (working_dir &&
+      (!working_dir.ResolvePath() ||
+       working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) {
+    error.SetErrorStringWithFormat("No such file or directory: %s",
+                                   working_dir.GetCString());
+    return error;
+  }
 
-    // Create the NativeProcessLinux in launch mode.
-    native_process_sp.reset (new NativeProcessLinux ());
+  // Create the NativeProcessLinux in launch mode.
+  native_process_sp.reset(new NativeProcessLinux());
 
-    if (!native_process_sp->RegisterNativeDelegate (native_delegate))
-    {
-        native_process_sp.reset ();
-        error.SetErrorStringWithFormat ("failed to register the native delegate");
-        return error;
-    }
+  if (!native_process_sp->RegisterNativeDelegate(native_delegate)) {
+    native_process_sp.reset();
+    error.SetErrorStringWithFormat("failed to register the native delegate");
+    return error;
+  }
 
-    error = std::static_pointer_cast<NativeProcessLinux>(native_process_sp)->LaunchInferior(mainloop, launch_info);
+  error = std::static_pointer_cast<NativeProcessLinux>(native_process_sp)
+              ->LaunchInferior(mainloop, launch_info);
 
-    if (error.Fail ())
-    {
-        native_process_sp.reset ();
-        if (log)
-            log->Printf ("NativeProcessLinux::%s failed to launch process: %s", __FUNCTION__, error.AsCString ());
-        return error;
-    }
+  if (error.Fail()) {
+    native_process_sp.reset();
+    if (log)
+      log->Printf("NativeProcessLinux::%s failed to launch process: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  }
 
-    launch_info.SetProcessID (native_process_sp->GetID ());
+  launch_info.SetProcessID(native_process_sp->GetID());
 
-    return error;
+  return error;
 }
 
-Error
-NativeProcessProtocol::Attach (
-    lldb::pid_t pid,
-    NativeProcessProtocol::NativeDelegate &native_delegate,
-    MainLoop &mainloop,
-    NativeProcessProtocolSP &native_process_sp)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-    if (log && log->GetMask ().Test (POSIX_LOG_VERBOSE))
-        log->Printf ("NativeProcessLinux::%s(pid = %" PRIi64 ")", __FUNCTION__, pid);
-
-    // Retrieve the architecture for the running process.
-    ArchSpec process_arch;
-    Error error = ResolveProcessArchitecture(pid, process_arch);
-    if (!error.Success ())
-        return error;
+Error NativeProcessProtocol::Attach(
+    lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
+    MainLoop &mainloop, NativeProcessProtocolSP &native_process_sp) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
+    log->Printf("NativeProcessLinux::%s(pid = %" PRIi64 ")", __FUNCTION__, pid);
 
-    std::shared_ptr<NativeProcessLinux> native_process_linux_sp (new NativeProcessLinux ());
+  // Retrieve the architecture for the running process.
+  ArchSpec process_arch;
+  Error error = ResolveProcessArchitecture(pid, process_arch);
+  if (!error.Success())
+    return error;
 
-    if (!native_process_linux_sp->RegisterNativeDelegate (native_delegate))
-    {
-        error.SetErrorStringWithFormat ("failed to register the native delegate");
-        return error;
-    }
+  std::shared_ptr<NativeProcessLinux> native_process_linux_sp(
+      new NativeProcessLinux());
 
-    native_process_linux_sp->AttachToInferior (mainloop, pid, error);
-    if (!error.Success ())
-        return error;
+  if (!native_process_linux_sp->RegisterNativeDelegate(native_delegate)) {
+    error.SetErrorStringWithFormat("failed to register the native delegate");
+    return error;
+  }
 
-    native_process_sp = native_process_linux_sp;
+  native_process_linux_sp->AttachToInferior(mainloop, pid, error);
+  if (!error.Success())
     return error;
+
+  native_process_sp = native_process_linux_sp;
+  return error;
 }
 
 // -----------------------------------------------------------------------------
 // Public Instance Methods
 // -----------------------------------------------------------------------------
 
-NativeProcessLinux::NativeProcessLinux () :
-    NativeProcessProtocol (LLDB_INVALID_PROCESS_ID),
-    m_arch (),
-    m_supports_mem_region (eLazyBoolCalculate),
-    m_mem_region_cache (),
-    m_pending_notification_tid(LLDB_INVALID_THREAD_ID)
-{
-}
-
-void
-NativeProcessLinux::AttachToInferior (MainLoop &mainloop, lldb::pid_t pid, Error &error)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-    if (log)
-        log->Printf ("NativeProcessLinux::%s (pid = %" PRIi64 ")", __FUNCTION__, pid);
-
-    m_sigchld_handle = mainloop.RegisterSignal(SIGCHLD,
-            [this] (MainLoopBase &) { SigchldHandler(); }, error);
-    if (! m_sigchld_handle)
-        return;
-
-    error = ResolveProcessArchitecture(pid, m_arch);
-    if (!error.Success())
-        return;
-
-    // Set the architecture to the exe architecture.
-    if (log)
-        log->Printf ("NativeProcessLinux::%s (pid = %" PRIi64 ") detected architecture %s", __FUNCTION__, pid, m_arch.GetArchitectureName ());
-
-    m_pid = pid;
-    SetState(eStateAttaching);
-
-    Attach(pid, error);
-}
-
-Error
-NativeProcessLinux::LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info)
-{
-    Error error;
-    m_sigchld_handle = mainloop.RegisterSignal(SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, error);
-    if (!m_sigchld_handle)
-        return error;
-
-    SetState(eStateLaunching);
-
-    MaybeLogLaunchInfo(launch_info);
-
-    ::pid_t pid = ProcessLauncherLinux().LaunchProcess(launch_info, error).GetProcessId();
-    if (error.Fail())
-        return error;
-
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-    // Wait for the child process to trap on its call to execve.
-    ::pid_t wpid;
-    int status;
-    if ((wpid = waitpid(pid, &status, 0)) < 0)
-    {
-        error.SetErrorToErrno();
-        if (log)
-            log->Printf ("NativeProcessLinux::%s waitpid for inferior failed with %s",
-                    __FUNCTION__, error.AsCString ());
-
-        // Mark the inferior as invalid.
-        // FIXME this could really use a new state - eStateLaunchFailure.  For now, using eStateInvalid.
-        SetState (StateType::eStateInvalid);
-
-        return error;
-    }
-    assert(WIFSTOPPED(status) && (wpid == static_cast< ::pid_t> (pid)) &&
-           "Could not sync with inferior process.");
-
-    if (log)
-        log->Printf ("NativeProcessLinux::%s inferior started, now in stopped state", __FUNCTION__);
-
-    error = SetDefaultPtraceOpts(pid);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s inferior failed to set default ptrace options: %s",
-                    __FUNCTION__, error.AsCString ());
-
-        // Mark the inferior as invalid.
-        // FIXME this could really use a new state - eStateLaunchFailure.  For now, using eStateInvalid.
-        SetState (StateType::eStateInvalid);
-
-        return error;
-    }
-
-    // Release the master terminal descriptor and pass it off to the
-    // NativeProcessLinux instance.  Similarly stash the inferior pid.
-    m_terminal_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
-    m_pid = pid;
-    launch_info.SetProcessID(pid);
-
-    if (m_terminal_fd != -1)
-    {
-        error = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
-        if (error.Fail())
-        {
-            if (log)
-                log->Printf(
-                    "NativeProcessLinux::%s inferior EnsureFDFlags failed for ensuring terminal O_NONBLOCK setting: %s",
-                    __FUNCTION__, error.AsCString());
-
-            // Mark the inferior as invalid.
-            // FIXME this could really use a new state - eStateLaunchFailure.  For now, using eStateInvalid.
-            SetState(StateType::eStateInvalid);
-
-            return error;
-        }
-    }
-
-    if (log)
-        log->Printf("NativeProcessLinux::%s() adding pid = %" PRIu64, __FUNCTION__, uint64_t(pid));
-
-    ResolveProcessArchitecture(m_pid, m_arch);
-    NativeThreadLinuxSP thread_sp = AddThread(pid);
-    assert (thread_sp && "AddThread() returned a nullptr thread");
-    thread_sp->SetStoppedBySignal(SIGSTOP);
-    ThreadWasCreated(*thread_sp);
-
-    // Let our process instance know the thread has stopped.
-    SetCurrentThreadID (thread_sp->GetID ());
-    SetState (StateType::eStateStopped);
-
-    if (log)
-    {
-        if (error.Success ())
-            log->Printf("NativeProcessLinux::%s inferior launching succeeded", __FUNCTION__);
-        else
-            log->Printf("NativeProcessLinux::%s inferior launching failed: %s", __FUNCTION__, error.AsCString());
-    }
+NativeProcessLinux::NativeProcessLinux()
+    : NativeProcessProtocol(LLDB_INVALID_PROCESS_ID), m_arch(),
+      m_supports_mem_region(eLazyBoolCalculate), m_mem_region_cache(),
+      m_pending_notification_tid(LLDB_INVALID_THREAD_ID) {}
+
+void NativeProcessLinux::AttachToInferior(MainLoop &mainloop, lldb::pid_t pid,
+                                          Error &error) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf("NativeProcessLinux::%s (pid = %" PRIi64 ")", __FUNCTION__,
+                pid);
+
+  m_sigchld_handle = mainloop.RegisterSignal(
+      SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, error);
+  if (!m_sigchld_handle)
+    return;
+
+  error = ResolveProcessArchitecture(pid, m_arch);
+  if (!error.Success())
+    return;
+
+  // Set the architecture to the exe architecture.
+  if (log)
+    log->Printf("NativeProcessLinux::%s (pid = %" PRIi64
+                ") detected architecture %s",
+                __FUNCTION__, pid, m_arch.GetArchitectureName());
+
+  m_pid = pid;
+  SetState(eStateAttaching);
+
+  Attach(pid, error);
+}
+
+Error NativeProcessLinux::LaunchInferior(MainLoop &mainloop,
+                                         ProcessLaunchInfo &launch_info) {
+  Error error;
+  m_sigchld_handle = mainloop.RegisterSignal(
+      SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, error);
+  if (!m_sigchld_handle)
     return error;
-}
-
-::pid_t
-NativeProcessLinux::Attach(lldb::pid_t pid, Error &error)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-    // Use a map to keep track of the threads which we have attached/need to attach.
-    Host::TidMap tids_to_attach;
-    if (pid <= 1)
-    {
-        error.SetErrorToGenericError();
-        error.SetErrorString("Attaching to process 1 is not allowed.");
-        return -1;
-    }
 
-    while (Host::FindProcessThreads(pid, tids_to_attach))
-    {
-        for (Host::TidMap::iterator it = tids_to_attach.begin();
-             it != tids_to_attach.end();)
-        {
-            if (it->second == false)
-            {
-                lldb::tid_t tid = it->first;
-
-                // Attach to the requested process.
-                // An attach will cause the thread to stop with a SIGSTOP.
-                error = PtraceWrapper(PTRACE_ATTACH, tid);
-                if (error.Fail())
-                {
-                    // No such thread. The thread may have exited.
-                    // More error handling may be needed.
-                    if (error.GetError() == ESRCH)
-                    {
-                        it = tids_to_attach.erase(it);
-                        continue;
-                    }
-                    else
-                        return -1;
-                }
-
-                int status;
-                // Need to use __WALL otherwise we receive an error with errno=ECHLD
-                // At this point we should have a thread stopped if waitpid succeeds.
-                if ((status = waitpid(tid, NULL, __WALL)) < 0)
-                {
-                    // No such thread. The thread may have exited.
-                    // More error handling may be needed.
-                    if (errno == ESRCH)
-                    {
-                        it = tids_to_attach.erase(it);
-                        continue;
-                    }
-                    else
-                    {
-                        error.SetErrorToErrno();
-                        return -1;
-                    }
-                }
-
-                error = SetDefaultPtraceOpts(tid);
-                if (error.Fail())
-                    return -1;
-
-                if (log)
-                    log->Printf ("NativeProcessLinux::%s() adding tid = %" PRIu64, __FUNCTION__, tid);
-
-                it->second = true;
-
-                // Create the thread, mark it as stopped.
-                NativeThreadLinuxSP thread_sp (AddThread(static_cast<lldb::tid_t>(tid)));
-                assert (thread_sp && "AddThread() returned a nullptr");
-
-                // This will notify this is a new thread and tell the system it is stopped.
-                thread_sp->SetStoppedBySignal(SIGSTOP);
-                ThreadWasCreated(*thread_sp);
-                SetCurrentThreadID (thread_sp->GetID ());
-            }
+  SetState(eStateLaunching);
 
-            // move the loop forward
-            ++it;
-        }
-    }
+  MaybeLogLaunchInfo(launch_info);
 
-    if (tids_to_attach.size() > 0)
-    {
-        m_pid = pid;
-        // Let our process instance know the thread has stopped.
-        SetState (StateType::eStateStopped);
-    }
-    else
-    {
-        error.SetErrorToGenericError();
-        error.SetErrorString("No such process.");
-        return -1;
-    }
-
-    return pid;
-}
+  ::pid_t pid =
+      ProcessLauncherLinux().LaunchProcess(launch_info, error).GetProcessId();
+  if (error.Fail())
+    return error;
 
-Error
-NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid)
-{
-    long ptrace_opts = 0;
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-    // Have the child raise an event on exit.  This is used to keep the child in
-    // limbo until it is destroyed.
-    ptrace_opts |= PTRACE_O_TRACEEXIT;
+  // Wait for the child process to trap on its call to execve.
+  ::pid_t wpid;
+  int status;
+  if ((wpid = waitpid(pid, &status, 0)) < 0) {
+    error.SetErrorToErrno();
+    if (log)
+      log->Printf("NativeProcessLinux::%s waitpid for inferior failed with %s",
+                  __FUNCTION__, error.AsCString());
+
+    // Mark the inferior as invalid.
+    // FIXME this could really use a new state - eStateLaunchFailure.  For now,
+    // using eStateInvalid.
+    SetState(StateType::eStateInvalid);
 
-    // Have the tracer trace threads which spawn in the inferior process.
-    // TODO: if we want to support tracing the inferiors' child, add the
-    // appropriate ptrace flags here (PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK)
-    ptrace_opts |= PTRACE_O_TRACECLONE;
+    return error;
+  }
+  assert(WIFSTOPPED(status) && (wpid == static_cast<::pid_t>(pid)) &&
+         "Could not sync with inferior process.");
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s inferior started, now in stopped state",
+                __FUNCTION__);
+
+  error = SetDefaultPtraceOpts(pid);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessLinux::%s inferior failed to set default "
+                  "ptrace options: %s",
+                  __FUNCTION__, error.AsCString());
+
+    // Mark the inferior as invalid.
+    // FIXME this could really use a new state - eStateLaunchFailure.  For now,
+    // using eStateInvalid.
+    SetState(StateType::eStateInvalid);
 
-    // Have the tracer notify us before execve returns
-    // (needed to disable legacy SIGTRAP generation)
-    ptrace_opts |= PTRACE_O_TRACEEXEC;
+    return error;
+  }
 
-    return PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void*)ptrace_opts);
-}
+  // Release the master terminal descriptor and pass it off to the
+  // NativeProcessLinux instance.  Similarly stash the inferior pid.
+  m_terminal_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
+  m_pid = pid;
+  launch_info.SetProcessID(pid);
+
+  if (m_terminal_fd != -1) {
+    error = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
+    if (error.Fail()) {
+      if (log)
+        log->Printf("NativeProcessLinux::%s inferior EnsureFDFlags failed for "
+                    "ensuring terminal O_NONBLOCK setting: %s",
+                    __FUNCTION__, error.AsCString());
 
-static ExitType convert_pid_status_to_exit_type (int status)
-{
-    if (WIFEXITED (status))
-        return ExitType::eExitTypeExit;
-    else if (WIFSIGNALED (status))
-        return ExitType::eExitTypeSignal;
-    else if (WIFSTOPPED (status))
-        return ExitType::eExitTypeStop;
-    else
-    {
-        // We don't know what this is.
-        return ExitType::eExitTypeInvalid;
-    }
-}
+      // Mark the inferior as invalid.
+      // FIXME this could really use a new state - eStateLaunchFailure.  For
+      // now, using eStateInvalid.
+      SetState(StateType::eStateInvalid);
+
+      return error;
+    }
+  }
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s() adding pid = %" PRIu64, __FUNCTION__,
+                uint64_t(pid));
+
+  ResolveProcessArchitecture(m_pid, m_arch);
+  NativeThreadLinuxSP thread_sp = AddThread(pid);
+  assert(thread_sp && "AddThread() returned a nullptr thread");
+  thread_sp->SetStoppedBySignal(SIGSTOP);
+  ThreadWasCreated(*thread_sp);
+
+  // Let our process instance know the thread has stopped.
+  SetCurrentThreadID(thread_sp->GetID());
+  SetState(StateType::eStateStopped);
 
-static int convert_pid_status_to_return_code (int status)
-{
-    if (WIFEXITED (status))
-        return WEXITSTATUS (status);
-    else if (WIFSIGNALED (status))
-        return WTERMSIG (status);
-    else if (WIFSTOPPED (status))
-        return WSTOPSIG (status);
+  if (log) {
+    if (error.Success())
+      log->Printf("NativeProcessLinux::%s inferior launching succeeded",
+                  __FUNCTION__);
     else
-    {
-        // We don't know what this is.
-        return ExitType::eExitTypeInvalid;
-    }
-}
-
-// Handles all waitpid events from the inferior process.
-void
-NativeProcessLinux::MonitorCallback(lldb::pid_t pid,
-                                    bool exited,
-                                    int signal,
-                                    int status)
-{
-    Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-    // Certain activities differ based on whether the pid is the tid of the main thread.
-    const bool is_main_thread = (pid == GetID ());
-
-    // Handle when the thread exits.
-    if (exited)
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() got exit signal(%d) , tid = %"  PRIu64 " (%s main thread)", __FUNCTION__, signal, pid, is_main_thread ? "is" : "is not");
-
-        // This is a thread that exited.  Ensure we're not tracking it anymore.
-        const bool thread_found = StopTrackingThread (pid);
-
-        if (is_main_thread)
-        {
-            // We only set the exit status and notify the delegate if we haven't already set the process
-            // state to an exited state.  We normally should have received a SIGTRAP | (PTRACE_EVENT_EXIT << 8)
-            // for the main thread.
-            const bool already_notified = (GetState() == StateType::eStateExited) || (GetState () == StateType::eStateCrashed);
-            if (!already_notified)
-            {
-                if (log)
-                    log->Printf ("NativeProcessLinux::%s() tid = %"  PRIu64 " handling main thread exit (%s), expected exit state already set but state was %s instead, setting exit state now", __FUNCTION__, pid, thread_found ? "stopped tracking thread metadata" : "thread metadata not found", StateAsCString (GetState ()));
-                // The main thread exited.  We're done monitoring.  Report to delegate.
-                SetExitStatus (convert_pid_status_to_exit_type (status), convert_pid_status_to_return_code (status), nullptr, true);
-
-                // Notify delegate that our process has exited.
-                SetState (StateType::eStateExited, true);
-            }
-            else
-            {
-                if (log)
-                    log->Printf ("NativeProcessLinux::%s() tid = %"  PRIu64 " main thread now exited (%s)", __FUNCTION__, pid, thread_found ? "stopped tracking thread metadata" : "thread metadata not found");
-            }
+      log->Printf("NativeProcessLinux::%s inferior launching failed: %s",
+                  __FUNCTION__, error.AsCString());
+  }
+  return error;
+}
+
+::pid_t NativeProcessLinux::Attach(lldb::pid_t pid, Error &error) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  // Use a map to keep track of the threads which we have attached/need to
+  // attach.
+  Host::TidMap tids_to_attach;
+  if (pid <= 1) {
+    error.SetErrorToGenericError();
+    error.SetErrorString("Attaching to process 1 is not allowed.");
+    return -1;
+  }
+
+  while (Host::FindProcessThreads(pid, tids_to_attach)) {
+    for (Host::TidMap::iterator it = tids_to_attach.begin();
+         it != tids_to_attach.end();) {
+      if (it->second == false) {
+        lldb::tid_t tid = it->first;
+
+        // Attach to the requested process.
+        // An attach will cause the thread to stop with a SIGSTOP.
+        error = PtraceWrapper(PTRACE_ATTACH, tid);
+        if (error.Fail()) {
+          // No such thread. The thread may have exited.
+          // More error handling may be needed.
+          if (error.GetError() == ESRCH) {
+            it = tids_to_attach.erase(it);
+            continue;
+          } else
+            return -1;
         }
-        else
-        {
-            // Do we want to report to the delegate in this case?  I think not.  If this was an orderly
-            // thread exit, we would already have received the SIGTRAP | (PTRACE_EVENT_EXIT << 8) signal,
-            // and we would have done an all-stop then.
-            if (log)
-                log->Printf ("NativeProcessLinux::%s() tid = %"  PRIu64 " handling non-main thread exit (%s)", __FUNCTION__, pid, thread_found ? "stopped tracking thread metadata" : "thread metadata not found");
+
+        int status;
+        // Need to use __WALL otherwise we receive an error with errno=ECHLD
+        // At this point we should have a thread stopped if waitpid succeeds.
+        if ((status = waitpid(tid, NULL, __WALL)) < 0) {
+          // No such thread. The thread may have exited.
+          // More error handling may be needed.
+          if (errno == ESRCH) {
+            it = tids_to_attach.erase(it);
+            continue;
+          } else {
+            error.SetErrorToErrno();
+            return -1;
+          }
         }
-        return;
-    }
 
-    siginfo_t info;
-    const auto info_err = GetSignalInfo(pid, &info);
-    auto thread_sp = GetThreadByID(pid);
+        error = SetDefaultPtraceOpts(tid);
+        if (error.Fail())
+          return -1;
 
-    if (! thread_sp)
-    {
-        // Normally, the only situation when we cannot find the thread is if we have just
-        // received a new thread notification. This is indicated by GetSignalInfo() returning
-        // si_code == SI_USER and si_pid == 0
         if (log)
-            log->Printf("NativeProcessLinux::%s received notification about an unknown tid %" PRIu64 ".", __FUNCTION__, pid);
+          log->Printf("NativeProcessLinux::%s() adding tid = %" PRIu64,
+                      __FUNCTION__, tid);
 
-        if (info_err.Fail())
-        {
-            if (log)
-                log->Printf("NativeProcessLinux::%s (tid %" PRIu64 ") GetSignalInfo failed (%s). Ingoring this notification.", __FUNCTION__, pid, info_err.AsCString());
-            return;
-        }
+        it->second = true;
 
-        if (log && (info.si_code != SI_USER || info.si_pid != 0))
-            log->Printf("NativeProcessLinux::%s (tid %" PRIu64 ") unexpected signal info (si_code: %d, si_pid: %d). Treating as a new thread notification anyway.", __FUNCTION__, pid, info.si_code, info.si_pid);
+        // Create the thread, mark it as stopped.
+        NativeThreadLinuxSP thread_sp(AddThread(static_cast<lldb::tid_t>(tid)));
+        assert(thread_sp && "AddThread() returned a nullptr");
 
-        auto thread_sp = AddThread(pid);
-        // Resume the newly created thread.
-        ResumeThread(*thread_sp, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
+        // This will notify this is a new thread and tell the system it is
+        // stopped.
+        thread_sp->SetStoppedBySignal(SIGSTOP);
         ThreadWasCreated(*thread_sp);
-        return;
-    }
+        SetCurrentThreadID(thread_sp->GetID());
+      }
 
-    // Get details on the signal raised.
-    if (info_err.Success())
-    {
-        // We have retrieved the signal info.  Dispatch appropriately.
-        if (info.si_signo == SIGTRAP)
-            MonitorSIGTRAP(info, *thread_sp);
-        else
-            MonitorSignal(info, *thread_sp, exited);
+      // move the loop forward
+      ++it;
     }
-    else
-    {
-        if (info_err.GetError() == EINVAL)
-        {
-            // This is a group stop reception for this tid.
-            // We can reach here if we reinject SIGSTOP, SIGSTP, SIGTTIN or SIGTTOU into the
-            // tracee, triggering the group-stop mechanism. Normally receiving these would stop
-            // the process, pending a SIGCONT. Simulating this state in a debugger is hard and is
-            // generally not needed (one use case is debugging background task being managed by a
-            // shell). For general use, it is sufficient to stop the process in a signal-delivery
-            // stop which happens before the group stop. This done by MonitorSignal and works
-            // correctly for all signals.
-            if (log)
-                log->Printf("NativeProcessLinux::%s received a group stop for pid %" PRIu64 " tid %" PRIu64 ". Transparent handling of group stops not supported, resuming the thread.", __FUNCTION__, GetID (), pid);
-            ResumeThread(*thread_sp, thread_sp->GetState(), LLDB_INVALID_SIGNAL_NUMBER);
-        }
-        else
-        {
-            // ptrace(GETSIGINFO) failed (but not due to group-stop).
-
-            // A return value of ESRCH means the thread/process is no longer on the system,
-            // so it was killed somehow outside of our control.  Either way, we can't do anything
-            // with it anymore.
-
-            // Stop tracking the metadata for the thread since it's entirely off the system now.
-            const bool thread_found = StopTrackingThread (pid);
-
-            if (log)
-                log->Printf ("NativeProcessLinux::%s GetSignalInfo failed: %s, tid = %" PRIu64 ", signal = %d, status = %d (%s, %s, %s)",
-                             __FUNCTION__, info_err.AsCString(), pid, signal, status, info_err.GetError() == ESRCH ? "thread/process killed" : "unknown reason", is_main_thread ? "is main thread" : "is not main thread", thread_found ? "thread metadata removed" : "thread metadata not found");
+  }
 
-            if (is_main_thread)
-            {
-                // Notify the delegate - our process is not available but appears to have been killed outside
-                // our control.  Is eStateExited the right exit state in this case?
-                SetExitStatus (convert_pid_status_to_exit_type (status), convert_pid_status_to_return_code (status), nullptr, true);
-                SetState (StateType::eStateExited, true);
-            }
-            else
-            {
-                // This thread was pulled out from underneath us.  Anything to do here? Do we want to do an all stop?
-                if (log)
-                    log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64 " non-main thread exit occurred, didn't tell delegate anything since thread disappeared out from underneath us", __FUNCTION__, GetID (), pid);
-            }
-        }
-    }
+  if (tids_to_attach.size() > 0) {
+    m_pid = pid;
+    // Let our process instance know the thread has stopped.
+    SetState(StateType::eStateStopped);
+  } else {
+    error.SetErrorToGenericError();
+    error.SetErrorString("No such process.");
+    return -1;
+  }
+
+  return pid;
+}
+
+Error NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid) {
+  long ptrace_opts = 0;
+
+  // Have the child raise an event on exit.  This is used to keep the child in
+  // limbo until it is destroyed.
+  ptrace_opts |= PTRACE_O_TRACEEXIT;
+
+  // Have the tracer trace threads which spawn in the inferior process.
+  // TODO: if we want to support tracing the inferiors' child, add the
+  // appropriate ptrace flags here (PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK)
+  ptrace_opts |= PTRACE_O_TRACECLONE;
+
+  // Have the tracer notify us before execve returns
+  // (needed to disable legacy SIGTRAP generation)
+  ptrace_opts |= PTRACE_O_TRACEEXEC;
+
+  return PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void *)ptrace_opts);
+}
+
+static ExitType convert_pid_status_to_exit_type(int status) {
+  if (WIFEXITED(status))
+    return ExitType::eExitTypeExit;
+  else if (WIFSIGNALED(status))
+    return ExitType::eExitTypeSignal;
+  else if (WIFSTOPPED(status))
+    return ExitType::eExitTypeStop;
+  else {
+    // We don't know what this is.
+    return ExitType::eExitTypeInvalid;
+  }
+}
+
+static int convert_pid_status_to_return_code(int status) {
+  if (WIFEXITED(status))
+    return WEXITSTATUS(status);
+  else if (WIFSIGNALED(status))
+    return WTERMSIG(status);
+  else if (WIFSTOPPED(status))
+    return WSTOPSIG(status);
+  else {
+    // We don't know what this is.
+    return ExitType::eExitTypeInvalid;
+  }
 }
 
-void
-NativeProcessLinux::WaitForNewThread(::pid_t tid)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-    NativeThreadLinuxSP new_thread_sp = GetThreadByID(tid);
-
-    if (new_thread_sp)
-    {
-        // We are already tracking the thread - we got the event on the new thread (see
-        // MonitorSignal) before this one. We are done.
-        return;
-    }
-
-    // The thread is not tracked yet, let's wait for it to appear.
-    int status = -1;
-    ::pid_t wait_pid;
-    do
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() received thread creation event for tid %" PRIu32 ". tid not tracked yet, waiting for thread to appear...", __FUNCTION__, tid);
-        wait_pid = waitpid(tid, &status, __WALL);
-    }
-    while (wait_pid == -1 && errno == EINTR);
-    // Since we are waiting on a specific tid, this must be the creation event. But let's do
-    // some checks just in case.
-    if (wait_pid != tid) {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() waiting for tid %" PRIu32 " failed. Assuming the thread has disappeared in the meantime", __FUNCTION__, tid);
-        // The only way I know of this could happen is if the whole process was
-        // SIGKILLed in the mean time. In any case, we can't do anything about that now.
-        return;
-    }
-    if (WIFEXITED(status))
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() waiting for tid %" PRIu32 " returned an 'exited' event. Not tracking the thread.", __FUNCTION__, tid);
-        // Also a very improbable event.
-        return;
-    }
+// Handles all waitpid events from the inferior process.
+void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
+                                         int signal, int status) {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  // Certain activities differ based on whether the pid is the tid of the main
+  // thread.
+  const bool is_main_thread = (pid == GetID());
+
+  // Handle when the thread exits.
+  if (exited) {
+    if (log)
+      log->Printf(
+          "NativeProcessLinux::%s() got exit signal(%d) , tid = %" PRIu64
+          " (%s main thread)",
+          __FUNCTION__, signal, pid, is_main_thread ? "is" : "is not");
+
+    // This is a thread that exited.  Ensure we're not tracking it anymore.
+    const bool thread_found = StopTrackingThread(pid);
+
+    if (is_main_thread) {
+      // We only set the exit status and notify the delegate if we haven't
+      // already set the process
+      // state to an exited state.  We normally should have received a SIGTRAP |
+      // (PTRACE_EVENT_EXIT << 8)
+      // for the main thread.
+      const bool already_notified = (GetState() == StateType::eStateExited) ||
+                                    (GetState() == StateType::eStateCrashed);
+      if (!already_notified) {
+        if (log)
+          log->Printf("NativeProcessLinux::%s() tid = %" PRIu64
+                      " handling main thread exit (%s), expected exit state "
+                      "already set but state was %s instead, setting exit "
+                      "state now",
+                      __FUNCTION__, pid,
+                      thread_found ? "stopped tracking thread metadata"
+                                   : "thread metadata not found",
+                      StateAsCString(GetState()));
+        // The main thread exited.  We're done monitoring.  Report to delegate.
+        SetExitStatus(convert_pid_status_to_exit_type(status),
+                      convert_pid_status_to_return_code(status), nullptr, true);
+
+        // Notify delegate that our process has exited.
+        SetState(StateType::eStateExited, true);
+      } else {
+        if (log)
+          log->Printf("NativeProcessLinux::%s() tid = %" PRIu64
+                      " main thread now exited (%s)",
+                      __FUNCTION__, pid,
+                      thread_found ? "stopped tracking thread metadata"
+                                   : "thread metadata not found");
+      }
+    } else {
+      // Do we want to report to the delegate in this case?  I think not.  If
+      // this was an orderly
+      // thread exit, we would already have received the SIGTRAP |
+      // (PTRACE_EVENT_EXIT << 8) signal,
+      // and we would have done an all-stop then.
+      if (log)
+        log->Printf("NativeProcessLinux::%s() tid = %" PRIu64
+                    " handling non-main thread exit (%s)",
+                    __FUNCTION__, pid,
+                    thread_found ? "stopped tracking thread metadata"
+                                 : "thread metadata not found");
+    }
+    return;
+  }
+
+  siginfo_t info;
+  const auto info_err = GetSignalInfo(pid, &info);
+  auto thread_sp = GetThreadByID(pid);
+
+  if (!thread_sp) {
+    // Normally, the only situation when we cannot find the thread is if we have
+    // just
+    // received a new thread notification. This is indicated by GetSignalInfo()
+    // returning
+    // si_code == SI_USER and si_pid == 0
+    if (log)
+      log->Printf("NativeProcessLinux::%s received notification about an "
+                  "unknown tid %" PRIu64 ".",
+                  __FUNCTION__, pid);
+
+    if (info_err.Fail()) {
+      if (log)
+        log->Printf("NativeProcessLinux::%s (tid %" PRIu64
+                    ") GetSignalInfo failed (%s). Ingoring this notification.",
+                    __FUNCTION__, pid, info_err.AsCString());
+      return;
+    }
+
+    if (log && (info.si_code != SI_USER || info.si_pid != 0))
+      log->Printf("NativeProcessLinux::%s (tid %" PRIu64
+                  ") unexpected signal info (si_code: %d, si_pid: %d). "
+                  "Treating as a new thread notification anyway.",
+                  __FUNCTION__, pid, info.si_code, info.si_pid);
+
+    auto thread_sp = AddThread(pid);
+    // Resume the newly created thread.
+    ResumeThread(*thread_sp, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
+    ThreadWasCreated(*thread_sp);
+    return;
+  }
 
-    siginfo_t info;
-    Error error = GetSignalInfo(tid, &info);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() GetSignalInfo for tid %" PRIu32 " failed. Assuming the thread has disappeared in the meantime.", __FUNCTION__, tid);
-        return;
-    }
+  // Get details on the signal raised.
+  if (info_err.Success()) {
+    // We have retrieved the signal info.  Dispatch appropriately.
+    if (info.si_signo == SIGTRAP)
+      MonitorSIGTRAP(info, *thread_sp);
+    else
+      MonitorSignal(info, *thread_sp, exited);
+  } else {
+    if (info_err.GetError() == EINVAL) {
+      // This is a group stop reception for this tid.
+      // We can reach here if we reinject SIGSTOP, SIGSTP, SIGTTIN or SIGTTOU
+      // into the
+      // tracee, triggering the group-stop mechanism. Normally receiving these
+      // would stop
+      // the process, pending a SIGCONT. Simulating this state in a debugger is
+      // hard and is
+      // generally not needed (one use case is debugging background task being
+      // managed by a
+      // shell). For general use, it is sufficient to stop the process in a
+      // signal-delivery
+      // stop which happens before the group stop. This done by MonitorSignal
+      // and works
+      // correctly for all signals.
+      if (log)
+        log->Printf(
+            "NativeProcessLinux::%s received a group stop for pid %" PRIu64
+            " tid %" PRIu64 ". Transparent handling of group stops not "
+                            "supported, resuming the thread.",
+            __FUNCTION__, GetID(), pid);
+      ResumeThread(*thread_sp, thread_sp->GetState(),
+                   LLDB_INVALID_SIGNAL_NUMBER);
+    } else {
+      // ptrace(GETSIGINFO) failed (but not due to group-stop).
 
-    if (((info.si_pid != 0) || (info.si_code != SI_USER)) && log)
-    {
-        // We should be getting a thread creation signal here, but we received something
-        // else. There isn't much we can do about it now, so we will just log that. Since the
-        // thread is alive and we are receiving events from it, we shall pretend that it was
-        // created properly.
-        log->Printf ("NativeProcessLinux::%s() GetSignalInfo for tid %" PRIu32 " received unexpected signal with code %d from pid %d.", __FUNCTION__, tid, info.si_code, info.si_pid);
-    }
+      // A return value of ESRCH means the thread/process is no longer on the
+      // system,
+      // so it was killed somehow outside of our control.  Either way, we can't
+      // do anything
+      // with it anymore.
+
+      // Stop tracking the metadata for the thread since it's entirely off the
+      // system now.
+      const bool thread_found = StopTrackingThread(pid);
+
+      if (log)
+        log->Printf(
+            "NativeProcessLinux::%s GetSignalInfo failed: %s, tid = %" PRIu64
+            ", signal = %d, status = %d (%s, %s, %s)",
+            __FUNCTION__, info_err.AsCString(), pid, signal, status,
+            info_err.GetError() == ESRCH ? "thread/process killed"
+                                         : "unknown reason",
+            is_main_thread ? "is main thread" : "is not main thread",
+            thread_found ? "thread metadata removed"
+                         : "thread metadata not found");
+
+      if (is_main_thread) {
+        // Notify the delegate - our process is not available but appears to
+        // have been killed outside
+        // our control.  Is eStateExited the right exit state in this case?
+        SetExitStatus(convert_pid_status_to_exit_type(status),
+                      convert_pid_status_to_return_code(status), nullptr, true);
+        SetState(StateType::eStateExited, true);
+      } else {
+        // This thread was pulled out from underneath us.  Anything to do here?
+        // Do we want to do an all stop?
+        if (log)
+          log->Printf("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64
+                      " non-main thread exit occurred, didn't tell delegate "
+                      "anything since thread disappeared out from underneath "
+                      "us",
+                      __FUNCTION__, GetID(), pid);
+      }
+    }
+  }
+}
+
+void NativeProcessLinux::WaitForNewThread(::pid_t tid) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  NativeThreadLinuxSP new_thread_sp = GetThreadByID(tid);
+
+  if (new_thread_sp) {
+    // We are already tracking the thread - we got the event on the new thread
+    // (see
+    // MonitorSignal) before this one. We are done.
+    return;
+  }
+
+  // The thread is not tracked yet, let's wait for it to appear.
+  int status = -1;
+  ::pid_t wait_pid;
+  do {
+    if (log)
+      log->Printf("NativeProcessLinux::%s() received thread creation event for "
+                  "tid %" PRIu32
+                  ". tid not tracked yet, waiting for thread to appear...",
+                  __FUNCTION__, tid);
+    wait_pid = waitpid(tid, &status, __WALL);
+  } while (wait_pid == -1 && errno == EINTR);
+  // Since we are waiting on a specific tid, this must be the creation event.
+  // But let's do
+  // some checks just in case.
+  if (wait_pid != tid) {
+    if (log)
+      log->Printf(
+          "NativeProcessLinux::%s() waiting for tid %" PRIu32
+          " failed. Assuming the thread has disappeared in the meantime",
+          __FUNCTION__, tid);
+    // The only way I know of this could happen is if the whole process was
+    // SIGKILLed in the mean time. In any case, we can't do anything about that
+    // now.
+    return;
+  }
+  if (WIFEXITED(status)) {
+    if (log)
+      log->Printf("NativeProcessLinux::%s() waiting for tid %" PRIu32
+                  " returned an 'exited' event. Not tracking the thread.",
+                  __FUNCTION__, tid);
+    // Also a very improbable event.
+    return;
+  }
+
+  siginfo_t info;
+  Error error = GetSignalInfo(tid, &info);
+  if (error.Fail()) {
+    if (log)
+      log->Printf(
+          "NativeProcessLinux::%s() GetSignalInfo for tid %" PRIu32
+          " failed. Assuming the thread has disappeared in the meantime.",
+          __FUNCTION__, tid);
+    return;
+  }
+
+  if (((info.si_pid != 0) || (info.si_code != SI_USER)) && log) {
+    // We should be getting a thread creation signal here, but we received
+    // something
+    // else. There isn't much we can do about it now, so we will just log that.
+    // Since the
+    // thread is alive and we are receiving events from it, we shall pretend
+    // that it was
+    // created properly.
+    log->Printf("NativeProcessLinux::%s() GetSignalInfo for tid %" PRIu32
+                " received unexpected signal with code %d from pid %d.",
+                __FUNCTION__, tid, info.si_code, info.si_pid);
+  }
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s() pid = %" PRIu64
+                ": tracking new thread tid %" PRIu32,
+                __FUNCTION__, GetID(), tid);
+
+  new_thread_sp = AddThread(tid);
+  ResumeThread(*new_thread_sp, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
+  ThreadWasCreated(*new_thread_sp);
+}
+
+void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
+                                        NativeThreadLinux &thread) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  const bool is_main_thread = (thread.GetID() == GetID());
+
+  assert(info.si_signo == SIGTRAP && "Unexpected child signal!");
+
+  switch (info.si_code) {
+  // TODO: these two cases are required if we want to support tracing of the
+  // inferiors' children.  We'd need this to debug a monitor.
+  // case (SIGTRAP | (PTRACE_EVENT_FORK << 8)):
+  // case (SIGTRAP | (PTRACE_EVENT_VFORK << 8)):
+
+  case (SIGTRAP | (PTRACE_EVENT_CLONE << 8)): {
+    // This is the notification on the parent thread which informs us of new
+    // thread
+    // creation.
+    // We don't want to do anything with the parent thread so we just resume it.
+    // In case we
+    // want to implement "break on thread creation" functionality, we would need
+    // to stop
+    // here.
+
+    unsigned long event_message = 0;
+    if (GetEventMessage(thread.GetID(), &event_message).Fail()) {
+      if (log)
+        log->Printf("NativeProcessLinux::%s() pid %" PRIu64
+                    " received thread creation event but GetEventMessage "
+                    "failed so we don't know the new tid",
+                    __FUNCTION__, thread.GetID());
+    } else
+      WaitForNewThread(event_message);
+
+    ResumeThread(thread, thread.GetState(), LLDB_INVALID_SIGNAL_NUMBER);
+    break;
+  }
 
+  case (SIGTRAP | (PTRACE_EVENT_EXEC << 8)): {
+    NativeThreadLinuxSP main_thread_sp;
     if (log)
-        log->Printf ("NativeProcessLinux::%s() pid = %" PRIu64 ": tracking new thread tid %" PRIu32,
-                 __FUNCTION__, GetID (), tid);
-
-    new_thread_sp = AddThread(tid);
-    ResumeThread(*new_thread_sp, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
-    ThreadWasCreated(*new_thread_sp);
-}
-
-void
-NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-    const bool is_main_thread = (thread.GetID() == GetID ());
-
-    assert(info.si_signo == SIGTRAP && "Unexpected child signal!");
-
-    switch (info.si_code)
-    {
-    // TODO: these two cases are required if we want to support tracing of the inferiors' children.  We'd need this to debug a monitor.
-    // case (SIGTRAP | (PTRACE_EVENT_FORK << 8)):
-    // case (SIGTRAP | (PTRACE_EVENT_VFORK << 8)):
-
-    case (SIGTRAP | (PTRACE_EVENT_CLONE << 8)):
-    {
-        // This is the notification on the parent thread which informs us of new thread
-        // creation.
-        // We don't want to do anything with the parent thread so we just resume it. In case we
-        // want to implement "break on thread creation" functionality, we would need to stop
-        // here.
-
-        unsigned long event_message = 0;
-        if (GetEventMessage(thread.GetID(), &event_message).Fail())
-        {
-            if (log)
-                log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 " received thread creation event but GetEventMessage failed so we don't know the new tid", __FUNCTION__, thread.GetID());
-        } else 
-            WaitForNewThread(event_message);
-
-        ResumeThread(thread, thread.GetState(), LLDB_INVALID_SIGNAL_NUMBER);
-        break;
-    }
-
-    case (SIGTRAP | (PTRACE_EVENT_EXEC << 8)):
-    {
-        NativeThreadLinuxSP main_thread_sp;
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() received exec event, code = %d", __FUNCTION__, info.si_code ^ SIGTRAP);
-
-        // Exec clears any pending notifications.
-        m_pending_notification_tid = LLDB_INVALID_THREAD_ID;
-
-        // Remove all but the main thread here.  Linux fork creates a new process which only copies the main thread.
-        if (log)
-            log->Printf ("NativeProcessLinux::%s exec received, stop tracking all but main thread", __FUNCTION__);
+      log->Printf("NativeProcessLinux::%s() received exec event, code = %d",
+                  __FUNCTION__, info.si_code ^ SIGTRAP);
 
-        for (auto thread_sp : m_threads)
-        {
-            const bool is_main_thread = thread_sp && thread_sp->GetID () == GetID ();
-            if (is_main_thread)
-            {
-                main_thread_sp = std::static_pointer_cast<NativeThreadLinux>(thread_sp);
-                if (log)
-                    log->Printf ("NativeProcessLinux::%s found main thread with tid %" PRIu64 ", keeping", __FUNCTION__, main_thread_sp->GetID ());
-            }
-            else
-            {
-                if (log)
-                    log->Printf ("NativeProcessLinux::%s discarding non-main-thread tid %" PRIu64 " due to exec", __FUNCTION__, thread_sp->GetID ());
-            }
-        }
-
-        m_threads.clear ();
-
-        if (main_thread_sp)
-        {
-            m_threads.push_back (main_thread_sp);
-            SetCurrentThreadID (main_thread_sp->GetID ());
-            main_thread_sp->SetStoppedByExec();
-        }
-        else
-        {
-            SetCurrentThreadID (LLDB_INVALID_THREAD_ID);
-            if (log)
-                log->Printf ("NativeProcessLinux::%s pid %" PRIu64 "no main thread found, discarded all threads, we're in a no-thread state!", __FUNCTION__, GetID ());
-        }
-
-        // Tell coordinator about about the "new" (since exec) stopped main thread.
-        ThreadWasCreated(*main_thread_sp);
-
-        // Let our delegate know we have just exec'd.
-        NotifyDidExec ();
-
-        // If we have a main thread, indicate we are stopped.
-        assert (main_thread_sp && "exec called during ptraced process but no main thread metadata tracked");
-
-        // Let the process know we're stopped.
-        StopRunningThreads(main_thread_sp->GetID());
-
-        break;
-    }
-
-    case (SIGTRAP | (PTRACE_EVENT_EXIT << 8)):
-    {
-        // The inferior process or one of its threads is about to exit.
-        // We don't want to do anything with the thread so we just resume it. In case we
-        // want to implement "break on thread exit" functionality, we would need to stop
-        // here.
-
-        unsigned long data = 0;
-        if (GetEventMessage(thread.GetID(), &data).Fail())
-            data = -1;
-
-        if (log)
-        {
-            log->Printf ("NativeProcessLinux::%s() received PTRACE_EVENT_EXIT, data = %lx (WIFEXITED=%s,WIFSIGNALED=%s), pid = %" PRIu64 " (%s)",
-                         __FUNCTION__,
-                         data, WIFEXITED (data) ? "true" : "false", WIFSIGNALED (data) ? "true" : "false",
-                         thread.GetID(),
-                    is_main_thread ? "is main thread" : "not main thread");
-        }
-
-        if (is_main_thread)
-        {
-            SetExitStatus (convert_pid_status_to_exit_type (data), convert_pid_status_to_return_code (data), nullptr, true);
-        }
-
-        StateType state = thread.GetState();
-        if (! StateIsRunningState(state))
-        {
-            // Due to a kernel bug, we may sometimes get this stop after the inferior gets a
-            // SIGKILL. This confuses our state tracking logic in ResumeThread(), since normally,
-            // we should not be receiving any ptrace events while the inferior is stopped. This
-            // makes sure that the inferior is resumed and exits normally.
-            state = eStateRunning;
-        }
-        ResumeThread(thread, state, LLDB_INVALID_SIGNAL_NUMBER);
-
-        break;
-    }
-
-    case 0:
-    case TRAP_TRACE:  // We receive this on single stepping.
-    case TRAP_HWBKPT: // We receive this on watchpoint hit
-    {
-        // If a watchpoint was hit, report it
-        uint32_t wp_index;
-        Error error = thread.GetRegisterContext()->GetWatchpointHitIndex(wp_index, (uintptr_t)info.si_addr);
-        if (error.Fail() && log)
-            log->Printf("NativeProcessLinux::%s() "
-                        "received error while checking for watchpoint hits, "
-                        "pid = %" PRIu64 " error = %s",
-                        __FUNCTION__, thread.GetID(), error.AsCString());
-        if (wp_index != LLDB_INVALID_INDEX32)
-        {
-            MonitorWatchpoint(thread, wp_index);
-            break;
-        }
+    // Exec clears any pending notifications.
+    m_pending_notification_tid = LLDB_INVALID_THREAD_ID;
 
-        // Otherwise, report step over
-        MonitorTrace(thread);
-        break;
-    }
+    // Remove all but the main thread here.  Linux fork creates a new process
+    // which only copies the main thread.
+    if (log)
+      log->Printf("NativeProcessLinux::%s exec received, stop tracking all but "
+                  "main thread",
+                  __FUNCTION__);
+
+    for (auto thread_sp : m_threads) {
+      const bool is_main_thread = thread_sp && thread_sp->GetID() == GetID();
+      if (is_main_thread) {
+        main_thread_sp = std::static_pointer_cast<NativeThreadLinux>(thread_sp);
+        if (log)
+          log->Printf(
+              "NativeProcessLinux::%s found main thread with tid %" PRIu64
+              ", keeping",
+              __FUNCTION__, main_thread_sp->GetID());
+      } else {
+        if (log)
+          log->Printf(
+              "NativeProcessLinux::%s discarding non-main-thread tid %" PRIu64
+              " due to exec",
+              __FUNCTION__, thread_sp->GetID());
+      }
+    }
+
+    m_threads.clear();
+
+    if (main_thread_sp) {
+      m_threads.push_back(main_thread_sp);
+      SetCurrentThreadID(main_thread_sp->GetID());
+      main_thread_sp->SetStoppedByExec();
+    } else {
+      SetCurrentThreadID(LLDB_INVALID_THREAD_ID);
+      if (log)
+        log->Printf("NativeProcessLinux::%s pid %" PRIu64
+                    "no main thread found, discarded all threads, we're in a "
+                    "no-thread state!",
+                    __FUNCTION__, GetID());
+    }
+
+    // Tell coordinator about about the "new" (since exec) stopped main thread.
+    ThreadWasCreated(*main_thread_sp);
+
+    // Let our delegate know we have just exec'd.
+    NotifyDidExec();
+
+    // If we have a main thread, indicate we are stopped.
+    assert(main_thread_sp && "exec called during ptraced process but no main "
+                             "thread metadata tracked");
+
+    // Let the process know we're stopped.
+    StopRunningThreads(main_thread_sp->GetID());
+
+    break;
+  }
+
+  case (SIGTRAP | (PTRACE_EVENT_EXIT << 8)): {
+    // The inferior process or one of its threads is about to exit.
+    // We don't want to do anything with the thread so we just resume it. In
+    // case we
+    // want to implement "break on thread exit" functionality, we would need to
+    // stop
+    // here.
+
+    unsigned long data = 0;
+    if (GetEventMessage(thread.GetID(), &data).Fail())
+      data = -1;
+
+    if (log) {
+      log->Printf("NativeProcessLinux::%s() received PTRACE_EVENT_EXIT, data = "
+                  "%lx (WIFEXITED=%s,WIFSIGNALED=%s), pid = %" PRIu64 " (%s)",
+                  __FUNCTION__, data, WIFEXITED(data) ? "true" : "false",
+                  WIFSIGNALED(data) ? "true" : "false", thread.GetID(),
+                  is_main_thread ? "is main thread" : "not main thread");
+    }
+
+    if (is_main_thread) {
+      SetExitStatus(convert_pid_status_to_exit_type(data),
+                    convert_pid_status_to_return_code(data), nullptr, true);
+    }
+
+    StateType state = thread.GetState();
+    if (!StateIsRunningState(state)) {
+      // Due to a kernel bug, we may sometimes get this stop after the inferior
+      // gets a
+      // SIGKILL. This confuses our state tracking logic in ResumeThread(),
+      // since normally,
+      // we should not be receiving any ptrace events while the inferior is
+      // stopped. This
+      // makes sure that the inferior is resumed and exits normally.
+      state = eStateRunning;
+    }
+    ResumeThread(thread, state, LLDB_INVALID_SIGNAL_NUMBER);
+
+    break;
+  }
+
+  case 0:
+  case TRAP_TRACE:  // We receive this on single stepping.
+  case TRAP_HWBKPT: // We receive this on watchpoint hit
+  {
+    // If a watchpoint was hit, report it
+    uint32_t wp_index;
+    Error error = thread.GetRegisterContext()->GetWatchpointHitIndex(
+        wp_index, (uintptr_t)info.si_addr);
+    if (error.Fail() && log)
+      log->Printf("NativeProcessLinux::%s() "
+                  "received error while checking for watchpoint hits, "
+                  "pid = %" PRIu64 " error = %s",
+                  __FUNCTION__, thread.GetID(), error.AsCString());
+    if (wp_index != LLDB_INVALID_INDEX32) {
+      MonitorWatchpoint(thread, wp_index);
+      break;
+    }
+
+    // Otherwise, report step over
+    MonitorTrace(thread);
+    break;
+  }
 
-    case SI_KERNEL:
+  case SI_KERNEL:
 #if defined __mips__
-        // For mips there is no special signal for watchpoint
-        // So we check for watchpoint in kernel trap
+    // For mips there is no special signal for watchpoint
+    // So we check for watchpoint in kernel trap
     {
-        // If a watchpoint was hit, report it
-        uint32_t wp_index;
-        Error error = thread.GetRegisterContext()->GetWatchpointHitIndex(wp_index, LLDB_INVALID_ADDRESS);
-        if (error.Fail() && log)
-            log->Printf("NativeProcessLinux::%s() "
-                        "received error while checking for watchpoint hits, "
-                        "pid = %" PRIu64 " error = %s",
-                        __FUNCTION__, thread.GetID(), error.AsCString());
-        if (wp_index != LLDB_INVALID_INDEX32)
-        {
-            MonitorWatchpoint(thread, wp_index);
-            break;
-        }
-    }
-        // NO BREAK
-#endif
-    case TRAP_BRKPT:
-        MonitorBreakpoint(thread);
-        break;
-
-    case SIGTRAP:
-    case (SIGTRAP | 0x80):
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() received unknown SIGTRAP system call stop event, pid %" PRIu64 "tid %" PRIu64 ", resuming", __FUNCTION__, GetID (), thread.GetID());
-
-        // Ignore these signals until we know more about them.
-        ResumeThread(thread, thread.GetState(), LLDB_INVALID_SIGNAL_NUMBER);
-        break;
-
-    default:
-        assert(false && "Unexpected SIGTRAP code!");
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 "tid %" PRIu64 " received unhandled SIGTRAP code: 0x%d",
-                    __FUNCTION__, GetID(), thread.GetID(), info.si_code);
+      // If a watchpoint was hit, report it
+      uint32_t wp_index;
+      Error error = thread.GetRegisterContext()->GetWatchpointHitIndex(
+          wp_index, LLDB_INVALID_ADDRESS);
+      if (error.Fail() && log)
+        log->Printf("NativeProcessLinux::%s() "
+                    "received error while checking for watchpoint hits, "
+                    "pid = %" PRIu64 " error = %s",
+                    __FUNCTION__, thread.GetID(), error.AsCString());
+      if (wp_index != LLDB_INVALID_INDEX32) {
+        MonitorWatchpoint(thread, wp_index);
         break;
-        
+      }
     }
-}
-
-void
-NativeProcessLinux::MonitorTrace(NativeThreadLinux &thread)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-    if (log)
-        log->Printf("NativeProcessLinux::%s() received trace event, pid = %" PRIu64 " (single stepping)",
-                __FUNCTION__, thread.GetID());
-
-    // This thread is currently stopped.
-    thread.SetStoppedByTrace();
-
-    StopRunningThreads(thread.GetID());
-}
-
-void
-NativeProcessLinux::MonitorBreakpoint(NativeThreadLinux &thread)
-{
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_BREAKPOINTS));
-    if (log)
-        log->Printf("NativeProcessLinux::%s() received breakpoint event, pid = %" PRIu64,
+// NO BREAK
+#endif
+  case TRAP_BRKPT:
+    MonitorBreakpoint(thread);
+    break;
+
+  case SIGTRAP:
+  case (SIGTRAP | 0x80):
+    if (log)
+      log->Printf("NativeProcessLinux::%s() received unknown SIGTRAP system "
+                  "call stop event, pid %" PRIu64 "tid %" PRIu64 ", resuming",
+                  __FUNCTION__, GetID(), thread.GetID());
+
+    // Ignore these signals until we know more about them.
+    ResumeThread(thread, thread.GetState(), LLDB_INVALID_SIGNAL_NUMBER);
+    break;
+
+  default:
+    assert(false && "Unexpected SIGTRAP code!");
+    if (log)
+      log->Printf("NativeProcessLinux::%s() pid %" PRIu64 "tid %" PRIu64
+                  " received unhandled SIGTRAP code: 0x%d",
+                  __FUNCTION__, GetID(), thread.GetID(), info.si_code);
+    break;
+  }
+}
+
+void NativeProcessLinux::MonitorTrace(NativeThreadLinux &thread) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf("NativeProcessLinux::%s() received trace event, pid = %" PRIu64
+                " (single stepping)",
                 __FUNCTION__, thread.GetID());
 
-    // Mark the thread as stopped at breakpoint.
-    thread.SetStoppedByBreakpoint();
-    Error error = FixupBreakpointPCAsNeeded(thread);
-    if (error.Fail())
-        if (log)
-            log->Printf("NativeProcessLinux::%s() pid = %" PRIu64 " fixup: %s",
-                    __FUNCTION__, thread.GetID(), error.AsCString());
+  // This thread is currently stopped.
+  thread.SetStoppedByTrace();
 
-    if (m_threads_stepping_with_breakpoint.find(thread.GetID()) != m_threads_stepping_with_breakpoint.end())
-        thread.SetStoppedByTrace();
-
-    StopRunningThreads(thread.GetID());
+  StopRunningThreads(thread.GetID());
 }
 
-void
-NativeProcessLinux::MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index)
-{
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_WATCHPOINTS));
+void NativeProcessLinux::MonitorBreakpoint(NativeThreadLinux &thread) {
+  Log *log(
+      GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_BREAKPOINTS));
+  if (log)
+    log->Printf(
+        "NativeProcessLinux::%s() received breakpoint event, pid = %" PRIu64,
+        __FUNCTION__, thread.GetID());
+
+  // Mark the thread as stopped at breakpoint.
+  thread.SetStoppedByBreakpoint();
+  Error error = FixupBreakpointPCAsNeeded(thread);
+  if (error.Fail())
     if (log)
-        log->Printf("NativeProcessLinux::%s() received watchpoint event, "
-                    "pid = %" PRIu64 ", wp_index = %" PRIu32,
-                    __FUNCTION__, thread.GetID(), wp_index);
+      log->Printf("NativeProcessLinux::%s() pid = %" PRIu64 " fixup: %s",
+                  __FUNCTION__, thread.GetID(), error.AsCString());
 
-    // Mark the thread as stopped at watchpoint.
-    // The address is at (lldb::addr_t)info->si_addr if we need it.
-    thread.SetStoppedByWatchpoint(wp_index);
+  if (m_threads_stepping_with_breakpoint.find(thread.GetID()) !=
+      m_threads_stepping_with_breakpoint.end())
+    thread.SetStoppedByTrace();
 
-    // We need to tell all other running threads before we notify the delegate about this stop.
-    StopRunningThreads(thread.GetID());
+  StopRunningThreads(thread.GetID());
 }
 
-void
-NativeProcessLinux::MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread, bool exited)
-{
-    const int signo = info.si_signo;
-    const bool is_from_llgs = info.si_pid == getpid ();
-
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-
-    // POSIX says that process behaviour is undefined after it ignores a SIGFPE,
-    // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a
-    // kill(2) or raise(3).  Similarly for tgkill(2) on Linux.
-    //
-    // IOW, user generated signals never generate what we consider to be a
-    // "crash".
-    //
-    // Similarly, ACK signals generated by this monitor.
-
-    // Handle the signal.
-    if (info.si_code == SI_TKILL || info.si_code == SI_USER)
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() received signal %s (%d) with code %s, (siginfo pid = %d (%s), waitpid pid = %" PRIu64 ")",
-                            __FUNCTION__,
-                            Host::GetSignalAsCString(signo),
-                            signo,
-                            (info.si_code == SI_TKILL ? "SI_TKILL" : "SI_USER"),
-                            info.si_pid,
-                            is_from_llgs ? "from llgs" : "not from llgs",
-                            thread.GetID());
-    }
-
-    // Check for thread stop notification.
-    if (is_from_llgs && (info.si_code == SI_TKILL) && (signo == SIGSTOP))
-    {
-        // This is a tgkill()-based stop.
-        if (log)
-            log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 " tid %" PRIu64 ", thread stopped",
-                         __FUNCTION__,
-                         GetID (),
-                         thread.GetID());
-
-        // Check that we're not already marked with a stop reason.
-        // Note this thread really shouldn't already be marked as stopped - if we were, that would imply that
-        // the kernel signaled us with the thread stopping which we handled and marked as stopped,
-        // and that, without an intervening resume, we received another stop.  It is more likely
-        // that we are missing the marking of a run state somewhere if we find that the thread was
-        // marked as stopped.
-        const StateType thread_state = thread.GetState();
-        if (!StateIsStoppedState (thread_state, false))
-        {
-            // An inferior thread has stopped because of a SIGSTOP we have sent it.
-            // Generally, these are not important stops and we don't want to report them as
-            // they are just used to stop other threads when one thread (the one with the
-            // *real* stop reason) hits a breakpoint (watchpoint, etc...). However, in the
-            // case of an asynchronous Interrupt(), this *is* the real stop reason, so we
-            // leave the signal intact if this is the thread that was chosen as the
-            // triggering thread.
-            if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID)
-            {
-                if (m_pending_notification_tid == thread.GetID())
-                    thread.SetStoppedBySignal(SIGSTOP, &info);
-                else
-                    thread.SetStoppedWithNoReason();
-
-                SetCurrentThreadID (thread.GetID ());
-                SignalIfAllThreadsStopped();
-            }
-            else
-            {
-                // We can end up here if stop was initiated by LLGS but by this time a
-                // thread stop has occurred - maybe initiated by another event.
-                Error error = ResumeThread(thread, thread.GetState(), 0);
-                if (error.Fail() && log)
-                {
-                    log->Printf("NativeProcessLinux::%s failed to resume thread tid  %" PRIu64 ": %s",
-                            __FUNCTION__, thread.GetID(), error.AsCString());
-                }
-            }
-        }
+void NativeProcessLinux::MonitorWatchpoint(NativeThreadLinux &thread,
+                                           uint32_t wp_index) {
+  Log *log(
+      GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_WATCHPOINTS));
+  if (log)
+    log->Printf("NativeProcessLinux::%s() received watchpoint event, "
+                "pid = %" PRIu64 ", wp_index = %" PRIu32,
+                __FUNCTION__, thread.GetID(), wp_index);
+
+  // Mark the thread as stopped at watchpoint.
+  // The address is at (lldb::addr_t)info->si_addr if we need it.
+  thread.SetStoppedByWatchpoint(wp_index);
+
+  // We need to tell all other running threads before we notify the delegate
+  // about this stop.
+  StopRunningThreads(thread.GetID());
+}
+
+void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
+                                       NativeThreadLinux &thread, bool exited) {
+  const int signo = info.si_signo;
+  const bool is_from_llgs = info.si_pid == getpid();
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  // POSIX says that process behaviour is undefined after it ignores a SIGFPE,
+  // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a
+  // kill(2) or raise(3).  Similarly for tgkill(2) on Linux.
+  //
+  // IOW, user generated signals never generate what we consider to be a
+  // "crash".
+  //
+  // Similarly, ACK signals generated by this monitor.
+
+  // Handle the signal.
+  if (info.si_code == SI_TKILL || info.si_code == SI_USER) {
+    if (log)
+      log->Printf("NativeProcessLinux::%s() received signal %s (%d) with code "
+                  "%s, (siginfo pid = %d (%s), waitpid pid = %" PRIu64 ")",
+                  __FUNCTION__, Host::GetSignalAsCString(signo), signo,
+                  (info.si_code == SI_TKILL ? "SI_TKILL" : "SI_USER"),
+                  info.si_pid, is_from_llgs ? "from llgs" : "not from llgs",
+                  thread.GetID());
+  }
+
+  // Check for thread stop notification.
+  if (is_from_llgs && (info.si_code == SI_TKILL) && (signo == SIGSTOP)) {
+    // This is a tgkill()-based stop.
+    if (log)
+      log->Printf("NativeProcessLinux::%s() pid %" PRIu64 " tid %" PRIu64
+                  ", thread stopped",
+                  __FUNCTION__, GetID(), thread.GetID());
+
+    // Check that we're not already marked with a stop reason.
+    // Note this thread really shouldn't already be marked as stopped - if we
+    // were, that would imply that
+    // the kernel signaled us with the thread stopping which we handled and
+    // marked as stopped,
+    // and that, without an intervening resume, we received another stop.  It is
+    // more likely
+    // that we are missing the marking of a run state somewhere if we find that
+    // the thread was
+    // marked as stopped.
+    const StateType thread_state = thread.GetState();
+    if (!StateIsStoppedState(thread_state, false)) {
+      // An inferior thread has stopped because of a SIGSTOP we have sent it.
+      // Generally, these are not important stops and we don't want to report
+      // them as
+      // they are just used to stop other threads when one thread (the one with
+      // the
+      // *real* stop reason) hits a breakpoint (watchpoint, etc...). However, in
+      // the
+      // case of an asynchronous Interrupt(), this *is* the real stop reason, so
+      // we
+      // leave the signal intact if this is the thread that was chosen as the
+      // triggering thread.
+      if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID) {
+        if (m_pending_notification_tid == thread.GetID())
+          thread.SetStoppedBySignal(SIGSTOP, &info);
         else
-        {
-            if (log)
-            {
-                // Retrieve the signal name if the thread was stopped by a signal.
-                int stop_signo = 0;
-                const bool stopped_by_signal = thread.IsStopped(&stop_signo);
-                const char *signal_name = stopped_by_signal ? Host::GetSignalAsCString(stop_signo) : "<not stopped by signal>";
-                if (!signal_name)
-                    signal_name = "<no-signal-name>";
-
-                log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 " tid %" PRIu64 ", thread was already marked as a stopped state (state=%s, signal=%d (%s)), leaving stop signal as is",
-                             __FUNCTION__,
-                             GetID (),
-                             thread.GetID(),
-                             StateAsCString (thread_state),
-                             stop_signo,
-                             signal_name);
-            }
-            SignalIfAllThreadsStopped();
-        }
-
-        // Done handling.
-        return;
-    }
+          thread.SetStoppedWithNoReason();
 
-    if (log)
-        log->Printf ("NativeProcessLinux::%s() received signal %s", __FUNCTION__, Host::GetSignalAsCString(signo));
+        SetCurrentThreadID(thread.GetID());
+        SignalIfAllThreadsStopped();
+      } else {
+        // We can end up here if stop was initiated by LLGS but by this time a
+        // thread stop has occurred - maybe initiated by another event.
+        Error error = ResumeThread(thread, thread.GetState(), 0);
+        if (error.Fail() && log) {
+          log->Printf(
+              "NativeProcessLinux::%s failed to resume thread tid  %" PRIu64
+              ": %s",
+              __FUNCTION__, thread.GetID(), error.AsCString());
+        }
+      }
+    } else {
+      if (log) {
+        // Retrieve the signal name if the thread was stopped by a signal.
+        int stop_signo = 0;
+        const bool stopped_by_signal = thread.IsStopped(&stop_signo);
+        const char *signal_name = stopped_by_signal
+                                      ? Host::GetSignalAsCString(stop_signo)
+                                      : "<not stopped by signal>";
+        if (!signal_name)
+          signal_name = "<no-signal-name>";
+
+        log->Printf("NativeProcessLinux::%s() pid %" PRIu64 " tid %" PRIu64
+                    ", thread was already marked as a stopped state (state=%s, "
+                    "signal=%d (%s)), leaving stop signal as is",
+                    __FUNCTION__, GetID(), thread.GetID(),
+                    StateAsCString(thread_state), stop_signo, signal_name);
+      }
+      SignalIfAllThreadsStopped();
+    }
+
+    // Done handling.
+    return;
+  }
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s() received signal %s", __FUNCTION__,
+                Host::GetSignalAsCString(signo));
 
-    // This thread is stopped.
-    thread.SetStoppedBySignal(signo, &info);
+  // This thread is stopped.
+  thread.SetStoppedBySignal(signo, &info);
 
-    // Send a stop to the debugger after we get all other threads to stop.
-    StopRunningThreads(thread.GetID());
+  // Send a stop to the debugger after we get all other threads to stop.
+  StopRunningThreads(thread.GetID());
 }
 
 namespace {
 
-struct EmulatorBaton
-{
-    NativeProcessLinux* m_process;
-    NativeRegisterContext* m_reg_context;
+struct EmulatorBaton {
+  NativeProcessLinux *m_process;
+  NativeRegisterContext *m_reg_context;
 
-    // eRegisterKindDWARF -> RegsiterValue
-    std::unordered_map<uint32_t, RegisterValue> m_register_values;
+  // eRegisterKindDWARF -> RegsiterValue
+  std::unordered_map<uint32_t, RegisterValue> m_register_values;
 
-    EmulatorBaton(NativeProcessLinux* process, NativeRegisterContext* reg_context) :
-            m_process(process), m_reg_context(reg_context) {}
+  EmulatorBaton(NativeProcessLinux *process, NativeRegisterContext *reg_context)
+      : m_process(process), m_reg_context(reg_context) {}
 };
 
 } // anonymous namespace
 
-static size_t
-ReadMemoryCallback (EmulateInstruction *instruction,
-                    void *baton,
-                    const EmulateInstruction::Context &context, 
-                    lldb::addr_t addr, 
-                    void *dst,
-                    size_t length)
-{
-    EmulatorBaton* emulator_baton = static_cast<EmulatorBaton*>(baton);
-
-    size_t bytes_read;
-    emulator_baton->m_process->ReadMemory(addr, dst, length, bytes_read);
-    return bytes_read;
-}
-
-static bool
-ReadRegisterCallback (EmulateInstruction *instruction,
-                      void *baton,
-                      const RegisterInfo *reg_info,
-                      RegisterValue &reg_value)
-{
-    EmulatorBaton* emulator_baton = static_cast<EmulatorBaton*>(baton);
-
-    auto it = emulator_baton->m_register_values.find(reg_info->kinds[eRegisterKindDWARF]);
-    if (it != emulator_baton->m_register_values.end())
-    {
-        reg_value = it->second;
-        return true;
-    }
-
-    // The emulator only fill in the dwarf regsiter numbers (and in some case
-    // the generic register numbers). Get the full register info from the
-    // register context based on the dwarf register numbers.
-    const RegisterInfo* full_reg_info = emulator_baton->m_reg_context->GetRegisterInfo(
-            eRegisterKindDWARF, reg_info->kinds[eRegisterKindDWARF]);
-
-    Error error = emulator_baton->m_reg_context->ReadRegister(full_reg_info, reg_value);
-    if (error.Success())
-        return true;
-
-    return false;
-}
+static size_t ReadMemoryCallback(EmulateInstruction *instruction, void *baton,
+                                 const EmulateInstruction::Context &context,
+                                 lldb::addr_t addr, void *dst, size_t length) {
+  EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
+
+  size_t bytes_read;
+  emulator_baton->m_process->ReadMemory(addr, dst, length, bytes_read);
+  return bytes_read;
+}
+
+static bool ReadRegisterCallback(EmulateInstruction *instruction, void *baton,
+                                 const RegisterInfo *reg_info,
+                                 RegisterValue &reg_value) {
+  EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
+
+  auto it = emulator_baton->m_register_values.find(
+      reg_info->kinds[eRegisterKindDWARF]);
+  if (it != emulator_baton->m_register_values.end()) {
+    reg_value = it->second;
+    return true;
+  }
 
-static bool
-WriteRegisterCallback (EmulateInstruction *instruction,
-                       void *baton,
-                       const EmulateInstruction::Context &context,
-                       const RegisterInfo *reg_info,
-                       const RegisterValue &reg_value)
-{
-    EmulatorBaton* emulator_baton = static_cast<EmulatorBaton*>(baton);
-    emulator_baton->m_register_values[reg_info->kinds[eRegisterKindDWARF]] = reg_value;
+  // The emulator only fill in the dwarf regsiter numbers (and in some case
+  // the generic register numbers). Get the full register info from the
+  // register context based on the dwarf register numbers.
+  const RegisterInfo *full_reg_info =
+      emulator_baton->m_reg_context->GetRegisterInfo(
+          eRegisterKindDWARF, reg_info->kinds[eRegisterKindDWARF]);
+
+  Error error =
+      emulator_baton->m_reg_context->ReadRegister(full_reg_info, reg_value);
+  if (error.Success())
     return true;
-}
 
-static size_t
-WriteMemoryCallback (EmulateInstruction *instruction,
-                     void *baton,
-                     const EmulateInstruction::Context &context, 
-                     lldb::addr_t addr, 
-                     const void *dst,
-                     size_t length)
-{
-    return length;
+  return false;
 }
 
-static lldb::addr_t
-ReadFlags (NativeRegisterContext* regsiter_context)
-{
-    const RegisterInfo* flags_info = regsiter_context->GetRegisterInfo(
-            eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
-    return regsiter_context->ReadRegisterAsUnsigned(flags_info, LLDB_INVALID_ADDRESS);
-}
-
-Error
-NativeProcessLinux::SetupSoftwareSingleStepping(NativeThreadLinux &thread)
-{
-    Error error;
-    NativeRegisterContextSP register_context_sp = thread.GetRegisterContext();
-
-    std::unique_ptr<EmulateInstruction> emulator_ap(
-        EmulateInstruction::FindPlugin(m_arch, eInstructionTypePCModifying, nullptr));
-
-    if (emulator_ap == nullptr)
-        return Error("Instruction emulator not found!");
-
-    EmulatorBaton baton(this, register_context_sp.get());
-    emulator_ap->SetBaton(&baton);
-    emulator_ap->SetReadMemCallback(&ReadMemoryCallback);
-    emulator_ap->SetReadRegCallback(&ReadRegisterCallback);
-    emulator_ap->SetWriteMemCallback(&WriteMemoryCallback);
-    emulator_ap->SetWriteRegCallback(&WriteRegisterCallback);
-
-    if (!emulator_ap->ReadInstruction())
-        return Error("Read instruction failed!");
-
-    bool emulation_result = emulator_ap->EvaluateInstruction(eEmulateInstructionOptionAutoAdvancePC);
+static bool WriteRegisterCallback(EmulateInstruction *instruction, void *baton,
+                                  const EmulateInstruction::Context &context,
+                                  const RegisterInfo *reg_info,
+                                  const RegisterValue &reg_value) {
+  EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
+  emulator_baton->m_register_values[reg_info->kinds[eRegisterKindDWARF]] =
+      reg_value;
+  return true;
+}
+
+static size_t WriteMemoryCallback(EmulateInstruction *instruction, void *baton,
+                                  const EmulateInstruction::Context &context,
+                                  lldb::addr_t addr, const void *dst,
+                                  size_t length) {
+  return length;
+}
+
+static lldb::addr_t ReadFlags(NativeRegisterContext *regsiter_context) {
+  const RegisterInfo *flags_info = regsiter_context->GetRegisterInfo(
+      eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
+  return regsiter_context->ReadRegisterAsUnsigned(flags_info,
+                                                  LLDB_INVALID_ADDRESS);
+}
+
+Error NativeProcessLinux::SetupSoftwareSingleStepping(
+    NativeThreadLinux &thread) {
+  Error error;
+  NativeRegisterContextSP register_context_sp = thread.GetRegisterContext();
+
+  std::unique_ptr<EmulateInstruction> emulator_ap(
+      EmulateInstruction::FindPlugin(m_arch, eInstructionTypePCModifying,
+                                     nullptr));
+
+  if (emulator_ap == nullptr)
+    return Error("Instruction emulator not found!");
+
+  EmulatorBaton baton(this, register_context_sp.get());
+  emulator_ap->SetBaton(&baton);
+  emulator_ap->SetReadMemCallback(&ReadMemoryCallback);
+  emulator_ap->SetReadRegCallback(&ReadRegisterCallback);
+  emulator_ap->SetWriteMemCallback(&WriteMemoryCallback);
+  emulator_ap->SetWriteRegCallback(&WriteRegisterCallback);
+
+  if (!emulator_ap->ReadInstruction())
+    return Error("Read instruction failed!");
+
+  bool emulation_result =
+      emulator_ap->EvaluateInstruction(eEmulateInstructionOptionAutoAdvancePC);
+
+  const RegisterInfo *reg_info_pc = register_context_sp->GetRegisterInfo(
+      eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+  const RegisterInfo *reg_info_flags = register_context_sp->GetRegisterInfo(
+      eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
+
+  auto pc_it =
+      baton.m_register_values.find(reg_info_pc->kinds[eRegisterKindDWARF]);
+  auto flags_it =
+      baton.m_register_values.find(reg_info_flags->kinds[eRegisterKindDWARF]);
+
+  lldb::addr_t next_pc;
+  lldb::addr_t next_flags;
+  if (emulation_result) {
+    assert(pc_it != baton.m_register_values.end() &&
+           "Emulation was successfull but PC wasn't updated");
+    next_pc = pc_it->second.GetAsUInt64();
 
-    const RegisterInfo* reg_info_pc = register_context_sp->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
-    const RegisterInfo* reg_info_flags = register_context_sp->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
-
-    auto pc_it = baton.m_register_values.find(reg_info_pc->kinds[eRegisterKindDWARF]);
-    auto flags_it = baton.m_register_values.find(reg_info_flags->kinds[eRegisterKindDWARF]);
-
-    lldb::addr_t next_pc;
-    lldb::addr_t next_flags;
-    if (emulation_result)
-    {
-        assert(pc_it != baton.m_register_values.end() && "Emulation was successfull but PC wasn't updated");
-        next_pc = pc_it->second.GetAsUInt64();
-
-        if (flags_it != baton.m_register_values.end())
-            next_flags = flags_it->second.GetAsUInt64();
-        else
-            next_flags = ReadFlags (register_context_sp.get());
-    }
-    else if (pc_it == baton.m_register_values.end())
-    {
-        // Emulate instruction failed and it haven't changed PC. Advance PC
-        // with the size of the current opcode because the emulation of all
-        // PC modifying instruction should be successful. The failure most
-        // likely caused by a not supported instruction which don't modify PC.
-        next_pc = register_context_sp->GetPC() + emulator_ap->GetOpcode().GetByteSize();
-        next_flags = ReadFlags (register_context_sp.get());
-    }
-    else
-    {
-        // The instruction emulation failed after it modified the PC. It is an
-        // unknown error where we can't continue because the next instruction is
-        // modifying the PC but we don't  know how.
-        return Error ("Instruction emulation failed unexpectedly.");
-    }
-
-    if (m_arch.GetMachine() == llvm::Triple::arm)
-    {
-        if (next_flags & 0x20)
-        {
-            // Thumb mode
-            error = SetSoftwareBreakpoint(next_pc, 2);
-        }
-        else
-        {
-            // Arm mode
-            error = SetSoftwareBreakpoint(next_pc, 4);
-        }
-    }
-    else if (m_arch.GetMachine() == llvm::Triple::mips64
-            || m_arch.GetMachine() == llvm::Triple::mips64el
-            || m_arch.GetMachine() == llvm::Triple::mips
-            || m_arch.GetMachine() == llvm::Triple::mipsel)
-        error = SetSoftwareBreakpoint(next_pc, 4);
+    if (flags_it != baton.m_register_values.end())
+      next_flags = flags_it->second.GetAsUInt64();
     else
-    {
-        // No size hint is given for the next breakpoint
-        error = SetSoftwareBreakpoint(next_pc, 0);
-    }
-
-    if (error.Fail())
-        return error;
-
-    m_threads_stepping_with_breakpoint.insert({thread.GetID(), next_pc});
-
-    return Error();
-}
-
-bool
-NativeProcessLinux::SupportHardwareSingleStepping() const
-{
-    if (m_arch.GetMachine() == llvm::Triple::arm
-        || m_arch.GetMachine() == llvm::Triple::mips64 || m_arch.GetMachine() == llvm::Triple::mips64el
-        || m_arch.GetMachine() == llvm::Triple::mips || m_arch.GetMachine() == llvm::Triple::mipsel)
-        return false;
-    return true;
-}
-
-Error
-NativeProcessLinux::Resume (const ResumeActionList &resume_actions)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
-    if (log)
-        log->Printf ("NativeProcessLinux::%s called: pid %" PRIu64, __FUNCTION__, GetID ());
-
-    bool software_single_step = !SupportHardwareSingleStepping();
-
-    if (software_single_step)
-    {
-        for (auto thread_sp : m_threads)
-        {
-            assert (thread_sp && "thread list should not contain NULL threads");
-
-            const ResumeAction *const action = resume_actions.GetActionForThread (thread_sp->GetID (), true);
-            if (action == nullptr)
-                continue;
-
-            if (action->state == eStateStepping)
-            {
-                Error error = SetupSoftwareSingleStepping(static_cast<NativeThreadLinux &>(*thread_sp));
-                if (error.Fail())
-                    return error;
-            }
-        }
-    }
-
-    for (auto thread_sp : m_threads)
-    {
-        assert (thread_sp && "thread list should not contain NULL threads");
-
-        const ResumeAction *const action = resume_actions.GetActionForThread (thread_sp->GetID (), true);
-
-        if (action == nullptr)
-        {
-            if (log)
-                log->Printf ("NativeProcessLinux::%s no action specified for pid %" PRIu64 " tid %" PRIu64,
-                    __FUNCTION__, GetID (), thread_sp->GetID ());
-            continue;
-        }
-
-        if (log)
-        {
-            log->Printf ("NativeProcessLinux::%s processing resume action state %s for pid %" PRIu64 " tid %" PRIu64, 
-                    __FUNCTION__, StateAsCString (action->state), GetID (), thread_sp->GetID ());
-        }
-
-        switch (action->state)
-        {
-        case eStateRunning:
-        case eStateStepping:
-        {
-            // Run the thread, possibly feeding it the signal.
-            const int signo = action->signal;
-            ResumeThread(static_cast<NativeThreadLinux &>(*thread_sp), action->state, signo);
-            break;
-        }
-
-        case eStateSuspended:
-        case eStateStopped:
-            lldbassert(0 && "Unexpected state");
-
-        default:
-            return Error ("NativeProcessLinux::%s (): unexpected state %s specified for pid %" PRIu64 ", tid %" PRIu64,
-                    __FUNCTION__, StateAsCString (action->state), GetID (), thread_sp->GetID ());
-        }
+      next_flags = ReadFlags(register_context_sp.get());
+  } else if (pc_it == baton.m_register_values.end()) {
+    // Emulate instruction failed and it haven't changed PC. Advance PC
+    // with the size of the current opcode because the emulation of all
+    // PC modifying instruction should be successful. The failure most
+    // likely caused by a not supported instruction which don't modify PC.
+    next_pc =
+        register_context_sp->GetPC() + emulator_ap->GetOpcode().GetByteSize();
+    next_flags = ReadFlags(register_context_sp.get());
+  } else {
+    // The instruction emulation failed after it modified the PC. It is an
+    // unknown error where we can't continue because the next instruction is
+    // modifying the PC but we don't  know how.
+    return Error("Instruction emulation failed unexpectedly.");
+  }
+
+  if (m_arch.GetMachine() == llvm::Triple::arm) {
+    if (next_flags & 0x20) {
+      // Thumb mode
+      error = SetSoftwareBreakpoint(next_pc, 2);
+    } else {
+      // Arm mode
+      error = SetSoftwareBreakpoint(next_pc, 4);
     }
+  } else if (m_arch.GetMachine() == llvm::Triple::mips64 ||
+             m_arch.GetMachine() == llvm::Triple::mips64el ||
+             m_arch.GetMachine() == llvm::Triple::mips ||
+             m_arch.GetMachine() == llvm::Triple::mipsel)
+    error = SetSoftwareBreakpoint(next_pc, 4);
+  else {
+    // No size hint is given for the next breakpoint
+    error = SetSoftwareBreakpoint(next_pc, 0);
+  }
 
-    return Error();
-}
-
-Error
-NativeProcessLinux::Halt ()
-{
-    Error error;
-
-    if (kill (GetID (), SIGSTOP) != 0)
-        error.SetErrorToErrno ();
-
+  if (error.Fail())
     return error;
-}
-
-Error
-NativeProcessLinux::Detach ()
-{
-    Error error;
 
-    // Stop monitoring the inferior.
-    m_sigchld_handle.reset();
+  m_threads_stepping_with_breakpoint.insert({thread.GetID(), next_pc});
 
-    // Tell ptrace to detach from the process.
-    if (GetID () == LLDB_INVALID_PROCESS_ID)
-        return error;
-
-    for (auto thread_sp : m_threads)
-    {
-        Error e = Detach(thread_sp->GetID());
-        if (e.Fail())
-            error = e; // Save the error, but still attempt to detach from other threads.
-    }
-
-    return error;
+  return Error();
 }
 
-Error
-NativeProcessLinux::Signal (int signo)
-{
-    Error error;
-
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-    if (log)
-        log->Printf ("NativeProcessLinux::%s: sending signal %d (%s) to pid %" PRIu64,
-                __FUNCTION__, signo, Host::GetSignalAsCString(signo), GetID());
-
-    if (kill(GetID(), signo))
-        error.SetErrorToErrno();
-
-    return error;
+bool NativeProcessLinux::SupportHardwareSingleStepping() const {
+  if (m_arch.GetMachine() == llvm::Triple::arm ||
+      m_arch.GetMachine() == llvm::Triple::mips64 ||
+      m_arch.GetMachine() == llvm::Triple::mips64el ||
+      m_arch.GetMachine() == llvm::Triple::mips ||
+      m_arch.GetMachine() == llvm::Triple::mipsel)
+    return false;
+  return true;
 }
 
-Error
-NativeProcessLinux::Interrupt ()
-{
-    // Pick a running thread (or if none, a not-dead stopped thread) as
-    // the chosen thread that will be the stop-reason thread.
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+Error NativeProcessLinux::Resume(const ResumeActionList &resume_actions) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
+  if (log)
+    log->Printf("NativeProcessLinux::%s called: pid %" PRIu64, __FUNCTION__,
+                GetID());
 
-    NativeThreadProtocolSP running_thread_sp;
-    NativeThreadProtocolSP stopped_thread_sp;
-        
-    if (log)
-        log->Printf ("NativeProcessLinux::%s selecting running thread for interrupt target", __FUNCTION__);
+  bool software_single_step = !SupportHardwareSingleStepping();
 
-    for (auto thread_sp : m_threads)
-    {
-        // The thread shouldn't be null but lets just cover that here.
-        if (!thread_sp)
-            continue;
-
-        // If we have a running or stepping thread, we'll call that the
-        // target of the interrupt.
-        const auto thread_state = thread_sp->GetState ();
-        if (thread_state == eStateRunning ||
-            thread_state == eStateStepping)
-        {
-            running_thread_sp = thread_sp;
-            break;
-        }
-        else if (!stopped_thread_sp && StateIsStoppedState (thread_state, true))
-        {
-            // Remember the first non-dead stopped thread.  We'll use that as a backup if there are no running threads.
-            stopped_thread_sp = thread_sp;
-        }
-    }
+  if (software_single_step) {
+    for (auto thread_sp : m_threads) {
+      assert(thread_sp && "thread list should not contain NULL threads");
 
-    if (!running_thread_sp && !stopped_thread_sp)
-    {
-        Error error("found no running/stepping or live stopped threads as target for interrupt");
-        if (log)
-            log->Printf ("NativeProcessLinux::%s skipping due to error: %s", __FUNCTION__, error.AsCString ());
+      const ResumeAction *const action =
+          resume_actions.GetActionForThread(thread_sp->GetID(), true);
+      if (action == nullptr)
+        continue;
 
-        return error;
+      if (action->state == eStateStepping) {
+        Error error = SetupSoftwareSingleStepping(
+            static_cast<NativeThreadLinux &>(*thread_sp));
+        if (error.Fail())
+          return error;
+      }
     }
+  }
 
-    NativeThreadProtocolSP deferred_signal_thread_sp = running_thread_sp ? running_thread_sp : stopped_thread_sp;
-
-    if (log)
-        log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " %s tid %" PRIu64 " chosen for interrupt target",
-                     __FUNCTION__,
-                     GetID (),
-                     running_thread_sp ? "running" : "stopped",
-                     deferred_signal_thread_sp->GetID ());
-
-    StopRunningThreads(deferred_signal_thread_sp->GetID());
+  for (auto thread_sp : m_threads) {
+    assert(thread_sp && "thread list should not contain NULL threads");
 
-    return Error();
-}
+    const ResumeAction *const action =
+        resume_actions.GetActionForThread(thread_sp->GetID(), true);
 
-Error
-NativeProcessLinux::Kill ()
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-    if (log)
-        log->Printf ("NativeProcessLinux::%s called for PID %" PRIu64, __FUNCTION__, GetID ());
-
-    Error error;
-
-    switch (m_state)
-    {
-        case StateType::eStateInvalid:
-        case StateType::eStateExited:
-        case StateType::eStateCrashed:
-        case StateType::eStateDetached:
-        case StateType::eStateUnloaded:
-            // Nothing to do - the process is already dead.
-            if (log)
-                log->Printf ("NativeProcessLinux::%s ignored for PID %" PRIu64 " due to current state: %s", __FUNCTION__, GetID (), StateAsCString (m_state));
-            return error;
-
-        case StateType::eStateConnected:
-        case StateType::eStateAttaching:
-        case StateType::eStateLaunching:
-        case StateType::eStateStopped:
-        case StateType::eStateRunning:
-        case StateType::eStateStepping:
-        case StateType::eStateSuspended:
-            // We can try to kill a process in these states.
-            break;
+    if (action == nullptr) {
+      if (log)
+        log->Printf(
+            "NativeProcessLinux::%s no action specified for pid %" PRIu64
+            " tid %" PRIu64,
+            __FUNCTION__, GetID(), thread_sp->GetID());
+      continue;
     }
 
-    if (kill (GetID (), SIGKILL) != 0)
-    {
-        error.SetErrorToErrno ();
-        return error;
+    if (log) {
+      log->Printf("NativeProcessLinux::%s processing resume action state %s "
+                  "for pid %" PRIu64 " tid %" PRIu64,
+                  __FUNCTION__, StateAsCString(action->state), GetID(),
+                  thread_sp->GetID());
     }
 
-    return error;
-}
-
-static Error
-ParseMemoryRegionInfoFromProcMapsLine (const std::string &maps_line, MemoryRegionInfo &memory_region_info)
-{
-    memory_region_info.Clear();
-
-    StringExtractor line_extractor (maps_line.c_str ());
-
-    // Format: {address_start_hex}-{address_end_hex} perms offset  dev   inode   pathname
-    // perms: rwxp   (letter is present if set, '-' if not, final character is p=private, s=shared).
-
-    // Parse out the starting address
-    lldb::addr_t start_address = line_extractor.GetHexMaxU64 (false, 0);
-
-    // Parse out hyphen separating start and end address from range.
-    if (!line_extractor.GetBytesLeft () || (line_extractor.GetChar () != '-'))
-        return Error ("malformed /proc/{pid}/maps entry, missing dash between address range");
-
-    // Parse out the ending address
-    lldb::addr_t end_address = line_extractor.GetHexMaxU64 (false, start_address);
-
-    // Parse out the space after the address.
-    if (!line_extractor.GetBytesLeft () || (line_extractor.GetChar () != ' '))
-        return Error ("malformed /proc/{pid}/maps entry, missing space after range");
-
-    // Save the range.
-    memory_region_info.GetRange ().SetRangeBase (start_address);
-    memory_region_info.GetRange ().SetRangeEnd (end_address);
-
-    // Any memory region in /proc/{pid}/maps is by definition mapped into the process.
-    memory_region_info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
-
-    // Parse out each permission entry.
-    if (line_extractor.GetBytesLeft () < 4)
-        return Error ("malformed /proc/{pid}/maps entry, missing some portion of permissions");
-
-    // Handle read permission.
-    const char read_perm_char = line_extractor.GetChar ();
-    if (read_perm_char == 'r')
-        memory_region_info.SetReadable (MemoryRegionInfo::OptionalBool::eYes);
-    else if (read_perm_char == '-')
-        memory_region_info.SetReadable (MemoryRegionInfo::OptionalBool::eNo);
-    else
-        return Error ("unexpected /proc/{pid}/maps read permission char");
-
-    // Handle write permission.
-    const char write_perm_char = line_extractor.GetChar ();
-    if (write_perm_char == 'w')
-        memory_region_info.SetWritable (MemoryRegionInfo::OptionalBool::eYes);
-    else if (write_perm_char == '-')
-        memory_region_info.SetWritable (MemoryRegionInfo::OptionalBool::eNo);
-    else
-        return Error ("unexpected /proc/{pid}/maps write permission char");
-
-    // Handle execute permission.
-    const char exec_perm_char = line_extractor.GetChar ();
-    if (exec_perm_char == 'x')
-        memory_region_info.SetExecutable (MemoryRegionInfo::OptionalBool::eYes);
-    else if (exec_perm_char == '-')
-        memory_region_info.SetExecutable (MemoryRegionInfo::OptionalBool::eNo);
-    else
-        return Error ("unexpected /proc/{pid}/maps exec permission char");
-
-    line_extractor.GetChar();              // Read the private bit
-    line_extractor.SkipSpaces();           // Skip the separator
-    line_extractor.GetHexMaxU64(false, 0); // Read the offset
-    line_extractor.GetHexMaxU64(false, 0); // Read the major device number
-    line_extractor.GetChar();              // Read the device id separator
-    line_extractor.GetHexMaxU64(false, 0); // Read the major device number
-    line_extractor.SkipSpaces();           // Skip the separator
-    line_extractor.GetU64(0, 10);          // Read the inode number
-
-    line_extractor.SkipSpaces();
-    const char* name = line_extractor.Peek();
-    if (name)
-        memory_region_info.SetName(name);
-
-    return Error ();
-}
-
-Error
-NativeProcessLinux::GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info)
-{
-    // FIXME review that the final memory region returned extends to the end of the virtual address space,
-    // with no perms if it is not mapped.
-
-    // Use an approach that reads memory regions from /proc/{pid}/maps.
-    // Assume proc maps entries are in ascending order.
-    // FIXME assert if we find differently.
-
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-    Error error;
-
-    if (m_supports_mem_region == LazyBool::eLazyBoolNo)
-    {
-        // We're done.
-        error.SetErrorString ("unsupported");
-        return error;
+    switch (action->state) {
+    case eStateRunning:
+    case eStateStepping: {
+      // Run the thread, possibly feeding it the signal.
+      const int signo = action->signal;
+      ResumeThread(static_cast<NativeThreadLinux &>(*thread_sp), action->state,
+                   signo);
+      break;
     }
 
-    // If our cache is empty, pull the latest.  There should always be at least one memory region
-    // if memory region handling is supported.
-    if (m_mem_region_cache.empty ())
-    {
-        error = ProcFileReader::ProcessLineByLine (GetID (), "maps",
-             [&] (const std::string &line) -> bool
-             {
-                 MemoryRegionInfo info;
-                 const Error parse_error = ParseMemoryRegionInfoFromProcMapsLine (line, info);
-                 if (parse_error.Success ())
-                 {
-                     m_mem_region_cache.push_back (info);
-                     return true;
-                 }
-                 else
-                 {
-                     if (log)
-                         log->Printf ("NativeProcessLinux::%s failed to parse proc maps line '%s': %s", __FUNCTION__, line.c_str (), error.AsCString ());
-                     return false;
-                 }
-             });
-
-        // If we had an error, we'll mark unsupported.
-        if (error.Fail ())
-        {
-            m_supports_mem_region = LazyBool::eLazyBoolNo;
-            return error;
-        }
-        else if (m_mem_region_cache.empty ())
-        {
-            // No entries after attempting to read them.  This shouldn't happen if /proc/{pid}/maps
-            // is supported.  Assume we don't support map entries via procfs.
-            if (log)
-                log->Printf ("NativeProcessLinux::%s failed to find any procfs maps entries, assuming no support for memory region metadata retrieval", __FUNCTION__);
-            m_supports_mem_region = LazyBool::eLazyBoolNo;
-            error.SetErrorString ("not supported");
-            return error;
-        }
-
-        if (log)
-            log->Printf ("NativeProcessLinux::%s read %" PRIu64 " memory region entries from /proc/%" PRIu64 "/maps", __FUNCTION__, static_cast<uint64_t> (m_mem_region_cache.size ()), GetID ());
+    case eStateSuspended:
+    case eStateStopped:
+      lldbassert(0 && "Unexpected state");
 
-        // We support memory retrieval, remember that.
-        m_supports_mem_region = LazyBool::eLazyBoolYes;
-    }
-    else
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s reusing %" PRIu64 " cached memory region entries", __FUNCTION__, static_cast<uint64_t> (m_mem_region_cache.size ()));
+    default:
+      return Error("NativeProcessLinux::%s (): unexpected state %s specified "
+                   "for pid %" PRIu64 ", tid %" PRIu64,
+                   __FUNCTION__, StateAsCString(action->state), GetID(),
+                   thread_sp->GetID());
     }
+  }
 
-    lldb::addr_t prev_base_address = 0;
+  return Error();
+}
 
-    // FIXME start by finding the last region that is <= target address using binary search.  Data is sorted.
-    // There can be a ton of regions on pthreads apps with lots of threads.
-    for (auto it = m_mem_region_cache.begin(); it != m_mem_region_cache.end (); ++it)
-    {
-        MemoryRegionInfo &proc_entry_info = *it;
+Error NativeProcessLinux::Halt() {
+  Error error;
 
-        // Sanity check assumption that /proc/{pid}/maps entries are ascending.
-        assert ((proc_entry_info.GetRange ().GetRangeBase () >= prev_base_address) && "descending /proc/pid/maps entries detected, unexpected");
-        prev_base_address = proc_entry_info.GetRange ().GetRangeBase ();
-
-        // If the target address comes before this entry, indicate distance to next region.
-        if (load_addr < proc_entry_info.GetRange ().GetRangeBase ())
-        {
-            range_info.GetRange ().SetRangeBase (load_addr);
-            range_info.GetRange ().SetByteSize (proc_entry_info.GetRange ().GetRangeBase () - load_addr);
-            range_info.SetReadable (MemoryRegionInfo::OptionalBool::eNo);
-            range_info.SetWritable (MemoryRegionInfo::OptionalBool::eNo);
-            range_info.SetExecutable (MemoryRegionInfo::OptionalBool::eNo);
-            range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+  if (kill(GetID(), SIGSTOP) != 0)
+    error.SetErrorToErrno();
 
-            return error;
-        }
-        else if (proc_entry_info.GetRange ().Contains (load_addr))
-        {
-            // The target address is within the memory region we're processing here.
-            range_info = proc_entry_info;
-            return error;
-        }
+  return error;
+}
 
-        // The target memory address comes somewhere after the region we just parsed.
-    }
+Error NativeProcessLinux::Detach() {
+  Error error;
+
+  // Stop monitoring the inferior.
+  m_sigchld_handle.reset();
 
-    // If we made it here, we didn't find an entry that contained the given address. Return the
-    // load_addr as start and the amount of bytes betwwen load address and the end of the memory as
-    // size.
-    range_info.GetRange ().SetRangeBase (load_addr);
-    range_info.GetRange ().SetRangeEnd(LLDB_INVALID_ADDRESS);
-    range_info.SetReadable (MemoryRegionInfo::OptionalBool::eNo);
-    range_info.SetWritable (MemoryRegionInfo::OptionalBool::eNo);
-    range_info.SetExecutable (MemoryRegionInfo::OptionalBool::eNo);
-    range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+  // Tell ptrace to detach from the process.
+  if (GetID() == LLDB_INVALID_PROCESS_ID)
     return error;
-}
 
-void
-NativeProcessLinux::DoStopIDBumped (uint32_t newBumpId)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+  for (auto thread_sp : m_threads) {
+    Error e = Detach(thread_sp->GetID());
+    if (e.Fail())
+      error =
+          e; // Save the error, but still attempt to detach from other threads.
+  }
+
+  return error;
+}
+
+Error NativeProcessLinux::Signal(int signo) {
+  Error error;
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf(
+        "NativeProcessLinux::%s: sending signal %d (%s) to pid %" PRIu64,
+        __FUNCTION__, signo, Host::GetSignalAsCString(signo), GetID());
+
+  if (kill(GetID(), signo))
+    error.SetErrorToErrno();
+
+  return error;
+}
+
+Error NativeProcessLinux::Interrupt() {
+  // Pick a running thread (or if none, a not-dead stopped thread) as
+  // the chosen thread that will be the stop-reason thread.
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  NativeThreadProtocolSP running_thread_sp;
+  NativeThreadProtocolSP stopped_thread_sp;
+
+  if (log)
+    log->Printf(
+        "NativeProcessLinux::%s selecting running thread for interrupt target",
+        __FUNCTION__);
+
+  for (auto thread_sp : m_threads) {
+    // The thread shouldn't be null but lets just cover that here.
+    if (!thread_sp)
+      continue;
+
+    // If we have a running or stepping thread, we'll call that the
+    // target of the interrupt.
+    const auto thread_state = thread_sp->GetState();
+    if (thread_state == eStateRunning || thread_state == eStateStepping) {
+      running_thread_sp = thread_sp;
+      break;
+    } else if (!stopped_thread_sp && StateIsStoppedState(thread_state, true)) {
+      // Remember the first non-dead stopped thread.  We'll use that as a backup
+      // if there are no running threads.
+      stopped_thread_sp = thread_sp;
+    }
+  }
+
+  if (!running_thread_sp && !stopped_thread_sp) {
+    Error error("found no running/stepping or live stopped threads as target "
+                "for interrupt");
     if (log)
-        log->Printf ("NativeProcessLinux::%s(newBumpId=%" PRIu32 ") called", __FUNCTION__, newBumpId);
+      log->Printf("NativeProcessLinux::%s skipping due to error: %s",
+                  __FUNCTION__, error.AsCString());
 
-        if (log)
-            log->Printf ("NativeProcessLinux::%s clearing %" PRIu64 " entries from the cache", __FUNCTION__, static_cast<uint64_t> (m_mem_region_cache.size ()));
-        m_mem_region_cache.clear ();
+    return error;
+  }
+
+  NativeThreadProtocolSP deferred_signal_thread_sp =
+      running_thread_sp ? running_thread_sp : stopped_thread_sp;
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s pid %" PRIu64 " %s tid %" PRIu64
+                " chosen for interrupt target",
+                __FUNCTION__, GetID(),
+                running_thread_sp ? "running" : "stopped",
+                deferred_signal_thread_sp->GetID());
+
+  StopRunningThreads(deferred_signal_thread_sp->GetID());
+
+  return Error();
+}
+
+Error NativeProcessLinux::Kill() {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf("NativeProcessLinux::%s called for PID %" PRIu64, __FUNCTION__,
+                GetID());
+
+  Error error;
+
+  switch (m_state) {
+  case StateType::eStateInvalid:
+  case StateType::eStateExited:
+  case StateType::eStateCrashed:
+  case StateType::eStateDetached:
+  case StateType::eStateUnloaded:
+    // Nothing to do - the process is already dead.
+    if (log)
+      log->Printf("NativeProcessLinux::%s ignored for PID %" PRIu64
+                  " due to current state: %s",
+                  __FUNCTION__, GetID(), StateAsCString(m_state));
+    return error;
+
+  case StateType::eStateConnected:
+  case StateType::eStateAttaching:
+  case StateType::eStateLaunching:
+  case StateType::eStateStopped:
+  case StateType::eStateRunning:
+  case StateType::eStateStepping:
+  case StateType::eStateSuspended:
+    // We can try to kill a process in these states.
+    break;
+  }
+
+  if (kill(GetID(), SIGKILL) != 0) {
+    error.SetErrorToErrno();
+    return error;
+  }
+
+  return error;
 }
 
-Error
-NativeProcessLinux::AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr)
-{
-    // FIXME implementing this requires the equivalent of
-    // InferiorCallPOSIX::InferiorCallMmap, which depends on
-    // functional ThreadPlans working with Native*Protocol.
+static Error
+ParseMemoryRegionInfoFromProcMapsLine(const std::string &maps_line,
+                                      MemoryRegionInfo &memory_region_info) {
+  memory_region_info.Clear();
+
+  StringExtractor line_extractor(maps_line.c_str());
+
+  // Format: {address_start_hex}-{address_end_hex} perms offset  dev   inode
+  // pathname
+  // perms: rwxp   (letter is present if set, '-' if not, final character is
+  // p=private, s=shared).
+
+  // Parse out the starting address
+  lldb::addr_t start_address = line_extractor.GetHexMaxU64(false, 0);
+
+  // Parse out hyphen separating start and end address from range.
+  if (!line_extractor.GetBytesLeft() || (line_extractor.GetChar() != '-'))
+    return Error(
+        "malformed /proc/{pid}/maps entry, missing dash between address range");
+
+  // Parse out the ending address
+  lldb::addr_t end_address = line_extractor.GetHexMaxU64(false, start_address);
+
+  // Parse out the space after the address.
+  if (!line_extractor.GetBytesLeft() || (line_extractor.GetChar() != ' '))
+    return Error("malformed /proc/{pid}/maps entry, missing space after range");
+
+  // Save the range.
+  memory_region_info.GetRange().SetRangeBase(start_address);
+  memory_region_info.GetRange().SetRangeEnd(end_address);
+
+  // Any memory region in /proc/{pid}/maps is by definition mapped into the
+  // process.
+  memory_region_info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
+
+  // Parse out each permission entry.
+  if (line_extractor.GetBytesLeft() < 4)
+    return Error("malformed /proc/{pid}/maps entry, missing some portion of "
+                 "permissions");
+
+  // Handle read permission.
+  const char read_perm_char = line_extractor.GetChar();
+  if (read_perm_char == 'r')
+    memory_region_info.SetReadable(MemoryRegionInfo::OptionalBool::eYes);
+  else if (read_perm_char == '-')
+    memory_region_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+  else
+    return Error("unexpected /proc/{pid}/maps read permission char");
+
+  // Handle write permission.
+  const char write_perm_char = line_extractor.GetChar();
+  if (write_perm_char == 'w')
+    memory_region_info.SetWritable(MemoryRegionInfo::OptionalBool::eYes);
+  else if (write_perm_char == '-')
+    memory_region_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+  else
+    return Error("unexpected /proc/{pid}/maps write permission char");
+
+  // Handle execute permission.
+  const char exec_perm_char = line_extractor.GetChar();
+  if (exec_perm_char == 'x')
+    memory_region_info.SetExecutable(MemoryRegionInfo::OptionalBool::eYes);
+  else if (exec_perm_char == '-')
+    memory_region_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+  else
+    return Error("unexpected /proc/{pid}/maps exec permission char");
+
+  line_extractor.GetChar();              // Read the private bit
+  line_extractor.SkipSpaces();           // Skip the separator
+  line_extractor.GetHexMaxU64(false, 0); // Read the offset
+  line_extractor.GetHexMaxU64(false, 0); // Read the major device number
+  line_extractor.GetChar();              // Read the device id separator
+  line_extractor.GetHexMaxU64(false, 0); // Read the major device number
+  line_extractor.SkipSpaces();           // Skip the separator
+  line_extractor.GetU64(0, 10);          // Read the inode number
+
+  line_extractor.SkipSpaces();
+  const char *name = line_extractor.Peek();
+  if (name)
+    memory_region_info.SetName(name);
+
+  return Error();
+}
+
+Error NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
+                                              MemoryRegionInfo &range_info) {
+  // FIXME review that the final memory region returned extends to the end of
+  // the virtual address space,
+  // with no perms if it is not mapped.
+
+  // Use an approach that reads memory regions from /proc/{pid}/maps.
+  // Assume proc maps entries are in ascending order.
+  // FIXME assert if we find differently.
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  Error error;
+
+  if (m_supports_mem_region == LazyBool::eLazyBoolNo) {
+    // We're done.
+    error.SetErrorString("unsupported");
+    return error;
+  }
+
+  // If our cache is empty, pull the latest.  There should always be at least
+  // one memory region
+  // if memory region handling is supported.
+  if (m_mem_region_cache.empty()) {
+    error = ProcFileReader::ProcessLineByLine(
+        GetID(), "maps", [&](const std::string &line) -> bool {
+          MemoryRegionInfo info;
+          const Error parse_error =
+              ParseMemoryRegionInfoFromProcMapsLine(line, info);
+          if (parse_error.Success()) {
+            m_mem_region_cache.push_back(info);
+            return true;
+          } else {
+            if (log)
+              log->Printf("NativeProcessLinux::%s failed to parse proc maps "
+                          "line '%s': %s",
+                          __FUNCTION__, line.c_str(), error.AsCString());
+            return false;
+          }
+        });
+
+    // If we had an error, we'll mark unsupported.
+    if (error.Fail()) {
+      m_supports_mem_region = LazyBool::eLazyBoolNo;
+      return error;
+    } else if (m_mem_region_cache.empty()) {
+      // No entries after attempting to read them.  This shouldn't happen if
+      // /proc/{pid}/maps
+      // is supported.  Assume we don't support map entries via procfs.
+      if (log)
+        log->Printf("NativeProcessLinux::%s failed to find any procfs maps "
+                    "entries, assuming no support for memory region metadata "
+                    "retrieval",
+                    __FUNCTION__);
+      m_supports_mem_region = LazyBool::eLazyBoolNo;
+      error.SetErrorString("not supported");
+      return error;
+    }
+
+    if (log)
+      log->Printf("NativeProcessLinux::%s read %" PRIu64
+                  " memory region entries from /proc/%" PRIu64 "/maps",
+                  __FUNCTION__,
+                  static_cast<uint64_t>(m_mem_region_cache.size()), GetID());
+
+    // We support memory retrieval, remember that.
+    m_supports_mem_region = LazyBool::eLazyBoolYes;
+  } else {
+    if (log)
+      log->Printf("NativeProcessLinux::%s reusing %" PRIu64
+                  " cached memory region entries",
+                  __FUNCTION__,
+                  static_cast<uint64_t>(m_mem_region_cache.size()));
+  }
+
+  lldb::addr_t prev_base_address = 0;
+
+  // FIXME start by finding the last region that is <= target address using
+  // binary search.  Data is sorted.
+  // There can be a ton of regions on pthreads apps with lots of threads.
+  for (auto it = m_mem_region_cache.begin(); it != m_mem_region_cache.end();
+       ++it) {
+    MemoryRegionInfo &proc_entry_info = *it;
+
+    // Sanity check assumption that /proc/{pid}/maps entries are ascending.
+    assert((proc_entry_info.GetRange().GetRangeBase() >= prev_base_address) &&
+           "descending /proc/pid/maps entries detected, unexpected");
+    prev_base_address = proc_entry_info.GetRange().GetRangeBase();
+
+    // If the target address comes before this entry, indicate distance to next
+    // region.
+    if (load_addr < proc_entry_info.GetRange().GetRangeBase()) {
+      range_info.GetRange().SetRangeBase(load_addr);
+      range_info.GetRange().SetByteSize(
+          proc_entry_info.GetRange().GetRangeBase() - load_addr);
+      range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+      range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+      range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+      range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+
+      return error;
+    } else if (proc_entry_info.GetRange().Contains(load_addr)) {
+      // The target address is within the memory region we're processing here.
+      range_info = proc_entry_info;
+      return error;
+    }
+
+    // The target memory address comes somewhere after the region we just
+    // parsed.
+  }
+
+  // If we made it here, we didn't find an entry that contained the given
+  // address. Return the
+  // load_addr as start and the amount of bytes betwwen load address and the end
+  // of the memory as
+  // size.
+  range_info.GetRange().SetRangeBase(load_addr);
+  range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
+  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+  return error;
+}
+
+void NativeProcessLinux::DoStopIDBumped(uint32_t newBumpId) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log)
+    log->Printf("NativeProcessLinux::%s(newBumpId=%" PRIu32 ") called",
+                __FUNCTION__, newBumpId);
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s clearing %" PRIu64
+                " entries from the cache",
+                __FUNCTION__, static_cast<uint64_t>(m_mem_region_cache.size()));
+  m_mem_region_cache.clear();
+}
+
+Error NativeProcessLinux::AllocateMemory(size_t size, uint32_t permissions,
+                                         lldb::addr_t &addr) {
+// FIXME implementing this requires the equivalent of
+// InferiorCallPOSIX::InferiorCallMmap, which depends on
+// functional ThreadPlans working with Native*Protocol.
 #if 1
-    return Error ("not implemented yet");
+  return Error("not implemented yet");
 #else
-    addr = LLDB_INVALID_ADDRESS;
+  addr = LLDB_INVALID_ADDRESS;
 
-    unsigned prot = 0;
-    if (permissions & lldb::ePermissionsReadable)
-        prot |= eMmapProtRead;
-    if (permissions & lldb::ePermissionsWritable)
-        prot |= eMmapProtWrite;
-    if (permissions & lldb::ePermissionsExecutable)
-        prot |= eMmapProtExec;
-
-    // TODO implement this directly in NativeProcessLinux
-    // (and lift to NativeProcessPOSIX if/when that class is
-    // refactored out).
-    if (InferiorCallMmap(this, addr, 0, size, prot,
-                         eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
-        m_addr_to_mmap_size[addr] = size;
-        return Error ();
-    } else {
-        addr = LLDB_INVALID_ADDRESS;
-        return Error("unable to allocate %" PRIu64 " bytes of memory with permissions %s", size, GetPermissionsAsCString (permissions));
-    }
+  unsigned prot = 0;
+  if (permissions & lldb::ePermissionsReadable)
+    prot |= eMmapProtRead;
+  if (permissions & lldb::ePermissionsWritable)
+    prot |= eMmapProtWrite;
+  if (permissions & lldb::ePermissionsExecutable)
+    prot |= eMmapProtExec;
+
+  // TODO implement this directly in NativeProcessLinux
+  // (and lift to NativeProcessPOSIX if/when that class is
+  // refactored out).
+  if (InferiorCallMmap(this, addr, 0, size, prot,
+                       eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
+    m_addr_to_mmap_size[addr] = size;
+    return Error();
+  } else {
+    addr = LLDB_INVALID_ADDRESS;
+    return Error("unable to allocate %" PRIu64
+                 " bytes of memory with permissions %s",
+                 size, GetPermissionsAsCString(permissions));
+  }
 #endif
 }
 
-Error
-NativeProcessLinux::DeallocateMemory (lldb::addr_t addr)
-{
-    // FIXME see comments in AllocateMemory - required lower-level
-    // bits not in place yet (ThreadPlans)
-    return Error ("not implemented");
+Error NativeProcessLinux::DeallocateMemory(lldb::addr_t addr) {
+  // FIXME see comments in AllocateMemory - required lower-level
+  // bits not in place yet (ThreadPlans)
+  return Error("not implemented");
 }
 
-lldb::addr_t
-NativeProcessLinux::GetSharedLibraryInfoAddress ()
-{
-    // punt on this for now
-    return LLDB_INVALID_ADDRESS;
+lldb::addr_t NativeProcessLinux::GetSharedLibraryInfoAddress() {
+  // punt on this for now
+  return LLDB_INVALID_ADDRESS;
 }
 
-size_t
-NativeProcessLinux::UpdateThreads ()
-{
-    // The NativeProcessLinux monitoring threads are always up to date
-    // with respect to thread state and they keep the thread list
-    // populated properly. All this method needs to do is return the
-    // thread count.
-    return m_threads.size ();
+size_t NativeProcessLinux::UpdateThreads() {
+  // The NativeProcessLinux monitoring threads are always up to date
+  // with respect to thread state and they keep the thread list
+  // populated properly. All this method needs to do is return the
+  // thread count.
+  return m_threads.size();
 }
 
-bool
-NativeProcessLinux::GetArchitecture (ArchSpec &arch) const
-{
-    arch = m_arch;
-    return true;
+bool NativeProcessLinux::GetArchitecture(ArchSpec &arch) const {
+  arch = m_arch;
+  return true;
 }
 
-Error
-NativeProcessLinux::GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size)
-{
-    // FIXME put this behind a breakpoint protocol class that can be
-    // set per architecture.  Need ARM, MIPS support here.
-    static const uint8_t g_i386_opcode [] = { 0xCC };
-    static const uint8_t g_s390x_opcode[] = { 0x00, 0x01 };
-
-    switch (m_arch.GetMachine ())
-    {
-        case llvm::Triple::x86:
-        case llvm::Triple::x86_64:
-            actual_opcode_size = static_cast<uint32_t> (sizeof(g_i386_opcode));
-            return Error ();
-
-        case llvm::Triple::systemz:
-            actual_opcode_size = static_cast<uint32_t> (sizeof(g_s390x_opcode));
-            return Error ();
-
-        case llvm::Triple::arm:
-        case llvm::Triple::aarch64:
-        case llvm::Triple::mips64:
-        case llvm::Triple::mips64el:
-        case llvm::Triple::mips:
-        case llvm::Triple::mipsel:
-            // On these architectures the PC don't get updated for breakpoint hits
-            actual_opcode_size = 0;
-            return Error ();
-        
-        default:
-            assert(false && "CPU type not supported!");
-            return Error ("CPU type not supported");
-    }
-}
+Error NativeProcessLinux::GetSoftwareBreakpointPCOffset(
+    uint32_t &actual_opcode_size) {
+  // FIXME put this behind a breakpoint protocol class that can be
+  // set per architecture.  Need ARM, MIPS support here.
+  static const uint8_t g_i386_opcode[] = {0xCC};
+  static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
 
-Error
-NativeProcessLinux::SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware)
-{
-    if (hardware)
-        return Error ("NativeProcessLinux does not support hardware breakpoints");
-    else
-        return SetSoftwareBreakpoint (addr, size);
-}
+  switch (m_arch.GetMachine()) {
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+    actual_opcode_size = static_cast<uint32_t>(sizeof(g_i386_opcode));
+    return Error();
 
-Error
-NativeProcessLinux::GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint,
-                                                     size_t &actual_opcode_size,
-                                                     const uint8_t *&trap_opcode_bytes)
-{
-    // FIXME put this behind a breakpoint protocol class that can be set per
-    // architecture.  Need MIPS support here.
-    static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xd4 };
-    // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the
-    // linux kernel does otherwise.
-    static const uint8_t g_arm_breakpoint_opcode[] = { 0xf0, 0x01, 0xf0, 0xe7 };
-    static const uint8_t g_i386_opcode [] = { 0xCC };
-    static const uint8_t g_mips64_opcode[] = { 0x00, 0x00, 0x00, 0x0d };
-    static const uint8_t g_mips64el_opcode[] = { 0x0d, 0x00, 0x00, 0x00 };
-    static const uint8_t g_s390x_opcode[] = { 0x00, 0x01 };
-    static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde };
+  case llvm::Triple::systemz:
+    actual_opcode_size = static_cast<uint32_t>(sizeof(g_s390x_opcode));
+    return Error();
 
-    switch (m_arch.GetMachine ())
-    {
-    case llvm::Triple::aarch64:
-        trap_opcode_bytes = g_aarch64_opcode;
-        actual_opcode_size = sizeof(g_aarch64_opcode);
-        return Error ();
-
-    case llvm::Triple::arm:
-        switch (trap_opcode_size_hint)
-        {
-        case 2:
-            trap_opcode_bytes = g_thumb_breakpoint_opcode;
-            actual_opcode_size = sizeof(g_thumb_breakpoint_opcode);
-            return Error ();
-        case 4:
-            trap_opcode_bytes = g_arm_breakpoint_opcode;
-            actual_opcode_size = sizeof(g_arm_breakpoint_opcode);
-            return Error ();
-        default:
-            assert(false && "Unrecognised trap opcode size hint!");
-            return Error ("Unrecognised trap opcode size hint!");
-        }
+  case llvm::Triple::arm:
+  case llvm::Triple::aarch64:
+  case llvm::Triple::mips64:
+  case llvm::Triple::mips64el:
+  case llvm::Triple::mips:
+  case llvm::Triple::mipsel:
+    // On these architectures the PC don't get updated for breakpoint hits
+    actual_opcode_size = 0;
+    return Error();
 
-    case llvm::Triple::x86:
-    case llvm::Triple::x86_64:
-        trap_opcode_bytes = g_i386_opcode;
-        actual_opcode_size = sizeof(g_i386_opcode);
-        return Error ();
-
-    case llvm::Triple::mips:
-    case llvm::Triple::mips64:
-        trap_opcode_bytes = g_mips64_opcode;
-        actual_opcode_size = sizeof(g_mips64_opcode);
-        return Error ();
-
-    case llvm::Triple::mipsel:
-    case llvm::Triple::mips64el:
-        trap_opcode_bytes = g_mips64el_opcode;
-        actual_opcode_size = sizeof(g_mips64el_opcode);
-        return Error ();
-
-    case llvm::Triple::systemz:
-        trap_opcode_bytes = g_s390x_opcode;
-        actual_opcode_size = sizeof(g_s390x_opcode);
-        return Error ();
+  default:
+    assert(false && "CPU type not supported!");
+    return Error("CPU type not supported");
+  }
+}
+
+Error NativeProcessLinux::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+                                        bool hardware) {
+  if (hardware)
+    return Error("NativeProcessLinux does not support hardware breakpoints");
+  else
+    return SetSoftwareBreakpoint(addr, size);
+}
+
+Error NativeProcessLinux::GetSoftwareBreakpointTrapOpcode(
+    size_t trap_opcode_size_hint, size_t &actual_opcode_size,
+    const uint8_t *&trap_opcode_bytes) {
+  // FIXME put this behind a breakpoint protocol class that can be set per
+  // architecture.  Need MIPS support here.
+  static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
+  // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the
+  // linux kernel does otherwise.
+  static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
+  static const uint8_t g_i386_opcode[] = {0xCC};
+  static const uint8_t g_mips64_opcode[] = {0x00, 0x00, 0x00, 0x0d};
+  static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00};
+  static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
+  static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
+
+  switch (m_arch.GetMachine()) {
+  case llvm::Triple::aarch64:
+    trap_opcode_bytes = g_aarch64_opcode;
+    actual_opcode_size = sizeof(g_aarch64_opcode);
+    return Error();
 
+  case llvm::Triple::arm:
+    switch (trap_opcode_size_hint) {
+    case 2:
+      trap_opcode_bytes = g_thumb_breakpoint_opcode;
+      actual_opcode_size = sizeof(g_thumb_breakpoint_opcode);
+      return Error();
+    case 4:
+      trap_opcode_bytes = g_arm_breakpoint_opcode;
+      actual_opcode_size = sizeof(g_arm_breakpoint_opcode);
+      return Error();
     default:
-        assert(false && "CPU type not supported!");
-        return Error ("CPU type not supported");
+      assert(false && "Unrecognised trap opcode size hint!");
+      return Error("Unrecognised trap opcode size hint!");
     }
+
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+    trap_opcode_bytes = g_i386_opcode;
+    actual_opcode_size = sizeof(g_i386_opcode);
+    return Error();
+
+  case llvm::Triple::mips:
+  case llvm::Triple::mips64:
+    trap_opcode_bytes = g_mips64_opcode;
+    actual_opcode_size = sizeof(g_mips64_opcode);
+    return Error();
+
+  case llvm::Triple::mipsel:
+  case llvm::Triple::mips64el:
+    trap_opcode_bytes = g_mips64el_opcode;
+    actual_opcode_size = sizeof(g_mips64el_opcode);
+    return Error();
+
+  case llvm::Triple::systemz:
+    trap_opcode_bytes = g_s390x_opcode;
+    actual_opcode_size = sizeof(g_s390x_opcode);
+    return Error();
+
+  default:
+    assert(false && "CPU type not supported!");
+    return Error("CPU type not supported");
+  }
 }
 
 #if 0
@@ -2012,7 +2009,6 @@ NativeProcessLinux::GetCrashReasonForSIG
 }
 #endif
 
-
 #if 0
 ProcessMessage::CrashReason
 NativeProcessLinux::GetCrashReasonForSIGILL(const siginfo_t *info)
@@ -2130,640 +2126,628 @@ NativeProcessLinux::GetCrashReasonForSIG
 }
 #endif
 
-Error
-NativeProcessLinux::ReadMemory (lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
-{
-    if (ProcessVmReadvSupported()) {
-        // The process_vm_readv path is about 50 times faster than ptrace api. We want to use
-        // this syscall if it is supported.
-
-        const ::pid_t pid = GetID();
-
-        struct iovec local_iov, remote_iov;
-        local_iov.iov_base = buf;
-        local_iov.iov_len = size;
-        remote_iov.iov_base = reinterpret_cast<void *>(addr);
-        remote_iov.iov_len = size;
-
-        bytes_read = process_vm_readv(pid, &local_iov, 1, &remote_iov, 1, 0);
-        const bool success = bytes_read == size;
-
-        Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
-        if (log)
-            log->Printf ("NativeProcessLinux::%s using process_vm_readv to read %zd bytes from inferior address 0x%" PRIx64": %s",
-                    __FUNCTION__, size, addr, success ? "Success" : strerror(errno));
-
-        if (success)
-            return Error();
-        // else
-        //     the call failed for some reason, let's retry the read using ptrace api.
-    }
+Error NativeProcessLinux::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+                                     size_t &bytes_read) {
+  if (ProcessVmReadvSupported()) {
+    // The process_vm_readv path is about 50 times faster than ptrace api. We
+    // want to use
+    // this syscall if it is supported.
+
+    const ::pid_t pid = GetID();
+
+    struct iovec local_iov, remote_iov;
+    local_iov.iov_base = buf;
+    local_iov.iov_len = size;
+    remote_iov.iov_base = reinterpret_cast<void *>(addr);
+    remote_iov.iov_len = size;
 
-    unsigned char *dst = static_cast<unsigned char*>(buf);
-    size_t remainder;
-    long data;
+    bytes_read = process_vm_readv(pid, &local_iov, 1, &remote_iov, 1, 0);
+    const bool success = bytes_read == size;
 
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_ALL));
+    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
     if (log)
-        ProcessPOSIXLog::IncNestLevel();
-    if (log && ProcessPOSIXLog::AtTopNestLevel() && log->GetMask().Test(POSIX_LOG_MEMORY))
-        log->Printf ("NativeProcessLinux::%s(%p, %p, %zd, _)", __FUNCTION__, (void*)addr, buf, size);
-
-    for (bytes_read = 0; bytes_read < size; bytes_read += remainder)
-    {
-        Error error = NativeProcessLinux::PtraceWrapper(PTRACE_PEEKDATA, GetID(), (void*)addr, nullptr, 0, &data);
-        if (error.Fail())
-        {
-            if (log)
-                ProcessPOSIXLog::DecNestLevel();
-            return error;
-        }
-
-        remainder = size - bytes_read;
-        remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
-
-        // Copy the data into our buffer
-        memcpy(dst, &data, remainder);
-
-        if (log && ProcessPOSIXLog::AtTopNestLevel() &&
-                (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
-                        (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
-                                size <= POSIX_LOG_MEMORY_SHORT_BYTES)))
-        {
-            uintptr_t print_dst = 0;
-            // Format bytes from data by moving into print_dst for log output
-            for (unsigned i = 0; i < remainder; ++i)
-                print_dst |= (((data >> i*8) & 0xFF) << i*8);
-            log->Printf ("NativeProcessLinux::%s() [0x%" PRIx64 "]:0x%" PRIx64 " (0x%" PRIx64 ")",
-                    __FUNCTION__, addr, uint64_t(print_dst), uint64_t(data));
-        }
-        addr += k_ptrace_word_size;
-        dst += k_ptrace_word_size;
+      log->Printf("NativeProcessLinux::%s using process_vm_readv to read %zd "
+                  "bytes from inferior address 0x%" PRIx64 ": %s",
+                  __FUNCTION__, size, addr,
+                  success ? "Success" : strerror(errno));
+
+    if (success)
+      return Error();
+    // else
+    //     the call failed for some reason, let's retry the read using ptrace
+    //     api.
+  }
+
+  unsigned char *dst = static_cast<unsigned char *>(buf);
+  size_t remainder;
+  long data;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL));
+  if (log)
+    ProcessPOSIXLog::IncNestLevel();
+  if (log && ProcessPOSIXLog::AtTopNestLevel() &&
+      log->GetMask().Test(POSIX_LOG_MEMORY))
+    log->Printf("NativeProcessLinux::%s(%p, %p, %zd, _)", __FUNCTION__,
+                (void *)addr, buf, size);
+
+  for (bytes_read = 0; bytes_read < size; bytes_read += remainder) {
+    Error error = NativeProcessLinux::PtraceWrapper(
+        PTRACE_PEEKDATA, GetID(), (void *)addr, nullptr, 0, &data);
+    if (error.Fail()) {
+      if (log)
+        ProcessPOSIXLog::DecNestLevel();
+      return error;
     }
 
-    if (log)
-        ProcessPOSIXLog::DecNestLevel();
-    return Error();
-}
+    remainder = size - bytes_read;
+    remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
 
-Error
-NativeProcessLinux::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
-{
-    Error error = ReadMemory(addr, buf, size, bytes_read);
-    if (error.Fail()) return error;
-    return m_breakpoint_list.RemoveTrapsFromBuffer(addr, buf, size);
-}
+    // Copy the data into our buffer
+    memcpy(dst, &data, remainder);
 
-Error
-NativeProcessLinux::WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)
-{
-    const unsigned char *src = static_cast<const unsigned char*>(buf);
-    size_t remainder;
-    Error error;
+    if (log && ProcessPOSIXLog::AtTopNestLevel() &&
+        (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
+         (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
+          size <= POSIX_LOG_MEMORY_SHORT_BYTES))) {
+      uintptr_t print_dst = 0;
+      // Format bytes from data by moving into print_dst for log output
+      for (unsigned i = 0; i < remainder; ++i)
+        print_dst |= (((data >> i * 8) & 0xFF) << i * 8);
+      log->Printf("NativeProcessLinux::%s() [0x%" PRIx64 "]:0x%" PRIx64
+                  " (0x%" PRIx64 ")",
+                  __FUNCTION__, addr, uint64_t(print_dst), uint64_t(data));
+    }
+    addr += k_ptrace_word_size;
+    dst += k_ptrace_word_size;
+  }
+
+  if (log)
+    ProcessPOSIXLog::DecNestLevel();
+  return Error();
+}
+
+Error NativeProcessLinux::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf,
+                                                size_t size,
+                                                size_t &bytes_read) {
+  Error error = ReadMemory(addr, buf, size, bytes_read);
+  if (error.Fail())
+    return error;
+  return m_breakpoint_list.RemoveTrapsFromBuffer(addr, buf, size);
+}
 
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_ALL));
-    if (log)
-        ProcessPOSIXLog::IncNestLevel();
-    if (log && ProcessPOSIXLog::AtTopNestLevel() && log->GetMask().Test(POSIX_LOG_MEMORY))
-        log->Printf ("NativeProcessLinux::%s(0x%" PRIx64 ", %p, %zu)", __FUNCTION__, addr, buf, size);
+Error NativeProcessLinux::WriteMemory(lldb::addr_t addr, const void *buf,
+                                      size_t size, size_t &bytes_written) {
+  const unsigned char *src = static_cast<const unsigned char *>(buf);
+  size_t remainder;
+  Error error;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL));
+  if (log)
+    ProcessPOSIXLog::IncNestLevel();
+  if (log && ProcessPOSIXLog::AtTopNestLevel() &&
+      log->GetMask().Test(POSIX_LOG_MEMORY))
+    log->Printf("NativeProcessLinux::%s(0x%" PRIx64 ", %p, %zu)", __FUNCTION__,
+                addr, buf, size);
+
+  for (bytes_written = 0; bytes_written < size; bytes_written += remainder) {
+    remainder = size - bytes_written;
+    remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
+
+    if (remainder == k_ptrace_word_size) {
+      unsigned long data = 0;
+      memcpy(&data, src, k_ptrace_word_size);
+
+      if (log && ProcessPOSIXLog::AtTopNestLevel() &&
+          (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
+           (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
+            size <= POSIX_LOG_MEMORY_SHORT_BYTES)))
+        log->Printf("NativeProcessLinux::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__,
+                    (void *)addr, *(const unsigned long *)src, data);
+
+      error = NativeProcessLinux::PtraceWrapper(PTRACE_POKEDATA, GetID(),
+                                                (void *)addr, (void *)data);
+      if (error.Fail()) {
+        if (log)
+          ProcessPOSIXLog::DecNestLevel();
+        return error;
+      }
+    } else {
+      unsigned char buff[8];
+      size_t bytes_read;
+      error = ReadMemory(addr, buff, k_ptrace_word_size, bytes_read);
+      if (error.Fail()) {
+        if (log)
+          ProcessPOSIXLog::DecNestLevel();
+        return error;
+      }
 
-    for (bytes_written = 0; bytes_written < size; bytes_written += remainder)
-    {
-        remainder = size - bytes_written;
-        remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
+      memcpy(buff, src, remainder);
 
-        if (remainder == k_ptrace_word_size)
-        {
-            unsigned long data = 0;
-            memcpy(&data, src, k_ptrace_word_size);
-
-            if (log && ProcessPOSIXLog::AtTopNestLevel() &&
-                    (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
-                            (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
-                                    size <= POSIX_LOG_MEMORY_SHORT_BYTES)))
-                log->Printf ("NativeProcessLinux::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__,
-                        (void*)addr, *(const unsigned long*)src, data);
-
-            error = NativeProcessLinux::PtraceWrapper(PTRACE_POKEDATA, GetID(), (void*)addr, (void*)data);
-            if (error.Fail())
-            {
-                if (log)
-                    ProcessPOSIXLog::DecNestLevel();
-                return error;
-            }
-        }
-        else
-        {
-            unsigned char buff[8];
-            size_t bytes_read;
-            error = ReadMemory(addr, buff, k_ptrace_word_size, bytes_read);
-            if (error.Fail())
-            {
-                if (log)
-                    ProcessPOSIXLog::DecNestLevel();
-                return error;
-            }
-
-            memcpy(buff, src, remainder);
-
-            size_t bytes_written_rec;
-            error = WriteMemory(addr, buff, k_ptrace_word_size, bytes_written_rec);
-            if (error.Fail())
-            {
-                if (log)
-                    ProcessPOSIXLog::DecNestLevel();
-                return error;
-            }
-
-            if (log && ProcessPOSIXLog::AtTopNestLevel() &&
-                    (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
-                            (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
-                                    size <= POSIX_LOG_MEMORY_SHORT_BYTES)))
-                log->Printf ("NativeProcessLinux::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__,
-                        (void*)addr, *(const unsigned long*)src, *(unsigned long*)buff);
-        }
+      size_t bytes_written_rec;
+      error = WriteMemory(addr, buff, k_ptrace_word_size, bytes_written_rec);
+      if (error.Fail()) {
+        if (log)
+          ProcessPOSIXLog::DecNestLevel();
+        return error;
+      }
 
-        addr += k_ptrace_word_size;
-        src += k_ptrace_word_size;
+      if (log && ProcessPOSIXLog::AtTopNestLevel() &&
+          (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) ||
+           (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) &&
+            size <= POSIX_LOG_MEMORY_SHORT_BYTES)))
+        log->Printf("NativeProcessLinux::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__,
+                    (void *)addr, *(const unsigned long *)src,
+                    *(unsigned long *)buff);
     }
-    if (log)
-        ProcessPOSIXLog::DecNestLevel();
-    return error;
+
+    addr += k_ptrace_word_size;
+    src += k_ptrace_word_size;
+  }
+  if (log)
+    ProcessPOSIXLog::DecNestLevel();
+  return error;
 }
 
-Error
-NativeProcessLinux::GetSignalInfo(lldb::tid_t tid, void *siginfo)
-{
-    return PtraceWrapper(PTRACE_GETSIGINFO, tid, nullptr, siginfo);
+Error NativeProcessLinux::GetSignalInfo(lldb::tid_t tid, void *siginfo) {
+  return PtraceWrapper(PTRACE_GETSIGINFO, tid, nullptr, siginfo);
 }
 
-Error
-NativeProcessLinux::GetEventMessage(lldb::tid_t tid, unsigned long *message)
-{
-    return PtraceWrapper(PTRACE_GETEVENTMSG, tid, nullptr, message);
+Error NativeProcessLinux::GetEventMessage(lldb::tid_t tid,
+                                          unsigned long *message) {
+  return PtraceWrapper(PTRACE_GETEVENTMSG, tid, nullptr, message);
 }
 
-Error
-NativeProcessLinux::Detach(lldb::tid_t tid)
-{
-    if (tid == LLDB_INVALID_THREAD_ID)
-        return Error();
+Error NativeProcessLinux::Detach(lldb::tid_t tid) {
+  if (tid == LLDB_INVALID_THREAD_ID)
+    return Error();
 
-    return PtraceWrapper(PTRACE_DETACH, tid);
+  return PtraceWrapper(PTRACE_DETACH, tid);
 }
 
-bool
-NativeProcessLinux::HasThreadNoLock (lldb::tid_t thread_id)
-{
-    for (auto thread_sp : m_threads)
-    {
-        assert (thread_sp && "thread list should not contain NULL threads");
-        if (thread_sp->GetID () == thread_id)
-        {
-            // We have this thread.
-            return true;
-        }
+bool NativeProcessLinux::HasThreadNoLock(lldb::tid_t thread_id) {
+  for (auto thread_sp : m_threads) {
+    assert(thread_sp && "thread list should not contain NULL threads");
+    if (thread_sp->GetID() == thread_id) {
+      // We have this thread.
+      return true;
     }
+  }
 
-    // We don't have this thread.
-    return false;
+  // We don't have this thread.
+  return false;
 }
 
-bool
-NativeProcessLinux::StopTrackingThread (lldb::tid_t thread_id)
-{
-    Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
+bool NativeProcessLinux::StopTrackingThread(lldb::tid_t thread_id) {
+  Log *const log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
 
-    if (log)
-        log->Printf("NativeProcessLinux::%s (tid: %" PRIu64 ")", __FUNCTION__, thread_id);
+  if (log)
+    log->Printf("NativeProcessLinux::%s (tid: %" PRIu64 ")", __FUNCTION__,
+                thread_id);
 
-    bool found = false;
+  bool found = false;
 
-    for (auto it = m_threads.begin (); it != m_threads.end (); ++it)
-    {
-        if (*it && ((*it)->GetID () == thread_id))
-        {
-            m_threads.erase (it);
-            found = true;
-            break;
-        }
+  for (auto it = m_threads.begin(); it != m_threads.end(); ++it) {
+    if (*it && ((*it)->GetID() == thread_id)) {
+      m_threads.erase(it);
+      found = true;
+      break;
     }
+  }
 
-    SignalIfAllThreadsStopped();
+  SignalIfAllThreadsStopped();
 
-    return found;
+  return found;
 }
 
-NativeThreadLinuxSP
-NativeProcessLinux::AddThread (lldb::tid_t thread_id)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
+NativeThreadLinuxSP NativeProcessLinux::AddThread(lldb::tid_t thread_id) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
 
-    if (log)
-    {
-        log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " adding thread with tid %" PRIu64,
-                __FUNCTION__,
-                GetID (),
-                thread_id);
-    }
+  if (log) {
+    log->Printf("NativeProcessLinux::%s pid %" PRIu64
+                " adding thread with tid %" PRIu64,
+                __FUNCTION__, GetID(), thread_id);
+  }
 
-    assert (!HasThreadNoLock (thread_id) && "attempted to add a thread by id that already exists");
+  assert(!HasThreadNoLock(thread_id) &&
+         "attempted to add a thread by id that already exists");
 
-    // If this is the first thread, save it as the current thread
-    if (m_threads.empty ())
-        SetCurrentThreadID (thread_id);
+  // If this is the first thread, save it as the current thread
+  if (m_threads.empty())
+    SetCurrentThreadID(thread_id);
 
-    auto thread_sp = std::make_shared<NativeThreadLinux>(this, thread_id);
-    m_threads.push_back (thread_sp);
-    return thread_sp;
+  auto thread_sp = std::make_shared<NativeThreadLinux>(this, thread_id);
+  m_threads.push_back(thread_sp);
+  return thread_sp;
 }
 
-Error
-NativeProcessLinux::FixupBreakpointPCAsNeeded(NativeThreadLinux &thread)
-{
-    Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
-
-    Error error;
-
-    // Find out the size of a breakpoint (might depend on where we are in the code).
-    NativeRegisterContextSP context_sp = thread.GetRegisterContext();
-    if (!context_sp)
-    {
-        error.SetErrorString ("cannot get a NativeRegisterContext for the thread");
-        if (log)
-            log->Printf ("NativeProcessLinux::%s failed: %s", __FUNCTION__, error.AsCString ());
-        return error;
-    }
-
-    uint32_t breakpoint_size = 0;
-    error = GetSoftwareBreakpointPCOffset(breakpoint_size);
-    if (error.Fail ())
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s GetBreakpointSize() failed: %s", __FUNCTION__, error.AsCString ());
-        return error;
-    }
-    else
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s breakpoint size: %" PRIu32, __FUNCTION__, breakpoint_size);
-    }
-
-    // First try probing for a breakpoint at a software breakpoint location: PC - breakpoint size.
-    const lldb::addr_t initial_pc_addr = context_sp->GetPCfromBreakpointLocation ();
-    lldb::addr_t breakpoint_addr = initial_pc_addr;
-    if (breakpoint_size > 0)
-    {
-        // Do not allow breakpoint probe to wrap around.
-        if (breakpoint_addr >= breakpoint_size)
-            breakpoint_addr -= breakpoint_size;
-    }
-
-    // Check if we stopped because of a breakpoint.
-    NativeBreakpointSP breakpoint_sp;
-    error = m_breakpoint_list.GetBreakpoint (breakpoint_addr, breakpoint_sp);
-    if (!error.Success () || !breakpoint_sp)
-    {
-        // We didn't find one at a software probe location.  Nothing to do.
-        if (log)
-            log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " no lldb breakpoint found at current pc with adjustment: 0x%" PRIx64, __FUNCTION__, GetID (), breakpoint_addr);
-        return Error ();
-    }
-
-    // If the breakpoint is not a software breakpoint, nothing to do.
-    if (!breakpoint_sp->IsSoftwareBreakpoint ())
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " breakpoint found at 0x%" PRIx64 ", not software, nothing to adjust", __FUNCTION__, GetID (), breakpoint_addr);
-        return Error ();
-    }
+Error NativeProcessLinux::FixupBreakpointPCAsNeeded(NativeThreadLinux &thread) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
 
-    //
-    // We have a software breakpoint and need to adjust the PC.
-    //
-
-    // Sanity check.
-    if (breakpoint_size == 0)
-    {
-        // Nothing to do!  How did we get here?
-        if (log)
-            log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " breakpoint found at 0x%" PRIx64 ", it is software, but the size is zero, nothing to do (unexpected)", __FUNCTION__, GetID (), breakpoint_addr);
-        return Error ();
-    }
+  Error error;
 
-    // Change the program counter.
+  // Find out the size of a breakpoint (might depend on where we are in the
+  // code).
+  NativeRegisterContextSP context_sp = thread.GetRegisterContext();
+  if (!context_sp) {
+    error.SetErrorString("cannot get a NativeRegisterContext for the thread");
     if (log)
-        log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64 ": changing PC from 0x%" PRIx64 " to 0x%" PRIx64, __FUNCTION__, GetID(), thread.GetID(), initial_pc_addr, breakpoint_addr);
-
-    error = context_sp->SetPC (breakpoint_addr);
-    if (error.Fail ())
-    {
-        if (log)
-            log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64 ": failed to set PC: %s", __FUNCTION__, GetID(), thread.GetID(), error.AsCString ());
-        return error;
-    }
-
+      log->Printf("NativeProcessLinux::%s failed: %s", __FUNCTION__,
+                  error.AsCString());
     return error;
-}
-
-Error
-NativeProcessLinux::GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec)
-{
-    FileSpec module_file_spec(module_path, true);
-
-    bool found = false;
-    file_spec.Clear();
-    ProcFileReader::ProcessLineByLine(GetID(), "maps",
-        [&] (const std::string &line)
-        {
-            SmallVector<StringRef, 16> columns;
-            StringRef(line).split(columns, " ", -1, false);
-            if (columns.size() < 6)
-                return true; // continue searching
-
-            FileSpec this_file_spec(columns[5].str().c_str(), false);
-            if (this_file_spec.GetFilename() != module_file_spec.GetFilename())
-                return true; // continue searching
-
-            file_spec = this_file_spec;
-            found = true;
-            return false; // we are done
-        });
-
-    if (! found)
-        return Error("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
-                module_file_spec.GetFilename().AsCString(), GetID());
+  }
 
+  uint32_t breakpoint_size = 0;
+  error = GetSoftwareBreakpointPCOffset(breakpoint_size);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessLinux::%s GetBreakpointSize() failed: %s",
+                  __FUNCTION__, error.AsCString());
+    return error;
+  } else {
+    if (log)
+      log->Printf("NativeProcessLinux::%s breakpoint size: %" PRIu32,
+                  __FUNCTION__, breakpoint_size);
+  }
+
+  // First try probing for a breakpoint at a software breakpoint location: PC -
+  // breakpoint size.
+  const lldb::addr_t initial_pc_addr =
+      context_sp->GetPCfromBreakpointLocation();
+  lldb::addr_t breakpoint_addr = initial_pc_addr;
+  if (breakpoint_size > 0) {
+    // Do not allow breakpoint probe to wrap around.
+    if (breakpoint_addr >= breakpoint_size)
+      breakpoint_addr -= breakpoint_size;
+  }
+
+  // Check if we stopped because of a breakpoint.
+  NativeBreakpointSP breakpoint_sp;
+  error = m_breakpoint_list.GetBreakpoint(breakpoint_addr, breakpoint_sp);
+  if (!error.Success() || !breakpoint_sp) {
+    // We didn't find one at a software probe location.  Nothing to do.
+    if (log)
+      log->Printf(
+          "NativeProcessLinux::%s pid %" PRIu64
+          " no lldb breakpoint found at current pc with adjustment: 0x%" PRIx64,
+          __FUNCTION__, GetID(), breakpoint_addr);
     return Error();
-}
-
-Error
-NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef& file_name, lldb::addr_t& load_addr)
-{
-    load_addr = LLDB_INVALID_ADDRESS;
-    Error error = ProcFileReader::ProcessLineByLine (GetID (), "maps",
-        [&] (const std::string &line) -> bool
-        {
-            StringRef maps_row(line);
- 
-            SmallVector<StringRef, 16> maps_columns;
-            maps_row.split(maps_columns, StringRef(" "), -1, false);
- 
-            if (maps_columns.size() < 6)
-            {
-                // Return true to continue reading the proc file
-                return true;
-            }
-
-            if (maps_columns[5] == file_name)
-            {
-                StringExtractor addr_extractor(maps_columns[0].str().c_str());
-                load_addr = addr_extractor.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); 
-
-                // Return false to stop reading the proc file further
-                return false;
-            }
- 
-            // Return true to continue reading the proc file
-            return true;
-        });
-    return error; 
-}
+  }
 
-NativeThreadLinuxSP
-NativeProcessLinux::GetThreadByID(lldb::tid_t tid)
-{
-    return std::static_pointer_cast<NativeThreadLinux>(NativeProcessProtocol::GetThreadByID(tid));
-}
+  // If the breakpoint is not a software breakpoint, nothing to do.
+  if (!breakpoint_sp->IsSoftwareBreakpoint()) {
+    if (log)
+      log->Printf("NativeProcessLinux::%s pid %" PRIu64
+                  " breakpoint found at 0x%" PRIx64
+                  ", not software, nothing to adjust",
+                  __FUNCTION__, GetID(), breakpoint_addr);
+    return Error();
+  }
 
-Error
-NativeProcessLinux::ResumeThread(NativeThreadLinux &thread, lldb::StateType state, int signo)
-{
-    Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
+  //
+  // We have a software breakpoint and need to adjust the PC.
+  //
+
+  // Sanity check.
+  if (breakpoint_size == 0) {
+    // Nothing to do!  How did we get here?
+    if (log)
+      log->Printf(
+          "NativeProcessLinux::%s pid %" PRIu64
+          " breakpoint found at 0x%" PRIx64
+          ", it is software, but the size is zero, nothing to do (unexpected)",
+          __FUNCTION__, GetID(), breakpoint_addr);
+    return Error();
+  }
 
-    if (log)
-        log->Printf("NativeProcessLinux::%s (tid: %" PRIu64 ")",
-                __FUNCTION__, thread.GetID());
-    
-    // Before we do the resume below, first check if we have a pending
-    // stop notification that is currently waiting for
-    // all threads to stop.  This is potentially a buggy situation since
-    // we're ostensibly waiting for threads to stop before we send out the
-    // pending notification, and here we are resuming one before we send
-    // out the pending stop notification.
-    if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID && log)
-    {
-        log->Printf("NativeProcessLinux::%s about to resume tid %" PRIu64 " per explicit request but we have a pending stop notification (tid %" PRIu64 ") that is actively waiting for this thread to stop. Valid sequence of events?", __FUNCTION__, thread.GetID(), m_pending_notification_tid);
-    }
+  // Change the program counter.
+  if (log)
+    log->Printf("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64
+                ": changing PC from 0x%" PRIx64 " to 0x%" PRIx64,
+                __FUNCTION__, GetID(), thread.GetID(), initial_pc_addr,
+                breakpoint_addr);
+
+  error = context_sp->SetPC(breakpoint_addr);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64
+                  ": failed to set PC: %s",
+                  __FUNCTION__, GetID(), thread.GetID(), error.AsCString());
+    return error;
+  }
 
-    // Request a resume.  We expect this to be synchronous and the system
-    // to reflect it is running after this completes.
-    switch (state)
-    {
-    case eStateRunning:
-    {
-        const auto resume_result = thread.Resume(signo);
-        if (resume_result.Success())
-            SetState(eStateRunning, true);
-        return resume_result;
-    }
-    case eStateStepping:
-    {
-        const auto step_result = thread.SingleStep(signo);
-        if (step_result.Success())
-            SetState(eStateRunning, true);
-        return step_result;
-    }
-    default:
-        if (log)
-            log->Printf("NativeProcessLinux::%s Unhandled state %s.",
-                    __FUNCTION__, StateAsCString(state));
-        llvm_unreachable("Unhandled state for resume");
-    }
+  return error;
 }
 
-//===----------------------------------------------------------------------===//
-
-void
-NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid)
-{
-    Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
+Error NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path,
+                                                  FileSpec &file_spec) {
+  FileSpec module_file_spec(module_path, true);
 
-    if (log)
-    {
-        log->Printf("NativeProcessLinux::%s about to process event: (triggering_tid: %" PRIu64 ")",
-                __FUNCTION__, triggering_tid);
-    }
+  bool found = false;
+  file_spec.Clear();
+  ProcFileReader::ProcessLineByLine(
+      GetID(), "maps", [&](const std::string &line) {
+        SmallVector<StringRef, 16> columns;
+        StringRef(line).split(columns, " ", -1, false);
+        if (columns.size() < 6)
+          return true; // continue searching
 
-    m_pending_notification_tid = triggering_tid;
+        FileSpec this_file_spec(columns[5].str().c_str(), false);
+        if (this_file_spec.GetFilename() != module_file_spec.GetFilename())
+          return true; // continue searching
 
-    // Request a stop for all the thread stops that need to be stopped
-    // and are not already known to be stopped.
-    for (const auto &thread_sp: m_threads)
-    {
-        if (StateIsRunningState(thread_sp->GetState()))
-            static_pointer_cast<NativeThreadLinux>(thread_sp)->RequestStop();
-    }
+        file_spec = this_file_spec;
+        found = true;
+        return false; // we are done
+      });
 
-    SignalIfAllThreadsStopped();
+  if (!found)
+    return Error("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
+                 module_file_spec.GetFilename().AsCString(), GetID());
 
-    if (log)
-    {
-        log->Printf("NativeProcessLinux::%s event processing done", __FUNCTION__);
-    }
+  return Error();
 }
 
-void
-NativeProcessLinux::SignalIfAllThreadsStopped()
-{
-    if (m_pending_notification_tid == LLDB_INVALID_THREAD_ID)
-        return; // No pending notification. Nothing to do.
-
-    for (const auto &thread_sp: m_threads)
-    {
-        if (StateIsRunningState(thread_sp->GetState()))
-            return; // Some threads are still running. Don't signal yet.
-    }
+Error NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef &file_name,
+                                             lldb::addr_t &load_addr) {
+  load_addr = LLDB_INVALID_ADDRESS;
+  Error error = ProcFileReader::ProcessLineByLine(
+      GetID(), "maps", [&](const std::string &line) -> bool {
+        StringRef maps_row(line);
 
-    // We have a pending notification and all threads have stopped.
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_BREAKPOINTS));
+        SmallVector<StringRef, 16> maps_columns;
+        maps_row.split(maps_columns, StringRef(" "), -1, false);
 
-    // Clear any temporary breakpoints we used to implement software single stepping.
-    for (const auto &thread_info: m_threads_stepping_with_breakpoint)
-    {
-        Error error = RemoveBreakpoint (thread_info.second);
-        if (error.Fail())
-            if (log)
-                log->Printf("NativeProcessLinux::%s() pid = %" PRIu64 " remove stepping breakpoint: %s",
-                        __FUNCTION__, thread_info.first, error.AsCString());
-    }
-    m_threads_stepping_with_breakpoint.clear();
+        if (maps_columns.size() < 6) {
+          // Return true to continue reading the proc file
+          return true;
+        }
 
-    // Notify the delegate about the stop
-    SetCurrentThreadID(m_pending_notification_tid);
-    SetState(StateType::eStateStopped, true);
-    m_pending_notification_tid = LLDB_INVALID_THREAD_ID;
-}
+        if (maps_columns[5] == file_name) {
+          StringExtractor addr_extractor(maps_columns[0].str().c_str());
+          load_addr = addr_extractor.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
 
-void
-NativeProcessLinux::ThreadWasCreated(NativeThreadLinux &thread)
-{
-    Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
+          // Return false to stop reading the proc file further
+          return false;
+        }
 
-    if (log)
-        log->Printf("NativeProcessLinux::%s (tid: %" PRIu64 ")", __FUNCTION__, thread.GetID());
+        // Return true to continue reading the proc file
+        return true;
+      });
+  return error;
+}
 
-    if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID && StateIsRunningState(thread.GetState()))
-    {
-        // We will need to wait for this new thread to stop as well before firing the
-        // notification.
-        thread.RequestStop();
-    }
+NativeThreadLinuxSP NativeProcessLinux::GetThreadByID(lldb::tid_t tid) {
+  return std::static_pointer_cast<NativeThreadLinux>(
+      NativeProcessProtocol::GetThreadByID(tid));
+}
+
+Error NativeProcessLinux::ResumeThread(NativeThreadLinux &thread,
+                                       lldb::StateType state, int signo) {
+  Log *const log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s (tid: %" PRIu64 ")", __FUNCTION__,
+                thread.GetID());
+
+  // Before we do the resume below, first check if we have a pending
+  // stop notification that is currently waiting for
+  // all threads to stop.  This is potentially a buggy situation since
+  // we're ostensibly waiting for threads to stop before we send out the
+  // pending notification, and here we are resuming one before we send
+  // out the pending stop notification.
+  if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID && log) {
+    log->Printf("NativeProcessLinux::%s about to resume tid %" PRIu64
+                " per explicit request but we have a pending stop notification "
+                "(tid %" PRIu64 ") that is actively waiting for this thread to "
+                                "stop. Valid sequence of events?",
+                __FUNCTION__, thread.GetID(), m_pending_notification_tid);
+  }
+
+  // Request a resume.  We expect this to be synchronous and the system
+  // to reflect it is running after this completes.
+  switch (state) {
+  case eStateRunning: {
+    const auto resume_result = thread.Resume(signo);
+    if (resume_result.Success())
+      SetState(eStateRunning, true);
+    return resume_result;
+  }
+  case eStateStepping: {
+    const auto step_result = thread.SingleStep(signo);
+    if (step_result.Success())
+      SetState(eStateRunning, true);
+    return step_result;
+  }
+  default:
+    if (log)
+      log->Printf("NativeProcessLinux::%s Unhandled state %s.", __FUNCTION__,
+                  StateAsCString(state));
+    llvm_unreachable("Unhandled state for resume");
+  }
 }
 
-void
-NativeProcessLinux::SigchldHandler()
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-    // Process all pending waitpid notifications.
-    while (true)
-    {
-        int status = -1;
-        ::pid_t wait_pid = waitpid(-1, &status, __WALL | __WNOTHREAD | WNOHANG);
+//===----------------------------------------------------------------------===//
 
-        if (wait_pid == 0)
-            break; // We are done.
+void NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid) {
+  Log *const log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
 
-        if (wait_pid == -1)
-        {
-            if (errno == EINTR)
-                continue;
+  if (log) {
+    log->Printf("NativeProcessLinux::%s about to process event: "
+                "(triggering_tid: %" PRIu64 ")",
+                __FUNCTION__, triggering_tid);
+  }
 
-            Error error(errno, eErrorTypePOSIX);
-            if (log)
-                log->Printf("NativeProcessLinux::%s waitpid (-1, &status, __WALL | __WNOTHREAD | WNOHANG) failed: %s",
-                        __FUNCTION__, error.AsCString());
-            break;
-        }
+  m_pending_notification_tid = triggering_tid;
 
-        bool exited = false;
-        int signal = 0;
-        int exit_status = 0;
-        const char *status_cstr = nullptr;
-        if (WIFSTOPPED(status))
-        {
-            signal = WSTOPSIG(status);
-            status_cstr = "STOPPED";
-        }
-        else if (WIFEXITED(status))
-        {
-            exit_status = WEXITSTATUS(status);
-            status_cstr = "EXITED";
-            exited = true;
-        }
-        else if (WIFSIGNALED(status))
-        {
-            signal = WTERMSIG(status);
-            status_cstr = "SIGNALED";
-            if (wait_pid == static_cast< ::pid_t>(GetID())) {
-                exited = true;
-                exit_status = -1;
-            }
-        }
-        else
-            status_cstr = "(\?\?\?)";
+  // Request a stop for all the thread stops that need to be stopped
+  // and are not already known to be stopped.
+  for (const auto &thread_sp : m_threads) {
+    if (StateIsRunningState(thread_sp->GetState()))
+      static_pointer_cast<NativeThreadLinux>(thread_sp)->RequestStop();
+  }
 
-        if (log)
-            log->Printf("NativeProcessLinux::%s: waitpid (-1, &status, __WALL | __WNOTHREAD | WNOHANG)"
-                "=> pid = %" PRIi32 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i",
-                __FUNCTION__, wait_pid, status, status_cstr, signal, exit_status);
+  SignalIfAllThreadsStopped();
 
-        MonitorCallback (wait_pid, exited, signal, exit_status);
-    }
+  if (log) {
+    log->Printf("NativeProcessLinux::%s event processing done", __FUNCTION__);
+  }
 }
 
-// Wrapper for ptrace to catch errors and log calls.
-// Note that ptrace sets errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
-Error
-NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr, void *data, size_t data_size, long *result)
-{
-    Error error;
-    long int ret;
+void NativeProcessLinux::SignalIfAllThreadsStopped() {
+  if (m_pending_notification_tid == LLDB_INVALID_THREAD_ID)
+    return; // No pending notification. Nothing to do.
 
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PTRACE));
+  for (const auto &thread_sp : m_threads) {
+    if (StateIsRunningState(thread_sp->GetState()))
+      return; // Some threads are still running. Don't signal yet.
+  }
 
-    PtraceDisplayBytes(req, data, data_size);
+  // We have a pending notification and all threads have stopped.
+  Log *log(
+      GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_BREAKPOINTS));
 
-    errno = 0;
-    if (req == PTRACE_GETREGSET || req == PTRACE_SETREGSET)
-        ret = ptrace(static_cast<__ptrace_request>(req), static_cast< ::pid_t>(pid), *(unsigned int *)addr, data);
-    else
-        ret = ptrace(static_cast<__ptrace_request>(req), static_cast< ::pid_t>(pid), addr, data);
+  // Clear any temporary breakpoints we used to implement software single
+  // stepping.
+  for (const auto &thread_info : m_threads_stepping_with_breakpoint) {
+    Error error = RemoveBreakpoint(thread_info.second);
+    if (error.Fail())
+      if (log)
+        log->Printf("NativeProcessLinux::%s() pid = %" PRIu64
+                    " remove stepping breakpoint: %s",
+                    __FUNCTION__, thread_info.first, error.AsCString());
+  }
+  m_threads_stepping_with_breakpoint.clear();
+
+  // Notify the delegate about the stop
+  SetCurrentThreadID(m_pending_notification_tid);
+  SetState(StateType::eStateStopped, true);
+  m_pending_notification_tid = LLDB_INVALID_THREAD_ID;
+}
+
+void NativeProcessLinux::ThreadWasCreated(NativeThreadLinux &thread) {
+  Log *const log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  if (log)
+    log->Printf("NativeProcessLinux::%s (tid: %" PRIu64 ")", __FUNCTION__,
+                thread.GetID());
+
+  if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID &&
+      StateIsRunningState(thread.GetState())) {
+    // We will need to wait for this new thread to stop as well before firing
+    // the
+    // notification.
+    thread.RequestStop();
+  }
+}
+
+void NativeProcessLinux::SigchldHandler() {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  // Process all pending waitpid notifications.
+  while (true) {
+    int status = -1;
+    ::pid_t wait_pid = waitpid(-1, &status, __WALL | __WNOTHREAD | WNOHANG);
 
-    if (ret == -1)
-        error.SetErrorToErrno();
+    if (wait_pid == 0)
+      break; // We are done.
 
-    if (result)
-        *result = ret;
+    if (wait_pid == -1) {
+      if (errno == EINTR)
+        continue;
+
+      Error error(errno, eErrorTypePOSIX);
+      if (log)
+        log->Printf("NativeProcessLinux::%s waitpid (-1, &status, __WALL | "
+                    "__WNOTHREAD | WNOHANG) failed: %s",
+                    __FUNCTION__, error.AsCString());
+      break;
+    }
 
-    if (log)
-        log->Printf("ptrace(%d, %" PRIu64 ", %p, %p, %zu)=%lX", req, pid, addr, data, data_size, ret);
+    bool exited = false;
+    int signal = 0;
+    int exit_status = 0;
+    const char *status_cstr = nullptr;
+    if (WIFSTOPPED(status)) {
+      signal = WSTOPSIG(status);
+      status_cstr = "STOPPED";
+    } else if (WIFEXITED(status)) {
+      exit_status = WEXITSTATUS(status);
+      status_cstr = "EXITED";
+      exited = true;
+    } else if (WIFSIGNALED(status)) {
+      signal = WTERMSIG(status);
+      status_cstr = "SIGNALED";
+      if (wait_pid == static_cast<::pid_t>(GetID())) {
+        exited = true;
+        exit_status = -1;
+      }
+    } else
+      status_cstr = "(\?\?\?)";
+
+    if (log)
+      log->Printf("NativeProcessLinux::%s: waitpid (-1, &status, __WALL | "
+                  "__WNOTHREAD | WNOHANG)"
+                  "=> pid = %" PRIi32
+                  ", status = 0x%8.8x (%s), signal = %i, exit_state = %i",
+                  __FUNCTION__, wait_pid, status, status_cstr, signal,
+                  exit_status);
 
-    PtraceDisplayBytes(req, data, data_size);
+    MonitorCallback(wait_pid, exited, signal, exit_status);
+  }
+}
 
-    if (log && error.GetError() != 0)
-    {
-        const char* str;
-        switch (error.GetError())
-        {
-        case ESRCH:  str = "ESRCH"; break;
-        case EINVAL: str = "EINVAL"; break;
-        case EBUSY:  str = "EBUSY"; break;
-        case EPERM:  str = "EPERM"; break;
-        default:     str = error.AsCString();
-        }
-        log->Printf("ptrace() failed; errno=%d (%s)", error.GetError(), str);
+// Wrapper for ptrace to catch errors and log calls.
+// Note that ptrace sets errno on error because -1 can be a valid result (i.e.
+// for PTRACE_PEEK*)
+Error NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
+                                        void *data, size_t data_size,
+                                        long *result) {
+  Error error;
+  long int ret;
+
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE));
+
+  PtraceDisplayBytes(req, data, data_size);
+
+  errno = 0;
+  if (req == PTRACE_GETREGSET || req == PTRACE_SETREGSET)
+    ret = ptrace(static_cast<__ptrace_request>(req), static_cast<::pid_t>(pid),
+                 *(unsigned int *)addr, data);
+  else
+    ret = ptrace(static_cast<__ptrace_request>(req), static_cast<::pid_t>(pid),
+                 addr, data);
+
+  if (ret == -1)
+    error.SetErrorToErrno();
+
+  if (result)
+    *result = ret;
+
+  if (log)
+    log->Printf("ptrace(%d, %" PRIu64 ", %p, %p, %zu)=%lX", req, pid, addr,
+                data, data_size, ret);
+
+  PtraceDisplayBytes(req, data, data_size);
+
+  if (log && error.GetError() != 0) {
+    const char *str;
+    switch (error.GetError()) {
+    case ESRCH:
+      str = "ESRCH";
+      break;
+    case EINVAL:
+      str = "EINVAL";
+      break;
+    case EBUSY:
+      str = "EBUSY";
+      break;
+    case EPERM:
+      str = "EPERM";
+      break;
+    default:
+      str = error.AsCString();
     }
+    log->Printf("ptrace() failed; errno=%d (%s)", error.GetError(), str);
+  }
 
-    return error;
+  return error;
 }

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h Tue Sep  6 15:57:50 2016
@@ -15,186 +15,151 @@
 
 // Other libraries and framework includes
 #include "lldb/Core/ArchSpec.h"
-#include "lldb/lldb-types.h"
 #include "lldb/Host/Debug.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/lldb-types.h"
 
-#include "lldb/Host/common/NativeProcessProtocol.h"
 #include "NativeThreadLinux.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
 
 namespace lldb_private {
-    class Error;
-    class Scalar;
+class Error;
+class Scalar;
 
 namespace process_linux {
-    /// @class NativeProcessLinux
-    /// @brief Manages communication with the inferior (debugee) process.
-    ///
-    /// Upon construction, this class prepares and launches an inferior process for
-    /// debugging.
-    ///
-    /// Changes in the inferior process state are broadcasted.
-    class NativeProcessLinux: public NativeProcessProtocol
-    {
-        friend Error
-        NativeProcessProtocol::Launch (ProcessLaunchInfo &launch_info,
-                NativeDelegate &native_delegate,
-                MainLoop &mainloop,
-                NativeProcessProtocolSP &process_sp);
+/// @class NativeProcessLinux
+/// @brief Manages communication with the inferior (debugee) process.
+///
+/// Upon construction, this class prepares and launches an inferior process for
+/// debugging.
+///
+/// Changes in the inferior process state are broadcasted.
+class NativeProcessLinux : public NativeProcessProtocol {
+  friend Error NativeProcessProtocol::Launch(
+      ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
+      MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
 
-        friend Error
-        NativeProcessProtocol::Attach (lldb::pid_t pid,
-                NativeProcessProtocol::NativeDelegate &native_delegate,
-                MainLoop &mainloop,
-                NativeProcessProtocolSP &process_sp);
+  friend Error NativeProcessProtocol::Attach(
+      lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
+      MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
 
-    public:
-        // ---------------------------------------------------------------------
-        // NativeProcessProtocol Interface
-        // ---------------------------------------------------------------------
-        Error
-        Resume (const ResumeActionList &resume_actions) override;
+public:
+  // ---------------------------------------------------------------------
+  // NativeProcessProtocol Interface
+  // ---------------------------------------------------------------------
+  Error Resume(const ResumeActionList &resume_actions) override;
 
-        Error
-        Halt () override;
+  Error Halt() override;
 
-        Error
-        Detach () override;
+  Error Detach() override;
 
-        Error
-        Signal (int signo) override;
+  Error Signal(int signo) override;
 
-        Error
-        Interrupt () override;
+  Error Interrupt() override;
 
-        Error
-        Kill () override;
+  Error Kill() override;
 
-        Error
-        GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info) override;
+  Error GetMemoryRegionInfo(lldb::addr_t load_addr,
+                            MemoryRegionInfo &range_info) override;
 
-        Error
-        ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override;
+  Error ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+                   size_t &bytes_read) override;
 
-        Error
-        ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override;
+  Error ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
+                              size_t &bytes_read) override;
 
-        Error
-        WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override;
+  Error WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
+                    size_t &bytes_written) override;
 
-        Error
-        AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) override;
+  Error AllocateMemory(size_t size, uint32_t permissions,
+                       lldb::addr_t &addr) override;
 
-        Error
-        DeallocateMemory (lldb::addr_t addr) override;
+  Error DeallocateMemory(lldb::addr_t addr) override;
 
-        lldb::addr_t
-        GetSharedLibraryInfoAddress () override;
+  lldb::addr_t GetSharedLibraryInfoAddress() override;
 
-        size_t
-        UpdateThreads () override;
+  size_t UpdateThreads() override;
 
-        bool
-        GetArchitecture (ArchSpec &arch) const override;
+  bool GetArchitecture(ArchSpec &arch) const override;
 
-        Error
-        SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) override;
+  Error SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override;
 
-        void
-        DoStopIDBumped (uint32_t newBumpId) override;
+  void DoStopIDBumped(uint32_t newBumpId) override;
 
-        Error
-        GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) override;
+  Error GetLoadedModuleFileSpec(const char *module_path,
+                                FileSpec &file_spec) override;
 
-        Error
-        GetFileLoadAddress(const llvm::StringRef& file_name, lldb::addr_t& load_addr) override;
+  Error GetFileLoadAddress(const llvm::StringRef &file_name,
+                           lldb::addr_t &load_addr) override;
 
-        NativeThreadLinuxSP
-        GetThreadByID(lldb::tid_t id);
+  NativeThreadLinuxSP GetThreadByID(lldb::tid_t id);
 
-        // ---------------------------------------------------------------------
-        // Interface used by NativeRegisterContext-derived classes.
-        // ---------------------------------------------------------------------
-        static Error
-        PtraceWrapper(int req,
-                      lldb::pid_t pid,
-                      void *addr = nullptr,
-                      void *data = nullptr,
-                      size_t data_size = 0,
-                      long *result = nullptr);
+  // ---------------------------------------------------------------------
+  // Interface used by NativeRegisterContext-derived classes.
+  // ---------------------------------------------------------------------
+  static Error PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
+                             void *data = nullptr, size_t data_size = 0,
+                             long *result = nullptr);
 
-        bool
-        SupportHardwareSingleStepping() const;
+  bool SupportHardwareSingleStepping() const;
 
-    protected:
-        // ---------------------------------------------------------------------
-        // NativeProcessProtocol protected interface
-        // ---------------------------------------------------------------------
-        Error
-        GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) override;
+protected:
+  // ---------------------------------------------------------------------
+  // NativeProcessProtocol protected interface
+  // ---------------------------------------------------------------------
+  Error
+  GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
+                                  size_t &actual_opcode_size,
+                                  const uint8_t *&trap_opcode_bytes) override;
 
-    private:
+private:
+  MainLoop::SignalHandleUP m_sigchld_handle;
+  ArchSpec m_arch;
 
-        MainLoop::SignalHandleUP m_sigchld_handle;
-        ArchSpec m_arch;
+  LazyBool m_supports_mem_region;
+  std::vector<MemoryRegionInfo> m_mem_region_cache;
 
-        LazyBool m_supports_mem_region;
-        std::vector<MemoryRegionInfo> m_mem_region_cache;
+  lldb::tid_t m_pending_notification_tid;
 
-        lldb::tid_t m_pending_notification_tid;
+  // List of thread ids stepping with a breakpoint with the address of
+  // the relevan breakpoint
+  std::map<lldb::tid_t, lldb::addr_t> m_threads_stepping_with_breakpoint;
 
-        // List of thread ids stepping with a breakpoint with the address of
-        // the relevan breakpoint
-        std::map<lldb::tid_t, lldb::addr_t> m_threads_stepping_with_breakpoint;
+  // ---------------------------------------------------------------------
+  // Private Instance Methods
+  // ---------------------------------------------------------------------
+  NativeProcessLinux();
 
+  Error LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info);
 
-        // ---------------------------------------------------------------------
-        // Private Instance Methods
-        // ---------------------------------------------------------------------
-        NativeProcessLinux ();
+  /// Attaches to an existing process.  Forms the
+  /// implementation of Process::DoAttach
+  void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Error &error);
 
-        Error
-        LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info);
+  ::pid_t Attach(lldb::pid_t pid, Error &error);
 
-        /// Attaches to an existing process.  Forms the
-        /// implementation of Process::DoAttach
-        void
-        AttachToInferior (MainLoop &mainloop, lldb::pid_t pid, Error &error);
+  static Error SetDefaultPtraceOpts(const lldb::pid_t);
 
-        ::pid_t
-        Attach(lldb::pid_t pid, Error &error);
+  static void *MonitorThread(void *baton);
 
-        static Error
-        SetDefaultPtraceOpts(const lldb::pid_t);
+  void MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status);
 
-        static void *
-        MonitorThread(void *baton);
+  void WaitForNewThread(::pid_t tid);
 
-        void
-        MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status);
+  void MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread);
 
-        void
-        WaitForNewThread(::pid_t tid);
+  void MonitorTrace(NativeThreadLinux &thread);
 
-        void
-        MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread);
+  void MonitorBreakpoint(NativeThreadLinux &thread);
 
-        void
-        MonitorTrace(NativeThreadLinux &thread);
+  void MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index);
 
-        void
-        MonitorBreakpoint(NativeThreadLinux &thread);
+  void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread,
+                     bool exited);
 
-        void
-        MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index);
-
-        void
-        MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread, bool exited);
-
-        Error
-        SetupSoftwareSingleStepping(NativeThreadLinux &thread);
+  Error SetupSoftwareSingleStepping(NativeThreadLinux &thread);
 
 #if 0
         static ::ProcessMessage::CrashReason
@@ -210,59 +175,49 @@ namespace process_linux {
         GetCrashReasonForSIGBUS(const siginfo_t *info);
 #endif
 
-        bool
-        HasThreadNoLock (lldb::tid_t thread_id);
-
-        bool
-        StopTrackingThread (lldb::tid_t thread_id);
+  bool HasThreadNoLock(lldb::tid_t thread_id);
 
-        NativeThreadLinuxSP
-        AddThread (lldb::tid_t thread_id);
+  bool StopTrackingThread(lldb::tid_t thread_id);
 
-        Error
-        GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
+  NativeThreadLinuxSP AddThread(lldb::tid_t thread_id);
 
-        Error
-        FixupBreakpointPCAsNeeded(NativeThreadLinux &thread);
+  Error GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
 
-        /// Writes a siginfo_t structure corresponding to the given thread ID to the
-        /// memory region pointed to by @p siginfo.
-        Error
-        GetSignalInfo(lldb::tid_t tid, void *siginfo);
+  Error FixupBreakpointPCAsNeeded(NativeThreadLinux &thread);
 
-        /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
-        /// corresponding to the given thread ID to the memory pointed to by @p
-        /// message.
-        Error
-        GetEventMessage(lldb::tid_t tid, unsigned long *message);
+  /// Writes a siginfo_t structure corresponding to the given thread ID to the
+  /// memory region pointed to by @p siginfo.
+  Error GetSignalInfo(lldb::tid_t tid, void *siginfo);
 
-        void
-        NotifyThreadDeath (lldb::tid_t tid);
+  /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
+  /// corresponding to the given thread ID to the memory pointed to by @p
+  /// message.
+  Error GetEventMessage(lldb::tid_t tid, unsigned long *message);
 
-        Error
-        Detach(lldb::tid_t tid);
+  void NotifyThreadDeath(lldb::tid_t tid);
 
+  Error Detach(lldb::tid_t tid);
 
-        // This method is requests a stop on all threads which are still running. It sets up a
-        // deferred delegate notification, which will fire once threads report as stopped. The
-        // triggerring_tid will be set as the current thread (main stop reason).
-        void
-        StopRunningThreads(lldb::tid_t triggering_tid);
+  // This method is requests a stop on all threads which are still running. It
+  // sets up a
+  // deferred delegate notification, which will fire once threads report as
+  // stopped. The
+  // triggerring_tid will be set as the current thread (main stop reason).
+  void StopRunningThreads(lldb::tid_t triggering_tid);
 
-        // Notify the delegate if all threads have stopped.
-        void SignalIfAllThreadsStopped();
+  // Notify the delegate if all threads have stopped.
+  void SignalIfAllThreadsStopped();
 
-        // Resume the given thread, optionally passing it the given signal. The type of resume
-        // operation (continue, single-step) depends on the state parameter.
-        Error
-        ResumeThread(NativeThreadLinux &thread, lldb::StateType state, int signo);
+  // Resume the given thread, optionally passing it the given signal. The type
+  // of resume
+  // operation (continue, single-step) depends on the state parameter.
+  Error ResumeThread(NativeThreadLinux &thread, lldb::StateType state,
+                     int signo);
 
-        void
-        ThreadWasCreated(NativeThreadLinux &thread);
+  void ThreadWasCreated(NativeThreadLinux &thread);
 
-        void
-        SigchldHandler();
-    };
+  void SigchldHandler();
+};
 
 } // namespace process_linux
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp Tue Sep  6 15:57:50 2016
@@ -19,212 +19,195 @@
 using namespace lldb_private;
 using namespace lldb_private::process_linux;
 
-NativeRegisterContextLinux::NativeRegisterContextLinux(NativeThreadProtocol &native_thread,
-                                                       uint32_t concrete_frame_idx,
-                                                       RegisterInfoInterface *reg_info_interface_p) :
-    NativeRegisterContextRegisterInfo(native_thread, concrete_frame_idx, reg_info_interface_p)
-{}
-
-lldb::ByteOrder
-NativeRegisterContextLinux::GetByteOrder() const
-{
-    // Get the target process whose privileged thread was used for the register read.
-    lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
-
-    NativeProcessProtocolSP process_sp (m_thread.GetProcess ());
-    if (!process_sp)
-        return byte_order;
-
-    if (!process_sp->GetByteOrder (byte_order))
-    {
-        // FIXME log here
-    }
+NativeRegisterContextLinux::NativeRegisterContextLinux(
+    NativeThreadProtocol &native_thread, uint32_t concrete_frame_idx,
+    RegisterInfoInterface *reg_info_interface_p)
+    : NativeRegisterContextRegisterInfo(native_thread, concrete_frame_idx,
+                                        reg_info_interface_p) {}
+
+lldb::ByteOrder NativeRegisterContextLinux::GetByteOrder() const {
+  // Get the target process whose privileged thread was used for the register
+  // read.
+  lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
 
+  NativeProcessProtocolSP process_sp(m_thread.GetProcess());
+  if (!process_sp)
     return byte_order;
-}
 
-Error
-NativeRegisterContextLinux::ReadRegisterRaw(uint32_t reg_index, RegisterValue &reg_value)
-{
-    const RegisterInfo *const reg_info = GetRegisterInfoAtIndex(reg_index);
-    if (!reg_info)
-        return Error("register %" PRIu32 " not found", reg_index);
-
-    return DoReadRegisterValue(reg_info->byte_offset, reg_info->name, reg_info->byte_size, reg_value);
-}
-
-Error
-NativeRegisterContextLinux::WriteRegisterRaw(uint32_t reg_index, const RegisterValue &reg_value)
-{
-    uint32_t reg_to_write = reg_index;
-    RegisterValue value_to_write = reg_value;
-
-    // Check if this is a subregister of a full register.
-    const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_index);
-    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
-    {
-        Error error;
-
-        RegisterValue full_value;
-        uint32_t full_reg = reg_info->invalidate_regs[0];
-        const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
-
-        // Read the full register.
-        error = ReadRegister(full_reg_info, full_value);
-        if (error.Fail ())
-            return error;
-
-        lldb::ByteOrder byte_order = GetByteOrder();
-        uint8_t dst[RegisterValue::kMaxRegisterByteSize];
-
-        // Get the bytes for the full register.
-        const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
-                                                               dst,
-                                                               sizeof(dst),
-                                                               byte_order,
-                                                               error);
-        if (error.Success() && dest_size)
-        {
-            uint8_t src[RegisterValue::kMaxRegisterByteSize];
-
-            // Get the bytes for the source data.
-            const uint32_t src_size = reg_value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
-            if (error.Success() && src_size && (src_size < dest_size))
-            {
-                // Copy the src bytes to the destination.
-                memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
-                // Set this full register as the value to write.
-                value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
-                value_to_write.SetType(full_reg_info);
-                reg_to_write = full_reg;
-            }
-        }
+  if (!process_sp->GetByteOrder(byte_order)) {
+    // FIXME log here
+  }
+
+  return byte_order;
+}
+
+Error NativeRegisterContextLinux::ReadRegisterRaw(uint32_t reg_index,
+                                                  RegisterValue &reg_value) {
+  const RegisterInfo *const reg_info = GetRegisterInfoAtIndex(reg_index);
+  if (!reg_info)
+    return Error("register %" PRIu32 " not found", reg_index);
+
+  return DoReadRegisterValue(reg_info->byte_offset, reg_info->name,
+                             reg_info->byte_size, reg_value);
+}
+
+Error NativeRegisterContextLinux::WriteRegisterRaw(
+    uint32_t reg_index, const RegisterValue &reg_value) {
+  uint32_t reg_to_write = reg_index;
+  RegisterValue value_to_write = reg_value;
+
+  // Check if this is a subregister of a full register.
+  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_index);
+  if (reg_info->invalidate_regs &&
+      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
+    Error error;
+
+    RegisterValue full_value;
+    uint32_t full_reg = reg_info->invalidate_regs[0];
+    const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
+
+    // Read the full register.
+    error = ReadRegister(full_reg_info, full_value);
+    if (error.Fail())
+      return error;
+
+    lldb::ByteOrder byte_order = GetByteOrder();
+    uint8_t dst[RegisterValue::kMaxRegisterByteSize];
+
+    // Get the bytes for the full register.
+    const uint32_t dest_size = full_value.GetAsMemoryData(
+        full_reg_info, dst, sizeof(dst), byte_order, error);
+    if (error.Success() && dest_size) {
+      uint8_t src[RegisterValue::kMaxRegisterByteSize];
+
+      // Get the bytes for the source data.
+      const uint32_t src_size = reg_value.GetAsMemoryData(
+          reg_info, src, sizeof(src), byte_order, error);
+      if (error.Success() && src_size && (src_size < dest_size)) {
+        // Copy the src bytes to the destination.
+        memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
+        // Set this full register as the value to write.
+        value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
+        value_to_write.SetType(full_reg_info);
+        reg_to_write = full_reg;
+      }
     }
+  }
 
-    const RegisterInfo *const register_to_write_info_p = GetRegisterInfoAtIndex (reg_to_write);
-    assert (register_to_write_info_p && "register to write does not have valid RegisterInfo");
-    if (!register_to_write_info_p)
-        return Error("NativeRegisterContextLinux::%s failed to get RegisterInfo for write register index %" PRIu32, __FUNCTION__, reg_to_write);
+  const RegisterInfo *const register_to_write_info_p =
+      GetRegisterInfoAtIndex(reg_to_write);
+  assert(register_to_write_info_p &&
+         "register to write does not have valid RegisterInfo");
+  if (!register_to_write_info_p)
+    return Error("NativeRegisterContextLinux::%s failed to get RegisterInfo "
+                 "for write register index %" PRIu32,
+                 __FUNCTION__, reg_to_write);
 
-    return DoWriteRegisterValue(reg_info->byte_offset, reg_info->name, reg_value);
+  return DoWriteRegisterValue(reg_info->byte_offset, reg_info->name, reg_value);
 }
 
-Error
-NativeRegisterContextLinux::ReadGPR()
-{
-    void* buf = GetGPRBuffer();
-    if (!buf)
-        return Error("GPR buffer is NULL");
-    size_t buf_size = GetGPRSize();
+Error NativeRegisterContextLinux::ReadGPR() {
+  void *buf = GetGPRBuffer();
+  if (!buf)
+    return Error("GPR buffer is NULL");
+  size_t buf_size = GetGPRSize();
 
-    return DoReadGPR(buf, buf_size);
+  return DoReadGPR(buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::WriteGPR()
-{
-    void* buf = GetGPRBuffer();
-    if (!buf)
-        return Error("GPR buffer is NULL");
-    size_t buf_size = GetGPRSize();
+Error NativeRegisterContextLinux::WriteGPR() {
+  void *buf = GetGPRBuffer();
+  if (!buf)
+    return Error("GPR buffer is NULL");
+  size_t buf_size = GetGPRSize();
 
-    return DoWriteGPR(buf, buf_size);
+  return DoWriteGPR(buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::ReadFPR()
-{
-    void* buf = GetFPRBuffer();
-    if (!buf)
-        return Error("FPR buffer is NULL");
-    size_t buf_size = GetFPRSize();
+Error NativeRegisterContextLinux::ReadFPR() {
+  void *buf = GetFPRBuffer();
+  if (!buf)
+    return Error("FPR buffer is NULL");
+  size_t buf_size = GetFPRSize();
 
-    return DoReadFPR(buf, buf_size);
+  return DoReadFPR(buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::WriteFPR()
-{
-    void* buf = GetFPRBuffer();
-    if (!buf)
-        return Error("FPR buffer is NULL");
-    size_t buf_size = GetFPRSize();
+Error NativeRegisterContextLinux::WriteFPR() {
+  void *buf = GetFPRBuffer();
+  if (!buf)
+    return Error("FPR buffer is NULL");
+  size_t buf_size = GetFPRSize();
 
-    return DoWriteFPR(buf, buf_size);
+  return DoWriteFPR(buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::ReadRegisterSet(void *buf, size_t buf_size, unsigned int regset)
-{
-    return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(),
-            static_cast<void *>(&regset), buf, buf_size);
+Error NativeRegisterContextLinux::ReadRegisterSet(void *buf, size_t buf_size,
+                                                  unsigned int regset) {
+  return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(),
+                                           static_cast<void *>(&regset), buf,
+                                           buf_size);
 }
 
-Error
-NativeRegisterContextLinux::WriteRegisterSet(void *buf, size_t buf_size, unsigned int regset)
-{
-    return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(),
-            static_cast<void *>(&regset), buf, buf_size);
+Error NativeRegisterContextLinux::WriteRegisterSet(void *buf, size_t buf_size,
+                                                   unsigned int regset) {
+  return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(),
+                                           static_cast<void *>(&regset), buf,
+                                           buf_size);
 }
 
-Error
-NativeRegisterContextLinux::DoReadRegisterValue(uint32_t offset,
-                                                const char* reg_name,
-                                                uint32_t size,
-                                                RegisterValue &value)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_REGISTERS));
+Error NativeRegisterContextLinux::DoReadRegisterValue(uint32_t offset,
+                                                      const char *reg_name,
+                                                      uint32_t size,
+                                                      RegisterValue &value) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_REGISTERS));
 
-    long data;
-    Error error = NativeProcessLinux::PtraceWrapper(
-            PTRACE_PEEKUSER, m_thread.GetID(), reinterpret_cast<void *>(offset), nullptr, 0, &data);
+  long data;
+  Error error = NativeProcessLinux::PtraceWrapper(
+      PTRACE_PEEKUSER, m_thread.GetID(), reinterpret_cast<void *>(offset),
+      nullptr, 0, &data);
 
-    if (error.Success())
-        // First cast to an unsigned of the same size to avoid sign extension.
-        value.SetUInt64(static_cast<unsigned long>(data));
+  if (error.Success())
+    // First cast to an unsigned of the same size to avoid sign extension.
+    value.SetUInt64(static_cast<unsigned long>(data));
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux::%s() reg %s: 0x%lx", __FUNCTION__, reg_name, data);
+  if (log)
+    log->Printf("NativeRegisterContextLinux::%s() reg %s: 0x%lx", __FUNCTION__,
+                reg_name, data);
 
-    return error;
+  return error;
 }
 
-Error
-NativeRegisterContextLinux::DoWriteRegisterValue(uint32_t offset,
-                                                 const char* reg_name,
-                                                 const RegisterValue &value)
-{
-    Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_REGISTERS));
+Error NativeRegisterContextLinux::DoWriteRegisterValue(
+    uint32_t offset, const char *reg_name, const RegisterValue &value) {
+  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_REGISTERS));
 
-    void* buf = reinterpret_cast<void *>(value.GetAsUInt64());
+  void *buf = reinterpret_cast<void *>(value.GetAsUInt64());
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux::%s() reg %s: %p", __FUNCTION__, reg_name, buf);
+  if (log)
+    log->Printf("NativeRegisterContextLinux::%s() reg %s: %p", __FUNCTION__,
+                reg_name, buf);
 
-    return NativeProcessLinux::PtraceWrapper(
-            PTRACE_POKEUSER, m_thread.GetID(), reinterpret_cast<void *>(offset), buf);
+  return NativeProcessLinux::PtraceWrapper(
+      PTRACE_POKEUSER, m_thread.GetID(), reinterpret_cast<void *>(offset), buf);
 }
 
-Error
-NativeRegisterContextLinux::DoReadGPR(void *buf, size_t buf_size)
-{
-    return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), nullptr, buf, buf_size);
+Error NativeRegisterContextLinux::DoReadGPR(void *buf, size_t buf_size) {
+  return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(),
+                                           nullptr, buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::DoWriteGPR(void *buf, size_t buf_size)
-{
-    return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGS, m_thread.GetID(), nullptr, buf, buf_size);
+Error NativeRegisterContextLinux::DoWriteGPR(void *buf, size_t buf_size) {
+  return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGS, m_thread.GetID(),
+                                           nullptr, buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::DoReadFPR(void *buf, size_t buf_size)
-{
-    return NativeProcessLinux::PtraceWrapper(PTRACE_GETFPREGS, m_thread.GetID(), nullptr, buf, buf_size);
+Error NativeRegisterContextLinux::DoReadFPR(void *buf, size_t buf_size) {
+  return NativeProcessLinux::PtraceWrapper(PTRACE_GETFPREGS, m_thread.GetID(),
+                                           nullptr, buf, buf_size);
 }
 
-Error
-NativeRegisterContextLinux::DoWriteFPR(void *buf, size_t buf_size)
-{
-    return NativeProcessLinux::PtraceWrapper(PTRACE_SETFPREGS, m_thread.GetID(), nullptr, buf, buf_size);
+Error NativeRegisterContextLinux::DoWriteFPR(void *buf, size_t buf_size) {
+  return NativeProcessLinux::PtraceWrapper(PTRACE_SETFPREGS, m_thread.GetID(),
+                                           nullptr, buf, buf_size);
 }

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.h Tue Sep  6 15:57:50 2016
@@ -18,87 +18,72 @@
 namespace lldb_private {
 namespace process_linux {
 
-class NativeRegisterContextLinux : public NativeRegisterContextRegisterInfo
-{
+class NativeRegisterContextLinux : public NativeRegisterContextRegisterInfo {
 public:
-    NativeRegisterContextLinux(NativeThreadProtocol &native_thread,
-                               uint32_t concrete_frame_idx,
-                               RegisterInfoInterface *reg_info_interface_p);
-
-    // This function is implemented in the NativeRegisterContextLinux_* subclasses to create a new
-    // instance of the host specific NativeRegisterContextLinux. The implementations can't collide
-    // as only one NativeRegisterContextLinux_* variant should be compiled into the final
-    // executable.
-    static NativeRegisterContextLinux*
-    CreateHostNativeRegisterContextLinux(const ArchSpec& target_arch,
-                                         NativeThreadProtocol &native_thread,
-                                         uint32_t concrete_frame_idx);
+  NativeRegisterContextLinux(NativeThreadProtocol &native_thread,
+                             uint32_t concrete_frame_idx,
+                             RegisterInfoInterface *reg_info_interface_p);
+
+  // This function is implemented in the NativeRegisterContextLinux_* subclasses
+  // to create a new
+  // instance of the host specific NativeRegisterContextLinux. The
+  // implementations can't collide
+  // as only one NativeRegisterContextLinux_* variant should be compiled into
+  // the final
+  // executable.
+  static NativeRegisterContextLinux *
+  CreateHostNativeRegisterContextLinux(const ArchSpec &target_arch,
+                                       NativeThreadProtocol &native_thread,
+                                       uint32_t concrete_frame_idx);
 
 protected:
-    lldb::ByteOrder
-    GetByteOrder() const;
+  lldb::ByteOrder GetByteOrder() const;
 
-    virtual Error
-    ReadRegisterRaw(uint32_t reg_index, RegisterValue& reg_value);
+  virtual Error ReadRegisterRaw(uint32_t reg_index, RegisterValue &reg_value);
 
-    virtual Error
-    WriteRegisterRaw(uint32_t reg_index, const RegisterValue& reg_value);
+  virtual Error WriteRegisterRaw(uint32_t reg_index,
+                                 const RegisterValue &reg_value);
 
-    virtual Error
-    ReadRegisterSet(void *buf, size_t buf_size, unsigned int regset);
+  virtual Error ReadRegisterSet(void *buf, size_t buf_size,
+                                unsigned int regset);
 
-    virtual Error
-    WriteRegisterSet(void *buf, size_t buf_size, unsigned int regset);
+  virtual Error WriteRegisterSet(void *buf, size_t buf_size,
+                                 unsigned int regset);
 
-    virtual Error
-    ReadGPR();
+  virtual Error ReadGPR();
 
-    virtual Error
-    WriteGPR();
+  virtual Error WriteGPR();
 
-    virtual Error
-    ReadFPR();
+  virtual Error ReadFPR();
 
-    virtual Error
-    WriteFPR();
+  virtual Error WriteFPR();
 
-    virtual void*
-    GetGPRBuffer() { return nullptr; }
+  virtual void *GetGPRBuffer() { return nullptr; }
 
-    virtual size_t
-    GetGPRSize() { return GetRegisterInfoInterface().GetGPRSize(); }
+  virtual size_t GetGPRSize() {
+    return GetRegisterInfoInterface().GetGPRSize();
+  }
 
-    virtual void*
-    GetFPRBuffer() { return nullptr; }
+  virtual void *GetFPRBuffer() { return nullptr; }
 
-    virtual size_t
-    GetFPRSize() { return 0; }
+  virtual size_t GetFPRSize() { return 0; }
 
+  // The Do*** functions are executed on the privileged thread and can perform
+  // ptrace
+  // operations directly.
+  virtual Error DoReadRegisterValue(uint32_t offset, const char *reg_name,
+                                    uint32_t size, RegisterValue &value);
 
-    // The Do*** functions are executed on the privileged thread and can perform ptrace
-    // operations directly.
-    virtual Error
-    DoReadRegisterValue(uint32_t offset,
-                        const char* reg_name,
-                        uint32_t size,
-                        RegisterValue &value);
+  virtual Error DoWriteRegisterValue(uint32_t offset, const char *reg_name,
+                                     const RegisterValue &value);
 
-    virtual Error
-    DoWriteRegisterValue(uint32_t offset,
-                       const char* reg_name,
-                       const RegisterValue &value);
+  virtual Error DoReadGPR(void *buf, size_t buf_size);
 
-    virtual Error
-    DoReadGPR(void *buf, size_t buf_size);
+  virtual Error DoWriteGPR(void *buf, size_t buf_size);
 
-    virtual Error
-    DoWriteGPR(void *buf, size_t buf_size);
+  virtual Error DoReadFPR(void *buf, size_t buf_size);
 
-    virtual Error
-    DoReadFPR(void *buf, size_t buf_size);
-
-    virtual Error
-    DoWriteFPR(void *buf, size_t buf_size);
+  virtual Error DoWriteFPR(void *buf, size_t buf_size);
 };
 
 } // namespace process_linux

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp Tue Sep  6 15:57:50 2016
@@ -22,21 +22,21 @@
 #include <elf.h>
 #include <sys/socket.h>
 
-#define REG_CONTEXT_SIZE (GetGPRSize() + sizeof (m_fpr))
+#define REG_CONTEXT_SIZE (GetGPRSize() + sizeof(m_fpr))
 
 #ifndef PTRACE_GETVFPREGS
-  #define PTRACE_GETVFPREGS 27
-  #define PTRACE_SETVFPREGS 28
+#define PTRACE_GETVFPREGS 27
+#define PTRACE_SETVFPREGS 28
 #endif
 #ifndef PTRACE_GETHBPREGS
-  #define PTRACE_GETHBPREGS 29
-  #define PTRACE_SETHBPREGS 30
+#define PTRACE_GETHBPREGS 29
+#define PTRACE_SETHBPREGS 30
 #endif
 #if !defined(PTRACE_TYPE_ARG3)
-  #define PTRACE_TYPE_ARG3 void *
+#define PTRACE_TYPE_ARG3 void *
 #endif
 #if !defined(PTRACE_TYPE_ARG4)
-  #define PTRACE_TYPE_ARG4 void *
+#define PTRACE_TYPE_ARG4 void *
 #endif
 
 using namespace lldb;
@@ -44,1084 +44,933 @@ using namespace lldb_private;
 using namespace lldb_private::process_linux;
 
 // arm general purpose registers.
-static const uint32_t g_gpr_regnums_arm[] =
-{
-    gpr_r0_arm,
-    gpr_r1_arm,
-    gpr_r2_arm,
-    gpr_r3_arm,
-    gpr_r4_arm,
-    gpr_r5_arm,
-    gpr_r6_arm,
-    gpr_r7_arm,
-    gpr_r8_arm,
-    gpr_r9_arm,
-    gpr_r10_arm,
-    gpr_r11_arm,
-    gpr_r12_arm,
-    gpr_sp_arm,
-    gpr_lr_arm,
-    gpr_pc_arm,
-    gpr_cpsr_arm,
+static const uint32_t g_gpr_regnums_arm[] = {
+    gpr_r0_arm,         gpr_r1_arm,   gpr_r2_arm,  gpr_r3_arm, gpr_r4_arm,
+    gpr_r5_arm,         gpr_r6_arm,   gpr_r7_arm,  gpr_r8_arm, gpr_r9_arm,
+    gpr_r10_arm,        gpr_r11_arm,  gpr_r12_arm, gpr_sp_arm, gpr_lr_arm,
+    gpr_pc_arm,         gpr_cpsr_arm,
     LLDB_INVALID_REGNUM // register sets need to end with this flag
 };
-static_assert(((sizeof g_gpr_regnums_arm / sizeof g_gpr_regnums_arm[0]) - 1) == k_num_gpr_registers_arm, \
+static_assert(((sizeof g_gpr_regnums_arm / sizeof g_gpr_regnums_arm[0]) - 1) ==
+                  k_num_gpr_registers_arm,
               "g_gpr_regnums_arm has wrong number of register infos");
 
 // arm floating point registers.
-static const uint32_t g_fpu_regnums_arm[] =
-{
-    fpu_s0_arm,
-    fpu_s1_arm,
-    fpu_s2_arm,
-    fpu_s3_arm,
-    fpu_s4_arm,
-    fpu_s5_arm,
-    fpu_s6_arm,
-    fpu_s7_arm,
-    fpu_s8_arm,
-    fpu_s9_arm,
-    fpu_s10_arm,
-    fpu_s11_arm,
-    fpu_s12_arm,
-    fpu_s13_arm,
-    fpu_s14_arm,
-    fpu_s15_arm,
-    fpu_s16_arm,
-    fpu_s17_arm,
-    fpu_s18_arm,
-    fpu_s19_arm,
-    fpu_s20_arm,
-    fpu_s21_arm,
-    fpu_s22_arm,
-    fpu_s23_arm,
-    fpu_s24_arm,
-    fpu_s25_arm,
-    fpu_s26_arm,
-    fpu_s27_arm,
-    fpu_s28_arm,
-    fpu_s29_arm,
-    fpu_s30_arm,
-    fpu_s31_arm,
-    fpu_fpscr_arm,
-    fpu_d0_arm,
-    fpu_d1_arm,
-    fpu_d2_arm,
-    fpu_d3_arm,
-    fpu_d4_arm,
-    fpu_d5_arm,
-    fpu_d6_arm,
-    fpu_d7_arm,
-    fpu_d8_arm,
-    fpu_d9_arm,
-    fpu_d10_arm,
-    fpu_d11_arm,
-    fpu_d12_arm,
-    fpu_d13_arm,
-    fpu_d14_arm,
-    fpu_d15_arm,
-    fpu_d16_arm,
-    fpu_d17_arm,
-    fpu_d18_arm,
-    fpu_d19_arm,
-    fpu_d20_arm,
-    fpu_d21_arm,
-    fpu_d22_arm,
-    fpu_d23_arm,
-    fpu_d24_arm,
-    fpu_d25_arm,
-    fpu_d26_arm,
-    fpu_d27_arm,
-    fpu_d28_arm,
-    fpu_d29_arm,
-    fpu_d30_arm,
-    fpu_d31_arm,
-    fpu_q0_arm,
-    fpu_q1_arm,
-    fpu_q2_arm,
-    fpu_q3_arm,
-    fpu_q4_arm,
-    fpu_q5_arm,
-    fpu_q6_arm,
-    fpu_q7_arm,
-    fpu_q8_arm,
-    fpu_q9_arm,
-    fpu_q10_arm,
-    fpu_q11_arm,
-    fpu_q12_arm,
-    fpu_q13_arm,
-    fpu_q14_arm,
+static const uint32_t g_fpu_regnums_arm[] = {
+    fpu_s0_arm,         fpu_s1_arm,  fpu_s2_arm,    fpu_s3_arm,  fpu_s4_arm,
+    fpu_s5_arm,         fpu_s6_arm,  fpu_s7_arm,    fpu_s8_arm,  fpu_s9_arm,
+    fpu_s10_arm,        fpu_s11_arm, fpu_s12_arm,   fpu_s13_arm, fpu_s14_arm,
+    fpu_s15_arm,        fpu_s16_arm, fpu_s17_arm,   fpu_s18_arm, fpu_s19_arm,
+    fpu_s20_arm,        fpu_s21_arm, fpu_s22_arm,   fpu_s23_arm, fpu_s24_arm,
+    fpu_s25_arm,        fpu_s26_arm, fpu_s27_arm,   fpu_s28_arm, fpu_s29_arm,
+    fpu_s30_arm,        fpu_s31_arm, fpu_fpscr_arm, fpu_d0_arm,  fpu_d1_arm,
+    fpu_d2_arm,         fpu_d3_arm,  fpu_d4_arm,    fpu_d5_arm,  fpu_d6_arm,
+    fpu_d7_arm,         fpu_d8_arm,  fpu_d9_arm,    fpu_d10_arm, fpu_d11_arm,
+    fpu_d12_arm,        fpu_d13_arm, fpu_d14_arm,   fpu_d15_arm, fpu_d16_arm,
+    fpu_d17_arm,        fpu_d18_arm, fpu_d19_arm,   fpu_d20_arm, fpu_d21_arm,
+    fpu_d22_arm,        fpu_d23_arm, fpu_d24_arm,   fpu_d25_arm, fpu_d26_arm,
+    fpu_d27_arm,        fpu_d28_arm, fpu_d29_arm,   fpu_d30_arm, fpu_d31_arm,
+    fpu_q0_arm,         fpu_q1_arm,  fpu_q2_arm,    fpu_q3_arm,  fpu_q4_arm,
+    fpu_q5_arm,         fpu_q6_arm,  fpu_q7_arm,    fpu_q8_arm,  fpu_q9_arm,
+    fpu_q10_arm,        fpu_q11_arm, fpu_q12_arm,   fpu_q13_arm, fpu_q14_arm,
     fpu_q15_arm,
     LLDB_INVALID_REGNUM // register sets need to end with this flag
 };
-static_assert(((sizeof g_fpu_regnums_arm / sizeof g_fpu_regnums_arm[0]) - 1) == k_num_fpr_registers_arm, \
+static_assert(((sizeof g_fpu_regnums_arm / sizeof g_fpu_regnums_arm[0]) - 1) ==
+                  k_num_fpr_registers_arm,
               "g_fpu_regnums_arm has wrong number of register infos");
 
 namespace {
-    // Number of register sets provided by this context.
-    enum
-    {
-        k_num_register_sets = 2
-    };
+// Number of register sets provided by this context.
+enum { k_num_register_sets = 2 };
 }
 
 // Register sets for arm.
-static const RegisterSet
-g_reg_sets_arm[k_num_register_sets] =
-{
-    { "General Purpose Registers",  "gpr", k_num_gpr_registers_arm, g_gpr_regnums_arm },
-    { "Floating Point Registers",   "fpu", k_num_fpr_registers_arm, g_fpu_regnums_arm }
-};
+static const RegisterSet g_reg_sets_arm[k_num_register_sets] = {
+    {"General Purpose Registers", "gpr", k_num_gpr_registers_arm,
+     g_gpr_regnums_arm},
+    {"Floating Point Registers", "fpu", k_num_fpr_registers_arm,
+     g_fpu_regnums_arm}};
 
 #if defined(__arm__)
 
-NativeRegisterContextLinux*
-NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(const ArchSpec& target_arch,
-                                                                 NativeThreadProtocol &native_thread,
-                                                                 uint32_t concrete_frame_idx)
-{
-    return new NativeRegisterContextLinux_arm(target_arch, native_thread, concrete_frame_idx);
+NativeRegisterContextLinux *
+NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
+    const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
+    uint32_t concrete_frame_idx) {
+  return new NativeRegisterContextLinux_arm(target_arch, native_thread,
+                                            concrete_frame_idx);
 }
 
 #endif // defined(__arm__)
 
-NativeRegisterContextLinux_arm::NativeRegisterContextLinux_arm (const ArchSpec& target_arch,
-                                                                NativeThreadProtocol &native_thread,
-                                                                uint32_t concrete_frame_idx) :
-    NativeRegisterContextLinux (native_thread, concrete_frame_idx, new RegisterContextLinux_arm(target_arch))
-{
-    switch (target_arch.GetMachine())
-    {
-        case llvm::Triple::arm:
-            m_reg_info.num_registers     = k_num_registers_arm;
-            m_reg_info.num_gpr_registers = k_num_gpr_registers_arm;
-            m_reg_info.num_fpr_registers = k_num_fpr_registers_arm;
-            m_reg_info.last_gpr          = k_last_gpr_arm;
-            m_reg_info.first_fpr         = k_first_fpr_arm;
-            m_reg_info.last_fpr          = k_last_fpr_arm;
-            m_reg_info.first_fpr_v       = fpu_s0_arm;
-            m_reg_info.last_fpr_v        = fpu_s31_arm;
-            m_reg_info.gpr_flags         = gpr_cpsr_arm;
-            break;
-        default:
-            assert(false && "Unhandled target architecture.");
-            break;
-    }
-
-    ::memset(&m_fpr, 0, sizeof (m_fpr));
-    ::memset(&m_gpr_arm, 0, sizeof (m_gpr_arm));
-    ::memset(&m_hwp_regs, 0, sizeof (m_hwp_regs));
-
-    // 16 is just a maximum value, query hardware for actual watchpoint count
-    m_max_hwp_supported = 16;
-    m_max_hbp_supported = 16;
-    m_refresh_hwdebug_info = true;
+NativeRegisterContextLinux_arm::NativeRegisterContextLinux_arm(
+    const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
+    uint32_t concrete_frame_idx)
+    : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+                                 new RegisterContextLinux_arm(target_arch)) {
+  switch (target_arch.GetMachine()) {
+  case llvm::Triple::arm:
+    m_reg_info.num_registers = k_num_registers_arm;
+    m_reg_info.num_gpr_registers = k_num_gpr_registers_arm;
+    m_reg_info.num_fpr_registers = k_num_fpr_registers_arm;
+    m_reg_info.last_gpr = k_last_gpr_arm;
+    m_reg_info.first_fpr = k_first_fpr_arm;
+    m_reg_info.last_fpr = k_last_fpr_arm;
+    m_reg_info.first_fpr_v = fpu_s0_arm;
+    m_reg_info.last_fpr_v = fpu_s31_arm;
+    m_reg_info.gpr_flags = gpr_cpsr_arm;
+    break;
+  default:
+    assert(false && "Unhandled target architecture.");
+    break;
+  }
+
+  ::memset(&m_fpr, 0, sizeof(m_fpr));
+  ::memset(&m_gpr_arm, 0, sizeof(m_gpr_arm));
+  ::memset(&m_hwp_regs, 0, sizeof(m_hwp_regs));
+
+  // 16 is just a maximum value, query hardware for actual watchpoint count
+  m_max_hwp_supported = 16;
+  m_max_hbp_supported = 16;
+  m_refresh_hwdebug_info = true;
+}
+
+uint32_t NativeRegisterContextLinux_arm::GetRegisterSetCount() const {
+  return k_num_register_sets;
+}
+
+uint32_t NativeRegisterContextLinux_arm::GetUserRegisterCount() const {
+  uint32_t count = 0;
+  for (uint32_t set_index = 0; set_index < k_num_register_sets; ++set_index)
+    count += g_reg_sets_arm[set_index].num_registers;
+  return count;
 }
 
-uint32_t
-NativeRegisterContextLinux_arm::GetRegisterSetCount () const
-{
-    return k_num_register_sets;
-}
+const RegisterSet *
+NativeRegisterContextLinux_arm::GetRegisterSet(uint32_t set_index) const {
+  if (set_index < k_num_register_sets)
+    return &g_reg_sets_arm[set_index];
 
-uint32_t
-NativeRegisterContextLinux_arm::GetUserRegisterCount() const
-{
-    uint32_t count = 0;
-    for (uint32_t set_index = 0; set_index < k_num_register_sets; ++set_index)
-        count += g_reg_sets_arm[set_index].num_registers;
-    return count;
+  return nullptr;
 }
 
-const RegisterSet *
-NativeRegisterContextLinux_arm::GetRegisterSet (uint32_t set_index) const
-{
-    if (set_index < k_num_register_sets)
-        return &g_reg_sets_arm[set_index];
-
-    return nullptr;
-}
-
-Error
-NativeRegisterContextLinux_arm::ReadRegister (const RegisterInfo *reg_info, RegisterValue &reg_value)
-{
-    Error error;
-
-    if (!reg_info)
-    {
-        error.SetErrorString ("reg_info NULL");
-        return error;
-    }
+Error NativeRegisterContextLinux_arm::ReadRegister(const RegisterInfo *reg_info,
+                                                   RegisterValue &reg_value) {
+  Error error;
 
-    const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
+  if (!reg_info) {
+    error.SetErrorString("reg_info NULL");
+    return error;
+  }
 
-    if (IsFPR(reg))
-    {
-        error = ReadFPR();
-        if (error.Fail())
-            return error;
-    }
-    else
-    {
-        uint32_t full_reg = reg;
-        bool is_subreg = reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
-
-        if (is_subreg)
-        {
-            // Read the full aligned 64-bit register.
-            full_reg = reg_info->invalidate_regs[0];
-        }
-
-        error = ReadRegisterRaw(full_reg, reg_value);
-
-        if (error.Success ())
-        {
-            // If our read was not aligned (for ah,bh,ch,dh), shift our returned value one byte to the right.
-            if (is_subreg && (reg_info->byte_offset & 0x1))
-                reg_value.SetUInt64(reg_value.GetAsUInt64() >> 8);
-
-            // If our return byte size was greater than the return value reg size, then
-            // use the type specified by reg_info rather than the uint64_t default
-            if (reg_value.GetByteSize() > reg_info->byte_size)
-                reg_value.SetType(reg_info);
-        }
-        return error;
-    }
+  const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
 
-    // Get pointer to m_fpr variable and set the data from it.
-    uint32_t fpr_offset = CalculateFprOffset(reg_info);
-    assert (fpr_offset < sizeof m_fpr);
-    uint8_t *src = (uint8_t *)&m_fpr + fpr_offset;
-    switch (reg_info->byte_size)
-    {
-        case 2:
-            reg_value.SetUInt16(*(uint16_t *)src);
-            break;
-        case 4:
-            reg_value.SetUInt32(*(uint32_t *)src);
-            break;
-        case 8:
-            reg_value.SetUInt64(*(uint64_t *)src);
-            break;
-        case 16:
-            reg_value.SetBytes(src, 16, GetByteOrder());
-            break;
-        default:
-            assert(false && "Unhandled data size.");
-            error.SetErrorStringWithFormat ("unhandled byte size: %" PRIu32, reg_info->byte_size);
-            break;
+  if (IsFPR(reg)) {
+    error = ReadFPR();
+    if (error.Fail())
+      return error;
+  } else {
+    uint32_t full_reg = reg;
+    bool is_subreg = reg_info->invalidate_regs &&
+                     (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
+
+    if (is_subreg) {
+      // Read the full aligned 64-bit register.
+      full_reg = reg_info->invalidate_regs[0];
+    }
+
+    error = ReadRegisterRaw(full_reg, reg_value);
+
+    if (error.Success()) {
+      // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
+      // one byte to the right.
+      if (is_subreg && (reg_info->byte_offset & 0x1))
+        reg_value.SetUInt64(reg_value.GetAsUInt64() >> 8);
+
+      // If our return byte size was greater than the return value reg size,
+      // then
+      // use the type specified by reg_info rather than the uint64_t default
+      if (reg_value.GetByteSize() > reg_info->byte_size)
+        reg_value.SetType(reg_info);
     }
-
     return error;
-}
+  }
+
+  // Get pointer to m_fpr variable and set the data from it.
+  uint32_t fpr_offset = CalculateFprOffset(reg_info);
+  assert(fpr_offset < sizeof m_fpr);
+  uint8_t *src = (uint8_t *)&m_fpr + fpr_offset;
+  switch (reg_info->byte_size) {
+  case 2:
+    reg_value.SetUInt16(*(uint16_t *)src);
+    break;
+  case 4:
+    reg_value.SetUInt32(*(uint32_t *)src);
+    break;
+  case 8:
+    reg_value.SetUInt64(*(uint64_t *)src);
+    break;
+  case 16:
+    reg_value.SetBytes(src, 16, GetByteOrder());
+    break;
+  default:
+    assert(false && "Unhandled data size.");
+    error.SetErrorStringWithFormat("unhandled byte size: %" PRIu32,
+                                   reg_info->byte_size);
+    break;
+  }
+
+  return error;
+}
+
+Error NativeRegisterContextLinux_arm::WriteRegister(
+    const RegisterInfo *reg_info, const RegisterValue &reg_value) {
+  if (!reg_info)
+    return Error("reg_info NULL");
+
+  const uint32_t reg_index = reg_info->kinds[lldb::eRegisterKindLLDB];
+  if (reg_index == LLDB_INVALID_REGNUM)
+    return Error("no lldb regnum for %s", reg_info && reg_info->name
+                                              ? reg_info->name
+                                              : "<unknown register>");
 
-Error
-NativeRegisterContextLinux_arm::WriteRegister (const RegisterInfo *reg_info, const RegisterValue &reg_value)
-{
-    if (!reg_info)
-        return Error ("reg_info NULL");
-
-    const uint32_t reg_index = reg_info->kinds[lldb::eRegisterKindLLDB];
-    if (reg_index == LLDB_INVALID_REGNUM)
-        return Error ("no lldb regnum for %s", reg_info && reg_info->name ? reg_info->name : "<unknown register>");
-
-    if (IsGPR(reg_index))
-        return WriteRegisterRaw(reg_index, reg_value);
-
-    if (IsFPR(reg_index))
-    {
-        // Get pointer to m_fpr variable and set the data to it.
-        uint32_t fpr_offset = CalculateFprOffset(reg_info);
-        assert (fpr_offset < sizeof m_fpr);
-        uint8_t *dst = (uint8_t *)&m_fpr + fpr_offset;
-        switch (reg_info->byte_size)
-        {
-            case 2:
-                *(uint16_t *)dst = reg_value.GetAsUInt16();
-                break;
-            case 4:
-                *(uint32_t *)dst = reg_value.GetAsUInt32();
-                break;
-            case 8:
-                *(uint64_t *)dst = reg_value.GetAsUInt64();
-                break;
-            default:
-                assert(false && "Unhandled data size.");
-                return Error ("unhandled register data size %" PRIu32, reg_info->byte_size);
-        }
-
-        Error error = WriteFPR();
-        if (error.Fail())
-            return error;
+  if (IsGPR(reg_index))
+    return WriteRegisterRaw(reg_index, reg_value);
 
-        return Error ();
+  if (IsFPR(reg_index)) {
+    // Get pointer to m_fpr variable and set the data to it.
+    uint32_t fpr_offset = CalculateFprOffset(reg_info);
+    assert(fpr_offset < sizeof m_fpr);
+    uint8_t *dst = (uint8_t *)&m_fpr + fpr_offset;
+    switch (reg_info->byte_size) {
+    case 2:
+      *(uint16_t *)dst = reg_value.GetAsUInt16();
+      break;
+    case 4:
+      *(uint32_t *)dst = reg_value.GetAsUInt32();
+      break;
+    case 8:
+      *(uint64_t *)dst = reg_value.GetAsUInt64();
+      break;
+    default:
+      assert(false && "Unhandled data size.");
+      return Error("unhandled register data size %" PRIu32,
+                   reg_info->byte_size);
     }
 
-    return Error ("failed - register wasn't recognized to be a GPR or an FPR, write strategy unknown");
-}
+    Error error = WriteFPR();
+    if (error.Fail())
+      return error;
 
-Error
-NativeRegisterContextLinux_arm::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
-{
-    Error error;
+    return Error();
+  }
 
-    data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
-    if (!data_sp)
-        return Error ("failed to allocate DataBufferHeap instance of size %" PRIu64, (uint64_t)REG_CONTEXT_SIZE);
+  return Error("failed - register wasn't recognized to be a GPR or an FPR, "
+               "write strategy unknown");
+}
 
-    error = ReadGPR();
-    if (error.Fail())
-        return error;
+Error NativeRegisterContextLinux_arm::ReadAllRegisterValues(
+    lldb::DataBufferSP &data_sp) {
+  Error error;
 
-    error = ReadFPR();
-    if (error.Fail())
-        return error;
+  data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
+  if (!data_sp)
+    return Error("failed to allocate DataBufferHeap instance of size %" PRIu64,
+                 (uint64_t)REG_CONTEXT_SIZE);
 
-    uint8_t *dst = data_sp->GetBytes ();
-    if (dst == nullptr)
-    {
-        error.SetErrorStringWithFormat ("DataBufferHeap instance of size %" PRIu64 " returned a null pointer", (uint64_t)REG_CONTEXT_SIZE);
-        return error;
-    }
+  error = ReadGPR();
+  if (error.Fail())
+    return error;
 
-    ::memcpy (dst, &m_gpr_arm, GetGPRSize());
-    dst += GetGPRSize();
-    ::memcpy (dst, &m_fpr, sizeof(m_fpr));
+  error = ReadFPR();
+  if (error.Fail())
+    return error;
 
+  uint8_t *dst = data_sp->GetBytes();
+  if (dst == nullptr) {
+    error.SetErrorStringWithFormat("DataBufferHeap instance of size %" PRIu64
+                                   " returned a null pointer",
+                                   (uint64_t)REG_CONTEXT_SIZE);
     return error;
-}
+  }
 
-Error
-NativeRegisterContextLinux_arm::WriteAllRegisterValues (const lldb::DataBufferSP &data_sp)
-{
-    Error error;
-
-    if (!data_sp)
-    {
-        error.SetErrorStringWithFormat ("NativeRegisterContextLinux_x86_64::%s invalid data_sp provided", __FUNCTION__);
-        return error;
-    }
+  ::memcpy(dst, &m_gpr_arm, GetGPRSize());
+  dst += GetGPRSize();
+  ::memcpy(dst, &m_fpr, sizeof(m_fpr));
 
-    if (data_sp->GetByteSize () != REG_CONTEXT_SIZE)
-    {
-        error.SetErrorStringWithFormat ("NativeRegisterContextLinux_x86_64::%s data_sp contained mismatched data size, expected %" PRIu64 ", actual %" PRIu64, __FUNCTION__, (uint64_t)REG_CONTEXT_SIZE, data_sp->GetByteSize ());
-        return error;
-    }
+  return error;
+}
 
+Error NativeRegisterContextLinux_arm::WriteAllRegisterValues(
+    const lldb::DataBufferSP &data_sp) {
+  Error error;
 
-    uint8_t *src = data_sp->GetBytes ();
-    if (src == nullptr)
-    {
-        error.SetErrorStringWithFormat ("NativeRegisterContextLinux_x86_64::%s DataBuffer::GetBytes() returned a null pointer", __FUNCTION__);
-        return error;
-    }
-    ::memcpy (&m_gpr_arm, src, GetRegisterInfoInterface ().GetGPRSize ());
+  if (!data_sp) {
+    error.SetErrorStringWithFormat(
+        "NativeRegisterContextLinux_x86_64::%s invalid data_sp provided",
+        __FUNCTION__);
+    return error;
+  }
 
-    error = WriteGPR();
-    if (error.Fail())
-        return error;
+  if (data_sp->GetByteSize() != REG_CONTEXT_SIZE) {
+    error.SetErrorStringWithFormat(
+        "NativeRegisterContextLinux_x86_64::%s data_sp contained mismatched "
+        "data size, expected %" PRIu64 ", actual %" PRIu64,
+        __FUNCTION__, (uint64_t)REG_CONTEXT_SIZE, data_sp->GetByteSize());
+    return error;
+  }
 
-    src += GetRegisterInfoInterface ().GetGPRSize ();
-    ::memcpy (&m_fpr, src, sizeof(m_fpr));
+  uint8_t *src = data_sp->GetBytes();
+  if (src == nullptr) {
+    error.SetErrorStringWithFormat("NativeRegisterContextLinux_x86_64::%s "
+                                   "DataBuffer::GetBytes() returned a null "
+                                   "pointer",
+                                   __FUNCTION__);
+    return error;
+  }
+  ::memcpy(&m_gpr_arm, src, GetRegisterInfoInterface().GetGPRSize());
 
-    error = WriteFPR();
-    if (error.Fail())
-        return error;
+  error = WriteGPR();
+  if (error.Fail())
+    return error;
+
+  src += GetRegisterInfoInterface().GetGPRSize();
+  ::memcpy(&m_fpr, src, sizeof(m_fpr));
 
+  error = WriteFPR();
+  if (error.Fail())
     return error;
+
+  return error;
 }
 
-bool
-NativeRegisterContextLinux_arm::IsGPR(unsigned reg) const
-{
-    return reg <= m_reg_info.last_gpr;   // GPR's come first.
+bool NativeRegisterContextLinux_arm::IsGPR(unsigned reg) const {
+  return reg <= m_reg_info.last_gpr; // GPR's come first.
 }
 
-bool
-NativeRegisterContextLinux_arm::IsFPR(unsigned reg) const
-{
-    return (m_reg_info.first_fpr <= reg && reg <= m_reg_info.last_fpr);
+bool NativeRegisterContextLinux_arm::IsFPR(unsigned reg) const {
+  return (m_reg_info.first_fpr <= reg && reg <= m_reg_info.last_fpr);
 }
 
 uint32_t
-NativeRegisterContextLinux_arm::SetHardwareBreakpoint (lldb::addr_t addr, size_t size)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
+NativeRegisterContextLinux_arm::SetHardwareBreakpoint(lldb::addr_t addr,
+                                                      size_t size) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    Error error;
+  Error error;
 
-    // Read hardware breakpoint and watchpoint information.
-    error = ReadHardwareDebugInfo ();
+  // Read hardware breakpoint and watchpoint information.
+  error = ReadHardwareDebugInfo();
 
-    if (error.Fail())
-        return LLDB_INVALID_INDEX32;
+  if (error.Fail())
+    return LLDB_INVALID_INDEX32;
+
+  uint32_t control_value = 0, bp_index = 0;
+
+  // Check if size has a valid hardware breakpoint length.
+  // Thumb instructions are 2-bytes but we have no way here to determine
+  // if target address is a thumb or arm instruction.
+  // TODO: Add support for setting thumb mode hardware breakpoints
+  if (size != 4 && size != 2)
+    return LLDB_INVALID_INDEX32;
+
+  // Setup control value
+  // Make the byte_mask into a valid Byte Address Select mask
+  control_value = 0xfu << 5;
+
+  // Enable this breakpoint and make it stop in privileged or user mode;
+  control_value |= 7;
+
+  // Make sure bits 1:0 are clear in our address
+  // This should be different once we support thumb here.
+  addr &= ~((lldb::addr_t)3);
 
-    uint32_t control_value = 0, bp_index = 0;
+  // Iterate over stored hardware breakpoints
+  // Find a free bp_index or update reference count if duplicate.
+  bp_index = LLDB_INVALID_INDEX32;
 
-    // Check if size has a valid hardware breakpoint length.
-    // Thumb instructions are 2-bytes but we have no way here to determine
-    // if target address is a thumb or arm instruction.
-    // TODO: Add support for setting thumb mode hardware breakpoints
-    if (size != 4 && size != 2)
-        return LLDB_INVALID_INDEX32;
-
-    // Setup control value
-    // Make the byte_mask into a valid Byte Address Select mask
-    control_value = 0xfu << 5;
-
-    // Enable this breakpoint and make it stop in privileged or user mode;
-    control_value |= 7;
-
-    // Make sure bits 1:0 are clear in our address
-    // This should be different once we support thumb here.
-    addr &= ~((lldb::addr_t)3);
-
-    // Iterate over stored hardware breakpoints
-    // Find a free bp_index or update reference count if duplicate.
-    bp_index = LLDB_INVALID_INDEX32;
-
-    for (uint32_t i = 0; i < m_max_hbp_supported; i++)
-    {
-        if ((m_hbr_regs[i].control & 1) == 0)
-        {
-            bp_index = i;  // Mark last free slot
-        }
-        else if (m_hbr_regs[i].address == addr && m_hbr_regs[i].control == control_value)
-        {
-            bp_index = i;  // Mark duplicate index
-            break;  // Stop searching here
-        }
+  for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
+    if ((m_hbr_regs[i].control & 1) == 0) {
+      bp_index = i; // Mark last free slot
+    } else if (m_hbr_regs[i].address == addr &&
+               m_hbr_regs[i].control == control_value) {
+      bp_index = i; // Mark duplicate index
+      break;        // Stop searching here
     }
+  }
 
-     if (bp_index == LLDB_INVALID_INDEX32)
-         return LLDB_INVALID_INDEX32;
+  if (bp_index == LLDB_INVALID_INDEX32)
+    return LLDB_INVALID_INDEX32;
 
-    // Add new or update existing breakpoint
-    if ((m_hbr_regs[bp_index].control & 1) == 0)
-    {
-        m_hbr_regs[bp_index].address = addr;
-        m_hbr_regs[bp_index].control = control_value;
-        m_hbr_regs[bp_index].refcount = 1;
-
-        // PTRACE call to set corresponding hardware breakpoint register.
-        error = WriteHardwareDebugRegs(eDREGTypeBREAK, bp_index);
-
-        if (error.Fail())
-        {
-            m_hbr_regs[bp_index].address = 0;
-            m_hbr_regs[bp_index].control &= ~1;
-            m_hbr_regs[bp_index].refcount = 0;
+  // Add new or update existing breakpoint
+  if ((m_hbr_regs[bp_index].control & 1) == 0) {
+    m_hbr_regs[bp_index].address = addr;
+    m_hbr_regs[bp_index].control = control_value;
+    m_hbr_regs[bp_index].refcount = 1;
 
-            return LLDB_INVALID_INDEX32;
-        }
+    // PTRACE call to set corresponding hardware breakpoint register.
+    error = WriteHardwareDebugRegs(eDREGTypeBREAK, bp_index);
+
+    if (error.Fail()) {
+      m_hbr_regs[bp_index].address = 0;
+      m_hbr_regs[bp_index].control &= ~1;
+      m_hbr_regs[bp_index].refcount = 0;
+
+      return LLDB_INVALID_INDEX32;
     }
-    else
-        m_hbr_regs[bp_index].refcount++;
+  } else
+    m_hbr_regs[bp_index].refcount++;
 
-    return bp_index;
+  return bp_index;
 }
 
-bool
-NativeRegisterContextLinux_arm::ClearHardwareBreakpoint (uint32_t hw_idx)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
+bool NativeRegisterContextLinux_arm::ClearHardwareBreakpoint(uint32_t hw_idx) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    Error error;
+  Error error;
 
-    // Read hardware breakpoint and watchpoint information.
-    error = ReadHardwareDebugInfo ();
+  // Read hardware breakpoint and watchpoint information.
+  error = ReadHardwareDebugInfo();
 
-    if (error.Fail())
-        return false;
+  if (error.Fail())
+    return false;
+
+  if (hw_idx >= m_max_hbp_supported)
+    return false;
 
-    if (hw_idx >= m_max_hbp_supported)
-        return false;
+  // Update reference count if multiple references.
+  if (m_hbr_regs[hw_idx].refcount > 1) {
+    m_hbr_regs[hw_idx].refcount--;
+    return true;
+  } else if (m_hbr_regs[hw_idx].refcount == 1) {
+    // Create a backup we can revert to in case of failure.
+    lldb::addr_t tempAddr = m_hbr_regs[hw_idx].address;
+    uint32_t tempControl = m_hbr_regs[hw_idx].control;
+    uint32_t tempRefCount = m_hbr_regs[hw_idx].refcount;
 
-    // Update reference count if multiple references.
-    if (m_hbr_regs[hw_idx].refcount > 1)
-    {
-        m_hbr_regs[hw_idx].refcount--;
-        return true;
-    }
-    else if (m_hbr_regs[hw_idx].refcount == 1)
-    {
-        // Create a backup we can revert to in case of failure.
-        lldb::addr_t tempAddr = m_hbr_regs[hw_idx].address;
-        uint32_t tempControl = m_hbr_regs[hw_idx].control;
-        uint32_t tempRefCount = m_hbr_regs[hw_idx].refcount;
-
-        m_hbr_regs[hw_idx].control &= ~1;
-        m_hbr_regs[hw_idx].address = 0;
-        m_hbr_regs[hw_idx].refcount = 0;
-
-        // PTRACE call to clear corresponding hardware breakpoint register.
-        WriteHardwareDebugRegs(eDREGTypeBREAK, hw_idx);
-
-        if (error.Fail())
-        {
-            m_hbr_regs[hw_idx].control = tempControl;
-            m_hbr_regs[hw_idx].address = tempAddr;
-            m_hbr_regs[hw_idx].refcount = tempRefCount;
+    m_hbr_regs[hw_idx].control &= ~1;
+    m_hbr_regs[hw_idx].address = 0;
+    m_hbr_regs[hw_idx].refcount = 0;
+
+    // PTRACE call to clear corresponding hardware breakpoint register.
+    WriteHardwareDebugRegs(eDREGTypeBREAK, hw_idx);
 
-            return false;
-        }
+    if (error.Fail()) {
+      m_hbr_regs[hw_idx].control = tempControl;
+      m_hbr_regs[hw_idx].address = tempAddr;
+      m_hbr_regs[hw_idx].refcount = tempRefCount;
 
-        return true;
+      return false;
     }
 
-    return false;
+    return true;
+  }
+
+  return false;
 }
 
-uint32_t
-NativeRegisterContextLinux_arm::NumSupportedHardwareWatchpoints ()
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
+uint32_t NativeRegisterContextLinux_arm::NumSupportedHardwareWatchpoints() {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    Error error;
+  Error error;
 
-    // Read hardware breakpoint and watchpoint information.
-    error = ReadHardwareDebugInfo ();
+  // Read hardware breakpoint and watchpoint information.
+  error = ReadHardwareDebugInfo();
 
-    if (error.Fail())
-        return 0;
+  if (error.Fail())
+    return 0;
 
-    return m_max_hwp_supported;
+  return m_max_hwp_supported;
 }
 
-uint32_t
-NativeRegisterContextLinux_arm::SetHardwareWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
-
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
-    
-    Error error;
+uint32_t NativeRegisterContextLinux_arm::SetHardwareWatchpoint(
+    lldb::addr_t addr, size_t size, uint32_t watch_flags) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    // Read hardware breakpoint and watchpoint information.
-    error = ReadHardwareDebugInfo ();
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    if (error.Fail())
-        return LLDB_INVALID_INDEX32;
-		
-    uint32_t control_value = 0, wp_index = 0, addr_word_offset = 0, byte_mask = 0;
-    lldb::addr_t real_addr = addr;
-
-    // Check if we are setting watchpoint other than read/write/access
-    // Also update watchpoint flag to match Arm write-read bit configuration.
-    switch (watch_flags)
-    {
-        case 1:
-            watch_flags = 2;
-            break;
-        case 2:
-            watch_flags = 1;
-            break;
-        case 3:
-            break;
-        default:
-            return LLDB_INVALID_INDEX32;
-    }
+  Error error;
 
-    // Can't watch zero bytes
-    // Can't watch more than 4 bytes per WVR/WCR pair
+  // Read hardware breakpoint and watchpoint information.
+  error = ReadHardwareDebugInfo();
 
-    if (size == 0 || size > 4)
-        return LLDB_INVALID_INDEX32;
+  if (error.Fail())
+    return LLDB_INVALID_INDEX32;
 
-    // Check 4-byte alignment for hardware watchpoint target address.
-    // Below is a hack to recalculate address and size in order to
-    // make sure we can watch non 4-byte alligned addresses as well.
-    if (addr & 0x03)
-    {
-        uint8_t watch_mask = (addr & 0x03) + size;
-
-        if (watch_mask > 0x04)
-            return LLDB_INVALID_INDEX32;
-        else if (watch_mask <= 0x02)
-            size = 2;
-        else if (watch_mask <= 0x04)
-            size = 4;
+  uint32_t control_value = 0, wp_index = 0, addr_word_offset = 0, byte_mask = 0;
+  lldb::addr_t real_addr = addr;
 
-        addr = addr & (~0x03);
-    }
+  // Check if we are setting watchpoint other than read/write/access
+  // Also update watchpoint flag to match Arm write-read bit configuration.
+  switch (watch_flags) {
+  case 1:
+    watch_flags = 2;
+    break;
+  case 2:
+    watch_flags = 1;
+    break;
+  case 3:
+    break;
+  default:
+    return LLDB_INVALID_INDEX32;
+  }
+
+  // Can't watch zero bytes
+  // Can't watch more than 4 bytes per WVR/WCR pair
+
+  if (size == 0 || size > 4)
+    return LLDB_INVALID_INDEX32;
+
+  // Check 4-byte alignment for hardware watchpoint target address.
+  // Below is a hack to recalculate address and size in order to
+  // make sure we can watch non 4-byte alligned addresses as well.
+  if (addr & 0x03) {
+    uint8_t watch_mask = (addr & 0x03) + size;
 
-	// We can only watch up to four bytes that follow a 4 byte aligned address
-    // per watchpoint register pair, so make sure we can properly encode this.
-    addr_word_offset = addr % 4;
-    byte_mask = ((1u << size) - 1u) << addr_word_offset;
-
-    // Check if we need multiple watchpoint register
-    if (byte_mask > 0xfu)
-        return LLDB_INVALID_INDEX32;
-
-    // Setup control value
-    // Make the byte_mask into a valid Byte Address Select mask
-    control_value = byte_mask << 5;
-
-    //Turn on appropriate watchpoint flags read or write
-    control_value |= (watch_flags << 3);
-
-    // Enable this watchpoint and make it stop in privileged or user mode;
-    control_value |= 7;
-
-    // Make sure bits 1:0 are clear in our address
-    addr &= ~((lldb::addr_t)3);
-
-    // Iterate over stored watchpoints
-    // Find a free wp_index or update reference count if duplicate.
-    wp_index = LLDB_INVALID_INDEX32;
-    for (uint32_t i = 0; i < m_max_hwp_supported; i++)
-    {
-        if ((m_hwp_regs[i].control & 1) == 0)
-        {
-            wp_index = i; // Mark last free slot
-        }
-        else if (m_hwp_regs[i].address == addr && m_hwp_regs[i].control == control_value)
-        {
-            wp_index = i; // Mark duplicate index
-            break; // Stop searching here
-        }
+    if (watch_mask > 0x04)
+      return LLDB_INVALID_INDEX32;
+    else if (watch_mask <= 0x02)
+      size = 2;
+    else if (watch_mask <= 0x04)
+      size = 4;
+
+    addr = addr & (~0x03);
+  }
+
+  // We can only watch up to four bytes that follow a 4 byte aligned address
+  // per watchpoint register pair, so make sure we can properly encode this.
+  addr_word_offset = addr % 4;
+  byte_mask = ((1u << size) - 1u) << addr_word_offset;
+
+  // Check if we need multiple watchpoint register
+  if (byte_mask > 0xfu)
+    return LLDB_INVALID_INDEX32;
+
+  // Setup control value
+  // Make the byte_mask into a valid Byte Address Select mask
+  control_value = byte_mask << 5;
+
+  // Turn on appropriate watchpoint flags read or write
+  control_value |= (watch_flags << 3);
+
+  // Enable this watchpoint and make it stop in privileged or user mode;
+  control_value |= 7;
+
+  // Make sure bits 1:0 are clear in our address
+  addr &= ~((lldb::addr_t)3);
+
+  // Iterate over stored watchpoints
+  // Find a free wp_index or update reference count if duplicate.
+  wp_index = LLDB_INVALID_INDEX32;
+  for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
+    if ((m_hwp_regs[i].control & 1) == 0) {
+      wp_index = i; // Mark last free slot
+    } else if (m_hwp_regs[i].address == addr &&
+               m_hwp_regs[i].control == control_value) {
+      wp_index = i; // Mark duplicate index
+      break;        // Stop searching here
     }
+  }
+
+  if (wp_index == LLDB_INVALID_INDEX32)
+    return LLDB_INVALID_INDEX32;
+
+  // Add new or update existing watchpoint
+  if ((m_hwp_regs[wp_index].control & 1) == 0) {
+    // Update watchpoint in local cache
+    m_hwp_regs[wp_index].real_addr = real_addr;
+    m_hwp_regs[wp_index].address = addr;
+    m_hwp_regs[wp_index].control = control_value;
+    m_hwp_regs[wp_index].refcount = 1;
 
-     if (wp_index == LLDB_INVALID_INDEX32)
-        return LLDB_INVALID_INDEX32;
+    // PTRACE call to set corresponding watchpoint register.
+    error = WriteHardwareDebugRegs(eDREGTypeWATCH, wp_index);
 
-    // Add new or update existing watchpoint
-    if ((m_hwp_regs[wp_index].control & 1) == 0)
-    {
-        // Update watchpoint in local cache
-        m_hwp_regs[wp_index].real_addr = real_addr;
-        m_hwp_regs[wp_index].address = addr;
-        m_hwp_regs[wp_index].control = control_value;
-        m_hwp_regs[wp_index].refcount = 1;
-
-        // PTRACE call to set corresponding watchpoint register.
-        error = WriteHardwareDebugRegs(eDREGTypeWATCH, wp_index);
-
-        if (error.Fail())
-        {
-            m_hwp_regs[wp_index].address = 0;
-            m_hwp_regs[wp_index].control &= ~1;
-            m_hwp_regs[wp_index].refcount = 0;
+    if (error.Fail()) {
+      m_hwp_regs[wp_index].address = 0;
+      m_hwp_regs[wp_index].control &= ~1;
+      m_hwp_regs[wp_index].refcount = 0;
 
-            return LLDB_INVALID_INDEX32;
-        }
+      return LLDB_INVALID_INDEX32;
     }
-    else
-        m_hwp_regs[wp_index].refcount++;
+  } else
+    m_hwp_regs[wp_index].refcount++;
 
-    return wp_index;
+  return wp_index;
 }
 
-bool
-NativeRegisterContextLinux_arm::ClearHardwareWatchpoint (uint32_t wp_index)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
+bool NativeRegisterContextLinux_arm::ClearHardwareWatchpoint(
+    uint32_t wp_index) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    Error error;
+  Error error;
 
-    // Read hardware breakpoint and watchpoint information.
-    error = ReadHardwareDebugInfo ();
+  // Read hardware breakpoint and watchpoint information.
+  error = ReadHardwareDebugInfo();
 
-    if (error.Fail())
-        return false;
+  if (error.Fail())
+    return false;
 
-    if (wp_index >= m_max_hwp_supported)
-        return false;
+  if (wp_index >= m_max_hwp_supported)
+    return false;
 
-    // Update reference count if multiple references.
-    if (m_hwp_regs[wp_index].refcount > 1)
-    {
-        m_hwp_regs[wp_index].refcount--;
-        return true;
-    }
-    else if (m_hwp_regs[wp_index].refcount == 1)
-    {
-        // Create a backup we can revert to in case of failure.
-        lldb::addr_t tempAddr = m_hwp_regs[wp_index].address;
-        uint32_t tempControl = m_hwp_regs[wp_index].control;
-        uint32_t tempRefCount = m_hwp_regs[wp_index].refcount;
-
-        // Update watchpoint in local cache
-        m_hwp_regs[wp_index].control &= ~1;
-        m_hwp_regs[wp_index].address = 0;
-        m_hwp_regs[wp_index].refcount = 0;
-
-        // Ptrace call to update hardware debug registers
-        error = WriteHardwareDebugRegs(eDREGTypeWATCH, wp_index);
-
-        if (error.Fail())
-        {
-            m_hwp_regs[wp_index].control = tempControl;
-            m_hwp_regs[wp_index].address = tempAddr;
-            m_hwp_regs[wp_index].refcount = tempRefCount;
+  // Update reference count if multiple references.
+  if (m_hwp_regs[wp_index].refcount > 1) {
+    m_hwp_regs[wp_index].refcount--;
+    return true;
+  } else if (m_hwp_regs[wp_index].refcount == 1) {
+    // Create a backup we can revert to in case of failure.
+    lldb::addr_t tempAddr = m_hwp_regs[wp_index].address;
+    uint32_t tempControl = m_hwp_regs[wp_index].control;
+    uint32_t tempRefCount = m_hwp_regs[wp_index].refcount;
+
+    // Update watchpoint in local cache
+    m_hwp_regs[wp_index].control &= ~1;
+    m_hwp_regs[wp_index].address = 0;
+    m_hwp_regs[wp_index].refcount = 0;
 
-            return false;
-        }
+    // Ptrace call to update hardware debug registers
+    error = WriteHardwareDebugRegs(eDREGTypeWATCH, wp_index);
 
-        return true;
+    if (error.Fail()) {
+      m_hwp_regs[wp_index].control = tempControl;
+      m_hwp_regs[wp_index].address = tempAddr;
+      m_hwp_regs[wp_index].refcount = tempRefCount;
+
+      return false;
     }
 
-    return false;
+    return true;
+  }
+
+  return false;
 }
 
-Error
-NativeRegisterContextLinux_arm::ClearAllHardwareWatchpoints ()
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
+Error NativeRegisterContextLinux_arm::ClearAllHardwareWatchpoints() {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    Error error;
+  Error error;
 
-    // Read hardware breakpoint and watchpoint information.
-    error = ReadHardwareDebugInfo ();
+  // Read hardware breakpoint and watchpoint information.
+  error = ReadHardwareDebugInfo();
 
-    if (error.Fail())
-        return error;
+  if (error.Fail())
+    return error;
+
+  lldb::addr_t tempAddr = 0;
+  uint32_t tempControl = 0, tempRefCount = 0;
+
+  for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
+    if (m_hwp_regs[i].control & 0x01) {
+      // Create a backup we can revert to in case of failure.
+      tempAddr = m_hwp_regs[i].address;
+      tempControl = m_hwp_regs[i].control;
+      tempRefCount = m_hwp_regs[i].refcount;
+
+      // Clear watchpoints in local cache
+      m_hwp_regs[i].control &= ~1;
+      m_hwp_regs[i].address = 0;
+      m_hwp_regs[i].refcount = 0;
 
-    lldb::addr_t tempAddr = 0;
-    uint32_t tempControl = 0, tempRefCount = 0;
+      // Ptrace call to update hardware debug registers
+      error = WriteHardwareDebugRegs(eDREGTypeWATCH, i);
 
-    for (uint32_t i = 0; i < m_max_hwp_supported; i++)
-    {
-        if (m_hwp_regs[i].control & 0x01)
-        {
-            // Create a backup we can revert to in case of failure.
-            tempAddr = m_hwp_regs[i].address;
-            tempControl = m_hwp_regs[i].control;
-            tempRefCount = m_hwp_regs[i].refcount;
-
-            // Clear watchpoints in local cache
-            m_hwp_regs[i].control &= ~1;
-            m_hwp_regs[i].address = 0;
-            m_hwp_regs[i].refcount = 0;
-
-            // Ptrace call to update hardware debug registers
-            error = WriteHardwareDebugRegs(eDREGTypeWATCH, i);
-
-            if (error.Fail())
-            {
-                m_hwp_regs[i].control = tempControl;
-                m_hwp_regs[i].address = tempAddr;
-                m_hwp_regs[i].refcount = tempRefCount;
-
-                return error;
-            }
-        }
+      if (error.Fail()) {
+        m_hwp_regs[i].control = tempControl;
+        m_hwp_regs[i].address = tempAddr;
+        m_hwp_regs[i].refcount = tempRefCount;
+
+        return error;
+      }
     }
+  }
 
-    return Error();
+  return Error();
 }
 
-uint32_t
-NativeRegisterContextLinux_arm::GetWatchpointSize(uint32_t wp_index)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
-
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
-
-    switch ((m_hwp_regs[wp_index].control >> 5) & 0x0f)
-    {
-        case 0x01:
-            return 1;
-        case 0x03:
-            return 2;
-        case 0x07:
-            return 3;
-        case 0x0f:
-            return 4;
-        default:
-            return 0;
-    }
+uint32_t NativeRegisterContextLinux_arm::GetWatchpointSize(uint32_t wp_index) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
+
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+
+  switch ((m_hwp_regs[wp_index].control >> 5) & 0x0f) {
+  case 0x01:
+    return 1;
+  case 0x03:
+    return 2;
+  case 0x07:
+    return 3;
+  case 0x0f:
+    return 4;
+  default:
+    return 0;
+  }
 }
-bool
-NativeRegisterContextLinux_arm::WatchpointIsEnabled(uint32_t wp_index)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
-
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
-
-    if ((m_hwp_regs[wp_index].control & 0x1) == 0x1)
-        return true;
-    else
-        return false;
-}
-
-Error
-NativeRegisterContextLinux_arm::GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
-
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
-
-    uint32_t watch_size;
-    lldb::addr_t watch_addr;
-
-    for (wp_index = 0; wp_index < m_max_hwp_supported; ++wp_index)
-    {
-        watch_size = GetWatchpointSize (wp_index);
-        watch_addr = m_hwp_regs[wp_index].address;
-
-        if (m_hwp_regs[wp_index].refcount >= 1 && WatchpointIsEnabled(wp_index)
-            && trap_addr >= watch_addr && trap_addr < watch_addr + watch_size)
-        {
-            m_hwp_regs[wp_index].hit_addr = trap_addr;
-            return Error();
-        }
+bool NativeRegisterContextLinux_arm::WatchpointIsEnabled(uint32_t wp_index) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
+
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+
+  if ((m_hwp_regs[wp_index].control & 0x1) == 0x1)
+    return true;
+  else
+    return false;
+}
+
+Error NativeRegisterContextLinux_arm::GetWatchpointHitIndex(
+    uint32_t &wp_index, lldb::addr_t trap_addr) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
+
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+
+  uint32_t watch_size;
+  lldb::addr_t watch_addr;
+
+  for (wp_index = 0; wp_index < m_max_hwp_supported; ++wp_index) {
+    watch_size = GetWatchpointSize(wp_index);
+    watch_addr = m_hwp_regs[wp_index].address;
+
+    if (m_hwp_regs[wp_index].refcount >= 1 && WatchpointIsEnabled(wp_index) &&
+        trap_addr >= watch_addr && trap_addr < watch_addr + watch_size) {
+      m_hwp_regs[wp_index].hit_addr = trap_addr;
+      return Error();
     }
+  }
 
-    wp_index = LLDB_INVALID_INDEX32;
-    return Error();
+  wp_index = LLDB_INVALID_INDEX32;
+  return Error();
 }
 
 lldb::addr_t
-NativeRegisterContextLinux_arm::GetWatchpointAddress (uint32_t wp_index)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
-
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
-
-    if (wp_index >= m_max_hwp_supported)
-        return LLDB_INVALID_ADDRESS;
-
-    if (WatchpointIsEnabled(wp_index))
-        return m_hwp_regs[wp_index].real_addr;
-    else
-        return LLDB_INVALID_ADDRESS;
+NativeRegisterContextLinux_arm::GetWatchpointAddress(uint32_t wp_index) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
+
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
+
+  if (wp_index >= m_max_hwp_supported)
+    return LLDB_INVALID_ADDRESS;
+
+  if (WatchpointIsEnabled(wp_index))
+    return m_hwp_regs[wp_index].real_addr;
+  else
+    return LLDB_INVALID_ADDRESS;
 }
 
 lldb::addr_t
-NativeRegisterContextLinux_arm::GetWatchpointHitAddress (uint32_t wp_index)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
-
-    if (log)
-        log->Printf ("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
-
-    if (wp_index >= m_max_hwp_supported)
-        return LLDB_INVALID_ADDRESS;
-
-    if (WatchpointIsEnabled(wp_index))
-        return m_hwp_regs[wp_index].hit_addr;
-    else
-        return LLDB_INVALID_ADDRESS;
-}
-
-Error
-NativeRegisterContextLinux_arm::ReadHardwareDebugInfo()
-{
-    Error error;
-
-    if (!m_refresh_hwdebug_info)
-    {
-        return Error();
-    }
+NativeRegisterContextLinux_arm::GetWatchpointHitAddress(uint32_t wp_index) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
 
-    unsigned int cap_val;
+  if (log)
+    log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__);
 
-    error = NativeProcessLinux::PtraceWrapper(PTRACE_GETHBPREGS, m_thread.GetID(), nullptr, &cap_val, sizeof(unsigned int));
+  if (wp_index >= m_max_hwp_supported)
+    return LLDB_INVALID_ADDRESS;
 
-    if (error.Fail())
-        return error;
+  if (WatchpointIsEnabled(wp_index))
+    return m_hwp_regs[wp_index].hit_addr;
+  else
+    return LLDB_INVALID_ADDRESS;
+}
 
-    m_max_hwp_supported = (cap_val >> 8) & 0xff;
-    m_max_hbp_supported = cap_val & 0xff;
-    m_refresh_hwdebug_info = false;
+Error NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
+  Error error;
 
-    return error;
-}
+  if (!m_refresh_hwdebug_info) {
+    return Error();
+  }
 
-Error
-NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType, int hwb_index)
-{
-    Error error;
-
-    lldb::addr_t *addr_buf;
-    uint32_t *ctrl_buf;
-
-    if (hwbType == eDREGTypeWATCH)
-    {
-        addr_buf = &m_hwp_regs[hwb_index].address;
-        ctrl_buf = &m_hwp_regs[hwb_index].control;
-
-        error = NativeProcessLinux::PtraceWrapper(PTRACE_SETHBPREGS,
-                m_thread.GetID(), (PTRACE_TYPE_ARG3)(intptr_t) -((hwb_index << 1) + 1),
-                addr_buf, sizeof(unsigned int));
-
-        if (error.Fail())
-            return error;
-
-        error = NativeProcessLinux::PtraceWrapper(PTRACE_SETHBPREGS,
-                m_thread.GetID(), (PTRACE_TYPE_ARG3)(intptr_t) -((hwb_index << 1) + 2),
-                ctrl_buf, sizeof(unsigned int));
-    }
-    else
-    {
-        addr_buf = &m_hwp_regs[hwb_index].address;
-        ctrl_buf = &m_hwp_regs[hwb_index].control;
-
-        error = NativeProcessLinux::PtraceWrapper(PTRACE_SETHBPREGS,
-                m_thread.GetID(), (PTRACE_TYPE_ARG3)(intptr_t) ((hwb_index << 1) + 1),
-                addr_buf, sizeof(unsigned int));
-
-        if (error.Fail())
-            return error;
-
-        error = NativeProcessLinux::PtraceWrapper(PTRACE_SETHBPREGS,
-                m_thread.GetID(), (PTRACE_TYPE_ARG3)(intptr_t) ((hwb_index << 1) + 2),
-                ctrl_buf, sizeof(unsigned int));
+  unsigned int cap_val;
 
-    }
+  error = NativeProcessLinux::PtraceWrapper(PTRACE_GETHBPREGS, m_thread.GetID(),
+                                            nullptr, &cap_val,
+                                            sizeof(unsigned int));
 
+  if (error.Fail())
     return error;
+
+  m_max_hwp_supported = (cap_val >> 8) & 0xff;
+  m_max_hbp_supported = cap_val & 0xff;
+  m_refresh_hwdebug_info = false;
+
+  return error;
 }
 
-uint32_t
-NativeRegisterContextLinux_arm::CalculateFprOffset(const RegisterInfo* reg_info) const
-{
-    return reg_info->byte_offset - GetRegisterInfoAtIndex(m_reg_info.first_fpr)->byte_offset;
-}
-
-Error
-NativeRegisterContextLinux_arm::DoReadRegisterValue(uint32_t offset,
-                                                    const char* reg_name,
-                                                    uint32_t size,
-                                                    RegisterValue &value)
-{
-    // PTRACE_PEEKUSER don't work in the aarch64 linux kernel used on android devices (always return
-    // "Bad address"). To avoid using PTRACE_PEEKUSER we read out the full GPR register set instead.
-    // This approach is about 4 times slower but the performance overhead is negligible in
-    // comparision to processing time in lldb-server.
-    assert(offset % 4 == 0 && "Try to write a register with unaligned offset");
-    if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm))
-        return Error("Register isn't fit into the size of the GPR area");
+Error NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
+                                                             int hwb_index) {
+  Error error;
+
+  lldb::addr_t *addr_buf;
+  uint32_t *ctrl_buf;
+
+  if (hwbType == eDREGTypeWATCH) {
+    addr_buf = &m_hwp_regs[hwb_index].address;
+    ctrl_buf = &m_hwp_regs[hwb_index].control;
+
+    error = NativeProcessLinux::PtraceWrapper(
+        PTRACE_SETHBPREGS, m_thread.GetID(),
+        (PTRACE_TYPE_ARG3)(intptr_t) - ((hwb_index << 1) + 1), addr_buf,
+        sizeof(unsigned int));
 
-    Error error = DoReadGPR(m_gpr_arm, sizeof(m_gpr_arm));
     if (error.Fail())
-        return error;
+      return error;
 
-    value.SetUInt32(m_gpr_arm[offset / sizeof(uint32_t)]);
-    return Error();
-}
+    error = NativeProcessLinux::PtraceWrapper(
+        PTRACE_SETHBPREGS, m_thread.GetID(),
+        (PTRACE_TYPE_ARG3)(intptr_t) - ((hwb_index << 1) + 2), ctrl_buf,
+        sizeof(unsigned int));
+  } else {
+    addr_buf = &m_hwp_regs[hwb_index].address;
+    ctrl_buf = &m_hwp_regs[hwb_index].control;
 
-Error
-NativeRegisterContextLinux_arm::DoWriteRegisterValue(uint32_t offset,
-                                                     const char* reg_name,
-                                                     const RegisterValue &value)
-{
-    // PTRACE_POKEUSER don't work in the aarch64 linux kernel used on android devices (always return
-    // "Bad address"). To avoid using PTRACE_POKEUSER we read out the full GPR register set, modify
-    // the requested register and write it back. This approach is about 4 times slower but the
-    // performance overhead is negligible in comparision to processing time in lldb-server.
-    assert(offset % 4 == 0 && "Try to write a register with unaligned offset");
-    if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm))
-        return Error("Register isn't fit into the size of the GPR area");
+    error = NativeProcessLinux::PtraceWrapper(
+        PTRACE_SETHBPREGS, m_thread.GetID(),
+        (PTRACE_TYPE_ARG3)(intptr_t)((hwb_index << 1) + 1), addr_buf,
+        sizeof(unsigned int));
 
-    Error error = DoReadGPR(m_gpr_arm, sizeof(m_gpr_arm));
     if (error.Fail())
-        return error;
+      return error;
+
+    error = NativeProcessLinux::PtraceWrapper(
+        PTRACE_SETHBPREGS, m_thread.GetID(),
+        (PTRACE_TYPE_ARG3)(intptr_t)((hwb_index << 1) + 2), ctrl_buf,
+        sizeof(unsigned int));
+  }
+
+  return error;
+}
+
+uint32_t NativeRegisterContextLinux_arm::CalculateFprOffset(
+    const RegisterInfo *reg_info) const {
+  return reg_info->byte_offset -
+         GetRegisterInfoAtIndex(m_reg_info.first_fpr)->byte_offset;
+}
+
+Error NativeRegisterContextLinux_arm::DoReadRegisterValue(
+    uint32_t offset, const char *reg_name, uint32_t size,
+    RegisterValue &value) {
+  // PTRACE_PEEKUSER don't work in the aarch64 linux kernel used on android
+  // devices (always return
+  // "Bad address"). To avoid using PTRACE_PEEKUSER we read out the full GPR
+  // register set instead.
+  // This approach is about 4 times slower but the performance overhead is
+  // negligible in
+  // comparision to processing time in lldb-server.
+  assert(offset % 4 == 0 && "Try to write a register with unaligned offset");
+  if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm))
+    return Error("Register isn't fit into the size of the GPR area");
+
+  Error error = DoReadGPR(m_gpr_arm, sizeof(m_gpr_arm));
+  if (error.Fail())
+    return error;
+
+  value.SetUInt32(m_gpr_arm[offset / sizeof(uint32_t)]);
+  return Error();
+}
+
+Error NativeRegisterContextLinux_arm::DoWriteRegisterValue(
+    uint32_t offset, const char *reg_name, const RegisterValue &value) {
+  // PTRACE_POKEUSER don't work in the aarch64 linux kernel used on android
+  // devices (always return
+  // "Bad address"). To avoid using PTRACE_POKEUSER we read out the full GPR
+  // register set, modify
+  // the requested register and write it back. This approach is about 4 times
+  // slower but the
+  // performance overhead is negligible in comparision to processing time in
+  // lldb-server.
+  assert(offset % 4 == 0 && "Try to write a register with unaligned offset");
+  if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm))
+    return Error("Register isn't fit into the size of the GPR area");
+
+  Error error = DoReadGPR(m_gpr_arm, sizeof(m_gpr_arm));
+  if (error.Fail())
+    return error;
 
-    uint32_t reg_value = value.GetAsUInt32();
-    // As precaution for an undefined behavior encountered while setting PC we
-    // will clear thumb bit of new PC if we are already in thumb mode; that is
-    // CPSR thumb mode bit is set.
-    if (offset / sizeof(uint32_t) == gpr_pc_arm)
-    {
-        // Check if we are already in thumb mode and
-        // thumb bit of current PC is read out to be zero and
-        // thumb bit of next PC is read out to be one.
-        if ((m_gpr_arm[gpr_cpsr_arm] &  0x20) &&
-            !(m_gpr_arm[gpr_pc_arm] &  0x01) &&
-            (value.GetAsUInt32() & 0x01))
-        {
-            reg_value &= (~1ull);
-        }
+  uint32_t reg_value = value.GetAsUInt32();
+  // As precaution for an undefined behavior encountered while setting PC we
+  // will clear thumb bit of new PC if we are already in thumb mode; that is
+  // CPSR thumb mode bit is set.
+  if (offset / sizeof(uint32_t) == gpr_pc_arm) {
+    // Check if we are already in thumb mode and
+    // thumb bit of current PC is read out to be zero and
+    // thumb bit of next PC is read out to be one.
+    if ((m_gpr_arm[gpr_cpsr_arm] & 0x20) && !(m_gpr_arm[gpr_pc_arm] & 0x01) &&
+        (value.GetAsUInt32() & 0x01)) {
+      reg_value &= (~1ull);
     }
+  }
 
-    m_gpr_arm[offset / sizeof(uint32_t)] = reg_value;
-    return DoWriteGPR(m_gpr_arm, sizeof(m_gpr_arm));
+  m_gpr_arm[offset / sizeof(uint32_t)] = reg_value;
+  return DoWriteGPR(m_gpr_arm, sizeof(m_gpr_arm));
 }
 
-Error
-NativeRegisterContextLinux_arm::DoReadGPR(void *buf, size_t buf_size)
-{
+Error NativeRegisterContextLinux_arm::DoReadGPR(void *buf, size_t buf_size) {
 #ifdef __arm__
-    return NativeRegisterContextLinux::DoReadGPR(buf, buf_size);
-#else // __aarch64__
-    struct iovec ioVec;
-    ioVec.iov_base = buf;
-    ioVec.iov_len = buf_size;
+  return NativeRegisterContextLinux::DoReadGPR(buf, buf_size);
+#else  // __aarch64__
+  struct iovec ioVec;
+  ioVec.iov_base = buf;
+  ioVec.iov_len = buf_size;
 
-    return ReadRegisterSet(&ioVec, buf_size, NT_PRSTATUS);
+  return ReadRegisterSet(&ioVec, buf_size, NT_PRSTATUS);
 #endif // __arm__
 }
 
-Error
-NativeRegisterContextLinux_arm::DoWriteGPR(void *buf, size_t buf_size)
-{
+Error NativeRegisterContextLinux_arm::DoWriteGPR(void *buf, size_t buf_size) {
 #ifdef __arm__
-    return NativeRegisterContextLinux::DoWriteGPR(buf, buf_size);
-#else // __aarch64__
-    struct iovec ioVec;
-    ioVec.iov_base = buf;
-    ioVec.iov_len = buf_size;
+  return NativeRegisterContextLinux::DoWriteGPR(buf, buf_size);
+#else  // __aarch64__
+  struct iovec ioVec;
+  ioVec.iov_base = buf;
+  ioVec.iov_len = buf_size;
 
-    return WriteRegisterSet(&ioVec, buf_size, NT_PRSTATUS);
+  return WriteRegisterSet(&ioVec, buf_size, NT_PRSTATUS);
 #endif // __arm__
 }
 
-Error
-NativeRegisterContextLinux_arm::DoReadFPR(void *buf, size_t buf_size)
-{
+Error NativeRegisterContextLinux_arm::DoReadFPR(void *buf, size_t buf_size) {
 #ifdef __arm__
-    return NativeProcessLinux::PtraceWrapper(PTRACE_GETVFPREGS,
-                                             m_thread.GetID(),
-                                             nullptr,
-                                             buf,
-                                             buf_size);
-#else // __aarch64__
-    struct iovec ioVec;
-    ioVec.iov_base = buf;
-    ioVec.iov_len = buf_size;
+  return NativeProcessLinux::PtraceWrapper(PTRACE_GETVFPREGS, m_thread.GetID(),
+                                           nullptr, buf, buf_size);
+#else  // __aarch64__
+  struct iovec ioVec;
+  ioVec.iov_base = buf;
+  ioVec.iov_len = buf_size;
 
-    return ReadRegisterSet(&ioVec, buf_size, NT_ARM_VFP);
+  return ReadRegisterSet(&ioVec, buf_size, NT_ARM_VFP);
 #endif // __arm__
 }
 
-Error
-NativeRegisterContextLinux_arm::DoWriteFPR(void *buf, size_t buf_size)
-{
+Error NativeRegisterContextLinux_arm::DoWriteFPR(void *buf, size_t buf_size) {
 #ifdef __arm__
-    return NativeProcessLinux::PtraceWrapper(PTRACE_SETVFPREGS,
-                                             m_thread.GetID(),
-                                             nullptr,
-                                             buf,
-                                             buf_size);
-#else // __aarch64__
-    struct iovec ioVec;
-    ioVec.iov_base = buf;
-    ioVec.iov_len = buf_size;
+  return NativeProcessLinux::PtraceWrapper(PTRACE_SETVFPREGS, m_thread.GetID(),
+                                           nullptr, buf, buf_size);
+#else  // __aarch64__
+  struct iovec ioVec;
+  ioVec.iov_base = buf;
+  ioVec.iov_len = buf_size;
 
-    return WriteRegisterSet(&ioVec, buf_size, NT_ARM_VFP);
+  return WriteRegisterSet(&ioVec, buf_size, NT_ARM_VFP);
 #endif // __arm__
 }
 

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h Tue Sep  6 15:57:50 2016
@@ -18,181 +18,142 @@
 namespace lldb_private {
 namespace process_linux {
 
-    class NativeProcessLinux;
+class NativeProcessLinux;
 
-    class NativeRegisterContextLinux_arm : public NativeRegisterContextLinux
-    {
-    public:
-        NativeRegisterContextLinux_arm (const ArchSpec& target_arch,
-                                        NativeThreadProtocol &native_thread,
-                                        uint32_t concrete_frame_idx);
+class NativeRegisterContextLinux_arm : public NativeRegisterContextLinux {
+public:
+  NativeRegisterContextLinux_arm(const ArchSpec &target_arch,
+                                 NativeThreadProtocol &native_thread,
+                                 uint32_t concrete_frame_idx);
 
-        uint32_t
-        GetRegisterSetCount () const override;
+  uint32_t GetRegisterSetCount() const override;
 
-        const RegisterSet *
-        GetRegisterSet (uint32_t set_index) const override;
+  const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
 
-        uint32_t
-        GetUserRegisterCount() const override;
+  uint32_t GetUserRegisterCount() const override;
 
-        Error
-        ReadRegister (const RegisterInfo *reg_info, RegisterValue &reg_value) override;
+  Error ReadRegister(const RegisterInfo *reg_info,
+                     RegisterValue &reg_value) override;
 
-        Error
-        WriteRegister (const RegisterInfo *reg_info, const RegisterValue &reg_value) override;
+  Error WriteRegister(const RegisterInfo *reg_info,
+                      const RegisterValue &reg_value) override;
 
-        Error
-        ReadAllRegisterValues (lldb::DataBufferSP &data_sp) override;
+  Error ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
 
-        Error
-        WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) override;
+  Error WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
 
-        //------------------------------------------------------------------
-        // Hardware breakpoints/watchpoint mangement functions
-        //------------------------------------------------------------------
+  //------------------------------------------------------------------
+  // Hardware breakpoints/watchpoint mangement functions
+  //------------------------------------------------------------------
 
-        uint32_t
-        SetHardwareBreakpoint (lldb::addr_t addr, size_t size) override;
+  uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
 
-        bool
-        ClearHardwareBreakpoint (uint32_t hw_idx) override;
+  bool ClearHardwareBreakpoint(uint32_t hw_idx) override;
 
-        uint32_t
-        NumSupportedHardwareWatchpoints () override;
+  uint32_t NumSupportedHardwareWatchpoints() override;
 
-        uint32_t
-        SetHardwareWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags) override;
+  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
+                                 uint32_t watch_flags) override;
 
-        bool
-        ClearHardwareWatchpoint (uint32_t hw_index) override;
+  bool ClearHardwareWatchpoint(uint32_t hw_index) override;
 
-        Error
-        ClearAllHardwareWatchpoints () override;
+  Error ClearAllHardwareWatchpoints() override;
 
-        Error
-        GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr) override;
+  Error GetWatchpointHitIndex(uint32_t &wp_index,
+                              lldb::addr_t trap_addr) override;
 
-        lldb::addr_t
-        GetWatchpointHitAddress (uint32_t wp_index) override;
+  lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;
 
-        lldb::addr_t
-        GetWatchpointAddress (uint32_t wp_index) override;
+  lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
 
-        uint32_t
-        GetWatchpointSize(uint32_t wp_index);
+  uint32_t GetWatchpointSize(uint32_t wp_index);
 
-        bool
-        WatchpointIsEnabled(uint32_t wp_index);
+  bool WatchpointIsEnabled(uint32_t wp_index);
 
-        // Debug register type select
-        enum DREGType
-        {
-            eDREGTypeWATCH = 0,
-            eDREGTypeBREAK
-        };
+  // Debug register type select
+  enum DREGType { eDREGTypeWATCH = 0, eDREGTypeBREAK };
 
-    protected:
-        Error
-        DoReadRegisterValue(uint32_t offset,
-                            const char* reg_name,
-                            uint32_t size,
-                            RegisterValue &value) override;
+protected:
+  Error DoReadRegisterValue(uint32_t offset, const char *reg_name,
+                            uint32_t size, RegisterValue &value) override;
 
-        Error
-        DoWriteRegisterValue(uint32_t offset,
-                             const char* reg_name,
+  Error DoWriteRegisterValue(uint32_t offset, const char *reg_name,
                              const RegisterValue &value) override;
 
-        Error
-        DoReadGPR(void *buf, size_t buf_size) override;
+  Error DoReadGPR(void *buf, size_t buf_size) override;
 
-        Error
-        DoWriteGPR(void *buf, size_t buf_size) override;
+  Error DoWriteGPR(void *buf, size_t buf_size) override;
 
-        Error
-        DoReadFPR(void *buf, size_t buf_size) override;
+  Error DoReadFPR(void *buf, size_t buf_size) override;
 
-        Error
-        DoWriteFPR(void *buf, size_t buf_size) override;
-
-        void*
-        GetGPRBuffer() override { return &m_gpr_arm; }
-
-        void*
-        GetFPRBuffer() override { return &m_fpr; }
-
-        size_t
-        GetFPRSize() override { return sizeof(m_fpr); }
-
-    private:
-        struct RegInfo
-        {
-            uint32_t num_registers;
-            uint32_t num_gpr_registers;
-            uint32_t num_fpr_registers;
-
-            uint32_t last_gpr;
-            uint32_t first_fpr;
-            uint32_t last_fpr;
-
-            uint32_t first_fpr_v;
-            uint32_t last_fpr_v;
-
-            uint32_t gpr_flags;
-        };
-
-        struct QReg
-        {
-            uint8_t bytes[16];
-        };
-
-        struct FPU
-        {
-            union {
-                uint32_t s[32];
-                uint64_t d[32];
-                QReg     q[16];  // the 128-bit NEON registers
-                } floats;
-            uint32_t fpscr;
-        };
-
-        uint32_t m_gpr_arm[k_num_gpr_registers_arm];
-        RegInfo  m_reg_info;
-        FPU m_fpr; 
-
-        // Debug register info for hardware breakpoints and watchpoints management.
-        struct DREG
-        {
-            lldb::addr_t address;  // Breakpoint/watchpoint address value.
-            lldb::addr_t hit_addr; // Address at which last watchpoint trigger exception occurred.
-            lldb::addr_t real_addr;  // Address value that should cause target to stop.
-            uint32_t control;  // Breakpoint/watchpoint control value.
-            uint32_t refcount;  // Serves as enable/disable and refernce counter.
-        };
-
-        struct DREG m_hbr_regs[16];  // Arm native linux hardware breakpoints
-        struct DREG m_hwp_regs[16];  // Arm native linux hardware watchpoints
-
-        uint32_t m_max_hwp_supported;
-        uint32_t m_max_hbp_supported;
-        bool m_refresh_hwdebug_info;
-
-        bool
-        IsGPR(unsigned reg) const;
-
-        bool
-        IsFPR(unsigned reg) const;
-
-        Error
-        ReadHardwareDebugInfo();
-
-        Error
-        WriteHardwareDebugRegs(int hwbType, int hwb_index);
-
-        uint32_t
-        CalculateFprOffset(const RegisterInfo* reg_info) const;
-    };
+  Error DoWriteFPR(void *buf, size_t buf_size) override;
+
+  void *GetGPRBuffer() override { return &m_gpr_arm; }
+
+  void *GetFPRBuffer() override { return &m_fpr; }
+
+  size_t GetFPRSize() override { return sizeof(m_fpr); }
+
+private:
+  struct RegInfo {
+    uint32_t num_registers;
+    uint32_t num_gpr_registers;
+    uint32_t num_fpr_registers;
+
+    uint32_t last_gpr;
+    uint32_t first_fpr;
+    uint32_t last_fpr;
+
+    uint32_t first_fpr_v;
+    uint32_t last_fpr_v;
+
+    uint32_t gpr_flags;
+  };
+
+  struct QReg {
+    uint8_t bytes[16];
+  };
+
+  struct FPU {
+    union {
+      uint32_t s[32];
+      uint64_t d[32];
+      QReg q[16]; // the 128-bit NEON registers
+    } floats;
+    uint32_t fpscr;
+  };
+
+  uint32_t m_gpr_arm[k_num_gpr_registers_arm];
+  RegInfo m_reg_info;
+  FPU m_fpr;
+
+  // Debug register info for hardware breakpoints and watchpoints management.
+  struct DREG {
+    lldb::addr_t address;  // Breakpoint/watchpoint address value.
+    lldb::addr_t hit_addr; // Address at which last watchpoint trigger exception
+                           // occurred.
+    lldb::addr_t real_addr; // Address value that should cause target to stop.
+    uint32_t control;       // Breakpoint/watchpoint control value.
+    uint32_t refcount;      // Serves as enable/disable and refernce counter.
+  };
+
+  struct DREG m_hbr_regs[16]; // Arm native linux hardware breakpoints
+  struct DREG m_hwp_regs[16]; // Arm native linux hardware watchpoints
+
+  uint32_t m_max_hwp_supported;
+  uint32_t m_max_hbp_supported;
+  bool m_refresh_hwdebug_info;
+
+  bool IsGPR(unsigned reg) const;
+
+  bool IsFPR(unsigned reg) const;
+
+  Error ReadHardwareDebugInfo();
+
+  Error WriteHardwareDebugRegs(int hwbType, int hwb_index);
+
+  uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const;
+};
 
 } // namespace process_linux
 } // namespace lldb_private




More information about the lldb-commits mailing list