[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/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Tue Sep  6 15:57:50 2016
@@ -10,9 +10,13 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
-#include "llvm/ADT/StringRef.h" 
+#include "llvm/ADT/StringRef.h"
 
 // Project includes
+#include "Plugins/Process/Utility/RegisterContextDarwin_arm.h"
+#include "Plugins/Process/Utility/RegisterContextDarwin_arm64.h"
+#include "Plugins/Process/Utility/RegisterContextDarwin_i386.h"
+#include "Plugins/Process/Utility/RegisterContextDarwin_x86_64.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/Debugger.h"
@@ -28,8 +32,8 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/UUID.h"
-#include "lldb/Host/Host.h"
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Host/Host.h"
 #include "lldb/Symbol/DWARFCallFrameInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Target/DynamicLoader.h"
@@ -40,16 +44,13 @@
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadList.h"
-#include "Plugins/Process/Utility/RegisterContextDarwin_arm.h"
-#include "Plugins/Process/Utility/RegisterContextDarwin_arm64.h"
-#include "Plugins/Process/Utility/RegisterContextDarwin_i386.h"
-#include "Plugins/Process/Utility/RegisterContextDarwin_x86_64.h"
 
 #include "lldb/Utility/SafeMachO.h"
 
 #include "ObjectFileMachO.h"
 
-#if defined (__APPLE__) && (defined (__arm__) || defined (__arm64__) || defined (__aarch64__))
+#if defined(__APPLE__) &&                                                      \
+    (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
 // GetLLDBSharedCacheUUID() needs to call dlsym()
 #include <dlfcn.h>
 #endif
@@ -66,6047 +67,6024 @@ using namespace llvm::MachO;
 // Some structure definitions needed for parsing the dyld shared cache files
 // found on iOS devices.
 
-struct lldb_copy_dyld_cache_header_v1
-{
-    char        magic[16];            // e.g. "dyld_v0    i386", "dyld_v1   armv7", etc.
-    uint32_t    mappingOffset;        // file offset to first dyld_cache_mapping_info
-    uint32_t    mappingCount;         // number of dyld_cache_mapping_info entries
-    uint32_t    imagesOffset;
-    uint32_t    imagesCount;
-    uint64_t    dyldBaseAddress;
-    uint64_t    codeSignatureOffset;
-    uint64_t    codeSignatureSize;
-    uint64_t    slideInfoOffset;
-    uint64_t    slideInfoSize;
-    uint64_t    localSymbolsOffset;
-    uint64_t    localSymbolsSize;
-    uint8_t     uuid[16];             // v1 and above, also recorded in dyld_all_image_infos v13 and later
+struct lldb_copy_dyld_cache_header_v1 {
+  char magic[16];         // e.g. "dyld_v0    i386", "dyld_v1   armv7", etc.
+  uint32_t mappingOffset; // file offset to first dyld_cache_mapping_info
+  uint32_t mappingCount;  // number of dyld_cache_mapping_info entries
+  uint32_t imagesOffset;
+  uint32_t imagesCount;
+  uint64_t dyldBaseAddress;
+  uint64_t codeSignatureOffset;
+  uint64_t codeSignatureSize;
+  uint64_t slideInfoOffset;
+  uint64_t slideInfoSize;
+  uint64_t localSymbolsOffset;
+  uint64_t localSymbolsSize;
+  uint8_t uuid[16]; // v1 and above, also recorded in dyld_all_image_infos v13
+                    // and later
 };
 
-struct lldb_copy_dyld_cache_mapping_info
-{
-    uint64_t        address;
-    uint64_t        size;
-    uint64_t        fileOffset;
-    uint32_t        maxProt;
-    uint32_t        initProt;
+struct lldb_copy_dyld_cache_mapping_info {
+  uint64_t address;
+  uint64_t size;
+  uint64_t fileOffset;
+  uint32_t maxProt;
+  uint32_t initProt;
 };
 
-struct lldb_copy_dyld_cache_local_symbols_info
-{
-    uint32_t        nlistOffset;
-    uint32_t        nlistCount;
-    uint32_t        stringsOffset;
-    uint32_t        stringsSize;
-    uint32_t        entriesOffset;
-    uint32_t        entriesCount;
+struct lldb_copy_dyld_cache_local_symbols_info {
+  uint32_t nlistOffset;
+  uint32_t nlistCount;
+  uint32_t stringsOffset;
+  uint32_t stringsSize;
+  uint32_t entriesOffset;
+  uint32_t entriesCount;
 };
-struct lldb_copy_dyld_cache_local_symbols_entry
-{
-    uint32_t        dylibOffset;
-    uint32_t        nlistStartIndex;
-    uint32_t        nlistCount;
+struct lldb_copy_dyld_cache_local_symbols_entry {
+  uint32_t dylibOffset;
+  uint32_t nlistStartIndex;
+  uint32_t nlistCount;
 };
 
-
-class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64
-{
+class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 {
 public:
-    RegisterContextDarwin_x86_64_Mach (lldb_private::Thread &thread, const DataExtractor &data) :
-        RegisterContextDarwin_x86_64 (thread, 0)
-    {
-        SetRegisterDataFrom_LC_THREAD (data);
-    }
-
-    void
-    InvalidateAllRegisters() override
-    {
-        // Do nothing... registers are always valid...
-    }
-
-    void
-    SetRegisterDataFrom_LC_THREAD (const DataExtractor &data)
-    {
-        lldb::offset_t offset = 0;
-        SetError (GPRRegSet, Read, -1);
-        SetError (FPURegSet, Read, -1);
-        SetError (EXCRegSet, Read, -1);
-        bool done = false;
-
-        while (!done)
-        {
-            int flavor = data.GetU32 (&offset);
-            if (flavor == 0)
-                done = true;
-            else
-            {
-                uint32_t i;
-                uint32_t count = data.GetU32 (&offset);
-                switch (flavor)
-                {
-                    case GPRRegSet:
-                        for (i=0; i<count; ++i)
-                            (&gpr.rax)[i] = data.GetU64(&offset);
-                        SetError (GPRRegSet, Read, 0);
-                        done = true;
+  RegisterContextDarwin_x86_64_Mach(lldb_private::Thread &thread,
+                                    const DataExtractor &data)
+      : RegisterContextDarwin_x86_64(thread, 0) {
+    SetRegisterDataFrom_LC_THREAD(data);
+  }
+
+  void InvalidateAllRegisters() override {
+    // Do nothing... registers are always valid...
+  }
 
-                        break;
-                    case FPURegSet:
-                        // TODO: fill in FPU regs....
-                        //SetError (FPURegSet, Read, -1);
-                        done = true;
-
-                        break;
-                    case EXCRegSet:
-                        exc.trapno = data.GetU32(&offset);
-                        exc.err = data.GetU32(&offset);
-                        exc.faultvaddr = data.GetU64(&offset);
-                        SetError (EXCRegSet, Read, 0);
-                        done = true;
-                        break;
-                    case 7:
-                    case 8:
-                    case 9:
-                        // fancy flavors that encapsulate of the above
-                        // flavors...
-                        break;
+  void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data) {
+    lldb::offset_t offset = 0;
+    SetError(GPRRegSet, Read, -1);
+    SetError(FPURegSet, Read, -1);
+    SetError(EXCRegSet, Read, -1);
+    bool done = false;
+
+    while (!done) {
+      int flavor = data.GetU32(&offset);
+      if (flavor == 0)
+        done = true;
+      else {
+        uint32_t i;
+        uint32_t count = data.GetU32(&offset);
+        switch (flavor) {
+        case GPRRegSet:
+          for (i = 0; i < count; ++i)
+            (&gpr.rax)[i] = data.GetU64(&offset);
+          SetError(GPRRegSet, Read, 0);
+          done = true;
+
+          break;
+        case FPURegSet:
+          // TODO: fill in FPU regs....
+          // SetError (FPURegSet, Read, -1);
+          done = true;
+
+          break;
+        case EXCRegSet:
+          exc.trapno = data.GetU32(&offset);
+          exc.err = data.GetU32(&offset);
+          exc.faultvaddr = data.GetU64(&offset);
+          SetError(EXCRegSet, Read, 0);
+          done = true;
+          break;
+        case 7:
+        case 8:
+        case 9:
+          // fancy flavors that encapsulate of the above
+          // flavors...
+          break;
 
-                    default:
-                        done = true;
-                        break;
-                }
-            }
+        default:
+          done = true;
+          break;
         }
+      }
     }
+  }
 
-    static size_t
-    WriteRegister (RegisterContext *reg_ctx, const char *name, const char *alt_name, size_t reg_byte_size, Stream &data)
-    {
-        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
-        if (reg_info == NULL)
-            reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
-        if (reg_info)
-        {
-            lldb_private::RegisterValue reg_value;
-            if (reg_ctx->ReadRegister(reg_info, reg_value))
-            {
-                if (reg_info->byte_size >= reg_byte_size)
-                    data.Write(reg_value.GetBytes(), reg_byte_size);
-                else
-                {
-                    data.Write(reg_value.GetBytes(), reg_info->byte_size);
-                    for (size_t i=0, n = reg_byte_size - reg_info->byte_size; i<n; ++ i)
-                        data.PutChar(0);
-                }
-                return reg_byte_size;
-            }
-        }
-        // Just write zeros if all else fails
-        for (size_t i=0; i<reg_byte_size; ++ i)
+  static size_t WriteRegister(RegisterContext *reg_ctx, const char *name,
+                              const char *alt_name, size_t reg_byte_size,
+                              Stream &data) {
+    const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
+    if (reg_info == NULL)
+      reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
+    if (reg_info) {
+      lldb_private::RegisterValue reg_value;
+      if (reg_ctx->ReadRegister(reg_info, reg_value)) {
+        if (reg_info->byte_size >= reg_byte_size)
+          data.Write(reg_value.GetBytes(), reg_byte_size);
+        else {
+          data.Write(reg_value.GetBytes(), reg_info->byte_size);
+          for (size_t i = 0, n = reg_byte_size - reg_info->byte_size; i < n;
+               ++i)
             data.PutChar(0);
+        }
         return reg_byte_size;
+      }
     }
-
-    static bool
-    Create_LC_THREAD (Thread *thread, Stream &data)
-    {
-        RegisterContextSP reg_ctx_sp (thread->GetRegisterContext());
-        if (reg_ctx_sp)
-        {
-            RegisterContext *reg_ctx = reg_ctx_sp.get();
-
-            data.PutHex32 (GPRRegSet);  // Flavor
-            data.PutHex32 (GPRWordCount);
-            WriteRegister (reg_ctx, "rax", NULL, 8, data);
-            WriteRegister (reg_ctx, "rbx", NULL, 8, data);
-            WriteRegister (reg_ctx, "rcx", NULL, 8, data);
-            WriteRegister (reg_ctx, "rdx", NULL, 8, data);
-            WriteRegister (reg_ctx, "rdi", NULL, 8, data);
-            WriteRegister (reg_ctx, "rsi", NULL, 8, data);
-            WriteRegister (reg_ctx, "rbp", NULL, 8, data);
-            WriteRegister (reg_ctx, "rsp", NULL, 8, data);
-            WriteRegister (reg_ctx, "r8", NULL, 8, data);
-            WriteRegister (reg_ctx, "r9", NULL, 8, data);
-            WriteRegister (reg_ctx, "r10", NULL, 8, data);
-            WriteRegister (reg_ctx, "r11", NULL, 8, data);
-            WriteRegister (reg_ctx, "r12", NULL, 8, data);
-            WriteRegister (reg_ctx, "r13", NULL, 8, data);
-            WriteRegister (reg_ctx, "r14", NULL, 8, data);
-            WriteRegister (reg_ctx, "r15", NULL, 8, data);
-            WriteRegister (reg_ctx, "rip", NULL, 8, data);
-            WriteRegister (reg_ctx, "rflags", NULL, 8, data);
-            WriteRegister (reg_ctx, "cs", NULL, 8, data);
-            WriteRegister (reg_ctx, "fs", NULL, 8, data);
-            WriteRegister (reg_ctx, "gs", NULL, 8, data);
-
-//            // Write out the FPU registers
-//            const size_t fpu_byte_size = sizeof(FPU);
-//            size_t bytes_written = 0;
-//            data.PutHex32 (FPURegSet);
-//            data.PutHex32 (fpu_byte_size/sizeof(uint64_t));
-//            bytes_written += data.PutHex32(0);                                   // uint32_t pad[0]
-//            bytes_written += data.PutHex32(0);                                   // uint32_t pad[1]
-//            bytes_written += WriteRegister (reg_ctx, "fcw", "fctrl", 2, data);   // uint16_t    fcw;    // "fctrl"
-//            bytes_written += WriteRegister (reg_ctx, "fsw" , "fstat", 2, data);  // uint16_t    fsw;    // "fstat"
-//            bytes_written += WriteRegister (reg_ctx, "ftw" , "ftag", 1, data);   // uint8_t     ftw;    // "ftag"
-//            bytes_written += data.PutHex8  (0);                                  // uint8_t pad1;
-//            bytes_written += WriteRegister (reg_ctx, "fop" , NULL, 2, data);     // uint16_t    fop;    // "fop"
-//            bytes_written += WriteRegister (reg_ctx, "fioff", "ip", 4, data);    // uint32_t    ip;     // "fioff"
-//            bytes_written += WriteRegister (reg_ctx, "fiseg", NULL, 2, data);    // uint16_t    cs;     // "fiseg"
-//            bytes_written += data.PutHex16 (0);                                  // uint16_t    pad2;
-//            bytes_written += WriteRegister (reg_ctx, "dp", "fooff" , 4, data);   // uint32_t    dp;     // "fooff"
-//            bytes_written += WriteRegister (reg_ctx, "foseg", NULL, 2, data);    // uint16_t    ds;     // "foseg"
-//            bytes_written += data.PutHex16 (0);                                  // uint16_t    pad3;
-//            bytes_written += WriteRegister (reg_ctx, "mxcsr", NULL, 4, data);    // uint32_t    mxcsr;
-//            bytes_written += WriteRegister (reg_ctx, "mxcsrmask", NULL, 4, data);// uint32_t    mxcsrmask;
-//            bytes_written += WriteRegister (reg_ctx, "stmm0", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm1", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm2", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm3", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm4", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm5", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm6", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "stmm7", NULL, sizeof(MMSReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm0" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm1" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm2" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm3" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm4" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm5" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm6" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm7" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm8" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm9" , NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm10", NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm11", NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm12", NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm13", NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm14", NULL, sizeof(XMMReg), data);
-//            bytes_written += WriteRegister (reg_ctx, "xmm15", NULL, sizeof(XMMReg), data);
-//            
-//            // Fill rest with zeros
-//            for (size_t i=0, n = fpu_byte_size - bytes_written; i<n; ++ i)
-//                data.PutChar(0);
-            
-            // Write out the EXC registers
-            data.PutHex32 (EXCRegSet);
-            data.PutHex32 (EXCWordCount);
-            WriteRegister (reg_ctx, "trapno", NULL, 4, data);
-            WriteRegister (reg_ctx, "err", NULL, 4, data);
-            WriteRegister (reg_ctx, "faultvaddr", NULL, 8, data);
-            return true;
-        }
-        return false;
+    // Just write zeros if all else fails
+    for (size_t i = 0; i < reg_byte_size; ++i)
+      data.PutChar(0);
+    return reg_byte_size;
+  }
+
+  static bool Create_LC_THREAD(Thread *thread, Stream &data) {
+    RegisterContextSP reg_ctx_sp(thread->GetRegisterContext());
+    if (reg_ctx_sp) {
+      RegisterContext *reg_ctx = reg_ctx_sp.get();
+
+      data.PutHex32(GPRRegSet); // Flavor
+      data.PutHex32(GPRWordCount);
+      WriteRegister(reg_ctx, "rax", NULL, 8, data);
+      WriteRegister(reg_ctx, "rbx", NULL, 8, data);
+      WriteRegister(reg_ctx, "rcx", NULL, 8, data);
+      WriteRegister(reg_ctx, "rdx", NULL, 8, data);
+      WriteRegister(reg_ctx, "rdi", NULL, 8, data);
+      WriteRegister(reg_ctx, "rsi", NULL, 8, data);
+      WriteRegister(reg_ctx, "rbp", NULL, 8, data);
+      WriteRegister(reg_ctx, "rsp", NULL, 8, data);
+      WriteRegister(reg_ctx, "r8", NULL, 8, data);
+      WriteRegister(reg_ctx, "r9", NULL, 8, data);
+      WriteRegister(reg_ctx, "r10", NULL, 8, data);
+      WriteRegister(reg_ctx, "r11", NULL, 8, data);
+      WriteRegister(reg_ctx, "r12", NULL, 8, data);
+      WriteRegister(reg_ctx, "r13", NULL, 8, data);
+      WriteRegister(reg_ctx, "r14", NULL, 8, data);
+      WriteRegister(reg_ctx, "r15", NULL, 8, data);
+      WriteRegister(reg_ctx, "rip", NULL, 8, data);
+      WriteRegister(reg_ctx, "rflags", NULL, 8, data);
+      WriteRegister(reg_ctx, "cs", NULL, 8, data);
+      WriteRegister(reg_ctx, "fs", NULL, 8, data);
+      WriteRegister(reg_ctx, "gs", NULL, 8, data);
+
+      //            // Write out the FPU registers
+      //            const size_t fpu_byte_size = sizeof(FPU);
+      //            size_t bytes_written = 0;
+      //            data.PutHex32 (FPURegSet);
+      //            data.PutHex32 (fpu_byte_size/sizeof(uint64_t));
+      //            bytes_written += data.PutHex32(0); // uint32_t pad[0]
+      //            bytes_written += data.PutHex32(0); // uint32_t pad[1]
+      //            bytes_written += WriteRegister (reg_ctx, "fcw", "fctrl", 2,
+      //            data);   // uint16_t    fcw;    // "fctrl"
+      //            bytes_written += WriteRegister (reg_ctx, "fsw" , "fstat", 2,
+      //            data);  // uint16_t    fsw;    // "fstat"
+      //            bytes_written += WriteRegister (reg_ctx, "ftw" , "ftag", 1,
+      //            data);   // uint8_t     ftw;    // "ftag"
+      //            bytes_written += data.PutHex8  (0); // uint8_t pad1;
+      //            bytes_written += WriteRegister (reg_ctx, "fop" , NULL, 2,
+      //            data);     // uint16_t    fop;    // "fop"
+      //            bytes_written += WriteRegister (reg_ctx, "fioff", "ip", 4,
+      //            data);    // uint32_t    ip;     // "fioff"
+      //            bytes_written += WriteRegister (reg_ctx, "fiseg", NULL, 2,
+      //            data);    // uint16_t    cs;     // "fiseg"
+      //            bytes_written += data.PutHex16 (0); // uint16_t    pad2;
+      //            bytes_written += WriteRegister (reg_ctx, "dp", "fooff" , 4,
+      //            data);   // uint32_t    dp;     // "fooff"
+      //            bytes_written += WriteRegister (reg_ctx, "foseg", NULL, 2,
+      //            data);    // uint16_t    ds;     // "foseg"
+      //            bytes_written += data.PutHex16 (0); // uint16_t    pad3;
+      //            bytes_written += WriteRegister (reg_ctx, "mxcsr", NULL, 4,
+      //            data);    // uint32_t    mxcsr;
+      //            bytes_written += WriteRegister (reg_ctx, "mxcsrmask", NULL,
+      //            4, data);// uint32_t    mxcsrmask;
+      //            bytes_written += WriteRegister (reg_ctx, "stmm0", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm1", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm2", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm3", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm4", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm5", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm6", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "stmm7", NULL,
+      //            sizeof(MMSReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm0" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm1" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm2" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm3" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm4" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm5" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm6" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm7" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm8" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm9" , NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm10", NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm11", NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm12", NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm13", NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm14", NULL,
+      //            sizeof(XMMReg), data);
+      //            bytes_written += WriteRegister (reg_ctx, "xmm15", NULL,
+      //            sizeof(XMMReg), data);
+      //
+      //            // Fill rest with zeros
+      //            for (size_t i=0, n = fpu_byte_size - bytes_written; i<n; ++
+      //            i)
+      //                data.PutChar(0);
+
+      // Write out the EXC registers
+      data.PutHex32(EXCRegSet);
+      data.PutHex32(EXCWordCount);
+      WriteRegister(reg_ctx, "trapno", NULL, 4, data);
+      WriteRegister(reg_ctx, "err", NULL, 4, data);
+      WriteRegister(reg_ctx, "faultvaddr", NULL, 8, data);
+      return true;
     }
+    return false;
+  }
 
 protected:
-    int
-    DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
-    {
-        return 0;
-    }
+  int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return 0; }
 
-    int
-    DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
-    {
-        return 0;
-    }
+  int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return 0; }
 
-    int
-    DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
-    {
-        return 0;
-    }
+  int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return 0; }
 
-    int
-    DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
-    {
-        return 0;
-    }
+  int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override {
+    return 0;
+  }
 
-    int
-    DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
-    {
-        return 0;
-    }
+  int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override {
+    return 0;
+  }
 
-    int
-    DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
-    {
-        return 0;
-    }
+  int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override {
+    return 0;
+  }
 };
 
-class RegisterContextDarwin_i386_Mach : public RegisterContextDarwin_i386
-{
+class RegisterContextDarwin_i386_Mach : public RegisterContextDarwin_i386 {
 public:
-    RegisterContextDarwin_i386_Mach (lldb_private::Thread &thread, const DataExtractor &data) :
-    RegisterContextDarwin_i386 (thread, 0)
-    {
-        SetRegisterDataFrom_LC_THREAD (data);
-    }
-
-    void
-    InvalidateAllRegisters() override
-    {
-        // Do nothing... registers are always valid...
-    }
-
-    void
-    SetRegisterDataFrom_LC_THREAD (const DataExtractor &data)
-    {
-        lldb::offset_t offset = 0;
-        SetError (GPRRegSet, Read, -1);
-        SetError (FPURegSet, Read, -1);
-        SetError (EXCRegSet, Read, -1);
-        bool done = false;
-
-        while (!done)
-        {
-            int flavor = data.GetU32 (&offset);
-            if (flavor == 0)
-                done = true;
-            else
-            {
-                uint32_t i;
-                uint32_t count = data.GetU32 (&offset);
-                switch (flavor)
-                {
-                    case GPRRegSet:
-                        for (i=0; i<count; ++i)
-                            (&gpr.eax)[i] = data.GetU32(&offset);
-                        SetError (GPRRegSet, Read, 0);
-                        done = true;
-
-                        break;
-                    case FPURegSet:
-                        // TODO: fill in FPU regs....
-                        //SetError (FPURegSet, Read, -1);
-                        done = true;
+  RegisterContextDarwin_i386_Mach(lldb_private::Thread &thread,
+                                  const DataExtractor &data)
+      : RegisterContextDarwin_i386(thread, 0) {
+    SetRegisterDataFrom_LC_THREAD(data);
+  }
+
+  void InvalidateAllRegisters() override {
+    // Do nothing... registers are always valid...
+  }
 
-                        break;
-                    case EXCRegSet:
-                        exc.trapno = data.GetU32(&offset);
-                        exc.err = data.GetU32(&offset);
-                        exc.faultvaddr = data.GetU32(&offset);
-                        SetError (EXCRegSet, Read, 0);
-                        done = true;
-                        break;
-                    case 7:
-                    case 8:
-                    case 9:
-                        // fancy flavors that encapsulate of the above
-                        // flavors...
-                        break;
+  void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data) {
+    lldb::offset_t offset = 0;
+    SetError(GPRRegSet, Read, -1);
+    SetError(FPURegSet, Read, -1);
+    SetError(EXCRegSet, Read, -1);
+    bool done = false;
+
+    while (!done) {
+      int flavor = data.GetU32(&offset);
+      if (flavor == 0)
+        done = true;
+      else {
+        uint32_t i;
+        uint32_t count = data.GetU32(&offset);
+        switch (flavor) {
+        case GPRRegSet:
+          for (i = 0; i < count; ++i)
+            (&gpr.eax)[i] = data.GetU32(&offset);
+          SetError(GPRRegSet, Read, 0);
+          done = true;
+
+          break;
+        case FPURegSet:
+          // TODO: fill in FPU regs....
+          // SetError (FPURegSet, Read, -1);
+          done = true;
+
+          break;
+        case EXCRegSet:
+          exc.trapno = data.GetU32(&offset);
+          exc.err = data.GetU32(&offset);
+          exc.faultvaddr = data.GetU32(&offset);
+          SetError(EXCRegSet, Read, 0);
+          done = true;
+          break;
+        case 7:
+        case 8:
+        case 9:
+          // fancy flavors that encapsulate of the above
+          // flavors...
+          break;
 
-                    default:
-                        done = true;
-                        break;
-                }
-            }
+        default:
+          done = true;
+          break;
         }
+      }
     }
+  }
 
-    static size_t
-    WriteRegister (RegisterContext *reg_ctx, const char *name, const char *alt_name, size_t reg_byte_size, Stream &data)
-    {
-        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
-        if (reg_info == NULL)
-            reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
-        if (reg_info)
-        {
-            lldb_private::RegisterValue reg_value;
-            if (reg_ctx->ReadRegister(reg_info, reg_value))
-            {
-                if (reg_info->byte_size >= reg_byte_size)
-                    data.Write(reg_value.GetBytes(), reg_byte_size);
-                else
-                {
-                    data.Write(reg_value.GetBytes(), reg_info->byte_size);
-                    for (size_t i=0, n = reg_byte_size - reg_info->byte_size; i<n; ++ i)
-                        data.PutChar(0);
-                }
-                return reg_byte_size;
-            }
-        }
-        // Just write zeros if all else fails
-        for (size_t i=0; i<reg_byte_size; ++ i)
+  static size_t WriteRegister(RegisterContext *reg_ctx, const char *name,
+                              const char *alt_name, size_t reg_byte_size,
+                              Stream &data) {
+    const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
+    if (reg_info == NULL)
+      reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
+    if (reg_info) {
+      lldb_private::RegisterValue reg_value;
+      if (reg_ctx->ReadRegister(reg_info, reg_value)) {
+        if (reg_info->byte_size >= reg_byte_size)
+          data.Write(reg_value.GetBytes(), reg_byte_size);
+        else {
+          data.Write(reg_value.GetBytes(), reg_info->byte_size);
+          for (size_t i = 0, n = reg_byte_size - reg_info->byte_size; i < n;
+               ++i)
             data.PutChar(0);
+        }
         return reg_byte_size;
+      }
     }
-
-    static bool
-    Create_LC_THREAD (Thread *thread, Stream &data)
-    {
-        RegisterContextSP reg_ctx_sp (thread->GetRegisterContext());
-        if (reg_ctx_sp)
-        {
-            RegisterContext *reg_ctx = reg_ctx_sp.get();
-
-            data.PutHex32 (GPRRegSet);  // Flavor
-            data.PutHex32 (GPRWordCount);
-            WriteRegister (reg_ctx, "eax", NULL, 4, data);
-            WriteRegister (reg_ctx, "ebx", NULL, 4, data);
-            WriteRegister (reg_ctx, "ecx", NULL, 4, data);
-            WriteRegister (reg_ctx, "edx", NULL, 4, data);
-            WriteRegister (reg_ctx, "edi", NULL, 4, data);
-            WriteRegister (reg_ctx, "esi", NULL, 4, data);
-            WriteRegister (reg_ctx, "ebp", NULL, 4, data);
-            WriteRegister (reg_ctx, "esp", NULL, 4, data);
-            WriteRegister (reg_ctx, "ss", NULL, 4, data);
-            WriteRegister (reg_ctx, "eflags", NULL, 4, data);
-            WriteRegister (reg_ctx, "eip", NULL, 4, data);
-            WriteRegister (reg_ctx, "cs", NULL, 4, data);
-            WriteRegister (reg_ctx, "ds", NULL, 4, data);
-            WriteRegister (reg_ctx, "es", NULL, 4, data);
-            WriteRegister (reg_ctx, "fs", NULL, 4, data);
-            WriteRegister (reg_ctx, "gs", NULL, 4, data);
-
-            // Write out the EXC registers
-            data.PutHex32 (EXCRegSet);
-            data.PutHex32 (EXCWordCount);
-            WriteRegister (reg_ctx, "trapno", NULL, 4, data);
-            WriteRegister (reg_ctx, "err", NULL, 4, data);
-            WriteRegister (reg_ctx, "faultvaddr", NULL, 4, data);
-            return true;
-        }
-        return false;
+    // Just write zeros if all else fails
+    for (size_t i = 0; i < reg_byte_size; ++i)
+      data.PutChar(0);
+    return reg_byte_size;
+  }
+
+  static bool Create_LC_THREAD(Thread *thread, Stream &data) {
+    RegisterContextSP reg_ctx_sp(thread->GetRegisterContext());
+    if (reg_ctx_sp) {
+      RegisterContext *reg_ctx = reg_ctx_sp.get();
+
+      data.PutHex32(GPRRegSet); // Flavor
+      data.PutHex32(GPRWordCount);
+      WriteRegister(reg_ctx, "eax", NULL, 4, data);
+      WriteRegister(reg_ctx, "ebx", NULL, 4, data);
+      WriteRegister(reg_ctx, "ecx", NULL, 4, data);
+      WriteRegister(reg_ctx, "edx", NULL, 4, data);
+      WriteRegister(reg_ctx, "edi", NULL, 4, data);
+      WriteRegister(reg_ctx, "esi", NULL, 4, data);
+      WriteRegister(reg_ctx, "ebp", NULL, 4, data);
+      WriteRegister(reg_ctx, "esp", NULL, 4, data);
+      WriteRegister(reg_ctx, "ss", NULL, 4, data);
+      WriteRegister(reg_ctx, "eflags", NULL, 4, data);
+      WriteRegister(reg_ctx, "eip", NULL, 4, data);
+      WriteRegister(reg_ctx, "cs", NULL, 4, data);
+      WriteRegister(reg_ctx, "ds", NULL, 4, data);
+      WriteRegister(reg_ctx, "es", NULL, 4, data);
+      WriteRegister(reg_ctx, "fs", NULL, 4, data);
+      WriteRegister(reg_ctx, "gs", NULL, 4, data);
+
+      // Write out the EXC registers
+      data.PutHex32(EXCRegSet);
+      data.PutHex32(EXCWordCount);
+      WriteRegister(reg_ctx, "trapno", NULL, 4, data);
+      WriteRegister(reg_ctx, "err", NULL, 4, data);
+      WriteRegister(reg_ctx, "faultvaddr", NULL, 4, data);
+      return true;
     }
+    return false;
+  }
 
 protected:
-    int
-    DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
-    {
-        return 0;
-    }
+  int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return 0; }
 
-    int
-    DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
-    {
-        return 0;
-    }
+  int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return 0; }
 
-    int
-    DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
-    {
-        return 0;
-    }
+  int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return 0; }
 
-    int
-    DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
-    {
-        return 0;
-    }
+  int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override {
+    return 0;
+  }
 
-    int
-    DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
-    {
-        return 0;
-    }
+  int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override {
+    return 0;
+  }
 
-    int
-    DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
-    {
-        return 0;
-    }
+  int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override {
+    return 0;
+  }
 };
 
-class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm
-{
+class RegisterContextDarwin_arm_Mach : public RegisterContextDarwin_arm {
 public:
-    RegisterContextDarwin_arm_Mach (lldb_private::Thread &thread, const DataExtractor &data) :
-        RegisterContextDarwin_arm (thread, 0)
-    {
-        SetRegisterDataFrom_LC_THREAD (data);
-    }
-
-    void
-    InvalidateAllRegisters() override
-    {
-        // Do nothing... registers are always valid...
-    }
-
-    void
-    SetRegisterDataFrom_LC_THREAD (const DataExtractor &data)
-    {
-        lldb::offset_t offset = 0;
-        SetError (GPRRegSet, Read, -1);
-        SetError (FPURegSet, Read, -1);
-        SetError (EXCRegSet, Read, -1);
-        bool done = false;
-
-        while (!done)
-        {
-            int flavor = data.GetU32 (&offset);
-            uint32_t count = data.GetU32 (&offset);
-            lldb::offset_t next_thread_state = offset + (count * 4);
-            switch (flavor)
-            {
-                case GPRAltRegSet:
-                case GPRRegSet:
-                    for (uint32_t i=0; i<count; ++i)
-                    {
-                        gpr.r[i] = data.GetU32(&offset);
-                    }
-
-                    // Note that gpr.cpsr is also copied by the above loop; this loop technically extends 
-                    // one element past the end of the gpr.r[] array.
-
-                    SetError (GPRRegSet, Read, 0);
-                    offset = next_thread_state;
-                    break;
-
-                case FPURegSet:
-                    {
-                        uint8_t  *fpu_reg_buf = (uint8_t*) &fpu.floats.s[0];
-                        const int fpu_reg_buf_size = sizeof (fpu.floats);
-                        if (data.ExtractBytes (offset, fpu_reg_buf_size, eByteOrderLittle, fpu_reg_buf) == fpu_reg_buf_size)
-                        {
-                            offset += fpu_reg_buf_size;
-                            fpu.fpscr = data.GetU32(&offset);
-                            SetError (FPURegSet, Read, 0);
-                        }
-                        else
-                        {
-                            done = true;
-                        }
-                    }
-                    offset = next_thread_state;
-                    break;
-
-                case EXCRegSet:
-                    if (count == 3)
-                    {
-                        exc.exception = data.GetU32(&offset);
-                        exc.fsr = data.GetU32(&offset);
-                        exc.far = data.GetU32(&offset);
-                        SetError (EXCRegSet, Read, 0);
-                    }
-                    done = true;
-                    offset = next_thread_state;
-                    break;
-
-                // Unknown register set flavor, stop trying to parse.
-                default:
-                    done = true;
-            }
-        }
-    }
+  RegisterContextDarwin_arm_Mach(lldb_private::Thread &thread,
+                                 const DataExtractor &data)
+      : RegisterContextDarwin_arm(thread, 0) {
+    SetRegisterDataFrom_LC_THREAD(data);
+  }
+
+  void InvalidateAllRegisters() override {
+    // Do nothing... registers are always valid...
+  }
 
-    static size_t
-    WriteRegister (RegisterContext *reg_ctx, const char *name, const char *alt_name, size_t reg_byte_size, Stream &data)
-    {
-        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
-        if (reg_info == NULL)
-            reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
-        if (reg_info)
-        {
-            lldb_private::RegisterValue reg_value;
-            if (reg_ctx->ReadRegister(reg_info, reg_value))
-            {
-                if (reg_info->byte_size >= reg_byte_size)
-                    data.Write(reg_value.GetBytes(), reg_byte_size);
-                else
-                {
-                    data.Write(reg_value.GetBytes(), reg_info->byte_size);
-                    for (size_t i=0, n = reg_byte_size - reg_info->byte_size; i<n; ++ i)
-                        data.PutChar(0);
-                }
-                return reg_byte_size;
-            }
-        }
-        // Just write zeros if all else fails
-        for (size_t i=0; i<reg_byte_size; ++ i)
+  void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data) {
+    lldb::offset_t offset = 0;
+    SetError(GPRRegSet, Read, -1);
+    SetError(FPURegSet, Read, -1);
+    SetError(EXCRegSet, Read, -1);
+    bool done = false;
+
+    while (!done) {
+      int flavor = data.GetU32(&offset);
+      uint32_t count = data.GetU32(&offset);
+      lldb::offset_t next_thread_state = offset + (count * 4);
+      switch (flavor) {
+      case GPRAltRegSet:
+      case GPRRegSet:
+        for (uint32_t i = 0; i < count; ++i) {
+          gpr.r[i] = data.GetU32(&offset);
+        }
+
+        // Note that gpr.cpsr is also copied by the above loop; this loop
+        // technically extends
+        // one element past the end of the gpr.r[] array.
+
+        SetError(GPRRegSet, Read, 0);
+        offset = next_thread_state;
+        break;
+
+      case FPURegSet: {
+        uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats.s[0];
+        const int fpu_reg_buf_size = sizeof(fpu.floats);
+        if (data.ExtractBytes(offset, fpu_reg_buf_size, eByteOrderLittle,
+                              fpu_reg_buf) == fpu_reg_buf_size) {
+          offset += fpu_reg_buf_size;
+          fpu.fpscr = data.GetU32(&offset);
+          SetError(FPURegSet, Read, 0);
+        } else {
+          done = true;
+        }
+      }
+        offset = next_thread_state;
+        break;
+
+      case EXCRegSet:
+        if (count == 3) {
+          exc.exception = data.GetU32(&offset);
+          exc.fsr = data.GetU32(&offset);
+          exc.far = data.GetU32(&offset);
+          SetError(EXCRegSet, Read, 0);
+        }
+        done = true;
+        offset = next_thread_state;
+        break;
+
+      // Unknown register set flavor, stop trying to parse.
+      default:
+        done = true;
+      }
+    }
+  }
+
+  static size_t WriteRegister(RegisterContext *reg_ctx, const char *name,
+                              const char *alt_name, size_t reg_byte_size,
+                              Stream &data) {
+    const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
+    if (reg_info == NULL)
+      reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
+    if (reg_info) {
+      lldb_private::RegisterValue reg_value;
+      if (reg_ctx->ReadRegister(reg_info, reg_value)) {
+        if (reg_info->byte_size >= reg_byte_size)
+          data.Write(reg_value.GetBytes(), reg_byte_size);
+        else {
+          data.Write(reg_value.GetBytes(), reg_info->byte_size);
+          for (size_t i = 0, n = reg_byte_size - reg_info->byte_size; i < n;
+               ++i)
             data.PutChar(0);
+        }
         return reg_byte_size;
+      }
     }
-
-    static bool
-    Create_LC_THREAD (Thread *thread, Stream &data)
-    {
-        RegisterContextSP reg_ctx_sp (thread->GetRegisterContext());
-        if (reg_ctx_sp)
-        {
-            RegisterContext *reg_ctx = reg_ctx_sp.get();
-
-            data.PutHex32 (GPRRegSet);  // Flavor
-            data.PutHex32 (GPRWordCount);
-            WriteRegister (reg_ctx, "r0", NULL, 4, data);
-            WriteRegister (reg_ctx, "r1", NULL, 4, data);
-            WriteRegister (reg_ctx, "r2", NULL, 4, data);
-            WriteRegister (reg_ctx, "r3", NULL, 4, data);
-            WriteRegister (reg_ctx, "r4", NULL, 4, data);
-            WriteRegister (reg_ctx, "r5", NULL, 4, data);
-            WriteRegister (reg_ctx, "r6", NULL, 4, data);
-            WriteRegister (reg_ctx, "r7", NULL, 4, data);
-            WriteRegister (reg_ctx, "r8", NULL, 4, data);
-            WriteRegister (reg_ctx, "r9", NULL, 4, data);
-            WriteRegister (reg_ctx, "r10", NULL, 4, data);
-            WriteRegister (reg_ctx, "r11", NULL, 4, data);
-            WriteRegister (reg_ctx, "r12", NULL, 4, data);
-            WriteRegister (reg_ctx, "sp", NULL, 4, data);
-            WriteRegister (reg_ctx, "lr", NULL, 4, data);
-            WriteRegister (reg_ctx, "pc", NULL, 4, data);
-            WriteRegister (reg_ctx, "cpsr", NULL, 4, data);
-
-            // Write out the EXC registers
-//            data.PutHex32 (EXCRegSet);
-//            data.PutHex32 (EXCWordCount);
-//            WriteRegister (reg_ctx, "exception", NULL, 4, data);
-//            WriteRegister (reg_ctx, "fsr", NULL, 4, data);
-//            WriteRegister (reg_ctx, "far", NULL, 4, data);
-            return true;
-        }
-        return false;
+    // Just write zeros if all else fails
+    for (size_t i = 0; i < reg_byte_size; ++i)
+      data.PutChar(0);
+    return reg_byte_size;
+  }
+
+  static bool Create_LC_THREAD(Thread *thread, Stream &data) {
+    RegisterContextSP reg_ctx_sp(thread->GetRegisterContext());
+    if (reg_ctx_sp) {
+      RegisterContext *reg_ctx = reg_ctx_sp.get();
+
+      data.PutHex32(GPRRegSet); // Flavor
+      data.PutHex32(GPRWordCount);
+      WriteRegister(reg_ctx, "r0", NULL, 4, data);
+      WriteRegister(reg_ctx, "r1", NULL, 4, data);
+      WriteRegister(reg_ctx, "r2", NULL, 4, data);
+      WriteRegister(reg_ctx, "r3", NULL, 4, data);
+      WriteRegister(reg_ctx, "r4", NULL, 4, data);
+      WriteRegister(reg_ctx, "r5", NULL, 4, data);
+      WriteRegister(reg_ctx, "r6", NULL, 4, data);
+      WriteRegister(reg_ctx, "r7", NULL, 4, data);
+      WriteRegister(reg_ctx, "r8", NULL, 4, data);
+      WriteRegister(reg_ctx, "r9", NULL, 4, data);
+      WriteRegister(reg_ctx, "r10", NULL, 4, data);
+      WriteRegister(reg_ctx, "r11", NULL, 4, data);
+      WriteRegister(reg_ctx, "r12", NULL, 4, data);
+      WriteRegister(reg_ctx, "sp", NULL, 4, data);
+      WriteRegister(reg_ctx, "lr", NULL, 4, data);
+      WriteRegister(reg_ctx, "pc", NULL, 4, data);
+      WriteRegister(reg_ctx, "cpsr", NULL, 4, data);
+
+      // Write out the EXC registers
+      //            data.PutHex32 (EXCRegSet);
+      //            data.PutHex32 (EXCWordCount);
+      //            WriteRegister (reg_ctx, "exception", NULL, 4, data);
+      //            WriteRegister (reg_ctx, "fsr", NULL, 4, data);
+      //            WriteRegister (reg_ctx, "far", NULL, 4, data);
+      return true;
     }
+    return false;
+  }
 
 protected:
-    int
-    DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
-    {
-        return -1;
-    }
+  int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return -1; }
 
-    int
-    DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
-    {
-        return -1;
-    }
+  int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return -1; }
 
-    int
-    DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
-    {
-        return -1;
-    }
+  int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return -1; }
 
-    int
-    DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) override
-    {
-        return -1;
-    }
+  int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) override { return -1; }
 
-    int
-    DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
-    {
-        return 0;
-    }
+  int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override {
+    return 0;
+  }
 
-    int
-    DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
-    {
-        return 0;
-    }
+  int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override {
+    return 0;
+  }
 
-    int
-    DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
-    {
-        return 0;
-    }
+  int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override {
+    return 0;
+  }
 
-    int
-    DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) override
-    {
-        return -1;
-    }
+  int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) override {
+    return -1;
+  }
 };
 
-class RegisterContextDarwin_arm64_Mach : public RegisterContextDarwin_arm64
-{
+class RegisterContextDarwin_arm64_Mach : public RegisterContextDarwin_arm64 {
 public:
-    RegisterContextDarwin_arm64_Mach (lldb_private::Thread &thread, const DataExtractor &data) :
-        RegisterContextDarwin_arm64 (thread, 0)
-    {
-        SetRegisterDataFrom_LC_THREAD (data);
-    }
-    
-    void
-    InvalidateAllRegisters() override
-    {
-        // Do nothing... registers are always valid...
-    }
-    
-    void
-    SetRegisterDataFrom_LC_THREAD (const DataExtractor &data)
-    {
-        lldb::offset_t offset = 0;
-        SetError (GPRRegSet, Read, -1);
-        SetError (FPURegSet, Read, -1);
-        SetError (EXCRegSet, Read, -1);
-        bool done = false;
-        while (!done)
-        {
-            int flavor = data.GetU32 (&offset);
-            uint32_t count = data.GetU32 (&offset);
-            lldb::offset_t next_thread_state = offset + (count * 4);
-            switch (flavor)
-            {
-                case GPRRegSet:
-                    // x0-x29 + fp + lr + sp + pc (== 33 64-bit registers) plus cpsr (1 32-bit register)
-                    if (count >= (33 * 2) + 1)
-                    {
-                        for (uint32_t i=0; i<33; ++i)
-                            gpr.x[i] = data.GetU64(&offset);
-                        gpr.cpsr = data.GetU32(&offset);
-                        SetError (GPRRegSet, Read, 0);
-                    }
-                    offset = next_thread_state;
-                    break;
-                case FPURegSet:
-                    {
-                        uint8_t *fpu_reg_buf = (uint8_t*) &fpu.v[0];
-                        const int fpu_reg_buf_size = sizeof (fpu);
-                        if (fpu_reg_buf_size == count
-                            && data.ExtractBytes (offset, fpu_reg_buf_size, eByteOrderLittle, fpu_reg_buf) == fpu_reg_buf_size)
-                        {
-                            SetError (FPURegSet, Read, 0);
-                        }
-                        else
-                        {
-                            done = true;
-                        }
-                    }
-                    offset = next_thread_state;
-                    break;
-                case EXCRegSet:
-                    if (count == 4)
-                    {
-                        exc.far = data.GetU64(&offset);
-                        exc.esr = data.GetU32(&offset);
-                        exc.exception = data.GetU32(&offset);
-                        SetError (EXCRegSet, Read, 0);
-                    }
-                    offset = next_thread_state;
-                    break;
-                default:
-                    done = true;
-                    break;
-            }
-        }
-    }
+  RegisterContextDarwin_arm64_Mach(lldb_private::Thread &thread,
+                                   const DataExtractor &data)
+      : RegisterContextDarwin_arm64(thread, 0) {
+    SetRegisterDataFrom_LC_THREAD(data);
+  }
+
+  void InvalidateAllRegisters() override {
+    // Do nothing... registers are always valid...
+  }
 
-    static size_t
-    WriteRegister (RegisterContext *reg_ctx, const char *name, const char *alt_name, size_t reg_byte_size, Stream &data)
-    {
-        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
-        if (reg_info == NULL)
-            reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
-        if (reg_info)
-        {
-            lldb_private::RegisterValue reg_value;
-            if (reg_ctx->ReadRegister(reg_info, reg_value))
-            {
-                if (reg_info->byte_size >= reg_byte_size)
-                    data.Write(reg_value.GetBytes(), reg_byte_size);
-                else
-                {
-                    data.Write(reg_value.GetBytes(), reg_info->byte_size);
-                    for (size_t i=0, n = reg_byte_size - reg_info->byte_size; i<n; ++ i)
-                        data.PutChar(0);
-                }
-                return reg_byte_size;
-            }
-        }
-        // Just write zeros if all else fails
-        for (size_t i=0; i<reg_byte_size; ++ i)
+  void SetRegisterDataFrom_LC_THREAD(const DataExtractor &data) {
+    lldb::offset_t offset = 0;
+    SetError(GPRRegSet, Read, -1);
+    SetError(FPURegSet, Read, -1);
+    SetError(EXCRegSet, Read, -1);
+    bool done = false;
+    while (!done) {
+      int flavor = data.GetU32(&offset);
+      uint32_t count = data.GetU32(&offset);
+      lldb::offset_t next_thread_state = offset + (count * 4);
+      switch (flavor) {
+      case GPRRegSet:
+        // x0-x29 + fp + lr + sp + pc (== 33 64-bit registers) plus cpsr (1
+        // 32-bit register)
+        if (count >= (33 * 2) + 1) {
+          for (uint32_t i = 0; i < 33; ++i)
+            gpr.x[i] = data.GetU64(&offset);
+          gpr.cpsr = data.GetU32(&offset);
+          SetError(GPRRegSet, Read, 0);
+        }
+        offset = next_thread_state;
+        break;
+      case FPURegSet: {
+        uint8_t *fpu_reg_buf = (uint8_t *)&fpu.v[0];
+        const int fpu_reg_buf_size = sizeof(fpu);
+        if (fpu_reg_buf_size == count &&
+            data.ExtractBytes(offset, fpu_reg_buf_size, eByteOrderLittle,
+                              fpu_reg_buf) == fpu_reg_buf_size) {
+          SetError(FPURegSet, Read, 0);
+        } else {
+          done = true;
+        }
+      }
+        offset = next_thread_state;
+        break;
+      case EXCRegSet:
+        if (count == 4) {
+          exc.far = data.GetU64(&offset);
+          exc.esr = data.GetU32(&offset);
+          exc.exception = data.GetU32(&offset);
+          SetError(EXCRegSet, Read, 0);
+        }
+        offset = next_thread_state;
+        break;
+      default:
+        done = true;
+        break;
+      }
+    }
+  }
+
+  static size_t WriteRegister(RegisterContext *reg_ctx, const char *name,
+                              const char *alt_name, size_t reg_byte_size,
+                              Stream &data) {
+    const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name);
+    if (reg_info == NULL)
+      reg_info = reg_ctx->GetRegisterInfoByName(alt_name);
+    if (reg_info) {
+      lldb_private::RegisterValue reg_value;
+      if (reg_ctx->ReadRegister(reg_info, reg_value)) {
+        if (reg_info->byte_size >= reg_byte_size)
+          data.Write(reg_value.GetBytes(), reg_byte_size);
+        else {
+          data.Write(reg_value.GetBytes(), reg_info->byte_size);
+          for (size_t i = 0, n = reg_byte_size - reg_info->byte_size; i < n;
+               ++i)
             data.PutChar(0);
+        }
         return reg_byte_size;
+      }
     }
-
-    static bool
-    Create_LC_THREAD (Thread *thread, Stream &data)
-    {
-        RegisterContextSP reg_ctx_sp (thread->GetRegisterContext());
-        if (reg_ctx_sp)
-        {
-            RegisterContext *reg_ctx = reg_ctx_sp.get();
-
-            data.PutHex32 (GPRRegSet);  // Flavor
-            data.PutHex32 (GPRWordCount);
-            WriteRegister (reg_ctx, "x0", NULL, 8, data);
-            WriteRegister (reg_ctx, "x1", NULL, 8, data);
-            WriteRegister (reg_ctx, "x2", NULL, 8, data);
-            WriteRegister (reg_ctx, "x3", NULL, 8, data);
-            WriteRegister (reg_ctx, "x4", NULL, 8, data);
-            WriteRegister (reg_ctx, "x5", NULL, 8, data);
-            WriteRegister (reg_ctx, "x6", NULL, 8, data);
-            WriteRegister (reg_ctx, "x7", NULL, 8, data);
-            WriteRegister (reg_ctx, "x8", NULL, 8, data);
-            WriteRegister (reg_ctx, "x9", NULL, 8, data);
-            WriteRegister (reg_ctx, "x10", NULL, 8, data);
-            WriteRegister (reg_ctx, "x11", NULL, 8, data);
-            WriteRegister (reg_ctx, "x12", NULL, 8, data);
-            WriteRegister (reg_ctx, "x13", NULL, 8, data);
-            WriteRegister (reg_ctx, "x14", NULL, 8, data);
-            WriteRegister (reg_ctx, "x15", NULL, 8, data);
-            WriteRegister (reg_ctx, "x16", NULL, 8, data);
-            WriteRegister (reg_ctx, "x17", NULL, 8, data);
-            WriteRegister (reg_ctx, "x18", NULL, 8, data);
-            WriteRegister (reg_ctx, "x19", NULL, 8, data);
-            WriteRegister (reg_ctx, "x20", NULL, 8, data);
-            WriteRegister (reg_ctx, "x21", NULL, 8, data);
-            WriteRegister (reg_ctx, "x22", NULL, 8, data);
-            WriteRegister (reg_ctx, "x23", NULL, 8, data);
-            WriteRegister (reg_ctx, "x24", NULL, 8, data);
-            WriteRegister (reg_ctx, "x25", NULL, 8, data);
-            WriteRegister (reg_ctx, "x26", NULL, 8, data);
-            WriteRegister (reg_ctx, "x27", NULL, 8, data);
-            WriteRegister (reg_ctx, "x28", NULL, 8, data);
-            WriteRegister (reg_ctx, "fp", NULL, 8, data);
-            WriteRegister (reg_ctx, "lr", NULL, 8, data);
-            WriteRegister (reg_ctx, "sp", NULL, 8, data);
-            WriteRegister (reg_ctx, "pc", NULL, 8, data);
-            WriteRegister (reg_ctx, "cpsr", NULL, 4, data);
-
-            // Write out the EXC registers
-//            data.PutHex32 (EXCRegSet);
-//            data.PutHex32 (EXCWordCount);
-//            WriteRegister (reg_ctx, "far", NULL, 8, data);
-//            WriteRegister (reg_ctx, "esr", NULL, 4, data);
-//            WriteRegister (reg_ctx, "exception", NULL, 4, data);
-            return true;
-        }
-        return false;
+    // Just write zeros if all else fails
+    for (size_t i = 0; i < reg_byte_size; ++i)
+      data.PutChar(0);
+    return reg_byte_size;
+  }
+
+  static bool Create_LC_THREAD(Thread *thread, Stream &data) {
+    RegisterContextSP reg_ctx_sp(thread->GetRegisterContext());
+    if (reg_ctx_sp) {
+      RegisterContext *reg_ctx = reg_ctx_sp.get();
+
+      data.PutHex32(GPRRegSet); // Flavor
+      data.PutHex32(GPRWordCount);
+      WriteRegister(reg_ctx, "x0", NULL, 8, data);
+      WriteRegister(reg_ctx, "x1", NULL, 8, data);
+      WriteRegister(reg_ctx, "x2", NULL, 8, data);
+      WriteRegister(reg_ctx, "x3", NULL, 8, data);
+      WriteRegister(reg_ctx, "x4", NULL, 8, data);
+      WriteRegister(reg_ctx, "x5", NULL, 8, data);
+      WriteRegister(reg_ctx, "x6", NULL, 8, data);
+      WriteRegister(reg_ctx, "x7", NULL, 8, data);
+      WriteRegister(reg_ctx, "x8", NULL, 8, data);
+      WriteRegister(reg_ctx, "x9", NULL, 8, data);
+      WriteRegister(reg_ctx, "x10", NULL, 8, data);
+      WriteRegister(reg_ctx, "x11", NULL, 8, data);
+      WriteRegister(reg_ctx, "x12", NULL, 8, data);
+      WriteRegister(reg_ctx, "x13", NULL, 8, data);
+      WriteRegister(reg_ctx, "x14", NULL, 8, data);
+      WriteRegister(reg_ctx, "x15", NULL, 8, data);
+      WriteRegister(reg_ctx, "x16", NULL, 8, data);
+      WriteRegister(reg_ctx, "x17", NULL, 8, data);
+      WriteRegister(reg_ctx, "x18", NULL, 8, data);
+      WriteRegister(reg_ctx, "x19", NULL, 8, data);
+      WriteRegister(reg_ctx, "x20", NULL, 8, data);
+      WriteRegister(reg_ctx, "x21", NULL, 8, data);
+      WriteRegister(reg_ctx, "x22", NULL, 8, data);
+      WriteRegister(reg_ctx, "x23", NULL, 8, data);
+      WriteRegister(reg_ctx, "x24", NULL, 8, data);
+      WriteRegister(reg_ctx, "x25", NULL, 8, data);
+      WriteRegister(reg_ctx, "x26", NULL, 8, data);
+      WriteRegister(reg_ctx, "x27", NULL, 8, data);
+      WriteRegister(reg_ctx, "x28", NULL, 8, data);
+      WriteRegister(reg_ctx, "fp", NULL, 8, data);
+      WriteRegister(reg_ctx, "lr", NULL, 8, data);
+      WriteRegister(reg_ctx, "sp", NULL, 8, data);
+      WriteRegister(reg_ctx, "pc", NULL, 8, data);
+      WriteRegister(reg_ctx, "cpsr", NULL, 4, data);
+
+      // Write out the EXC registers
+      //            data.PutHex32 (EXCRegSet);
+      //            data.PutHex32 (EXCWordCount);
+      //            WriteRegister (reg_ctx, "far", NULL, 8, data);
+      //            WriteRegister (reg_ctx, "esr", NULL, 4, data);
+      //            WriteRegister (reg_ctx, "exception", NULL, 4, data);
+      return true;
     }
+    return false;
+  }
 
 protected:
-    int
-    DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override
-    {
-        return -1;
-    }
-    
-    int
-    DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override
-    {
-        return -1;
-    }
-    
-    int
-    DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override
-    {
-        return -1;
-    }
-
-    int
-    DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) override
-    {
-        return -1;
-    }
-    
-    int
-    DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override
-    {
-        return 0;
-    }
-    
-    int
-    DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override
-    {
-        return 0;
-    }
-    
-    int
-    DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override
-    {
-        return 0;
-    }
-    
-    int
-    DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) override
-    {
-        return -1;
-    }
-};
+  int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return -1; }
 
-static uint32_t
-MachHeaderSizeFromMagic(uint32_t magic)
-{
-    switch (magic)
-    {
-        case MH_MAGIC:
-        case MH_CIGAM:
-            return sizeof(struct mach_header);
-            
-        case MH_MAGIC_64:
-        case MH_CIGAM_64:
-            return sizeof(struct mach_header_64);
-            break;
-            
-        default:
-            break;
-    }
+  int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return -1; }
+
+  int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return -1; }
+
+  int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) override { return -1; }
+
+  int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override {
+    return 0;
+  }
+
+  int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) override {
+    return 0;
+  }
+
+  int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) override {
     return 0;
+  }
+
+  int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) override {
+    return -1;
+  }
+};
+
+static uint32_t MachHeaderSizeFromMagic(uint32_t magic) {
+  switch (magic) {
+  case MH_MAGIC:
+  case MH_CIGAM:
+    return sizeof(struct mach_header);
+
+  case MH_MAGIC_64:
+  case MH_CIGAM_64:
+    return sizeof(struct mach_header_64);
+    break;
+
+  default:
+    break;
+  }
+  return 0;
 }
 
 #define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008
 
-void
-ObjectFileMachO::Initialize()
-{
-    PluginManager::RegisterPlugin (GetPluginNameStatic(),
-                                   GetPluginDescriptionStatic(),
-                                   CreateInstance,
-                                   CreateMemoryInstance,
-                                   GetModuleSpecifications,
-                                   SaveCore);
-}
-
-void
-ObjectFileMachO::Terminate()
-{
-    PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-lldb_private::ConstString
-ObjectFileMachO::GetPluginNameStatic()
-{
-    static ConstString g_name("mach-o");
-    return g_name;
-}
-
-const char *
-ObjectFileMachO::GetPluginDescriptionStatic()
-{
-    return "Mach-o object file reader (32 and 64 bit)";
-}
-
-ObjectFile *
-ObjectFileMachO::CreateInstance (const lldb::ModuleSP &module_sp,
-                                 DataBufferSP& data_sp,
-                                 lldb::offset_t data_offset,
-                                 const FileSpec* file,
-                                 lldb::offset_t file_offset,
-                                 lldb::offset_t length)
-{
-    if (!data_sp)
-    {
-        data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
-        data_offset = 0;
-    }
-
-    if (ObjectFileMachO::MagicBytesMatch(data_sp, data_offset, length))
-    {
-        // Update the data to contain the entire file if it doesn't already
-        if (data_sp->GetByteSize() < length)
-        {
-            data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
-            data_offset = 0;
-        }
-        std::unique_ptr<ObjectFile> objfile_ap(new ObjectFileMachO (module_sp, data_sp, data_offset, file, file_offset, length));
-        if (objfile_ap.get() && objfile_ap->ParseHeader())
-            return objfile_ap.release();
-    }
-    return NULL;
-}
-
-ObjectFile *
-ObjectFileMachO::CreateMemoryInstance (const lldb::ModuleSP &module_sp,
-                                       DataBufferSP& data_sp,
-                                       const ProcessSP &process_sp,
-                                       lldb::addr_t header_addr)
-{
-    if (ObjectFileMachO::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize()))
-    {
-        std::unique_ptr<ObjectFile> objfile_ap(new ObjectFileMachO (module_sp, data_sp, process_sp, header_addr));
-        if (objfile_ap.get() && objfile_ap->ParseHeader())
-            return objfile_ap.release();
-    }
-    return NULL;
-}
-
-size_t
-ObjectFileMachO::GetModuleSpecifications (const lldb_private::FileSpec& file,
-                                          lldb::DataBufferSP& data_sp,
-                                          lldb::offset_t data_offset,
-                                          lldb::offset_t file_offset,
-                                          lldb::offset_t length,
-                                          lldb_private::ModuleSpecList &specs)
-{
-    const size_t initial_count = specs.GetSize();
-    
-    if (ObjectFileMachO::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize()))
-    {
-        DataExtractor data;
+void ObjectFileMachO::Initialize() {
+  PluginManager::RegisterPlugin(
+      GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+      CreateMemoryInstance, GetModuleSpecifications, SaveCore);
+}
+
+void ObjectFileMachO::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb_private::ConstString ObjectFileMachO::GetPluginNameStatic() {
+  static ConstString g_name("mach-o");
+  return g_name;
+}
+
+const char *ObjectFileMachO::GetPluginDescriptionStatic() {
+  return "Mach-o object file reader (32 and 64 bit)";
+}
+
+ObjectFile *ObjectFileMachO::CreateInstance(const lldb::ModuleSP &module_sp,
+                                            DataBufferSP &data_sp,
+                                            lldb::offset_t data_offset,
+                                            const FileSpec *file,
+                                            lldb::offset_t file_offset,
+                                            lldb::offset_t length) {
+  if (!data_sp) {
+    data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+    data_offset = 0;
+  }
+
+  if (ObjectFileMachO::MagicBytesMatch(data_sp, data_offset, length)) {
+    // Update the data to contain the entire file if it doesn't already
+    if (data_sp->GetByteSize() < length) {
+      data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+      data_offset = 0;
+    }
+    std::unique_ptr<ObjectFile> objfile_ap(new ObjectFileMachO(
+        module_sp, data_sp, data_offset, file, file_offset, length));
+    if (objfile_ap.get() && objfile_ap->ParseHeader())
+      return objfile_ap.release();
+  }
+  return NULL;
+}
+
+ObjectFile *ObjectFileMachO::CreateMemoryInstance(
+    const lldb::ModuleSP &module_sp, DataBufferSP &data_sp,
+    const ProcessSP &process_sp, lldb::addr_t header_addr) {
+  if (ObjectFileMachO::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) {
+    std::unique_ptr<ObjectFile> objfile_ap(
+        new ObjectFileMachO(module_sp, data_sp, process_sp, header_addr));
+    if (objfile_ap.get() && objfile_ap->ParseHeader())
+      return objfile_ap.release();
+  }
+  return NULL;
+}
+
+size_t ObjectFileMachO::GetModuleSpecifications(
+    const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
+    lldb::offset_t data_offset, lldb::offset_t file_offset,
+    lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
+  const size_t initial_count = specs.GetSize();
+
+  if (ObjectFileMachO::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) {
+    DataExtractor data;
+    data.SetData(data_sp);
+    llvm::MachO::mach_header header;
+    if (ParseHeader(data, &data_offset, header)) {
+      size_t header_and_load_cmds =
+          header.sizeofcmds + MachHeaderSizeFromMagic(header.magic);
+      if (header_and_load_cmds >= data_sp->GetByteSize()) {
+        data_sp = file.ReadFileContents(file_offset, header_and_load_cmds);
         data.SetData(data_sp);
-        llvm::MachO::mach_header header;
-        if (ParseHeader (data, &data_offset, header))
-        {
-            size_t header_and_load_cmds = header.sizeofcmds + MachHeaderSizeFromMagic(header.magic);
-            if (header_and_load_cmds >= data_sp->GetByteSize())
-            {
-                data_sp = file.ReadFileContents(file_offset, header_and_load_cmds);
-                data.SetData(data_sp);
-                data_offset = MachHeaderSizeFromMagic(header.magic);
-            }
-            if (data_sp)
-            {
-                ModuleSpec spec;
-                spec.GetFileSpec() = file;
-                spec.SetObjectOffset(file_offset);
-                spec.SetObjectSize(length);
-
-                if (GetArchitecture (header, data, data_offset, spec.GetArchitecture()))
-                {
-                    if (spec.GetArchitecture().IsValid())
-                    {
-                        GetUUID (header, data, data_offset, spec.GetUUID());
-                        specs.Append(spec);
-                    }
-                }
-            }
+        data_offset = MachHeaderSizeFromMagic(header.magic);
+      }
+      if (data_sp) {
+        ModuleSpec spec;
+        spec.GetFileSpec() = file;
+        spec.SetObjectOffset(file_offset);
+        spec.SetObjectSize(length);
+
+        if (GetArchitecture(header, data, data_offset,
+                            spec.GetArchitecture())) {
+          if (spec.GetArchitecture().IsValid()) {
+            GetUUID(header, data, data_offset, spec.GetUUID());
+            specs.Append(spec);
+          }
         }
+      }
     }
-    return specs.GetSize() - initial_count;
+  }
+  return specs.GetSize() - initial_count;
 }
 
-const ConstString &
-ObjectFileMachO::GetSegmentNameTEXT()
-{
-    static ConstString g_segment_name_TEXT ("__TEXT");
-    return g_segment_name_TEXT;
+const ConstString &ObjectFileMachO::GetSegmentNameTEXT() {
+  static ConstString g_segment_name_TEXT("__TEXT");
+  return g_segment_name_TEXT;
 }
 
-const ConstString &
-ObjectFileMachO::GetSegmentNameDATA()
-{
-    static ConstString g_segment_name_DATA ("__DATA");
-    return g_segment_name_DATA;
+const ConstString &ObjectFileMachO::GetSegmentNameDATA() {
+  static ConstString g_segment_name_DATA("__DATA");
+  return g_segment_name_DATA;
 }
 
-const ConstString &
-ObjectFileMachO::GetSegmentNameDATA_DIRTY()
-{
-    static ConstString g_segment_name ("__DATA_DIRTY");
-    return g_segment_name;
+const ConstString &ObjectFileMachO::GetSegmentNameDATA_DIRTY() {
+  static ConstString g_segment_name("__DATA_DIRTY");
+  return g_segment_name;
 }
 
-const ConstString &
-ObjectFileMachO::GetSegmentNameDATA_CONST()
-{
-    static ConstString g_segment_name ("__DATA_CONST");
-    return g_segment_name;
+const ConstString &ObjectFileMachO::GetSegmentNameDATA_CONST() {
+  static ConstString g_segment_name("__DATA_CONST");
+  return g_segment_name;
 }
 
-const ConstString &
-ObjectFileMachO::GetSegmentNameOBJC()
-{
-    static ConstString g_segment_name_OBJC ("__OBJC");
-    return g_segment_name_OBJC;
+const ConstString &ObjectFileMachO::GetSegmentNameOBJC() {
+  static ConstString g_segment_name_OBJC("__OBJC");
+  return g_segment_name_OBJC;
 }
 
-const ConstString &
-ObjectFileMachO::GetSegmentNameLINKEDIT()
-{
-    static ConstString g_section_name_LINKEDIT ("__LINKEDIT");
-    return g_section_name_LINKEDIT;
+const ConstString &ObjectFileMachO::GetSegmentNameLINKEDIT() {
+  static ConstString g_section_name_LINKEDIT("__LINKEDIT");
+  return g_section_name_LINKEDIT;
 }
 
-const ConstString &
-ObjectFileMachO::GetSectionNameEHFrame()
-{
-    static ConstString g_section_name_eh_frame ("__eh_frame");
-    return g_section_name_eh_frame;
+const ConstString &ObjectFileMachO::GetSectionNameEHFrame() {
+  static ConstString g_section_name_eh_frame("__eh_frame");
+  return g_section_name_eh_frame;
 }
 
-bool
-ObjectFileMachO::MagicBytesMatch (DataBufferSP& data_sp,
-                                  lldb::addr_t data_offset,
-                                  lldb::addr_t data_length)
-{
-    DataExtractor data;
-    data.SetData (data_sp, data_offset, data_length);
-    lldb::offset_t offset = 0;
-    uint32_t magic = data.GetU32(&offset);
-    return MachHeaderSizeFromMagic(magic) != 0;
+bool ObjectFileMachO::MagicBytesMatch(DataBufferSP &data_sp,
+                                      lldb::addr_t data_offset,
+                                      lldb::addr_t data_length) {
+  DataExtractor data;
+  data.SetData(data_sp, data_offset, data_length);
+  lldb::offset_t offset = 0;
+  uint32_t magic = data.GetU32(&offset);
+  return MachHeaderSizeFromMagic(magic) != 0;
 }
 
 ObjectFileMachO::ObjectFileMachO(const lldb::ModuleSP &module_sp,
-                                 DataBufferSP& data_sp,
+                                 DataBufferSP &data_sp,
                                  lldb::offset_t data_offset,
-                                 const FileSpec* file,
+                                 const FileSpec *file,
                                  lldb::offset_t file_offset,
-                                 lldb::offset_t length) :
-    ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset),
-    m_mach_segments(),
-    m_mach_sections(),
-    m_entry_point_address(),
-    m_thread_context_offsets(),
-    m_thread_context_offsets_valid(false),
-    m_reexported_dylibs (),
-    m_allow_assembly_emulation_unwind_plans (true)
-{
-    ::memset (&m_header, 0, sizeof(m_header));
-    ::memset (&m_dysymtab, 0, sizeof(m_dysymtab));
-}
-
-ObjectFileMachO::ObjectFileMachO (const lldb::ModuleSP &module_sp,
-                                  lldb::DataBufferSP& header_data_sp,
-                                  const lldb::ProcessSP &process_sp,
-                                  lldb::addr_t header_addr) :
-    ObjectFile(module_sp, process_sp, header_addr, header_data_sp),
-    m_mach_segments(),
-    m_mach_sections(),
-    m_entry_point_address(),
-    m_thread_context_offsets(),
-    m_thread_context_offsets_valid(false),
-    m_reexported_dylibs (),
-    m_allow_assembly_emulation_unwind_plans (true)
-{
-    ::memset (&m_header, 0, sizeof(m_header));
-    ::memset (&m_dysymtab, 0, sizeof(m_dysymtab));
-}
-
-bool
-ObjectFileMachO::ParseHeader (DataExtractor &data,
-                              lldb::offset_t *data_offset_ptr,
-                              llvm::MachO::mach_header &header)
-{
-    data.SetByteOrder (endian::InlHostByteOrder());
-    // Leave magic in the original byte order
-    header.magic = data.GetU32(data_offset_ptr);
+                                 lldb::offset_t length)
+    : ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset),
+      m_mach_segments(), m_mach_sections(), m_entry_point_address(),
+      m_thread_context_offsets(), m_thread_context_offsets_valid(false),
+      m_reexported_dylibs(), m_allow_assembly_emulation_unwind_plans(true) {
+  ::memset(&m_header, 0, sizeof(m_header));
+  ::memset(&m_dysymtab, 0, sizeof(m_dysymtab));
+}
+
+ObjectFileMachO::ObjectFileMachO(const lldb::ModuleSP &module_sp,
+                                 lldb::DataBufferSP &header_data_sp,
+                                 const lldb::ProcessSP &process_sp,
+                                 lldb::addr_t header_addr)
+    : ObjectFile(module_sp, process_sp, header_addr, header_data_sp),
+      m_mach_segments(), m_mach_sections(), m_entry_point_address(),
+      m_thread_context_offsets(), m_thread_context_offsets_valid(false),
+      m_reexported_dylibs(), m_allow_assembly_emulation_unwind_plans(true) {
+  ::memset(&m_header, 0, sizeof(m_header));
+  ::memset(&m_dysymtab, 0, sizeof(m_dysymtab));
+}
+
+bool ObjectFileMachO::ParseHeader(DataExtractor &data,
+                                  lldb::offset_t *data_offset_ptr,
+                                  llvm::MachO::mach_header &header) {
+  data.SetByteOrder(endian::InlHostByteOrder());
+  // Leave magic in the original byte order
+  header.magic = data.GetU32(data_offset_ptr);
+  bool can_parse = false;
+  bool is_64_bit = false;
+  switch (header.magic) {
+  case MH_MAGIC:
+    data.SetByteOrder(endian::InlHostByteOrder());
+    data.SetAddressByteSize(4);
+    can_parse = true;
+    break;
+
+  case MH_MAGIC_64:
+    data.SetByteOrder(endian::InlHostByteOrder());
+    data.SetAddressByteSize(8);
+    can_parse = true;
+    is_64_bit = true;
+    break;
+
+  case MH_CIGAM:
+    data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig
+                          ? eByteOrderLittle
+                          : eByteOrderBig);
+    data.SetAddressByteSize(4);
+    can_parse = true;
+    break;
+
+  case MH_CIGAM_64:
+    data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig
+                          ? eByteOrderLittle
+                          : eByteOrderBig);
+    data.SetAddressByteSize(8);
+    is_64_bit = true;
+    can_parse = true;
+    break;
+
+  default:
+    break;
+  }
+
+  if (can_parse) {
+    data.GetU32(data_offset_ptr, &header.cputype, 6);
+    if (is_64_bit)
+      *data_offset_ptr += 4;
+    return true;
+  } else {
+    memset(&header, 0, sizeof(header));
+  }
+  return false;
+}
+
+bool ObjectFileMachO::ParseHeader() {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
     bool can_parse = false;
-    bool is_64_bit = false;
-    switch (header.magic)
-    {
-        case MH_MAGIC:
-            data.SetByteOrder (endian::InlHostByteOrder());
-            data.SetAddressByteSize(4);
-            can_parse = true;
-            break;
-            
-        case MH_MAGIC_64:
-            data.SetByteOrder (endian::InlHostByteOrder());
-            data.SetAddressByteSize(8);
-            can_parse = true;
-            is_64_bit = true;
-            break;
-            
-        case MH_CIGAM:
-            data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
-            data.SetAddressByteSize(4);
-            can_parse = true;
-            break;
-            
-        case MH_CIGAM_64:
-            data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
-            data.SetAddressByteSize(8);
-            is_64_bit = true;
-            can_parse = true;
-            break;
-            
-        default:
-            break;
-    }
-    
-    if (can_parse)
-    {
-        data.GetU32(data_offset_ptr, &header.cputype, 6);
-        if (is_64_bit)
-            *data_offset_ptr += 4;
+    lldb::offset_t offset = 0;
+    m_data.SetByteOrder(endian::InlHostByteOrder());
+    // Leave magic in the original byte order
+    m_header.magic = m_data.GetU32(&offset);
+    switch (m_header.magic) {
+    case MH_MAGIC:
+      m_data.SetByteOrder(endian::InlHostByteOrder());
+      m_data.SetAddressByteSize(4);
+      can_parse = true;
+      break;
+
+    case MH_MAGIC_64:
+      m_data.SetByteOrder(endian::InlHostByteOrder());
+      m_data.SetAddressByteSize(8);
+      can_parse = true;
+      break;
+
+    case MH_CIGAM:
+      m_data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig
+                              ? eByteOrderLittle
+                              : eByteOrderBig);
+      m_data.SetAddressByteSize(4);
+      can_parse = true;
+      break;
+
+    case MH_CIGAM_64:
+      m_data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig
+                              ? eByteOrderLittle
+                              : eByteOrderBig);
+      m_data.SetAddressByteSize(8);
+      can_parse = true;
+      break;
+
+    default:
+      break;
+    }
+
+    if (can_parse) {
+      m_data.GetU32(&offset, &m_header.cputype, 6);
+
+      ArchSpec mach_arch;
+
+      if (GetArchitecture(mach_arch)) {
+        // Check if the module has a required architecture
+        const ArchSpec &module_arch = module_sp->GetArchitecture();
+        if (module_arch.IsValid() && !module_arch.IsCompatibleMatch(mach_arch))
+          return false;
+
+        if (SetModulesArchitecture(mach_arch)) {
+          const size_t header_and_lc_size =
+              m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic);
+          if (m_data.GetByteSize() < header_and_lc_size) {
+            DataBufferSP data_sp;
+            ProcessSP process_sp(m_process_wp.lock());
+            if (process_sp) {
+              data_sp =
+                  ReadMemory(process_sp, m_memory_addr, header_and_lc_size);
+            } else {
+              // Read in all only the load command data from the file on disk
+              data_sp =
+                  m_file.ReadFileContents(m_file_offset, header_and_lc_size);
+              if (data_sp->GetByteSize() != header_and_lc_size)
+                return false;
+            }
+            if (data_sp)
+              m_data.SetData(data_sp);
+          }
+        }
         return true;
+      }
+    } else {
+      memset(&m_header, 0, sizeof(struct mach_header));
+    }
+  }
+  return false;
+}
+
+ByteOrder ObjectFileMachO::GetByteOrder() const {
+  return m_data.GetByteOrder();
+}
+
+bool ObjectFileMachO::IsExecutable() const {
+  return m_header.filetype == MH_EXECUTE;
+}
+
+uint32_t ObjectFileMachO::GetAddressByteSize() const {
+  return m_data.GetAddressByteSize();
+}
+
+AddressClass ObjectFileMachO::GetAddressClass(lldb::addr_t file_addr) {
+  Symtab *symtab = GetSymtab();
+  if (symtab) {
+    Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
+    if (symbol) {
+      if (symbol->ValueIsAddress()) {
+        SectionSP section_sp(symbol->GetAddressRef().GetSection());
+        if (section_sp) {
+          const lldb::SectionType section_type = section_sp->GetType();
+          switch (section_type) {
+          case eSectionTypeInvalid:
+            return eAddressClassUnknown;
+
+          case eSectionTypeCode:
+            if (m_header.cputype == llvm::MachO::CPU_TYPE_ARM) {
+              // For ARM we have a bit in the n_desc field of the symbol
+              // that tells us ARM/Thumb which is bit 0x0008.
+              if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
+                return eAddressClassCodeAlternateISA;
+            }
+            return eAddressClassCode;
+
+          case eSectionTypeContainer:
+            return eAddressClassUnknown;
+
+          case eSectionTypeData:
+          case eSectionTypeDataCString:
+          case eSectionTypeDataCStringPointers:
+          case eSectionTypeDataSymbolAddress:
+          case eSectionTypeData4:
+          case eSectionTypeData8:
+          case eSectionTypeData16:
+          case eSectionTypeDataPointers:
+          case eSectionTypeZeroFill:
+          case eSectionTypeDataObjCMessageRefs:
+          case eSectionTypeDataObjCCFStrings:
+          case eSectionTypeGoSymtab:
+            return eAddressClassData;
+
+          case eSectionTypeDebug:
+          case eSectionTypeDWARFDebugAbbrev:
+          case eSectionTypeDWARFDebugAddr:
+          case eSectionTypeDWARFDebugAranges:
+          case eSectionTypeDWARFDebugFrame:
+          case eSectionTypeDWARFDebugInfo:
+          case eSectionTypeDWARFDebugLine:
+          case eSectionTypeDWARFDebugLoc:
+          case eSectionTypeDWARFDebugMacInfo:
+          case eSectionTypeDWARFDebugMacro:
+          case eSectionTypeDWARFDebugPubNames:
+          case eSectionTypeDWARFDebugPubTypes:
+          case eSectionTypeDWARFDebugRanges:
+          case eSectionTypeDWARFDebugStr:
+          case eSectionTypeDWARFDebugStrOffsets:
+          case eSectionTypeDWARFAppleNames:
+          case eSectionTypeDWARFAppleTypes:
+          case eSectionTypeDWARFAppleNamespaces:
+          case eSectionTypeDWARFAppleObjC:
+            return eAddressClassDebug;
+
+          case eSectionTypeEHFrame:
+          case eSectionTypeARMexidx:
+          case eSectionTypeARMextab:
+          case eSectionTypeCompactUnwind:
+            return eAddressClassRuntime;
+
+          case eSectionTypeAbsoluteAddress:
+          case eSectionTypeELFSymbolTable:
+          case eSectionTypeELFDynamicSymbols:
+          case eSectionTypeELFRelocationEntries:
+          case eSectionTypeELFDynamicLinkInfo:
+          case eSectionTypeOther:
+            return eAddressClassUnknown;
+          }
+        }
+      }
+
+      const SymbolType symbol_type = symbol->GetType();
+      switch (symbol_type) {
+      case eSymbolTypeAny:
+        return eAddressClassUnknown;
+      case eSymbolTypeAbsolute:
+        return eAddressClassUnknown;
+
+      case eSymbolTypeCode:
+      case eSymbolTypeTrampoline:
+      case eSymbolTypeResolver:
+        if (m_header.cputype == llvm::MachO::CPU_TYPE_ARM) {
+          // For ARM we have a bit in the n_desc field of the symbol
+          // that tells us ARM/Thumb which is bit 0x0008.
+          if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
+            return eAddressClassCodeAlternateISA;
+        }
+        return eAddressClassCode;
+
+      case eSymbolTypeData:
+        return eAddressClassData;
+      case eSymbolTypeRuntime:
+        return eAddressClassRuntime;
+      case eSymbolTypeException:
+        return eAddressClassRuntime;
+      case eSymbolTypeSourceFile:
+        return eAddressClassDebug;
+      case eSymbolTypeHeaderFile:
+        return eAddressClassDebug;
+      case eSymbolTypeObjectFile:
+        return eAddressClassDebug;
+      case eSymbolTypeCommonBlock:
+        return eAddressClassDebug;
+      case eSymbolTypeBlock:
+        return eAddressClassDebug;
+      case eSymbolTypeLocal:
+        return eAddressClassData;
+      case eSymbolTypeParam:
+        return eAddressClassData;
+      case eSymbolTypeVariable:
+        return eAddressClassData;
+      case eSymbolTypeVariableType:
+        return eAddressClassDebug;
+      case eSymbolTypeLineEntry:
+        return eAddressClassDebug;
+      case eSymbolTypeLineHeader:
+        return eAddressClassDebug;
+      case eSymbolTypeScopeBegin:
+        return eAddressClassDebug;
+      case eSymbolTypeScopeEnd:
+        return eAddressClassDebug;
+      case eSymbolTypeAdditional:
+        return eAddressClassUnknown;
+      case eSymbolTypeCompiler:
+        return eAddressClassDebug;
+      case eSymbolTypeInstrumentation:
+        return eAddressClassDebug;
+      case eSymbolTypeUndefined:
+        return eAddressClassUnknown;
+      case eSymbolTypeObjCClass:
+        return eAddressClassRuntime;
+      case eSymbolTypeObjCMetaClass:
+        return eAddressClassRuntime;
+      case eSymbolTypeObjCIVar:
+        return eAddressClassRuntime;
+      case eSymbolTypeReExported:
+        return eAddressClassRuntime;
+      }
+    }
+  }
+  return eAddressClassUnknown;
+}
+
+Symtab *ObjectFileMachO::GetSymtab() {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    if (m_symtab_ap.get() == NULL) {
+      m_symtab_ap.reset(new Symtab(this));
+      std::lock_guard<std::recursive_mutex> symtab_guard(
+          m_symtab_ap->GetMutex());
+      ParseSymtab();
+      m_symtab_ap->Finalize();
     }
-    else
-    {
-        memset(&header, 0, sizeof(header));
-    }
-    return false;
+  }
+  return m_symtab_ap.get();
 }
 
-bool
-ObjectFileMachO::ParseHeader ()
-{
+bool ObjectFileMachO::IsStripped() {
+  if (m_dysymtab.cmd == 0) {
     ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        bool can_parse = false;
-        lldb::offset_t offset = 0;
-        m_data.SetByteOrder (endian::InlHostByteOrder());
-        // Leave magic in the original byte order
-        m_header.magic = m_data.GetU32(&offset);
-        switch (m_header.magic)
-        {
-        case MH_MAGIC:
-            m_data.SetByteOrder (endian::InlHostByteOrder());
-            m_data.SetAddressByteSize(4);
-            can_parse = true;
-            break;
-
-        case MH_MAGIC_64:
-            m_data.SetByteOrder (endian::InlHostByteOrder());
-            m_data.SetAddressByteSize(8);
-            can_parse = true;
-            break;
-
-        case MH_CIGAM:
-            m_data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
-            m_data.SetAddressByteSize(4);
-            can_parse = true;
-            break;
-
-        case MH_CIGAM_64:
-            m_data.SetByteOrder(endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
-            m_data.SetAddressByteSize(8);
-            can_parse = true;
-            break;
+    if (module_sp) {
+      lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+      for (uint32_t i = 0; i < m_header.ncmds; ++i) {
+        const lldb::offset_t load_cmd_offset = offset;
+
+        load_command lc;
+        if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
+          break;
+        if (lc.cmd == LC_DYSYMTAB) {
+          m_dysymtab.cmd = lc.cmd;
+          m_dysymtab.cmdsize = lc.cmdsize;
+          if (m_data.GetU32(&offset, &m_dysymtab.ilocalsym,
+                            (sizeof(m_dysymtab) / sizeof(uint32_t)) - 2) ==
+              NULL) {
+            // Clear m_dysymtab if we were unable to read all items from the
+            // load command
+            ::memset(&m_dysymtab, 0, sizeof(m_dysymtab));
+          }
+        }
+        offset = load_cmd_offset + lc.cmdsize;
+      }
+    }
+  }
+  if (m_dysymtab.cmd)
+    return m_dysymtab.nlocalsym <= 1;
+  return false;
+}
+
+void ObjectFileMachO::CreateSections(SectionList &unified_section_list) {
+  if (!m_sections_ap.get()) {
+    m_sections_ap.reset(new SectionList());
+
+    const bool is_dsym = (m_header.filetype == MH_DSYM);
+    lldb::user_id_t segID = 0;
+    lldb::user_id_t sectID = 0;
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    uint32_t i;
+    const bool is_core = GetType() == eTypeCoreFile;
+    // bool dump_sections = false;
+    ModuleSP module_sp(GetModule());
+    // First look up any LC_ENCRYPTION_INFO load commands
+    typedef RangeArray<uint32_t, uint32_t, 8> EncryptedFileRanges;
+    EncryptedFileRanges encrypted_file_ranges;
+    encryption_info_command encryption_cmd;
+    for (i = 0; i < m_header.ncmds; ++i) {
+      const lldb::offset_t load_cmd_offset = offset;
+      if (m_data.GetU32(&offset, &encryption_cmd, 2) == NULL)
+        break;
+
+      // LC_ENCRYPTION_INFO and LC_ENCRYPTION_INFO_64 have the same sizes for
+      // the 3 fields we care about, so treat them the same.
+      if (encryption_cmd.cmd == LC_ENCRYPTION_INFO ||
+          encryption_cmd.cmd == LC_ENCRYPTION_INFO_64) {
+        if (m_data.GetU32(&offset, &encryption_cmd.cryptoff, 3)) {
+          if (encryption_cmd.cryptid != 0) {
+            EncryptedFileRanges::Entry entry;
+            entry.SetRangeBase(encryption_cmd.cryptoff);
+            entry.SetByteSize(encryption_cmd.cryptsize);
+            encrypted_file_ranges.Append(entry);
+          }
+        }
+      }
+      offset = load_cmd_offset + encryption_cmd.cmdsize;
+    }
+
+    bool section_file_addresses_changed = false;
+
+    offset = MachHeaderSizeFromMagic(m_header.magic);
+
+    struct segment_command_64 load_cmd;
+    for (i = 0; i < m_header.ncmds; ++i) {
+      const lldb::offset_t load_cmd_offset = offset;
+      if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+        break;
+
+      if (load_cmd.cmd == LC_SEGMENT || load_cmd.cmd == LC_SEGMENT_64) {
+        if (m_data.GetU8(&offset, (uint8_t *)load_cmd.segname, 16)) {
+          bool add_section = true;
+          bool add_to_unified = true;
+          ConstString const_segname(load_cmd.segname,
+                                    std::min<size_t>(strlen(load_cmd.segname),
+                                                     sizeof(load_cmd.segname)));
+
+          SectionSP unified_section_sp(
+              unified_section_list.FindSectionByName(const_segname));
+          if (is_dsym && unified_section_sp) {
+            if (const_segname == GetSegmentNameLINKEDIT()) {
+              // We need to keep the __LINKEDIT segment private to this object
+              // file only
+              add_to_unified = false;
+            } else {
+              // This is the dSYM file and this section has already been created
+              // by
+              // the object file, no need to create it.
+              add_section = false;
+            }
+          }
+          load_cmd.vmaddr = m_data.GetAddress(&offset);
+          load_cmd.vmsize = m_data.GetAddress(&offset);
+          load_cmd.fileoff = m_data.GetAddress(&offset);
+          load_cmd.filesize = m_data.GetAddress(&offset);
+          if (m_length != 0 && load_cmd.filesize != 0) {
+            if (load_cmd.fileoff > m_length) {
+              // We have a load command that says it extends past the end of the
+              // file.  This is likely
+              // a corrupt file.  We don't have any way to return an error
+              // condition here (this method
+              // was likely invoked from something like
+              // ObjectFile::GetSectionList()) -- all we can do
+              // is null out the SectionList vector and if a process has been
+              // set up, dump a message
+              // to stdout.  The most common case here is core file debugging
+              // with a truncated file.
+              const char *lc_segment_name = load_cmd.cmd == LC_SEGMENT_64
+                                                ? "LC_SEGMENT_64"
+                                                : "LC_SEGMENT";
+              module_sp->ReportWarning(
+                  "load command %u %s has a fileoff (0x%" PRIx64
+                  ") that extends beyond the end of the file (0x%" PRIx64
+                  "), ignoring this section",
+                  i, lc_segment_name, load_cmd.fileoff, m_length);
+
+              load_cmd.fileoff = 0;
+              load_cmd.filesize = 0;
+            }
+
+            if (load_cmd.fileoff + load_cmd.filesize > m_length) {
+              // We have a load command that says it extends past the end of the
+              // file.  This is likely
+              // a corrupt file.  We don't have any way to return an error
+              // condition here (this method
+              // was likely invoked from something like
+              // ObjectFile::GetSectionList()) -- all we can do
+              // is null out the SectionList vector and if a process has been
+              // set up, dump a message
+              // to stdout.  The most common case here is core file debugging
+              // with a truncated file.
+              const char *lc_segment_name = load_cmd.cmd == LC_SEGMENT_64
+                                                ? "LC_SEGMENT_64"
+                                                : "LC_SEGMENT";
+              GetModule()->ReportWarning(
+                  "load command %u %s has a fileoff + filesize (0x%" PRIx64
+                  ") that extends beyond the end of the file (0x%" PRIx64
+                  "), the segment will be truncated to match",
+                  i, lc_segment_name, load_cmd.fileoff + load_cmd.filesize,
+                  m_length);
+
+              // Tuncase the length
+              load_cmd.filesize = m_length - load_cmd.fileoff;
+            }
+          }
+          if (m_data.GetU32(&offset, &load_cmd.maxprot, 4)) {
+            const uint32_t segment_permissions =
+                ((load_cmd.initprot & VM_PROT_READ) ? ePermissionsReadable
+                                                    : 0) |
+                ((load_cmd.initprot & VM_PROT_WRITE) ? ePermissionsWritable
+                                                     : 0) |
+                ((load_cmd.initprot & VM_PROT_EXECUTE) ? ePermissionsExecutable
+                                                       : 0);
+
+            const bool segment_is_encrypted =
+                (load_cmd.flags & SG_PROTECTED_VERSION_1) != 0;
+
+            // Keep a list of mach segments around in case we need to
+            // get at data that isn't stored in the abstracted Sections.
+            m_mach_segments.push_back(load_cmd);
+
+            // Use a segment ID of the segment index shifted left by 8 so they
+            // never conflict with any of the sections.
+            SectionSP segment_sp;
+            if (add_section && (const_segname || is_core)) {
+              segment_sp.reset(new Section(
+                  module_sp,     // Module to which this section belongs
+                  this,          // Object file to which this sections belongs
+                  ++segID << 8,  // Section ID is the 1 based segment index
+                                 // shifted right by 8 bits as not to collide
+                                 // with any of the 256 section IDs that are
+                                 // possible
+                  const_segname, // Name of this section
+                  eSectionTypeContainer, // This section is a container of other
+                                         // sections.
+                  load_cmd.vmaddr,   // File VM address == addresses as they are
+                                     // found in the object file
+                  load_cmd.vmsize,   // VM size in bytes of this section
+                  load_cmd.fileoff,  // Offset to the data for this section in
+                                     // the file
+                  load_cmd.filesize, // Size in bytes of this section as found
+                                     // in the file
+                  0,                 // Segments have no alignment information
+                  load_cmd.flags));  // Flags for this section
+
+              segment_sp->SetIsEncrypted(segment_is_encrypted);
+              m_sections_ap->AddSection(segment_sp);
+              segment_sp->SetPermissions(segment_permissions);
+              if (add_to_unified)
+                unified_section_list.AddSection(segment_sp);
+            } else if (unified_section_sp) {
+              if (is_dsym &&
+                  unified_section_sp->GetFileAddress() != load_cmd.vmaddr) {
+                // Check to see if the module was read from memory?
+                if (module_sp->GetObjectFile()->GetHeaderAddress().IsValid()) {
+                  // We have a module that is in memory and needs to have its
+                  // file address adjusted. We need to do this because when we
+                  // load a file from memory, its addresses will be slid
+                  // already,
+                  // yet the addresses in the new symbol file will still be
+                  // unslid.
+                  // Since everything is stored as section offset, this
+                  // shouldn't
+                  // cause any problems.
+
+                  // Make sure we've parsed the symbol table from the
+                  // ObjectFile before we go around changing its Sections.
+                  module_sp->GetObjectFile()->GetSymtab();
+                  // eh_frame would present the same problems but we parse that
+                  // on
+                  // a per-function basis as-needed so it's more difficult to
+                  // remove its use of the Sections.  Realistically, the
+                  // environments
+                  // where this code path will be taken will not have eh_frame
+                  // sections.
+
+                  unified_section_sp->SetFileAddress(load_cmd.vmaddr);
+
+                  // Notify the module that the section addresses have been
+                  // changed once
+                  // we're done so any file-address caches can be updated.
+                  section_file_addresses_changed = true;
+                }
+              }
+              m_sections_ap->AddSection(unified_section_sp);
+            }
+
+            struct section_64 sect64;
+            ::memset(&sect64, 0, sizeof(sect64));
+            // Push a section into our mach sections for the section at
+            // index zero (NO_SECT) if we don't have any mach sections yet...
+            if (m_mach_sections.empty())
+              m_mach_sections.push_back(sect64);
+            uint32_t segment_sect_idx;
+            const lldb::user_id_t first_segment_sectID = sectID + 1;
+
+            const uint32_t num_u32s = load_cmd.cmd == LC_SEGMENT ? 7 : 8;
+            for (segment_sect_idx = 0; segment_sect_idx < load_cmd.nsects;
+                 ++segment_sect_idx) {
+              if (m_data.GetU8(&offset, (uint8_t *)sect64.sectname,
+                               sizeof(sect64.sectname)) == NULL)
+                break;
+              if (m_data.GetU8(&offset, (uint8_t *)sect64.segname,
+                               sizeof(sect64.segname)) == NULL)
+                break;
+              sect64.addr = m_data.GetAddress(&offset);
+              sect64.size = m_data.GetAddress(&offset);
 
-        default:
-            break;
-        }
+              if (m_data.GetU32(&offset, &sect64.offset, num_u32s) == NULL)
+                break;
 
-        if (can_parse)
-        {
-            m_data.GetU32(&offset, &m_header.cputype, 6);
-
-            
-            ArchSpec mach_arch;
-            
-            if (GetArchitecture (mach_arch))
-            {
-                // Check if the module has a required architecture
-                const ArchSpec &module_arch = module_sp->GetArchitecture();
-                if (module_arch.IsValid() && !module_arch.IsCompatibleMatch(mach_arch))
-                    return false;
-
-                if (SetModulesArchitecture (mach_arch))
-                {
-                    const size_t header_and_lc_size = m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic);
-                    if (m_data.GetByteSize() < header_and_lc_size)
-                    {
-                        DataBufferSP data_sp;
-                        ProcessSP process_sp (m_process_wp.lock());
-                        if (process_sp)
-                        {
-                            data_sp = ReadMemory (process_sp, m_memory_addr, header_and_lc_size);
-                        }
-                        else
-                        {
-                            // Read in all only the load command data from the file on disk
-                            data_sp = m_file.ReadFileContents(m_file_offset, header_and_lc_size);
-                            if (data_sp->GetByteSize() != header_and_lc_size)
-                                return false;
-                        }
-                        if (data_sp)
-                            m_data.SetData (data_sp);
+              // Keep a list of mach sections around in case we need to
+              // get at data that isn't stored in the abstracted Sections.
+              m_mach_sections.push_back(sect64);
+
+              if (add_section) {
+                ConstString section_name(
+                    sect64.sectname, std::min<size_t>(strlen(sect64.sectname),
+                                                      sizeof(sect64.sectname)));
+                if (!const_segname) {
+                  // We have a segment with no name so we need to conjure up
+                  // segments that correspond to the section's segname if there
+                  // isn't already such a section. If there is such a section,
+                  // we resize the section so that it spans all sections.
+                  // We also mark these sections as fake so address matches
+                  // don't
+                  // hit if they land in the gaps between the child sections.
+                  const_segname.SetTrimmedCStringWithLength(
+                      sect64.segname, sizeof(sect64.segname));
+                  segment_sp =
+                      unified_section_list.FindSectionByName(const_segname);
+                  if (segment_sp.get()) {
+                    Section *segment = segment_sp.get();
+                    // Grow the section size as needed.
+                    const lldb::addr_t sect64_min_addr = sect64.addr;
+                    const lldb::addr_t sect64_max_addr =
+                        sect64_min_addr + sect64.size;
+                    const lldb::addr_t curr_seg_byte_size =
+                        segment->GetByteSize();
+                    const lldb::addr_t curr_seg_min_addr =
+                        segment->GetFileAddress();
+                    const lldb::addr_t curr_seg_max_addr =
+                        curr_seg_min_addr + curr_seg_byte_size;
+                    if (sect64_min_addr >= curr_seg_min_addr) {
+                      const lldb::addr_t new_seg_byte_size =
+                          sect64_max_addr - curr_seg_min_addr;
+                      // Only grow the section size if needed
+                      if (new_seg_byte_size > curr_seg_byte_size)
+                        segment->SetByteSize(new_seg_byte_size);
+                    } else {
+                      // We need to change the base address of the segment and
+                      // adjust the child section offsets for all existing
+                      // children.
+                      const lldb::addr_t slide_amount =
+                          sect64_min_addr - curr_seg_min_addr;
+                      segment->Slide(slide_amount, false);
+                      segment->GetChildren().Slide(-slide_amount, false);
+                      segment->SetByteSize(curr_seg_max_addr - sect64_min_addr);
+                    }
+
+                    // Grow the section size as needed.
+                    if (sect64.offset) {
+                      const lldb::addr_t segment_min_file_offset =
+                          segment->GetFileOffset();
+                      const lldb::addr_t segment_max_file_offset =
+                          segment_min_file_offset + segment->GetFileSize();
+
+                      const lldb::addr_t section_min_file_offset =
+                          sect64.offset;
+                      const lldb::addr_t section_max_file_offset =
+                          section_min_file_offset + sect64.size;
+                      const lldb::addr_t new_file_offset = std::min(
+                          section_min_file_offset, segment_min_file_offset);
+                      const lldb::addr_t new_file_size =
+                          std::max(section_max_file_offset,
+                                   segment_max_file_offset) -
+                          new_file_offset;
+                      segment->SetFileOffset(new_file_offset);
+                      segment->SetFileSize(new_file_size);
+                    }
+                  } else {
+                    // Create a fake section for the section's named segment
+                    segment_sp.reset(new Section(
+                        segment_sp, // Parent section
+                        module_sp,  // Module to which this section belongs
+                        this,       // Object file to which this section belongs
+                        ++segID << 8, // Section ID is the 1 based segment index
+                                      // shifted right by 8 bits as not to
+                                      // collide with any of the 256 section IDs
+                                      // that are possible
+                        const_segname,         // Name of this section
+                        eSectionTypeContainer, // This section is a container of
+                                               // other sections.
+                        sect64.addr, // File VM address == addresses as they are
+                                     // found in the object file
+                        sect64.size, // VM size in bytes of this section
+                        sect64.offset, // Offset to the data for this section in
+                                       // the file
+                        sect64.offset ? sect64.size : 0, // Size in bytes of
+                                                         // this section as
+                                                         // found in the file
+                        sect64.align,
+                        load_cmd.flags)); // Flags for this section
+                    segment_sp->SetIsFake(true);
+                    segment_sp->SetPermissions(segment_permissions);
+                    m_sections_ap->AddSection(segment_sp);
+                    if (add_to_unified)
+                      unified_section_list.AddSection(segment_sp);
+                    segment_sp->SetIsEncrypted(segment_is_encrypted);
+                  }
+                }
+                assert(segment_sp.get());
+
+                lldb::SectionType sect_type = eSectionTypeOther;
+
+                if (sect64.flags &
+                    (S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS))
+                  sect_type = eSectionTypeCode;
+                else {
+                  uint32_t mach_sect_type = sect64.flags & SECTION_TYPE;
+                  static ConstString g_sect_name_objc_data("__objc_data");
+                  static ConstString g_sect_name_objc_msgrefs("__objc_msgrefs");
+                  static ConstString g_sect_name_objc_selrefs("__objc_selrefs");
+                  static ConstString g_sect_name_objc_classrefs(
+                      "__objc_classrefs");
+                  static ConstString g_sect_name_objc_superrefs(
+                      "__objc_superrefs");
+                  static ConstString g_sect_name_objc_const("__objc_const");
+                  static ConstString g_sect_name_objc_classlist(
+                      "__objc_classlist");
+                  static ConstString g_sect_name_cfstring("__cfstring");
+
+                  static ConstString g_sect_name_dwarf_debug_abbrev(
+                      "__debug_abbrev");
+                  static ConstString g_sect_name_dwarf_debug_aranges(
+                      "__debug_aranges");
+                  static ConstString g_sect_name_dwarf_debug_frame(
+                      "__debug_frame");
+                  static ConstString g_sect_name_dwarf_debug_info(
+                      "__debug_info");
+                  static ConstString g_sect_name_dwarf_debug_line(
+                      "__debug_line");
+                  static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
+                  static ConstString g_sect_name_dwarf_debug_macinfo(
+                      "__debug_macinfo");
+                  static ConstString g_sect_name_dwarf_debug_pubnames(
+                      "__debug_pubnames");
+                  static ConstString g_sect_name_dwarf_debug_pubtypes(
+                      "__debug_pubtypes");
+                  static ConstString g_sect_name_dwarf_debug_ranges(
+                      "__debug_ranges");
+                  static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+                  static ConstString g_sect_name_dwarf_apple_names(
+                      "__apple_names");
+                  static ConstString g_sect_name_dwarf_apple_types(
+                      "__apple_types");
+                  static ConstString g_sect_name_dwarf_apple_namespaces(
+                      "__apple_namespac");
+                  static ConstString g_sect_name_dwarf_apple_objc(
+                      "__apple_objc");
+                  static ConstString g_sect_name_eh_frame("__eh_frame");
+                  static ConstString g_sect_name_compact_unwind(
+                      "__unwind_info");
+                  static ConstString g_sect_name_text("__text");
+                  static ConstString g_sect_name_data("__data");
+                  static ConstString g_sect_name_go_symtab("__gosymtab");
+
+                  if (section_name == g_sect_name_dwarf_debug_abbrev)
+                    sect_type = eSectionTypeDWARFDebugAbbrev;
+                  else if (section_name == g_sect_name_dwarf_debug_aranges)
+                    sect_type = eSectionTypeDWARFDebugAranges;
+                  else if (section_name == g_sect_name_dwarf_debug_frame)
+                    sect_type = eSectionTypeDWARFDebugFrame;
+                  else if (section_name == g_sect_name_dwarf_debug_info)
+                    sect_type = eSectionTypeDWARFDebugInfo;
+                  else if (section_name == g_sect_name_dwarf_debug_line)
+                    sect_type = eSectionTypeDWARFDebugLine;
+                  else if (section_name == g_sect_name_dwarf_debug_loc)
+                    sect_type = eSectionTypeDWARFDebugLoc;
+                  else if (section_name == g_sect_name_dwarf_debug_macinfo)
+                    sect_type = eSectionTypeDWARFDebugMacInfo;
+                  else if (section_name == g_sect_name_dwarf_debug_pubnames)
+                    sect_type = eSectionTypeDWARFDebugPubNames;
+                  else if (section_name == g_sect_name_dwarf_debug_pubtypes)
+                    sect_type = eSectionTypeDWARFDebugPubTypes;
+                  else if (section_name == g_sect_name_dwarf_debug_ranges)
+                    sect_type = eSectionTypeDWARFDebugRanges;
+                  else if (section_name == g_sect_name_dwarf_debug_str)
+                    sect_type = eSectionTypeDWARFDebugStr;
+                  else if (section_name == g_sect_name_dwarf_apple_names)
+                    sect_type = eSectionTypeDWARFAppleNames;
+                  else if (section_name == g_sect_name_dwarf_apple_types)
+                    sect_type = eSectionTypeDWARFAppleTypes;
+                  else if (section_name == g_sect_name_dwarf_apple_namespaces)
+                    sect_type = eSectionTypeDWARFAppleNamespaces;
+                  else if (section_name == g_sect_name_dwarf_apple_objc)
+                    sect_type = eSectionTypeDWARFAppleObjC;
+                  else if (section_name == g_sect_name_objc_selrefs)
+                    sect_type = eSectionTypeDataCStringPointers;
+                  else if (section_name == g_sect_name_objc_msgrefs)
+                    sect_type = eSectionTypeDataObjCMessageRefs;
+                  else if (section_name == g_sect_name_eh_frame)
+                    sect_type = eSectionTypeEHFrame;
+                  else if (section_name == g_sect_name_compact_unwind)
+                    sect_type = eSectionTypeCompactUnwind;
+                  else if (section_name == g_sect_name_cfstring)
+                    sect_type = eSectionTypeDataObjCCFStrings;
+                  else if (section_name == g_sect_name_go_symtab)
+                    sect_type = eSectionTypeGoSymtab;
+                  else if (section_name == g_sect_name_objc_data ||
+                           section_name == g_sect_name_objc_classrefs ||
+                           section_name == g_sect_name_objc_superrefs ||
+                           section_name == g_sect_name_objc_const ||
+                           section_name == g_sect_name_objc_classlist) {
+                    sect_type = eSectionTypeDataPointers;
+                  }
+
+                  if (sect_type == eSectionTypeOther) {
+                    switch (mach_sect_type) {
+                    // TODO: categorize sections by other flags for regular
+                    // sections
+                    case S_REGULAR:
+                      if (section_name == g_sect_name_text)
+                        sect_type = eSectionTypeCode;
+                      else if (section_name == g_sect_name_data)
+                        sect_type = eSectionTypeData;
+                      else
+                        sect_type = eSectionTypeOther;
+                      break;
+                    case S_ZEROFILL:
+                      sect_type = eSectionTypeZeroFill;
+                      break;
+                    case S_CSTRING_LITERALS:
+                      sect_type = eSectionTypeDataCString;
+                      break; // section with only literal C strings
+                    case S_4BYTE_LITERALS:
+                      sect_type = eSectionTypeData4;
+                      break; // section with only 4 byte literals
+                    case S_8BYTE_LITERALS:
+                      sect_type = eSectionTypeData8;
+                      break; // section with only 8 byte literals
+                    case S_LITERAL_POINTERS:
+                      sect_type = eSectionTypeDataPointers;
+                      break; // section with only pointers to literals
+                    case S_NON_LAZY_SYMBOL_POINTERS:
+                      sect_type = eSectionTypeDataPointers;
+                      break; // section with only non-lazy symbol pointers
+                    case S_LAZY_SYMBOL_POINTERS:
+                      sect_type = eSectionTypeDataPointers;
+                      break; // section with only lazy symbol pointers
+                    case S_SYMBOL_STUBS:
+                      sect_type = eSectionTypeCode;
+                      break; // section with only symbol stubs, byte size of
+                             // stub in the reserved2 field
+                    case S_MOD_INIT_FUNC_POINTERS:
+                      sect_type = eSectionTypeDataPointers;
+                      break; // section with only function pointers for
+                             // initialization
+                    case S_MOD_TERM_FUNC_POINTERS:
+                      sect_type = eSectionTypeDataPointers;
+                      break; // section with only function pointers for
+                             // termination
+                    case S_COALESCED:
+                      sect_type = eSectionTypeOther;
+                      break;
+                    case S_GB_ZEROFILL:
+                      sect_type = eSectionTypeZeroFill;
+                      break;
+                    case S_INTERPOSING:
+                      sect_type = eSectionTypeCode;
+                      break; // section with only pairs of function pointers for
+                             // interposing
+                    case S_16BYTE_LITERALS:
+                      sect_type = eSectionTypeData16;
+                      break; // section with only 16 byte literals
+                    case S_DTRACE_DOF:
+                      sect_type = eSectionTypeDebug;
+                      break;
+                    case S_LAZY_DYLIB_SYMBOL_POINTERS:
+                      sect_type = eSectionTypeDataPointers;
+                      break;
+                    default:
+                      break;
                     }
+                  }
                 }
-                return true;
-            }
-        }
-        else
-        {
-            memset(&m_header, 0, sizeof(struct mach_header));
-        }
-    }
-    return false;
-}
 
-ByteOrder
-ObjectFileMachO::GetByteOrder () const
-{
-    return m_data.GetByteOrder ();
-}
-
-bool
-ObjectFileMachO::IsExecutable() const
-{
-    return m_header.filetype == MH_EXECUTE;
-}
-
-uint32_t
-ObjectFileMachO::GetAddressByteSize () const
-{
-    return m_data.GetAddressByteSize ();
-}
-
-AddressClass
-ObjectFileMachO::GetAddressClass (lldb::addr_t file_addr)
-{
-    Symtab *symtab = GetSymtab();
-    if (symtab)
-    {
-        Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
-        if (symbol)
-        {
-            if (symbol->ValueIsAddress())
-            {
-                SectionSP section_sp (symbol->GetAddressRef().GetSection());
-                if (section_sp)
-                {
-                    const lldb::SectionType section_type = section_sp->GetType();
-                    switch (section_type)
-                    {
-                    case eSectionTypeInvalid:
-                        return eAddressClassUnknown;
+                SectionSP section_sp(new Section(
+                    segment_sp, module_sp, this, ++sectID, section_name,
+                    sect_type, sect64.addr - segment_sp->GetFileAddress(),
+                    sect64.size, sect64.offset,
+                    sect64.offset == 0 ? 0 : sect64.size, sect64.align,
+                    sect64.flags));
+                // Set the section to be encrypted to match the segment
 
-                    case eSectionTypeCode:
-                        if (m_header.cputype == llvm::MachO::CPU_TYPE_ARM)
-                        {
-                            // For ARM we have a bit in the n_desc field of the symbol
-                            // that tells us ARM/Thumb which is bit 0x0008.
-                            if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
-                                return eAddressClassCodeAlternateISA;
-                        }
-                        return eAddressClassCode;
+                bool section_is_encrypted = false;
+                if (!segment_is_encrypted && load_cmd.filesize != 0)
+                  section_is_encrypted =
+                      encrypted_file_ranges.FindEntryThatContains(
+                          sect64.offset) != NULL;
 
-                    case eSectionTypeContainer:
-                        return eAddressClassUnknown;
+                section_sp->SetIsEncrypted(segment_is_encrypted ||
+                                           section_is_encrypted);
+                section_sp->SetPermissions(segment_permissions);
+                segment_sp->GetChildren().AddSection(section_sp);
 
-                    case eSectionTypeData:
-                    case eSectionTypeDataCString:
-                    case eSectionTypeDataCStringPointers:
-                    case eSectionTypeDataSymbolAddress:
-                    case eSectionTypeData4:
-                    case eSectionTypeData8:
-                    case eSectionTypeData16:
-                    case eSectionTypeDataPointers:
-                    case eSectionTypeZeroFill:
-                    case eSectionTypeDataObjCMessageRefs:
-                    case eSectionTypeDataObjCCFStrings:
-                    case eSectionTypeGoSymtab:
-                        return eAddressClassData;
-
-                    case eSectionTypeDebug:
-                    case eSectionTypeDWARFDebugAbbrev:
-                    case eSectionTypeDWARFDebugAddr:
-                    case eSectionTypeDWARFDebugAranges:
-                    case eSectionTypeDWARFDebugFrame:
-                    case eSectionTypeDWARFDebugInfo:
-                    case eSectionTypeDWARFDebugLine:
-                    case eSectionTypeDWARFDebugLoc:
-                    case eSectionTypeDWARFDebugMacInfo:
-                    case eSectionTypeDWARFDebugMacro:
-                    case eSectionTypeDWARFDebugPubNames:
-                    case eSectionTypeDWARFDebugPubTypes:
-                    case eSectionTypeDWARFDebugRanges:
-                    case eSectionTypeDWARFDebugStr:
-                    case eSectionTypeDWARFDebugStrOffsets:
-                    case eSectionTypeDWARFAppleNames:
-                    case eSectionTypeDWARFAppleTypes:
-                    case eSectionTypeDWARFAppleNamespaces:
-                    case eSectionTypeDWARFAppleObjC:
-                        return eAddressClassDebug;
-
-                    case eSectionTypeEHFrame:
-                    case eSectionTypeARMexidx:
-                    case eSectionTypeARMextab:
-                    case eSectionTypeCompactUnwind:
-                        return eAddressClassRuntime;
-
-                    case eSectionTypeAbsoluteAddress:
-                    case eSectionTypeELFSymbolTable:
-                    case eSectionTypeELFDynamicSymbols:
-                    case eSectionTypeELFRelocationEntries:
-                    case eSectionTypeELFDynamicLinkInfo:
-                    case eSectionTypeOther:
-                        return eAddressClassUnknown;
-                    }
+                if (segment_sp->IsFake()) {
+                  segment_sp.reset();
+                  const_segname.Clear();
                 }
+              }
             }
+            if (segment_sp && is_dsym) {
+              if (first_segment_sectID <= sectID) {
+                lldb::user_id_t sect_uid;
+                for (sect_uid = first_segment_sectID; sect_uid <= sectID;
+                     ++sect_uid) {
+                  SectionSP curr_section_sp(
+                      segment_sp->GetChildren().FindSectionByID(sect_uid));
+                  SectionSP next_section_sp;
+                  if (sect_uid + 1 <= sectID)
+                    next_section_sp =
+                        segment_sp->GetChildren().FindSectionByID(sect_uid + 1);
 
-            const SymbolType symbol_type = symbol->GetType();
-            switch (symbol_type)
-            {
-            case eSymbolTypeAny:            return eAddressClassUnknown;
-            case eSymbolTypeAbsolute:       return eAddressClassUnknown;
-
-            case eSymbolTypeCode:
-            case eSymbolTypeTrampoline:
-            case eSymbolTypeResolver:
-                if (m_header.cputype == llvm::MachO::CPU_TYPE_ARM)
-                {
-                    // For ARM we have a bit in the n_desc field of the symbol
-                    // that tells us ARM/Thumb which is bit 0x0008.
-                    if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
-                        return eAddressClassCodeAlternateISA;
+                  if (curr_section_sp.get()) {
+                    if (curr_section_sp->GetByteSize() == 0) {
+                      if (next_section_sp.get() != NULL)
+                        curr_section_sp->SetByteSize(
+                            next_section_sp->GetFileAddress() -
+                            curr_section_sp->GetFileAddress());
+                      else
+                        curr_section_sp->SetByteSize(load_cmd.vmsize);
+                    }
+                  }
                 }
-                return eAddressClassCode;
-
-            case eSymbolTypeData:           return eAddressClassData;
-            case eSymbolTypeRuntime:        return eAddressClassRuntime;
-            case eSymbolTypeException:      return eAddressClassRuntime;
-            case eSymbolTypeSourceFile:     return eAddressClassDebug;
-            case eSymbolTypeHeaderFile:     return eAddressClassDebug;
-            case eSymbolTypeObjectFile:     return eAddressClassDebug;
-            case eSymbolTypeCommonBlock:    return eAddressClassDebug;
-            case eSymbolTypeBlock:          return eAddressClassDebug;
-            case eSymbolTypeLocal:          return eAddressClassData;
-            case eSymbolTypeParam:          return eAddressClassData;
-            case eSymbolTypeVariable:       return eAddressClassData;
-            case eSymbolTypeVariableType:   return eAddressClassDebug;
-            case eSymbolTypeLineEntry:      return eAddressClassDebug;
-            case eSymbolTypeLineHeader:     return eAddressClassDebug;
-            case eSymbolTypeScopeBegin:     return eAddressClassDebug;
-            case eSymbolTypeScopeEnd:       return eAddressClassDebug;
-            case eSymbolTypeAdditional:     return eAddressClassUnknown;
-            case eSymbolTypeCompiler:       return eAddressClassDebug;
-            case eSymbolTypeInstrumentation:return eAddressClassDebug;
-            case eSymbolTypeUndefined:      return eAddressClassUnknown;
-            case eSymbolTypeObjCClass:      return eAddressClassRuntime;
-            case eSymbolTypeObjCMetaClass:  return eAddressClassRuntime;
-            case eSymbolTypeObjCIVar:       return eAddressClassRuntime;
-            case eSymbolTypeReExported:     return eAddressClassRuntime;
+              }
             }
+          }
         }
+      } else if (load_cmd.cmd == LC_DYSYMTAB) {
+        m_dysymtab.cmd = load_cmd.cmd;
+        m_dysymtab.cmdsize = load_cmd.cmdsize;
+        m_data.GetU32(&offset, &m_dysymtab.ilocalsym,
+                      (sizeof(m_dysymtab) / sizeof(uint32_t)) - 2);
+      }
+
+      offset = load_cmd_offset + load_cmd.cmdsize;
     }
-    return eAddressClassUnknown;
-}
-
-Symtab *
-ObjectFileMachO::GetSymtab()
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        if (m_symtab_ap.get() == NULL)
-        {
-            m_symtab_ap.reset(new Symtab(this));
-            std::lock_guard<std::recursive_mutex> symtab_guard(m_symtab_ap->GetMutex());
-            ParseSymtab ();
-            m_symtab_ap->Finalize ();
-        }
-    }
-    return m_symtab_ap.get();
-}
-
-bool
-ObjectFileMachO::IsStripped ()
-{
-    if (m_dysymtab.cmd == 0)
-    {
-        ModuleSP module_sp(GetModule());
-        if (module_sp)
-        {
-            lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-            for (uint32_t i=0; i<m_header.ncmds; ++i)
-            {
-                const lldb::offset_t load_cmd_offset = offset;
-                
-                load_command lc;
-                if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
-                    break;
-                if (lc.cmd == LC_DYSYMTAB)
-                {
-                    m_dysymtab.cmd = lc.cmd;
-                    m_dysymtab.cmdsize = lc.cmdsize;
-                    if (m_data.GetU32 (&offset, &m_dysymtab.ilocalsym, (sizeof(m_dysymtab) / sizeof(uint32_t)) - 2) == NULL)
-                    {
-                        // Clear m_dysymtab if we were unable to read all items from the load command
-                        ::memset (&m_dysymtab, 0, sizeof(m_dysymtab));
-                    }
-                }
-                offset = load_cmd_offset + lc.cmdsize;
-            }
-        }
+
+    if (section_file_addresses_changed && module_sp.get()) {
+      module_sp->SectionFileAddressesChanged();
     }
-    if (m_dysymtab.cmd)
-        return m_dysymtab.nlocalsym <= 1;
-    return false;
+  }
 }
 
-void
-ObjectFileMachO::CreateSections (SectionList &unified_section_list)
-{
-    if (!m_sections_ap.get())
-    {
-        m_sections_ap.reset(new SectionList());
-        
-        const bool is_dsym = (m_header.filetype == MH_DSYM);
-        lldb::user_id_t segID = 0;
-        lldb::user_id_t sectID = 0;
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        uint32_t i;
-        const bool is_core = GetType() == eTypeCoreFile;
-        //bool dump_sections = false;
-        ModuleSP module_sp (GetModule());
-        // First look up any LC_ENCRYPTION_INFO load commands
-        typedef RangeArray<uint32_t, uint32_t, 8> EncryptedFileRanges;
-        EncryptedFileRanges encrypted_file_ranges;
-        encryption_info_command encryption_cmd;
-        for (i=0; i<m_header.ncmds; ++i)
-        {
-            const lldb::offset_t load_cmd_offset = offset;
-            if (m_data.GetU32(&offset, &encryption_cmd, 2) == NULL)
-                break;
+class MachSymtabSectionInfo {
+public:
+  MachSymtabSectionInfo(SectionList *section_list)
+      : m_section_list(section_list), m_section_infos() {
+    // Get the number of sections down to a depth of 1 to include
+    // all segments and their sections, but no other sections that
+    // may be added for debug map or
+    m_section_infos.resize(section_list->GetNumSections(1));
+  }
+
+  SectionSP GetSection(uint8_t n_sect, addr_t file_addr) {
+    if (n_sect == 0)
+      return SectionSP();
+    if (n_sect < m_section_infos.size()) {
+      if (!m_section_infos[n_sect].section_sp) {
+        SectionSP section_sp(m_section_list->FindSectionByID(n_sect));
+        m_section_infos[n_sect].section_sp = section_sp;
+        if (section_sp) {
+          m_section_infos[n_sect].vm_range.SetBaseAddress(
+              section_sp->GetFileAddress());
+          m_section_infos[n_sect].vm_range.SetByteSize(
+              section_sp->GetByteSize());
+        } else {
+          Host::SystemLog(Host::eSystemLogError,
+                          "error: unable to find section for section %u\n",
+                          n_sect);
+        }
+      }
+      if (m_section_infos[n_sect].vm_range.Contains(file_addr)) {
+        // Symbol is in section.
+        return m_section_infos[n_sect].section_sp;
+      } else if (m_section_infos[n_sect].vm_range.GetByteSize() == 0 &&
+                 m_section_infos[n_sect].vm_range.GetBaseAddress() ==
+                     file_addr) {
+        // Symbol is in section with zero size, but has the same start
+        // address as the section. This can happen with linker symbols
+        // (symbols that start with the letter 'l' or 'L'.
+        return m_section_infos[n_sect].section_sp;
+      }
+    }
+    return m_section_list->FindSectionContainingFileAddress(file_addr);
+  }
 
-            // LC_ENCRYPTION_INFO and LC_ENCRYPTION_INFO_64 have the same sizes for
-            // the 3 fields we care about, so treat them the same.
-            if (encryption_cmd.cmd == LC_ENCRYPTION_INFO || encryption_cmd.cmd == LC_ENCRYPTION_INFO_64)
-            {
-                if (m_data.GetU32(&offset, &encryption_cmd.cryptoff, 3))
-                {
-                    if (encryption_cmd.cryptid != 0)
-                    {
-                        EncryptedFileRanges::Entry entry;
-                        entry.SetRangeBase(encryption_cmd.cryptoff);
-                        entry.SetByteSize(encryption_cmd.cryptsize);
-                        encrypted_file_ranges.Append(entry);
-                    }
-                }
+protected:
+  struct SectionInfo {
+    SectionInfo() : vm_range(), section_sp() {}
+
+    VMRange vm_range;
+    SectionSP section_sp;
+  };
+  SectionList *m_section_list;
+  std::vector<SectionInfo> m_section_infos;
+};
+
+struct TrieEntry {
+  TrieEntry()
+      : name(), address(LLDB_INVALID_ADDRESS), flags(0), other(0),
+        import_name() {}
+
+  void Clear() {
+    name.Clear();
+    address = LLDB_INVALID_ADDRESS;
+    flags = 0;
+    other = 0;
+    import_name.Clear();
+  }
+
+  void Dump() const {
+    printf("0x%16.16llx 0x%16.16llx 0x%16.16llx \"%s\"",
+           static_cast<unsigned long long>(address),
+           static_cast<unsigned long long>(flags),
+           static_cast<unsigned long long>(other), name.GetCString());
+    if (import_name)
+      printf(" -> \"%s\"\n", import_name.GetCString());
+    else
+      printf("\n");
+  }
+  ConstString name;
+  uint64_t address;
+  uint64_t flags;
+  uint64_t other;
+  ConstString import_name;
+};
+
+struct TrieEntryWithOffset {
+  lldb::offset_t nodeOffset;
+  TrieEntry entry;
+
+  TrieEntryWithOffset(lldb::offset_t offset) : nodeOffset(offset), entry() {}
+
+  void Dump(uint32_t idx) const {
+    printf("[%3u] 0x%16.16llx: ", idx,
+           static_cast<unsigned long long>(nodeOffset));
+    entry.Dump();
+  }
+
+  bool operator<(const TrieEntryWithOffset &other) const {
+    return (nodeOffset < other.nodeOffset);
+  }
+};
+
+static bool ParseTrieEntries(DataExtractor &data, lldb::offset_t offset,
+                             const bool is_arm,
+                             std::vector<llvm::StringRef> &nameSlices,
+                             std::set<lldb::addr_t> &resolver_addresses,
+                             std::vector<TrieEntryWithOffset> &output) {
+  if (!data.ValidOffset(offset))
+    return true;
+
+  const uint64_t terminalSize = data.GetULEB128(&offset);
+  lldb::offset_t children_offset = offset + terminalSize;
+  if (terminalSize != 0) {
+    TrieEntryWithOffset e(offset);
+    e.entry.flags = data.GetULEB128(&offset);
+    const char *import_name = NULL;
+    if (e.entry.flags & EXPORT_SYMBOL_FLAGS_REEXPORT) {
+      e.entry.address = 0;
+      e.entry.other = data.GetULEB128(&offset); // dylib ordinal
+      import_name = data.GetCStr(&offset);
+    } else {
+      e.entry.address = data.GetULEB128(&offset);
+      if (e.entry.flags & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) {
+        e.entry.other = data.GetULEB128(&offset);
+        uint64_t resolver_addr = e.entry.other;
+        if (is_arm)
+          resolver_addr &= THUMB_ADDRESS_BIT_MASK;
+        resolver_addresses.insert(resolver_addr);
+      } else
+        e.entry.other = 0;
+    }
+    // Only add symbols that are reexport symbols with a valid import name
+    if (EXPORT_SYMBOL_FLAGS_REEXPORT & e.entry.flags && import_name &&
+        import_name[0]) {
+      std::string name;
+      if (!nameSlices.empty()) {
+        for (auto name_slice : nameSlices)
+          name.append(name_slice.data(), name_slice.size());
+      }
+      if (name.size() > 1) {
+        // Skip the leading '_'
+        e.entry.name.SetCStringWithLength(name.c_str() + 1, name.size() - 1);
+      }
+      if (import_name) {
+        // Skip the leading '_'
+        e.entry.import_name.SetCString(import_name + 1);
+      }
+      output.push_back(e);
+    }
+  }
+
+  const uint8_t childrenCount = data.GetU8(&children_offset);
+  for (uint8_t i = 0; i < childrenCount; ++i) {
+    const char *cstr = data.GetCStr(&children_offset);
+    if (cstr)
+      nameSlices.push_back(llvm::StringRef(cstr));
+    else
+      return false; // Corrupt data
+    lldb::offset_t childNodeOffset = data.GetULEB128(&children_offset);
+    if (childNodeOffset) {
+      if (!ParseTrieEntries(data, childNodeOffset, is_arm, nameSlices,
+                            resolver_addresses, output)) {
+        return false;
+      }
+    }
+    nameSlices.pop_back();
+  }
+  return true;
+}
+
+// Read the UUID out of a dyld_shared_cache file on-disk.
+UUID ObjectFileMachO::GetSharedCacheUUID(FileSpec dyld_shared_cache,
+                                         const ByteOrder byte_order,
+                                         const uint32_t addr_byte_size) {
+  UUID dsc_uuid;
+  DataBufferSP dsc_data_sp = dyld_shared_cache.MemoryMapFileContentsIfLocal(
+      0, sizeof(struct lldb_copy_dyld_cache_header_v1));
+  if (dsc_data_sp) {
+    DataExtractor dsc_header_data(dsc_data_sp, byte_order, addr_byte_size);
+
+    char version_str[7];
+    lldb::offset_t offset = 0;
+    memcpy(version_str, dsc_header_data.GetData(&offset, 6), 6);
+    version_str[6] = '\0';
+    if (strcmp(version_str, "dyld_v") == 0) {
+      offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid);
+      uint8_t uuid_bytes[sizeof(uuid_t)];
+      memcpy(uuid_bytes, dsc_header_data.GetData(&offset, sizeof(uuid_t)),
+             sizeof(uuid_t));
+      dsc_uuid.SetBytes(uuid_bytes);
+    }
+  }
+  return dsc_uuid;
+}
+
+size_t ObjectFileMachO::ParseSymtab() {
+  Timer scoped_timer(LLVM_PRETTY_FUNCTION,
+                     "ObjectFileMachO::ParseSymtab () module = %s",
+                     m_file.GetFilename().AsCString(""));
+  ModuleSP module_sp(GetModule());
+  if (!module_sp)
+    return 0;
+
+  struct symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
+  struct linkedit_data_command function_starts_load_command = {0, 0, 0, 0};
+  struct dyld_info_command dyld_info = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  typedef AddressDataArray<lldb::addr_t, bool, 100> FunctionStarts;
+  FunctionStarts function_starts;
+  lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+  uint32_t i;
+  FileSpecList dylib_files;
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS));
+  static const llvm::StringRef g_objc_v2_prefix_class("_OBJC_CLASS_$_");
+  static const llvm::StringRef g_objc_v2_prefix_metaclass("_OBJC_METACLASS_$_");
+  static const llvm::StringRef g_objc_v2_prefix_ivar("_OBJC_IVAR_$_");
+
+  for (i = 0; i < m_header.ncmds; ++i) {
+    const lldb::offset_t cmd_offset = offset;
+    // Read in the load command and load command size
+    struct load_command lc;
+    if (m_data.GetU32(&offset, &lc, 2) == NULL)
+      break;
+    // Watch for the symbol table load command
+    switch (lc.cmd) {
+    case LC_SYMTAB:
+      symtab_load_command.cmd = lc.cmd;
+      symtab_load_command.cmdsize = lc.cmdsize;
+      // Read in the rest of the symtab load command
+      if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4) ==
+          0) // fill in symoff, nsyms, stroff, strsize fields
+        return 0;
+      if (symtab_load_command.symoff == 0) {
+        if (log)
+          module_sp->LogMessage(log, "LC_SYMTAB.symoff == 0");
+        return 0;
+      }
+
+      if (symtab_load_command.stroff == 0) {
+        if (log)
+          module_sp->LogMessage(log, "LC_SYMTAB.stroff == 0");
+        return 0;
+      }
+
+      if (symtab_load_command.nsyms == 0) {
+        if (log)
+          module_sp->LogMessage(log, "LC_SYMTAB.nsyms == 0");
+        return 0;
+      }
+
+      if (symtab_load_command.strsize == 0) {
+        if (log)
+          module_sp->LogMessage(log, "LC_SYMTAB.strsize == 0");
+        return 0;
+      }
+      break;
+
+    case LC_DYLD_INFO:
+    case LC_DYLD_INFO_ONLY:
+      if (m_data.GetU32(&offset, &dyld_info.rebase_off, 10)) {
+        dyld_info.cmd = lc.cmd;
+        dyld_info.cmdsize = lc.cmdsize;
+      } else {
+        memset(&dyld_info, 0, sizeof(dyld_info));
+      }
+      break;
+
+    case LC_LOAD_DYLIB:
+    case LC_LOAD_WEAK_DYLIB:
+    case LC_REEXPORT_DYLIB:
+    case LC_LOADFVMLIB:
+    case LC_LOAD_UPWARD_DYLIB: {
+      uint32_t name_offset = cmd_offset + m_data.GetU32(&offset);
+      const char *path = m_data.PeekCStr(name_offset);
+      if (path) {
+        FileSpec file_spec(path, false);
+        // Strip the path if there is @rpath, @executable, etc so we just use
+        // the basename
+        if (path[0] == '@')
+          file_spec.GetDirectory().Clear();
+
+        if (lc.cmd == LC_REEXPORT_DYLIB) {
+          m_reexported_dylibs.AppendIfUnique(file_spec);
+        }
+
+        dylib_files.Append(file_spec);
+      }
+    } break;
+
+    case LC_FUNCTION_STARTS:
+      function_starts_load_command.cmd = lc.cmd;
+      function_starts_load_command.cmdsize = lc.cmdsize;
+      if (m_data.GetU32(&offset, &function_starts_load_command.dataoff, 2) ==
+          NULL) // fill in symoff, nsyms, stroff, strsize fields
+        memset(&function_starts_load_command, 0,
+               sizeof(function_starts_load_command));
+      break;
+
+    default:
+      break;
+    }
+    offset = cmd_offset + lc.cmdsize;
+  }
+
+  if (symtab_load_command.cmd) {
+    Symtab *symtab = m_symtab_ap.get();
+    SectionList *section_list = GetSectionList();
+    if (section_list == NULL)
+      return 0;
+
+    const uint32_t addr_byte_size = m_data.GetAddressByteSize();
+    const ByteOrder byte_order = m_data.GetByteOrder();
+    bool bit_width_32 = addr_byte_size == 4;
+    const size_t nlist_byte_size =
+        bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64);
+
+    DataExtractor nlist_data(NULL, 0, byte_order, addr_byte_size);
+    DataExtractor strtab_data(NULL, 0, byte_order, addr_byte_size);
+    DataExtractor function_starts_data(NULL, 0, byte_order, addr_byte_size);
+    DataExtractor indirect_symbol_index_data(NULL, 0, byte_order,
+                                             addr_byte_size);
+    DataExtractor dyld_trie_data(NULL, 0, byte_order, addr_byte_size);
+
+    const addr_t nlist_data_byte_size =
+        symtab_load_command.nsyms * nlist_byte_size;
+    const addr_t strtab_data_byte_size = symtab_load_command.strsize;
+    addr_t strtab_addr = LLDB_INVALID_ADDRESS;
+
+    ProcessSP process_sp(m_process_wp.lock());
+    Process *process = process_sp.get();
+
+    uint32_t memory_module_load_level = eMemoryModuleLoadLevelComplete;
+
+    if (process && m_header.filetype != llvm::MachO::MH_OBJECT) {
+      Target &target = process->GetTarget();
+
+      memory_module_load_level = target.GetMemoryModuleLoadLevel();
+
+      SectionSP linkedit_section_sp(
+          section_list->FindSectionByName(GetSegmentNameLINKEDIT()));
+      // Reading mach file from memory in a process or core file...
+
+      if (linkedit_section_sp) {
+        addr_t linkedit_load_addr =
+            linkedit_section_sp->GetLoadBaseAddress(&target);
+        if (linkedit_load_addr == LLDB_INVALID_ADDRESS) {
+          // We might be trying to access the symbol table before the
+          // __LINKEDIT's load
+          // address has been set in the target. We can't fail to read the
+          // symbol table,
+          // so calculate the right address manually
+          linkedit_load_addr = CalculateSectionLoadAddressForMemoryImage(
+              m_memory_addr, GetMachHeaderSection(), linkedit_section_sp.get());
+        }
+
+        const addr_t linkedit_file_offset =
+            linkedit_section_sp->GetFileOffset();
+        const addr_t symoff_addr = linkedit_load_addr +
+                                   symtab_load_command.symoff -
+                                   linkedit_file_offset;
+        strtab_addr = linkedit_load_addr + symtab_load_command.stroff -
+                      linkedit_file_offset;
+
+        bool data_was_read = false;
+
+#if defined(__APPLE__) &&                                                      \
+    (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
+        if (m_header.flags & 0x80000000u &&
+            process->GetAddressByteSize() == sizeof(void *)) {
+          // This mach-o memory file is in the dyld shared cache. If this
+          // program is not remote and this is iOS, then this process will
+          // share the same shared cache as the process we are debugging and
+          // we can read the entire __LINKEDIT from the address space in this
+          // process. This is a needed optimization that is used for local iOS
+          // debugging only since all shared libraries in the shared cache do
+          // not have corresponding files that exist in the file system of the
+          // device. They have been combined into a single file. This means we
+          // always have to load these files from memory. All of the symbol and
+          // string tables from all of the __LINKEDIT sections from the shared
+          // libraries in the shared cache have been merged into a single large
+          // symbol and string table. Reading all of this symbol and string
+          // table
+          // data across can slow down debug launch times, so we optimize this
+          // by
+          // reading the memory for the __LINKEDIT section from this process.
+
+          UUID lldb_shared_cache(GetLLDBSharedCacheUUID());
+          UUID process_shared_cache(GetProcessSharedCacheUUID(process));
+          bool use_lldb_cache = true;
+          if (lldb_shared_cache.IsValid() && process_shared_cache.IsValid() &&
+              lldb_shared_cache != process_shared_cache) {
+            use_lldb_cache = false;
+            ModuleSP module_sp(GetModule());
+            if (module_sp)
+              module_sp->ReportWarning("shared cache in process does not match "
+                                       "lldb's own shared cache, startup will "
+                                       "be slow.");
+          }
+
+          PlatformSP platform_sp(target.GetPlatform());
+          if (platform_sp && platform_sp->IsHost() && use_lldb_cache) {
+            data_was_read = true;
+            nlist_data.SetData((void *)symoff_addr, nlist_data_byte_size,
+                               eByteOrderLittle);
+            strtab_data.SetData((void *)strtab_addr, strtab_data_byte_size,
+                                eByteOrderLittle);
+            if (function_starts_load_command.cmd) {
+              const addr_t func_start_addr =
+                  linkedit_load_addr + function_starts_load_command.dataoff -
+                  linkedit_file_offset;
+              function_starts_data.SetData(
+                  (void *)func_start_addr,
+                  function_starts_load_command.datasize, eByteOrderLittle);
             }
-            offset = load_cmd_offset + encryption_cmd.cmdsize;
+          }
         }
+#endif
 
-        bool section_file_addresses_changed = false;
+        if (!data_was_read) {
+          // Always load dyld - the dynamic linker - from memory if we didn't
+          // find a binary anywhere else.
+          // lldb will not register dylib/framework/bundle loads/unloads if we
+          // don't have the dyld symbols,
+          // we force dyld to load from memory despite the user's
+          // target.memory-module-load-level setting.
+          if (memory_module_load_level == eMemoryModuleLoadLevelComplete ||
+              m_header.filetype == llvm::MachO::MH_DYLINKER) {
+            DataBufferSP nlist_data_sp(
+                ReadMemory(process_sp, symoff_addr, nlist_data_byte_size));
+            if (nlist_data_sp)
+              nlist_data.SetData(nlist_data_sp, 0,
+                                 nlist_data_sp->GetByteSize());
+            // Load strings individually from memory when loading from memory
+            // since shared cache
+            // string tables contain strings for all symbols from all shared
+            // cached libraries
+            // DataBufferSP strtab_data_sp (ReadMemory (process_sp, strtab_addr,
+            // strtab_data_byte_size));
+            // if (strtab_data_sp)
+            //    strtab_data.SetData (strtab_data_sp, 0,
+            //    strtab_data_sp->GetByteSize());
+            if (m_dysymtab.nindirectsyms != 0) {
+              const addr_t indirect_syms_addr = linkedit_load_addr +
+                                                m_dysymtab.indirectsymoff -
+                                                linkedit_file_offset;
+              DataBufferSP indirect_syms_data_sp(
+                  ReadMemory(process_sp, indirect_syms_addr,
+                             m_dysymtab.nindirectsyms * 4));
+              if (indirect_syms_data_sp)
+                indirect_symbol_index_data.SetData(
+                    indirect_syms_data_sp, 0,
+                    indirect_syms_data_sp->GetByteSize());
+            }
+          } else if (memory_module_load_level >=
+                     eMemoryModuleLoadLevelPartial) {
+            if (function_starts_load_command.cmd) {
+              const addr_t func_start_addr =
+                  linkedit_load_addr + function_starts_load_command.dataoff -
+                  linkedit_file_offset;
+              DataBufferSP func_start_data_sp(
+                  ReadMemory(process_sp, func_start_addr,
+                             function_starts_load_command.datasize));
+              if (func_start_data_sp)
+                function_starts_data.SetData(func_start_data_sp, 0,
+                                             func_start_data_sp->GetByteSize());
+            }
+          }
+        }
+      }
+    } else {
+      nlist_data.SetData(m_data, symtab_load_command.symoff,
+                         nlist_data_byte_size);
+      strtab_data.SetData(m_data, symtab_load_command.stroff,
+                          strtab_data_byte_size);
+
+      if (dyld_info.export_size > 0) {
+        dyld_trie_data.SetData(m_data, dyld_info.export_off,
+                               dyld_info.export_size);
+      }
+
+      if (m_dysymtab.nindirectsyms != 0) {
+        indirect_symbol_index_data.SetData(m_data, m_dysymtab.indirectsymoff,
+                                           m_dysymtab.nindirectsyms * 4);
+      }
+      if (function_starts_load_command.cmd) {
+        function_starts_data.SetData(m_data,
+                                     function_starts_load_command.dataoff,
+                                     function_starts_load_command.datasize);
+      }
+    }
+
+    if (nlist_data.GetByteSize() == 0 &&
+        memory_module_load_level == eMemoryModuleLoadLevelComplete) {
+      if (log)
+        module_sp->LogMessage(log, "failed to read nlist data");
+      return 0;
+    }
+
+    const bool have_strtab_data = strtab_data.GetByteSize() > 0;
+    if (!have_strtab_data) {
+      if (process) {
+        if (strtab_addr == LLDB_INVALID_ADDRESS) {
+          if (log)
+            module_sp->LogMessage(log, "failed to locate the strtab in memory");
+          return 0;
+        }
+      } else {
+        if (log)
+          module_sp->LogMessage(log, "failed to read strtab data");
+        return 0;
+      }
+    }
 
-        offset = MachHeaderSizeFromMagic(m_header.magic);
+    const ConstString &g_segment_name_TEXT = GetSegmentNameTEXT();
+    const ConstString &g_segment_name_DATA = GetSegmentNameDATA();
+    const ConstString &g_segment_name_DATA_DIRTY = GetSegmentNameDATA_DIRTY();
+    const ConstString &g_segment_name_DATA_CONST = GetSegmentNameDATA_CONST();
+    const ConstString &g_segment_name_OBJC = GetSegmentNameOBJC();
+    const ConstString &g_section_name_eh_frame = GetSectionNameEHFrame();
+    SectionSP text_section_sp(
+        section_list->FindSectionByName(g_segment_name_TEXT));
+    SectionSP data_section_sp(
+        section_list->FindSectionByName(g_segment_name_DATA));
+    SectionSP data_dirty_section_sp(
+        section_list->FindSectionByName(g_segment_name_DATA_DIRTY));
+    SectionSP data_const_section_sp(
+        section_list->FindSectionByName(g_segment_name_DATA_CONST));
+    SectionSP objc_section_sp(
+        section_list->FindSectionByName(g_segment_name_OBJC));
+    SectionSP eh_frame_section_sp;
+    if (text_section_sp.get())
+      eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName(
+          g_section_name_eh_frame);
+    else
+      eh_frame_section_sp =
+          section_list->FindSectionByName(g_section_name_eh_frame);
 
-        struct segment_command_64 load_cmd;
-        for (i=0; i<m_header.ncmds; ++i)
-        {
-            const lldb::offset_t load_cmd_offset = offset;
-            if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
-                break;
+    const bool is_arm = (m_header.cputype == llvm::MachO::CPU_TYPE_ARM);
 
-            if (load_cmd.cmd == LC_SEGMENT || load_cmd.cmd == LC_SEGMENT_64)
-            {
-                if (m_data.GetU8(&offset, (uint8_t*)load_cmd.segname, 16))
-                {
-                    bool add_section = true;
-                    bool add_to_unified = true;
-                    ConstString const_segname (load_cmd.segname, std::min<size_t>(strlen(load_cmd.segname), sizeof(load_cmd.segname)));
+    // lldb works best if it knows the start address of all functions in a
+    // module.
+    // Linker symbols or debug info are normally the best source of information
+    // for start addr / size but
+    // they may be stripped in a released binary.
+    // Two additional sources of information exist in Mach-O binaries:
+    //    LC_FUNCTION_STARTS - a list of ULEB128 encoded offsets of each
+    //    function's start address in the
+    //                         binary, relative to the text section.
+    //    eh_frame           - the eh_frame FDEs have the start addr & size of
+    //    each function
+    //  LC_FUNCTION_STARTS is the fastest source to read in, and is present on
+    //  all modern binaries.
+    //  Binaries built to run on older releases may need to use eh_frame
+    //  information.
+
+    if (text_section_sp && function_starts_data.GetByteSize()) {
+      FunctionStarts::Entry function_start_entry;
+      function_start_entry.data = false;
+      lldb::offset_t function_start_offset = 0;
+      function_start_entry.addr = text_section_sp->GetFileAddress();
+      uint64_t delta;
+      while ((delta = function_starts_data.GetULEB128(&function_start_offset)) >
+             0) {
+        // Now append the current entry
+        function_start_entry.addr += delta;
+        function_starts.Append(function_start_entry);
+      }
+    } else {
+      // If m_type is eTypeDebugInfo, then this is a dSYM - it will have the
+      // load command claiming an eh_frame
+      // but it doesn't actually have the eh_frame content.  And if we have a
+      // dSYM, we don't need to do any
+      // of this fill-in-the-missing-symbols works anyway - the debug info
+      // should give us all the functions in
+      // the module.
+      if (text_section_sp.get() && eh_frame_section_sp.get() &&
+          m_type != eTypeDebugInfo) {
+        DWARFCallFrameInfo eh_frame(*this, eh_frame_section_sp,
+                                    eRegisterKindEHFrame, true);
+        DWARFCallFrameInfo::FunctionAddressAndSizeVector functions;
+        eh_frame.GetFunctionAddressAndSizeVector(functions);
+        addr_t text_base_addr = text_section_sp->GetFileAddress();
+        size_t count = functions.GetSize();
+        for (size_t i = 0; i < count; ++i) {
+          const DWARFCallFrameInfo::FunctionAddressAndSizeVector::Entry *func =
+              functions.GetEntryAtIndex(i);
+          if (func) {
+            FunctionStarts::Entry function_start_entry;
+            function_start_entry.addr = func->base - text_base_addr;
+            function_starts.Append(function_start_entry);
+          }
+        }
+      }
+    }
+
+    const size_t function_starts_count = function_starts.GetSize();
+
+    // For user process binaries (executables, dylibs, frameworks, bundles), if
+    // we don't have
+    // LC_FUNCTION_STARTS/eh_frame section in this binary, we're going to assume
+    // the binary
+    // has been stripped.  Don't allow assembly language instruction emulation
+    // because we don't
+    // know proper function start boundaries.
+    //
+    // For all other types of binaries (kernels, stand-alone bare board
+    // binaries, kexts), they
+    // may not have LC_FUNCTION_STARTS / eh_frame sections - we should not make
+    // any assumptions
+    // about them based on that.
+    if (function_starts_count == 0 && CalculateStrata() == eStrataUser) {
+      m_allow_assembly_emulation_unwind_plans = false;
+      Log *unwind_or_symbol_log(lldb_private::GetLogIfAnyCategoriesSet(
+          LIBLLDB_LOG_SYMBOLS | LIBLLDB_LOG_UNWIND));
+
+      if (unwind_or_symbol_log)
+        module_sp->LogMessage(
+            unwind_or_symbol_log,
+            "no LC_FUNCTION_STARTS, will not allow assembly profiled unwinds");
+    }
+
+    const user_id_t TEXT_eh_frame_sectID =
+        eh_frame_section_sp.get() ? eh_frame_section_sp->GetID()
+                                  : static_cast<user_id_t>(NO_SECT);
+
+    lldb::offset_t nlist_data_offset = 0;
+
+    uint32_t N_SO_index = UINT32_MAX;
+
+    MachSymtabSectionInfo section_info(section_list);
+    std::vector<uint32_t> N_FUN_indexes;
+    std::vector<uint32_t> N_NSYM_indexes;
+    std::vector<uint32_t> N_INCL_indexes;
+    std::vector<uint32_t> N_BRAC_indexes;
+    std::vector<uint32_t> N_COMM_indexes;
+    typedef std::multimap<uint64_t, uint32_t> ValueToSymbolIndexMap;
+    typedef std::map<uint32_t, uint32_t> NListIndexToSymbolIndexMap;
+    typedef std::map<const char *, uint32_t> ConstNameToSymbolIndexMap;
+    ValueToSymbolIndexMap N_FUN_addr_to_sym_idx;
+    ValueToSymbolIndexMap N_STSYM_addr_to_sym_idx;
+    ConstNameToSymbolIndexMap N_GSYM_name_to_sym_idx;
+    // Any symbols that get merged into another will get an entry
+    // in this map so we know
+    NListIndexToSymbolIndexMap m_nlist_idx_to_sym_idx;
+    uint32_t nlist_idx = 0;
+    Symbol *symbol_ptr = NULL;
+
+    uint32_t sym_idx = 0;
+    Symbol *sym = NULL;
+    size_t num_syms = 0;
+    std::string memory_symbol_name;
+    uint32_t unmapped_local_symbols_found = 0;
+
+    std::vector<TrieEntryWithOffset> trie_entries;
+    std::set<lldb::addr_t> resolver_addresses;
+
+    if (dyld_trie_data.GetByteSize() > 0) {
+      std::vector<llvm::StringRef> nameSlices;
+      ParseTrieEntries(dyld_trie_data, 0, is_arm, nameSlices,
+                       resolver_addresses, trie_entries);
+
+      ConstString text_segment_name("__TEXT");
+      SectionSP text_segment_sp =
+          GetSectionList()->FindSectionByName(text_segment_name);
+      if (text_segment_sp) {
+        const lldb::addr_t text_segment_file_addr =
+            text_segment_sp->GetFileAddress();
+        if (text_segment_file_addr != LLDB_INVALID_ADDRESS) {
+          for (auto &e : trie_entries)
+            e.entry.address += text_segment_file_addr;
+        }
+      }
+    }
+
+    typedef std::set<ConstString> IndirectSymbols;
+    IndirectSymbols indirect_symbol_names;
+
+#if defined(__APPLE__) &&                                                      \
+    (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
+
+    // Some recent builds of the dyld_shared_cache (hereafter: DSC) have been
+    // optimized by moving LOCAL
+    // symbols out of the memory mapped portion of the DSC. The symbol
+    // information has all been retained,
+    // but it isn't available in the normal nlist data. However, there *are*
+    // duplicate entries of *some*
+    // LOCAL symbols in the normal nlist data. To handle this situation
+    // correctly, we must first attempt
+    // to parse any DSC unmapped symbol information. If we find any, we set a
+    // flag that tells the normal
+    // nlist parser to ignore all LOCAL symbols.
+
+    if (m_header.flags & 0x80000000u) {
+      // Before we can start mapping the DSC, we need to make certain the target
+      // process is actually
+      // using the cache we can find.
+
+      // Next we need to determine the correct path for the dyld shared cache.
+
+      ArchSpec header_arch;
+      GetArchitecture(header_arch);
+      char dsc_path[PATH_MAX];
+      char dsc_path_development[PATH_MAX];
+
+      snprintf(
+          dsc_path, sizeof(dsc_path), "%s%s%s",
+          "/System/Library/Caches/com.apple.dyld/", /* IPHONE_DYLD_SHARED_CACHE_DIR
+                                                       */
+          "dyld_shared_cache_", /* DYLD_SHARED_CACHE_BASE_NAME */
+          header_arch.GetArchitectureName());
+
+      snprintf(
+          dsc_path_development, sizeof(dsc_path), "%s%s%s%s",
+          "/System/Library/Caches/com.apple.dyld/", /* IPHONE_DYLD_SHARED_CACHE_DIR
+                                                       */
+          "dyld_shared_cache_", /* DYLD_SHARED_CACHE_BASE_NAME */
+          header_arch.GetArchitectureName(),
+          ".development");
+
+      FileSpec dsc_nondevelopment_filespec(dsc_path, false);
+      FileSpec dsc_development_filespec(dsc_path_development, false);
+      FileSpec dsc_filespec;
+
+      UUID dsc_uuid;
+      UUID process_shared_cache_uuid;
+
+      if (process) {
+        process_shared_cache_uuid = GetProcessSharedCacheUUID(process);
+      }
+
+      // First see if we can find an exact match for the inferior process shared
+      // cache UUID in
+      // the development or non-development shared caches on disk.
+      if (process_shared_cache_uuid.IsValid()) {
+        if (dsc_development_filespec.Exists()) {
+          UUID dsc_development_uuid = GetSharedCacheUUID(
+              dsc_development_filespec, byte_order, addr_byte_size);
+          if (dsc_development_uuid.IsValid() &&
+              dsc_development_uuid == process_shared_cache_uuid) {
+            dsc_filespec = dsc_development_filespec;
+            dsc_uuid = dsc_development_uuid;
+          }
+        }
+        if (!dsc_uuid.IsValid() && dsc_nondevelopment_filespec.Exists()) {
+          UUID dsc_nondevelopment_uuid = GetSharedCacheUUID(
+              dsc_nondevelopment_filespec, byte_order, addr_byte_size);
+          if (dsc_nondevelopment_uuid.IsValid() &&
+              dsc_nondevelopment_uuid == process_shared_cache_uuid) {
+            dsc_filespec = dsc_nondevelopment_filespec;
+            dsc_uuid = dsc_nondevelopment_uuid;
+          }
+        }
+      }
+
+      // Failing a UUID match, prefer the development dyld_shared cache if both
+      // are present.
+      if (!dsc_filespec.Exists()) {
+        if (dsc_development_filespec.Exists()) {
+          dsc_filespec = dsc_development_filespec;
+        } else {
+          dsc_filespec = dsc_nondevelopment_filespec;
+        }
+      }
+
+      /* The dyld_cache_header has a pointer to the
+         dyld_cache_local_symbols_info structure (localSymbolsOffset).
+         The dyld_cache_local_symbols_info structure gives us three things:
+           1. The start and count of the nlist records in the dyld_shared_cache
+         file
+           2. The start and size of the strings for these nlist records
+           3. The start and count of dyld_cache_local_symbols_entry entries
+
+         There is one dyld_cache_local_symbols_entry per dylib/framework in the
+         dyld shared cache.
+         The "dylibOffset" field is the Mach-O header of this dylib/framework in
+         the dyld shared cache.
+         The dyld_cache_local_symbols_entry also lists the start of this
+         dylib/framework's nlist records
+         and the count of how many nlist records there are for this
+         dylib/framework.
+      */
+
+      // Process the dyld shared cache header to find the unmapped symbols
+
+      DataBufferSP dsc_data_sp = dsc_filespec.MemoryMapFileContentsIfLocal(
+          0, sizeof(struct lldb_copy_dyld_cache_header_v1));
+      if (!dsc_uuid.IsValid()) {
+        dsc_uuid = GetSharedCacheUUID(dsc_filespec, byte_order, addr_byte_size);
+      }
+      if (dsc_data_sp) {
+        DataExtractor dsc_header_data(dsc_data_sp, byte_order, addr_byte_size);
+
+        bool uuid_match = true;
+        if (dsc_uuid.IsValid() && process) {
+          if (process_shared_cache_uuid.IsValid() &&
+              dsc_uuid != process_shared_cache_uuid) {
+            // The on-disk dyld_shared_cache file is not the same as the one in
+            // this
+            // process' memory, don't use it.
+            uuid_match = false;
+            ModuleSP module_sp(GetModule());
+            if (module_sp)
+              module_sp->ReportWarning("process shared cache does not match "
+                                       "on-disk dyld_shared_cache file, some "
+                                       "symbol names will be missing.");
+          }
+        }
+
+        offset = offsetof(struct lldb_copy_dyld_cache_header_v1, mappingOffset);
+
+        uint32_t mappingOffset = dsc_header_data.GetU32(&offset);
+
+        // If the mappingOffset points to a location inside the header, we've
+        // opened an old dyld shared cache, and should not proceed further.
+        if (uuid_match &&
+            mappingOffset >= sizeof(struct lldb_copy_dyld_cache_header_v1)) {
+
+          DataBufferSP dsc_mapping_info_data_sp =
+              dsc_filespec.MemoryMapFileContentsIfLocal(
+                  mappingOffset,
+                  sizeof(struct lldb_copy_dyld_cache_mapping_info));
+          DataExtractor dsc_mapping_info_data(dsc_mapping_info_data_sp,
+                                              byte_order, addr_byte_size);
+          offset = 0;
+
+          // The File addresses (from the in-memory Mach-O load commands) for
+          // the shared libraries
+          // in the shared library cache need to be adjusted by an offset to
+          // match up with the
+          // dylibOffset identifying field in the
+          // dyld_cache_local_symbol_entry's.  This offset is
+          // recorded in mapping_offset_value.
+          const uint64_t mapping_offset_value =
+              dsc_mapping_info_data.GetU64(&offset);
+
+          offset = offsetof(struct lldb_copy_dyld_cache_header_v1,
+                            localSymbolsOffset);
+          uint64_t localSymbolsOffset = dsc_header_data.GetU64(&offset);
+          uint64_t localSymbolsSize = dsc_header_data.GetU64(&offset);
+
+          if (localSymbolsOffset && localSymbolsSize) {
+            // Map the local symbols
+            if (DataBufferSP dsc_local_symbols_data_sp =
+                    dsc_filespec.MemoryMapFileContentsIfLocal(
+                        localSymbolsOffset, localSymbolsSize)) {
+              DataExtractor dsc_local_symbols_data(dsc_local_symbols_data_sp,
+                                                   byte_order, addr_byte_size);
+
+              offset = 0;
+
+              typedef std::map<ConstString, uint16_t> UndefinedNameToDescMap;
+              typedef std::map<uint32_t, ConstString> SymbolIndexToName;
+              UndefinedNameToDescMap undefined_name_to_desc;
+              SymbolIndexToName reexport_shlib_needs_fixup;
+
+              // Read the local_symbols_infos struct in one shot
+              struct lldb_copy_dyld_cache_local_symbols_info local_symbols_info;
+              dsc_local_symbols_data.GetU32(&offset,
+                                            &local_symbols_info.nlistOffset, 6);
+
+              SectionSP text_section_sp(
+                  section_list->FindSectionByName(GetSegmentNameTEXT()));
+
+              uint32_t header_file_offset =
+                  (text_section_sp->GetFileAddress() - mapping_offset_value);
+
+              offset = local_symbols_info.entriesOffset;
+              for (uint32_t entry_index = 0;
+                   entry_index < local_symbols_info.entriesCount;
+                   entry_index++) {
+                struct lldb_copy_dyld_cache_local_symbols_entry
+                    local_symbols_entry;
+                local_symbols_entry.dylibOffset =
+                    dsc_local_symbols_data.GetU32(&offset);
+                local_symbols_entry.nlistStartIndex =
+                    dsc_local_symbols_data.GetU32(&offset);
+                local_symbols_entry.nlistCount =
+                    dsc_local_symbols_data.GetU32(&offset);
+
+                if (header_file_offset == local_symbols_entry.dylibOffset) {
+                  unmapped_local_symbols_found = local_symbols_entry.nlistCount;
+
+                  // The normal nlist code cannot correctly size the Symbols
+                  // array, we need to allocate it here.
+                  sym = symtab->Resize(
+                      symtab_load_command.nsyms + m_dysymtab.nindirectsyms +
+                      unmapped_local_symbols_found - m_dysymtab.nlocalsym);
+                  num_syms = symtab->GetNumSymbols();
+
+                  nlist_data_offset =
+                      local_symbols_info.nlistOffset +
+                      (nlist_byte_size * local_symbols_entry.nlistStartIndex);
+                  uint32_t string_table_offset =
+                      local_symbols_info.stringsOffset;
+
+                  for (uint32_t nlist_index = 0;
+                       nlist_index < local_symbols_entry.nlistCount;
+                       nlist_index++) {
+                    /////////////////////////////
+                    {
+                      struct nlist_64 nlist;
+                      if (!dsc_local_symbols_data.ValidOffsetForDataOfSize(
+                              nlist_data_offset, nlist_byte_size))
+                        break;
+
+                      nlist.n_strx = dsc_local_symbols_data.GetU32_unchecked(
+                          &nlist_data_offset);
+                      nlist.n_type = dsc_local_symbols_data.GetU8_unchecked(
+                          &nlist_data_offset);
+                      nlist.n_sect = dsc_local_symbols_data.GetU8_unchecked(
+                          &nlist_data_offset);
+                      nlist.n_desc = dsc_local_symbols_data.GetU16_unchecked(
+                          &nlist_data_offset);
+                      nlist.n_value =
+                          dsc_local_symbols_data.GetAddress_unchecked(
+                              &nlist_data_offset);
+
+                      SymbolType type = eSymbolTypeInvalid;
+                      const char *symbol_name = dsc_local_symbols_data.PeekCStr(
+                          string_table_offset + nlist.n_strx);
 
-                    SectionSP unified_section_sp(unified_section_list.FindSectionByName(const_segname));
-                    if (is_dsym && unified_section_sp)
-                    {
-                        if (const_segname == GetSegmentNameLINKEDIT())
-                        {
-                            // We need to keep the __LINKEDIT segment private to this object file only
-                            add_to_unified = false;
-                        }
-                        else
-                        {
-                            // This is the dSYM file and this section has already been created by
-                            // the object file, no need to create it.
-                            add_section = false;
-                        }
-                    }
-                    load_cmd.vmaddr = m_data.GetAddress(&offset);
-                    load_cmd.vmsize = m_data.GetAddress(&offset);
-                    load_cmd.fileoff = m_data.GetAddress(&offset);
-                    load_cmd.filesize = m_data.GetAddress(&offset);
-                    if (m_length != 0 && load_cmd.filesize != 0)
-                    {
-                        if (load_cmd.fileoff > m_length)
-                        {
-                            // We have a load command that says it extends past the end of the file.  This is likely
-                            // a corrupt file.  We don't have any way to return an error condition here (this method
-                            // was likely invoked from something like ObjectFile::GetSectionList()) -- all we can do
-                            // is null out the SectionList vector and if a process has been set up, dump a message
-                            // to stdout.  The most common case here is core file debugging with a truncated file.
-                            const char *lc_segment_name = load_cmd.cmd == LC_SEGMENT_64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
-                            module_sp->ReportWarning("load command %u %s has a fileoff (0x%" PRIx64 ") that extends beyond the end of the file (0x%" PRIx64 "), ignoring this section",
-                                                   i,
-                                                   lc_segment_name,
-                                                   load_cmd.fileoff,
-                                                   m_length);
-                            
-                            load_cmd.fileoff = 0;
-                            load_cmd.filesize = 0;
-                        }
-                        
-                        if (load_cmd.fileoff + load_cmd.filesize > m_length)
-                        {
-                            // We have a load command that says it extends past the end of the file.  This is likely
-                            // a corrupt file.  We don't have any way to return an error condition here (this method
-                            // was likely invoked from something like ObjectFile::GetSectionList()) -- all we can do
-                            // is null out the SectionList vector and if a process has been set up, dump a message
-                            // to stdout.  The most common case here is core file debugging with a truncated file.
-                            const char *lc_segment_name = load_cmd.cmd == LC_SEGMENT_64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
-                            GetModule()->ReportWarning("load command %u %s has a fileoff + filesize (0x%" PRIx64 ") that extends beyond the end of the file (0x%" PRIx64 "), the segment will be truncated to match",
-                                                     i,
-                                                     lc_segment_name,
-                                                     load_cmd.fileoff + load_cmd.filesize,
-                                                     m_length);
-                            
-                            // Tuncase the length
-                            load_cmd.filesize = m_length - load_cmd.fileoff;
-                        }
-                    }
-                    if (m_data.GetU32(&offset, &load_cmd.maxprot, 4))
-                    {
-                        const uint32_t segment_permissions =
-                            ((load_cmd.initprot & VM_PROT_READ) ? ePermissionsReadable : 0) |
-                            ((load_cmd.initprot & VM_PROT_WRITE) ? ePermissionsWritable : 0) |
-                            ((load_cmd.initprot & VM_PROT_EXECUTE) ? ePermissionsExecutable : 0);
-
-                        const bool segment_is_encrypted = (load_cmd.flags & SG_PROTECTED_VERSION_1) != 0;
-
-                        // Keep a list of mach segments around in case we need to
-                        // get at data that isn't stored in the abstracted Sections.
-                        m_mach_segments.push_back (load_cmd);
-
-                        // Use a segment ID of the segment index shifted left by 8 so they
-                        // never conflict with any of the sections.
-                        SectionSP segment_sp;
-                        if (add_section && (const_segname || is_core))
-                        {
-                            segment_sp.reset(new Section (module_sp,              // Module to which this section belongs
-                                                          this,                   // Object file to which this sections belongs
-                                                          ++segID << 8,           // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
-                                                          const_segname,          // Name of this section
-                                                          eSectionTypeContainer,  // This section is a container of other sections.
-                                                          load_cmd.vmaddr,        // File VM address == addresses as they are found in the object file
-                                                          load_cmd.vmsize,        // VM size in bytes of this section
-                                                          load_cmd.fileoff,       // Offset to the data for this section in the file
-                                                          load_cmd.filesize,      // Size in bytes of this section as found in the file
-                                                          0,                      // Segments have no alignment information
-                                                          load_cmd.flags));       // Flags for this section
-
-                            segment_sp->SetIsEncrypted (segment_is_encrypted);
-                            m_sections_ap->AddSection(segment_sp);
-                            segment_sp->SetPermissions(segment_permissions);
-                            if (add_to_unified)
-                                unified_section_list.AddSection(segment_sp);
-                        }
-                        else if (unified_section_sp)
-                        {
-                            if (is_dsym && unified_section_sp->GetFileAddress() != load_cmd.vmaddr)
-                            {
-                                // Check to see if the module was read from memory?
-                                if (module_sp->GetObjectFile()->GetHeaderAddress().IsValid())
-                                {
-                                    // We have a module that is in memory and needs to have its
-                                    // file address adjusted. We need to do this because when we
-                                    // load a file from memory, its addresses will be slid already,
-                                    // yet the addresses in the new symbol file will still be unslid.
-                                    // Since everything is stored as section offset, this shouldn't
-                                    // cause any problems.
-
-                                    // Make sure we've parsed the symbol table from the 
-                                    // ObjectFile before we go around changing its Sections.
-                                    module_sp->GetObjectFile()->GetSymtab();
-                                    // eh_frame would present the same problems but we parse that on
-                                    // a per-function basis as-needed so it's more difficult to
-                                    // remove its use of the Sections.  Realistically, the environments
-                                    // where this code path will be taken will not have eh_frame sections.
-
-                                    unified_section_sp->SetFileAddress(load_cmd.vmaddr);
-
-                                    // Notify the module that the section addresses have been changed once
-                                    // we're done so any file-address caches can be updated.
-                                    section_file_addresses_changed = true;
+                      if (symbol_name == NULL) {
+                        // No symbol should be NULL, even the symbols with no
+                        // string values should have an offset zero which points
+                        // to an empty C-string
+                        Host::SystemLog(
+                            Host::eSystemLogError,
+                            "error: DSC unmapped local symbol[%u] has invalid "
+                            "string table offset 0x%x in %s, ignoring symbol\n",
+                            entry_index, nlist.n_strx,
+                            module_sp->GetFileSpec().GetPath().c_str());
+                        continue;
+                      }
+                      if (symbol_name[0] == '\0')
+                        symbol_name = NULL;
+
+                      const char *symbol_name_non_abi_mangled = NULL;
+
+                      SectionSP symbol_section;
+                      uint32_t symbol_byte_size = 0;
+                      bool add_nlist = true;
+                      bool is_debug = ((nlist.n_type & N_STAB) != 0);
+                      bool demangled_is_synthesized = false;
+                      bool is_gsym = false;
+                      bool set_value = true;
+
+                      assert(sym_idx < num_syms);
+
+                      sym[sym_idx].SetDebug(is_debug);
+
+                      if (is_debug) {
+                        switch (nlist.n_type) {
+                        case N_GSYM:
+                          // global symbol: name,,NO_SECT,type,0
+                          // Sometimes the N_GSYM value contains the address.
+
+                          // FIXME: In the .o files, we have a GSYM and a debug
+                          // symbol for all the ObjC data.  They
+                          // have the same address, but we want to ensure that
+                          // we always find only the real symbol,
+                          // 'cause we don't currently correctly attribute the
+                          // GSYM one to the ObjCClass/Ivar/MetaClass
+                          // symbol type.  This is a temporary hack to make sure
+                          // the ObjectiveC symbols get treated
+                          // correctly.  To do this right, we should coalesce
+                          // all the GSYM & global symbols that have the
+                          // same address.
+
+                          is_gsym = true;
+                          sym[sym_idx].SetExternal(true);
+
+                          if (symbol_name && symbol_name[0] == '_' &&
+                              symbol_name[1] == 'O') {
+                            llvm::StringRef symbol_name_ref(symbol_name);
+                            if (symbol_name_ref.startswith(
+                                    g_objc_v2_prefix_class)) {
+                              symbol_name_non_abi_mangled = symbol_name + 1;
+                              symbol_name =
+                                  symbol_name + g_objc_v2_prefix_class.size();
+                              type = eSymbolTypeObjCClass;
+                              demangled_is_synthesized = true;
+
+                            } else if (symbol_name_ref.startswith(
+                                           g_objc_v2_prefix_metaclass)) {
+                              symbol_name_non_abi_mangled = symbol_name + 1;
+                              symbol_name = symbol_name +
+                                            g_objc_v2_prefix_metaclass.size();
+                              type = eSymbolTypeObjCMetaClass;
+                              demangled_is_synthesized = true;
+                            } else if (symbol_name_ref.startswith(
+                                           g_objc_v2_prefix_ivar)) {
+                              symbol_name_non_abi_mangled = symbol_name + 1;
+                              symbol_name =
+                                  symbol_name + g_objc_v2_prefix_ivar.size();
+                              type = eSymbolTypeObjCIVar;
+                              demangled_is_synthesized = true;
+                            }
+                          } else {
+                            if (nlist.n_value != 0)
+                              symbol_section = section_info.GetSection(
+                                  nlist.n_sect, nlist.n_value);
+                            type = eSymbolTypeData;
+                          }
+                          break;
+
+                        case N_FNAME:
+                          // procedure name (f77 kludge): name,,NO_SECT,0,0
+                          type = eSymbolTypeCompiler;
+                          break;
+
+                        case N_FUN:
+                          // procedure: name,,n_sect,linenumber,address
+                          if (symbol_name) {
+                            type = eSymbolTypeCode;
+                            symbol_section = section_info.GetSection(
+                                nlist.n_sect, nlist.n_value);
+
+                            N_FUN_addr_to_sym_idx.insert(
+                                std::make_pair(nlist.n_value, sym_idx));
+                            // We use the current number of symbols in the
+                            // symbol table in lieu of
+                            // using nlist_idx in case we ever start trimming
+                            // entries out
+                            N_FUN_indexes.push_back(sym_idx);
+                          } else {
+                            type = eSymbolTypeCompiler;
+
+                            if (!N_FUN_indexes.empty()) {
+                              // Copy the size of the function into the original
+                              // STAB entry so we don't have
+                              // to hunt for it later
+                              symtab->SymbolAtIndex(N_FUN_indexes.back())
+                                  ->SetByteSize(nlist.n_value);
+                              N_FUN_indexes.pop_back();
+                              // We don't really need the end function STAB as
+                              // it contains the size which
+                              // we already placed with the original symbol, so
+                              // don't add it if we want a
+                              // minimal symbol table
+                              add_nlist = false;
+                            }
+                          }
+                          break;
+
+                        case N_STSYM:
+                          // static symbol: name,,n_sect,type,address
+                          N_STSYM_addr_to_sym_idx.insert(
+                              std::make_pair(nlist.n_value, sym_idx));
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                          if (symbol_name && symbol_name[0]) {
+                            type = ObjectFile::GetSymbolTypeFromName(
+                                symbol_name + 1, eSymbolTypeData);
+                          }
+                          break;
+
+                        case N_LCSYM:
+                          // .lcomm symbol: name,,n_sect,type,address
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                          type = eSymbolTypeCommonBlock;
+                          break;
+
+                        case N_BNSYM:
+                          // We use the current number of symbols in the symbol
+                          // table in lieu of
+                          // using nlist_idx in case we ever start trimming
+                          // entries out
+                          // Skip these if we want minimal symbol tables
+                          add_nlist = false;
+                          break;
+
+                        case N_ENSYM:
+                          // Set the size of the N_BNSYM to the terminating
+                          // index of this N_ENSYM
+                          // so that we can always skip the entire symbol if we
+                          // need to navigate
+                          // more quickly at the source level when parsing STABS
+                          // Skip these if we want minimal symbol tables
+                          add_nlist = false;
+                          break;
+
+                        case N_OPT:
+                          // emitted with gcc2_compiled and in gcc source
+                          type = eSymbolTypeCompiler;
+                          break;
+
+                        case N_RSYM:
+                          // register sym: name,,NO_SECT,type,register
+                          type = eSymbolTypeVariable;
+                          break;
+
+                        case N_SLINE:
+                          // src line: 0,,n_sect,linenumber,address
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                          type = eSymbolTypeLineEntry;
+                          break;
+
+                        case N_SSYM:
+                          // structure elt: name,,NO_SECT,type,struct_offset
+                          type = eSymbolTypeVariableType;
+                          break;
+
+                        case N_SO:
+                          // source file name
+                          type = eSymbolTypeSourceFile;
+                          if (symbol_name == NULL) {
+                            add_nlist = false;
+                            if (N_SO_index != UINT32_MAX) {
+                              // Set the size of the N_SO to the terminating
+                              // index of this N_SO
+                              // so that we can always skip the entire N_SO if
+                              // we need to navigate
+                              // more quickly at the source level when parsing
+                              // STABS
+                              symbol_ptr = symtab->SymbolAtIndex(N_SO_index);
+                              symbol_ptr->SetByteSize(sym_idx);
+                              symbol_ptr->SetSizeIsSibling(true);
+                            }
+                            N_NSYM_indexes.clear();
+                            N_INCL_indexes.clear();
+                            N_BRAC_indexes.clear();
+                            N_COMM_indexes.clear();
+                            N_FUN_indexes.clear();
+                            N_SO_index = UINT32_MAX;
+                          } else {
+                            // We use the current number of symbols in the
+                            // symbol table in lieu of
+                            // using nlist_idx in case we ever start trimming
+                            // entries out
+                            const bool N_SO_has_full_path =
+                                symbol_name[0] == '/';
+                            if (N_SO_has_full_path) {
+                              if ((N_SO_index == sym_idx - 1) &&
+                                  ((sym_idx - 1) < num_syms)) {
+                                // We have two consecutive N_SO entries where
+                                // the first contains a directory
+                                // and the second contains a full path.
+                                sym[sym_idx - 1].GetMangled().SetValue(
+                                    ConstString(symbol_name), false);
+                                m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
+                                add_nlist = false;
+                              } else {
+                                // This is the first entry in a N_SO that
+                                // contains a directory or
+                                // a full path to the source file
+                                N_SO_index = sym_idx;
+                              }
+                            } else if ((N_SO_index == sym_idx - 1) &&
+                                       ((sym_idx - 1) < num_syms)) {
+                              // This is usually the second N_SO entry that
+                              // contains just the filename,
+                              // so here we combine it with the first one if we
+                              // are minimizing the symbol table
+                              const char *so_path =
+                                  sym[sym_idx - 1]
+                                      .GetMangled()
+                                      .GetDemangledName(
+                                          lldb::eLanguageTypeUnknown)
+                                      .AsCString();
+                              if (so_path && so_path[0]) {
+                                std::string full_so_path(so_path);
+                                const size_t double_slash_pos =
+                                    full_so_path.find("//");
+                                if (double_slash_pos != std::string::npos) {
+                                  // The linker has been generating bad N_SO
+                                  // entries with doubled up paths
+                                  // in the format "%s%s" where the first string
+                                  // in the DW_AT_comp_dir,
+                                  // and the second is the directory for the
+                                  // source file so you end up with
+                                  // a path that looks like "/tmp/src//tmp/src/"
+                                  FileSpec so_dir(so_path, false);
+                                  if (!so_dir.Exists()) {
+                                    so_dir.SetFile(
+                                        &full_so_path[double_slash_pos + 1],
+                                        false);
+                                    if (so_dir.Exists()) {
+                                      // Trim off the incorrect path
+                                      full_so_path.erase(0,
+                                                         double_slash_pos + 1);
+                                    }
+                                  }
                                 }
+                                if (*full_so_path.rbegin() != '/')
+                                  full_so_path += '/';
+                                full_so_path += symbol_name;
+                                sym[sym_idx - 1].GetMangled().SetValue(
+                                    ConstString(full_so_path.c_str()), false);
+                                add_nlist = false;
+                                m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
+                              }
+                            } else {
+                              // This could be a relative path to a N_SO
+                              N_SO_index = sym_idx;
                             }
-                            m_sections_ap->AddSection(unified_section_sp);
-                        }
+                          }
+                          break;
+
+                        case N_OSO:
+                          // object file name: name,,0,0,st_mtime
+                          type = eSymbolTypeObjectFile;
+                          break;
+
+                        case N_LSYM:
+                          // local sym: name,,NO_SECT,type,offset
+                          type = eSymbolTypeLocal;
+                          break;
+
+                        //----------------------------------------------------------------------
+                        // INCL scopes
+                        //----------------------------------------------------------------------
+                        case N_BINCL:
+                          // include file beginning: name,,NO_SECT,0,sum
+                          // We use the current number of symbols in the symbol
+                          // table in lieu of
+                          // using nlist_idx in case we ever start trimming
+                          // entries out
+                          N_INCL_indexes.push_back(sym_idx);
+                          type = eSymbolTypeScopeBegin;
+                          break;
+
+                        case N_EINCL:
+                          // include file end: name,,NO_SECT,0,0
+                          // Set the size of the N_BINCL to the terminating
+                          // index of this N_EINCL
+                          // so that we can always skip the entire symbol if we
+                          // need to navigate
+                          // more quickly at the source level when parsing STABS
+                          if (!N_INCL_indexes.empty()) {
+                            symbol_ptr =
+                                symtab->SymbolAtIndex(N_INCL_indexes.back());
+                            symbol_ptr->SetByteSize(sym_idx + 1);
+                            symbol_ptr->SetSizeIsSibling(true);
+                            N_INCL_indexes.pop_back();
+                          }
+                          type = eSymbolTypeScopeEnd;
+                          break;
+
+                        case N_SOL:
+                          // #included file name: name,,n_sect,0,address
+                          type = eSymbolTypeHeaderFile;
+
+                          // We currently don't use the header files on darwin
+                          add_nlist = false;
+                          break;
+
+                        case N_PARAMS:
+                          // compiler parameters: name,,NO_SECT,0,0
+                          type = eSymbolTypeCompiler;
+                          break;
+
+                        case N_VERSION:
+                          // compiler version: name,,NO_SECT,0,0
+                          type = eSymbolTypeCompiler;
+                          break;
+
+                        case N_OLEVEL:
+                          // compiler -O level: name,,NO_SECT,0,0
+                          type = eSymbolTypeCompiler;
+                          break;
+
+                        case N_PSYM:
+                          // parameter: name,,NO_SECT,type,offset
+                          type = eSymbolTypeVariable;
+                          break;
+
+                        case N_ENTRY:
+                          // alternate entry: name,,n_sect,linenumber,address
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                          type = eSymbolTypeLineEntry;
+                          break;
+
+                        //----------------------------------------------------------------------
+                        // Left and Right Braces
+                        //----------------------------------------------------------------------
+                        case N_LBRAC:
+                          // left bracket: 0,,NO_SECT,nesting level,address
+                          // We use the current number of symbols in the symbol
+                          // table in lieu of
+                          // using nlist_idx in case we ever start trimming
+                          // entries out
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                          N_BRAC_indexes.push_back(sym_idx);
+                          type = eSymbolTypeScopeBegin;
+                          break;
+
+                        case N_RBRAC:
+                          // right bracket: 0,,NO_SECT,nesting level,address
+                          // Set the size of the N_LBRAC to the terminating
+                          // index of this N_RBRAC
+                          // so that we can always skip the entire symbol if we
+                          // need to navigate
+                          // more quickly at the source level when parsing STABS
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                          if (!N_BRAC_indexes.empty()) {
+                            symbol_ptr =
+                                symtab->SymbolAtIndex(N_BRAC_indexes.back());
+                            symbol_ptr->SetByteSize(sym_idx + 1);
+                            symbol_ptr->SetSizeIsSibling(true);
+                            N_BRAC_indexes.pop_back();
+                          }
+                          type = eSymbolTypeScopeEnd;
+                          break;
+
+                        case N_EXCL:
+                          // deleted include file: name,,NO_SECT,0,sum
+                          type = eSymbolTypeHeaderFile;
+                          break;
+
+                        //----------------------------------------------------------------------
+                        // COMM scopes
+                        //----------------------------------------------------------------------
+                        case N_BCOMM:
+                          // begin common: name,,NO_SECT,0,0
+                          // We use the current number of symbols in the symbol
+                          // table in lieu of
+                          // using nlist_idx in case we ever start trimming
+                          // entries out
+                          type = eSymbolTypeScopeBegin;
+                          N_COMM_indexes.push_back(sym_idx);
+                          break;
+
+                        case N_ECOML:
+                          // end common (local name): 0,,n_sect,0,address
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
+                        // Fall through
+
+                        case N_ECOMM:
+                          // end common: name,,n_sect,0,0
+                          // Set the size of the N_BCOMM to the terminating
+                          // index of this N_ECOMM/N_ECOML
+                          // so that we can always skip the entire symbol if we
+                          // need to navigate
+                          // more quickly at the source level when parsing STABS
+                          if (!N_COMM_indexes.empty()) {
+                            symbol_ptr =
+                                symtab->SymbolAtIndex(N_COMM_indexes.back());
+                            symbol_ptr->SetByteSize(sym_idx + 1);
+                            symbol_ptr->SetSizeIsSibling(true);
+                            N_COMM_indexes.pop_back();
+                          }
+                          type = eSymbolTypeScopeEnd;
+                          break;
+
+                        case N_LENG:
+                          // second stab entry with length information
+                          type = eSymbolTypeAdditional;
+                          break;
 
-                        struct section_64 sect64;
-                        ::memset (&sect64, 0, sizeof(sect64));
-                        // Push a section into our mach sections for the section at
-                        // index zero (NO_SECT) if we don't have any mach sections yet...
-                        if (m_mach_sections.empty())
-                            m_mach_sections.push_back(sect64);
-                        uint32_t segment_sect_idx;
-                        const lldb::user_id_t first_segment_sectID = sectID + 1;
+                        default:
+                          break;
+                        }
+                      } else {
+                        // uint8_t n_pext    = N_PEXT & nlist.n_type;
+                        uint8_t n_type = N_TYPE & nlist.n_type;
+                        sym[sym_idx].SetExternal((N_EXT & nlist.n_type) != 0);
+
+                        switch (n_type) {
+                        case N_INDR: {
+                          const char *reexport_name_cstr =
+                              strtab_data.PeekCStr(nlist.n_value);
+                          if (reexport_name_cstr && reexport_name_cstr[0]) {
+                            type = eSymbolTypeReExported;
+                            ConstString reexport_name(
+                                reexport_name_cstr +
+                                ((reexport_name_cstr[0] == '_') ? 1 : 0));
+                            sym[sym_idx].SetReExportedSymbolName(reexport_name);
+                            set_value = false;
+                            reexport_shlib_needs_fixup[sym_idx] = reexport_name;
+                            indirect_symbol_names.insert(
+                                ConstString(symbol_name +
+                                            ((symbol_name[0] == '_') ? 1 : 0)));
+                          } else
+                            type = eSymbolTypeUndefined;
+                        } break;
+
+                        case N_UNDF:
+                          if (symbol_name && symbol_name[0]) {
+                            ConstString undefined_name(
+                                symbol_name +
+                                ((symbol_name[0] == '_') ? 1 : 0));
+                            undefined_name_to_desc[undefined_name] =
+                                nlist.n_desc;
+                          }
+                        // Fall through
+                        case N_PBUD:
+                          type = eSymbolTypeUndefined;
+                          break;
+
+                        case N_ABS:
+                          type = eSymbolTypeAbsolute;
+                          break;
+
+                        case N_SECT: {
+                          symbol_section = section_info.GetSection(
+                              nlist.n_sect, nlist.n_value);
 
+                          if (symbol_section == NULL) {
+                            // TODO: warn about this?
+                            add_nlist = false;
+                            break;
+                          }
 
-                        const uint32_t num_u32s = load_cmd.cmd == LC_SEGMENT ? 7 : 8;
-                        for (segment_sect_idx=0; segment_sect_idx<load_cmd.nsects; ++segment_sect_idx)
-                        {
-                            if (m_data.GetU8(&offset, (uint8_t*)sect64.sectname, sizeof(sect64.sectname)) == NULL)
+                          if (TEXT_eh_frame_sectID == nlist.n_sect) {
+                            type = eSymbolTypeException;
+                          } else {
+                            uint32_t section_type =
+                                symbol_section->Get() & SECTION_TYPE;
+
+                            switch (section_type) {
+                            case S_CSTRING_LITERALS:
+                              type = eSymbolTypeData;
+                              break; // section with only literal C strings
+                            case S_4BYTE_LITERALS:
+                              type = eSymbolTypeData;
+                              break; // section with only 4 byte literals
+                            case S_8BYTE_LITERALS:
+                              type = eSymbolTypeData;
+                              break; // section with only 8 byte literals
+                            case S_LITERAL_POINTERS:
+                              type = eSymbolTypeTrampoline;
+                              break; // section with only pointers to literals
+                            case S_NON_LAZY_SYMBOL_POINTERS:
+                              type = eSymbolTypeTrampoline;
+                              break; // section with only non-lazy symbol
+                                     // pointers
+                            case S_LAZY_SYMBOL_POINTERS:
+                              type = eSymbolTypeTrampoline;
+                              break; // section with only lazy symbol pointers
+                            case S_SYMBOL_STUBS:
+                              type = eSymbolTypeTrampoline;
+                              break; // section with only symbol stubs, byte
+                                     // size of stub in the reserved2 field
+                            case S_MOD_INIT_FUNC_POINTERS:
+                              type = eSymbolTypeCode;
+                              break; // section with only function pointers for
+                                     // initialization
+                            case S_MOD_TERM_FUNC_POINTERS:
+                              type = eSymbolTypeCode;
+                              break; // section with only function pointers for
+                                     // termination
+                            case S_INTERPOSING:
+                              type = eSymbolTypeTrampoline;
+                              break; // section with only pairs of function
+                                     // pointers for interposing
+                            case S_16BYTE_LITERALS:
+                              type = eSymbolTypeData;
+                              break; // section with only 16 byte literals
+                            case S_DTRACE_DOF:
+                              type = eSymbolTypeInstrumentation;
+                              break;
+                            case S_LAZY_DYLIB_SYMBOL_POINTERS:
+                              type = eSymbolTypeTrampoline;
+                              break;
+                            default:
+                              switch (symbol_section->GetType()) {
+                              case lldb::eSectionTypeCode:
+                                type = eSymbolTypeCode;
                                 break;
-                            if (m_data.GetU8(&offset, (uint8_t*)sect64.segname, sizeof(sect64.segname)) == NULL)
+                              case eSectionTypeData:
+                              case eSectionTypeDataCString: // Inlined C string
+                                                            // data
+                              case eSectionTypeDataCStringPointers: // Pointers
+                                                                    // to C
+                                                                    // string
+                                                                    // data
+                              case eSectionTypeDataSymbolAddress: // Address of
+                                                                  // a symbol in
+                                                                  // the symbol
+                                                                  // table
+                              case eSectionTypeData4:
+                              case eSectionTypeData8:
+                              case eSectionTypeData16:
+                                type = eSymbolTypeData;
                                 break;
-                            sect64.addr = m_data.GetAddress(&offset);
-                            sect64.size = m_data.GetAddress(&offset);
-
-                            if (m_data.GetU32(&offset, &sect64.offset, num_u32s) == NULL)
+                              default:
                                 break;
+                              }
+                              break;
+                            }
 
-                            // Keep a list of mach sections around in case we need to
-                            // get at data that isn't stored in the abstracted Sections.
-                            m_mach_sections.push_back (sect64);
-
-                            if (add_section)
-                            {
-                                ConstString section_name (sect64.sectname, std::min<size_t>(strlen(sect64.sectname), sizeof(sect64.sectname)));
-                                if (!const_segname)
-                                {
-                                    // We have a segment with no name so we need to conjure up
-                                    // segments that correspond to the section's segname if there
-                                    // isn't already such a section. If there is such a section,
-                                    // we resize the section so that it spans all sections.
-                                    // We also mark these sections as fake so address matches don't
-                                    // hit if they land in the gaps between the child sections.
-                                    const_segname.SetTrimmedCStringWithLength(sect64.segname, sizeof(sect64.segname));
-                                    segment_sp = unified_section_list.FindSectionByName (const_segname);
-                                    if (segment_sp.get())
-                                    {
-                                        Section *segment = segment_sp.get();
-                                        // Grow the section size as needed.
-                                        const lldb::addr_t sect64_min_addr = sect64.addr;
-                                        const lldb::addr_t sect64_max_addr = sect64_min_addr + sect64.size;
-                                        const lldb::addr_t curr_seg_byte_size = segment->GetByteSize();
-                                        const lldb::addr_t curr_seg_min_addr = segment->GetFileAddress();
-                                        const lldb::addr_t curr_seg_max_addr = curr_seg_min_addr + curr_seg_byte_size;
-                                        if (sect64_min_addr >= curr_seg_min_addr)
-                                        {
-                                            const lldb::addr_t new_seg_byte_size = sect64_max_addr - curr_seg_min_addr;
-                                            // Only grow the section size if needed
-                                            if (new_seg_byte_size > curr_seg_byte_size)
-                                                segment->SetByteSize (new_seg_byte_size);
-                                        }
-                                        else
-                                        {
-                                            // We need to change the base address of the segment and
-                                            // adjust the child section offsets for all existing children.
-                                            const lldb::addr_t slide_amount = sect64_min_addr - curr_seg_min_addr;
-                                            segment->Slide(slide_amount, false);
-                                            segment->GetChildren().Slide(-slide_amount, false);
-                                            segment->SetByteSize (curr_seg_max_addr - sect64_min_addr);
-                                        }
-
-                                        // Grow the section size as needed.
-                                        if (sect64.offset)
-                                        {
-                                            const lldb::addr_t segment_min_file_offset = segment->GetFileOffset();
-                                            const lldb::addr_t segment_max_file_offset = segment_min_file_offset + segment->GetFileSize();
-
-                                            const lldb::addr_t section_min_file_offset = sect64.offset;
-                                            const lldb::addr_t section_max_file_offset = section_min_file_offset + sect64.size;
-                                            const lldb::addr_t new_file_offset = std::min (section_min_file_offset, segment_min_file_offset);
-                                            const lldb::addr_t new_file_size = std::max (section_max_file_offset, segment_max_file_offset) - new_file_offset;
-                                            segment->SetFileOffset (new_file_offset);
-                                            segment->SetFileSize (new_file_size);
-                                        }
-                                    }
-                                    else
-                                    {
-                                        // Create a fake section for the section's named segment
-                                        segment_sp.reset(new Section (segment_sp,            // Parent section
-                                                                      module_sp,             // Module to which this section belongs
-                                                                      this,                  // Object file to which this section belongs
-                                                                      ++segID << 8,          // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
-                                                                      const_segname,         // Name of this section
-                                                                      eSectionTypeContainer, // This section is a container of other sections.
-                                                                      sect64.addr,           // File VM address == addresses as they are found in the object file
-                                                                      sect64.size,           // VM size in bytes of this section
-                                                                      sect64.offset,         // Offset to the data for this section in the file
-                                                                      sect64.offset ? sect64.size : 0,        // Size in bytes of this section as found in the file
-                                                                      sect64.align,
-                                                                      load_cmd.flags));      // Flags for this section
-                                        segment_sp->SetIsFake(true);
-                                        segment_sp->SetPermissions(segment_permissions);
-                                        m_sections_ap->AddSection(segment_sp);
-                                        if (add_to_unified)
-                                            unified_section_list.AddSection(segment_sp);
-                                        segment_sp->SetIsEncrypted (segment_is_encrypted);
+                            if (type == eSymbolTypeInvalid) {
+                              const char *symbol_sect_name =
+                                  symbol_section->GetName().AsCString();
+                              if (symbol_section->IsDescendant(
+                                      text_section_sp.get())) {
+                                if (symbol_section->IsClear(
+                                        S_ATTR_PURE_INSTRUCTIONS |
+                                        S_ATTR_SELF_MODIFYING_CODE |
+                                        S_ATTR_SOME_INSTRUCTIONS))
+                                  type = eSymbolTypeData;
+                                else
+                                  type = eSymbolTypeCode;
+                              } else if (symbol_section->IsDescendant(
+                                             data_section_sp.get()) ||
+                                         symbol_section->IsDescendant(
+                                             data_dirty_section_sp.get()) ||
+                                         symbol_section->IsDescendant(
+                                             data_const_section_sp.get())) {
+                                if (symbol_sect_name &&
+                                    ::strstr(symbol_sect_name, "__objc") ==
+                                        symbol_sect_name) {
+                                  type = eSymbolTypeRuntime;
+
+                                  if (symbol_name) {
+                                    llvm::StringRef symbol_name_ref(
+                                        symbol_name);
+                                    if (symbol_name_ref.startswith("_OBJC_")) {
+                                      static const llvm::StringRef
+                                          g_objc_v2_prefix_class(
+                                              "_OBJC_CLASS_$_");
+                                      static const llvm::StringRef
+                                          g_objc_v2_prefix_metaclass(
+                                              "_OBJC_METACLASS_$_");
+                                      static const llvm::StringRef
+                                          g_objc_v2_prefix_ivar(
+                                              "_OBJC_IVAR_$_");
+                                      if (symbol_name_ref.startswith(
+                                              g_objc_v2_prefix_class)) {
+                                        symbol_name_non_abi_mangled =
+                                            symbol_name + 1;
+                                        symbol_name =
+                                            symbol_name +
+                                            g_objc_v2_prefix_class.size();
+                                        type = eSymbolTypeObjCClass;
+                                        demangled_is_synthesized = true;
+                                      } else if (
+                                          symbol_name_ref.startswith(
+                                              g_objc_v2_prefix_metaclass)) {
+                                        symbol_name_non_abi_mangled =
+                                            symbol_name + 1;
+                                        symbol_name =
+                                            symbol_name +
+                                            g_objc_v2_prefix_metaclass.size();
+                                        type = eSymbolTypeObjCMetaClass;
+                                        demangled_is_synthesized = true;
+                                      } else if (symbol_name_ref.startswith(
+                                                     g_objc_v2_prefix_ivar)) {
+                                        symbol_name_non_abi_mangled =
+                                            symbol_name + 1;
+                                        symbol_name =
+                                            symbol_name +
+                                            g_objc_v2_prefix_ivar.size();
+                                        type = eSymbolTypeObjCIVar;
+                                        demangled_is_synthesized = true;
+                                      }
                                     }
+                                  }
+                                } else if (symbol_sect_name &&
+                                           ::strstr(symbol_sect_name,
+                                                    "__gcc_except_tab") ==
+                                               symbol_sect_name) {
+                                  type = eSymbolTypeException;
+                                } else {
+                                  type = eSymbolTypeData;
+                                }
+                              } else if (symbol_sect_name &&
+                                         ::strstr(symbol_sect_name,
+                                                  "__IMPORT") ==
+                                             symbol_sect_name) {
+                                type = eSymbolTypeTrampoline;
+                              } else if (symbol_section->IsDescendant(
+                                             objc_section_sp.get())) {
+                                type = eSymbolTypeRuntime;
+                                if (symbol_name && symbol_name[0] == '.') {
+                                  llvm::StringRef symbol_name_ref(symbol_name);
+                                  static const llvm::StringRef
+                                      g_objc_v1_prefix_class(
+                                          ".objc_class_name_");
+                                  if (symbol_name_ref.startswith(
+                                          g_objc_v1_prefix_class)) {
+                                    symbol_name_non_abi_mangled = symbol_name;
+                                    symbol_name = symbol_name +
+                                                  g_objc_v1_prefix_class.size();
+                                    type = eSymbolTypeObjCClass;
+                                    demangled_is_synthesized = true;
+                                  }
                                 }
-                                assert (segment_sp.get());
+                              }
+                            }
+                          }
+                        } break;
+                        }
+                      }
 
-                                lldb::SectionType sect_type = eSectionTypeOther;
+                      if (add_nlist) {
+                        uint64_t symbol_value = nlist.n_value;
+                        if (symbol_name_non_abi_mangled) {
+                          sym[sym_idx].GetMangled().SetMangledName(
+                              ConstString(symbol_name_non_abi_mangled));
+                          sym[sym_idx].GetMangled().SetDemangledName(
+                              ConstString(symbol_name));
+                        } else {
+                          bool symbol_name_is_mangled = false;
 
-                                if (sect64.flags & (S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS))
-                                    sect_type = eSectionTypeCode;
-                                else
-                                {
-                                    uint32_t mach_sect_type = sect64.flags & SECTION_TYPE;
-                                    static ConstString g_sect_name_objc_data ("__objc_data");
-                                    static ConstString g_sect_name_objc_msgrefs ("__objc_msgrefs");
-                                    static ConstString g_sect_name_objc_selrefs ("__objc_selrefs");
-                                    static ConstString g_sect_name_objc_classrefs ("__objc_classrefs");
-                                    static ConstString g_sect_name_objc_superrefs ("__objc_superrefs");
-                                    static ConstString g_sect_name_objc_const ("__objc_const");
-                                    static ConstString g_sect_name_objc_classlist ("__objc_classlist");
-                                    static ConstString g_sect_name_cfstring ("__cfstring");
-
-                                    static ConstString g_sect_name_dwarf_debug_abbrev ("__debug_abbrev");
-                                    static ConstString g_sect_name_dwarf_debug_aranges ("__debug_aranges");
-                                    static ConstString g_sect_name_dwarf_debug_frame ("__debug_frame");
-                                    static ConstString g_sect_name_dwarf_debug_info ("__debug_info");
-                                    static ConstString g_sect_name_dwarf_debug_line ("__debug_line");
-                                    static ConstString g_sect_name_dwarf_debug_loc ("__debug_loc");
-                                    static ConstString g_sect_name_dwarf_debug_macinfo ("__debug_macinfo");
-                                    static ConstString g_sect_name_dwarf_debug_pubnames ("__debug_pubnames");
-                                    static ConstString g_sect_name_dwarf_debug_pubtypes ("__debug_pubtypes");
-                                    static ConstString g_sect_name_dwarf_debug_ranges ("__debug_ranges");
-                                    static ConstString g_sect_name_dwarf_debug_str ("__debug_str");
-                                    static ConstString g_sect_name_dwarf_apple_names ("__apple_names");
-                                    static ConstString g_sect_name_dwarf_apple_types ("__apple_types");
-                                    static ConstString g_sect_name_dwarf_apple_namespaces ("__apple_namespac");
-                                    static ConstString g_sect_name_dwarf_apple_objc ("__apple_objc");
-                                    static ConstString g_sect_name_eh_frame ("__eh_frame");
-                                    static ConstString g_sect_name_compact_unwind ("__unwind_info");
-                                    static ConstString g_sect_name_text ("__text");
-                                    static ConstString g_sect_name_data ("__data");
-                                    static ConstString g_sect_name_go_symtab ("__gosymtab");
-
-                                    if (section_name == g_sect_name_dwarf_debug_abbrev)
-                                        sect_type = eSectionTypeDWARFDebugAbbrev;
-                                    else if (section_name == g_sect_name_dwarf_debug_aranges)
-                                        sect_type = eSectionTypeDWARFDebugAranges;
-                                    else if (section_name == g_sect_name_dwarf_debug_frame)
-                                        sect_type = eSectionTypeDWARFDebugFrame;
-                                    else if (section_name == g_sect_name_dwarf_debug_info)
-                                        sect_type = eSectionTypeDWARFDebugInfo;
-                                    else if (section_name == g_sect_name_dwarf_debug_line)
-                                        sect_type = eSectionTypeDWARFDebugLine;
-                                    else if (section_name == g_sect_name_dwarf_debug_loc)
-                                        sect_type = eSectionTypeDWARFDebugLoc;
-                                    else if (section_name == g_sect_name_dwarf_debug_macinfo)
-                                        sect_type = eSectionTypeDWARFDebugMacInfo;
-                                    else if (section_name == g_sect_name_dwarf_debug_pubnames)
-                                        sect_type = eSectionTypeDWARFDebugPubNames;
-                                    else if (section_name == g_sect_name_dwarf_debug_pubtypes)
-                                        sect_type = eSectionTypeDWARFDebugPubTypes;
-                                    else if (section_name == g_sect_name_dwarf_debug_ranges)
-                                        sect_type = eSectionTypeDWARFDebugRanges;
-                                    else if (section_name == g_sect_name_dwarf_debug_str)
-                                        sect_type = eSectionTypeDWARFDebugStr;
-                                    else if (section_name == g_sect_name_dwarf_apple_names)
-                                        sect_type = eSectionTypeDWARFAppleNames;
-                                    else if (section_name == g_sect_name_dwarf_apple_types)
-                                        sect_type = eSectionTypeDWARFAppleTypes;
-                                    else if (section_name == g_sect_name_dwarf_apple_namespaces)
-                                        sect_type = eSectionTypeDWARFAppleNamespaces;
-                                    else if (section_name == g_sect_name_dwarf_apple_objc)
-                                        sect_type = eSectionTypeDWARFAppleObjC;
-                                    else if (section_name == g_sect_name_objc_selrefs)
-                                        sect_type = eSectionTypeDataCStringPointers;
-                                    else if (section_name == g_sect_name_objc_msgrefs)
-                                        sect_type = eSectionTypeDataObjCMessageRefs;
-                                    else if (section_name == g_sect_name_eh_frame)
-                                        sect_type = eSectionTypeEHFrame;
-                                    else if (section_name == g_sect_name_compact_unwind)
-                                        sect_type = eSectionTypeCompactUnwind;
-                                    else if (section_name == g_sect_name_cfstring)
-                                        sect_type = eSectionTypeDataObjCCFStrings;
-                                    else if (section_name == g_sect_name_go_symtab)
-                                        sect_type = eSectionTypeGoSymtab;
-                                    else if (section_name == g_sect_name_objc_data ||
-                                             section_name == g_sect_name_objc_classrefs ||
-                                             section_name == g_sect_name_objc_superrefs ||
-                                             section_name == g_sect_name_objc_const ||
-                                             section_name == g_sect_name_objc_classlist)
-                                    {
-                                        sect_type = eSectionTypeDataPointers;
-                                    }
+                          if (symbol_name && symbol_name[0] == '_') {
+                            symbol_name_is_mangled = symbol_name[1] == '_';
+                            symbol_name++; // Skip the leading underscore
+                          }
 
-                                    if (sect_type == eSectionTypeOther)
-                                    {
-                                        switch (mach_sect_type)
-                                        {
-                                        // TODO: categorize sections by other flags for regular sections
-                                        case S_REGULAR:
-                                            if (section_name == g_sect_name_text)
-                                                sect_type = eSectionTypeCode;
-                                            else if (section_name == g_sect_name_data)
-                                                sect_type = eSectionTypeData;
-                                            else
-                                                sect_type = eSectionTypeOther;
-                                            break;
-                                        case S_ZEROFILL:                   sect_type = eSectionTypeZeroFill; break;
-                                        case S_CSTRING_LITERALS:           sect_type = eSectionTypeDataCString;    break; // section with only literal C strings
-                                        case S_4BYTE_LITERALS:             sect_type = eSectionTypeData4;    break; // section with only 4 byte literals
-                                        case S_8BYTE_LITERALS:             sect_type = eSectionTypeData8;    break; // section with only 8 byte literals
-                                        case S_LITERAL_POINTERS:           sect_type = eSectionTypeDataPointers;  break; // section with only pointers to literals
-                                        case S_NON_LAZY_SYMBOL_POINTERS:   sect_type = eSectionTypeDataPointers;  break; // section with only non-lazy symbol pointers
-                                        case S_LAZY_SYMBOL_POINTERS:       sect_type = eSectionTypeDataPointers;  break; // section with only lazy symbol pointers
-                                        case S_SYMBOL_STUBS:               sect_type = eSectionTypeCode;  break; // section with only symbol stubs, byte size of stub in the reserved2 field
-                                        case S_MOD_INIT_FUNC_POINTERS:     sect_type = eSectionTypeDataPointers;    break; // section with only function pointers for initialization
-                                        case S_MOD_TERM_FUNC_POINTERS:     sect_type = eSectionTypeDataPointers; break; // section with only function pointers for termination
-                                        case S_COALESCED:                  sect_type = eSectionTypeOther; break;
-                                        case S_GB_ZEROFILL:                sect_type = eSectionTypeZeroFill; break;
-                                        case S_INTERPOSING:                sect_type = eSectionTypeCode;  break; // section with only pairs of function pointers for interposing
-                                        case S_16BYTE_LITERALS:            sect_type = eSectionTypeData16; break; // section with only 16 byte literals
-                                        case S_DTRACE_DOF:                 sect_type = eSectionTypeDebug; break;
-                                        case S_LAZY_DYLIB_SYMBOL_POINTERS: sect_type = eSectionTypeDataPointers;  break;
-                                        default: break;
-                                        }
-                                    }
-                                }
+                          if (symbol_name) {
+                            ConstString const_symbol_name(symbol_name);
+                            sym[sym_idx].GetMangled().SetValue(
+                                const_symbol_name, symbol_name_is_mangled);
+                            if (is_gsym && is_debug) {
+                              const char *gsym_name =
+                                  sym[sym_idx]
+                                      .GetMangled()
+                                      .GetName(lldb::eLanguageTypeUnknown,
+                                               Mangled::ePreferMangled)
+                                      .GetCString();
+                              if (gsym_name)
+                                N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
+                            }
+                          }
+                        }
+                        if (symbol_section) {
+                          const addr_t section_file_addr =
+                              symbol_section->GetFileAddress();
+                          if (symbol_byte_size == 0 &&
+                              function_starts_count > 0) {
+                            addr_t symbol_lookup_file_addr = nlist.n_value;
+                            // Do an exact address match for non-ARM addresses,
+                            // else get the closest since
+                            // the symbol might be a thumb symbol which has an
+                            // address with bit zero set
+                            FunctionStarts::Entry *func_start_entry =
+                                function_starts.FindEntry(
+                                    symbol_lookup_file_addr, !is_arm);
+                            if (is_arm && func_start_entry) {
+                              // Verify that the function start address is the
+                              // symbol address (ARM)
+                              // or the symbol address + 1 (thumb)
+                              if (func_start_entry->addr !=
+                                      symbol_lookup_file_addr &&
+                                  func_start_entry->addr !=
+                                      (symbol_lookup_file_addr + 1)) {
+                                // Not the right entry, NULL it out...
+                                func_start_entry = NULL;
+                              }
+                            }
+                            if (func_start_entry) {
+                              func_start_entry->data = true;
 
-                                SectionSP section_sp(new Section (segment_sp,
-                                                                  module_sp,
-                                                                  this,
-                                                                  ++sectID,
-                                                                  section_name,
-                                                                  sect_type,
-                                                                  sect64.addr - segment_sp->GetFileAddress(),
-                                                                  sect64.size,
-                                                                  sect64.offset,
-                                                                  sect64.offset == 0 ? 0 : sect64.size,
-                                                                  sect64.align,
-                                                                  sect64.flags));
-                                // Set the section to be encrypted to match the segment
-
-                                bool section_is_encrypted = false;
-                                if (!segment_is_encrypted && load_cmd.filesize != 0)
-                                    section_is_encrypted = encrypted_file_ranges.FindEntryThatContains(sect64.offset) != NULL;
-
-                                section_sp->SetIsEncrypted (segment_is_encrypted || section_is_encrypted);
-                                section_sp->SetPermissions(segment_permissions);
-                                segment_sp->GetChildren().AddSection(section_sp);
-
-                                if (segment_sp->IsFake())
-                                {
-                                    segment_sp.reset();
-                                    const_segname.Clear();
-                                }
+                              addr_t symbol_file_addr = func_start_entry->addr;
+                              uint32_t symbol_flags = 0;
+                              if (is_arm) {
+                                if (symbol_file_addr & 1)
+                                  symbol_flags =
+                                      MACHO_NLIST_ARM_SYMBOL_IS_THUMB;
+                                symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+                              }
+
+                              const FunctionStarts::Entry
+                                  *next_func_start_entry =
+                                      function_starts.FindNextEntry(
+                                          func_start_entry);
+                              const addr_t section_end_file_addr =
+                                  section_file_addr +
+                                  symbol_section->GetByteSize();
+                              if (next_func_start_entry) {
+                                addr_t next_symbol_file_addr =
+                                    next_func_start_entry->addr;
+                                // Be sure the clear the Thumb address bit when
+                                // we calculate the size
+                                // from the current and next address
+                                if (is_arm)
+                                  next_symbol_file_addr &=
+                                      THUMB_ADDRESS_BIT_MASK;
+                                symbol_byte_size = std::min<lldb::addr_t>(
+                                    next_symbol_file_addr - symbol_file_addr,
+                                    section_end_file_addr - symbol_file_addr);
+                              } else {
+                                symbol_byte_size =
+                                    section_end_file_addr - symbol_file_addr;
+                              }
                             }
+                          }
+                          symbol_value -= section_file_addr;
                         }
-                        if (segment_sp && is_dsym)
-                        {
-                            if (first_segment_sectID <= sectID)
-                            {
-                                lldb::user_id_t sect_uid;
-                                for (sect_uid = first_segment_sectID; sect_uid <= sectID; ++sect_uid)
-                                {
-                                    SectionSP curr_section_sp(segment_sp->GetChildren().FindSectionByID (sect_uid));
-                                    SectionSP next_section_sp;
-                                    if (sect_uid + 1 <= sectID)
-                                        next_section_sp = segment_sp->GetChildren().FindSectionByID (sect_uid+1);
-
-                                    if (curr_section_sp.get())
-                                    {
-                                        if (curr_section_sp->GetByteSize() == 0)
-                                        {
-                                            if (next_section_sp.get() != NULL)
-                                                curr_section_sp->SetByteSize ( next_section_sp->GetFileAddress() - curr_section_sp->GetFileAddress() );
-                                            else
-                                                curr_section_sp->SetByteSize ( load_cmd.vmsize );
-                                        }
-                                    }
+
+                        if (is_debug == false) {
+                          if (type == eSymbolTypeCode) {
+                            // See if we can find a N_FUN entry for any code
+                            // symbols.
+                            // If we do find a match, and the name matches, then
+                            // we
+                            // can merge the two into just the function symbol
+                            // to avoid
+                            // duplicate entries in the symbol table
+                            std::pair<ValueToSymbolIndexMap::const_iterator,
+                                      ValueToSymbolIndexMap::const_iterator>
+                                range;
+                            range = N_FUN_addr_to_sym_idx.equal_range(
+                                nlist.n_value);
+                            if (range.first != range.second) {
+                              bool found_it = false;
+                              for (ValueToSymbolIndexMap::const_iterator pos =
+                                       range.first;
+                                   pos != range.second; ++pos) {
+                                if (sym[sym_idx].GetMangled().GetName(
+                                        lldb::eLanguageTypeUnknown,
+                                        Mangled::ePreferMangled) ==
+                                    sym[pos->second].GetMangled().GetName(
+                                        lldb::eLanguageTypeUnknown,
+                                        Mangled::ePreferMangled)) {
+                                  m_nlist_idx_to_sym_idx[nlist_idx] =
+                                      pos->second;
+                                  // We just need the flags from the linker
+                                  // symbol, so put these flags
+                                  // into the N_FUN flags to avoid duplicate
+                                  // symbols in the symbol table
+                                  sym[pos->second].SetExternal(
+                                      sym[sym_idx].IsExternal());
+                                  sym[pos->second].SetFlags(nlist.n_type << 16 |
+                                                            nlist.n_desc);
+                                  if (resolver_addresses.find(nlist.n_value) !=
+                                      resolver_addresses.end())
+                                    sym[pos->second].SetType(
+                                        eSymbolTypeResolver);
+                                  sym[sym_idx].Clear();
+                                  found_it = true;
+                                  break;
+                                }
+                              }
+                              if (found_it)
+                                continue;
+                            } else {
+                              if (resolver_addresses.find(nlist.n_value) !=
+                                  resolver_addresses.end())
+                                type = eSymbolTypeResolver;
+                            }
+                          } else if (type == eSymbolTypeData ||
+                                     type == eSymbolTypeObjCClass ||
+                                     type == eSymbolTypeObjCMetaClass ||
+                                     type == eSymbolTypeObjCIVar) {
+                            // See if we can find a N_STSYM entry for any data
+                            // symbols.
+                            // If we do find a match, and the name matches, then
+                            // we
+                            // can merge the two into just the Static symbol to
+                            // avoid
+                            // duplicate entries in the symbol table
+                            std::pair<ValueToSymbolIndexMap::const_iterator,
+                                      ValueToSymbolIndexMap::const_iterator>
+                                range;
+                            range = N_STSYM_addr_to_sym_idx.equal_range(
+                                nlist.n_value);
+                            if (range.first != range.second) {
+                              bool found_it = false;
+                              for (ValueToSymbolIndexMap::const_iterator pos =
+                                       range.first;
+                                   pos != range.second; ++pos) {
+                                if (sym[sym_idx].GetMangled().GetName(
+                                        lldb::eLanguageTypeUnknown,
+                                        Mangled::ePreferMangled) ==
+                                    sym[pos->second].GetMangled().GetName(
+                                        lldb::eLanguageTypeUnknown,
+                                        Mangled::ePreferMangled)) {
+                                  m_nlist_idx_to_sym_idx[nlist_idx] =
+                                      pos->second;
+                                  // We just need the flags from the linker
+                                  // symbol, so put these flags
+                                  // into the N_STSYM flags to avoid duplicate
+                                  // symbols in the symbol table
+                                  sym[pos->second].SetExternal(
+                                      sym[sym_idx].IsExternal());
+                                  sym[pos->second].SetFlags(nlist.n_type << 16 |
+                                                            nlist.n_desc);
+                                  sym[sym_idx].Clear();
+                                  found_it = true;
+                                  break;
+                                }
+                              }
+                              if (found_it)
+                                continue;
+                            } else {
+                              const char *gsym_name =
+                                  sym[sym_idx]
+                                      .GetMangled()
+                                      .GetName(lldb::eLanguageTypeUnknown,
+                                               Mangled::ePreferMangled)
+                                      .GetCString();
+                              if (gsym_name) {
+                                // Combine N_GSYM stab entries with the non stab
+                                // symbol
+                                ConstNameToSymbolIndexMap::const_iterator pos =
+                                    N_GSYM_name_to_sym_idx.find(gsym_name);
+                                if (pos != N_GSYM_name_to_sym_idx.end()) {
+                                  const uint32_t GSYM_sym_idx = pos->second;
+                                  m_nlist_idx_to_sym_idx[nlist_idx] =
+                                      GSYM_sym_idx;
+                                  // Copy the address, because often the N_GSYM
+                                  // address has an invalid address of zero
+                                  // when the global is a common symbol
+                                  sym[GSYM_sym_idx].GetAddressRef().SetSection(
+                                      symbol_section);
+                                  sym[GSYM_sym_idx].GetAddressRef().SetOffset(
+                                      symbol_value);
+                                  // We just need the flags from the linker
+                                  // symbol, so put these flags
+                                  // into the N_GSYM flags to avoid duplicate
+                                  // symbols in the symbol table
+                                  sym[GSYM_sym_idx].SetFlags(
+                                      nlist.n_type << 16 | nlist.n_desc);
+                                  sym[sym_idx].Clear();
+                                  continue;
                                 }
+                              }
                             }
+                          }
                         }
-                    }
-                }
-            }
-            else if (load_cmd.cmd == LC_DYSYMTAB)
-            {
-                m_dysymtab.cmd = load_cmd.cmd;
-                m_dysymtab.cmdsize = load_cmd.cmdsize;
-                m_data.GetU32 (&offset, &m_dysymtab.ilocalsym, (sizeof(m_dysymtab) / sizeof(uint32_t)) - 2);
-            }
-
-            offset = load_cmd_offset + load_cmd.cmdsize;
-        }
 
+                        sym[sym_idx].SetID(nlist_idx);
+                        sym[sym_idx].SetType(type);
+                        if (set_value) {
+                          sym[sym_idx].GetAddressRef().SetSection(
+                              symbol_section);
+                          sym[sym_idx].GetAddressRef().SetOffset(symbol_value);
+                        }
+                        sym[sym_idx].SetFlags(nlist.n_type << 16 |
+                                              nlist.n_desc);
 
-        if (section_file_addresses_changed && module_sp.get())
-        {
-            module_sp->SectionFileAddressesChanged();
-        }
-    }
-}
+                        if (symbol_byte_size > 0)
+                          sym[sym_idx].SetByteSize(symbol_byte_size);
 
-class MachSymtabSectionInfo
-{
-public:
-    MachSymtabSectionInfo (SectionList *section_list) :
-        m_section_list (section_list),
-        m_section_infos()
-    {
-        // Get the number of sections down to a depth of 1 to include
-        // all segments and their sections, but no other sections that
-        // may be added for debug map or
-        m_section_infos.resize(section_list->GetNumSections(1));
-    }
-
-    SectionSP
-    GetSection (uint8_t n_sect, addr_t file_addr)
-    {
-        if (n_sect == 0)
-            return SectionSP();
-        if (n_sect < m_section_infos.size())
-        {
-            if (!m_section_infos[n_sect].section_sp)
-            {
-                SectionSP section_sp (m_section_list->FindSectionByID (n_sect));
-                m_section_infos[n_sect].section_sp = section_sp;
-                if (section_sp)
-                {
-                    m_section_infos[n_sect].vm_range.SetBaseAddress (section_sp->GetFileAddress());
-                    m_section_infos[n_sect].vm_range.SetByteSize (section_sp->GetByteSize());
+                        if (demangled_is_synthesized)
+                          sym[sym_idx].SetDemangledNameIsSynthesized(true);
+                        ++sym_idx;
+                      } else {
+                        sym[sym_idx].Clear();
+                      }
+                    }
+                    /////////////////////////////
+                  }
+                  break; // No more entries to consider
                 }
-                else
-                {
-                    Host::SystemLog (Host::eSystemLogError, "error: unable to find section for section %u\n", n_sect);
+              }
+
+              for (const auto &pos : reexport_shlib_needs_fixup) {
+                const auto undef_pos = undefined_name_to_desc.find(pos.second);
+                if (undef_pos != undefined_name_to_desc.end()) {
+                  const uint8_t dylib_ordinal =
+                      llvm::MachO::GET_LIBRARY_ORDINAL(undef_pos->second);
+                  if (dylib_ordinal > 0 &&
+                      dylib_ordinal < dylib_files.GetSize())
+                    sym[pos.first].SetReExportedSymbolSharedLibrary(
+                        dylib_files.GetFileSpecAtIndex(dylib_ordinal - 1));
                 }
+              }
             }
-            if (m_section_infos[n_sect].vm_range.Contains(file_addr))
-            {
-                // Symbol is in section.
-                return m_section_infos[n_sect].section_sp;
-            }
-            else if (m_section_infos[n_sect].vm_range.GetByteSize () == 0 &&
-                     m_section_infos[n_sect].vm_range.GetBaseAddress() == file_addr)
-            {
-                // Symbol is in section with zero size, but has the same start
-                // address as the section. This can happen with linker symbols
-                // (symbols that start with the letter 'l' or 'L'.
-                return m_section_infos[n_sect].section_sp;
-            }
+          }
         }
-        return m_section_list->FindSectionContainingFileAddress(file_addr);
+      }
     }
 
-protected:
-    struct SectionInfo
-    {
-        SectionInfo () :
-            vm_range(),
-            section_sp ()
-        {
-        }
-
-        VMRange vm_range;
-        SectionSP section_sp;
-    };
-    SectionList *m_section_list;
-    std::vector<SectionInfo> m_section_infos;
-};
+    // Must reset this in case it was mutated above!
+    nlist_data_offset = 0;
+#endif
 
-struct TrieEntry
-{
-    TrieEntry () :
-        name(),
-        address(LLDB_INVALID_ADDRESS),
-        flags (0),
-        other(0),
-        import_name()
-    {
-    }
-    
-    void
-    Clear ()
-    {
-        name.Clear();
-        address = LLDB_INVALID_ADDRESS;
-        flags = 0;
-        other = 0;
-        import_name.Clear();
-    }
-    
-    void
-    Dump () const
-    {
-        printf ("0x%16.16llx 0x%16.16llx 0x%16.16llx \"%s\"",
-                static_cast<unsigned long long>(address),
-                static_cast<unsigned long long>(flags),
-                static_cast<unsigned long long>(other), name.GetCString());
-        if (import_name)
-            printf (" -> \"%s\"\n", import_name.GetCString());
-        else
-            printf ("\n");
-    }
-    ConstString		name;
-    uint64_t		address;
-    uint64_t		flags;
-    uint64_t		other;
-    ConstString		import_name;
-};
+    if (nlist_data.GetByteSize() > 0) {
 
-struct TrieEntryWithOffset
-{
-	lldb::offset_t nodeOffset;
-	TrieEntry entry;
-
-    TrieEntryWithOffset (lldb::offset_t offset) :
-        nodeOffset (offset),
-        entry()
-    {
-    }
-
-    void
-    Dump (uint32_t idx) const
-    {
-        printf ("[%3u] 0x%16.16llx: ", idx,
-                static_cast<unsigned long long>(nodeOffset));
-        entry.Dump();
-    }
-
-	bool
-    operator<(const TrieEntryWithOffset& other) const
-    {
-        return ( nodeOffset < other.nodeOffset );
-    }
-};
+      // If the sym array was not created while parsing the DSC unmapped
+      // symbols, create it now.
+      if (sym == NULL) {
+        sym = symtab->Resize(symtab_load_command.nsyms +
+                             m_dysymtab.nindirectsyms);
+        num_syms = symtab->GetNumSymbols();
+      }
+
+      if (unmapped_local_symbols_found) {
+        assert(m_dysymtab.ilocalsym == 0);
+        nlist_data_offset += (m_dysymtab.nlocalsym * nlist_byte_size);
+        nlist_idx = m_dysymtab.nlocalsym;
+      } else {
+        nlist_idx = 0;
+      }
+
+      typedef std::map<ConstString, uint16_t> UndefinedNameToDescMap;
+      typedef std::map<uint32_t, ConstString> SymbolIndexToName;
+      UndefinedNameToDescMap undefined_name_to_desc;
+      SymbolIndexToName reexport_shlib_needs_fixup;
+      for (; nlist_idx < symtab_load_command.nsyms; ++nlist_idx) {
+        struct nlist_64 nlist;
+        if (!nlist_data.ValidOffsetForDataOfSize(nlist_data_offset,
+                                                 nlist_byte_size))
+          break;
+
+        nlist.n_strx = nlist_data.GetU32_unchecked(&nlist_data_offset);
+        nlist.n_type = nlist_data.GetU8_unchecked(&nlist_data_offset);
+        nlist.n_sect = nlist_data.GetU8_unchecked(&nlist_data_offset);
+        nlist.n_desc = nlist_data.GetU16_unchecked(&nlist_data_offset);
+        nlist.n_value = nlist_data.GetAddress_unchecked(&nlist_data_offset);
+
+        SymbolType type = eSymbolTypeInvalid;
+        const char *symbol_name = NULL;
+
+        if (have_strtab_data) {
+          symbol_name = strtab_data.PeekCStr(nlist.n_strx);
+
+          if (symbol_name == NULL) {
+            // No symbol should be NULL, even the symbols with no
+            // string values should have an offset zero which points
+            // to an empty C-string
+            Host::SystemLog(Host::eSystemLogError,
+                            "error: symbol[%u] has invalid string table offset "
+                            "0x%x in %s, ignoring symbol\n",
+                            nlist_idx, nlist.n_strx,
+                            module_sp->GetFileSpec().GetPath().c_str());
+            continue;
+          }
+          if (symbol_name[0] == '\0')
+            symbol_name = NULL;
+        } else {
+          const addr_t str_addr = strtab_addr + nlist.n_strx;
+          Error str_error;
+          if (process->ReadCStringFromMemory(str_addr, memory_symbol_name,
+                                             str_error))
+            symbol_name = memory_symbol_name.c_str();
+        }
+        const char *symbol_name_non_abi_mangled = NULL;
+
+        SectionSP symbol_section;
+        lldb::addr_t symbol_byte_size = 0;
+        bool add_nlist = true;
+        bool is_gsym = false;
+        bool is_debug = ((nlist.n_type & N_STAB) != 0);
+        bool demangled_is_synthesized = false;
+        bool set_value = true;
+        assert(sym_idx < num_syms);
+
+        sym[sym_idx].SetDebug(is_debug);
+
+        if (is_debug) {
+          switch (nlist.n_type) {
+          case N_GSYM:
+            // global symbol: name,,NO_SECT,type,0
+            // Sometimes the N_GSYM value contains the address.
+
+            // FIXME: In the .o files, we have a GSYM and a debug symbol for all
+            // the ObjC data.  They
+            // have the same address, but we want to ensure that we always find
+            // only the real symbol,
+            // 'cause we don't currently correctly attribute the GSYM one to the
+            // ObjCClass/Ivar/MetaClass
+            // symbol type.  This is a temporary hack to make sure the
+            // ObjectiveC symbols get treated
+            // correctly.  To do this right, we should coalesce all the GSYM &
+            // global symbols that have the
+            // same address.
+            is_gsym = true;
+            sym[sym_idx].SetExternal(true);
+
+            if (symbol_name && symbol_name[0] == '_' && symbol_name[1] == 'O') {
+              llvm::StringRef symbol_name_ref(symbol_name);
+              if (symbol_name_ref.startswith(g_objc_v2_prefix_class)) {
+                symbol_name_non_abi_mangled = symbol_name + 1;
+                symbol_name = symbol_name + g_objc_v2_prefix_class.size();
+                type = eSymbolTypeObjCClass;
+                demangled_is_synthesized = true;
+
+              } else if (symbol_name_ref.startswith(
+                             g_objc_v2_prefix_metaclass)) {
+                symbol_name_non_abi_mangled = symbol_name + 1;
+                symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
+                type = eSymbolTypeObjCMetaClass;
+                demangled_is_synthesized = true;
+              } else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar)) {
+                symbol_name_non_abi_mangled = symbol_name + 1;
+                symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
+                type = eSymbolTypeObjCIVar;
+                demangled_is_synthesized = true;
+              }
+            } else {
+              if (nlist.n_value != 0)
+                symbol_section =
+                    section_info.GetSection(nlist.n_sect, nlist.n_value);
+              type = eSymbolTypeData;
+            }
+            break;
 
-static bool
-ParseTrieEntries (DataExtractor &data,
-                  lldb::offset_t offset,
-                  const bool is_arm,
-                  std::vector<llvm::StringRef> &nameSlices,
-                  std::set<lldb::addr_t> &resolver_addresses,
-                  std::vector<TrieEntryWithOffset>& output)
-{
-	if (!data.ValidOffset(offset))
-        return true;
+          case N_FNAME:
+            // procedure name (f77 kludge): name,,NO_SECT,0,0
+            type = eSymbolTypeCompiler;
+            break;
 
-	const uint64_t terminalSize = data.GetULEB128(&offset);
-	lldb::offset_t children_offset = offset + terminalSize;
-	if ( terminalSize != 0 ) {
-		TrieEntryWithOffset e (offset);
-		e.entry.flags = data.GetULEB128(&offset);
-        const char *import_name = NULL;
-		if ( e.entry.flags & EXPORT_SYMBOL_FLAGS_REEXPORT ) {
-			e.entry.address = 0;
-			e.entry.other = data.GetULEB128(&offset); // dylib ordinal
-            import_name = data.GetCStr(&offset);
-		}
-		else {
-			e.entry.address = data.GetULEB128(&offset);
-			if ( e.entry.flags & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER )
-            {
-				e.entry.other = data.GetULEB128(&offset);
-                uint64_t resolver_addr = e.entry.other;
-                if (is_arm)
-                    resolver_addr &= THUMB_ADDRESS_BIT_MASK;
-                resolver_addresses.insert(resolver_addr);
-            }
-			else
-				e.entry.other = 0;
-		}
-        // Only add symbols that are reexport symbols with a valid import name
-        if (EXPORT_SYMBOL_FLAGS_REEXPORT & e.entry.flags && import_name && import_name[0])
-        {
-            std::string name;
-            if (!nameSlices.empty())
-            {
-                for (auto name_slice: nameSlices)
-                    name.append(name_slice.data(), name_slice.size());
-            }
-            if (name.size() > 1)
-            {
-                // Skip the leading '_'
-                e.entry.name.SetCStringWithLength(name.c_str() + 1,name.size() - 1);
-            }
-            if (import_name)
-            {
-                // Skip the leading '_'
-                e.entry.import_name.SetCString(import_name+1);                
+          case N_FUN:
+            // procedure: name,,n_sect,linenumber,address
+            if (symbol_name) {
+              type = eSymbolTypeCode;
+              symbol_section =
+                  section_info.GetSection(nlist.n_sect, nlist.n_value);
+
+              N_FUN_addr_to_sym_idx.insert(
+                  std::make_pair(nlist.n_value, sym_idx));
+              // We use the current number of symbols in the symbol table in
+              // lieu of
+              // using nlist_idx in case we ever start trimming entries out
+              N_FUN_indexes.push_back(sym_idx);
+            } else {
+              type = eSymbolTypeCompiler;
+
+              if (!N_FUN_indexes.empty()) {
+                // Copy the size of the function into the original STAB entry so
+                // we don't have
+                // to hunt for it later
+                symtab->SymbolAtIndex(N_FUN_indexes.back())
+                    ->SetByteSize(nlist.n_value);
+                N_FUN_indexes.pop_back();
+                // We don't really need the end function STAB as it contains the
+                // size which
+                // we already placed with the original symbol, so don't add it
+                // if we want a
+                // minimal symbol table
+                add_nlist = false;
+              }
             }
-            output.push_back(e);
-        }
-	}
-    
-	const uint8_t childrenCount = data.GetU8(&children_offset);
-	for (uint8_t i=0; i < childrenCount; ++i) {
-        const char *cstr = data.GetCStr(&children_offset);
-        if (cstr)
-            nameSlices.push_back(llvm::StringRef(cstr));
-        else
-            return false; // Corrupt data
-        lldb::offset_t childNodeOffset = data.GetULEB128(&children_offset);
-		if (childNodeOffset)
-        {
-            if (!ParseTrieEntries(data,
-                                 childNodeOffset,
-                                 is_arm,
-                                 nameSlices,
-                                 resolver_addresses,
-                                 output))
-            {
-                return false;
+            break;
+
+          case N_STSYM:
+            // static symbol: name,,n_sect,type,address
+            N_STSYM_addr_to_sym_idx.insert(
+                std::make_pair(nlist.n_value, sym_idx));
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            if (symbol_name && symbol_name[0]) {
+              type = ObjectFile::GetSymbolTypeFromName(symbol_name + 1,
+                                                       eSymbolTypeData);
             }
-        }
-        nameSlices.pop_back();
-	}
-    return true;
-}
+            break;
 
-// Read the UUID out of a dyld_shared_cache file on-disk.
-UUID
-ObjectFileMachO::GetSharedCacheUUID (FileSpec dyld_shared_cache, const ByteOrder byte_order, const uint32_t addr_byte_size)
-{
-    UUID dsc_uuid;
-    DataBufferSP dsc_data_sp = dyld_shared_cache.MemoryMapFileContentsIfLocal(0, sizeof(struct lldb_copy_dyld_cache_header_v1));
-    if (dsc_data_sp)
-    {
-        DataExtractor dsc_header_data (dsc_data_sp, byte_order, addr_byte_size);
-
-        char version_str[7];
-        lldb::offset_t offset = 0;
-        memcpy (version_str, dsc_header_data.GetData (&offset, 6), 6);
-        version_str[6] = '\0';
-        if (strcmp (version_str, "dyld_v") == 0)
-        {
-            offset = offsetof (struct lldb_copy_dyld_cache_header_v1, uuid);
-            uint8_t uuid_bytes[sizeof (uuid_t)];
-            memcpy (uuid_bytes, dsc_header_data.GetData (&offset, sizeof (uuid_t)), sizeof (uuid_t));
-            dsc_uuid.SetBytes (uuid_bytes);
-        }
-    }
-    return dsc_uuid;
-}
-
-size_t
-ObjectFileMachO::ParseSymtab ()
-{
-    Timer scoped_timer(LLVM_PRETTY_FUNCTION,
-                       "ObjectFileMachO::ParseSymtab () module = %s",
-                       m_file.GetFilename().AsCString(""));
-    ModuleSP module_sp (GetModule());
-    if (!module_sp)
-        return 0;
+          case N_LCSYM:
+            // .lcomm symbol: name,,n_sect,type,address
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            type = eSymbolTypeCommonBlock;
+            break;
 
-    struct symtab_command symtab_load_command = { 0, 0, 0, 0, 0, 0 };
-    struct linkedit_data_command function_starts_load_command = { 0, 0, 0, 0 };
-    struct dyld_info_command dyld_info = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-    typedef AddressDataArray<lldb::addr_t, bool, 100> FunctionStarts;
-    FunctionStarts function_starts;
-    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-    uint32_t i;
-    FileSpecList dylib_files;
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS));
-    static const llvm::StringRef g_objc_v2_prefix_class ("_OBJC_CLASS_$_");
-    static const llvm::StringRef g_objc_v2_prefix_metaclass ("_OBJC_METACLASS_$_");
-    static const llvm::StringRef g_objc_v2_prefix_ivar ("_OBJC_IVAR_$_");
+          case N_BNSYM:
+            // We use the current number of symbols in the symbol table in lieu
+            // of
+            // using nlist_idx in case we ever start trimming entries out
+            // Skip these if we want minimal symbol tables
+            add_nlist = false;
+            break;
 
-    for (i=0; i<m_header.ncmds; ++i)
-    {
-        const lldb::offset_t cmd_offset = offset;
-        // Read in the load command and load command size
-        struct load_command lc;
-        if (m_data.GetU32(&offset, &lc, 2) == NULL)
+          case N_ENSYM:
+            // Set the size of the N_BNSYM to the terminating index of this
+            // N_ENSYM
+            // so that we can always skip the entire symbol if we need to
+            // navigate
+            // more quickly at the source level when parsing STABS
+            // Skip these if we want minimal symbol tables
+            add_nlist = false;
             break;
-        // Watch for the symbol table load command
-        switch (lc.cmd)
-        {
-        case LC_SYMTAB:
-            symtab_load_command.cmd = lc.cmd;
-            symtab_load_command.cmdsize = lc.cmdsize;
-            // Read in the rest of the symtab load command
-            if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4) == 0) // fill in symoff, nsyms, stroff, strsize fields
-                return 0;
-            if (symtab_load_command.symoff == 0)
-            {
-                if (log)
-                    module_sp->LogMessage(log, "LC_SYMTAB.symoff == 0");
-                return 0;
-            }
 
-            if (symtab_load_command.stroff == 0)
-            {
-                if (log)
-                    module_sp->LogMessage(log, "LC_SYMTAB.stroff == 0");
-                return 0;
-            }
+          case N_OPT:
+            // emitted with gcc2_compiled and in gcc source
+            type = eSymbolTypeCompiler;
+            break;
 
-            if (symtab_load_command.nsyms == 0)
-            {
-                if (log)
-                    module_sp->LogMessage(log, "LC_SYMTAB.nsyms == 0");
-                return 0;
-            }
+          case N_RSYM:
+            // register sym: name,,NO_SECT,type,register
+            type = eSymbolTypeVariable;
+            break;
 
-            if (symtab_load_command.strsize == 0)
-            {
-                if (log)
-                    module_sp->LogMessage(log, "LC_SYMTAB.strsize == 0");
-                return 0;
-            }
+          case N_SLINE:
+            // src line: 0,,n_sect,linenumber,address
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            type = eSymbolTypeLineEntry;
             break;
 
-        case LC_DYLD_INFO:
-        case LC_DYLD_INFO_ONLY:
-            if (m_data.GetU32(&offset, &dyld_info.rebase_off, 10))
-            {
-                dyld_info.cmd = lc.cmd;
-                dyld_info.cmdsize = lc.cmdsize;
-            }
-            else
-            {
-                memset (&dyld_info, 0, sizeof(dyld_info));
+          case N_SSYM:
+            // structure elt: name,,NO_SECT,type,struct_offset
+            type = eSymbolTypeVariableType;
+            break;
+
+          case N_SO:
+            // source file name
+            type = eSymbolTypeSourceFile;
+            if (symbol_name == NULL) {
+              add_nlist = false;
+              if (N_SO_index != UINT32_MAX) {
+                // Set the size of the N_SO to the terminating index of this
+                // N_SO
+                // so that we can always skip the entire N_SO if we need to
+                // navigate
+                // more quickly at the source level when parsing STABS
+                symbol_ptr = symtab->SymbolAtIndex(N_SO_index);
+                symbol_ptr->SetByteSize(sym_idx);
+                symbol_ptr->SetSizeIsSibling(true);
+              }
+              N_NSYM_indexes.clear();
+              N_INCL_indexes.clear();
+              N_BRAC_indexes.clear();
+              N_COMM_indexes.clear();
+              N_FUN_indexes.clear();
+              N_SO_index = UINT32_MAX;
+            } else {
+              // We use the current number of symbols in the symbol table in
+              // lieu of
+              // using nlist_idx in case we ever start trimming entries out
+              const bool N_SO_has_full_path = symbol_name[0] == '/';
+              if (N_SO_has_full_path) {
+                if ((N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms)) {
+                  // We have two consecutive N_SO entries where the first
+                  // contains a directory
+                  // and the second contains a full path.
+                  sym[sym_idx - 1].GetMangled().SetValue(
+                      ConstString(symbol_name), false);
+                  m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
+                  add_nlist = false;
+                } else {
+                  // This is the first entry in a N_SO that contains a directory
+                  // or
+                  // a full path to the source file
+                  N_SO_index = sym_idx;
+                }
+              } else if ((N_SO_index == sym_idx - 1) &&
+                         ((sym_idx - 1) < num_syms)) {
+                // This is usually the second N_SO entry that contains just the
+                // filename,
+                // so here we combine it with the first one if we are minimizing
+                // the symbol table
+                const char *so_path =
+                    sym[sym_idx - 1]
+                        .GetMangled()
+                        .GetDemangledName(lldb::eLanguageTypeUnknown)
+                        .AsCString();
+                if (so_path && so_path[0]) {
+                  std::string full_so_path(so_path);
+                  const size_t double_slash_pos = full_so_path.find("//");
+                  if (double_slash_pos != std::string::npos) {
+                    // The linker has been generating bad N_SO entries with
+                    // doubled up paths
+                    // in the format "%s%s" where the first string in the
+                    // DW_AT_comp_dir,
+                    // and the second is the directory for the source file so
+                    // you end up with
+                    // a path that looks like "/tmp/src//tmp/src/"
+                    FileSpec so_dir(so_path, false);
+                    if (!so_dir.Exists()) {
+                      so_dir.SetFile(&full_so_path[double_slash_pos + 1],
+                                     false);
+                      if (so_dir.Exists()) {
+                        // Trim off the incorrect path
+                        full_so_path.erase(0, double_slash_pos + 1);
+                      }
+                    }
+                  }
+                  if (*full_so_path.rbegin() != '/')
+                    full_so_path += '/';
+                  full_so_path += symbol_name;
+                  sym[sym_idx - 1].GetMangled().SetValue(
+                      ConstString(full_so_path.c_str()), false);
+                  add_nlist = false;
+                  m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
+                }
+              } else {
+                // This could be a relative path to a N_SO
+                N_SO_index = sym_idx;
+              }
             }
             break;
 
-        case LC_LOAD_DYLIB:
-        case LC_LOAD_WEAK_DYLIB:
-        case LC_REEXPORT_DYLIB:
-        case LC_LOADFVMLIB:
-        case LC_LOAD_UPWARD_DYLIB:
-            {
-                uint32_t name_offset = cmd_offset + m_data.GetU32(&offset);
-                const char *path = m_data.PeekCStr(name_offset);
-                if (path)
-                {
-                    FileSpec file_spec(path, false);
-                    // Strip the path if there is @rpath, @executable, etc so we just use the basename
-                    if (path[0] == '@')
-                        file_spec.GetDirectory().Clear();
-                    
-                    if (lc.cmd == LC_REEXPORT_DYLIB)
-                    {
-                        m_reexported_dylibs.AppendIfUnique(file_spec);
-                    }
+          case N_OSO:
+            // object file name: name,,0,0,st_mtime
+            type = eSymbolTypeObjectFile;
+            break;
 
-                    dylib_files.Append(file_spec);
-                }
+          case N_LSYM:
+            // local sym: name,,NO_SECT,type,offset
+            type = eSymbolTypeLocal;
+            break;
+
+          //----------------------------------------------------------------------
+          // INCL scopes
+          //----------------------------------------------------------------------
+          case N_BINCL:
+            // include file beginning: name,,NO_SECT,0,sum
+            // We use the current number of symbols in the symbol table in lieu
+            // of
+            // using nlist_idx in case we ever start trimming entries out
+            N_INCL_indexes.push_back(sym_idx);
+            type = eSymbolTypeScopeBegin;
+            break;
+
+          case N_EINCL:
+            // include file end: name,,NO_SECT,0,0
+            // Set the size of the N_BINCL to the terminating index of this
+            // N_EINCL
+            // so that we can always skip the entire symbol if we need to
+            // navigate
+            // more quickly at the source level when parsing STABS
+            if (!N_INCL_indexes.empty()) {
+              symbol_ptr = symtab->SymbolAtIndex(N_INCL_indexes.back());
+              symbol_ptr->SetByteSize(sym_idx + 1);
+              symbol_ptr->SetSizeIsSibling(true);
+              N_INCL_indexes.pop_back();
             }
+            type = eSymbolTypeScopeEnd;
             break;
 
-        case LC_FUNCTION_STARTS:
-            function_starts_load_command.cmd = lc.cmd;
-            function_starts_load_command.cmdsize = lc.cmdsize;
-            if (m_data.GetU32(&offset, &function_starts_load_command.dataoff, 2) == NULL) // fill in symoff, nsyms, stroff, strsize fields
-                memset (&function_starts_load_command, 0, sizeof(function_starts_load_command));
+          case N_SOL:
+            // #included file name: name,,n_sect,0,address
+            type = eSymbolTypeHeaderFile;
+
+            // We currently don't use the header files on darwin
+            add_nlist = false;
             break;
 
-        default:
+          case N_PARAMS:
+            // compiler parameters: name,,NO_SECT,0,0
+            type = eSymbolTypeCompiler;
             break;
-        }
-        offset = cmd_offset + lc.cmdsize;
-    }
 
-    if (symtab_load_command.cmd)
-    {
-        Symtab *symtab = m_symtab_ap.get();
-        SectionList *section_list = GetSectionList();
-        if (section_list == NULL)
-            return 0;
-
-        const uint32_t addr_byte_size = m_data.GetAddressByteSize();
-        const ByteOrder byte_order = m_data.GetByteOrder();
-        bool bit_width_32 = addr_byte_size == 4;
-        const size_t nlist_byte_size = bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64);
-
-        DataExtractor nlist_data (NULL, 0, byte_order, addr_byte_size);
-        DataExtractor strtab_data (NULL, 0, byte_order, addr_byte_size);
-        DataExtractor function_starts_data (NULL, 0, byte_order, addr_byte_size);
-        DataExtractor indirect_symbol_index_data (NULL, 0, byte_order, addr_byte_size);
-        DataExtractor dyld_trie_data (NULL, 0, byte_order, addr_byte_size);
-
-        const addr_t nlist_data_byte_size = symtab_load_command.nsyms * nlist_byte_size;
-        const addr_t strtab_data_byte_size = symtab_load_command.strsize;
-        addr_t strtab_addr = LLDB_INVALID_ADDRESS;
-
-        ProcessSP process_sp (m_process_wp.lock());
-        Process *process = process_sp.get();
-        
-        uint32_t memory_module_load_level = eMemoryModuleLoadLevelComplete;
-
-        if (process && m_header.filetype != llvm::MachO::MH_OBJECT)
-        {
-            Target &target = process->GetTarget();
-            
-            memory_module_load_level = target.GetMemoryModuleLoadLevel();
+          case N_VERSION:
+            // compiler version: name,,NO_SECT,0,0
+            type = eSymbolTypeCompiler;
+            break;
 
-            SectionSP linkedit_section_sp(section_list->FindSectionByName(GetSegmentNameLINKEDIT()));
-            // Reading mach file from memory in a process or core file...
+          case N_OLEVEL:
+            // compiler -O level: name,,NO_SECT,0,0
+            type = eSymbolTypeCompiler;
+            break;
 
-            if (linkedit_section_sp)
-            {
-                addr_t linkedit_load_addr = linkedit_section_sp->GetLoadBaseAddress(&target);
-                if (linkedit_load_addr == LLDB_INVALID_ADDRESS)
-                {
-                    // We might be trying to access the symbol table before the __LINKEDIT's load
-                    // address has been set in the target. We can't fail to read the symbol table,
-                    // so calculate the right address manually
-                    linkedit_load_addr = CalculateSectionLoadAddressForMemoryImage(m_memory_addr, GetMachHeaderSection(), linkedit_section_sp.get());
-                }
+          case N_PSYM:
+            // parameter: name,,NO_SECT,type,offset
+            type = eSymbolTypeVariable;
+            break;
 
-                const addr_t linkedit_file_offset = linkedit_section_sp->GetFileOffset();
-                const addr_t symoff_addr = linkedit_load_addr + symtab_load_command.symoff - linkedit_file_offset;
-                strtab_addr = linkedit_load_addr + symtab_load_command.stroff - linkedit_file_offset;
-
-                bool data_was_read = false;
-
-#if defined (__APPLE__) && (defined (__arm__) || defined (__arm64__) || defined (__aarch64__))
-                if (m_header.flags & 0x80000000u && process->GetAddressByteSize() == sizeof (void*))
-                {
-                    // This mach-o memory file is in the dyld shared cache. If this
-                    // program is not remote and this is iOS, then this process will
-                    // share the same shared cache as the process we are debugging and
-                    // we can read the entire __LINKEDIT from the address space in this
-                    // process. This is a needed optimization that is used for local iOS
-                    // debugging only since all shared libraries in the shared cache do
-                    // not have corresponding files that exist in the file system of the
-                    // device. They have been combined into a single file. This means we
-                    // always have to load these files from memory. All of the symbol and
-                    // string tables from all of the __LINKEDIT sections from the shared
-                    // libraries in the shared cache have been merged into a single large
-                    // symbol and string table. Reading all of this symbol and string table
-                    // data across can slow down debug launch times, so we optimize this by
-                    // reading the memory for the __LINKEDIT section from this process.
-
-                    UUID lldb_shared_cache(GetLLDBSharedCacheUUID());
-                    UUID process_shared_cache(GetProcessSharedCacheUUID(process));
-                    bool use_lldb_cache = true;
-                    if (lldb_shared_cache.IsValid() && process_shared_cache.IsValid() && lldb_shared_cache != process_shared_cache)
-                    {
-                            use_lldb_cache = false;
-                            ModuleSP module_sp (GetModule());
-                            if (module_sp)
-                                module_sp->ReportWarning ("shared cache in process does not match lldb's own shared cache, startup will be slow.");
+          case N_ENTRY:
+            // alternate entry: name,,n_sect,linenumber,address
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            type = eSymbolTypeLineEntry;
+            break;
 
-                    }
+          //----------------------------------------------------------------------
+          // Left and Right Braces
+          //----------------------------------------------------------------------
+          case N_LBRAC:
+            // left bracket: 0,,NO_SECT,nesting level,address
+            // We use the current number of symbols in the symbol table in lieu
+            // of
+            // using nlist_idx in case we ever start trimming entries out
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            N_BRAC_indexes.push_back(sym_idx);
+            type = eSymbolTypeScopeBegin;
+            break;
 
-                    PlatformSP platform_sp (target.GetPlatform());
-                    if (platform_sp && platform_sp->IsHost() && use_lldb_cache)
-                    {
-                        data_was_read = true;
-                        nlist_data.SetData((void *)symoff_addr, nlist_data_byte_size, eByteOrderLittle);
-                        strtab_data.SetData((void *)strtab_addr, strtab_data_byte_size, eByteOrderLittle);
-                        if (function_starts_load_command.cmd)
-                        {
-                            const addr_t func_start_addr = linkedit_load_addr + function_starts_load_command.dataoff - linkedit_file_offset;
-                            function_starts_data.SetData ((void *)func_start_addr, function_starts_load_command.datasize, eByteOrderLittle);
-                        }
-                    }
-                }
-#endif
+          case N_RBRAC:
+            // right bracket: 0,,NO_SECT,nesting level,address
+            // Set the size of the N_LBRAC to the terminating index of this
+            // N_RBRAC
+            // so that we can always skip the entire symbol if we need to
+            // navigate
+            // more quickly at the source level when parsing STABS
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            if (!N_BRAC_indexes.empty()) {
+              symbol_ptr = symtab->SymbolAtIndex(N_BRAC_indexes.back());
+              symbol_ptr->SetByteSize(sym_idx + 1);
+              symbol_ptr->SetSizeIsSibling(true);
+              N_BRAC_indexes.pop_back();
+            }
+            type = eSymbolTypeScopeEnd;
+            break;
 
-                if (!data_was_read)
-                {
-                    // Always load dyld - the dynamic linker - from memory if we didn't find a binary anywhere else.
-                    // lldb will not register dylib/framework/bundle loads/unloads if we don't have the dyld symbols,
-                    // we force dyld to load from memory despite the user's target.memory-module-load-level setting.
-                    if (memory_module_load_level == eMemoryModuleLoadLevelComplete || m_header.filetype == llvm::MachO::MH_DYLINKER)
-                    {
-                        DataBufferSP nlist_data_sp (ReadMemory (process_sp, symoff_addr, nlist_data_byte_size));
-                        if (nlist_data_sp)
-                            nlist_data.SetData (nlist_data_sp, 0, nlist_data_sp->GetByteSize());
-                        // Load strings individually from memory when loading from memory since shared cache
-                        // string tables contain strings for all symbols from all shared cached libraries
-                        //DataBufferSP strtab_data_sp (ReadMemory (process_sp, strtab_addr, strtab_data_byte_size));
-                        //if (strtab_data_sp)
-                        //    strtab_data.SetData (strtab_data_sp, 0, strtab_data_sp->GetByteSize());
-                        if (m_dysymtab.nindirectsyms != 0)
-                        {
-                            const addr_t indirect_syms_addr = linkedit_load_addr + m_dysymtab.indirectsymoff - linkedit_file_offset;
-                            DataBufferSP indirect_syms_data_sp (ReadMemory (process_sp, indirect_syms_addr, m_dysymtab.nindirectsyms * 4));
-                            if (indirect_syms_data_sp)
-                                indirect_symbol_index_data.SetData (indirect_syms_data_sp, 0, indirect_syms_data_sp->GetByteSize());
-                        }
-                    }
-                    else if (memory_module_load_level >= eMemoryModuleLoadLevelPartial)
-                    {
-                        if (function_starts_load_command.cmd)
-                        {
-                            const addr_t func_start_addr = linkedit_load_addr + function_starts_load_command.dataoff - linkedit_file_offset;
-                            DataBufferSP func_start_data_sp (ReadMemory (process_sp, func_start_addr, function_starts_load_command.datasize));
-                            if (func_start_data_sp)
-                                function_starts_data.SetData (func_start_data_sp, 0, func_start_data_sp->GetByteSize());
-                        }
-                    }
-                }
-            }
-        }
-        else
-        {
-            nlist_data.SetData (m_data,
-                                symtab_load_command.symoff,
-                                nlist_data_byte_size);
-            strtab_data.SetData (m_data,
-                                 symtab_load_command.stroff,
-                                 strtab_data_byte_size);
-            
-            if (dyld_info.export_size > 0)
-            {
-                dyld_trie_data.SetData (m_data,
-                                        dyld_info.export_off,
-                                        dyld_info.export_size);
-            }
-
-            if (m_dysymtab.nindirectsyms != 0)
-            {
-                indirect_symbol_index_data.SetData (m_data,
-                                                    m_dysymtab.indirectsymoff,
-                                                    m_dysymtab.nindirectsyms * 4);
-            }
-            if (function_starts_load_command.cmd)
-            {
-                function_starts_data.SetData (m_data,
-                                              function_starts_load_command.dataoff,
-                                              function_starts_load_command.datasize);
-            }
-        }
-
-        if (nlist_data.GetByteSize() == 0 && memory_module_load_level == eMemoryModuleLoadLevelComplete)
-        {
-            if (log)
-                module_sp->LogMessage(log, "failed to read nlist data");
-            return 0;
-        }
-
-        const bool have_strtab_data = strtab_data.GetByteSize() > 0;
-        if (!have_strtab_data)
-        {
-            if (process)
-            {
-                if (strtab_addr == LLDB_INVALID_ADDRESS)
-                {
-                    if (log)
-                        module_sp->LogMessage(log, "failed to locate the strtab in memory");
-                    return 0;
-                }
-            }
-            else
-            {
-                if (log)
-                    module_sp->LogMessage(log, "failed to read strtab data");
-                return 0;
-            }
-        }
-
-        const ConstString &g_segment_name_TEXT = GetSegmentNameTEXT();
-        const ConstString &g_segment_name_DATA = GetSegmentNameDATA();
-        const ConstString &g_segment_name_DATA_DIRTY = GetSegmentNameDATA_DIRTY();
-        const ConstString &g_segment_name_DATA_CONST = GetSegmentNameDATA_CONST();
-        const ConstString &g_segment_name_OBJC = GetSegmentNameOBJC();
-        const ConstString &g_section_name_eh_frame = GetSectionNameEHFrame();
-        SectionSP text_section_sp(section_list->FindSectionByName(g_segment_name_TEXT));
-        SectionSP data_section_sp(section_list->FindSectionByName(g_segment_name_DATA));
-        SectionSP data_dirty_section_sp(section_list->FindSectionByName(g_segment_name_DATA_DIRTY));
-        SectionSP data_const_section_sp(section_list->FindSectionByName(g_segment_name_DATA_CONST));
-        SectionSP objc_section_sp(section_list->FindSectionByName(g_segment_name_OBJC));
-        SectionSP eh_frame_section_sp;
-        if (text_section_sp.get())
-            eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName (g_section_name_eh_frame);
-        else
-            eh_frame_section_sp = section_list->FindSectionByName (g_section_name_eh_frame);
-
-        const bool is_arm = (m_header.cputype == llvm::MachO::CPU_TYPE_ARM);
-
-        // lldb works best if it knows the start address of all functions in a module.
-        // Linker symbols or debug info are normally the best source of information for start addr / size but
-        // they may be stripped in a released binary.
-        // Two additional sources of information exist in Mach-O binaries:
-        //    LC_FUNCTION_STARTS - a list of ULEB128 encoded offsets of each function's start address in the
-        //                         binary, relative to the text section.
-        //    eh_frame           - the eh_frame FDEs have the start addr & size of each function
-        //  LC_FUNCTION_STARTS is the fastest source to read in, and is present on all modern binaries.
-        //  Binaries built to run on older releases may need to use eh_frame information.
-
-        if (text_section_sp && function_starts_data.GetByteSize())
-        {
-            FunctionStarts::Entry function_start_entry;
-            function_start_entry.data = false;
-            lldb::offset_t function_start_offset = 0;
-            function_start_entry.addr = text_section_sp->GetFileAddress();
-            uint64_t delta;
-            while ((delta = function_starts_data.GetULEB128(&function_start_offset)) > 0)
-            {
-                // Now append the current entry
-                function_start_entry.addr += delta;
-                function_starts.Append(function_start_entry);
-            }
-        }
-        else
-        {
-            // If m_type is eTypeDebugInfo, then this is a dSYM - it will have the load command claiming an eh_frame
-            // but it doesn't actually have the eh_frame content.  And if we have a dSYM, we don't need to do any
-            // of this fill-in-the-missing-symbols works anyway - the debug info should give us all the functions in
-            // the module.
-            if (text_section_sp.get() && eh_frame_section_sp.get() && m_type != eTypeDebugInfo)
-            {
-                DWARFCallFrameInfo eh_frame(*this, eh_frame_section_sp, eRegisterKindEHFrame, true);
-                DWARFCallFrameInfo::FunctionAddressAndSizeVector functions;
-                eh_frame.GetFunctionAddressAndSizeVector (functions);
-                addr_t text_base_addr = text_section_sp->GetFileAddress();
-                size_t count = functions.GetSize();
-                for (size_t i = 0; i < count; ++i)
-                {
-                    const DWARFCallFrameInfo::FunctionAddressAndSizeVector::Entry *func = functions.GetEntryAtIndex (i);
-                    if (func)
-                    {
-                        FunctionStarts::Entry function_start_entry;
-                        function_start_entry.addr = func->base - text_base_addr;
-                        function_starts.Append(function_start_entry);
-                    }
-                }
-            }
-        }
-
-        const size_t function_starts_count = function_starts.GetSize();
-
-        // For user process binaries (executables, dylibs, frameworks, bundles), if we don't have
-        // LC_FUNCTION_STARTS/eh_frame section in this binary, we're going to assume the binary
-        // has been stripped.  Don't allow assembly language instruction emulation because we don't
-        // know proper function start boundaries.
-        //
-        // For all other types of binaries (kernels, stand-alone bare board binaries, kexts), they
-        // may not have LC_FUNCTION_STARTS / eh_frame sections - we should not make any assumptions
-        // about them based on that.
-        if (function_starts_count == 0 && CalculateStrata() == eStrataUser)
-        {
-            m_allow_assembly_emulation_unwind_plans = false;
-            Log *unwind_or_symbol_log (lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_SYMBOLS | LIBLLDB_LOG_UNWIND));
-
-            if (unwind_or_symbol_log)
-                module_sp->LogMessage(unwind_or_symbol_log, "no LC_FUNCTION_STARTS, will not allow assembly profiled unwinds");
-        }
-
-        const user_id_t TEXT_eh_frame_sectID =
-            eh_frame_section_sp.get() ? eh_frame_section_sp->GetID()
-                                      : static_cast<user_id_t>(NO_SECT);
-
-        lldb::offset_t nlist_data_offset = 0;
-
-        uint32_t N_SO_index = UINT32_MAX;
-
-        MachSymtabSectionInfo section_info (section_list);
-        std::vector<uint32_t> N_FUN_indexes;
-        std::vector<uint32_t> N_NSYM_indexes;
-        std::vector<uint32_t> N_INCL_indexes;
-        std::vector<uint32_t> N_BRAC_indexes;
-        std::vector<uint32_t> N_COMM_indexes;
-        typedef std::multimap <uint64_t, uint32_t> ValueToSymbolIndexMap;
-        typedef std::map <uint32_t, uint32_t> NListIndexToSymbolIndexMap;
-        typedef std::map <const char *, uint32_t> ConstNameToSymbolIndexMap;
-        ValueToSymbolIndexMap N_FUN_addr_to_sym_idx;
-        ValueToSymbolIndexMap N_STSYM_addr_to_sym_idx;
-        ConstNameToSymbolIndexMap N_GSYM_name_to_sym_idx;
-        // Any symbols that get merged into another will get an entry
-        // in this map so we know
-        NListIndexToSymbolIndexMap m_nlist_idx_to_sym_idx;
-        uint32_t nlist_idx = 0;
-        Symbol *symbol_ptr = NULL;
-
-        uint32_t sym_idx = 0;
-        Symbol *sym = NULL;
-        size_t num_syms = 0;
-        std::string memory_symbol_name;
-        uint32_t unmapped_local_symbols_found = 0;
-
-        std::vector<TrieEntryWithOffset> trie_entries;
-        std::set<lldb::addr_t> resolver_addresses;
-
-        if (dyld_trie_data.GetByteSize() > 0)
-        {
-            std::vector<llvm::StringRef> nameSlices;
-            ParseTrieEntries (dyld_trie_data,
-                              0,
-                              is_arm,
-                              nameSlices,
-                              resolver_addresses,
-                              trie_entries);
-            
-            ConstString text_segment_name ("__TEXT");
-            SectionSP text_segment_sp = GetSectionList()->FindSectionByName(text_segment_name);
-            if (text_segment_sp)
-            {
-                const lldb::addr_t text_segment_file_addr = text_segment_sp->GetFileAddress();
-                if (text_segment_file_addr != LLDB_INVALID_ADDRESS)
-                {
-                    for (auto &e : trie_entries)
-                        e.entry.address += text_segment_file_addr;
-                }
-            }
-        }
-
-        typedef std::set<ConstString> IndirectSymbols;
-        IndirectSymbols indirect_symbol_names;
-
-#if defined (__APPLE__) && (defined (__arm__) || defined (__arm64__) || defined (__aarch64__))
-
-        // Some recent builds of the dyld_shared_cache (hereafter: DSC) have been optimized by moving LOCAL
-        // symbols out of the memory mapped portion of the DSC. The symbol information has all been retained,
-        // but it isn't available in the normal nlist data. However, there *are* duplicate entries of *some*
-        // LOCAL symbols in the normal nlist data. To handle this situation correctly, we must first attempt
-        // to parse any DSC unmapped symbol information. If we find any, we set a flag that tells the normal
-        // nlist parser to ignore all LOCAL symbols.
-
-        if (m_header.flags & 0x80000000u)
-        {
-            // Before we can start mapping the DSC, we need to make certain the target process is actually
-            // using the cache we can find.
-
-            // Next we need to determine the correct path for the dyld shared cache.
-
-            ArchSpec header_arch;
-            GetArchitecture(header_arch);
-            char dsc_path[PATH_MAX];
-            char dsc_path_development[PATH_MAX];
-
-            snprintf(dsc_path, sizeof(dsc_path), "%s%s%s",
-                     "/System/Library/Caches/com.apple.dyld/",  /* IPHONE_DYLD_SHARED_CACHE_DIR */
-                     "dyld_shared_cache_",          /* DYLD_SHARED_CACHE_BASE_NAME */
-                     header_arch.GetArchitectureName());
-
-            snprintf(dsc_path_development, sizeof(dsc_path), "%s%s%s%s",
-                     "/System/Library/Caches/com.apple.dyld/",  /* IPHONE_DYLD_SHARED_CACHE_DIR */
-                     "dyld_shared_cache_",          /* DYLD_SHARED_CACHE_BASE_NAME */
-                     header_arch.GetArchitectureName(),
-                     ".development");
-
-            FileSpec dsc_nondevelopment_filespec(dsc_path, false);
-            FileSpec dsc_development_filespec(dsc_path_development, false);
-            FileSpec dsc_filespec;
-
-            UUID dsc_uuid;
-            UUID process_shared_cache_uuid;
-
-            if (process)
-            {
-                process_shared_cache_uuid = GetProcessSharedCacheUUID(process);
-            }
-
-            // First see if we can find an exact match for the inferior process shared cache UUID in
-            // the development or non-development shared caches on disk.
-            if (process_shared_cache_uuid.IsValid())
-            {
-                if (dsc_development_filespec.Exists())
-                {
-                    UUID dsc_development_uuid = GetSharedCacheUUID (dsc_development_filespec, byte_order, addr_byte_size);
-                    if (dsc_development_uuid.IsValid() && dsc_development_uuid == process_shared_cache_uuid)
-                    {
-                        dsc_filespec = dsc_development_filespec;
-                        dsc_uuid = dsc_development_uuid;
-                    }
-                }
-                if (!dsc_uuid.IsValid() && dsc_nondevelopment_filespec.Exists())
-                {
-                    UUID dsc_nondevelopment_uuid = GetSharedCacheUUID (dsc_nondevelopment_filespec, byte_order, addr_byte_size);
-                    if (dsc_nondevelopment_uuid.IsValid() && dsc_nondevelopment_uuid == process_shared_cache_uuid)
-                    {
-                        dsc_filespec = dsc_nondevelopment_filespec;
-                        dsc_uuid = dsc_nondevelopment_uuid;
-                    }
-                }
-            }
-
-            // Failing a UUID match, prefer the development dyld_shared cache if both are present.
-            if (!dsc_filespec.Exists())
-            {
-                if (dsc_development_filespec.Exists())
-                {
-                    dsc_filespec = dsc_development_filespec;
-                }
-                else
-                {
-                    dsc_filespec = dsc_nondevelopment_filespec;
-                }
-            }
-
-            /* The dyld_cache_header has a pointer to the dyld_cache_local_symbols_info structure (localSymbolsOffset).
-               The dyld_cache_local_symbols_info structure gives us three things:
-                 1. The start and count of the nlist records in the dyld_shared_cache file
-                 2. The start and size of the strings for these nlist records
-                 3. The start and count of dyld_cache_local_symbols_entry entries
-
-               There is one dyld_cache_local_symbols_entry per dylib/framework in the dyld shared cache.
-               The "dylibOffset" field is the Mach-O header of this dylib/framework in the dyld shared cache.
-               The dyld_cache_local_symbols_entry also lists the start of this dylib/framework's nlist records
-               and the count of how many nlist records there are for this dylib/framework.
-            */
-
-            // Process the dyld shared cache header to find the unmapped symbols
-
-            DataBufferSP dsc_data_sp = dsc_filespec.MemoryMapFileContentsIfLocal(0, sizeof(struct lldb_copy_dyld_cache_header_v1));
-            if (!dsc_uuid.IsValid())
-            {
-                dsc_uuid = GetSharedCacheUUID (dsc_filespec, byte_order, addr_byte_size);
-            }
-            if (dsc_data_sp)
-            {
-                DataExtractor dsc_header_data (dsc_data_sp, byte_order, addr_byte_size);
-
-                bool uuid_match = true;
-                if (dsc_uuid.IsValid() && process)
-                {
-                    if (process_shared_cache_uuid.IsValid() && dsc_uuid != process_shared_cache_uuid)
-                    {
-                        // The on-disk dyld_shared_cache file is not the same as the one in this
-                        // process' memory, don't use it.
-                        uuid_match = false;
-                        ModuleSP module_sp (GetModule());
-                        if (module_sp)
-                            module_sp->ReportWarning ("process shared cache does not match on-disk dyld_shared_cache file, some symbol names will be missing.");
-                    }
-                }
-
-                offset = offsetof (struct lldb_copy_dyld_cache_header_v1, mappingOffset);
-
-                uint32_t mappingOffset = dsc_header_data.GetU32(&offset);
-
-                // If the mappingOffset points to a location inside the header, we've
-                // opened an old dyld shared cache, and should not proceed further.
-                if (uuid_match && mappingOffset >= sizeof(struct lldb_copy_dyld_cache_header_v1))
-                {
-
-                    DataBufferSP dsc_mapping_info_data_sp = dsc_filespec.MemoryMapFileContentsIfLocal(mappingOffset, sizeof (struct lldb_copy_dyld_cache_mapping_info));
-                    DataExtractor dsc_mapping_info_data(dsc_mapping_info_data_sp, byte_order, addr_byte_size);
-                    offset = 0;
-
-                    // The File addresses (from the in-memory Mach-O load commands) for the shared libraries
-                    // in the shared library cache need to be adjusted by an offset to match up with the
-                    // dylibOffset identifying field in the dyld_cache_local_symbol_entry's.  This offset is
-                    // recorded in mapping_offset_value.
-                    const uint64_t mapping_offset_value = dsc_mapping_info_data.GetU64(&offset);
-
-                    offset = offsetof (struct lldb_copy_dyld_cache_header_v1, localSymbolsOffset);
-                    uint64_t localSymbolsOffset = dsc_header_data.GetU64(&offset);
-                    uint64_t localSymbolsSize = dsc_header_data.GetU64(&offset);
-
-                    if (localSymbolsOffset && localSymbolsSize)
-                    {
-                        // Map the local symbols
-                        if (DataBufferSP dsc_local_symbols_data_sp = dsc_filespec.MemoryMapFileContentsIfLocal(localSymbolsOffset, localSymbolsSize))
-                        {
-                            DataExtractor dsc_local_symbols_data(dsc_local_symbols_data_sp, byte_order, addr_byte_size);
-
-                            offset = 0;
-
-                            typedef std::map<ConstString, uint16_t> UndefinedNameToDescMap;
-                            typedef std::map<uint32_t, ConstString> SymbolIndexToName;
-                            UndefinedNameToDescMap undefined_name_to_desc;
-                            SymbolIndexToName reexport_shlib_needs_fixup;
-
-
-                            // Read the local_symbols_infos struct in one shot
-                            struct lldb_copy_dyld_cache_local_symbols_info local_symbols_info;
-                            dsc_local_symbols_data.GetU32(&offset, &local_symbols_info.nlistOffset, 6);
-
-                            SectionSP text_section_sp(section_list->FindSectionByName(GetSegmentNameTEXT()));
-
-                            uint32_t header_file_offset = (text_section_sp->GetFileAddress() - mapping_offset_value);
-
-                            offset = local_symbols_info.entriesOffset;
-                            for (uint32_t entry_index = 0; entry_index < local_symbols_info.entriesCount; entry_index++)
-                            {
-                                struct lldb_copy_dyld_cache_local_symbols_entry local_symbols_entry;
-                                local_symbols_entry.dylibOffset = dsc_local_symbols_data.GetU32(&offset);
-                                local_symbols_entry.nlistStartIndex = dsc_local_symbols_data.GetU32(&offset);
-                                local_symbols_entry.nlistCount = dsc_local_symbols_data.GetU32(&offset);
-
-                                if (header_file_offset == local_symbols_entry.dylibOffset)
-                                {
-                                    unmapped_local_symbols_found = local_symbols_entry.nlistCount;
-
-                                    // The normal nlist code cannot correctly size the Symbols array, we need to allocate it here.
-                                    sym = symtab->Resize (symtab_load_command.nsyms + m_dysymtab.nindirectsyms + unmapped_local_symbols_found - m_dysymtab.nlocalsym);
-                                    num_syms = symtab->GetNumSymbols();
-
-                                    nlist_data_offset = local_symbols_info.nlistOffset + (nlist_byte_size * local_symbols_entry.nlistStartIndex);
-                                    uint32_t string_table_offset = local_symbols_info.stringsOffset;
-
-                                    for (uint32_t nlist_index = 0; nlist_index < local_symbols_entry.nlistCount; nlist_index++)
-                                    {
-                                        /////////////////////////////
-                                        {
-                                            struct nlist_64 nlist;
-                                            if (!dsc_local_symbols_data.ValidOffsetForDataOfSize(nlist_data_offset, nlist_byte_size))
-                                                break;
-
-                                            nlist.n_strx  = dsc_local_symbols_data.GetU32_unchecked(&nlist_data_offset);
-                                            nlist.n_type  = dsc_local_symbols_data.GetU8_unchecked (&nlist_data_offset);
-                                            nlist.n_sect  = dsc_local_symbols_data.GetU8_unchecked (&nlist_data_offset);
-                                            nlist.n_desc  = dsc_local_symbols_data.GetU16_unchecked (&nlist_data_offset);
-                                            nlist.n_value = dsc_local_symbols_data.GetAddress_unchecked (&nlist_data_offset);
-
-                                            SymbolType type = eSymbolTypeInvalid;
-                                            const char *symbol_name = dsc_local_symbols_data.PeekCStr(string_table_offset + nlist.n_strx);
-
-                                            if (symbol_name == NULL)
-                                            {
-                                                // No symbol should be NULL, even the symbols with no
-                                                // string values should have an offset zero which points
-                                                // to an empty C-string
-                                                Host::SystemLog (Host::eSystemLogError,
-                                                                 "error: DSC unmapped local symbol[%u] has invalid string table offset 0x%x in %s, ignoring symbol\n",
-                                                                 entry_index,
-                                                                 nlist.n_strx,
-                                                                 module_sp->GetFileSpec().GetPath().c_str());
-                                                continue;
-                                            }
-                                            if (symbol_name[0] == '\0')
-                                                symbol_name = NULL;
-
-                                            const char *symbol_name_non_abi_mangled = NULL;
-
-                                            SectionSP symbol_section;
-                                            uint32_t symbol_byte_size = 0;
-                                            bool add_nlist = true;
-                                            bool is_debug = ((nlist.n_type & N_STAB) != 0);
-                                            bool demangled_is_synthesized = false;
-                                            bool is_gsym = false;
-                                            bool set_value = true;
-
-                                            assert (sym_idx < num_syms);
-
-                                            sym[sym_idx].SetDebug (is_debug);
-
-                                            if (is_debug)
-                                            {
-                                                switch (nlist.n_type)
-                                                {
-                                                    case N_GSYM:
-                                                        // global symbol: name,,NO_SECT,type,0
-                                                        // Sometimes the N_GSYM value contains the address.
-
-                                                        // FIXME: In the .o files, we have a GSYM and a debug symbol for all the ObjC data.  They
-                                                        // have the same address, but we want to ensure that we always find only the real symbol,
-                                                        // 'cause we don't currently correctly attribute the GSYM one to the ObjCClass/Ivar/MetaClass
-                                                        // symbol type.  This is a temporary hack to make sure the ObjectiveC symbols get treated
-                                                        // correctly.  To do this right, we should coalesce all the GSYM & global symbols that have the
-                                                        // same address.
-
-                                                        is_gsym = true;
-                                                        sym[sym_idx].SetExternal(true);
-
-                                                        if (symbol_name && symbol_name[0] == '_' && symbol_name[1] ==  'O')
-                                                        {
-                                                            llvm::StringRef symbol_name_ref(symbol_name);
-                                                            if (symbol_name_ref.startswith(g_objc_v2_prefix_class))
-                                                            {
-                                                                symbol_name_non_abi_mangled = symbol_name + 1;
-                                                                symbol_name = symbol_name + g_objc_v2_prefix_class.size();
-                                                                type = eSymbolTypeObjCClass;
-                                                                demangled_is_synthesized = true;
-
-                                                            }
-                                                            else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
-                                                            {
-                                                                symbol_name_non_abi_mangled = symbol_name + 1;
-                                                                symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
-                                                                type = eSymbolTypeObjCMetaClass;
-                                                                demangled_is_synthesized = true;
-                                                            }
-                                                            else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
-                                                            {
-                                                                symbol_name_non_abi_mangled = symbol_name + 1;
-                                                                symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
-                                                                type = eSymbolTypeObjCIVar;
-                                                                demangled_is_synthesized = true;
-                                                            }
-                                                        }
-                                                        else
-                                                        {
-                                                            if (nlist.n_value != 0)
-                                                                symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                            type = eSymbolTypeData;
-                                                        }
-                                                        break;
-
-                                                    case N_FNAME:
-                                                        // procedure name (f77 kludge): name,,NO_SECT,0,0
-                                                        type = eSymbolTypeCompiler;
-                                                        break;
-
-                                                    case N_FUN:
-                                                        // procedure: name,,n_sect,linenumber,address
-                                                        if (symbol_name)
-                                                        {
-                                                            type = eSymbolTypeCode;
-                                                            symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-
-                                                            N_FUN_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx));
-                                                            // We use the current number of symbols in the symbol table in lieu of
-                                                            // using nlist_idx in case we ever start trimming entries out
-                                                            N_FUN_indexes.push_back(sym_idx);
-                                                        }
-                                                        else
-                                                        {
-                                                            type = eSymbolTypeCompiler;
-
-                                                            if ( !N_FUN_indexes.empty() )
-                                                            {
-                                                                // Copy the size of the function into the original STAB entry so we don't have
-                                                                // to hunt for it later
-                                                                symtab->SymbolAtIndex(N_FUN_indexes.back())->SetByteSize(nlist.n_value);
-                                                                N_FUN_indexes.pop_back();
-                                                                // We don't really need the end function STAB as it contains the size which
-                                                                // we already placed with the original symbol, so don't add it if we want a
-                                                                // minimal symbol table
-                                                                add_nlist = false;
-                                                            }
-                                                        }
-                                                        break;
-
-                                                    case N_STSYM:
-                                                        // static symbol: name,,n_sect,type,address
-                                                        N_STSYM_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx));
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        if (symbol_name && symbol_name[0])
-                                                        {
-                                                            type = ObjectFile::GetSymbolTypeFromName(symbol_name+1, eSymbolTypeData);
-                                                        }
-                                                        break;
-
-                                                    case N_LCSYM:
-                                                        // .lcomm symbol: name,,n_sect,type,address
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        type = eSymbolTypeCommonBlock;
-                                                        break;
-
-                                                    case N_BNSYM:
-                                                        // We use the current number of symbols in the symbol table in lieu of
-                                                        // using nlist_idx in case we ever start trimming entries out
-                                                        // Skip these if we want minimal symbol tables
-                                                        add_nlist = false;
-                                                        break;
-
-                                                    case N_ENSYM:
-                                                        // Set the size of the N_BNSYM to the terminating index of this N_ENSYM
-                                                        // so that we can always skip the entire symbol if we need to navigate
-                                                        // more quickly at the source level when parsing STABS
-                                                        // Skip these if we want minimal symbol tables
-                                                        add_nlist = false;
-                                                        break;
-
-                                                    case N_OPT:
-                                                        // emitted with gcc2_compiled and in gcc source
-                                                        type = eSymbolTypeCompiler;
-                                                        break;
-
-                                                    case N_RSYM:
-                                                        // register sym: name,,NO_SECT,type,register
-                                                        type = eSymbolTypeVariable;
-                                                        break;
-
-                                                    case N_SLINE:
-                                                        // src line: 0,,n_sect,linenumber,address
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        type = eSymbolTypeLineEntry;
-                                                        break;
-
-                                                    case N_SSYM:
-                                                        // structure elt: name,,NO_SECT,type,struct_offset
-                                                        type = eSymbolTypeVariableType;
-                                                        break;
-
-                                                    case N_SO:
-                                                        // source file name
-                                                        type = eSymbolTypeSourceFile;
-                                                        if (symbol_name == NULL)
-                                                        {
-                                                            add_nlist = false;
-                                                            if (N_SO_index != UINT32_MAX)
-                                                            {
-                                                                // Set the size of the N_SO to the terminating index of this N_SO
-                                                                // so that we can always skip the entire N_SO if we need to navigate
-                                                                // more quickly at the source level when parsing STABS
-                                                                symbol_ptr = symtab->SymbolAtIndex(N_SO_index);
-                                                                symbol_ptr->SetByteSize(sym_idx);
-                                                                symbol_ptr->SetSizeIsSibling(true);
-                                                            }
-                                                            N_NSYM_indexes.clear();
-                                                            N_INCL_indexes.clear();
-                                                            N_BRAC_indexes.clear();
-                                                            N_COMM_indexes.clear();
-                                                            N_FUN_indexes.clear();
-                                                            N_SO_index = UINT32_MAX;
-                                                        }
-                                                        else
-                                                        {
-                                                            // We use the current number of symbols in the symbol table in lieu of
-                                                            // using nlist_idx in case we ever start trimming entries out
-                                                            const bool N_SO_has_full_path = symbol_name[0] == '/';
-                                                            if (N_SO_has_full_path)
-                                                            {
-                                                                if ((N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms))
-                                                                {
-                                                                    // We have two consecutive N_SO entries where the first contains a directory
-                                                                    // and the second contains a full path.
-                                                                    sym[sym_idx - 1].GetMangled().SetValue(ConstString(symbol_name), false);
-                                                                    m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
-                                                                    add_nlist = false;
-                                                                }
-                                                                else
-                                                                {
-                                                                    // This is the first entry in a N_SO that contains a directory or
-                                                                    // a full path to the source file
-                                                                    N_SO_index = sym_idx;
-                                                                }
-                                                            }
-                                                            else if ((N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms))
-                                                            {
-                                                                // This is usually the second N_SO entry that contains just the filename,
-                                                                // so here we combine it with the first one if we are minimizing the symbol table
-                                                                const char *so_path = sym[sym_idx - 1].GetMangled().GetDemangledName(lldb::eLanguageTypeUnknown).AsCString();
-                                                                if (so_path && so_path[0])
-                                                                {
-                                                                    std::string full_so_path (so_path);
-                                                                    const size_t double_slash_pos = full_so_path.find("//");
-                                                                    if (double_slash_pos != std::string::npos)
-                                                                    {
-                                                                        // The linker has been generating bad N_SO entries with doubled up paths
-                                                                        // in the format "%s%s" where the first string in the DW_AT_comp_dir,
-                                                                        // and the second is the directory for the source file so you end up with
-                                                                        // a path that looks like "/tmp/src//tmp/src/"
-                                                                        FileSpec so_dir(so_path, false);
-                                                                        if (!so_dir.Exists())
-                                                                        {
-                                                                            so_dir.SetFile(&full_so_path[double_slash_pos + 1], false);
-                                                                            if (so_dir.Exists())
-                                                                            {
-                                                                                // Trim off the incorrect path
-                                                                                full_so_path.erase(0, double_slash_pos + 1);
-                                                                            }
-                                                                        }
-                                                                    }
-                                                                    if (*full_so_path.rbegin() != '/')
-                                                                        full_so_path += '/';
-                                                                    full_so_path += symbol_name;
-                                                                    sym[sym_idx - 1].GetMangled().SetValue(ConstString(full_so_path.c_str()), false);
-                                                                    add_nlist = false;
-                                                                    m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
-                                                                }
-                                                            }
-                                                            else
-                                                            {
-                                                                // This could be a relative path to a N_SO
-                                                                N_SO_index = sym_idx;
-                                                            }
-                                                        }
-                                                        break;
-
-                                                    case N_OSO:
-                                                        // object file name: name,,0,0,st_mtime
-                                                        type = eSymbolTypeObjectFile;
-                                                        break;
-
-                                                    case N_LSYM:
-                                                        // local sym: name,,NO_SECT,type,offset
-                                                        type = eSymbolTypeLocal;
-                                                        break;
-
-                                                        //----------------------------------------------------------------------
-                                                        // INCL scopes
-                                                        //----------------------------------------------------------------------
-                                                    case N_BINCL:
-                                                        // include file beginning: name,,NO_SECT,0,sum
-                                                        // We use the current number of symbols in the symbol table in lieu of
-                                                        // using nlist_idx in case we ever start trimming entries out
-                                                        N_INCL_indexes.push_back(sym_idx);
-                                                        type = eSymbolTypeScopeBegin;
-                                                        break;
-
-                                                    case N_EINCL:
-                                                        // include file end: name,,NO_SECT,0,0
-                                                        // Set the size of the N_BINCL to the terminating index of this N_EINCL
-                                                        // so that we can always skip the entire symbol if we need to navigate
-                                                        // more quickly at the source level when parsing STABS
-                                                        if ( !N_INCL_indexes.empty() )
-                                                        {
-                                                            symbol_ptr = symtab->SymbolAtIndex(N_INCL_indexes.back());
-                                                            symbol_ptr->SetByteSize(sym_idx + 1);
-                                                            symbol_ptr->SetSizeIsSibling(true);
-                                                            N_INCL_indexes.pop_back();
-                                                        }
-                                                        type = eSymbolTypeScopeEnd;
-                                                        break;
-
-                                                    case N_SOL:
-                                                        // #included file name: name,,n_sect,0,address
-                                                        type = eSymbolTypeHeaderFile;
-
-                                                        // We currently don't use the header files on darwin
-                                                        add_nlist = false;
-                                                        break;
-
-                                                    case N_PARAMS:
-                                                        // compiler parameters: name,,NO_SECT,0,0
-                                                        type = eSymbolTypeCompiler;
-                                                        break;
-
-                                                    case N_VERSION:
-                                                        // compiler version: name,,NO_SECT,0,0
-                                                        type = eSymbolTypeCompiler;
-                                                        break;
-
-                                                    case N_OLEVEL:
-                                                        // compiler -O level: name,,NO_SECT,0,0
-                                                        type = eSymbolTypeCompiler;
-                                                        break;
-
-                                                    case N_PSYM:
-                                                        // parameter: name,,NO_SECT,type,offset
-                                                        type = eSymbolTypeVariable;
-                                                        break;
-
-                                                    case N_ENTRY:
-                                                        // alternate entry: name,,n_sect,linenumber,address
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        type = eSymbolTypeLineEntry;
-                                                        break;
-
-                                                        //----------------------------------------------------------------------
-                                                        // Left and Right Braces
-                                                        //----------------------------------------------------------------------
-                                                    case N_LBRAC:
-                                                        // left bracket: 0,,NO_SECT,nesting level,address
-                                                        // We use the current number of symbols in the symbol table in lieu of
-                                                        // using nlist_idx in case we ever start trimming entries out
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        N_BRAC_indexes.push_back(sym_idx);
-                                                        type = eSymbolTypeScopeBegin;
-                                                        break;
-
-                                                    case N_RBRAC:
-                                                        // right bracket: 0,,NO_SECT,nesting level,address
-                                                        // Set the size of the N_LBRAC to the terminating index of this N_RBRAC
-                                                        // so that we can always skip the entire symbol if we need to navigate
-                                                        // more quickly at the source level when parsing STABS
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        if ( !N_BRAC_indexes.empty() )
-                                                        {
-                                                            symbol_ptr = symtab->SymbolAtIndex(N_BRAC_indexes.back());
-                                                            symbol_ptr->SetByteSize(sym_idx + 1);
-                                                            symbol_ptr->SetSizeIsSibling(true);
-                                                            N_BRAC_indexes.pop_back();
-                                                        }
-                                                        type = eSymbolTypeScopeEnd;
-                                                        break;
-
-                                                    case N_EXCL:
-                                                        // deleted include file: name,,NO_SECT,0,sum
-                                                        type = eSymbolTypeHeaderFile;
-                                                        break;
-
-                                                        //----------------------------------------------------------------------
-                                                        // COMM scopes
-                                                        //----------------------------------------------------------------------
-                                                    case N_BCOMM:
-                                                        // begin common: name,,NO_SECT,0,0
-                                                        // We use the current number of symbols in the symbol table in lieu of
-                                                        // using nlist_idx in case we ever start trimming entries out
-                                                        type = eSymbolTypeScopeBegin;
-                                                        N_COMM_indexes.push_back(sym_idx);
-                                                        break;
-
-                                                    case N_ECOML:
-                                                        // end common (local name): 0,,n_sect,0,address
-                                                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                                                        // Fall through
-
-                                                    case N_ECOMM:
-                                                        // end common: name,,n_sect,0,0
-                                                        // Set the size of the N_BCOMM to the terminating index of this N_ECOMM/N_ECOML
-                                                        // so that we can always skip the entire symbol if we need to navigate
-                                                        // more quickly at the source level when parsing STABS
-                                                        if ( !N_COMM_indexes.empty() )
-                                                        {
-                                                            symbol_ptr = symtab->SymbolAtIndex(N_COMM_indexes.back());
-                                                            symbol_ptr->SetByteSize(sym_idx + 1);
-                                                            symbol_ptr->SetSizeIsSibling(true);
-                                                            N_COMM_indexes.pop_back();
-                                                        }
-                                                        type = eSymbolTypeScopeEnd;
-                                                        break;
-
-                                                    case N_LENG:
-                                                        // second stab entry with length information
-                                                        type = eSymbolTypeAdditional;
-                                                        break;
-
-                                                    default: break;
-                                                }
-                                            }
-                                            else
-                                            {
-                                                //uint8_t n_pext    = N_PEXT & nlist.n_type;
-                                                uint8_t n_type  = N_TYPE & nlist.n_type;
-                                                sym[sym_idx].SetExternal((N_EXT & nlist.n_type) != 0);
-
-                                                switch (n_type)
-                                                {
-                                                    case N_INDR:
-                                                        {
-                                                            const char *reexport_name_cstr = strtab_data.PeekCStr(nlist.n_value);
-                                                            if (reexport_name_cstr && reexport_name_cstr[0])
-                                                            {
-                                                                type = eSymbolTypeReExported;
-                                                                ConstString reexport_name(reexport_name_cstr + ((reexport_name_cstr[0] == '_') ? 1 : 0));
-                                                                sym[sym_idx].SetReExportedSymbolName(reexport_name);
-                                                                set_value = false;
-                                                                reexport_shlib_needs_fixup[sym_idx] = reexport_name;
-                                                                indirect_symbol_names.insert(ConstString(symbol_name + ((symbol_name[0] == '_') ? 1 : 0)));
-                                                            }
-                                                            else
-                                                                type = eSymbolTypeUndefined;
-                                                        }
-                                                        break;
-                                                        
-                                                    case N_UNDF:
-                                                        if (symbol_name && symbol_name[0])
-                                                        {
-                                                            ConstString undefined_name(symbol_name + ((symbol_name[0] == '_') ? 1 : 0));
-                                                            undefined_name_to_desc[undefined_name] = nlist.n_desc;
-                                                        }
-                                                        // Fall through
-                                                    case N_PBUD:
-                                                        type = eSymbolTypeUndefined;
-                                                        break;
-
-                                                    case N_ABS:
-                                                        type = eSymbolTypeAbsolute;
-                                                        break;
-
-                                                    case N_SECT:
-                                                        {
-                                                            symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-
-                                                            if (symbol_section == NULL)
-                                                            {
-                                                                // TODO: warn about this?
-                                                                add_nlist = false;
-                                                                break;
-                                                            }
-
-                                                            if (TEXT_eh_frame_sectID == nlist.n_sect)
-                                                            {
-                                                                type = eSymbolTypeException;
-                                                            }
-                                                            else
-                                                            {
-                                                                uint32_t section_type = symbol_section->Get() & SECTION_TYPE;
-
-                                                                switch (section_type)
-                                                                {
-                                                                    case S_CSTRING_LITERALS:           type = eSymbolTypeData;    break; // section with only literal C strings
-                                                                    case S_4BYTE_LITERALS:             type = eSymbolTypeData;    break; // section with only 4 byte literals
-                                                                    case S_8BYTE_LITERALS:             type = eSymbolTypeData;    break; // section with only 8 byte literals
-                                                                    case S_LITERAL_POINTERS:           type = eSymbolTypeTrampoline; break; // section with only pointers to literals
-                                                                    case S_NON_LAZY_SYMBOL_POINTERS:   type = eSymbolTypeTrampoline; break; // section with only non-lazy symbol pointers
-                                                                    case S_LAZY_SYMBOL_POINTERS:       type = eSymbolTypeTrampoline; break; // section with only lazy symbol pointers
-                                                                    case S_SYMBOL_STUBS:               type = eSymbolTypeTrampoline; break; // section with only symbol stubs, byte size of stub in the reserved2 field
-                                                                    case S_MOD_INIT_FUNC_POINTERS:     type = eSymbolTypeCode;    break; // section with only function pointers for initialization
-                                                                    case S_MOD_TERM_FUNC_POINTERS:     type = eSymbolTypeCode;    break; // section with only function pointers for termination
-                                                                    case S_INTERPOSING:                type = eSymbolTypeTrampoline;  break; // section with only pairs of function pointers for interposing
-                                                                    case S_16BYTE_LITERALS:            type = eSymbolTypeData;    break; // section with only 16 byte literals
-                                                                    case S_DTRACE_DOF:                 type = eSymbolTypeInstrumentation; break;
-                                                                    case S_LAZY_DYLIB_SYMBOL_POINTERS: type = eSymbolTypeTrampoline; break;
-                                                                    default:
-                                                                        switch (symbol_section->GetType())
-                                                                        {
-                                                                            case lldb::eSectionTypeCode:
-                                                                                type = eSymbolTypeCode;
-                                                                                break;
-                                                                            case eSectionTypeData:
-                                                                            case eSectionTypeDataCString:            // Inlined C string data
-                                                                            case eSectionTypeDataCStringPointers:    // Pointers to C string data
-                                                                            case eSectionTypeDataSymbolAddress:      // Address of a symbol in the symbol table
-                                                                            case eSectionTypeData4:
-                                                                            case eSectionTypeData8:
-                                                                            case eSectionTypeData16:
-                                                                                type = eSymbolTypeData;
-                                                                                break;
-                                                                            default:
-                                                                                break;
-                                                                        }
-                                                                        break;
-                                                                }
-
-                                                                if (type == eSymbolTypeInvalid)
-                                                                {
-                                                                    const char *symbol_sect_name = symbol_section->GetName().AsCString();
-                                                                    if (symbol_section->IsDescendant (text_section_sp.get()))
-                                                                    {
-                                                                        if (symbol_section->IsClear(S_ATTR_PURE_INSTRUCTIONS |
-                                                                                                    S_ATTR_SELF_MODIFYING_CODE |
-                                                                                                    S_ATTR_SOME_INSTRUCTIONS))
-                                                                            type = eSymbolTypeData;
-                                                                        else
-                                                                            type = eSymbolTypeCode;
-                                                                    }
-                                                                    else if (symbol_section->IsDescendant(data_section_sp.get()) ||
-                                                                             symbol_section->IsDescendant(data_dirty_section_sp.get()) ||
-                                                                             symbol_section->IsDescendant(data_const_section_sp.get()))
-                                                                    {
-                                                                        if (symbol_sect_name && ::strstr (symbol_sect_name, "__objc") == symbol_sect_name)
-                                                                        {
-                                                                            type = eSymbolTypeRuntime;
-                                                                            
-                                                                            if (symbol_name)
-                                                                            {
-                                                                                llvm::StringRef symbol_name_ref(symbol_name);
-                                                                                if (symbol_name_ref.startswith("_OBJC_"))
-                                                                                {
-                                                                                    static const llvm::StringRef g_objc_v2_prefix_class ("_OBJC_CLASS_$_");
-                                                                                    static const llvm::StringRef g_objc_v2_prefix_metaclass ("_OBJC_METACLASS_$_");
-                                                                                    static const llvm::StringRef g_objc_v2_prefix_ivar ("_OBJC_IVAR_$_");
-                                                                                    if (symbol_name_ref.startswith(g_objc_v2_prefix_class))
-                                                                                    {
-                                                                                        symbol_name_non_abi_mangled = symbol_name + 1;
-                                                                                        symbol_name = symbol_name + g_objc_v2_prefix_class.size();
-                                                                                        type = eSymbolTypeObjCClass;
-                                                                                        demangled_is_synthesized = true;
-                                                                                    }
-                                                                                    else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
-                                                                                    {
-                                                                                        symbol_name_non_abi_mangled = symbol_name + 1;
-                                                                                        symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
-                                                                                        type = eSymbolTypeObjCMetaClass;
-                                                                                        demangled_is_synthesized = true;
-                                                                                    }
-                                                                                    else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
-                                                                                    {
-                                                                                        symbol_name_non_abi_mangled = symbol_name + 1;
-                                                                                        symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
-                                                                                        type = eSymbolTypeObjCIVar;
-                                                                                        demangled_is_synthesized = true;
-                                                                                    }
-                                                                                }
-                                                                            }
-                                                                        }
-                                                                        else if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
-                                                                        {
-                                                                            type = eSymbolTypeException;
-                                                                        }
-                                                                        else
-                                                                        {
-                                                                            type = eSymbolTypeData;
-                                                                        }
-                                                                    }
-                                                                    else if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
-                                                                    {
-                                                                        type = eSymbolTypeTrampoline;
-                                                                    }
-                                                                    else if (symbol_section->IsDescendant(objc_section_sp.get()))
-                                                                    {
-                                                                        type = eSymbolTypeRuntime;
-                                                                        if (symbol_name && symbol_name[0] == '.')
-                                                                        {
-                                                                            llvm::StringRef symbol_name_ref(symbol_name);
-                                                                            static const llvm::StringRef g_objc_v1_prefix_class (".objc_class_name_");
-                                                                            if (symbol_name_ref.startswith(g_objc_v1_prefix_class))
-                                                                            {
-                                                                                symbol_name_non_abi_mangled = symbol_name;
-                                                                                symbol_name = symbol_name + g_objc_v1_prefix_class.size();
-                                                                                type = eSymbolTypeObjCClass;
-                                                                                demangled_is_synthesized = true;
-                                                                            }
-                                                                        }
-                                                                    }
-                                                                }
-                                                            }
-                                                        }
-                                                        break;
-                                                }
-                                            }
-
-                                            if (add_nlist)
-                                            {
-                                                uint64_t symbol_value = nlist.n_value;
-                                                if (symbol_name_non_abi_mangled)
-                                                {
-                                                    sym[sym_idx].GetMangled().SetMangledName (ConstString(symbol_name_non_abi_mangled));
-                                                    sym[sym_idx].GetMangled().SetDemangledName (ConstString(symbol_name));
-                                                }
-                                                else
-                                                {
-                                                    bool symbol_name_is_mangled = false;
-                                                    
-                                                    if (symbol_name && symbol_name[0] == '_')
-                                                    {
-                                                        symbol_name_is_mangled = symbol_name[1] == '_';
-                                                        symbol_name++;  // Skip the leading underscore
-                                                    }
-
-                                                    if (symbol_name)
-                                                    {
-                                                        ConstString const_symbol_name(symbol_name);
-                                                        sym[sym_idx].GetMangled().SetValue(const_symbol_name, symbol_name_is_mangled);
-                                                        if (is_gsym && is_debug)
-                                                        {
-                                                            const char *gsym_name = sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled).GetCString();
-                                                            if (gsym_name)
-                                                                N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
-                                                        }
-                                                    }
-                                                }
-                                                if (symbol_section)
-                                                {
-                                                    const addr_t section_file_addr = symbol_section->GetFileAddress();
-                                                    if (symbol_byte_size == 0 && function_starts_count > 0)
-                                                    {
-                                                        addr_t symbol_lookup_file_addr = nlist.n_value;
-                                                        // Do an exact address match for non-ARM addresses, else get the closest since
-                                                        // the symbol might be a thumb symbol which has an address with bit zero set
-                                                        FunctionStarts::Entry *func_start_entry = function_starts.FindEntry (symbol_lookup_file_addr, !is_arm);
-                                                        if (is_arm && func_start_entry)
-                                                        {
-                                                            // Verify that the function start address is the symbol address (ARM)
-                                                            // or the symbol address + 1 (thumb)
-                                                            if (func_start_entry->addr != symbol_lookup_file_addr &&
-                                                                func_start_entry->addr != (symbol_lookup_file_addr + 1))
-                                                            {
-                                                                // Not the right entry, NULL it out...
-                                                                func_start_entry = NULL;
-                                                            }
-                                                        }
-                                                        if (func_start_entry)
-                                                        {
-                                                            func_start_entry->data = true;
-
-                                                            addr_t symbol_file_addr = func_start_entry->addr;
-                                                            uint32_t symbol_flags = 0;
-                                                            if (is_arm)
-                                                            {
-                                                                if (symbol_file_addr & 1)
-                                                                    symbol_flags = MACHO_NLIST_ARM_SYMBOL_IS_THUMB;
-                                                                symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-                                                            }
-
-                                                            const FunctionStarts::Entry *next_func_start_entry = function_starts.FindNextEntry (func_start_entry);
-                                                            const addr_t section_end_file_addr = section_file_addr + symbol_section->GetByteSize();
-                                                            if (next_func_start_entry)
-                                                            {
-                                                                addr_t next_symbol_file_addr = next_func_start_entry->addr;
-                                                                // Be sure the clear the Thumb address bit when we calculate the size
-                                                                // from the current and next address
-                                                                if (is_arm)
-                                                                    next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-                                                                symbol_byte_size = std::min<lldb::addr_t>(next_symbol_file_addr - symbol_file_addr, section_end_file_addr - symbol_file_addr);
-                                                            }
-                                                            else
-                                                            {
-                                                                symbol_byte_size = section_end_file_addr - symbol_file_addr;
-                                                            }
-                                                        }
-                                                    }
-                                                    symbol_value -= section_file_addr;
-                                                }
-
-                                                if (is_debug == false)
-                                                {
-                                                    if (type == eSymbolTypeCode)
-                                                    {
-                                                        // See if we can find a N_FUN entry for any code symbols.
-                                                        // If we do find a match, and the name matches, then we
-                                                        // can merge the two into just the function symbol to avoid
-                                                        // duplicate entries in the symbol table
-                                                        std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range;
-                                                        range = N_FUN_addr_to_sym_idx.equal_range(nlist.n_value);
-                                                        if (range.first != range.second)
-                                                        {
-                                                            bool found_it = false;
-                                                            for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos)
-                                                            {
-                                                                if (sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled))
-                                                                {
-                                                                    m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
-                                                                    // We just need the flags from the linker symbol, so put these flags
-                                                                    // into the N_FUN flags to avoid duplicate symbols in the symbol table
-                                                                    sym[pos->second].SetExternal(sym[sym_idx].IsExternal());
-                                                                    sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                                                    if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end())
-                                                                        sym[pos->second].SetType (eSymbolTypeResolver);
-                                                                    sym[sym_idx].Clear();
-                                                                    found_it = true;
-                                                                    break;
-                                                                }
-                                                            }
-                                                            if (found_it)
-                                                                continue;
-                                                        }
-                                                        else
-                                                        {
-                                                            if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end())
-                                                                type = eSymbolTypeResolver;
-                                                        }
-                                                    }
-                                                    else if (type == eSymbolTypeData          ||
-                                                             type == eSymbolTypeObjCClass     ||
-                                                             type == eSymbolTypeObjCMetaClass ||
-                                                             type == eSymbolTypeObjCIVar      )
-                                                    {
-                                                        // See if we can find a N_STSYM entry for any data symbols.
-                                                        // If we do find a match, and the name matches, then we
-                                                        // can merge the two into just the Static symbol to avoid
-                                                        // duplicate entries in the symbol table
-                                                        std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range;
-                                                        range = N_STSYM_addr_to_sym_idx.equal_range(nlist.n_value);
-                                                        if (range.first != range.second)
-                                                        {
-                                                            bool found_it = false;
-                                                            for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos)
-                                                            {
-                                                                if (sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled))
-                                                                {
-                                                                    m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
-                                                                    // We just need the flags from the linker symbol, so put these flags
-                                                                    // into the N_STSYM flags to avoid duplicate symbols in the symbol table
-                                                                    sym[pos->second].SetExternal(sym[sym_idx].IsExternal());
-                                                                    sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                                                    sym[sym_idx].Clear();
-                                                                    found_it = true;
-                                                                    break;
-                                                                }
-                                                            }
-                                                            if (found_it)
-                                                                continue;
-                                                        }
-                                                        else
-                                                        {
-                                                            const char *gsym_name = sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled).GetCString();
-                                                            if (gsym_name)
-                                                            {
-                                                                // Combine N_GSYM stab entries with the non stab symbol
-                                                                ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(gsym_name);
-                                                                if (pos != N_GSYM_name_to_sym_idx.end())
-                                                                {
-                                                                    const uint32_t GSYM_sym_idx = pos->second;
-                                                                    m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
-                                                                    // Copy the address, because often the N_GSYM address has an invalid address of zero
-                                                                    // when the global is a common symbol
-                                                                    sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
-                                                                    sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
-                                                                    // We just need the flags from the linker symbol, so put these flags
-                                                                    // into the N_GSYM flags to avoid duplicate symbols in the symbol table
-                                                                    sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                                                    sym[sym_idx].Clear();
-                                                                    continue;
-                                                                }
-                                                            }
-                                                        }
-                                                    }
-                                                }
-
-                                                sym[sym_idx].SetID (nlist_idx);
-                                                sym[sym_idx].SetType (type);
-                                                if (set_value)
-                                                {
-                                                    sym[sym_idx].GetAddressRef().SetSection (symbol_section);
-                                                    sym[sym_idx].GetAddressRef().SetOffset (symbol_value);
-                                                }
-                                                sym[sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-
-                                                if (symbol_byte_size > 0)
-                                                    sym[sym_idx].SetByteSize(symbol_byte_size);
-
-                                                if (demangled_is_synthesized)
-                                                    sym[sym_idx].SetDemangledNameIsSynthesized(true);
-                                                ++sym_idx;
-                                            }
-                                            else
-                                            {
-                                                sym[sym_idx].Clear();
-                                            }
-
-                                        }
-                                        /////////////////////////////
-                                    }
-                                    break; // No more entries to consider
-                                }
-                            }
-
-                            for (const auto &pos :reexport_shlib_needs_fixup)
-                            {
-                                const auto undef_pos = undefined_name_to_desc.find(pos.second);
-                                if (undef_pos != undefined_name_to_desc.end())
-                                {
-                                    const uint8_t dylib_ordinal = llvm::MachO::GET_LIBRARY_ORDINAL(undef_pos->second);
-                                    if (dylib_ordinal > 0 && dylib_ordinal < dylib_files.GetSize())
-                                        sym[pos.first].SetReExportedSymbolSharedLibrary(dylib_files.GetFileSpecAtIndex(dylib_ordinal-1));
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        // Must reset this in case it was mutated above!
-        nlist_data_offset = 0;
-#endif
-
-        if (nlist_data.GetByteSize() > 0)
-        {
-
-            // If the sym array was not created while parsing the DSC unmapped
-            // symbols, create it now.
-            if (sym == NULL)
-            {
-                sym = symtab->Resize (symtab_load_command.nsyms + m_dysymtab.nindirectsyms);
-                num_syms = symtab->GetNumSymbols();
-            }
-
-            if (unmapped_local_symbols_found)
-            {
-                assert(m_dysymtab.ilocalsym == 0);
-                nlist_data_offset += (m_dysymtab.nlocalsym * nlist_byte_size);
-                nlist_idx = m_dysymtab.nlocalsym;
-            }
-            else
-            {
-                nlist_idx = 0;
-            }
-
-            typedef std::map<ConstString, uint16_t> UndefinedNameToDescMap;
-            typedef std::map<uint32_t, ConstString> SymbolIndexToName;
-            UndefinedNameToDescMap undefined_name_to_desc;
-            SymbolIndexToName reexport_shlib_needs_fixup;
-            for (; nlist_idx < symtab_load_command.nsyms; ++nlist_idx)
-            {
-                struct nlist_64 nlist;
-                if (!nlist_data.ValidOffsetForDataOfSize(nlist_data_offset, nlist_byte_size))
-                    break;
-
-                nlist.n_strx  = nlist_data.GetU32_unchecked(&nlist_data_offset);
-                nlist.n_type  = nlist_data.GetU8_unchecked (&nlist_data_offset);
-                nlist.n_sect  = nlist_data.GetU8_unchecked (&nlist_data_offset);
-                nlist.n_desc  = nlist_data.GetU16_unchecked (&nlist_data_offset);
-                nlist.n_value = nlist_data.GetAddress_unchecked (&nlist_data_offset);
-
-                SymbolType type = eSymbolTypeInvalid;
-                const char *symbol_name = NULL;
-
-                if (have_strtab_data)
-                {
-                    symbol_name = strtab_data.PeekCStr(nlist.n_strx);
-
-                    if (symbol_name == NULL)
-                    {
-                        // No symbol should be NULL, even the symbols with no
-                        // string values should have an offset zero which points
-                        // to an empty C-string
-                        Host::SystemLog (Host::eSystemLogError,
-                                         "error: symbol[%u] has invalid string table offset 0x%x in %s, ignoring symbol\n",
-                                         nlist_idx,
-                                         nlist.n_strx,
-                                         module_sp->GetFileSpec().GetPath().c_str());
-                        continue;
-                    }
-                    if (symbol_name[0] == '\0')
-                        symbol_name = NULL;
-                }
-                else
-                {
-                    const addr_t str_addr = strtab_addr + nlist.n_strx;
-                    Error str_error;
-                    if (process->ReadCStringFromMemory(str_addr, memory_symbol_name, str_error))
-                        symbol_name = memory_symbol_name.c_str();
-                }
-                const char *symbol_name_non_abi_mangled = NULL;
-
-                SectionSP symbol_section;
-                lldb::addr_t symbol_byte_size = 0;
-                bool add_nlist = true;
-                bool is_gsym = false;
-                bool is_debug = ((nlist.n_type & N_STAB) != 0);
-                bool demangled_is_synthesized = false;
-                bool set_value = true;
-                assert (sym_idx < num_syms);
-
-                sym[sym_idx].SetDebug (is_debug);
-
-                if (is_debug)
-                {
-                    switch (nlist.n_type)
-                    {
-                    case N_GSYM:
-                        // global symbol: name,,NO_SECT,type,0
-                        // Sometimes the N_GSYM value contains the address.
-
-                        // FIXME: In the .o files, we have a GSYM and a debug symbol for all the ObjC data.  They
-                        // have the same address, but we want to ensure that we always find only the real symbol,
-                        // 'cause we don't currently correctly attribute the GSYM one to the ObjCClass/Ivar/MetaClass
-                        // symbol type.  This is a temporary hack to make sure the ObjectiveC symbols get treated
-                        // correctly.  To do this right, we should coalesce all the GSYM & global symbols that have the
-                        // same address.
-                        is_gsym = true;
-                        sym[sym_idx].SetExternal(true);
-
-                        if (symbol_name && symbol_name[0] == '_' && symbol_name[1] ==  'O')
-                        {
-                            llvm::StringRef symbol_name_ref(symbol_name);
-                            if (symbol_name_ref.startswith(g_objc_v2_prefix_class))
-                            {
-                                symbol_name_non_abi_mangled = symbol_name + 1;
-                                symbol_name = symbol_name + g_objc_v2_prefix_class.size();
-                                type = eSymbolTypeObjCClass;
-                                demangled_is_synthesized = true;
-                                
-                            }
-                            else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
-                            {
-                                symbol_name_non_abi_mangled = symbol_name + 1;
-                                symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
-                                type = eSymbolTypeObjCMetaClass;
-                                demangled_is_synthesized = true;
-                            }
-                            else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
-                            {
-                                symbol_name_non_abi_mangled = symbol_name + 1;
-                                symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
-                                type = eSymbolTypeObjCIVar;
-                                demangled_is_synthesized = true;
-                            }
-                        }
-                        else
-                        {
-                            if (nlist.n_value != 0)
-                                symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                            type = eSymbolTypeData;
-                        }
-                        break;
-
-                    case N_FNAME:
-                        // procedure name (f77 kludge): name,,NO_SECT,0,0
-                        type = eSymbolTypeCompiler;
-                        break;
-
-                    case N_FUN:
-                        // procedure: name,,n_sect,linenumber,address
-                        if (symbol_name)
-                        {
-                            type = eSymbolTypeCode;
-                            symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-
-                            N_FUN_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx));
-                            // We use the current number of symbols in the symbol table in lieu of
-                            // using nlist_idx in case we ever start trimming entries out
-                            N_FUN_indexes.push_back(sym_idx);
-                        }
-                        else
-                        {
-                            type = eSymbolTypeCompiler;
-
-                            if ( !N_FUN_indexes.empty() )
-                            {
-                                // Copy the size of the function into the original STAB entry so we don't have
-                                // to hunt for it later
-                                symtab->SymbolAtIndex(N_FUN_indexes.back())->SetByteSize(nlist.n_value);
-                                N_FUN_indexes.pop_back();
-                                // We don't really need the end function STAB as it contains the size which
-                                // we already placed with the original symbol, so don't add it if we want a
-                                // minimal symbol table
-                                add_nlist = false;
-                            }
-                        }
-                        break;
-
-                    case N_STSYM:
-                        // static symbol: name,,n_sect,type,address
-                        N_STSYM_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx));
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        if (symbol_name && symbol_name[0])
-                        {
-                            type = ObjectFile::GetSymbolTypeFromName(symbol_name+1, eSymbolTypeData);
-                        }
-                        break;
-
-                    case N_LCSYM:
-                        // .lcomm symbol: name,,n_sect,type,address
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        type = eSymbolTypeCommonBlock;
-                        break;
-
-                    case N_BNSYM:
-                        // We use the current number of symbols in the symbol table in lieu of
-                        // using nlist_idx in case we ever start trimming entries out
-                        // Skip these if we want minimal symbol tables
-                        add_nlist = false;
-                        break;
-
-                    case N_ENSYM:
-                        // Set the size of the N_BNSYM to the terminating index of this N_ENSYM
-                        // so that we can always skip the entire symbol if we need to navigate
-                        // more quickly at the source level when parsing STABS
-                        // Skip these if we want minimal symbol tables
-                        add_nlist = false;
-                        break;
-
-
-                    case N_OPT:
-                        // emitted with gcc2_compiled and in gcc source
-                        type = eSymbolTypeCompiler;
-                        break;
-
-                    case N_RSYM:
-                        // register sym: name,,NO_SECT,type,register
-                        type = eSymbolTypeVariable;
-                        break;
-
-                    case N_SLINE:
-                        // src line: 0,,n_sect,linenumber,address
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        type = eSymbolTypeLineEntry;
-                        break;
-
-                    case N_SSYM:
-                        // structure elt: name,,NO_SECT,type,struct_offset
-                        type = eSymbolTypeVariableType;
-                        break;
-
-                    case N_SO:
-                        // source file name
-                        type = eSymbolTypeSourceFile;
-                        if (symbol_name == NULL)
-                        {
-                            add_nlist = false;
-                            if (N_SO_index != UINT32_MAX)
-                            {
-                                // Set the size of the N_SO to the terminating index of this N_SO
-                                // so that we can always skip the entire N_SO if we need to navigate
-                                // more quickly at the source level when parsing STABS
-                                symbol_ptr = symtab->SymbolAtIndex(N_SO_index);
-                                symbol_ptr->SetByteSize(sym_idx);
-                                symbol_ptr->SetSizeIsSibling(true);
-                            }
-                            N_NSYM_indexes.clear();
-                            N_INCL_indexes.clear();
-                            N_BRAC_indexes.clear();
-                            N_COMM_indexes.clear();
-                            N_FUN_indexes.clear();
-                            N_SO_index = UINT32_MAX;
-                        }
-                        else
-                        {
-                            // We use the current number of symbols in the symbol table in lieu of
-                            // using nlist_idx in case we ever start trimming entries out
-                            const bool N_SO_has_full_path = symbol_name[0] == '/';
-                            if (N_SO_has_full_path)
-                            {
-                                if ((N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms))
-                                {
-                                    // We have two consecutive N_SO entries where the first contains a directory
-                                    // and the second contains a full path.
-                                    sym[sym_idx - 1].GetMangled().SetValue(ConstString(symbol_name), false);
-                                    m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
-                                    add_nlist = false;
-                                }
-                                else
-                                {
-                                    // This is the first entry in a N_SO that contains a directory or
-                                    // a full path to the source file
-                                    N_SO_index = sym_idx;
-                                }
-                            }
-                            else if ((N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms))
-                            {
-                                // This is usually the second N_SO entry that contains just the filename,
-                                // so here we combine it with the first one if we are minimizing the symbol table
-                                const char *so_path = sym[sym_idx - 1].GetMangled().GetDemangledName(lldb::eLanguageTypeUnknown).AsCString();
-                                if (so_path && so_path[0])
-                                {
-                                    std::string full_so_path (so_path);
-                                    const size_t double_slash_pos = full_so_path.find("//");
-                                    if (double_slash_pos != std::string::npos)
-                                    {
-                                        // The linker has been generating bad N_SO entries with doubled up paths
-                                        // in the format "%s%s" where the first string in the DW_AT_comp_dir,
-                                        // and the second is the directory for the source file so you end up with
-                                        // a path that looks like "/tmp/src//tmp/src/"
-                                        FileSpec so_dir(so_path, false);
-                                        if (!so_dir.Exists())
-                                        {
-                                            so_dir.SetFile(&full_so_path[double_slash_pos + 1], false);
-                                            if (so_dir.Exists())
-                                            {
-                                                // Trim off the incorrect path
-                                                full_so_path.erase(0, double_slash_pos + 1);
-                                            }
-                                        }
-                                    }
-                                    if (*full_so_path.rbegin() != '/')
-                                        full_so_path += '/';
-                                    full_so_path += symbol_name;
-                                    sym[sym_idx - 1].GetMangled().SetValue(ConstString(full_so_path.c_str()), false);
-                                    add_nlist = false;
-                                    m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
-                                }
-                            }
-                            else
-                            {
-                                // This could be a relative path to a N_SO
-                                N_SO_index = sym_idx;
-                            }
-                        }
-                        break;
-
-                    case N_OSO:
-                        // object file name: name,,0,0,st_mtime
-                        type = eSymbolTypeObjectFile;
-                        break;
-
-                    case N_LSYM:
-                        // local sym: name,,NO_SECT,type,offset
-                        type = eSymbolTypeLocal;
-                        break;
-
-                    //----------------------------------------------------------------------
-                    // INCL scopes
-                    //----------------------------------------------------------------------
-                    case N_BINCL:
-                        // include file beginning: name,,NO_SECT,0,sum
-                        // We use the current number of symbols in the symbol table in lieu of
-                        // using nlist_idx in case we ever start trimming entries out
-                        N_INCL_indexes.push_back(sym_idx);
-                        type = eSymbolTypeScopeBegin;
-                        break;
-
-                    case N_EINCL:
-                        // include file end: name,,NO_SECT,0,0
-                        // Set the size of the N_BINCL to the terminating index of this N_EINCL
-                        // so that we can always skip the entire symbol if we need to navigate
-                        // more quickly at the source level when parsing STABS
-                        if ( !N_INCL_indexes.empty() )
-                        {
-                            symbol_ptr = symtab->SymbolAtIndex(N_INCL_indexes.back());
-                            symbol_ptr->SetByteSize(sym_idx + 1);
-                            symbol_ptr->SetSizeIsSibling(true);
-                            N_INCL_indexes.pop_back();
-                        }
-                        type = eSymbolTypeScopeEnd;
-                        break;
-
-                    case N_SOL:
-                        // #included file name: name,,n_sect,0,address
-                        type = eSymbolTypeHeaderFile;
-
-                        // We currently don't use the header files on darwin
-                        add_nlist = false;
-                        break;
-
-                    case N_PARAMS:
-                        // compiler parameters: name,,NO_SECT,0,0
-                        type = eSymbolTypeCompiler;
-                        break;
-
-                    case N_VERSION:
-                        // compiler version: name,,NO_SECT,0,0
-                        type = eSymbolTypeCompiler;
-                        break;
-
-                    case N_OLEVEL:
-                        // compiler -O level: name,,NO_SECT,0,0
-                        type = eSymbolTypeCompiler;
-                        break;
-
-                    case N_PSYM:
-                        // parameter: name,,NO_SECT,type,offset
-                        type = eSymbolTypeVariable;
-                        break;
-
-                    case N_ENTRY:
-                        // alternate entry: name,,n_sect,linenumber,address
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        type = eSymbolTypeLineEntry;
-                        break;
-
-                    //----------------------------------------------------------------------
-                    // Left and Right Braces
-                    //----------------------------------------------------------------------
-                    case N_LBRAC:
-                        // left bracket: 0,,NO_SECT,nesting level,address
-                        // We use the current number of symbols in the symbol table in lieu of
-                        // using nlist_idx in case we ever start trimming entries out
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        N_BRAC_indexes.push_back(sym_idx);
-                        type = eSymbolTypeScopeBegin;
-                        break;
-
-                    case N_RBRAC:
-                        // right bracket: 0,,NO_SECT,nesting level,address
-                        // Set the size of the N_LBRAC to the terminating index of this N_RBRAC
-                        // so that we can always skip the entire symbol if we need to navigate
-                        // more quickly at the source level when parsing STABS
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        if ( !N_BRAC_indexes.empty() )
-                        {
-                            symbol_ptr = symtab->SymbolAtIndex(N_BRAC_indexes.back());
-                            symbol_ptr->SetByteSize(sym_idx + 1);
-                            symbol_ptr->SetSizeIsSibling(true);
-                            N_BRAC_indexes.pop_back();
-                        }
-                        type = eSymbolTypeScopeEnd;
-                        break;
-
-                    case N_EXCL:
-                        // deleted include file: name,,NO_SECT,0,sum
-                        type = eSymbolTypeHeaderFile;
-                        break;
-
-                    //----------------------------------------------------------------------
-                    // COMM scopes
-                    //----------------------------------------------------------------------
-                    case N_BCOMM:
-                        // begin common: name,,NO_SECT,0,0
-                        // We use the current number of symbols in the symbol table in lieu of
-                        // using nlist_idx in case we ever start trimming entries out
-                        type = eSymbolTypeScopeBegin;
-                        N_COMM_indexes.push_back(sym_idx);
-                        break;
-
-                    case N_ECOML:
-                        // end common (local name): 0,,n_sect,0,address
-                        symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-                        LLVM_FALLTHROUGH;
-
-                    case N_ECOMM:
-                        // end common: name,,n_sect,0,0
-                        // Set the size of the N_BCOMM to the terminating index of this N_ECOMM/N_ECOML
-                        // so that we can always skip the entire symbol if we need to navigate
-                        // more quickly at the source level when parsing STABS
-                        if ( !N_COMM_indexes.empty() )
-                        {
-                            symbol_ptr = symtab->SymbolAtIndex(N_COMM_indexes.back());
-                            symbol_ptr->SetByteSize(sym_idx + 1);
-                            symbol_ptr->SetSizeIsSibling(true);
-                            N_COMM_indexes.pop_back();
-                        }
-                        type = eSymbolTypeScopeEnd;
-                        break;
-
-                    case N_LENG:
-                        // second stab entry with length information
-                        type = eSymbolTypeAdditional;
-                        break;
-
-                    default: break;
-                    }
-                }
-                else
-                {
-                    //uint8_t n_pext    = N_PEXT & nlist.n_type;
-                    uint8_t n_type  = N_TYPE & nlist.n_type;
-                    sym[sym_idx].SetExternal((N_EXT & nlist.n_type) != 0);
-
-                    switch (n_type)
-                    {
-                    case N_INDR:
-                        {
-                            const char *reexport_name_cstr = strtab_data.PeekCStr(nlist.n_value);
-                            if (reexport_name_cstr && reexport_name_cstr[0])
-                            {
-                                type = eSymbolTypeReExported;
-                                ConstString reexport_name(reexport_name_cstr + ((reexport_name_cstr[0] == '_') ? 1 : 0));
-                                sym[sym_idx].SetReExportedSymbolName(reexport_name);
-                                set_value = false;
-                                reexport_shlib_needs_fixup[sym_idx] = reexport_name;
-                                indirect_symbol_names.insert(ConstString(symbol_name + ((symbol_name[0] == '_') ? 1 : 0)));
-                            }
-                            else
-                                type = eSymbolTypeUndefined;
-                        }
-                        break;
-
-                    case N_UNDF:
-                        if (symbol_name && symbol_name[0])
-                        {
-                            ConstString undefined_name(symbol_name + ((symbol_name[0] == '_') ? 1 : 0));
-                            undefined_name_to_desc[undefined_name] = nlist.n_desc;
-                        }
-                        LLVM_FALLTHROUGH;
-
-                    case N_PBUD:
-                        type = eSymbolTypeUndefined;
-                        break;
-
-                    case N_ABS:
-                        type = eSymbolTypeAbsolute;
-                        break;
-
-                    case N_SECT:
-                        {
-                            symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-
-                            if (!symbol_section)
-                            {
-                                // TODO: warn about this?
-                                add_nlist = false;
-                                break;
-                            }
-
-                            if (TEXT_eh_frame_sectID == nlist.n_sect)
-                            {
-                                type = eSymbolTypeException;
-                            }
-                            else
-                            {
-                                uint32_t section_type = symbol_section->Get() & SECTION_TYPE;
-
-                                switch (section_type)
-                                {
-                                case S_CSTRING_LITERALS:           type = eSymbolTypeData;    break; // section with only literal C strings
-                                case S_4BYTE_LITERALS:             type = eSymbolTypeData;    break; // section with only 4 byte literals
-                                case S_8BYTE_LITERALS:             type = eSymbolTypeData;    break; // section with only 8 byte literals
-                                case S_LITERAL_POINTERS:           type = eSymbolTypeTrampoline; break; // section with only pointers to literals
-                                case S_NON_LAZY_SYMBOL_POINTERS:   type = eSymbolTypeTrampoline; break; // section with only non-lazy symbol pointers
-                                case S_LAZY_SYMBOL_POINTERS:       type = eSymbolTypeTrampoline; break; // section with only lazy symbol pointers
-                                case S_SYMBOL_STUBS:               type = eSymbolTypeTrampoline; break; // section with only symbol stubs, byte size of stub in the reserved2 field
-                                case S_MOD_INIT_FUNC_POINTERS:     type = eSymbolTypeCode;    break; // section with only function pointers for initialization
-                                case S_MOD_TERM_FUNC_POINTERS:     type = eSymbolTypeCode;    break; // section with only function pointers for termination
-                                case S_INTERPOSING:                type = eSymbolTypeTrampoline;  break; // section with only pairs of function pointers for interposing
-                                case S_16BYTE_LITERALS:            type = eSymbolTypeData;    break; // section with only 16 byte literals
-                                case S_DTRACE_DOF:                 type = eSymbolTypeInstrumentation; break;
-                                case S_LAZY_DYLIB_SYMBOL_POINTERS: type = eSymbolTypeTrampoline; break;
-                                default:
-                                    switch (symbol_section->GetType())
-                                    {
-                                        case lldb::eSectionTypeCode:
-                                            type = eSymbolTypeCode;
-                                            break;
-                                        case eSectionTypeData:
-                                        case eSectionTypeDataCString:            // Inlined C string data
-                                        case eSectionTypeDataCStringPointers:    // Pointers to C string data
-                                        case eSectionTypeDataSymbolAddress:      // Address of a symbol in the symbol table
-                                        case eSectionTypeData4:
-                                        case eSectionTypeData8:
-                                        case eSectionTypeData16:
-                                            type = eSymbolTypeData;
-                                            break;
-                                        default:
-                                            break;
-                                    }
-                                    break;
-                                }
-
-                                if (type == eSymbolTypeInvalid)
-                                {
-                                    const char *symbol_sect_name = symbol_section->GetName().AsCString();
-                                    if (symbol_section->IsDescendant (text_section_sp.get()))
-                                    {
-                                        if (symbol_section->IsClear(S_ATTR_PURE_INSTRUCTIONS |
-                                                                    S_ATTR_SELF_MODIFYING_CODE |
-                                                                    S_ATTR_SOME_INSTRUCTIONS))
-                                            type = eSymbolTypeData;
-                                        else
-                                            type = eSymbolTypeCode;
-                                    }
-                                    else
-                                    if (symbol_section->IsDescendant(data_section_sp.get()) ||
-                                        symbol_section->IsDescendant(data_dirty_section_sp.get()) ||
-                                        symbol_section->IsDescendant(data_const_section_sp.get()))
-                                    {
-                                        if (symbol_sect_name && ::strstr (symbol_sect_name, "__objc") == symbol_sect_name)
-                                        {
-                                            type = eSymbolTypeRuntime;
-
-                                            if (symbol_name)
-                                            {
-                                                llvm::StringRef symbol_name_ref(symbol_name);
-                                                if (symbol_name_ref.startswith("_OBJC_"))
-                                                {
-                                                    static const llvm::StringRef g_objc_v2_prefix_class ("_OBJC_CLASS_$_");
-                                                    static const llvm::StringRef g_objc_v2_prefix_metaclass ("_OBJC_METACLASS_$_");
-                                                    static const llvm::StringRef g_objc_v2_prefix_ivar ("_OBJC_IVAR_$_");
-                                                    if (symbol_name_ref.startswith(g_objc_v2_prefix_class))
-                                                    {
-                                                        symbol_name_non_abi_mangled = symbol_name + 1;
-                                                        symbol_name = symbol_name + g_objc_v2_prefix_class.size();
-                                                        type = eSymbolTypeObjCClass;
-                                                        demangled_is_synthesized = true;
-                                                    }
-                                                    else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
-                                                    {
-                                                        symbol_name_non_abi_mangled = symbol_name + 1;
-                                                        symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
-                                                        type = eSymbolTypeObjCMetaClass;
-                                                        demangled_is_synthesized = true;
-                                                    }
-                                                    else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
-                                                    {
-                                                        symbol_name_non_abi_mangled = symbol_name + 1;
-                                                        symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
-                                                        type = eSymbolTypeObjCIVar;
-                                                        demangled_is_synthesized = true;
-                                                    }
-                                                }
-                                            }
-                                        }
-                                        else
-                                        if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
-                                        {
-                                            type = eSymbolTypeException;
-                                        }
-                                        else
-                                        {
-                                            type = eSymbolTypeData;
-                                        }
-                                    }
-                                    else
-                                    if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
-                                    {
-                                        type = eSymbolTypeTrampoline;
-                                    }
-                                    else
-                                    if (symbol_section->IsDescendant(objc_section_sp.get()))
-                                    {
-                                        type = eSymbolTypeRuntime;
-                                        if (symbol_name && symbol_name[0] == '.')
-                                        {
-                                            llvm::StringRef symbol_name_ref(symbol_name);
-                                            static const llvm::StringRef g_objc_v1_prefix_class (".objc_class_name_");
-                                            if (symbol_name_ref.startswith(g_objc_v1_prefix_class))
-                                            {
-                                                symbol_name_non_abi_mangled = symbol_name;
-                                                symbol_name = symbol_name + g_objc_v1_prefix_class.size();
-                                                type = eSymbolTypeObjCClass;
-                                                demangled_is_synthesized = true;
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                        break;
-                    }
-                }
-
-                if (add_nlist)
-                {
-                    uint64_t symbol_value = nlist.n_value;
-
-                    if (symbol_name_non_abi_mangled)
-                    {
-                        sym[sym_idx].GetMangled().SetMangledName (ConstString(symbol_name_non_abi_mangled));
-                        sym[sym_idx].GetMangled().SetDemangledName (ConstString(symbol_name));
-                    }
-                    else
-                    {
-                        bool symbol_name_is_mangled = false;
-
-                        if (symbol_name && symbol_name[0] == '_')
-                        {
-                            symbol_name_is_mangled = symbol_name[1] == '_';
-                            symbol_name++;  // Skip the leading underscore
-                        }
-
-                        if (symbol_name)
-                        {
-                            ConstString const_symbol_name(symbol_name);
-                            sym[sym_idx].GetMangled().SetValue(const_symbol_name, symbol_name_is_mangled);
-                        }
-                    }
-
-                    if (is_gsym)
-                    {
-                        const char *gsym_name = sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled).GetCString();
-                        if (gsym_name)
-                            N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
-                    }
-
-                    if (symbol_section)
-                    {
-                        const addr_t section_file_addr = symbol_section->GetFileAddress();
-                        if (symbol_byte_size == 0 && function_starts_count > 0)
-                        {
-                            addr_t symbol_lookup_file_addr = nlist.n_value;
-                            // Do an exact address match for non-ARM addresses, else get the closest since
-                            // the symbol might be a thumb symbol which has an address with bit zero set
-                            FunctionStarts::Entry *func_start_entry = function_starts.FindEntry (symbol_lookup_file_addr, !is_arm);
-                            if (is_arm && func_start_entry)
-                            {
-                                // Verify that the function start address is the symbol address (ARM)
-                                // or the symbol address + 1 (thumb)
-                                if (func_start_entry->addr != symbol_lookup_file_addr &&
-                                    func_start_entry->addr != (symbol_lookup_file_addr + 1))
-                                {
-                                    // Not the right entry, NULL it out...
-                                    func_start_entry = NULL;
-                                }
-                            }
-                            if (func_start_entry)
-                            {
-                                func_start_entry->data = true;
-
-                                addr_t symbol_file_addr = func_start_entry->addr;
-                                if (is_arm)
-                                    symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-
-                                const FunctionStarts::Entry *next_func_start_entry = function_starts.FindNextEntry (func_start_entry);
-                                const addr_t section_end_file_addr = section_file_addr + symbol_section->GetByteSize();
-                                if (next_func_start_entry)
-                                {
-                                    addr_t next_symbol_file_addr = next_func_start_entry->addr;
-                                    // Be sure the clear the Thumb address bit when we calculate the size
-                                    // from the current and next address
-                                    if (is_arm)
-                                        next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-                                    symbol_byte_size = std::min<lldb::addr_t>(next_symbol_file_addr - symbol_file_addr, section_end_file_addr - symbol_file_addr);
-                                }
-                                else
-                                {
-                                    symbol_byte_size = section_end_file_addr - symbol_file_addr;
-                                }
-                            }
-                        }
-                        symbol_value -= section_file_addr;
-                    }
-
-                    if (is_debug == false)
-                    {
-                        if (type == eSymbolTypeCode)
-                        {
-                            // See if we can find a N_FUN entry for any code symbols.
-                            // If we do find a match, and the name matches, then we
-                            // can merge the two into just the function symbol to avoid
-                            // duplicate entries in the symbol table
-                            std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range;
-                            range = N_FUN_addr_to_sym_idx.equal_range(nlist.n_value);
-                            if (range.first != range.second)
-                            {
-                                bool found_it = false;
-                                for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos)
-                                {
-                                    if (sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled))
-                                    {
-                                        m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
-                                        // We just need the flags from the linker symbol, so put these flags
-                                        // into the N_FUN flags to avoid duplicate symbols in the symbol table
-                                        sym[pos->second].SetExternal(sym[sym_idx].IsExternal());
-                                        sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                        if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end())
-                                            sym[pos->second].SetType (eSymbolTypeResolver);
-                                        sym[sym_idx].Clear();
-                                        found_it = true;
-                                        break;
-                                    }
-                                }
-                                if (found_it)
-                                    continue;
-                            }
-                            else
-                            {
-                                if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end())
-                                    type = eSymbolTypeResolver;
-                            }
-                        }
-                        else if (type == eSymbolTypeData          ||
-                                 type == eSymbolTypeObjCClass     ||
-                                 type == eSymbolTypeObjCMetaClass ||
-                                 type == eSymbolTypeObjCIVar      )
-                        {
-                            // See if we can find a N_STSYM entry for any data symbols.
-                            // If we do find a match, and the name matches, then we
-                            // can merge the two into just the Static symbol to avoid
-                            // duplicate entries in the symbol table
-                            std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range;
-                            range = N_STSYM_addr_to_sym_idx.equal_range(nlist.n_value);
-                            if (range.first != range.second)
-                            {
-                                bool found_it = false;
-                                for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos)
-                                {
-                                    if (sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled))
-                                    {
-                                        m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
-                                        // We just need the flags from the linker symbol, so put these flags
-                                        // into the N_STSYM flags to avoid duplicate symbols in the symbol table
-                                        sym[pos->second].SetExternal(sym[sym_idx].IsExternal());
-                                        sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                        sym[sym_idx].Clear();
-                                        found_it = true;
-                                        break;
-                                    }
-                                }
-                                if (found_it)
-                                    continue;
-                            }
-                            else
-                            {
-                                // Combine N_GSYM stab entries with the non stab symbol
-                                const char *gsym_name = sym[sym_idx].GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled).GetCString();
-                                if (gsym_name)
-                                {
-                                    ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(gsym_name);
-                                    if (pos != N_GSYM_name_to_sym_idx.end())
-                                    {
-                                        const uint32_t GSYM_sym_idx = pos->second;
-                                        m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
-                                        // Copy the address, because often the N_GSYM address has an invalid address of zero
-                                        // when the global is a common symbol
-                                        sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
-                                        sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
-                                        // We just need the flags from the linker symbol, so put these flags
-                                        // into the N_GSYM flags to avoid duplicate symbols in the symbol table
-                                        sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                        sym[sym_idx].Clear();
-                                        continue;
-                                    }
-                                }
-                            }
-                        }
-                    }
-
-                    sym[sym_idx].SetID (nlist_idx);
-                    sym[sym_idx].SetType (type);
-                    if (set_value)
-                    {
-                        sym[sym_idx].GetAddressRef().SetSection (symbol_section);
-                        sym[sym_idx].GetAddressRef().SetOffset (symbol_value);
-                    }
-                    sym[sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-
-                    if (symbol_byte_size > 0)
-                        sym[sym_idx].SetByteSize(symbol_byte_size);
-
-                    if (demangled_is_synthesized)
-                        sym[sym_idx].SetDemangledNameIsSynthesized(true);
-
-                    ++sym_idx;
-                }
-                else
-                {
-                    sym[sym_idx].Clear();
-                }
-            }
-
-            for (const auto &pos :reexport_shlib_needs_fixup)
-            {
-                const auto undef_pos = undefined_name_to_desc.find(pos.second);
-                if (undef_pos != undefined_name_to_desc.end())
-                {
-                    const uint8_t dylib_ordinal = llvm::MachO::GET_LIBRARY_ORDINAL(undef_pos->second);
-                    if (dylib_ordinal > 0 && dylib_ordinal < dylib_files.GetSize())
-                        sym[pos.first].SetReExportedSymbolSharedLibrary(dylib_files.GetFileSpecAtIndex(dylib_ordinal-1));
-                }
-            }
-        }
-
-        uint32_t synthetic_sym_id = symtab_load_command.nsyms;
-
-        if (function_starts_count > 0)
-        {
-            uint32_t num_synthetic_function_symbols = 0;
-            for (i=0; i<function_starts_count; ++i)
-            {
-                if (function_starts.GetEntryRef (i).data == false)
-                    ++num_synthetic_function_symbols;
-            }
-
-            if (num_synthetic_function_symbols > 0)
-            {
-                if (num_syms < sym_idx + num_synthetic_function_symbols)
-                {
-                    num_syms = sym_idx + num_synthetic_function_symbols;
-                    sym = symtab->Resize (num_syms);
-                }
-                for (i=0; i<function_starts_count; ++i)
-                {
-                    const FunctionStarts::Entry *func_start_entry = function_starts.GetEntryAtIndex (i);
-                    if (func_start_entry->data == false)
-                    {
-                        addr_t symbol_file_addr = func_start_entry->addr;
-                        uint32_t symbol_flags = 0;
-                        if (is_arm)
-                        {
-                            if (symbol_file_addr & 1)
-                                symbol_flags = MACHO_NLIST_ARM_SYMBOL_IS_THUMB;
-                            symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-                        }
-                        Address symbol_addr;
-                        if (module_sp->ResolveFileAddress (symbol_file_addr, symbol_addr))
-                        {
-                            SectionSP symbol_section (symbol_addr.GetSection());
-                            uint32_t symbol_byte_size = 0;
-                            if (symbol_section)
-                            {
-                                const addr_t section_file_addr = symbol_section->GetFileAddress();
-                                const FunctionStarts::Entry *next_func_start_entry = function_starts.FindNextEntry (func_start_entry);
-                                const addr_t section_end_file_addr = section_file_addr + symbol_section->GetByteSize();
-                                if (next_func_start_entry)
-                                {
-                                    addr_t next_symbol_file_addr = next_func_start_entry->addr;
-                                    if (is_arm)
-                                        next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-                                    symbol_byte_size = std::min<lldb::addr_t>(next_symbol_file_addr - symbol_file_addr, section_end_file_addr - symbol_file_addr);
-                                }
-                                else
-                                {
-                                    symbol_byte_size = section_end_file_addr - symbol_file_addr;
-                                }
-                                sym[sym_idx].SetID (synthetic_sym_id++);
-                                sym[sym_idx].GetMangled().SetDemangledName(GetNextSyntheticSymbolName());
-                                sym[sym_idx].SetType (eSymbolTypeCode);
-                                sym[sym_idx].SetIsSynthetic (true);
-                                sym[sym_idx].GetAddressRef() = symbol_addr;
-                                if (symbol_flags)
-                                    sym[sym_idx].SetFlags (symbol_flags);
-                                if (symbol_byte_size)
-                                    sym[sym_idx].SetByteSize (symbol_byte_size);
-                                ++sym_idx;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        // Trim our symbols down to just what we ended up with after
-        // removing any symbols.
-        if (sym_idx < num_syms)
-        {
-            num_syms = sym_idx;
-            sym = symtab->Resize (num_syms);
-        }
-
-        // Now synthesize indirect symbols
-        if (m_dysymtab.nindirectsyms != 0)
-        {
-            if (indirect_symbol_index_data.GetByteSize())
-            {
-                NListIndexToSymbolIndexMap::const_iterator end_index_pos = m_nlist_idx_to_sym_idx.end();
-
-                for (uint32_t sect_idx = 1; sect_idx < m_mach_sections.size(); ++sect_idx)
-                {
-                    if ((m_mach_sections[sect_idx].flags & SECTION_TYPE) == S_SYMBOL_STUBS)
-                    {
-                        uint32_t symbol_stub_byte_size = m_mach_sections[sect_idx].reserved2;
-                        if (symbol_stub_byte_size == 0)
-                            continue;
-
-                        const uint32_t num_symbol_stubs = m_mach_sections[sect_idx].size / symbol_stub_byte_size;
-
-                        if (num_symbol_stubs == 0)
-                            continue;
-
-                        const uint32_t symbol_stub_index_offset = m_mach_sections[sect_idx].reserved1;
-                        for (uint32_t stub_idx = 0; stub_idx < num_symbol_stubs; ++stub_idx)
-                        {
-                            const uint32_t symbol_stub_index = symbol_stub_index_offset + stub_idx;
-                            const lldb::addr_t symbol_stub_addr = m_mach_sections[sect_idx].addr + (stub_idx * symbol_stub_byte_size);
-                            lldb::offset_t symbol_stub_offset = symbol_stub_index * 4;
-                            if (indirect_symbol_index_data.ValidOffsetForDataOfSize(symbol_stub_offset, 4))
-                            {
-                                const uint32_t stub_sym_id = indirect_symbol_index_data.GetU32 (&symbol_stub_offset);
-                                if (stub_sym_id & (INDIRECT_SYMBOL_ABS | INDIRECT_SYMBOL_LOCAL))
-                                    continue;
-
-                                NListIndexToSymbolIndexMap::const_iterator index_pos = m_nlist_idx_to_sym_idx.find (stub_sym_id);
-                                Symbol *stub_symbol = NULL;
-                                if (index_pos != end_index_pos)
-                                {
-                                    // We have a remapping from the original nlist index to
-                                    // a current symbol index, so just look this up by index
-                                    stub_symbol = symtab->SymbolAtIndex (index_pos->second);
-                                }
-                                else
-                                {
-                                    // We need to lookup a symbol using the original nlist
-                                    // symbol index since this index is coming from the
-                                    // S_SYMBOL_STUBS
-                                    stub_symbol = symtab->FindSymbolByID (stub_sym_id);
-                                }
-
-                                if (stub_symbol)
-                                {
-                                    Address so_addr(symbol_stub_addr, section_list);
-
-                                    if (stub_symbol->GetType() == eSymbolTypeUndefined)
-                                    {
-                                        // Change the external symbol into a trampoline that makes sense
-                                        // These symbols were N_UNDF N_EXT, and are useless to us, so we
-                                        // can re-use them so we don't have to make up a synthetic symbol
-                                        // for no good reason.
-                                        if (resolver_addresses.find(symbol_stub_addr) == resolver_addresses.end())
-                                            stub_symbol->SetType (eSymbolTypeTrampoline);
-                                        else
-                                            stub_symbol->SetType (eSymbolTypeResolver);
-                                        stub_symbol->SetExternal (false);
-                                        stub_symbol->GetAddressRef() = so_addr;
-                                        stub_symbol->SetByteSize (symbol_stub_byte_size);
-                                    }
-                                    else
-                                    {
-                                        // Make a synthetic symbol to describe the trampoline stub
-                                        Mangled stub_symbol_mangled_name(stub_symbol->GetMangled());
-                                        if (sym_idx >= num_syms)
-                                        {
-                                            sym = symtab->Resize (++num_syms);
-                                            stub_symbol = NULL;  // this pointer no longer valid
-                                        }
-                                        sym[sym_idx].SetID (synthetic_sym_id++);
-                                        sym[sym_idx].GetMangled() = stub_symbol_mangled_name;
-                                        if (resolver_addresses.find(symbol_stub_addr) == resolver_addresses.end())
-                                            sym[sym_idx].SetType (eSymbolTypeTrampoline);
-                                        else
-                                            sym[sym_idx].SetType (eSymbolTypeResolver);
-                                        sym[sym_idx].SetIsSynthetic (true);
-                                        sym[sym_idx].GetAddressRef() = so_addr;
-                                        sym[sym_idx].SetByteSize (symbol_stub_byte_size);
-                                        ++sym_idx;
-                                    }
-                                }
-                                else
-                                {
-                                    if (log)
-                                        log->Warning ("symbol stub referencing symbol table symbol %u that isn't in our minimal symbol table, fix this!!!", stub_sym_id);
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        if (!trie_entries.empty())
-        {
-            for (const auto &e : trie_entries)
-            {
-                if (e.entry.import_name)
-                {
-                    // Only add indirect symbols from the Trie entries if we
-                    // didn't have a N_INDR nlist entry for this already
-                    if (indirect_symbol_names.find(e.entry.name) == indirect_symbol_names.end())
-                    {
-                        // Make a synthetic symbol to describe re-exported symbol.
-                        if (sym_idx >= num_syms)
-                            sym = symtab->Resize (++num_syms);
-                        sym[sym_idx].SetID (synthetic_sym_id++);
-                        sym[sym_idx].GetMangled() = Mangled(e.entry.name);
-                        sym[sym_idx].SetType (eSymbolTypeReExported);
-                        sym[sym_idx].SetIsSynthetic (true);
-                        sym[sym_idx].SetReExportedSymbolName(e.entry.import_name);
-                        if (e.entry.other > 0 && e.entry.other <= dylib_files.GetSize())
-                        {
-                            sym[sym_idx].SetReExportedSymbolSharedLibrary(dylib_files.GetFileSpecAtIndex(e.entry.other-1));
-                        }
-                        ++sym_idx;
-                    }
-                }
-            }
-        }
-       
-//        StreamFile s(stdout, false);
-//        s.Printf ("Symbol table before CalculateSymbolSizes():\n");
-//        symtab->Dump(&s, NULL, eSortOrderNone);
-        // Set symbol byte sizes correctly since mach-o nlist entries don't have sizes
-        symtab->CalculateSymbolSizes();
-
-//        s.Printf ("Symbol table after CalculateSymbolSizes():\n");
-//        symtab->Dump(&s, NULL, eSortOrderNone);
-
-        return symtab->GetNumSymbols();
-    }
-    return 0;
-}
-
-void
-ObjectFileMachO::Dump (Stream *s)
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        s->Printf("%p: ", static_cast<void*>(this));
-        s->Indent();
-        if (m_header.magic == MH_MAGIC_64 || m_header.magic == MH_CIGAM_64)
-            s->PutCString("ObjectFileMachO64");
-        else
-            s->PutCString("ObjectFileMachO32");
-
-        ArchSpec header_arch;
-        GetArchitecture(header_arch);
-
-        *s << ", file = '" << m_file << "', arch = " << header_arch.GetArchitectureName() << "\n";
-
-        SectionList *sections = GetSectionList();
-        if (sections)
-            sections->Dump(s, NULL, true, UINT32_MAX);
-
-        if (m_symtab_ap.get())
-            m_symtab_ap->Dump(s, NULL, eSortOrderNone);
-    }
-}
-
-bool
-ObjectFileMachO::GetUUID (const llvm::MachO::mach_header &header,
-                          const lldb_private::DataExtractor &data,
-                          lldb::offset_t lc_offset,
-                          lldb_private::UUID& uuid)
-{
-    uint32_t i;
-    struct uuid_command load_cmd;
-
-    lldb::offset_t offset = lc_offset;
-    for (i=0; i<header.ncmds; ++i)
-    {
-        const lldb::offset_t cmd_offset = offset;
-        if (data.GetU32(&offset, &load_cmd, 2) == NULL)
-            break;
-        
-        if (load_cmd.cmd == LC_UUID)
-        {
-            const uint8_t *uuid_bytes = data.PeekData(offset, 16);
-            
-            if (uuid_bytes)
-            {
-                // OpenCL on Mac OS X uses the same UUID for each of its object files.
-                // We pretend these object files have no UUID to prevent crashing.
-                
-                const uint8_t opencl_uuid[] = { 0x8c, 0x8e, 0xb3, 0x9b,
-                    0x3b, 0xa8,
-                    0x4b, 0x16,
-                    0xb6, 0xa4,
-                    0x27, 0x63, 0xbb, 0x14, 0xf0, 0x0d };
-                
-                if (!memcmp(uuid_bytes, opencl_uuid, 16))
-                    return false;
-                
-                uuid.SetBytes (uuid_bytes);
-                return true;
-            }
-            return false;
-        }
-        offset = cmd_offset + load_cmd.cmdsize;
-    }
-    return false;
-}
-
-bool
-ObjectFileMachO::GetArchitecture (const llvm::MachO::mach_header &header,
-                                  const lldb_private::DataExtractor &data,
-                                  lldb::offset_t lc_offset,
-                                  ArchSpec &arch)
-{
-    arch.SetArchitecture (eArchTypeMachO, header.cputype, header.cpusubtype);
-
-    if (arch.IsValid())
-    {
-        llvm::Triple &triple = arch.GetTriple();
-
-        // Set OS to an unspecified unknown or a "*" so it can match any OS
-        triple.setOS(llvm::Triple::UnknownOS);
-        triple.setOSName(llvm::StringRef());
-
-        if (header.filetype == MH_PRELOAD)
-        {
-            if (header.cputype == CPU_TYPE_ARM)
-            {
-                // If this is a 32-bit arm binary, and it's a standalone binary,
-                // force the Vendor to Apple so we don't accidentally pick up 
-                // the generic armv7 ABI at runtime.  Apple's armv7 ABI always uses
-                // r7 for the frame pointer register; most other armv7 ABIs use a
-                // combination of r7 and r11.
-                triple.setVendor(llvm::Triple::Apple);
-            }
-            else
-            {
-                // Set vendor to an unspecified unknown or a "*" so it can match any vendor
-                // This is required for correct behavior of EFI debugging on x86_64
-                triple.setVendor(llvm::Triple::UnknownVendor);
-                triple.setVendorName(llvm::StringRef());
-            }
-            return true;
-        }
-        else
-        {
-            struct load_command load_cmd;
-
-            lldb::offset_t offset = lc_offset;
-            for (uint32_t i=0; i<header.ncmds; ++i)
-            {
-                const lldb::offset_t cmd_offset = offset;
-                if (data.GetU32(&offset, &load_cmd, 2) == NULL)
-                    break;
-                
-                switch (load_cmd.cmd)
-                {
-                    case llvm::MachO::LC_VERSION_MIN_IPHONEOS:
-                        triple.setOS (llvm::Triple::IOS);
-                        return true;
-                        
-                    case llvm::MachO::LC_VERSION_MIN_MACOSX:
-                        triple.setOS (llvm::Triple::MacOSX);
-                        return true;
-
-                    case llvm::MachO::LC_VERSION_MIN_TVOS:
-                        triple.setOS (llvm::Triple::TvOS);
-                        return true;
-                        
-                    case llvm::MachO::LC_VERSION_MIN_WATCHOS:
-                        triple.setOS (llvm::Triple::WatchOS);
-                        return true;
-
-                    default:
-                        break;
-                }
-
-                offset = cmd_offset + load_cmd.cmdsize;
-            }
-            
-            if (header.filetype != MH_KEXT_BUNDLE)
-            {
-                // We didn't find a LC_VERSION_MIN load command and this isn't a KEXT
-                // so lets not say our Vendor is Apple, leave it as an unspecified unknown
-                triple.setVendor(llvm::Triple::UnknownVendor);
-                triple.setVendorName(llvm::StringRef());
-            }
-        }
-    }
-    return arch.IsValid();
-}
-
-bool
-ObjectFileMachO::GetUUID (lldb_private::UUID* uuid)
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        return GetUUID (m_header, m_data, offset, *uuid);
-    }
-    return false;
-}
-
-uint32_t
-ObjectFileMachO::GetDependentModules (FileSpecList& files)
-{
-    uint32_t count = 0;
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        struct load_command load_cmd;
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        std::vector<std::string> rpath_paths;
-        std::vector<std::string> rpath_relative_paths;
-        const bool resolve_path = false; // Don't resolve the dependent file paths since they may not reside on this system
-        uint32_t i;
-        for (i=0; i<m_header.ncmds; ++i)
-        {
-            const uint32_t cmd_offset = offset;
-            if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
-                break;
-
-            switch (load_cmd.cmd)
-            {
-            case LC_RPATH:
-            case LC_LOAD_DYLIB:
-            case LC_LOAD_WEAK_DYLIB:
-            case LC_REEXPORT_DYLIB:
-            case LC_LOAD_DYLINKER:
-            case LC_LOADFVMLIB:
-            case LC_LOAD_UPWARD_DYLIB:
-                {
-                    uint32_t name_offset = cmd_offset + m_data.GetU32(&offset);
-                    const char *path = m_data.PeekCStr(name_offset);
-                    if (path)
-                    {
-                        if (load_cmd.cmd == LC_RPATH)
-                            rpath_paths.push_back(path);
-                        else
-                        {
-                            if (path[0] == '@')
-                            {
-                                if (strncmp(path, "@rpath", strlen("@rpath")) == 0)
-                                    rpath_relative_paths.push_back(path + strlen("@rpath"));
-                            }
-                            else
-                            {
-                                FileSpec file_spec(path, resolve_path);
-                                if (files.AppendIfUnique(file_spec))
-                                    count++;
-                            }
-                        }
-                    }
-                }
-                break;
-
-            default:
-                break;
-            }
-            offset = cmd_offset + load_cmd.cmdsize;
-        }
-
-        if (!rpath_paths.empty())
-        {
-            // Fixup all LC_RPATH values to be absolute paths
-            FileSpec this_file_spec(m_file);
-            this_file_spec.ResolvePath();
-            std::string loader_path("@loader_path");
-            std::string executable_path("@executable_path");
-            for (auto &rpath : rpath_paths)
-            {
-                if (rpath.find(loader_path) == 0)
-                {
-                    rpath.erase(0, loader_path.size());
-                    rpath.insert(0, this_file_spec.GetDirectory().GetCString());
-                }
-                else if (rpath.find(executable_path) == 0)
-                {
-                    rpath.erase(0, executable_path.size());
-                    rpath.insert(0, this_file_spec.GetDirectory().GetCString());
-                }
-            }
-
-            for (const auto &rpath_relative_path : rpath_relative_paths)
-            {
-                for (const auto &rpath : rpath_paths)
-                {
-                    std::string path = rpath;
-                    path += rpath_relative_path;
-                    // It is OK to resolve this path because we must find a file on
-                    // disk for us to accept it anyway if it is rpath relative.
-                    FileSpec file_spec(path, true);
-                    // Remove any redundant parts of the path (like "../foo") since
-                    // LC_RPATH values often contain "..".
-                    file_spec.NormalizePath ();
-                    if (file_spec.Exists() && files.AppendIfUnique(file_spec))
-                    {
-                        count++;
-                        break;
-                    }
-                }
-            }
-        }
-    }
-    return count;
-}
-
-lldb_private::Address
-ObjectFileMachO::GetEntryPointAddress ()
-{
-    // If the object file is not an executable it can't hold the entry point.  m_entry_point_address
-    // is initialized to an invalid address, so we can just return that.
-    // If m_entry_point_address is valid it means we've found it already, so return the cached value.
-
-    if (!IsExecutable() || m_entry_point_address.IsValid())
-        return m_entry_point_address;
-
-    // Otherwise, look for the UnixThread or Thread command.  The data for the Thread command is given in
-    // /usr/include/mach-o.h, but it is basically:
-    //
-    //  uint32_t flavor  - this is the flavor argument you would pass to thread_get_state
-    //  uint32_t count   - this is the count of longs in the thread state data
-    //  struct XXX_thread_state state - this is the structure from <machine/thread_status.h> corresponding to the flavor.
-    //  <repeat this trio>
-    //
-    // So we just keep reading the various register flavors till we find the GPR one, then read the PC out of there.
-    // FIXME: We will need to have a "RegisterContext data provider" class at some point that can get all the registers
-    // out of data in this form & attach them to a given thread.  That should underlie the MacOS X User process plugin,
-    // and we'll also need it for the MacOS X Core File process plugin.  When we have that we can also use it here.
-    //
-    // For now we hard-code the offsets and flavors we need:
-    //
-    //
-
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        struct load_command load_cmd;
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        uint32_t i;
-        lldb::addr_t start_address = LLDB_INVALID_ADDRESS;
-        bool done = false;
-
-        for (i=0; i<m_header.ncmds; ++i)
-        {
-            const lldb::offset_t cmd_offset = offset;
-            if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
-                break;
-
-            switch (load_cmd.cmd)
-            {
-            case LC_UNIXTHREAD:
-            case LC_THREAD:
-                {
-                    while (offset < cmd_offset + load_cmd.cmdsize)
-                    {
-                        uint32_t flavor = m_data.GetU32(&offset);
-                        uint32_t count = m_data.GetU32(&offset);
-                        if (count == 0)
-                        {
-                            // We've gotten off somehow, log and exit;
-                            return m_entry_point_address;
-                        }
-
-                        switch (m_header.cputype)
-                        {
-                        case llvm::MachO::CPU_TYPE_ARM:
-                           if (flavor == 1 || flavor == 9) // ARM_THREAD_STATE/ARM_THREAD_STATE32 from mach/arm/thread_status.h
-                           {
-                               offset += 60;  // This is the offset of pc in the GPR thread state data structure.
-                               start_address = m_data.GetU32(&offset);
-                               done = true;
-                            }
-                        break;
-                        case llvm::MachO::CPU_TYPE_ARM64:
-                           if (flavor == 6) // ARM_THREAD_STATE64 from mach/arm/thread_status.h
-                           {
-                               offset += 256;  // This is the offset of pc in the GPR thread state data structure.
-                               start_address = m_data.GetU64(&offset);
-                               done = true;
-                            }
-                        break;
-                        case llvm::MachO::CPU_TYPE_I386:
-                           if (flavor == 1) // x86_THREAD_STATE32 from mach/i386/thread_status.h
-                           {
-                               offset += 40;  // This is the offset of eip in the GPR thread state data structure.
-                               start_address = m_data.GetU32(&offset);
-                               done = true;
-                            }
-                        break;
-                        case llvm::MachO::CPU_TYPE_X86_64:
-                           if (flavor == 4) // x86_THREAD_STATE64 from mach/i386/thread_status.h
-                           {
-                               offset += 16 * 8;  // This is the offset of rip in the GPR thread state data structure.
-                               start_address = m_data.GetU64(&offset);
-                               done = true;
-                            }
-                        break;
-                        default:
-                            return m_entry_point_address;
-                        }
-                        // Haven't found the GPR flavor yet, skip over the data for this flavor:
-                        if (done)
-                            break;
-                        offset += count * 4;
-                    }
-                }
-                break;
-            case LC_MAIN:
-                {
-                    ConstString text_segment_name ("__TEXT");
-                    uint64_t entryoffset = m_data.GetU64(&offset);
-                    SectionSP text_segment_sp = GetSectionList()->FindSectionByName(text_segment_name);
-                    if (text_segment_sp)
-                    {
-                        done = true;
-                        start_address = text_segment_sp->GetFileAddress() + entryoffset;
-                    }
-                }
-                break;
+          case N_EXCL:
+            // deleted include file: name,,NO_SECT,0,sum
+            type = eSymbolTypeHeaderFile;
+            break;
 
-            default:
-                break;
+          //----------------------------------------------------------------------
+          // COMM scopes
+          //----------------------------------------------------------------------
+          case N_BCOMM:
+            // begin common: name,,NO_SECT,0,0
+            // We use the current number of symbols in the symbol table in lieu
+            // of
+            // using nlist_idx in case we ever start trimming entries out
+            type = eSymbolTypeScopeBegin;
+            N_COMM_indexes.push_back(sym_idx);
+            break;
+
+          case N_ECOML:
+            // end common (local name): 0,,n_sect,0,address
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+            LLVM_FALLTHROUGH;
+
+          case N_ECOMM:
+            // end common: name,,n_sect,0,0
+            // Set the size of the N_BCOMM to the terminating index of this
+            // N_ECOMM/N_ECOML
+            // so that we can always skip the entire symbol if we need to
+            // navigate
+            // more quickly at the source level when parsing STABS
+            if (!N_COMM_indexes.empty()) {
+              symbol_ptr = symtab->SymbolAtIndex(N_COMM_indexes.back());
+              symbol_ptr->SetByteSize(sym_idx + 1);
+              symbol_ptr->SetSizeIsSibling(true);
+              N_COMM_indexes.pop_back();
             }
-            if (done)
-                break;
+            type = eSymbolTypeScopeEnd;
+            break;
 
-            // Go to the next load command:
-            offset = cmd_offset + load_cmd.cmdsize;
-        }
+          case N_LENG:
+            // second stab entry with length information
+            type = eSymbolTypeAdditional;
+            break;
 
-        if (start_address != LLDB_INVALID_ADDRESS)
-        {
-            // We got the start address from the load commands, so now resolve that address in the sections
-            // of this ObjectFile:
-            if (!m_entry_point_address.ResolveAddressUsingFileSections (start_address, GetSectionList()))
-            {
-                m_entry_point_address.Clear();
+          default:
+            break;
+          }
+        } else {
+          // uint8_t n_pext    = N_PEXT & nlist.n_type;
+          uint8_t n_type = N_TYPE & nlist.n_type;
+          sym[sym_idx].SetExternal((N_EXT & nlist.n_type) != 0);
+
+          switch (n_type) {
+          case N_INDR: {
+            const char *reexport_name_cstr =
+                strtab_data.PeekCStr(nlist.n_value);
+            if (reexport_name_cstr && reexport_name_cstr[0]) {
+              type = eSymbolTypeReExported;
+              ConstString reexport_name(
+                  reexport_name_cstr +
+                  ((reexport_name_cstr[0] == '_') ? 1 : 0));
+              sym[sym_idx].SetReExportedSymbolName(reexport_name);
+              set_value = false;
+              reexport_shlib_needs_fixup[sym_idx] = reexport_name;
+              indirect_symbol_names.insert(
+                  ConstString(symbol_name + ((symbol_name[0] == '_') ? 1 : 0)));
+            } else
+              type = eSymbolTypeUndefined;
+          } break;
+
+          case N_UNDF:
+            if (symbol_name && symbol_name[0]) {
+              ConstString undefined_name(symbol_name +
+                                         ((symbol_name[0] == '_') ? 1 : 0));
+              undefined_name_to_desc[undefined_name] = nlist.n_desc;
             }
-        }
-        else
-        {
-            // We couldn't read the UnixThread load command - maybe it wasn't there.  As a fallback look for the
-            // "start" symbol in the main executable.
+            LLVM_FALLTHROUGH;
 
-            ModuleSP module_sp (GetModule());
+          case N_PBUD:
+            type = eSymbolTypeUndefined;
+            break;
 
-            if (module_sp)
-            {
-                SymbolContextList contexts;
-                SymbolContext context;
-                if (module_sp->FindSymbolsWithNameAndType(ConstString ("start"), eSymbolTypeCode, contexts))
-                {
-                    if (contexts.GetContextAtIndex(0, context))
-                        m_entry_point_address = context.symbol->GetAddress();
+          case N_ABS:
+            type = eSymbolTypeAbsolute;
+            break;
+
+          case N_SECT: {
+            symbol_section =
+                section_info.GetSection(nlist.n_sect, nlist.n_value);
+
+            if (!symbol_section) {
+              // TODO: warn about this?
+              add_nlist = false;
+              break;
+            }
+
+            if (TEXT_eh_frame_sectID == nlist.n_sect) {
+              type = eSymbolTypeException;
+            } else {
+              uint32_t section_type = symbol_section->Get() & SECTION_TYPE;
+
+              switch (section_type) {
+              case S_CSTRING_LITERALS:
+                type = eSymbolTypeData;
+                break; // section with only literal C strings
+              case S_4BYTE_LITERALS:
+                type = eSymbolTypeData;
+                break; // section with only 4 byte literals
+              case S_8BYTE_LITERALS:
+                type = eSymbolTypeData;
+                break; // section with only 8 byte literals
+              case S_LITERAL_POINTERS:
+                type = eSymbolTypeTrampoline;
+                break; // section with only pointers to literals
+              case S_NON_LAZY_SYMBOL_POINTERS:
+                type = eSymbolTypeTrampoline;
+                break; // section with only non-lazy symbol pointers
+              case S_LAZY_SYMBOL_POINTERS:
+                type = eSymbolTypeTrampoline;
+                break; // section with only lazy symbol pointers
+              case S_SYMBOL_STUBS:
+                type = eSymbolTypeTrampoline;
+                break; // section with only symbol stubs, byte size of stub in
+                       // the reserved2 field
+              case S_MOD_INIT_FUNC_POINTERS:
+                type = eSymbolTypeCode;
+                break; // section with only function pointers for initialization
+              case S_MOD_TERM_FUNC_POINTERS:
+                type = eSymbolTypeCode;
+                break; // section with only function pointers for termination
+              case S_INTERPOSING:
+                type = eSymbolTypeTrampoline;
+                break; // section with only pairs of function pointers for
+                       // interposing
+              case S_16BYTE_LITERALS:
+                type = eSymbolTypeData;
+                break; // section with only 16 byte literals
+              case S_DTRACE_DOF:
+                type = eSymbolTypeInstrumentation;
+                break;
+              case S_LAZY_DYLIB_SYMBOL_POINTERS:
+                type = eSymbolTypeTrampoline;
+                break;
+              default:
+                switch (symbol_section->GetType()) {
+                case lldb::eSectionTypeCode:
+                  type = eSymbolTypeCode;
+                  break;
+                case eSectionTypeData:
+                case eSectionTypeDataCString:         // Inlined C string data
+                case eSectionTypeDataCStringPointers: // Pointers to C string
+                                                      // data
+                case eSectionTypeDataSymbolAddress:   // Address of a symbol in
+                                                      // the symbol table
+                case eSectionTypeData4:
+                case eSectionTypeData8:
+                case eSectionTypeData16:
+                  type = eSymbolTypeData;
+                  break;
+                default:
+                  break;
                 }
-            }
-        }
-    }
+                break;
+              }
 
-    return m_entry_point_address;
-}
+              if (type == eSymbolTypeInvalid) {
+                const char *symbol_sect_name =
+                    symbol_section->GetName().AsCString();
+                if (symbol_section->IsDescendant(text_section_sp.get())) {
+                  if (symbol_section->IsClear(S_ATTR_PURE_INSTRUCTIONS |
+                                              S_ATTR_SELF_MODIFYING_CODE |
+                                              S_ATTR_SOME_INSTRUCTIONS))
+                    type = eSymbolTypeData;
+                  else
+                    type = eSymbolTypeCode;
+                } else if (symbol_section->IsDescendant(
+                               data_section_sp.get()) ||
+                           symbol_section->IsDescendant(
+                               data_dirty_section_sp.get()) ||
+                           symbol_section->IsDescendant(
+                               data_const_section_sp.get())) {
+                  if (symbol_sect_name &&
+                      ::strstr(symbol_sect_name, "__objc") ==
+                          symbol_sect_name) {
+                    type = eSymbolTypeRuntime;
+
+                    if (symbol_name) {
+                      llvm::StringRef symbol_name_ref(symbol_name);
+                      if (symbol_name_ref.startswith("_OBJC_")) {
+                        static const llvm::StringRef g_objc_v2_prefix_class(
+                            "_OBJC_CLASS_$_");
+                        static const llvm::StringRef g_objc_v2_prefix_metaclass(
+                            "_OBJC_METACLASS_$_");
+                        static const llvm::StringRef g_objc_v2_prefix_ivar(
+                            "_OBJC_IVAR_$_");
+                        if (symbol_name_ref.startswith(
+                                g_objc_v2_prefix_class)) {
+                          symbol_name_non_abi_mangled = symbol_name + 1;
+                          symbol_name =
+                              symbol_name + g_objc_v2_prefix_class.size();
+                          type = eSymbolTypeObjCClass;
+                          demangled_is_synthesized = true;
+                        } else if (symbol_name_ref.startswith(
+                                       g_objc_v2_prefix_metaclass)) {
+                          symbol_name_non_abi_mangled = symbol_name + 1;
+                          symbol_name =
+                              symbol_name + g_objc_v2_prefix_metaclass.size();
+                          type = eSymbolTypeObjCMetaClass;
+                          demangled_is_synthesized = true;
+                        } else if (symbol_name_ref.startswith(
+                                       g_objc_v2_prefix_ivar)) {
+                          symbol_name_non_abi_mangled = symbol_name + 1;
+                          symbol_name =
+                              symbol_name + g_objc_v2_prefix_ivar.size();
+                          type = eSymbolTypeObjCIVar;
+                          demangled_is_synthesized = true;
+                        }
+                      }
+                    }
+                  } else if (symbol_sect_name &&
+                             ::strstr(symbol_sect_name, "__gcc_except_tab") ==
+                                 symbol_sect_name) {
+                    type = eSymbolTypeException;
+                  } else {
+                    type = eSymbolTypeData;
+                  }
+                } else if (symbol_sect_name &&
+                           ::strstr(symbol_sect_name, "__IMPORT") ==
+                               symbol_sect_name) {
+                  type = eSymbolTypeTrampoline;
+                } else if (symbol_section->IsDescendant(
+                               objc_section_sp.get())) {
+                  type = eSymbolTypeRuntime;
+                  if (symbol_name && symbol_name[0] == '.') {
+                    llvm::StringRef symbol_name_ref(symbol_name);
+                    static const llvm::StringRef g_objc_v1_prefix_class(
+                        ".objc_class_name_");
+                    if (symbol_name_ref.startswith(g_objc_v1_prefix_class)) {
+                      symbol_name_non_abi_mangled = symbol_name;
+                      symbol_name = symbol_name + g_objc_v1_prefix_class.size();
+                      type = eSymbolTypeObjCClass;
+                      demangled_is_synthesized = true;
+                    }
+                  }
+                }
+              }
+            }
+          } break;
+          }
+        }
+
+        if (add_nlist) {
+          uint64_t symbol_value = nlist.n_value;
+
+          if (symbol_name_non_abi_mangled) {
+            sym[sym_idx].GetMangled().SetMangledName(
+                ConstString(symbol_name_non_abi_mangled));
+            sym[sym_idx].GetMangled().SetDemangledName(
+                ConstString(symbol_name));
+          } else {
+            bool symbol_name_is_mangled = false;
+
+            if (symbol_name && symbol_name[0] == '_') {
+              symbol_name_is_mangled = symbol_name[1] == '_';
+              symbol_name++; // Skip the leading underscore
+            }
+
+            if (symbol_name) {
+              ConstString const_symbol_name(symbol_name);
+              sym[sym_idx].GetMangled().SetValue(const_symbol_name,
+                                                 symbol_name_is_mangled);
+            }
+          }
+
+          if (is_gsym) {
+            const char *gsym_name = sym[sym_idx]
+                                        .GetMangled()
+                                        .GetName(lldb::eLanguageTypeUnknown,
+                                                 Mangled::ePreferMangled)
+                                        .GetCString();
+            if (gsym_name)
+              N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
+          }
+
+          if (symbol_section) {
+            const addr_t section_file_addr = symbol_section->GetFileAddress();
+            if (symbol_byte_size == 0 && function_starts_count > 0) {
+              addr_t symbol_lookup_file_addr = nlist.n_value;
+              // Do an exact address match for non-ARM addresses, else get the
+              // closest since
+              // the symbol might be a thumb symbol which has an address with
+              // bit zero set
+              FunctionStarts::Entry *func_start_entry =
+                  function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
+              if (is_arm && func_start_entry) {
+                // Verify that the function start address is the symbol address
+                // (ARM)
+                // or the symbol address + 1 (thumb)
+                if (func_start_entry->addr != symbol_lookup_file_addr &&
+                    func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
+                  // Not the right entry, NULL it out...
+                  func_start_entry = NULL;
+                }
+              }
+              if (func_start_entry) {
+                func_start_entry->data = true;
 
-lldb_private::Address
-ObjectFileMachO::GetHeaderAddress ()
-{
-    lldb_private::Address header_addr;
-    SectionList *section_list = GetSectionList();
-    if (section_list)
-    {
-        SectionSP text_segment_sp (section_list->FindSectionByName (GetSegmentNameTEXT()));
-        if (text_segment_sp)
-        {
-            header_addr.SetSection (text_segment_sp);
-            header_addr.SetOffset (0);
-        }
-    }
-    return header_addr;
-}
+                addr_t symbol_file_addr = func_start_entry->addr;
+                if (is_arm)
+                  symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
 
-uint32_t
-ObjectFileMachO::GetNumThreadContexts ()
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        if (!m_thread_context_offsets_valid)
-        {
-            m_thread_context_offsets_valid = true;
-            lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-            FileRangeArray::Entry file_range;
-            thread_command thread_cmd;
-            for (uint32_t i=0; i<m_header.ncmds; ++i)
-            {
-                const uint32_t cmd_offset = offset;
-                if (m_data.GetU32(&offset, &thread_cmd, 2) == NULL)
+                const FunctionStarts::Entry *next_func_start_entry =
+                    function_starts.FindNextEntry(func_start_entry);
+                const addr_t section_end_file_addr =
+                    section_file_addr + symbol_section->GetByteSize();
+                if (next_func_start_entry) {
+                  addr_t next_symbol_file_addr = next_func_start_entry->addr;
+                  // Be sure the clear the Thumb address bit when we calculate
+                  // the size
+                  // from the current and next address
+                  if (is_arm)
+                    next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+                  symbol_byte_size = std::min<lldb::addr_t>(
+                      next_symbol_file_addr - symbol_file_addr,
+                      section_end_file_addr - symbol_file_addr);
+                } else {
+                  symbol_byte_size = section_end_file_addr - symbol_file_addr;
+                }
+              }
+            }
+            symbol_value -= section_file_addr;
+          }
+
+          if (is_debug == false) {
+            if (type == eSymbolTypeCode) {
+              // See if we can find a N_FUN entry for any code symbols.
+              // If we do find a match, and the name matches, then we
+              // can merge the two into just the function symbol to avoid
+              // duplicate entries in the symbol table
+              std::pair<ValueToSymbolIndexMap::const_iterator,
+                        ValueToSymbolIndexMap::const_iterator>
+                  range;
+              range = N_FUN_addr_to_sym_idx.equal_range(nlist.n_value);
+              if (range.first != range.second) {
+                bool found_it = false;
+                for (ValueToSymbolIndexMap::const_iterator pos = range.first;
+                     pos != range.second; ++pos) {
+                  if (sym[sym_idx].GetMangled().GetName(
+                          lldb::eLanguageTypeUnknown,
+                          Mangled::ePreferMangled) ==
+                      sym[pos->second].GetMangled().GetName(
+                          lldb::eLanguageTypeUnknown,
+                          Mangled::ePreferMangled)) {
+                    m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
+                    // We just need the flags from the linker symbol, so put
+                    // these flags
+                    // into the N_FUN flags to avoid duplicate symbols in the
+                    // symbol table
+                    sym[pos->second].SetExternal(sym[sym_idx].IsExternal());
+                    sym[pos->second].SetFlags(nlist.n_type << 16 |
+                                              nlist.n_desc);
+                    if (resolver_addresses.find(nlist.n_value) !=
+                        resolver_addresses.end())
+                      sym[pos->second].SetType(eSymbolTypeResolver);
+                    sym[sym_idx].Clear();
+                    found_it = true;
                     break;
-
-                if (thread_cmd.cmd == LC_THREAD)
-                {
-                    file_range.SetRangeBase (offset);
-                    file_range.SetByteSize (thread_cmd.cmdsize - 8);
-                    m_thread_context_offsets.Append (file_range);
+                  }
                 }
-                offset = cmd_offset + thread_cmd.cmdsize;
+                if (found_it)
+                  continue;
+              } else {
+                if (resolver_addresses.find(nlist.n_value) !=
+                    resolver_addresses.end())
+                  type = eSymbolTypeResolver;
+              }
+            } else if (type == eSymbolTypeData ||
+                       type == eSymbolTypeObjCClass ||
+                       type == eSymbolTypeObjCMetaClass ||
+                       type == eSymbolTypeObjCIVar) {
+              // See if we can find a N_STSYM entry for any data symbols.
+              // If we do find a match, and the name matches, then we
+              // can merge the two into just the Static symbol to avoid
+              // duplicate entries in the symbol table
+              std::pair<ValueToSymbolIndexMap::const_iterator,
+                        ValueToSymbolIndexMap::const_iterator>
+                  range;
+              range = N_STSYM_addr_to_sym_idx.equal_range(nlist.n_value);
+              if (range.first != range.second) {
+                bool found_it = false;
+                for (ValueToSymbolIndexMap::const_iterator pos = range.first;
+                     pos != range.second; ++pos) {
+                  if (sym[sym_idx].GetMangled().GetName(
+                          lldb::eLanguageTypeUnknown,
+                          Mangled::ePreferMangled) ==
+                      sym[pos->second].GetMangled().GetName(
+                          lldb::eLanguageTypeUnknown,
+                          Mangled::ePreferMangled)) {
+                    m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
+                    // We just need the flags from the linker symbol, so put
+                    // these flags
+                    // into the N_STSYM flags to avoid duplicate symbols in the
+                    // symbol table
+                    sym[pos->second].SetExternal(sym[sym_idx].IsExternal());
+                    sym[pos->second].SetFlags(nlist.n_type << 16 |
+                                              nlist.n_desc);
+                    sym[sym_idx].Clear();
+                    found_it = true;
+                    break;
+                  }
+                }
+                if (found_it)
+                  continue;
+              } else {
+                // Combine N_GSYM stab entries with the non stab symbol
+                const char *gsym_name = sym[sym_idx]
+                                            .GetMangled()
+                                            .GetName(lldb::eLanguageTypeUnknown,
+                                                     Mangled::ePreferMangled)
+                                            .GetCString();
+                if (gsym_name) {
+                  ConstNameToSymbolIndexMap::const_iterator pos =
+                      N_GSYM_name_to_sym_idx.find(gsym_name);
+                  if (pos != N_GSYM_name_to_sym_idx.end()) {
+                    const uint32_t GSYM_sym_idx = pos->second;
+                    m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
+                    // Copy the address, because often the N_GSYM address has an
+                    // invalid address of zero
+                    // when the global is a common symbol
+                    sym[GSYM_sym_idx].GetAddressRef().SetSection(
+                        symbol_section);
+                    sym[GSYM_sym_idx].GetAddressRef().SetOffset(symbol_value);
+                    // We just need the flags from the linker symbol, so put
+                    // these flags
+                    // into the N_GSYM flags to avoid duplicate symbols in the
+                    // symbol table
+                    sym[GSYM_sym_idx].SetFlags(nlist.n_type << 16 |
+                                               nlist.n_desc);
+                    sym[sym_idx].Clear();
+                    continue;
+                  }
+                }
+              }
             }
-        }
-    }
-    return m_thread_context_offsets.GetSize();
+          }
+
+          sym[sym_idx].SetID(nlist_idx);
+          sym[sym_idx].SetType(type);
+          if (set_value) {
+            sym[sym_idx].GetAddressRef().SetSection(symbol_section);
+            sym[sym_idx].GetAddressRef().SetOffset(symbol_value);
+          }
+          sym[sym_idx].SetFlags(nlist.n_type << 16 | nlist.n_desc);
+
+          if (symbol_byte_size > 0)
+            sym[sym_idx].SetByteSize(symbol_byte_size);
+
+          if (demangled_is_synthesized)
+            sym[sym_idx].SetDemangledNameIsSynthesized(true);
+
+          ++sym_idx;
+        } else {
+          sym[sym_idx].Clear();
+        }
+      }
+
+      for (const auto &pos : reexport_shlib_needs_fixup) {
+        const auto undef_pos = undefined_name_to_desc.find(pos.second);
+        if (undef_pos != undefined_name_to_desc.end()) {
+          const uint8_t dylib_ordinal =
+              llvm::MachO::GET_LIBRARY_ORDINAL(undef_pos->second);
+          if (dylib_ordinal > 0 && dylib_ordinal < dylib_files.GetSize())
+            sym[pos.first].SetReExportedSymbolSharedLibrary(
+                dylib_files.GetFileSpecAtIndex(dylib_ordinal - 1));
+        }
+      }
+    }
+
+    uint32_t synthetic_sym_id = symtab_load_command.nsyms;
+
+    if (function_starts_count > 0) {
+      uint32_t num_synthetic_function_symbols = 0;
+      for (i = 0; i < function_starts_count; ++i) {
+        if (function_starts.GetEntryRef(i).data == false)
+          ++num_synthetic_function_symbols;
+      }
+
+      if (num_synthetic_function_symbols > 0) {
+        if (num_syms < sym_idx + num_synthetic_function_symbols) {
+          num_syms = sym_idx + num_synthetic_function_symbols;
+          sym = symtab->Resize(num_syms);
+        }
+        for (i = 0; i < function_starts_count; ++i) {
+          const FunctionStarts::Entry *func_start_entry =
+              function_starts.GetEntryAtIndex(i);
+          if (func_start_entry->data == false) {
+            addr_t symbol_file_addr = func_start_entry->addr;
+            uint32_t symbol_flags = 0;
+            if (is_arm) {
+              if (symbol_file_addr & 1)
+                symbol_flags = MACHO_NLIST_ARM_SYMBOL_IS_THUMB;
+              symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+            }
+            Address symbol_addr;
+            if (module_sp->ResolveFileAddress(symbol_file_addr, symbol_addr)) {
+              SectionSP symbol_section(symbol_addr.GetSection());
+              uint32_t symbol_byte_size = 0;
+              if (symbol_section) {
+                const addr_t section_file_addr =
+                    symbol_section->GetFileAddress();
+                const FunctionStarts::Entry *next_func_start_entry =
+                    function_starts.FindNextEntry(func_start_entry);
+                const addr_t section_end_file_addr =
+                    section_file_addr + symbol_section->GetByteSize();
+                if (next_func_start_entry) {
+                  addr_t next_symbol_file_addr = next_func_start_entry->addr;
+                  if (is_arm)
+                    next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+                  symbol_byte_size = std::min<lldb::addr_t>(
+                      next_symbol_file_addr - symbol_file_addr,
+                      section_end_file_addr - symbol_file_addr);
+                } else {
+                  symbol_byte_size = section_end_file_addr - symbol_file_addr;
+                }
+                sym[sym_idx].SetID(synthetic_sym_id++);
+                sym[sym_idx].GetMangled().SetDemangledName(
+                    GetNextSyntheticSymbolName());
+                sym[sym_idx].SetType(eSymbolTypeCode);
+                sym[sym_idx].SetIsSynthetic(true);
+                sym[sym_idx].GetAddressRef() = symbol_addr;
+                if (symbol_flags)
+                  sym[sym_idx].SetFlags(symbol_flags);
+                if (symbol_byte_size)
+                  sym[sym_idx].SetByteSize(symbol_byte_size);
+                ++sym_idx;
+              }
+            }
+          }
+        }
+      }
+    }
+
+    // Trim our symbols down to just what we ended up with after
+    // removing any symbols.
+    if (sym_idx < num_syms) {
+      num_syms = sym_idx;
+      sym = symtab->Resize(num_syms);
+    }
+
+    // Now synthesize indirect symbols
+    if (m_dysymtab.nindirectsyms != 0) {
+      if (indirect_symbol_index_data.GetByteSize()) {
+        NListIndexToSymbolIndexMap::const_iterator end_index_pos =
+            m_nlist_idx_to_sym_idx.end();
+
+        for (uint32_t sect_idx = 1; sect_idx < m_mach_sections.size();
+             ++sect_idx) {
+          if ((m_mach_sections[sect_idx].flags & SECTION_TYPE) ==
+              S_SYMBOL_STUBS) {
+            uint32_t symbol_stub_byte_size =
+                m_mach_sections[sect_idx].reserved2;
+            if (symbol_stub_byte_size == 0)
+              continue;
+
+            const uint32_t num_symbol_stubs =
+                m_mach_sections[sect_idx].size / symbol_stub_byte_size;
+
+            if (num_symbol_stubs == 0)
+              continue;
+
+            const uint32_t symbol_stub_index_offset =
+                m_mach_sections[sect_idx].reserved1;
+            for (uint32_t stub_idx = 0; stub_idx < num_symbol_stubs;
+                 ++stub_idx) {
+              const uint32_t symbol_stub_index =
+                  symbol_stub_index_offset + stub_idx;
+              const lldb::addr_t symbol_stub_addr =
+                  m_mach_sections[sect_idx].addr +
+                  (stub_idx * symbol_stub_byte_size);
+              lldb::offset_t symbol_stub_offset = symbol_stub_index * 4;
+              if (indirect_symbol_index_data.ValidOffsetForDataOfSize(
+                      symbol_stub_offset, 4)) {
+                const uint32_t stub_sym_id =
+                    indirect_symbol_index_data.GetU32(&symbol_stub_offset);
+                if (stub_sym_id & (INDIRECT_SYMBOL_ABS | INDIRECT_SYMBOL_LOCAL))
+                  continue;
+
+                NListIndexToSymbolIndexMap::const_iterator index_pos =
+                    m_nlist_idx_to_sym_idx.find(stub_sym_id);
+                Symbol *stub_symbol = NULL;
+                if (index_pos != end_index_pos) {
+                  // We have a remapping from the original nlist index to
+                  // a current symbol index, so just look this up by index
+                  stub_symbol = symtab->SymbolAtIndex(index_pos->second);
+                } else {
+                  // We need to lookup a symbol using the original nlist
+                  // symbol index since this index is coming from the
+                  // S_SYMBOL_STUBS
+                  stub_symbol = symtab->FindSymbolByID(stub_sym_id);
+                }
+
+                if (stub_symbol) {
+                  Address so_addr(symbol_stub_addr, section_list);
+
+                  if (stub_symbol->GetType() == eSymbolTypeUndefined) {
+                    // Change the external symbol into a trampoline that makes
+                    // sense
+                    // These symbols were N_UNDF N_EXT, and are useless to us,
+                    // so we
+                    // can re-use them so we don't have to make up a synthetic
+                    // symbol
+                    // for no good reason.
+                    if (resolver_addresses.find(symbol_stub_addr) ==
+                        resolver_addresses.end())
+                      stub_symbol->SetType(eSymbolTypeTrampoline);
+                    else
+                      stub_symbol->SetType(eSymbolTypeResolver);
+                    stub_symbol->SetExternal(false);
+                    stub_symbol->GetAddressRef() = so_addr;
+                    stub_symbol->SetByteSize(symbol_stub_byte_size);
+                  } else {
+                    // Make a synthetic symbol to describe the trampoline stub
+                    Mangled stub_symbol_mangled_name(stub_symbol->GetMangled());
+                    if (sym_idx >= num_syms) {
+                      sym = symtab->Resize(++num_syms);
+                      stub_symbol = NULL; // this pointer no longer valid
+                    }
+                    sym[sym_idx].SetID(synthetic_sym_id++);
+                    sym[sym_idx].GetMangled() = stub_symbol_mangled_name;
+                    if (resolver_addresses.find(symbol_stub_addr) ==
+                        resolver_addresses.end())
+                      sym[sym_idx].SetType(eSymbolTypeTrampoline);
+                    else
+                      sym[sym_idx].SetType(eSymbolTypeResolver);
+                    sym[sym_idx].SetIsSynthetic(true);
+                    sym[sym_idx].GetAddressRef() = so_addr;
+                    sym[sym_idx].SetByteSize(symbol_stub_byte_size);
+                    ++sym_idx;
+                  }
+                } else {
+                  if (log)
+                    log->Warning("symbol stub referencing symbol table symbol "
+                                 "%u that isn't in our minimal symbol table, "
+                                 "fix this!!!",
+                                 stub_sym_id);
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+
+    if (!trie_entries.empty()) {
+      for (const auto &e : trie_entries) {
+        if (e.entry.import_name) {
+          // Only add indirect symbols from the Trie entries if we
+          // didn't have a N_INDR nlist entry for this already
+          if (indirect_symbol_names.find(e.entry.name) ==
+              indirect_symbol_names.end()) {
+            // Make a synthetic symbol to describe re-exported symbol.
+            if (sym_idx >= num_syms)
+              sym = symtab->Resize(++num_syms);
+            sym[sym_idx].SetID(synthetic_sym_id++);
+            sym[sym_idx].GetMangled() = Mangled(e.entry.name);
+            sym[sym_idx].SetType(eSymbolTypeReExported);
+            sym[sym_idx].SetIsSynthetic(true);
+            sym[sym_idx].SetReExportedSymbolName(e.entry.import_name);
+            if (e.entry.other > 0 && e.entry.other <= dylib_files.GetSize()) {
+              sym[sym_idx].SetReExportedSymbolSharedLibrary(
+                  dylib_files.GetFileSpecAtIndex(e.entry.other - 1));
+            }
+            ++sym_idx;
+          }
+        }
+      }
+    }
+
+    //        StreamFile s(stdout, false);
+    //        s.Printf ("Symbol table before CalculateSymbolSizes():\n");
+    //        symtab->Dump(&s, NULL, eSortOrderNone);
+    // Set symbol byte sizes correctly since mach-o nlist entries don't have
+    // sizes
+    symtab->CalculateSymbolSizes();
+
+    //        s.Printf ("Symbol table after CalculateSymbolSizes():\n");
+    //        symtab->Dump(&s, NULL, eSortOrderNone);
+
+    return symtab->GetNumSymbols();
+  }
+  return 0;
+}
+
+void ObjectFileMachO::Dump(Stream *s) {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    s->Printf("%p: ", static_cast<void *>(this));
+    s->Indent();
+    if (m_header.magic == MH_MAGIC_64 || m_header.magic == MH_CIGAM_64)
+      s->PutCString("ObjectFileMachO64");
+    else
+      s->PutCString("ObjectFileMachO32");
+
+    ArchSpec header_arch;
+    GetArchitecture(header_arch);
+
+    *s << ", file = '" << m_file
+       << "', arch = " << header_arch.GetArchitectureName() << "\n";
+
+    SectionList *sections = GetSectionList();
+    if (sections)
+      sections->Dump(s, NULL, true, UINT32_MAX);
+
+    if (m_symtab_ap.get())
+      m_symtab_ap->Dump(s, NULL, eSortOrderNone);
+  }
 }
 
-lldb::RegisterContextSP
-ObjectFileMachO::GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread)
-{
-    lldb::RegisterContextSP reg_ctx_sp;
+bool ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
+                              const lldb_private::DataExtractor &data,
+                              lldb::offset_t lc_offset,
+                              lldb_private::UUID &uuid) {
+  uint32_t i;
+  struct uuid_command load_cmd;
 
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        if (!m_thread_context_offsets_valid)
-            GetNumThreadContexts ();
-
-        const FileRangeArray::Entry *thread_context_file_range = m_thread_context_offsets.GetEntryAtIndex (idx);
-        if (thread_context_file_range)
-        {
-
-            DataExtractor data (m_data,
-                                thread_context_file_range->GetRangeBase(),
-                                thread_context_file_range->GetByteSize());
+  lldb::offset_t offset = lc_offset;
+  for (i = 0; i < header.ncmds; ++i) {
+    const lldb::offset_t cmd_offset = offset;
+    if (data.GetU32(&offset, &load_cmd, 2) == NULL)
+      break;
 
-            switch (m_header.cputype)
-            {
-                case llvm::MachO::CPU_TYPE_ARM64:
-                    reg_ctx_sp.reset (new RegisterContextDarwin_arm64_Mach (thread, data));
-                    break;
-                    
-                case llvm::MachO::CPU_TYPE_ARM:
-                    reg_ctx_sp.reset (new RegisterContextDarwin_arm_Mach (thread, data));
-                    break;
+    if (load_cmd.cmd == LC_UUID) {
+      const uint8_t *uuid_bytes = data.PeekData(offset, 16);
 
-                case llvm::MachO::CPU_TYPE_I386:
-                    reg_ctx_sp.reset (new RegisterContextDarwin_i386_Mach (thread, data));
-                    break;
+      if (uuid_bytes) {
+        // OpenCL on Mac OS X uses the same UUID for each of its object files.
+        // We pretend these object files have no UUID to prevent crashing.
 
-                case llvm::MachO::CPU_TYPE_X86_64:
-                    reg_ctx_sp.reset (new RegisterContextDarwin_x86_64_Mach (thread, data));
-                    break;
-            }
-        }
+        const uint8_t opencl_uuid[] = {0x8c, 0x8e, 0xb3, 0x9b, 0x3b, 0xa8,
+                                       0x4b, 0x16, 0xb6, 0xa4, 0x27, 0x63,
+                                       0xbb, 0x14, 0xf0, 0x0d};
+
+        if (!memcmp(uuid_bytes, opencl_uuid, 16))
+          return false;
+
+        uuid.SetBytes(uuid_bytes);
+        return true;
+      }
+      return false;
     }
-    return reg_ctx_sp;
-}
+    offset = cmd_offset + load_cmd.cmdsize;
+  }
+  return false;
+}
+
+bool ObjectFileMachO::GetArchitecture(const llvm::MachO::mach_header &header,
+                                      const lldb_private::DataExtractor &data,
+                                      lldb::offset_t lc_offset,
+                                      ArchSpec &arch) {
+  arch.SetArchitecture(eArchTypeMachO, header.cputype, header.cpusubtype);
+
+  if (arch.IsValid()) {
+    llvm::Triple &triple = arch.GetTriple();
+
+    // Set OS to an unspecified unknown or a "*" so it can match any OS
+    triple.setOS(llvm::Triple::UnknownOS);
+    triple.setOSName(llvm::StringRef());
+
+    if (header.filetype == MH_PRELOAD) {
+      if (header.cputype == CPU_TYPE_ARM) {
+        // If this is a 32-bit arm binary, and it's a standalone binary,
+        // force the Vendor to Apple so we don't accidentally pick up
+        // the generic armv7 ABI at runtime.  Apple's armv7 ABI always uses
+        // r7 for the frame pointer register; most other armv7 ABIs use a
+        // combination of r7 and r11.
+        triple.setVendor(llvm::Triple::Apple);
+      } else {
+        // Set vendor to an unspecified unknown or a "*" so it can match any
+        // vendor
+        // This is required for correct behavior of EFI debugging on x86_64
+        triple.setVendor(llvm::Triple::UnknownVendor);
+        triple.setVendorName(llvm::StringRef());
+      }
+      return true;
+    } else {
+      struct load_command load_cmd;
 
-ObjectFile::Type
-ObjectFileMachO::CalculateType()
-{
-    switch (m_header.filetype)
-    {
-        case MH_OBJECT:                                         // 0x1u
-            if (GetAddressByteSize () == 4)
-            {
-                // 32 bit kexts are just object files, but they do have a valid
-                // UUID load command.
-                UUID uuid;
-                if (GetUUID(&uuid))
-                {
-                    // this checking for the UUID load command is not enough
-                    // we could eventually look for the symbol named
-                    // "OSKextGetCurrentIdentifier" as this is required of kexts
-                    if (m_strata == eStrataInvalid)
-                        m_strata = eStrataKernel;
-                    return eTypeSharedLibrary;
-                }
-            }
-            return eTypeObjectFile;
+      lldb::offset_t offset = lc_offset;
+      for (uint32_t i = 0; i < header.ncmds; ++i) {
+        const lldb::offset_t cmd_offset = offset;
+        if (data.GetU32(&offset, &load_cmd, 2) == NULL)
+          break;
+
+        switch (load_cmd.cmd) {
+        case llvm::MachO::LC_VERSION_MIN_IPHONEOS:
+          triple.setOS(llvm::Triple::IOS);
+          return true;
+
+        case llvm::MachO::LC_VERSION_MIN_MACOSX:
+          triple.setOS(llvm::Triple::MacOSX);
+          return true;
+
+        case llvm::MachO::LC_VERSION_MIN_TVOS:
+          triple.setOS(llvm::Triple::TvOS);
+          return true;
+
+        case llvm::MachO::LC_VERSION_MIN_WATCHOS:
+          triple.setOS(llvm::Triple::WatchOS);
+          return true;
 
-        case MH_EXECUTE:            return eTypeExecutable;     // 0x2u
-        case MH_FVMLIB:             return eTypeSharedLibrary;  // 0x3u
-        case MH_CORE:               return eTypeCoreFile;       // 0x4u
-        case MH_PRELOAD:            return eTypeSharedLibrary;  // 0x5u
-        case MH_DYLIB:              return eTypeSharedLibrary;  // 0x6u
-        case MH_DYLINKER:           return eTypeDynamicLinker;  // 0x7u
-        case MH_BUNDLE:             return eTypeSharedLibrary;  // 0x8u
-        case MH_DYLIB_STUB:         return eTypeStubLibrary;    // 0x9u
-        case MH_DSYM:               return eTypeDebugInfo;      // 0xAu
-        case MH_KEXT_BUNDLE:        return eTypeSharedLibrary;  // 0xBu
         default:
+          break;
+        }
+
+        offset = cmd_offset + load_cmd.cmdsize;
+      }
+
+      if (header.filetype != MH_KEXT_BUNDLE) {
+        // We didn't find a LC_VERSION_MIN load command and this isn't a KEXT
+        // so lets not say our Vendor is Apple, leave it as an unspecified
+        // unknown
+        triple.setVendor(llvm::Triple::UnknownVendor);
+        triple.setVendorName(llvm::StringRef());
+      }
+    }
+  }
+  return arch.IsValid();
+}
+
+bool ObjectFileMachO::GetUUID(lldb_private::UUID *uuid) {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    return GetUUID(m_header, m_data, offset, *uuid);
+  }
+  return false;
+}
+
+uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
+  uint32_t count = 0;
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    struct load_command load_cmd;
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    std::vector<std::string> rpath_paths;
+    std::vector<std::string> rpath_relative_paths;
+    const bool resolve_path = false; // Don't resolve the dependent file paths
+                                     // since they may not reside on this system
+    uint32_t i;
+    for (i = 0; i < m_header.ncmds; ++i) {
+      const uint32_t cmd_offset = offset;
+      if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+        break;
+
+      switch (load_cmd.cmd) {
+      case LC_RPATH:
+      case LC_LOAD_DYLIB:
+      case LC_LOAD_WEAK_DYLIB:
+      case LC_REEXPORT_DYLIB:
+      case LC_LOAD_DYLINKER:
+      case LC_LOADFVMLIB:
+      case LC_LOAD_UPWARD_DYLIB: {
+        uint32_t name_offset = cmd_offset + m_data.GetU32(&offset);
+        const char *path = m_data.PeekCStr(name_offset);
+        if (path) {
+          if (load_cmd.cmd == LC_RPATH)
+            rpath_paths.push_back(path);
+          else {
+            if (path[0] == '@') {
+              if (strncmp(path, "@rpath", strlen("@rpath")) == 0)
+                rpath_relative_paths.push_back(path + strlen("@rpath"));
+            } else {
+              FileSpec file_spec(path, resolve_path);
+              if (files.AppendIfUnique(file_spec))
+                count++;
+            }
+          }
+        }
+      } break;
+
+      default:
+        break;
+      }
+      offset = cmd_offset + load_cmd.cmdsize;
+    }
+
+    if (!rpath_paths.empty()) {
+      // Fixup all LC_RPATH values to be absolute paths
+      FileSpec this_file_spec(m_file);
+      this_file_spec.ResolvePath();
+      std::string loader_path("@loader_path");
+      std::string executable_path("@executable_path");
+      for (auto &rpath : rpath_paths) {
+        if (rpath.find(loader_path) == 0) {
+          rpath.erase(0, loader_path.size());
+          rpath.insert(0, this_file_spec.GetDirectory().GetCString());
+        } else if (rpath.find(executable_path) == 0) {
+          rpath.erase(0, executable_path.size());
+          rpath.insert(0, this_file_spec.GetDirectory().GetCString());
+        }
+      }
+
+      for (const auto &rpath_relative_path : rpath_relative_paths) {
+        for (const auto &rpath : rpath_paths) {
+          std::string path = rpath;
+          path += rpath_relative_path;
+          // It is OK to resolve this path because we must find a file on
+          // disk for us to accept it anyway if it is rpath relative.
+          FileSpec file_spec(path, true);
+          // Remove any redundant parts of the path (like "../foo") since
+          // LC_RPATH values often contain "..".
+          file_spec.NormalizePath();
+          if (file_spec.Exists() && files.AppendIfUnique(file_spec)) {
+            count++;
             break;
+          }
+        }
+      }
     }
-    return eTypeUnknown;
+  }
+  return count;
 }
 
-ObjectFile::Strata
-ObjectFileMachO::CalculateStrata()
-{
-    switch (m_header.filetype)
-    {
-        case MH_OBJECT:                                  // 0x1u
-            {
-                // 32 bit kexts are just object files, but they do have a valid
-                // UUID load command.
-                UUID uuid;
-                if (GetUUID(&uuid))
-                {
-                    // this checking for the UUID load command is not enough
-                    // we could eventually look for the symbol named
-                    // "OSKextGetCurrentIdentifier" as this is required of kexts
-                    if (m_type == eTypeInvalid)
-                        m_type = eTypeSharedLibrary;
+lldb_private::Address ObjectFileMachO::GetEntryPointAddress() {
+  // If the object file is not an executable it can't hold the entry point.
+  // m_entry_point_address
+  // is initialized to an invalid address, so we can just return that.
+  // If m_entry_point_address is valid it means we've found it already, so
+  // return the cached value.
 
-                    return eStrataKernel;
-                }
-            }
-            return eStrataUnknown;
+  if (!IsExecutable() || m_entry_point_address.IsValid())
+    return m_entry_point_address;
 
-        case MH_EXECUTE:                                 // 0x2u
-            // Check for the MH_DYLDLINK bit in the flags
-            if (m_header.flags & MH_DYLDLINK)
-            {
-                return eStrataUser;
+  // Otherwise, look for the UnixThread or Thread command.  The data for the
+  // Thread command is given in
+  // /usr/include/mach-o.h, but it is basically:
+  //
+  //  uint32_t flavor  - this is the flavor argument you would pass to
+  //  thread_get_state
+  //  uint32_t count   - this is the count of longs in the thread state data
+  //  struct XXX_thread_state state - this is the structure from
+  //  <machine/thread_status.h> corresponding to the flavor.
+  //  <repeat this trio>
+  //
+  // So we just keep reading the various register flavors till we find the GPR
+  // one, then read the PC out of there.
+  // FIXME: We will need to have a "RegisterContext data provider" class at some
+  // point that can get all the registers
+  // out of data in this form & attach them to a given thread.  That should
+  // underlie the MacOS X User process plugin,
+  // and we'll also need it for the MacOS X Core File process plugin.  When we
+  // have that we can also use it here.
+  //
+  // For now we hard-code the offsets and flavors we need:
+  //
+  //
+
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    struct load_command load_cmd;
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    uint32_t i;
+    lldb::addr_t start_address = LLDB_INVALID_ADDRESS;
+    bool done = false;
+
+    for (i = 0; i < m_header.ncmds; ++i) {
+      const lldb::offset_t cmd_offset = offset;
+      if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+        break;
+
+      switch (load_cmd.cmd) {
+      case LC_UNIXTHREAD:
+      case LC_THREAD: {
+        while (offset < cmd_offset + load_cmd.cmdsize) {
+          uint32_t flavor = m_data.GetU32(&offset);
+          uint32_t count = m_data.GetU32(&offset);
+          if (count == 0) {
+            // We've gotten off somehow, log and exit;
+            return m_entry_point_address;
+          }
+
+          switch (m_header.cputype) {
+          case llvm::MachO::CPU_TYPE_ARM:
+            if (flavor == 1 ||
+                flavor == 9) // ARM_THREAD_STATE/ARM_THREAD_STATE32 from
+                             // mach/arm/thread_status.h
+            {
+              offset += 60; // This is the offset of pc in the GPR thread state
+                            // data structure.
+              start_address = m_data.GetU32(&offset);
+              done = true;
             }
-            else
+            break;
+          case llvm::MachO::CPU_TYPE_ARM64:
+            if (flavor == 6) // ARM_THREAD_STATE64 from mach/arm/thread_status.h
             {
-                SectionList *section_list = GetSectionList();
-                if (section_list)
-                {
-                    static ConstString g_kld_section_name ("__KLD");
-                    if (section_list->FindSectionByName(g_kld_section_name))
-                        return eStrataKernel;
-                }
+              offset += 256; // This is the offset of pc in the GPR thread state
+                             // data structure.
+              start_address = m_data.GetU64(&offset);
+              done = true;
             }
-            return eStrataRawImage;
-
-        case MH_FVMLIB:      return eStrataUser;         // 0x3u
-        case MH_CORE:        return eStrataUnknown;      // 0x4u
-        case MH_PRELOAD:     return eStrataRawImage;     // 0x5u
-        case MH_DYLIB:       return eStrataUser;         // 0x6u
-        case MH_DYLINKER:    return eStrataUser;         // 0x7u
-        case MH_BUNDLE:      return eStrataUser;         // 0x8u
-        case MH_DYLIB_STUB:  return eStrataUser;         // 0x9u
-        case MH_DSYM:        return eStrataUnknown;      // 0xAu
-        case MH_KEXT_BUNDLE: return eStrataKernel;       // 0xBu
-        default:
             break;
-    }
-    return eStrataUnknown;
-}
-
-uint32_t
-ObjectFileMachO::GetVersion (uint32_t *versions, uint32_t num_versions)
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        struct dylib_command load_cmd;
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        uint32_t version_cmd = 0;
-        uint64_t version = 0;
-        uint32_t i;
-        for (i=0; i<m_header.ncmds; ++i)
-        {
-            const lldb::offset_t cmd_offset = offset;
-            if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
-                break;
-
-            if (load_cmd.cmd == LC_ID_DYLIB)
-            {
-                if (version_cmd == 0)
-                {
-                    version_cmd = load_cmd.cmd;
-                    if (m_data.GetU32(&offset, &load_cmd.dylib, 4) == NULL)
-                        break;
-                    version = load_cmd.dylib.current_version;
-                }
-                break; // Break for now unless there is another more complete version
-                       // number load command in the future.
+          case llvm::MachO::CPU_TYPE_I386:
+            if (flavor ==
+                1) // x86_THREAD_STATE32 from mach/i386/thread_status.h
+            {
+              offset += 40; // This is the offset of eip in the GPR thread state
+                            // data structure.
+              start_address = m_data.GetU32(&offset);
+              done = true;
             }
-            offset = cmd_offset + load_cmd.cmdsize;
+            break;
+          case llvm::MachO::CPU_TYPE_X86_64:
+            if (flavor ==
+                4) // x86_THREAD_STATE64 from mach/i386/thread_status.h
+            {
+              offset += 16 * 8; // This is the offset of rip in the GPR thread
+                                // state data structure.
+              start_address = m_data.GetU64(&offset);
+              done = true;
+            }
+            break;
+          default:
+            return m_entry_point_address;
+          }
+          // Haven't found the GPR flavor yet, skip over the data for this
+          // flavor:
+          if (done)
+            break;
+          offset += count * 4;
         }
-
-        if (version_cmd == LC_ID_DYLIB)
-        {
-            if (versions != NULL && num_versions > 0)
-            {
-                if (num_versions > 0)
-                    versions[0] = (version & 0xFFFF0000ull) >> 16;
-                if (num_versions > 1)
-                    versions[1] = (version & 0x0000FF00ull) >> 8;
-                if (num_versions > 2)
-                    versions[2] = (version & 0x000000FFull);
-                // Fill in an remaining version numbers with invalid values
-                for (i=3; i<num_versions; ++i)
-                    versions[i] = UINT32_MAX;
-            }
-            // The LC_ID_DYLIB load command has a version with 3 version numbers
-            // in it, so always return 3
-            return 3;
+      } break;
+      case LC_MAIN: {
+        ConstString text_segment_name("__TEXT");
+        uint64_t entryoffset = m_data.GetU64(&offset);
+        SectionSP text_segment_sp =
+            GetSectionList()->FindSectionByName(text_segment_name);
+        if (text_segment_sp) {
+          done = true;
+          start_address = text_segment_sp->GetFileAddress() + entryoffset;
+        }
+      } break;
+
+      default:
+        break;
+      }
+      if (done)
+        break;
+
+      // Go to the next load command:
+      offset = cmd_offset + load_cmd.cmdsize;
+    }
+
+    if (start_address != LLDB_INVALID_ADDRESS) {
+      // We got the start address from the load commands, so now resolve that
+      // address in the sections
+      // of this ObjectFile:
+      if (!m_entry_point_address.ResolveAddressUsingFileSections(
+              start_address, GetSectionList())) {
+        m_entry_point_address.Clear();
+      }
+    } else {
+      // We couldn't read the UnixThread load command - maybe it wasn't there.
+      // As a fallback look for the
+      // "start" symbol in the main executable.
+
+      ModuleSP module_sp(GetModule());
+
+      if (module_sp) {
+        SymbolContextList contexts;
+        SymbolContext context;
+        if (module_sp->FindSymbolsWithNameAndType(ConstString("start"),
+                                                  eSymbolTypeCode, contexts)) {
+          if (contexts.GetContextAtIndex(0, context))
+            m_entry_point_address = context.symbol->GetAddress();
+        }
+      }
+    }
+  }
+
+  return m_entry_point_address;
+}
+
+lldb_private::Address ObjectFileMachO::GetHeaderAddress() {
+  lldb_private::Address header_addr;
+  SectionList *section_list = GetSectionList();
+  if (section_list) {
+    SectionSP text_segment_sp(
+        section_list->FindSectionByName(GetSegmentNameTEXT()));
+    if (text_segment_sp) {
+      header_addr.SetSection(text_segment_sp);
+      header_addr.SetOffset(0);
+    }
+  }
+  return header_addr;
+}
+
+uint32_t ObjectFileMachO::GetNumThreadContexts() {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    if (!m_thread_context_offsets_valid) {
+      m_thread_context_offsets_valid = true;
+      lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+      FileRangeArray::Entry file_range;
+      thread_command thread_cmd;
+      for (uint32_t i = 0; i < m_header.ncmds; ++i) {
+        const uint32_t cmd_offset = offset;
+        if (m_data.GetU32(&offset, &thread_cmd, 2) == NULL)
+          break;
+
+        if (thread_cmd.cmd == LC_THREAD) {
+          file_range.SetRangeBase(offset);
+          file_range.SetByteSize(thread_cmd.cmdsize - 8);
+          m_thread_context_offsets.Append(file_range);
         }
+        offset = cmd_offset + thread_cmd.cmdsize;
+      }
     }
-    return false;
-}
-
-bool
-ObjectFileMachO::GetArchitecture (ArchSpec &arch)
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        return GetArchitecture (m_header, m_data, MachHeaderSizeFromMagic(m_header.magic), arch);
-    }
-    return false;
+  }
+  return m_thread_context_offsets.GetSize();
 }
 
-UUID
-ObjectFileMachO::GetProcessSharedCacheUUID (Process *process)
-{
+lldb::RegisterContextSP
+ObjectFileMachO::GetThreadContextAtIndex(uint32_t idx,
+                                         lldb_private::Thread &thread) {
+  lldb::RegisterContextSP reg_ctx_sp;
+
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    if (!m_thread_context_offsets_valid)
+      GetNumThreadContexts();
+
+    const FileRangeArray::Entry *thread_context_file_range =
+        m_thread_context_offsets.GetEntryAtIndex(idx);
+    if (thread_context_file_range) {
+
+      DataExtractor data(m_data, thread_context_file_range->GetRangeBase(),
+                         thread_context_file_range->GetByteSize());
+
+      switch (m_header.cputype) {
+      case llvm::MachO::CPU_TYPE_ARM64:
+        reg_ctx_sp.reset(new RegisterContextDarwin_arm64_Mach(thread, data));
+        break;
+
+      case llvm::MachO::CPU_TYPE_ARM:
+        reg_ctx_sp.reset(new RegisterContextDarwin_arm_Mach(thread, data));
+        break;
+
+      case llvm::MachO::CPU_TYPE_I386:
+        reg_ctx_sp.reset(new RegisterContextDarwin_i386_Mach(thread, data));
+        break;
+
+      case llvm::MachO::CPU_TYPE_X86_64:
+        reg_ctx_sp.reset(new RegisterContextDarwin_x86_64_Mach(thread, data));
+        break;
+      }
+    }
+  }
+  return reg_ctx_sp;
+}
+
+ObjectFile::Type ObjectFileMachO::CalculateType() {
+  switch (m_header.filetype) {
+  case MH_OBJECT: // 0x1u
+    if (GetAddressByteSize() == 4) {
+      // 32 bit kexts are just object files, but they do have a valid
+      // UUID load command.
+      UUID uuid;
+      if (GetUUID(&uuid)) {
+        // this checking for the UUID load command is not enough
+        // we could eventually look for the symbol named
+        // "OSKextGetCurrentIdentifier" as this is required of kexts
+        if (m_strata == eStrataInvalid)
+          m_strata = eStrataKernel;
+        return eTypeSharedLibrary;
+      }
+    }
+    return eTypeObjectFile;
+
+  case MH_EXECUTE:
+    return eTypeExecutable; // 0x2u
+  case MH_FVMLIB:
+    return eTypeSharedLibrary; // 0x3u
+  case MH_CORE:
+    return eTypeCoreFile; // 0x4u
+  case MH_PRELOAD:
+    return eTypeSharedLibrary; // 0x5u
+  case MH_DYLIB:
+    return eTypeSharedLibrary; // 0x6u
+  case MH_DYLINKER:
+    return eTypeDynamicLinker; // 0x7u
+  case MH_BUNDLE:
+    return eTypeSharedLibrary; // 0x8u
+  case MH_DYLIB_STUB:
+    return eTypeStubLibrary; // 0x9u
+  case MH_DSYM:
+    return eTypeDebugInfo; // 0xAu
+  case MH_KEXT_BUNDLE:
+    return eTypeSharedLibrary; // 0xBu
+  default:
+    break;
+  }
+  return eTypeUnknown;
+}
+
+ObjectFile::Strata ObjectFileMachO::CalculateStrata() {
+  switch (m_header.filetype) {
+  case MH_OBJECT: // 0x1u
+  {
+    // 32 bit kexts are just object files, but they do have a valid
+    // UUID load command.
     UUID uuid;
-    if (process && process->GetDynamicLoader())
-    {
-        DynamicLoader *dl = process->GetDynamicLoader();
-        addr_t load_address;
-        LazyBool using_shared_cache;
-        LazyBool private_shared_cache;
-        dl->GetSharedCacheInformation (load_address, uuid, using_shared_cache, private_shared_cache);
-    }
-    return uuid;
-}
+    if (GetUUID(&uuid)) {
+      // this checking for the UUID load command is not enough
+      // we could eventually look for the symbol named
+      // "OSKextGetCurrentIdentifier" as this is required of kexts
+      if (m_type == eTypeInvalid)
+        m_type = eTypeSharedLibrary;
 
-UUID
-ObjectFileMachO::GetLLDBSharedCacheUUID ()
-{
-    UUID uuid;
-#if defined (__APPLE__) && (defined (__arm__) || defined (__arm64__) || defined (__aarch64__))
-    uint8_t *(*dyld_get_all_image_infos)(void);
-    dyld_get_all_image_infos = (uint8_t*(*)()) dlsym (RTLD_DEFAULT, "_dyld_get_all_image_infos");
-    if (dyld_get_all_image_infos)
-    {
-        uint8_t *dyld_all_image_infos_address = dyld_get_all_image_infos();
-        if (dyld_all_image_infos_address)
-        {
-            uint32_t *version = (uint32_t*) dyld_all_image_infos_address;              // version <mach-o/dyld_images.h>
-            if (*version >= 13)
-            {
-                uuid_t *sharedCacheUUID_address = 0;
-                int wordsize = sizeof (uint8_t *);
-                if (wordsize == 8)
-                {
-                    sharedCacheUUID_address = (uuid_t*) ((uint8_t*) dyld_all_image_infos_address + 160); // sharedCacheUUID <mach-o/dyld_images.h>
-                }
-                else
-                {
-                    sharedCacheUUID_address = (uuid_t*) ((uint8_t*) dyld_all_image_infos_address + 84);  // sharedCacheUUID <mach-o/dyld_images.h>
-                }
-                uuid.SetBytes (sharedCacheUUID_address);
-            }
-        }
+      return eStrataKernel;
     }
-#endif
-    return uuid;
-}
+  }
+    return eStrataUnknown;
 
-uint32_t
-ObjectFileMachO::GetMinimumOSVersion (uint32_t *versions, uint32_t num_versions)
-{
-    if (m_min_os_versions.empty())
-    {
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        bool success = false;
-        for (uint32_t i=0; success == false && i < m_header.ncmds; ++i)
-        {
-            const lldb::offset_t load_cmd_offset = offset;
-            
-            version_min_command lc;
-            if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
-                break;
-            if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX 
-                 || lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS 
-                 || lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS 
-                 || lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS)
-            {
-                if (m_data.GetU32 (&offset, &lc.version, (sizeof(lc) / sizeof(uint32_t)) - 2))
-                {
-                    const uint32_t xxxx = lc.version >> 16;
-                    const uint32_t yy = (lc.version >> 8) & 0xffu;
-                    const uint32_t zz = lc.version  & 0xffu;
-                    if (xxxx)
-                    {
-                        m_min_os_versions.push_back(xxxx);
-                        m_min_os_versions.push_back(yy);
-                        m_min_os_versions.push_back(zz);
-                    }
-                    success = true;
-                }
-            }
-            offset = load_cmd_offset + lc.cmdsize;
+  case MH_EXECUTE: // 0x2u
+    // Check for the MH_DYLDLINK bit in the flags
+    if (m_header.flags & MH_DYLDLINK) {
+      return eStrataUser;
+    } else {
+      SectionList *section_list = GetSectionList();
+      if (section_list) {
+        static ConstString g_kld_section_name("__KLD");
+        if (section_list->FindSectionByName(g_kld_section_name))
+          return eStrataKernel;
+      }
+    }
+    return eStrataRawImage;
+
+  case MH_FVMLIB:
+    return eStrataUser; // 0x3u
+  case MH_CORE:
+    return eStrataUnknown; // 0x4u
+  case MH_PRELOAD:
+    return eStrataRawImage; // 0x5u
+  case MH_DYLIB:
+    return eStrataUser; // 0x6u
+  case MH_DYLINKER:
+    return eStrataUser; // 0x7u
+  case MH_BUNDLE:
+    return eStrataUser; // 0x8u
+  case MH_DYLIB_STUB:
+    return eStrataUser; // 0x9u
+  case MH_DSYM:
+    return eStrataUnknown; // 0xAu
+  case MH_KEXT_BUNDLE:
+    return eStrataKernel; // 0xBu
+  default:
+    break;
+  }
+  return eStrataUnknown;
+}
+
+uint32_t ObjectFileMachO::GetVersion(uint32_t *versions,
+                                     uint32_t num_versions) {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    struct dylib_command load_cmd;
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    uint32_t version_cmd = 0;
+    uint64_t version = 0;
+    uint32_t i;
+    for (i = 0; i < m_header.ncmds; ++i) {
+      const lldb::offset_t cmd_offset = offset;
+      if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+        break;
+
+      if (load_cmd.cmd == LC_ID_DYLIB) {
+        if (version_cmd == 0) {
+          version_cmd = load_cmd.cmd;
+          if (m_data.GetU32(&offset, &load_cmd.dylib, 4) == NULL)
+            break;
+          version = load_cmd.dylib.current_version;
         }
-        
-        if (success == false)
-        {
-            // Push an invalid value so we don't keep trying to
-            m_min_os_versions.push_back(UINT32_MAX);
+        break; // Break for now unless there is another more complete version
+               // number load command in the future.
+      }
+      offset = cmd_offset + load_cmd.cmdsize;
+    }
+
+    if (version_cmd == LC_ID_DYLIB) {
+      if (versions != NULL && num_versions > 0) {
+        if (num_versions > 0)
+          versions[0] = (version & 0xFFFF0000ull) >> 16;
+        if (num_versions > 1)
+          versions[1] = (version & 0x0000FF00ull) >> 8;
+        if (num_versions > 2)
+          versions[2] = (version & 0x000000FFull);
+        // Fill in an remaining version numbers with invalid values
+        for (i = 3; i < num_versions; ++i)
+          versions[i] = UINT32_MAX;
+      }
+      // The LC_ID_DYLIB load command has a version with 3 version numbers
+      // in it, so always return 3
+      return 3;
+    }
+  }
+  return false;
+}
+
+bool ObjectFileMachO::GetArchitecture(ArchSpec &arch) {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    return GetArchitecture(m_header, m_data,
+                           MachHeaderSizeFromMagic(m_header.magic), arch);
+  }
+  return false;
+}
+
+UUID ObjectFileMachO::GetProcessSharedCacheUUID(Process *process) {
+  UUID uuid;
+  if (process && process->GetDynamicLoader()) {
+    DynamicLoader *dl = process->GetDynamicLoader();
+    addr_t load_address;
+    LazyBool using_shared_cache;
+    LazyBool private_shared_cache;
+    dl->GetSharedCacheInformation(load_address, uuid, using_shared_cache,
+                                  private_shared_cache);
+  }
+  return uuid;
+}
+
+UUID ObjectFileMachO::GetLLDBSharedCacheUUID() {
+  UUID uuid;
+#if defined(__APPLE__) &&                                                      \
+    (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
+  uint8_t *(*dyld_get_all_image_infos)(void);
+  dyld_get_all_image_infos =
+      (uint8_t * (*)())dlsym(RTLD_DEFAULT, "_dyld_get_all_image_infos");
+  if (dyld_get_all_image_infos) {
+    uint8_t *dyld_all_image_infos_address = dyld_get_all_image_infos();
+    if (dyld_all_image_infos_address) {
+      uint32_t *version = (uint32_t *)
+          dyld_all_image_infos_address; // version <mach-o/dyld_images.h>
+      if (*version >= 13) {
+        uuid_t *sharedCacheUUID_address = 0;
+        int wordsize = sizeof(uint8_t *);
+        if (wordsize == 8) {
+          sharedCacheUUID_address =
+              (uuid_t *)((uint8_t *)dyld_all_image_infos_address +
+                         160); // sharedCacheUUID <mach-o/dyld_images.h>
+        } else {
+          sharedCacheUUID_address =
+              (uuid_t *)((uint8_t *)dyld_all_image_infos_address +
+                         84); // sharedCacheUUID <mach-o/dyld_images.h>
         }
+        uuid.SetBytes(sharedCacheUUID_address);
+      }
     }
-    
-    if (m_min_os_versions.size() > 1 || m_min_os_versions[0] != UINT32_MAX)
-    {
-        if (versions != NULL && num_versions > 0)
-        {
-            for (size_t i=0; i<num_versions; ++i)
-            {
-                if (i < m_min_os_versions.size())
-                    versions[i] = m_min_os_versions[i];
-                else
-                    versions[i] = 0;
-            }
-        }
-        return m_min_os_versions.size();
-    }
-    // Call the superclasses version that will empty out the data
-    return ObjectFile::GetMinimumOSVersion (versions, num_versions);
-}
-
-uint32_t
-ObjectFileMachO::GetSDKVersion(uint32_t *versions, uint32_t num_versions)
-{
-    if (m_sdk_versions.empty())
-    {
-        lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-        bool success = false;
-        for (uint32_t i=0; success == false && i < m_header.ncmds; ++i)
-        {
-            const lldb::offset_t load_cmd_offset = offset;
-            
-            version_min_command lc;
-            if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
-                break;
-            if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX 
-                || lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS
-                || lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS
-                || lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS)
-            {
-                if (m_data.GetU32 (&offset, &lc.version, (sizeof(lc) / sizeof(uint32_t)) - 2))
-                {
-                    const uint32_t xxxx = lc.sdk >> 16;
-                    const uint32_t yy = (lc.sdk >> 8) & 0xffu;
-                    const uint32_t zz = lc.sdk & 0xffu;
-                    if (xxxx)
-                    {
-                        m_sdk_versions.push_back(xxxx);
-                        m_sdk_versions.push_back(yy);
-                        m_sdk_versions.push_back(zz);
-                    }
-                    success = true;
-                }
-            }
-            offset = load_cmd_offset + lc.cmdsize;
-        }
-        
-        if (success == false)
-        {
-            // Push an invalid value so we don't keep trying to
-            m_sdk_versions.push_back(UINT32_MAX);
-        }
+  }
+#endif
+  return uuid;
+}
+
+uint32_t ObjectFileMachO::GetMinimumOSVersion(uint32_t *versions,
+                                              uint32_t num_versions) {
+  if (m_min_os_versions.empty()) {
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    bool success = false;
+    for (uint32_t i = 0; success == false && i < m_header.ncmds; ++i) {
+      const lldb::offset_t load_cmd_offset = offset;
+
+      version_min_command lc;
+      if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
+        break;
+      if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX ||
+          lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS ||
+          lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS ||
+          lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS) {
+        if (m_data.GetU32(&offset, &lc.version,
+                          (sizeof(lc) / sizeof(uint32_t)) - 2)) {
+          const uint32_t xxxx = lc.version >> 16;
+          const uint32_t yy = (lc.version >> 8) & 0xffu;
+          const uint32_t zz = lc.version & 0xffu;
+          if (xxxx) {
+            m_min_os_versions.push_back(xxxx);
+            m_min_os_versions.push_back(yy);
+            m_min_os_versions.push_back(zz);
+          }
+          success = true;
+        }
+      }
+      offset = load_cmd_offset + lc.cmdsize;
+    }
+
+    if (success == false) {
+      // Push an invalid value so we don't keep trying to
+      m_min_os_versions.push_back(UINT32_MAX);
+    }
+  }
+
+  if (m_min_os_versions.size() > 1 || m_min_os_versions[0] != UINT32_MAX) {
+    if (versions != NULL && num_versions > 0) {
+      for (size_t i = 0; i < num_versions; ++i) {
+        if (i < m_min_os_versions.size())
+          versions[i] = m_min_os_versions[i];
+        else
+          versions[i] = 0;
+      }
     }
-    
-    if (m_sdk_versions.size() > 1 || m_sdk_versions[0] != UINT32_MAX)
-    {
-        if (versions != NULL && num_versions > 0)
-        {
-            for (size_t i=0; i<num_versions; ++i)
-            {
-                if (i < m_sdk_versions.size())
-                    versions[i] = m_sdk_versions[i];
-                else
-                    versions[i] = 0;
-            }
-        }
-        return m_sdk_versions.size();
+    return m_min_os_versions.size();
+  }
+  // Call the superclasses version that will empty out the data
+  return ObjectFile::GetMinimumOSVersion(versions, num_versions);
+}
+
+uint32_t ObjectFileMachO::GetSDKVersion(uint32_t *versions,
+                                        uint32_t num_versions) {
+  if (m_sdk_versions.empty()) {
+    lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+    bool success = false;
+    for (uint32_t i = 0; success == false && i < m_header.ncmds; ++i) {
+      const lldb::offset_t load_cmd_offset = offset;
+
+      version_min_command lc;
+      if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
+        break;
+      if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX ||
+          lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS ||
+          lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS ||
+          lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS) {
+        if (m_data.GetU32(&offset, &lc.version,
+                          (sizeof(lc) / sizeof(uint32_t)) - 2)) {
+          const uint32_t xxxx = lc.sdk >> 16;
+          const uint32_t yy = (lc.sdk >> 8) & 0xffu;
+          const uint32_t zz = lc.sdk & 0xffu;
+          if (xxxx) {
+            m_sdk_versions.push_back(xxxx);
+            m_sdk_versions.push_back(yy);
+            m_sdk_versions.push_back(zz);
+          }
+          success = true;
+        }
+      }
+      offset = load_cmd_offset + lc.cmdsize;
+    }
+
+    if (success == false) {
+      // Push an invalid value so we don't keep trying to
+      m_sdk_versions.push_back(UINT32_MAX);
+    }
+  }
+
+  if (m_sdk_versions.size() > 1 || m_sdk_versions[0] != UINT32_MAX) {
+    if (versions != NULL && num_versions > 0) {
+      for (size_t i = 0; i < num_versions; ++i) {
+        if (i < m_sdk_versions.size())
+          versions[i] = m_sdk_versions[i];
+        else
+          versions[i] = 0;
+      }
     }
-    // Call the superclasses version that will empty out the data
-    return ObjectFile::GetSDKVersion (versions, num_versions);
+    return m_sdk_versions.size();
+  }
+  // Call the superclasses version that will empty out the data
+  return ObjectFile::GetSDKVersion(versions, num_versions);
 }
 
-bool
-ObjectFileMachO::GetIsDynamicLinkEditor()
-{
-    return m_header.filetype == llvm::MachO::MH_DYLINKER;
+bool ObjectFileMachO::GetIsDynamicLinkEditor() {
+  return m_header.filetype == llvm::MachO::MH_DYLINKER;
 }
 
-bool
-ObjectFileMachO::AllowAssemblyEmulationUnwindPlans ()
-{
-    return m_allow_assembly_emulation_unwind_plans;
+bool ObjectFileMachO::AllowAssemblyEmulationUnwindPlans() {
+  return m_allow_assembly_emulation_unwind_plans;
 }
 
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
-lldb_private::ConstString
-ObjectFileMachO::GetPluginName()
-{
-    return GetPluginNameStatic();
-}
-
-uint32_t
-ObjectFileMachO::GetPluginVersion()
-{
-    return 1;
-}
-
-Section *
-ObjectFileMachO::GetMachHeaderSection()
-{
-    // Find the first address of the mach header which is the first non-zero
-    // file sized section whose file offset is zero. This is the base file address
-    // of the mach-o file which can be subtracted from the vmaddr of the other
-    // segments found in memory and added to the load address
-    ModuleSP module_sp = GetModule();
-    if (module_sp)
-    {
-        SectionList *section_list = GetSectionList ();
-        if (section_list)
-        {
-            lldb::addr_t mach_base_file_addr = LLDB_INVALID_ADDRESS;
-            const size_t num_sections = section_list->GetSize();
-
-            for (size_t sect_idx = 0;
-                 sect_idx < num_sections && mach_base_file_addr == LLDB_INVALID_ADDRESS;
-                 ++sect_idx)
-            {
-                Section *section = section_list->GetSectionAtIndex (sect_idx).get();
-                if (section &&
-                    section->GetFileSize() > 0 &&
-                    section->GetFileOffset() == 0 &&
-                    section->IsThreadSpecific() == false &&
-                    module_sp.get() == section->GetModule().get())
-                {
-                    return section;
-                }
-            }
-        }
-    }
-    return nullptr;
-}
-
-lldb::addr_t
-ObjectFileMachO::CalculateSectionLoadAddressForMemoryImage(lldb::addr_t mach_header_load_address, const Section *mach_header_section, const Section *section)
-{
-    ModuleSP module_sp = GetModule();
-    if (module_sp && mach_header_section && section && mach_header_load_address != LLDB_INVALID_ADDRESS)
-    {
-        lldb::addr_t mach_header_file_addr = mach_header_section->GetFileAddress();
-        if (mach_header_file_addr != LLDB_INVALID_ADDRESS)
-        {
-            if (section &&
-                section->GetFileSize() > 0 &&
-                section->IsThreadSpecific() == false &&
-                module_sp.get() == section->GetModule().get())
-            {
-                // Ignore __LINKEDIT and __DWARF segments
-                if (section->GetName() == GetSegmentNameLINKEDIT())
-                {
-                    // Only map __LINKEDIT if we have an in memory image and this isn't
-                    // a kernel binary like a kext or mach_kernel.
-                    const bool is_memory_image = (bool)m_process_wp.lock();
-                    const Strata strata = GetStrata();
-                    if (is_memory_image == false || strata == eStrataKernel)
-                        return LLDB_INVALID_ADDRESS;
-                }
-                return section->GetFileAddress() - mach_header_file_addr + mach_header_load_address;
-            }
-        }
-    }
-    return LLDB_INVALID_ADDRESS;
+lldb_private::ConstString ObjectFileMachO::GetPluginName() {
+  return GetPluginNameStatic();
 }
 
-bool
-ObjectFileMachO::SetLoadAddress (Target &target,
-                                 lldb::addr_t value,
-                                 bool value_is_offset)
-{
-    ModuleSP module_sp = GetModule();
-    if (module_sp)
-    {
-        size_t num_loaded_sections = 0;
-        SectionList *section_list = GetSectionList ();
-        if (section_list)
-        {
-            const size_t num_sections = section_list->GetSize();
-
-            if (value_is_offset)
-            {
-                // "value" is an offset to apply to each top level segment
-                for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
-                {
-                    // Iterate through the object file sections to find all
-                    // of the sections that size on disk (to avoid __PAGEZERO)
-                    // and load them
-                    SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
-                    if (section_sp &&
-                        section_sp->GetFileSize() > 0 &&
-                        section_sp->IsThreadSpecific() == false &&
-                        module_sp.get() == section_sp->GetModule().get())
-                    {
-                        // Ignore __LINKEDIT and __DWARF segments
-                        if (section_sp->GetName() == GetSegmentNameLINKEDIT())
-                        {
-                            // Only map __LINKEDIT if we have an in memory image and this isn't
-                            // a kernel binary like a kext or mach_kernel.
-                            const bool is_memory_image = (bool)m_process_wp.lock();
-                            const Strata strata = GetStrata();
-                            if (is_memory_image == false || strata == eStrataKernel)
-                                continue;
-                        }
-                        if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
-                            ++num_loaded_sections;
-                    }
-                }
-            }
-            else
-            {
-                // "value" is the new base address of the mach_header, adjust each
-                // section accordingly
-
-                Section *mach_header_section = GetMachHeaderSection();
-                if (mach_header_section)
-                {
-                    for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
-                    {
-                        SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
+uint32_t ObjectFileMachO::GetPluginVersion() { return 1; }
 
-                        lldb::addr_t section_load_addr = CalculateSectionLoadAddressForMemoryImage(value, mach_header_section, section_sp.get());
-                        if (section_load_addr != LLDB_INVALID_ADDRESS)
-                        {
-                            if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_load_addr))
-                                ++num_loaded_sections;
-                        }
-                    }
-                }
-            }
-        }
-        return num_loaded_sections > 0;
-    }
-    return false;
-}
+Section *ObjectFileMachO::GetMachHeaderSection() {
+  // Find the first address of the mach header which is the first non-zero
+  // file sized section whose file offset is zero. This is the base file address
+  // of the mach-o file which can be subtracted from the vmaddr of the other
+  // segments found in memory and added to the load address
+  ModuleSP module_sp = GetModule();
+  if (module_sp) {
+    SectionList *section_list = GetSectionList();
+    if (section_list) {
+      lldb::addr_t mach_base_file_addr = LLDB_INVALID_ADDRESS;
+      const size_t num_sections = section_list->GetSize();
+
+      for (size_t sect_idx = 0; sect_idx < num_sections &&
+                                mach_base_file_addr == LLDB_INVALID_ADDRESS;
+           ++sect_idx) {
+        Section *section = section_list->GetSectionAtIndex(sect_idx).get();
+        if (section && section->GetFileSize() > 0 &&
+            section->GetFileOffset() == 0 &&
+            section->IsThreadSpecific() == false &&
+            module_sp.get() == section->GetModule().get()) {
+          return section;
+        }
+      }
+    }
+  }
+  return nullptr;
+}
+
+lldb::addr_t ObjectFileMachO::CalculateSectionLoadAddressForMemoryImage(
+    lldb::addr_t mach_header_load_address, const Section *mach_header_section,
+    const Section *section) {
+  ModuleSP module_sp = GetModule();
+  if (module_sp && mach_header_section && section &&
+      mach_header_load_address != LLDB_INVALID_ADDRESS) {
+    lldb::addr_t mach_header_file_addr = mach_header_section->GetFileAddress();
+    if (mach_header_file_addr != LLDB_INVALID_ADDRESS) {
+      if (section && section->GetFileSize() > 0 &&
+          section->IsThreadSpecific() == false &&
+          module_sp.get() == section->GetModule().get()) {
+        // Ignore __LINKEDIT and __DWARF segments
+        if (section->GetName() == GetSegmentNameLINKEDIT()) {
+          // Only map __LINKEDIT if we have an in memory image and this isn't
+          // a kernel binary like a kext or mach_kernel.
+          const bool is_memory_image = (bool)m_process_wp.lock();
+          const Strata strata = GetStrata();
+          if (is_memory_image == false || strata == eStrataKernel)
+            return LLDB_INVALID_ADDRESS;
+        }
+        return section->GetFileAddress() - mach_header_file_addr +
+               mach_header_load_address;
+      }
+    }
+  }
+  return LLDB_INVALID_ADDRESS;
+}
+
+bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
+                                     bool value_is_offset) {
+  ModuleSP module_sp = GetModule();
+  if (module_sp) {
+    size_t num_loaded_sections = 0;
+    SectionList *section_list = GetSectionList();
+    if (section_list) {
+      const size_t num_sections = section_list->GetSize();
 
-bool
-ObjectFileMachO::SaveCore (const lldb::ProcessSP &process_sp,
-                           const FileSpec &outfile,
-                           Error &error)
-{
-    if (process_sp)
-    {
-        Target &target = process_sp->GetTarget();
-        const ArchSpec target_arch = target.GetArchitecture();
-        const llvm::Triple &target_triple = target_arch.GetTriple();
-        if (target_triple.getVendor() == llvm::Triple::Apple &&
-            (target_triple.getOS() == llvm::Triple::MacOSX 
-             || target_triple.getOS() == llvm::Triple::IOS
-             || target_triple.getOS() == llvm::Triple::WatchOS
-             || target_triple.getOS() == llvm::Triple::TvOS))
-        {
-            bool make_core = false;
-            switch (target_arch.GetMachine())
-            {
-                case llvm::Triple::aarch64:
-                case llvm::Triple::arm:
-                case llvm::Triple::thumb:
-                case llvm::Triple::x86:
-                case llvm::Triple::x86_64:
-                    make_core = true;
-                    break;
-                default:
-                    error.SetErrorStringWithFormat ("unsupported core architecture: %s", target_triple.str().c_str());
-                    break;
+      if (value_is_offset) {
+        // "value" is an offset to apply to each top level segment
+        for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
+          // Iterate through the object file sections to find all
+          // of the sections that size on disk (to avoid __PAGEZERO)
+          // and load them
+          SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
+          if (section_sp && section_sp->GetFileSize() > 0 &&
+              section_sp->IsThreadSpecific() == false &&
+              module_sp.get() == section_sp->GetModule().get()) {
+            // Ignore __LINKEDIT and __DWARF segments
+            if (section_sp->GetName() == GetSegmentNameLINKEDIT()) {
+              // Only map __LINKEDIT if we have an in memory image and this
+              // isn't
+              // a kernel binary like a kext or mach_kernel.
+              const bool is_memory_image = (bool)m_process_wp.lock();
+              const Strata strata = GetStrata();
+              if (is_memory_image == false || strata == eStrataKernel)
+                continue;
+            }
+            if (target.GetSectionLoadList().SetSectionLoadAddress(
+                    section_sp, section_sp->GetFileAddress() + value))
+              ++num_loaded_sections;
+          }
+        }
+      } else {
+        // "value" is the new base address of the mach_header, adjust each
+        // section accordingly
+
+        Section *mach_header_section = GetMachHeaderSection();
+        if (mach_header_section) {
+          for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
+            SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
+
+            lldb::addr_t section_load_addr =
+                CalculateSectionLoadAddressForMemoryImage(
+                    value, mach_header_section, section_sp.get());
+            if (section_load_addr != LLDB_INVALID_ADDRESS) {
+              if (target.GetSectionLoadList().SetSectionLoadAddress(
+                      section_sp, section_load_addr))
+                ++num_loaded_sections;
+            }
+          }
+        }
+      }
+    }
+    return num_loaded_sections > 0;
+  }
+  return false;
+}
+
+bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
+                               const FileSpec &outfile, Error &error) {
+  if (process_sp) {
+    Target &target = process_sp->GetTarget();
+    const ArchSpec target_arch = target.GetArchitecture();
+    const llvm::Triple &target_triple = target_arch.GetTriple();
+    if (target_triple.getVendor() == llvm::Triple::Apple &&
+        (target_triple.getOS() == llvm::Triple::MacOSX ||
+         target_triple.getOS() == llvm::Triple::IOS ||
+         target_triple.getOS() == llvm::Triple::WatchOS ||
+         target_triple.getOS() == llvm::Triple::TvOS)) {
+      bool make_core = false;
+      switch (target_arch.GetMachine()) {
+      case llvm::Triple::aarch64:
+      case llvm::Triple::arm:
+      case llvm::Triple::thumb:
+      case llvm::Triple::x86:
+      case llvm::Triple::x86_64:
+        make_core = true;
+        break;
+      default:
+        error.SetErrorStringWithFormat("unsupported core architecture: %s",
+                                       target_triple.str().c_str());
+        break;
+      }
+
+      if (make_core) {
+        std::vector<segment_command_64> segment_load_commands;
+        //                uint32_t range_info_idx = 0;
+        MemoryRegionInfo range_info;
+        Error range_error = process_sp->GetMemoryRegionInfo(0, range_info);
+        const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
+        const ByteOrder byte_order = target_arch.GetByteOrder();
+        if (range_error.Success()) {
+          while (range_info.GetRange().GetRangeBase() != LLDB_INVALID_ADDRESS) {
+            const addr_t addr = range_info.GetRange().GetRangeBase();
+            const addr_t size = range_info.GetRange().GetByteSize();
+
+            if (size == 0)
+              break;
+
+            // Calculate correct protections
+            uint32_t prot = 0;
+            if (range_info.GetReadable() == MemoryRegionInfo::eYes)
+              prot |= VM_PROT_READ;
+            if (range_info.GetWritable() == MemoryRegionInfo::eYes)
+              prot |= VM_PROT_WRITE;
+            if (range_info.GetExecutable() == MemoryRegionInfo::eYes)
+              prot |= VM_PROT_EXECUTE;
+
+            //                        printf ("[%3u] [0x%16.16" PRIx64 " -
+            //                        0x%16.16" PRIx64 ") %c%c%c\n",
+            //                                range_info_idx,
+            //                                addr,
+            //                                size,
+            //                                (prot & VM_PROT_READ   ) ? 'r' :
+            //                                '-',
+            //                                (prot & VM_PROT_WRITE  ) ? 'w' :
+            //                                '-',
+            //                                (prot & VM_PROT_EXECUTE) ? 'x' :
+            //                                '-');
+
+            if (prot != 0) {
+              uint32_t cmd_type = LC_SEGMENT_64;
+              uint32_t segment_size = sizeof(segment_command_64);
+              if (addr_byte_size == 4) {
+                cmd_type = LC_SEGMENT;
+                segment_size = sizeof(segment_command);
+              }
+              segment_command_64 segment = {
+                  cmd_type,     // uint32_t cmd;
+                  segment_size, // uint32_t cmdsize;
+                  {0},          // char segname[16];
+                  addr, // uint64_t vmaddr;    // uint32_t for 32-bit Mach-O
+                  size, // uint64_t vmsize;    // uint32_t for 32-bit Mach-O
+                  0,    // uint64_t fileoff;   // uint32_t for 32-bit Mach-O
+                  size, // uint64_t filesize;  // uint32_t for 32-bit Mach-O
+                  prot, // uint32_t maxprot;
+                  prot, // uint32_t initprot;
+                  0,    // uint32_t nsects;
+                  0};   // uint32_t flags;
+              segment_load_commands.push_back(segment);
+            } else {
+              // No protections and a size of 1 used to be returned from old
+              // debugservers when we asked about a region that was past the
+              // last memory region and it indicates the end...
+              if (size == 1)
+                break;
             }
-            
-            if (make_core)
-            {
-                std::vector<segment_command_64> segment_load_commands;
-//                uint32_t range_info_idx = 0;
-                MemoryRegionInfo range_info;
-                Error range_error = process_sp->GetMemoryRegionInfo(0, range_info);
-                const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
-                const ByteOrder byte_order = target_arch.GetByteOrder();
-                if (range_error.Success())
-                {
-                    while (range_info.GetRange().GetRangeBase() != LLDB_INVALID_ADDRESS)
-                    {
-                        const addr_t addr = range_info.GetRange().GetRangeBase();
-                        const addr_t size = range_info.GetRange().GetByteSize();
-
-                        if (size == 0)
-                            break;
 
-                        // Calculate correct protections
-                        uint32_t prot = 0;
-                        if (range_info.GetReadable() == MemoryRegionInfo::eYes)
-                            prot |= VM_PROT_READ;
-                        if (range_info.GetWritable() == MemoryRegionInfo::eYes)
-                            prot |= VM_PROT_WRITE;
-                        if (range_info.GetExecutable() == MemoryRegionInfo::eYes)
-                            prot |= VM_PROT_EXECUTE;
-
-//                        printf ("[%3u] [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") %c%c%c\n",
-//                                range_info_idx,
-//                                addr,
-//                                size,
-//                                (prot & VM_PROT_READ   ) ? 'r' : '-',
-//                                (prot & VM_PROT_WRITE  ) ? 'w' : '-',
-//                                (prot & VM_PROT_EXECUTE) ? 'x' : '-');
-
-                        if (prot != 0)
-                        {
-                            uint32_t cmd_type = LC_SEGMENT_64;
-                            uint32_t segment_size = sizeof (segment_command_64);
-                            if (addr_byte_size == 4)
-                            {
-                                cmd_type = LC_SEGMENT;
-                                segment_size = sizeof (segment_command);
-                            }
-                            segment_command_64 segment = {
-                                cmd_type,           // uint32_t cmd;
-                                segment_size,       // uint32_t cmdsize;
-                                {0},                // char segname[16];
-                                addr,               // uint64_t vmaddr;    // uint32_t for 32-bit Mach-O
-                                size,               // uint64_t vmsize;    // uint32_t for 32-bit Mach-O
-                                0,                  // uint64_t fileoff;   // uint32_t for 32-bit Mach-O
-                                size,               // uint64_t filesize;  // uint32_t for 32-bit Mach-O
-                                prot,               // uint32_t maxprot;
-                                prot,               // uint32_t initprot;
-                                0,                  // uint32_t nsects;
-                                0 };                // uint32_t flags;
-                            segment_load_commands.push_back(segment);
-                        }
-                        else
-                        {
-                            // No protections and a size of 1 used to be returned from old
-                            // debugservers when we asked about a region that was past the
-                            // last memory region and it indicates the end...
-                            if (size == 1)
-                                break;
-                        }
-                        
-                        range_error = process_sp->GetMemoryRegionInfo(range_info.GetRange().GetRangeEnd(), range_info);
-                        if (range_error.Fail())
-                            break;
-                    }
-                    
-                    StreamString buffer (Stream::eBinary,
-                                         addr_byte_size,
-                                         byte_order);
+            range_error = process_sp->GetMemoryRegionInfo(
+                range_info.GetRange().GetRangeEnd(), range_info);
+            if (range_error.Fail())
+              break;
+          }
+
+          StreamString buffer(Stream::eBinary, addr_byte_size, byte_order);
+
+          mach_header_64 mach_header;
+          if (addr_byte_size == 8) {
+            mach_header.magic = MH_MAGIC_64;
+          } else {
+            mach_header.magic = MH_MAGIC;
+          }
+          mach_header.cputype = target_arch.GetMachOCPUType();
+          mach_header.cpusubtype = target_arch.GetMachOCPUSubType();
+          mach_header.filetype = MH_CORE;
+          mach_header.ncmds = segment_load_commands.size();
+          mach_header.flags = 0;
+          mach_header.reserved = 0;
+          ThreadList &thread_list = process_sp->GetThreadList();
+          const uint32_t num_threads = thread_list.GetSize();
+
+          // Make an array of LC_THREAD data items. Each one contains
+          // the contents of the LC_THREAD load command. The data doesn't
+          // contain the load command + load command size, we will
+          // add the load command and load command size as we emit the data.
+          std::vector<StreamString> LC_THREAD_datas(num_threads);
+          for (auto &LC_THREAD_data : LC_THREAD_datas) {
+            LC_THREAD_data.GetFlags().Set(Stream::eBinary);
+            LC_THREAD_data.SetAddressByteSize(addr_byte_size);
+            LC_THREAD_data.SetByteOrder(byte_order);
+          }
+          for (uint32_t thread_idx = 0; thread_idx < num_threads;
+               ++thread_idx) {
+            ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));
+            if (thread_sp) {
+              switch (mach_header.cputype) {
+              case llvm::MachO::CPU_TYPE_ARM64:
+                RegisterContextDarwin_arm64_Mach::Create_LC_THREAD(
+                    thread_sp.get(), LC_THREAD_datas[thread_idx]);
+                break;
 
-                    mach_header_64 mach_header;
-                    if (addr_byte_size == 8)
-                    {
-                        mach_header.magic = MH_MAGIC_64;
-                    }
-                    else
-                    {
-                        mach_header.magic = MH_MAGIC;
-                    }
-                    mach_header.cputype = target_arch.GetMachOCPUType();
-                    mach_header.cpusubtype = target_arch.GetMachOCPUSubType();
-                    mach_header.filetype = MH_CORE;
-                    mach_header.ncmds = segment_load_commands.size();
-                    mach_header.flags = 0;
-                    mach_header.reserved = 0;
-                    ThreadList &thread_list = process_sp->GetThreadList();
-                    const uint32_t num_threads = thread_list.GetSize();
-
-                    // Make an array of LC_THREAD data items. Each one contains
-                    // the contents of the LC_THREAD load command. The data doesn't
-                    // contain the load command + load command size, we will
-                    // add the load command and load command size as we emit the data.
-                    std::vector<StreamString> LC_THREAD_datas(num_threads);
-                    for (auto &LC_THREAD_data : LC_THREAD_datas)
-                    {
-                        LC_THREAD_data.GetFlags().Set(Stream::eBinary);
-                        LC_THREAD_data.SetAddressByteSize(addr_byte_size);
-                        LC_THREAD_data.SetByteOrder(byte_order);
-                    }
-                    for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx)
-                    {
-                        ThreadSP thread_sp (thread_list.GetThreadAtIndex(thread_idx));
-                        if (thread_sp)
-                        {
-                            switch (mach_header.cputype)
-                            {
-                                case llvm::MachO::CPU_TYPE_ARM64:
-                                    RegisterContextDarwin_arm64_Mach::Create_LC_THREAD (thread_sp.get(), LC_THREAD_datas[thread_idx]);
-                                    break;
-
-                                case llvm::MachO::CPU_TYPE_ARM:
-                                    RegisterContextDarwin_arm_Mach::Create_LC_THREAD (thread_sp.get(), LC_THREAD_datas[thread_idx]);
-                                    break;
-
-                                case llvm::MachO::CPU_TYPE_I386:
-                                    RegisterContextDarwin_i386_Mach::Create_LC_THREAD (thread_sp.get(), LC_THREAD_datas[thread_idx]);
-                                    break;
-                                    
-                                case llvm::MachO::CPU_TYPE_X86_64:
-                                    RegisterContextDarwin_x86_64_Mach::Create_LC_THREAD (thread_sp.get(), LC_THREAD_datas[thread_idx]);
-                                    break;
-                            }
-                            
-                        }
-                    }
-                    
-                    // The size of the load command is the size of the segments...
-                    if (addr_byte_size == 8)
-                    {
-                        mach_header.sizeofcmds = segment_load_commands.size() * sizeof (struct segment_command_64);
-                    }
-                    else
-                    {
-                        mach_header.sizeofcmds = segment_load_commands.size() * sizeof (struct segment_command);
-                    }
-                    
-                    // and the size of all LC_THREAD load command
-                    for (const auto &LC_THREAD_data : LC_THREAD_datas)
-                    {
-                        ++mach_header.ncmds;
-                        mach_header.sizeofcmds += 8 + LC_THREAD_data.GetSize();
-                    }
+              case llvm::MachO::CPU_TYPE_ARM:
+                RegisterContextDarwin_arm_Mach::Create_LC_THREAD(
+                    thread_sp.get(), LC_THREAD_datas[thread_idx]);
+                break;
 
-                    printf ("mach_header: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x\n",
-                            mach_header.magic,
-                            mach_header.cputype,
-                            mach_header.cpusubtype,
-                            mach_header.filetype,
-                            mach_header.ncmds,
-                            mach_header.sizeofcmds,
-                            mach_header.flags,
-                            mach_header.reserved);
-
-                    // Write the mach header
-                    buffer.PutHex32(mach_header.magic);
-                    buffer.PutHex32(mach_header.cputype);
-                    buffer.PutHex32(mach_header.cpusubtype);
-                    buffer.PutHex32(mach_header.filetype);
-                    buffer.PutHex32(mach_header.ncmds);
-                    buffer.PutHex32(mach_header.sizeofcmds);
-                    buffer.PutHex32(mach_header.flags);
-                    if (addr_byte_size == 8)
-                    {
-                        buffer.PutHex32(mach_header.reserved);
-                    }
-                    
-                    // Skip the mach header and all load commands and align to the next
-                    // 0x1000 byte boundary
-                    addr_t file_offset = buffer.GetSize() + mach_header.sizeofcmds;
-                    if (file_offset & 0x00000fff)
-                    {
-                        file_offset += 0x00001000ull;
-                        file_offset &= (~0x00001000ull + 1);
-                    }
-                    
-                    for (auto &segment : segment_load_commands)
-                    {
-                        segment.fileoff = file_offset;
-                        file_offset += segment.filesize;
-                    }
-                    
-                    // Write out all of the LC_THREAD load commands
-                    for (const auto &LC_THREAD_data : LC_THREAD_datas)
-                    {
-                        const size_t LC_THREAD_data_size = LC_THREAD_data.GetSize();
-                        buffer.PutHex32(LC_THREAD);
-                        buffer.PutHex32(8 + LC_THREAD_data_size); // cmd + cmdsize + data
-                        buffer.Write(LC_THREAD_data.GetData(), LC_THREAD_data_size);
-                    }
+              case llvm::MachO::CPU_TYPE_I386:
+                RegisterContextDarwin_i386_Mach::Create_LC_THREAD(
+                    thread_sp.get(), LC_THREAD_datas[thread_idx]);
+                break;
 
-                    // Write out all of the segment load commands
-                    for (const auto &segment : segment_load_commands)
-                    {
-                        printf ("0x%8.8x 0x%8.8x [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") [0x%16.16" PRIx64 " 0x%16.16" PRIx64 ") 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x]\n",
-                                segment.cmd,
-                                segment.cmdsize,
-                                segment.vmaddr,
-                                segment.vmaddr + segment.vmsize,
-                                segment.fileoff,
-                                segment.filesize,
-                                segment.maxprot,
-                                segment.initprot,
-                                segment.nsects,
-                                segment.flags);
-                        
-                        buffer.PutHex32(segment.cmd);
-                        buffer.PutHex32(segment.cmdsize);
-                        buffer.PutRawBytes(segment.segname, sizeof(segment.segname));
-                        if (addr_byte_size == 8)
-                        {
-                            buffer.PutHex64(segment.vmaddr);
-                            buffer.PutHex64(segment.vmsize);
-                            buffer.PutHex64(segment.fileoff);
-                            buffer.PutHex64(segment.filesize);
-                        }
-                        else
-                        {
-                            buffer.PutHex32(static_cast<uint32_t>(segment.vmaddr));
-                            buffer.PutHex32(static_cast<uint32_t>(segment.vmsize));
-                            buffer.PutHex32(static_cast<uint32_t>(segment.fileoff));
-                            buffer.PutHex32(static_cast<uint32_t>(segment.filesize));
-                        }
-                        buffer.PutHex32(segment.maxprot);
-                        buffer.PutHex32(segment.initprot);
-                        buffer.PutHex32(segment.nsects);
-                        buffer.PutHex32(segment.flags);
-                    }
-                    
-                    File core_file;
-                    std::string core_file_path(outfile.GetPath());
-                    error = core_file.Open(core_file_path.c_str(),
-                                           File::eOpenOptionWrite    |
-                                           File::eOpenOptionTruncate |
-                                           File::eOpenOptionCanCreate);
-                    if (error.Success())
-                    {
-                        // Read 1 page at a time
-                        uint8_t bytes[0x1000];
-                        // Write the mach header and load commands out to the core file
-                        size_t bytes_written = buffer.GetString().size();
-                        error = core_file.Write(buffer.GetString().data(), bytes_written);
-                        if (error.Success())
-                        {
-                            // Now write the file data for all memory segments in the process
-                            for (const auto &segment : segment_load_commands)
-                            {
-                                if (core_file.SeekFromStart(segment.fileoff) == -1)
-                                {
-                                    error.SetErrorStringWithFormat("unable to seek to offset 0x%" PRIx64 " in '%s'", segment.fileoff, core_file_path.c_str());
-                                    break;
-                                }
-                                
-                                printf ("Saving %" PRId64 " bytes of data for memory region at 0x%" PRIx64 "\n", segment.vmsize, segment.vmaddr);
-                                addr_t bytes_left = segment.vmsize;
-                                addr_t addr = segment.vmaddr;
-                                Error memory_read_error;
-                                while (bytes_left > 0 && error.Success())
-                                {
-                                    const size_t bytes_to_read = bytes_left > sizeof(bytes) ? sizeof(bytes) : bytes_left;
-                                    const size_t bytes_read = process_sp->ReadMemory(addr, bytes, bytes_to_read, memory_read_error);
-                                    if (bytes_read == bytes_to_read)
-                                    {
-                                        size_t bytes_written = bytes_read;
-                                        error = core_file.Write(bytes, bytes_written);
-                                        bytes_left -= bytes_read;
-                                        addr += bytes_read;
-                                    }
-                                    else
-                                    {
-                                        // Some pages within regions are not readable, those
-                                        // should be zero filled
-                                        memset (bytes, 0, bytes_to_read);
-                                        size_t bytes_written = bytes_to_read;
-                                        error = core_file.Write(bytes, bytes_written);
-                                        bytes_left -= bytes_to_read;
-                                        addr += bytes_to_read;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-                else
-                {
-                    error.SetErrorString("process doesn't support getting memory region info");
-                }
+              case llvm::MachO::CPU_TYPE_X86_64:
+                RegisterContextDarwin_x86_64_Mach::Create_LC_THREAD(
+                    thread_sp.get(), LC_THREAD_datas[thread_idx]);
+                break;
+              }
             }
-            return true; // This is the right plug to handle saving core files for this process
-        }
+          }
+
+          // The size of the load command is the size of the segments...
+          if (addr_byte_size == 8) {
+            mach_header.sizeofcmds = segment_load_commands.size() *
+                                     sizeof(struct segment_command_64);
+          } else {
+            mach_header.sizeofcmds =
+                segment_load_commands.size() * sizeof(struct segment_command);
+          }
+
+          // and the size of all LC_THREAD load command
+          for (const auto &LC_THREAD_data : LC_THREAD_datas) {
+            ++mach_header.ncmds;
+            mach_header.sizeofcmds += 8 + LC_THREAD_data.GetSize();
+          }
+
+          printf("mach_header: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x "
+                 "0x%8.8x 0x%8.8x\n",
+                 mach_header.magic, mach_header.cputype, mach_header.cpusubtype,
+                 mach_header.filetype, mach_header.ncmds,
+                 mach_header.sizeofcmds, mach_header.flags,
+                 mach_header.reserved);
+
+          // Write the mach header
+          buffer.PutHex32(mach_header.magic);
+          buffer.PutHex32(mach_header.cputype);
+          buffer.PutHex32(mach_header.cpusubtype);
+          buffer.PutHex32(mach_header.filetype);
+          buffer.PutHex32(mach_header.ncmds);
+          buffer.PutHex32(mach_header.sizeofcmds);
+          buffer.PutHex32(mach_header.flags);
+          if (addr_byte_size == 8) {
+            buffer.PutHex32(mach_header.reserved);
+          }
+
+          // Skip the mach header and all load commands and align to the next
+          // 0x1000 byte boundary
+          addr_t file_offset = buffer.GetSize() + mach_header.sizeofcmds;
+          if (file_offset & 0x00000fff) {
+            file_offset += 0x00001000ull;
+            file_offset &= (~0x00001000ull + 1);
+          }
+
+          for (auto &segment : segment_load_commands) {
+            segment.fileoff = file_offset;
+            file_offset += segment.filesize;
+          }
+
+          // Write out all of the LC_THREAD load commands
+          for (const auto &LC_THREAD_data : LC_THREAD_datas) {
+            const size_t LC_THREAD_data_size = LC_THREAD_data.GetSize();
+            buffer.PutHex32(LC_THREAD);
+            buffer.PutHex32(8 + LC_THREAD_data_size); // cmd + cmdsize + data
+            buffer.Write(LC_THREAD_data.GetData(), LC_THREAD_data_size);
+          }
+
+          // Write out all of the segment load commands
+          for (const auto &segment : segment_load_commands) {
+            printf("0x%8.8x 0x%8.8x [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
+                   ") [0x%16.16" PRIx64 " 0x%16.16" PRIx64
+                   ") 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x]\n",
+                   segment.cmd, segment.cmdsize, segment.vmaddr,
+                   segment.vmaddr + segment.vmsize, segment.fileoff,
+                   segment.filesize, segment.maxprot, segment.initprot,
+                   segment.nsects, segment.flags);
+
+            buffer.PutHex32(segment.cmd);
+            buffer.PutHex32(segment.cmdsize);
+            buffer.PutRawBytes(segment.segname, sizeof(segment.segname));
+            if (addr_byte_size == 8) {
+              buffer.PutHex64(segment.vmaddr);
+              buffer.PutHex64(segment.vmsize);
+              buffer.PutHex64(segment.fileoff);
+              buffer.PutHex64(segment.filesize);
+            } else {
+              buffer.PutHex32(static_cast<uint32_t>(segment.vmaddr));
+              buffer.PutHex32(static_cast<uint32_t>(segment.vmsize));
+              buffer.PutHex32(static_cast<uint32_t>(segment.fileoff));
+              buffer.PutHex32(static_cast<uint32_t>(segment.filesize));
+            }
+            buffer.PutHex32(segment.maxprot);
+            buffer.PutHex32(segment.initprot);
+            buffer.PutHex32(segment.nsects);
+            buffer.PutHex32(segment.flags);
+          }
+
+          File core_file;
+          std::string core_file_path(outfile.GetPath());
+          error = core_file.Open(core_file_path.c_str(),
+                                 File::eOpenOptionWrite |
+                                     File::eOpenOptionTruncate |
+                                     File::eOpenOptionCanCreate);
+          if (error.Success()) {
+            // Read 1 page at a time
+            uint8_t bytes[0x1000];
+            // Write the mach header and load commands out to the core file
+            size_t bytes_written = buffer.GetString().size();
+            error = core_file.Write(buffer.GetString().data(), bytes_written);
+            if (error.Success()) {
+              // Now write the file data for all memory segments in the process
+              for (const auto &segment : segment_load_commands) {
+                if (core_file.SeekFromStart(segment.fileoff) == -1) {
+                  error.SetErrorStringWithFormat(
+                      "unable to seek to offset 0x%" PRIx64 " in '%s'",
+                      segment.fileoff, core_file_path.c_str());
+                  break;
+                }
+
+                printf("Saving %" PRId64
+                       " bytes of data for memory region at 0x%" PRIx64 "\n",
+                       segment.vmsize, segment.vmaddr);
+                addr_t bytes_left = segment.vmsize;
+                addr_t addr = segment.vmaddr;
+                Error memory_read_error;
+                while (bytes_left > 0 && error.Success()) {
+                  const size_t bytes_to_read =
+                      bytes_left > sizeof(bytes) ? sizeof(bytes) : bytes_left;
+                  const size_t bytes_read = process_sp->ReadMemory(
+                      addr, bytes, bytes_to_read, memory_read_error);
+                  if (bytes_read == bytes_to_read) {
+                    size_t bytes_written = bytes_read;
+                    error = core_file.Write(bytes, bytes_written);
+                    bytes_left -= bytes_read;
+                    addr += bytes_read;
+                  } else {
+                    // Some pages within regions are not readable, those
+                    // should be zero filled
+                    memset(bytes, 0, bytes_to_read);
+                    size_t bytes_written = bytes_to_read;
+                    error = core_file.Write(bytes, bytes_written);
+                    bytes_left -= bytes_to_read;
+                    addr += bytes_to_read;
+                  }
+                }
+              }
+            }
+          }
+        } else {
+          error.SetErrorString(
+              "process doesn't support getting memory region info");
+        }
+      }
+      return true; // This is the right plug to handle saving core files for
+                   // this process
     }
-    return false;
+  }
+  return false;
 }

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h Tue Sep  6 15:57:50 2016
@@ -14,242 +14,192 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Utility/SafeMachO.h"
 #include "lldb/Core/Address.h"
 #include "lldb/Core/FileSpecList.h"
 #include "lldb/Core/RangeMap.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/SafeMachO.h"
 
 //----------------------------------------------------------------------
 // This class needs to be hidden as eventually belongs in a plugin that
 // will export the ObjectFile protocol
 //----------------------------------------------------------------------
-class ObjectFileMachO :
-    public lldb_private::ObjectFile
-{
+class ObjectFileMachO : public lldb_private::ObjectFile {
 public:
-    ObjectFileMachO(const lldb::ModuleSP &module_sp,
-                    lldb::DataBufferSP& data_sp,
-                    lldb::offset_t data_offset,
-                    const lldb_private::FileSpec* file,
-                    lldb::offset_t offset,
-                    lldb::offset_t length);
-
-    ObjectFileMachO(const lldb::ModuleSP &module_sp,
-                    lldb::DataBufferSP& data_sp,
-                    const lldb::ProcessSP &process_sp,
-                    lldb::addr_t header_addr);
-
-    ~ObjectFileMachO() override = default;
-
-    //------------------------------------------------------------------
-    // Static Functions
-    //------------------------------------------------------------------
-    static void
-    Initialize();
-
-    static void
-    Terminate();
-
-    static lldb_private::ConstString
-    GetPluginNameStatic();
-
-    static const char *
-    GetPluginDescriptionStatic();
-
-    static lldb_private::ObjectFile *
-    CreateInstance (const lldb::ModuleSP &module_sp,
-                    lldb::DataBufferSP& data_sp,
-                    lldb::offset_t data_offset,
-                    const lldb_private::FileSpec* file,
-                    lldb::offset_t file_offset,
-                    lldb::offset_t length);
-
-    static lldb_private::ObjectFile *
-    CreateMemoryInstance (const lldb::ModuleSP &module_sp, 
-                          lldb::DataBufferSP& data_sp, 
-                          const lldb::ProcessSP &process_sp, 
-                          lldb::addr_t header_addr);
-
-    static size_t
-    GetModuleSpecifications (const lldb_private::FileSpec& file,
-                             lldb::DataBufferSP& data_sp,
-                             lldb::offset_t data_offset,
-                             lldb::offset_t file_offset,
-                             lldb::offset_t length,
-                             lldb_private::ModuleSpecList &specs);
-
-    static bool
-    SaveCore (const lldb::ProcessSP &process_sp,
-              const lldb_private::FileSpec &outfile,
-              lldb_private::Error &error);
-
-    static bool
-    MagicBytesMatch (lldb::DataBufferSP& data_sp,
-                     lldb::addr_t offset, 
-                     lldb::addr_t length);
-
-    //------------------------------------------------------------------
-    // Member Functions
-    //------------------------------------------------------------------
-    bool
-    ParseHeader() override;
-
-    bool
-    SetLoadAddress(lldb_private::Target &target,
-                   lldb::addr_t value,
-                   bool value_is_offset) override;
-    
-    lldb::ByteOrder
-    GetByteOrder() const override;
-    
-    bool
-    IsExecutable() const override;
-
-    uint32_t
-    GetAddressByteSize() const override;
-
-    lldb::AddressClass
-    GetAddressClass(lldb::addr_t file_addr) override;
-
-    lldb_private::Symtab *
-    GetSymtab() override;
-
-    bool
-    IsStripped() override;
-    
-    void
-    CreateSections(lldb_private::SectionList &unified_section_list) override;
-
-    void
-    Dump(lldb_private::Stream *s) override;
-
-    bool
-    GetArchitecture(lldb_private::ArchSpec &arch) override;
-
-    bool
-    GetUUID(lldb_private::UUID* uuid) override;
-
-    uint32_t
-    GetDependentModules(lldb_private::FileSpecList& files) override;
-
-    lldb_private::FileSpecList
-    GetReExportedLibraries() override
-    {
-        return m_reexported_dylibs;
-    }
-
-    lldb_private::Address
-    GetEntryPointAddress() override;
-    
-    lldb_private::Address
-    GetHeaderAddress() override;
-    
-    uint32_t
-    GetNumThreadContexts() override;
-    
-    lldb::RegisterContextSP
-    GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override;
-
-    ObjectFile::Type
-    CalculateType() override;
-    
-    ObjectFile::Strata
-    CalculateStrata() override;
-
-    uint32_t
-    GetVersion(uint32_t *versions, uint32_t num_versions) override;
-
-    uint32_t
-    GetMinimumOSVersion(uint32_t *versions, uint32_t num_versions) override;
-    
-    uint32_t
-    GetSDKVersion(uint32_t *versions, uint32_t num_versions) override;
-
-    bool
-    GetIsDynamicLinkEditor() override;
-
-    static bool
-    ParseHeader (lldb_private::DataExtractor &data,
-                 lldb::offset_t *data_offset_ptr,
-                 llvm::MachO::mach_header &header);
-    
-    bool
-    AllowAssemblyEmulationUnwindPlans () override;
-
-    //------------------------------------------------------------------
-    // PluginInterface protocol
-    //------------------------------------------------------------------
-    lldb_private::ConstString
-    GetPluginName() override;
+  ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+                  lldb::offset_t data_offset,
+                  const lldb_private::FileSpec *file, lldb::offset_t offset,
+                  lldb::offset_t length);
+
+  ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+                  const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+
+  ~ObjectFileMachO() override = default;
+
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static const char *GetPluginDescriptionStatic();
+
+  static lldb_private::ObjectFile *
+  CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+                 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
+                 lldb::offset_t file_offset, lldb::offset_t length);
+
+  static lldb_private::ObjectFile *CreateMemoryInstance(
+      const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+      const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+
+  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
+                                        lldb::DataBufferSP &data_sp,
+                                        lldb::offset_t data_offset,
+                                        lldb::offset_t file_offset,
+                                        lldb::offset_t length,
+                                        lldb_private::ModuleSpecList &specs);
+
+  static bool SaveCore(const lldb::ProcessSP &process_sp,
+                       const lldb_private::FileSpec &outfile,
+                       lldb_private::Error &error);
+
+  static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
+                              lldb::addr_t length);
+
+  //------------------------------------------------------------------
+  // Member Functions
+  //------------------------------------------------------------------
+  bool ParseHeader() override;
+
+  bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
+                      bool value_is_offset) override;
+
+  lldb::ByteOrder GetByteOrder() const override;
+
+  bool IsExecutable() const override;
+
+  uint32_t GetAddressByteSize() const override;
+
+  lldb::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
+
+  lldb_private::Symtab *GetSymtab() override;
+
+  bool IsStripped() override;
+
+  void CreateSections(lldb_private::SectionList &unified_section_list) override;
+
+  void Dump(lldb_private::Stream *s) override;
+
+  bool GetArchitecture(lldb_private::ArchSpec &arch) override;
+
+  bool GetUUID(lldb_private::UUID *uuid) override;
+
+  uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
+
+  lldb_private::FileSpecList GetReExportedLibraries() override {
+    return m_reexported_dylibs;
+  }
+
+  lldb_private::Address GetEntryPointAddress() override;
+
+  lldb_private::Address GetHeaderAddress() override;
+
+  uint32_t GetNumThreadContexts() override;
+
+  lldb::RegisterContextSP
+  GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override;
+
+  ObjectFile::Type CalculateType() override;
+
+  ObjectFile::Strata CalculateStrata() override;
+
+  uint32_t GetVersion(uint32_t *versions, uint32_t num_versions) override;
+
+  uint32_t GetMinimumOSVersion(uint32_t *versions,
+                               uint32_t num_versions) override;
+
+  uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override;
+
+  bool GetIsDynamicLinkEditor() override;
+
+  static bool ParseHeader(lldb_private::DataExtractor &data,
+                          lldb::offset_t *data_offset_ptr,
+                          llvm::MachO::mach_header &header);
+
+  bool AllowAssemblyEmulationUnwindPlans() override;
+
+  //------------------------------------------------------------------
+  // PluginInterface protocol
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
 
-    uint32_t
-    GetPluginVersion() override;
+  uint32_t GetPluginVersion() override;
 
 protected:
-    static bool
-    GetUUID (const llvm::MachO::mach_header &header,
-             const lldb_private::DataExtractor &data,
-             lldb::offset_t lc_offset, // Offset to the first load command
-             lldb_private::UUID& uuid);
-    
-    static bool
-    GetArchitecture (const llvm::MachO::mach_header &header,
-                     const lldb_private::DataExtractor &data,
-                     lldb::offset_t lc_offset,
-                     lldb_private::ArchSpec &arch);
-
-    // Intended for same-host arm device debugging where lldb needs to
-    // detect libraries in the shared cache and augment the nlist entries
-    // with an on-disk dyld_shared_cache file.  The process will record
-    // the shared cache UUID so the on-disk cache can be matched or rejected
-    // correctly.
-    lldb_private::UUID
-    GetProcessSharedCacheUUID (lldb_private::Process *);
-
-    // Intended for same-host arm device debugging where lldb will read
-    // shared cache libraries out of its own memory instead of the remote
-    // process' memory as an optimization.  If lldb's shared cache UUID 
-    // does not match the process' shared cache UUID, this optimization
-    // should not be used.
-    lldb_private::UUID
-    GetLLDBSharedCacheUUID ();
-
-    lldb_private::Section *
-    GetMachHeaderSection();
-
-    lldb::addr_t
-    CalculateSectionLoadAddressForMemoryImage(lldb::addr_t mach_header_load_address,
-                                              const lldb_private::Section *mach_header_section,
-                                              const lldb_private::Section *section);
-
-    lldb_private::UUID
-    GetSharedCacheUUID (lldb_private::FileSpec dyld_shared_cache, const lldb::ByteOrder byte_order, const uint32_t addr_byte_size);
-
-    size_t
-    ParseSymtab();
-
-    llvm::MachO::mach_header m_header;
-    static const lldb_private::ConstString &GetSegmentNameTEXT();
-    static const lldb_private::ConstString &GetSegmentNameDATA();
-    static const lldb_private::ConstString &GetSegmentNameDATA_DIRTY();
-    static const lldb_private::ConstString &GetSegmentNameDATA_CONST();
-    static const lldb_private::ConstString &GetSegmentNameOBJC();
-    static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
-    static const lldb_private::ConstString &GetSectionNameEHFrame();
-
-    llvm::MachO::dysymtab_command m_dysymtab;
-    std::vector<llvm::MachO::segment_command_64> m_mach_segments;
-    std::vector<llvm::MachO::section_64> m_mach_sections;
-    std::vector<uint32_t> m_min_os_versions;
-    std::vector<uint32_t> m_sdk_versions;
-    typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray;
-    lldb_private::Address  m_entry_point_address;
-    FileRangeArray m_thread_context_offsets;
-    bool m_thread_context_offsets_valid;
-    lldb_private::FileSpecList m_reexported_dylibs;
-    bool m_allow_assembly_emulation_unwind_plans;
+  static bool
+  GetUUID(const llvm::MachO::mach_header &header,
+          const lldb_private::DataExtractor &data,
+          lldb::offset_t lc_offset, // Offset to the first load command
+          lldb_private::UUID &uuid);
+
+  static bool GetArchitecture(const llvm::MachO::mach_header &header,
+                              const lldb_private::DataExtractor &data,
+                              lldb::offset_t lc_offset,
+                              lldb_private::ArchSpec &arch);
+
+  // Intended for same-host arm device debugging where lldb needs to
+  // detect libraries in the shared cache and augment the nlist entries
+  // with an on-disk dyld_shared_cache file.  The process will record
+  // the shared cache UUID so the on-disk cache can be matched or rejected
+  // correctly.
+  lldb_private::UUID GetProcessSharedCacheUUID(lldb_private::Process *);
+
+  // Intended for same-host arm device debugging where lldb will read
+  // shared cache libraries out of its own memory instead of the remote
+  // process' memory as an optimization.  If lldb's shared cache UUID
+  // does not match the process' shared cache UUID, this optimization
+  // should not be used.
+  lldb_private::UUID GetLLDBSharedCacheUUID();
+
+  lldb_private::Section *GetMachHeaderSection();
+
+  lldb::addr_t CalculateSectionLoadAddressForMemoryImage(
+      lldb::addr_t mach_header_load_address,
+      const lldb_private::Section *mach_header_section,
+      const lldb_private::Section *section);
+
+  lldb_private::UUID
+  GetSharedCacheUUID(lldb_private::FileSpec dyld_shared_cache,
+                     const lldb::ByteOrder byte_order,
+                     const uint32_t addr_byte_size);
+
+  size_t ParseSymtab();
+
+  llvm::MachO::mach_header m_header;
+  static const lldb_private::ConstString &GetSegmentNameTEXT();
+  static const lldb_private::ConstString &GetSegmentNameDATA();
+  static const lldb_private::ConstString &GetSegmentNameDATA_DIRTY();
+  static const lldb_private::ConstString &GetSegmentNameDATA_CONST();
+  static const lldb_private::ConstString &GetSegmentNameOBJC();
+  static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
+  static const lldb_private::ConstString &GetSectionNameEHFrame();
+
+  llvm::MachO::dysymtab_command m_dysymtab;
+  std::vector<llvm::MachO::segment_command_64> m_mach_segments;
+  std::vector<llvm::MachO::section_64> m_mach_sections;
+  std::vector<uint32_t> m_min_os_versions;
+  std::vector<uint32_t> m_sdk_versions;
+  typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray;
+  lldb_private::Address m_entry_point_address;
+  FileRangeArray m_thread_context_offsets;
+  bool m_thread_context_offsets_valid;
+  lldb_private::FileSpecList m_reexported_dylibs;
+  bool m_allow_assembly_emulation_unwind_plans;
 };
 
 #endif // liblldb_ObjectFileMachO_h_

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Tue Sep  6 15:57:50 2016
@@ -14,7 +14,6 @@
 
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
-#include "lldb/Host/FileSpec.h"
 #include "lldb/Core/FileSpecList.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
@@ -24,858 +23,781 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/UUID.h"
+#include "lldb/Host/FileSpec.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Target.h"
 
-#define IMAGE_DOS_SIGNATURE             0x5A4D      // MZ
-#define IMAGE_NT_SIGNATURE              0x00004550  // PE00
-#define OPT_HEADER_MAGIC_PE32           0x010b
-#define OPT_HEADER_MAGIC_PE32_PLUS      0x020b
+#define IMAGE_DOS_SIGNATURE 0x5A4D    // MZ
+#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
+#define OPT_HEADER_MAGIC_PE32 0x010b
+#define OPT_HEADER_MAGIC_PE32_PLUS 0x020b
 
 using namespace lldb;
 using namespace lldb_private;
 
-void
-ObjectFilePECOFF::Initialize()
-{
-    PluginManager::RegisterPlugin (GetPluginNameStatic(),
-                                   GetPluginDescriptionStatic(),
-                                   CreateInstance,
-                                   CreateMemoryInstance,
-                                   GetModuleSpecifications,
-                                   SaveCore);
-}
-
-void
-ObjectFilePECOFF::Terminate()
-{
-    PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-
-lldb_private::ConstString
-ObjectFilePECOFF::GetPluginNameStatic()
-{
-    static ConstString g_name("pe-coff");
-    return g_name;
-}
-
-const char *
-ObjectFilePECOFF::GetPluginDescriptionStatic()
-{
-    return "Portable Executable and Common Object File Format object file reader (32 and 64 bit)";
-}
-
-
-ObjectFile *
-ObjectFilePECOFF::CreateInstance (const lldb::ModuleSP &module_sp,
-                                  DataBufferSP& data_sp,
-                                  lldb::offset_t data_offset,
-                                  const lldb_private::FileSpec* file,
-                                  lldb::offset_t file_offset,
-                                  lldb::offset_t length)
-{
-    if (!data_sp)
-    {
-        data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
-        data_offset = 0;
-    }
-
-    if (ObjectFilePECOFF::MagicBytesMatch(data_sp))
-    {
-        // Update the data to contain the entire file if it doesn't already
-        if (data_sp->GetByteSize() < length)
-            data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
-        std::unique_ptr<ObjectFile> objfile_ap(new ObjectFilePECOFF (module_sp, data_sp, data_offset, file, file_offset, length));
-        if (objfile_ap.get() && objfile_ap->ParseHeader())
-            return objfile_ap.release();
-    }
-    return NULL;
-}
-
-ObjectFile *
-ObjectFilePECOFF::CreateMemoryInstance (const lldb::ModuleSP &module_sp, 
-                                        lldb::DataBufferSP& data_sp, 
-                                        const lldb::ProcessSP &process_sp, 
-                                        lldb::addr_t header_addr)
-{
-    return NULL;
-}
-
-size_t
-ObjectFilePECOFF::GetModuleSpecifications (const lldb_private::FileSpec& file,
-                                           lldb::DataBufferSP& data_sp,
-                                           lldb::offset_t data_offset,
-                                           lldb::offset_t file_offset,
-                                           lldb::offset_t length,
-                                           lldb_private::ModuleSpecList &specs)
-{
-    const size_t initial_count = specs.GetSize();
-
-    if (ObjectFilePECOFF::MagicBytesMatch(data_sp))
-    {
-        DataExtractor data;
-        data.SetData(data_sp, data_offset, length);
-        data.SetByteOrder(eByteOrderLittle);
-
-        dos_header_t dos_header;
-        coff_header_t coff_header;
-
-        if (ParseDOSHeader(data, dos_header))
-        {
-            lldb::offset_t offset = dos_header.e_lfanew;
-            uint32_t pe_signature = data.GetU32(&offset);
-            if (pe_signature != IMAGE_NT_SIGNATURE)
-                return false;
-            if (ParseCOFFHeader(data, &offset, coff_header))
-            {
-                ArchSpec spec;
-                if (coff_header.machine == MachineAmd64)
-                {
-                    spec.SetTriple("x86_64-pc-windows");
-                    specs.Append(ModuleSpec(file, spec));
-                }
-                else if (coff_header.machine == MachineX86)
-                {
-                    spec.SetTriple("i386-pc-windows");
-                    specs.Append(ModuleSpec(file, spec));
-                    spec.SetTriple("i686-pc-windows");
-                    specs.Append(ModuleSpec(file, spec));
-                }
-            }
+void ObjectFilePECOFF::Initialize() {
+  PluginManager::RegisterPlugin(
+      GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+      CreateMemoryInstance, GetModuleSpecifications, SaveCore);
+}
+
+void ObjectFilePECOFF::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb_private::ConstString ObjectFilePECOFF::GetPluginNameStatic() {
+  static ConstString g_name("pe-coff");
+  return g_name;
+}
+
+const char *ObjectFilePECOFF::GetPluginDescriptionStatic() {
+  return "Portable Executable and Common Object File Format object file reader "
+         "(32 and 64 bit)";
+}
+
+ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
+                                             DataBufferSP &data_sp,
+                                             lldb::offset_t data_offset,
+                                             const lldb_private::FileSpec *file,
+                                             lldb::offset_t file_offset,
+                                             lldb::offset_t length) {
+  if (!data_sp) {
+    data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+    data_offset = 0;
+  }
+
+  if (ObjectFilePECOFF::MagicBytesMatch(data_sp)) {
+    // Update the data to contain the entire file if it doesn't already
+    if (data_sp->GetByteSize() < length)
+      data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+    std::unique_ptr<ObjectFile> objfile_ap(new ObjectFilePECOFF(
+        module_sp, data_sp, data_offset, file, file_offset, length));
+    if (objfile_ap.get() && objfile_ap->ParseHeader())
+      return objfile_ap.release();
+  }
+  return NULL;
+}
+
+ObjectFile *ObjectFilePECOFF::CreateMemoryInstance(
+    const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+    const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) {
+  return NULL;
+}
+
+size_t ObjectFilePECOFF::GetModuleSpecifications(
+    const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
+    lldb::offset_t data_offset, lldb::offset_t file_offset,
+    lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
+  const size_t initial_count = specs.GetSize();
+
+  if (ObjectFilePECOFF::MagicBytesMatch(data_sp)) {
+    DataExtractor data;
+    data.SetData(data_sp, data_offset, length);
+    data.SetByteOrder(eByteOrderLittle);
+
+    dos_header_t dos_header;
+    coff_header_t coff_header;
+
+    if (ParseDOSHeader(data, dos_header)) {
+      lldb::offset_t offset = dos_header.e_lfanew;
+      uint32_t pe_signature = data.GetU32(&offset);
+      if (pe_signature != IMAGE_NT_SIGNATURE)
+        return false;
+      if (ParseCOFFHeader(data, &offset, coff_header)) {
+        ArchSpec spec;
+        if (coff_header.machine == MachineAmd64) {
+          spec.SetTriple("x86_64-pc-windows");
+          specs.Append(ModuleSpec(file, spec));
+        } else if (coff_header.machine == MachineX86) {
+          spec.SetTriple("i386-pc-windows");
+          specs.Append(ModuleSpec(file, spec));
+          spec.SetTriple("i686-pc-windows");
+          specs.Append(ModuleSpec(file, spec));
         }
+      }
     }
+  }
 
-    return specs.GetSize() - initial_count;
+  return specs.GetSize() - initial_count;
 }
 
-bool
-ObjectFilePECOFF::SaveCore(const lldb::ProcessSP &process_sp,
-                           const lldb_private::FileSpec &outfile,
-                           lldb_private::Error &error)
-{
-    return SaveMiniDump(process_sp, outfile, error);
+bool ObjectFilePECOFF::SaveCore(const lldb::ProcessSP &process_sp,
+                                const lldb_private::FileSpec &outfile,
+                                lldb_private::Error &error) {
+  return SaveMiniDump(process_sp, outfile, error);
 }
 
-
-bool
-ObjectFilePECOFF::MagicBytesMatch (DataBufferSP& data_sp)
-{
-    DataExtractor data(data_sp, eByteOrderLittle, 4);
-    lldb::offset_t offset = 0;
-    uint16_t magic = data.GetU16 (&offset);
-    return magic == IMAGE_DOS_SIGNATURE;
+bool ObjectFilePECOFF::MagicBytesMatch(DataBufferSP &data_sp) {
+  DataExtractor data(data_sp, eByteOrderLittle, 4);
+  lldb::offset_t offset = 0;
+  uint16_t magic = data.GetU16(&offset);
+  return magic == IMAGE_DOS_SIGNATURE;
 }
 
-lldb::SymbolType
-ObjectFilePECOFF::MapSymbolType(uint16_t coff_symbol_type)
-{
-    // TODO:  We need to complete this mapping of COFF symbol types to LLDB ones.
-    // For now, here's a hack to make sure our function have types.
-    const auto complex_type = coff_symbol_type >> llvm::COFF::SCT_COMPLEX_TYPE_SHIFT;
-    if (complex_type == llvm::COFF::IMAGE_SYM_DTYPE_FUNCTION)
-    {
-        return lldb::eSymbolTypeCode;
-    }
-    return lldb::eSymbolTypeInvalid;
+lldb::SymbolType ObjectFilePECOFF::MapSymbolType(uint16_t coff_symbol_type) {
+  // TODO:  We need to complete this mapping of COFF symbol types to LLDB ones.
+  // For now, here's a hack to make sure our function have types.
+  const auto complex_type =
+      coff_symbol_type >> llvm::COFF::SCT_COMPLEX_TYPE_SHIFT;
+  if (complex_type == llvm::COFF::IMAGE_SYM_DTYPE_FUNCTION) {
+    return lldb::eSymbolTypeCode;
+  }
+  return lldb::eSymbolTypeInvalid;
 }
 
-ObjectFilePECOFF::ObjectFilePECOFF (const lldb::ModuleSP &module_sp, 
-                                    DataBufferSP& data_sp,
-                                    lldb::offset_t data_offset,
-                                    const FileSpec* file, 
-                                    lldb::offset_t file_offset,
-                                    lldb::offset_t length) :
-    ObjectFile (module_sp, file, file_offset, length, data_sp, data_offset),
-    m_dos_header (),
-    m_coff_header (),
-    m_coff_header_opt (),
-    m_sect_headers (),
-    m_entry_point_address ()
-{
-    ::memset (&m_dos_header, 0, sizeof(m_dos_header));
-    ::memset (&m_coff_header, 0, sizeof(m_coff_header));
-    ::memset (&m_coff_header_opt, 0, sizeof(m_coff_header_opt));
+ObjectFilePECOFF::ObjectFilePECOFF(const lldb::ModuleSP &module_sp,
+                                   DataBufferSP &data_sp,
+                                   lldb::offset_t data_offset,
+                                   const FileSpec *file,
+                                   lldb::offset_t file_offset,
+                                   lldb::offset_t length)
+    : ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset),
+      m_dos_header(), m_coff_header(), m_coff_header_opt(), m_sect_headers(),
+      m_entry_point_address() {
+  ::memset(&m_dos_header, 0, sizeof(m_dos_header));
+  ::memset(&m_coff_header, 0, sizeof(m_coff_header));
+  ::memset(&m_coff_header_opt, 0, sizeof(m_coff_header_opt));
 }
 
+ObjectFilePECOFF::~ObjectFilePECOFF() {}
 
-ObjectFilePECOFF::~ObjectFilePECOFF()
-{
-}
-
-
-bool
-ObjectFilePECOFF::ParseHeader ()
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        m_sect_headers.clear();
-        m_data.SetByteOrder (eByteOrderLittle);
-        lldb::offset_t offset = 0;
-        
-        if (ParseDOSHeader(m_data, m_dos_header))
-        {
-            offset = m_dos_header.e_lfanew;
-            uint32_t pe_signature = m_data.GetU32 (&offset);
-            if (pe_signature != IMAGE_NT_SIGNATURE)
-                return false;
-            if (ParseCOFFHeader(m_data, &offset, m_coff_header))
-            {
-                if (m_coff_header.hdrsize > 0)
-                    ParseCOFFOptionalHeader(&offset);
-                ParseSectionHeaders (offset);
-            }
-            return true;
-        }
-    }
-    return false;
-}
+bool ObjectFilePECOFF::ParseHeader() {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    m_sect_headers.clear();
+    m_data.SetByteOrder(eByteOrderLittle);
+    lldb::offset_t offset = 0;
 
-bool
-ObjectFilePECOFF::SetLoadAddress(Target &target, addr_t value, bool value_is_offset)
-{
-    bool changed = false;
-    ModuleSP module_sp = GetModule();
-    if (module_sp)
-    {
-        size_t num_loaded_sections = 0;
-        SectionList *section_list = GetSectionList ();
-        if (section_list)
-        {
-            if (!value_is_offset)
-            {
-                value -= m_image_base;
-            }
-
-            const size_t num_sections = section_list->GetSize();
-            size_t sect_idx = 0;
-                
-            for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
-            {
-                // Iterate through the object file sections to find all
-                // of the sections that have SHF_ALLOC in their flag bits.
-                SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
-                if (section_sp && !section_sp->IsThreadSpecific())
-                {
-                    if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
-                        ++num_loaded_sections;
-                }
-            }
-            changed = num_loaded_sections > 0;
+    if (ParseDOSHeader(m_data, m_dos_header)) {
+      offset = m_dos_header.e_lfanew;
+      uint32_t pe_signature = m_data.GetU32(&offset);
+      if (pe_signature != IMAGE_NT_SIGNATURE)
+        return false;
+      if (ParseCOFFHeader(m_data, &offset, m_coff_header)) {
+        if (m_coff_header.hdrsize > 0)
+          ParseCOFFOptionalHeader(&offset);
+        ParseSectionHeaders(offset);
+      }
+      return true;
+    }
+  }
+  return false;
+}
+
+bool ObjectFilePECOFF::SetLoadAddress(Target &target, addr_t value,
+                                      bool value_is_offset) {
+  bool changed = false;
+  ModuleSP module_sp = GetModule();
+  if (module_sp) {
+    size_t num_loaded_sections = 0;
+    SectionList *section_list = GetSectionList();
+    if (section_list) {
+      if (!value_is_offset) {
+        value -= m_image_base;
+      }
+
+      const size_t num_sections = section_list->GetSize();
+      size_t sect_idx = 0;
+
+      for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
+        // Iterate through the object file sections to find all
+        // of the sections that have SHF_ALLOC in their flag bits.
+        SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
+        if (section_sp && !section_sp->IsThreadSpecific()) {
+          if (target.GetSectionLoadList().SetSectionLoadAddress(
+                  section_sp, section_sp->GetFileAddress() + value))
+            ++num_loaded_sections;
         }
+      }
+      changed = num_loaded_sections > 0;
     }
-    return changed;
+  }
+  return changed;
 }
 
+ByteOrder ObjectFilePECOFF::GetByteOrder() const { return eByteOrderLittle; }
 
-ByteOrder
-ObjectFilePECOFF::GetByteOrder () const
-{
-    return eByteOrderLittle;
+bool ObjectFilePECOFF::IsExecutable() const {
+  return (m_coff_header.flags & llvm::COFF::IMAGE_FILE_DLL) == 0;
 }
 
-bool
-ObjectFilePECOFF::IsExecutable() const
-{
-    return (m_coff_header.flags & llvm::COFF::IMAGE_FILE_DLL) == 0;
-}
-
-uint32_t
-ObjectFilePECOFF::GetAddressByteSize () const
-{
-    if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32_PLUS)
-        return 8;
-    else if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32)
-        return 4;
+uint32_t ObjectFilePECOFF::GetAddressByteSize() const {
+  if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32_PLUS)
+    return 8;
+  else if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32)
     return 4;
+  return 4;
 }
 
 //----------------------------------------------------------------------
 // NeedsEndianSwap
 //
-// Return true if an endian swap needs to occur when extracting data 
+// Return true if an endian swap needs to occur when extracting data
 // from this file.
 //----------------------------------------------------------------------
-bool 
-ObjectFilePECOFF::NeedsEndianSwap() const
-{
+bool ObjectFilePECOFF::NeedsEndianSwap() const {
 #if defined(__LITTLE_ENDIAN__)
-    return false;
+  return false;
 #else
-    return true;
+  return true;
 #endif
 }
 //----------------------------------------------------------------------
 // ParseDOSHeader
 //----------------------------------------------------------------------
-bool
-ObjectFilePECOFF::ParseDOSHeader (DataExtractor &data, dos_header_t &dos_header)
-{
-    bool success = false;
-    lldb::offset_t offset = 0;
-    success = data.ValidOffsetForDataOfSize(0, sizeof(dos_header));
-    
-    if (success)
-    {
-        dos_header.e_magic = data.GetU16(&offset); // Magic number
-        success = dos_header.e_magic == IMAGE_DOS_SIGNATURE;
-        
-        if (success)
-        {
-            dos_header.e_cblp     = data.GetU16(&offset); // Bytes on last page of file
-            dos_header.e_cp       = data.GetU16(&offset); // Pages in file
-            dos_header.e_crlc     = data.GetU16(&offset); // Relocations
-            dos_header.e_cparhdr  = data.GetU16(&offset); // Size of header in paragraphs
-            dos_header.e_minalloc = data.GetU16(&offset); // Minimum extra paragraphs needed
-            dos_header.e_maxalloc = data.GetU16(&offset); // Maximum extra paragraphs needed
-            dos_header.e_ss       = data.GetU16(&offset); // Initial (relative) SS value
-            dos_header.e_sp       = data.GetU16(&offset); // Initial SP value
-            dos_header.e_csum     = data.GetU16(&offset); // Checksum
-            dos_header.e_ip       = data.GetU16(&offset); // Initial IP value
-            dos_header.e_cs       = data.GetU16(&offset); // Initial (relative) CS value
-            dos_header.e_lfarlc   = data.GetU16(&offset); // File address of relocation table
-            dos_header.e_ovno     = data.GetU16(&offset); // Overlay number
-            
-            dos_header.e_res[0]   = data.GetU16(&offset); // Reserved words
-            dos_header.e_res[1]   = data.GetU16(&offset); // Reserved words
-            dos_header.e_res[2]   = data.GetU16(&offset); // Reserved words
-            dos_header.e_res[3]   = data.GetU16(&offset); // Reserved words
-            
-            dos_header.e_oemid    = data.GetU16(&offset); // OEM identifier (for e_oeminfo)
-            dos_header.e_oeminfo  = data.GetU16(&offset); // OEM information; e_oemid specific
-            dos_header.e_res2[0]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[1]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[2]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[3]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[4]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[5]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[6]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[7]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[8]  = data.GetU16(&offset); // Reserved words
-            dos_header.e_res2[9]  = data.GetU16(&offset); // Reserved words
-            
-            dos_header.e_lfanew   = data.GetU32(&offset); // File address of new exe header
-        }
-    }
-    if (!success)
-        memset(&dos_header, 0, sizeof(dos_header));
-    return success;
+bool ObjectFilePECOFF::ParseDOSHeader(DataExtractor &data,
+                                      dos_header_t &dos_header) {
+  bool success = false;
+  lldb::offset_t offset = 0;
+  success = data.ValidOffsetForDataOfSize(0, sizeof(dos_header));
+
+  if (success) {
+    dos_header.e_magic = data.GetU16(&offset); // Magic number
+    success = dos_header.e_magic == IMAGE_DOS_SIGNATURE;
+
+    if (success) {
+      dos_header.e_cblp = data.GetU16(&offset); // Bytes on last page of file
+      dos_header.e_cp = data.GetU16(&offset);   // Pages in file
+      dos_header.e_crlc = data.GetU16(&offset); // Relocations
+      dos_header.e_cparhdr =
+          data.GetU16(&offset); // Size of header in paragraphs
+      dos_header.e_minalloc =
+          data.GetU16(&offset); // Minimum extra paragraphs needed
+      dos_header.e_maxalloc =
+          data.GetU16(&offset);               // Maximum extra paragraphs needed
+      dos_header.e_ss = data.GetU16(&offset); // Initial (relative) SS value
+      dos_header.e_sp = data.GetU16(&offset); // Initial SP value
+      dos_header.e_csum = data.GetU16(&offset); // Checksum
+      dos_header.e_ip = data.GetU16(&offset);   // Initial IP value
+      dos_header.e_cs = data.GetU16(&offset);   // Initial (relative) CS value
+      dos_header.e_lfarlc =
+          data.GetU16(&offset); // File address of relocation table
+      dos_header.e_ovno = data.GetU16(&offset); // Overlay number
+
+      dos_header.e_res[0] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res[1] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res[2] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res[3] = data.GetU16(&offset); // Reserved words
+
+      dos_header.e_oemid =
+          data.GetU16(&offset); // OEM identifier (for e_oeminfo)
+      dos_header.e_oeminfo =
+          data.GetU16(&offset); // OEM information; e_oemid specific
+      dos_header.e_res2[0] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[1] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[2] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[3] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[4] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[5] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[6] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[7] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[8] = data.GetU16(&offset); // Reserved words
+      dos_header.e_res2[9] = data.GetU16(&offset); // Reserved words
+
+      dos_header.e_lfanew =
+          data.GetU32(&offset); // File address of new exe header
+    }
+  }
+  if (!success)
+    memset(&dos_header, 0, sizeof(dos_header));
+  return success;
 }
 
-
 //----------------------------------------------------------------------
 // ParserCOFFHeader
 //----------------------------------------------------------------------
-bool
-ObjectFilePECOFF::ParseCOFFHeader(DataExtractor &data, lldb::offset_t *offset_ptr, coff_header_t &coff_header)
-{
-    bool success = data.ValidOffsetForDataOfSize (*offset_ptr, sizeof(coff_header));
-    if (success)
-    {
-        coff_header.machine   = data.GetU16(offset_ptr);
-        coff_header.nsects    = data.GetU16(offset_ptr);
-        coff_header.modtime   = data.GetU32(offset_ptr);
-        coff_header.symoff    = data.GetU32(offset_ptr);
-        coff_header.nsyms     = data.GetU32(offset_ptr);
-        coff_header.hdrsize   = data.GetU16(offset_ptr);
-        coff_header.flags     = data.GetU16(offset_ptr);
-    }
-    if (!success)
-        memset(&coff_header, 0, sizeof(coff_header));
-    return success;
-}
-
-bool
-ObjectFilePECOFF::ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr)
-{
-    bool success = false;
-    const lldb::offset_t end_offset = *offset_ptr + m_coff_header.hdrsize;
-    if (*offset_ptr < end_offset)
-    {
-        success = true;
-        m_coff_header_opt.magic                         = m_data.GetU16(offset_ptr); 
-        m_coff_header_opt.major_linker_version          = m_data.GetU8 (offset_ptr);
-        m_coff_header_opt.minor_linker_version          = m_data.GetU8 (offset_ptr);     
-        m_coff_header_opt.code_size                     = m_data.GetU32(offset_ptr); 
-        m_coff_header_opt.data_size                     = m_data.GetU32(offset_ptr); 
-        m_coff_header_opt.bss_size                      = m_data.GetU32(offset_ptr); 
-        m_coff_header_opt.entry                         = m_data.GetU32(offset_ptr); 
-        m_coff_header_opt.code_offset                   = m_data.GetU32(offset_ptr); 
-
-        const uint32_t addr_byte_size = GetAddressByteSize ();
-
-        if (*offset_ptr < end_offset)
-        {
-            if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32)
-            {
-                // PE32 only
-                m_coff_header_opt.data_offset               = m_data.GetU32(offset_ptr);                             
-            }
-            else
-                m_coff_header_opt.data_offset = 0;
-        
-            if (*offset_ptr < end_offset)
-            {
-                m_coff_header_opt.image_base                    = m_data.GetMaxU64 (offset_ptr, addr_byte_size); 
-                m_coff_header_opt.sect_alignment                = m_data.GetU32(offset_ptr); 
-                m_coff_header_opt.file_alignment                = m_data.GetU32(offset_ptr); 
-                m_coff_header_opt.major_os_system_version       = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.minor_os_system_version       = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.major_image_version           = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.minor_image_version           = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.major_subsystem_version       = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.minor_subsystem_version       = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.reserved1                     = m_data.GetU32(offset_ptr); 
-                m_coff_header_opt.image_size                    = m_data.GetU32(offset_ptr); 
-                m_coff_header_opt.header_size                   = m_data.GetU32(offset_ptr); 
-                m_coff_header_opt.checksum                      = m_data.GetU32(offset_ptr); 
-                m_coff_header_opt.subsystem                     = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.dll_flags                     = m_data.GetU16(offset_ptr); 
-                m_coff_header_opt.stack_reserve_size            = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
-                m_coff_header_opt.stack_commit_size             = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
-                m_coff_header_opt.heap_reserve_size             = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
-                m_coff_header_opt.heap_commit_size              = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
-                m_coff_header_opt.loader_flags                  = m_data.GetU32(offset_ptr); 
-                uint32_t num_data_dir_entries = m_data.GetU32(offset_ptr);
-                m_coff_header_opt.data_dirs.clear();
-                m_coff_header_opt.data_dirs.resize(num_data_dir_entries);
-                uint32_t i;
-                for (i=0; i<num_data_dir_entries; i++)
-                {
-                    m_coff_header_opt.data_dirs[i].vmaddr = m_data.GetU32(offset_ptr);
-                    m_coff_header_opt.data_dirs[i].vmsize = m_data.GetU32(offset_ptr);
-                }
-
-                m_file_offset = m_coff_header_opt.image_base;
-                m_image_base = m_coff_header_opt.image_base;
-            }
+bool ObjectFilePECOFF::ParseCOFFHeader(DataExtractor &data,
+                                       lldb::offset_t *offset_ptr,
+                                       coff_header_t &coff_header) {
+  bool success =
+      data.ValidOffsetForDataOfSize(*offset_ptr, sizeof(coff_header));
+  if (success) {
+    coff_header.machine = data.GetU16(offset_ptr);
+    coff_header.nsects = data.GetU16(offset_ptr);
+    coff_header.modtime = data.GetU32(offset_ptr);
+    coff_header.symoff = data.GetU32(offset_ptr);
+    coff_header.nsyms = data.GetU32(offset_ptr);
+    coff_header.hdrsize = data.GetU16(offset_ptr);
+    coff_header.flags = data.GetU16(offset_ptr);
+  }
+  if (!success)
+    memset(&coff_header, 0, sizeof(coff_header));
+  return success;
+}
+
+bool ObjectFilePECOFF::ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr) {
+  bool success = false;
+  const lldb::offset_t end_offset = *offset_ptr + m_coff_header.hdrsize;
+  if (*offset_ptr < end_offset) {
+    success = true;
+    m_coff_header_opt.magic = m_data.GetU16(offset_ptr);
+    m_coff_header_opt.major_linker_version = m_data.GetU8(offset_ptr);
+    m_coff_header_opt.minor_linker_version = m_data.GetU8(offset_ptr);
+    m_coff_header_opt.code_size = m_data.GetU32(offset_ptr);
+    m_coff_header_opt.data_size = m_data.GetU32(offset_ptr);
+    m_coff_header_opt.bss_size = m_data.GetU32(offset_ptr);
+    m_coff_header_opt.entry = m_data.GetU32(offset_ptr);
+    m_coff_header_opt.code_offset = m_data.GetU32(offset_ptr);
+
+    const uint32_t addr_byte_size = GetAddressByteSize();
+
+    if (*offset_ptr < end_offset) {
+      if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32) {
+        // PE32 only
+        m_coff_header_opt.data_offset = m_data.GetU32(offset_ptr);
+      } else
+        m_coff_header_opt.data_offset = 0;
+
+      if (*offset_ptr < end_offset) {
+        m_coff_header_opt.image_base =
+            m_data.GetMaxU64(offset_ptr, addr_byte_size);
+        m_coff_header_opt.sect_alignment = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.file_alignment = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.major_os_system_version = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.minor_os_system_version = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.major_image_version = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.minor_image_version = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.major_subsystem_version = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.minor_subsystem_version = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.reserved1 = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.image_size = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.header_size = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.checksum = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.subsystem = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.dll_flags = m_data.GetU16(offset_ptr);
+        m_coff_header_opt.stack_reserve_size =
+            m_data.GetMaxU64(offset_ptr, addr_byte_size);
+        m_coff_header_opt.stack_commit_size =
+            m_data.GetMaxU64(offset_ptr, addr_byte_size);
+        m_coff_header_opt.heap_reserve_size =
+            m_data.GetMaxU64(offset_ptr, addr_byte_size);
+        m_coff_header_opt.heap_commit_size =
+            m_data.GetMaxU64(offset_ptr, addr_byte_size);
+        m_coff_header_opt.loader_flags = m_data.GetU32(offset_ptr);
+        uint32_t num_data_dir_entries = m_data.GetU32(offset_ptr);
+        m_coff_header_opt.data_dirs.clear();
+        m_coff_header_opt.data_dirs.resize(num_data_dir_entries);
+        uint32_t i;
+        for (i = 0; i < num_data_dir_entries; i++) {
+          m_coff_header_opt.data_dirs[i].vmaddr = m_data.GetU32(offset_ptr);
+          m_coff_header_opt.data_dirs[i].vmsize = m_data.GetU32(offset_ptr);
         }
-    }
-    // Make sure we are on track for section data which follows
-    *offset_ptr = end_offset;
-    return success;
-}
 
+        m_file_offset = m_coff_header_opt.image_base;
+        m_image_base = m_coff_header_opt.image_base;
+      }
+    }
+  }
+  // Make sure we are on track for section data which follows
+  *offset_ptr = end_offset;
+  return success;
+}
 
 //----------------------------------------------------------------------
 // ParseSectionHeaders
 //----------------------------------------------------------------------
-bool
-ObjectFilePECOFF::ParseSectionHeaders (uint32_t section_header_data_offset)
-{
-    const uint32_t nsects = m_coff_header.nsects;
-    m_sect_headers.clear();
-    
-    if (nsects > 0)
-    {
-        const uint32_t addr_byte_size = GetAddressByteSize ();
-        const size_t section_header_byte_size = nsects * sizeof(section_header_t);
-        DataBufferSP section_header_data_sp(m_file.ReadFileContents (section_header_data_offset, section_header_byte_size));
-        DataExtractor section_header_data (section_header_data_sp, GetByteOrder(), addr_byte_size);
+bool ObjectFilePECOFF::ParseSectionHeaders(
+    uint32_t section_header_data_offset) {
+  const uint32_t nsects = m_coff_header.nsects;
+  m_sect_headers.clear();
+
+  if (nsects > 0) {
+    const uint32_t addr_byte_size = GetAddressByteSize();
+    const size_t section_header_byte_size = nsects * sizeof(section_header_t);
+    DataBufferSP section_header_data_sp(m_file.ReadFileContents(
+        section_header_data_offset, section_header_byte_size));
+    DataExtractor section_header_data(section_header_data_sp, GetByteOrder(),
+                                      addr_byte_size);
 
-        lldb::offset_t offset = 0;
-        if (section_header_data.ValidOffsetForDataOfSize (offset, section_header_byte_size))
-        {
-            m_sect_headers.resize(nsects);
-            
-            for (uint32_t idx = 0; idx<nsects; ++idx)
-            {
-                const void *name_data = section_header_data.GetData(&offset, 8);
-                if (name_data)
-                {
-                    memcpy(m_sect_headers[idx].name, name_data, 8);
-                    m_sect_headers[idx].vmsize  = section_header_data.GetU32(&offset);
-                    m_sect_headers[idx].vmaddr  = section_header_data.GetU32(&offset);
-                    m_sect_headers[idx].size    = section_header_data.GetU32(&offset);
-                    m_sect_headers[idx].offset  = section_header_data.GetU32(&offset);
-                    m_sect_headers[idx].reloff  = section_header_data.GetU32(&offset);
-                    m_sect_headers[idx].lineoff = section_header_data.GetU32(&offset);
-                    m_sect_headers[idx].nreloc  = section_header_data.GetU16(&offset);
-                    m_sect_headers[idx].nline   = section_header_data.GetU16(&offset);
-                    m_sect_headers[idx].flags   = section_header_data.GetU32(&offset);
-                }
-            }
+    lldb::offset_t offset = 0;
+    if (section_header_data.ValidOffsetForDataOfSize(
+            offset, section_header_byte_size)) {
+      m_sect_headers.resize(nsects);
+
+      for (uint32_t idx = 0; idx < nsects; ++idx) {
+        const void *name_data = section_header_data.GetData(&offset, 8);
+        if (name_data) {
+          memcpy(m_sect_headers[idx].name, name_data, 8);
+          m_sect_headers[idx].vmsize = section_header_data.GetU32(&offset);
+          m_sect_headers[idx].vmaddr = section_header_data.GetU32(&offset);
+          m_sect_headers[idx].size = section_header_data.GetU32(&offset);
+          m_sect_headers[idx].offset = section_header_data.GetU32(&offset);
+          m_sect_headers[idx].reloff = section_header_data.GetU32(&offset);
+          m_sect_headers[idx].lineoff = section_header_data.GetU32(&offset);
+          m_sect_headers[idx].nreloc = section_header_data.GetU16(&offset);
+          m_sect_headers[idx].nline = section_header_data.GetU16(&offset);
+          m_sect_headers[idx].flags = section_header_data.GetU32(&offset);
         }
+      }
     }
-    
-    return m_sect_headers.empty() == false;
+  }
+
+  return m_sect_headers.empty() == false;
 }
 
-bool
-ObjectFilePECOFF::GetSectionName(std::string& sect_name, const section_header_t& sect)
-{
-    if (sect.name[0] == '/')
-    {
-        lldb::offset_t stroff = strtoul(&sect.name[1], NULL, 10);
-        lldb::offset_t string_file_offset = m_coff_header.symoff + (m_coff_header.nsyms * 18) + stroff;
-        const char *name = m_data.GetCStr (&string_file_offset);
-        if (name)
-        {
-            sect_name = name;
-            return true;
-        }
-        
-        return false;
+bool ObjectFilePECOFF::GetSectionName(std::string &sect_name,
+                                      const section_header_t &sect) {
+  if (sect.name[0] == '/') {
+    lldb::offset_t stroff = strtoul(&sect.name[1], NULL, 10);
+    lldb::offset_t string_file_offset =
+        m_coff_header.symoff + (m_coff_header.nsyms * 18) + stroff;
+    const char *name = m_data.GetCStr(&string_file_offset);
+    if (name) {
+      sect_name = name;
+      return true;
     }
-    sect_name = sect.name;
-    return true;
-}       
+
+    return false;
+  }
+  sect_name = sect.name;
+  return true;
+}
 
 //----------------------------------------------------------------------
 // GetNListSymtab
 //----------------------------------------------------------------------
-Symtab *
-ObjectFilePECOFF::GetSymtab()
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        if (m_symtab_ap.get() == NULL)
-        {
-            SectionList *sect_list = GetSectionList();
-            m_symtab_ap.reset(new Symtab(this));
-            std::lock_guard<std::recursive_mutex> guard(m_symtab_ap->GetMutex());
-
-            const uint32_t num_syms = m_coff_header.nsyms;
-
-            if (num_syms > 0 && m_coff_header.symoff > 0)
-            {
-                const uint32_t symbol_size = 18;
-                const uint32_t addr_byte_size = GetAddressByteSize ();
-                const size_t symbol_data_size = num_syms * symbol_size;
-                // Include the 4-byte string table size at the end of the symbols
-                DataBufferSP symtab_data_sp(m_file.ReadFileContents (m_coff_header.symoff, symbol_data_size + 4));
-                DataExtractor symtab_data (symtab_data_sp, GetByteOrder(), addr_byte_size);
-                lldb::offset_t offset = symbol_data_size;
-                const uint32_t strtab_size = symtab_data.GetU32 (&offset);
-                DataBufferSP strtab_data_sp(m_file.ReadFileContents (m_coff_header.symoff + symbol_data_size, strtab_size));
-                DataExtractor strtab_data (strtab_data_sp, GetByteOrder(), addr_byte_size);
-
-                // First 4 bytes should be zeroed after strtab_size has been read,
-                // because it is used as offset 0 to encode a NULL string.
-                uint32_t* strtab_data_start = (uint32_t*)strtab_data_sp->GetBytes();
-                strtab_data_start[0] = 0;
-
-                offset = 0;
-                std::string symbol_name;
-                Symbol *symbols = m_symtab_ap->Resize (num_syms);
-                for (uint32_t i=0; i<num_syms; ++i)
-                {
-                    coff_symbol_t symbol;
-                    const uint32_t symbol_offset = offset;
-                    const char *symbol_name_cstr = NULL;
-                    // If the first 4 bytes of the symbol string are zero, then they
-                    // are followed by a 4-byte string table offset. Else these
-                    // 8 bytes contain the symbol name
-                    if (symtab_data.GetU32 (&offset) == 0)
-                    {
-                        // Long string that doesn't fit into the symbol table name,
-                        // so now we must read the 4 byte string table offset
-                        uint32_t strtab_offset = symtab_data.GetU32 (&offset);
-                        symbol_name_cstr = strtab_data.PeekCStr (strtab_offset);
-                        symbol_name.assign (symbol_name_cstr);
-                    }
-                    else
-                    {
-                        // Short string that fits into the symbol table name which is 8 bytes
-                        offset += sizeof(symbol.name) - 4; // Skip remaining 
-                        symbol_name_cstr = symtab_data.PeekCStr (symbol_offset);
-                        if (symbol_name_cstr == NULL)
-                            break;
-                        symbol_name.assign (symbol_name_cstr, sizeof(symbol.name));
-                    }
-                    symbol.value    = symtab_data.GetU32 (&offset);
-                    symbol.sect     = symtab_data.GetU16 (&offset);
-                    symbol.type     = symtab_data.GetU16 (&offset);
-                    symbol.storage  = symtab_data.GetU8  (&offset);
-                    symbol.naux     = symtab_data.GetU8  (&offset);		
-                    symbols[i].GetMangled ().SetValue (ConstString(symbol_name.c_str()));
-                    if ((int16_t)symbol.sect >= 1)
-                    {
-                        Address symbol_addr(sect_list->GetSectionAtIndex(symbol.sect-1), symbol.value);
-                        symbols[i].GetAddressRef() = symbol_addr;
-                        symbols[i].SetType(MapSymbolType(symbol.type));
-                    }
-
-                    if (symbol.naux > 0)
-                    {
-                        i += symbol.naux;
-                        offset += symbol_size;
-                    }
-                }
-                
-            }
-
-            // Read export header
-            if (coff_data_dir_export_table < m_coff_header_opt.data_dirs.size()
-                && m_coff_header_opt.data_dirs[coff_data_dir_export_table].vmsize > 0 && m_coff_header_opt.data_dirs[coff_data_dir_export_table].vmaddr > 0)
-            {
-                export_directory_entry export_table;
-                uint32_t data_start = m_coff_header_opt.data_dirs[coff_data_dir_export_table].vmaddr;
-                Address address(m_coff_header_opt.image_base + data_start, sect_list);
-                DataBufferSP symtab_data_sp(m_file.ReadFileContents(address.GetSection()->GetFileOffset() + address.GetOffset(), m_coff_header_opt.data_dirs[0].vmsize));
-                DataExtractor symtab_data (symtab_data_sp, GetByteOrder(), GetAddressByteSize());
-                lldb::offset_t offset = 0;
-
-                // Read export_table header
-                export_table.characteristics = symtab_data.GetU32(&offset);
-                export_table.time_date_stamp = symtab_data.GetU32(&offset);
-                export_table.major_version = symtab_data.GetU16(&offset);
-                export_table.minor_version = symtab_data.GetU16(&offset);
-                export_table.name = symtab_data.GetU32(&offset);
-                export_table.base = symtab_data.GetU32(&offset);
-                export_table.number_of_functions = symtab_data.GetU32(&offset);
-                export_table.number_of_names = symtab_data.GetU32(&offset);
-                export_table.address_of_functions = symtab_data.GetU32(&offset);
-                export_table.address_of_names = symtab_data.GetU32(&offset);
-                export_table.address_of_name_ordinals = symtab_data.GetU32(&offset);
-
-                bool has_ordinal = export_table.address_of_name_ordinals != 0;
-
-                lldb::offset_t name_offset = export_table.address_of_names - data_start;
-                lldb::offset_t name_ordinal_offset = export_table.address_of_name_ordinals - data_start;
-
-                Symbol *symbols = m_symtab_ap->Resize(export_table.number_of_names);
-
-                std::string symbol_name;
-
-                // Read each export table entry
-                for (size_t i = 0; i < export_table.number_of_names; ++i)
-                {
-                    uint32_t name_ordinal = has_ordinal ? symtab_data.GetU16(&name_ordinal_offset) : i;
-                    uint32_t name_address = symtab_data.GetU32(&name_offset);
-
-                    const char* symbol_name_cstr = symtab_data.PeekCStr(name_address - data_start);
-                    symbol_name.assign(symbol_name_cstr);
-
-                    lldb::offset_t function_offset = export_table.address_of_functions - data_start + sizeof(uint32_t) * name_ordinal;
-                    uint32_t function_rva = symtab_data.GetU32(&function_offset);
-
-                    Address symbol_addr(m_coff_header_opt.image_base + function_rva, sect_list);
-                    symbols[i].GetMangled().SetValue(ConstString(symbol_name.c_str()));
-                    symbols[i].GetAddressRef() = symbol_addr;
-                    symbols[i].SetType(lldb::eSymbolTypeCode);
-                    symbols[i].SetDebug(true);
-                }
-            }
-            m_symtab_ap->CalculateSymbolSizes();
+Symtab *ObjectFilePECOFF::GetSymtab() {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    if (m_symtab_ap.get() == NULL) {
+      SectionList *sect_list = GetSectionList();
+      m_symtab_ap.reset(new Symtab(this));
+      std::lock_guard<std::recursive_mutex> guard(m_symtab_ap->GetMutex());
+
+      const uint32_t num_syms = m_coff_header.nsyms;
+
+      if (num_syms > 0 && m_coff_header.symoff > 0) {
+        const uint32_t symbol_size = 18;
+        const uint32_t addr_byte_size = GetAddressByteSize();
+        const size_t symbol_data_size = num_syms * symbol_size;
+        // Include the 4-byte string table size at the end of the symbols
+        DataBufferSP symtab_data_sp(m_file.ReadFileContents(
+            m_coff_header.symoff, symbol_data_size + 4));
+        DataExtractor symtab_data(symtab_data_sp, GetByteOrder(),
+                                  addr_byte_size);
+        lldb::offset_t offset = symbol_data_size;
+        const uint32_t strtab_size = symtab_data.GetU32(&offset);
+        DataBufferSP strtab_data_sp(m_file.ReadFileContents(
+            m_coff_header.symoff + symbol_data_size, strtab_size));
+        DataExtractor strtab_data(strtab_data_sp, GetByteOrder(),
+                                  addr_byte_size);
+
+        // First 4 bytes should be zeroed after strtab_size has been read,
+        // because it is used as offset 0 to encode a NULL string.
+        uint32_t *strtab_data_start = (uint32_t *)strtab_data_sp->GetBytes();
+        strtab_data_start[0] = 0;
+
+        offset = 0;
+        std::string symbol_name;
+        Symbol *symbols = m_symtab_ap->Resize(num_syms);
+        for (uint32_t i = 0; i < num_syms; ++i) {
+          coff_symbol_t symbol;
+          const uint32_t symbol_offset = offset;
+          const char *symbol_name_cstr = NULL;
+          // If the first 4 bytes of the symbol string are zero, then they
+          // are followed by a 4-byte string table offset. Else these
+          // 8 bytes contain the symbol name
+          if (symtab_data.GetU32(&offset) == 0) {
+            // Long string that doesn't fit into the symbol table name,
+            // so now we must read the 4 byte string table offset
+            uint32_t strtab_offset = symtab_data.GetU32(&offset);
+            symbol_name_cstr = strtab_data.PeekCStr(strtab_offset);
+            symbol_name.assign(symbol_name_cstr);
+          } else {
+            // Short string that fits into the symbol table name which is 8
+            // bytes
+            offset += sizeof(symbol.name) - 4; // Skip remaining
+            symbol_name_cstr = symtab_data.PeekCStr(symbol_offset);
+            if (symbol_name_cstr == NULL)
+              break;
+            symbol_name.assign(symbol_name_cstr, sizeof(symbol.name));
+          }
+          symbol.value = symtab_data.GetU32(&offset);
+          symbol.sect = symtab_data.GetU16(&offset);
+          symbol.type = symtab_data.GetU16(&offset);
+          symbol.storage = symtab_data.GetU8(&offset);
+          symbol.naux = symtab_data.GetU8(&offset);
+          symbols[i].GetMangled().SetValue(ConstString(symbol_name.c_str()));
+          if ((int16_t)symbol.sect >= 1) {
+            Address symbol_addr(sect_list->GetSectionAtIndex(symbol.sect - 1),
+                                symbol.value);
+            symbols[i].GetAddressRef() = symbol_addr;
+            symbols[i].SetType(MapSymbolType(symbol.type));
+          }
+
+          if (symbol.naux > 0) {
+            i += symbol.naux;
+            offset += symbol_size;
+          }
         }
-    }
-    return m_symtab_ap.get();
+      }
 
-}
+      // Read export header
+      if (coff_data_dir_export_table < m_coff_header_opt.data_dirs.size() &&
+          m_coff_header_opt.data_dirs[coff_data_dir_export_table].vmsize > 0 &&
+          m_coff_header_opt.data_dirs[coff_data_dir_export_table].vmaddr > 0) {
+        export_directory_entry export_table;
+        uint32_t data_start =
+            m_coff_header_opt.data_dirs[coff_data_dir_export_table].vmaddr;
+        Address address(m_coff_header_opt.image_base + data_start, sect_list);
+        DataBufferSP symtab_data_sp(m_file.ReadFileContents(
+            address.GetSection()->GetFileOffset() + address.GetOffset(),
+            m_coff_header_opt.data_dirs[0].vmsize));
+        DataExtractor symtab_data(symtab_data_sp, GetByteOrder(),
+                                  GetAddressByteSize());
+        lldb::offset_t offset = 0;
 
-bool
-ObjectFilePECOFF::IsStripped ()
-{
-    // TODO: determine this for COFF
-    return false;
+        // Read export_table header
+        export_table.characteristics = symtab_data.GetU32(&offset);
+        export_table.time_date_stamp = symtab_data.GetU32(&offset);
+        export_table.major_version = symtab_data.GetU16(&offset);
+        export_table.minor_version = symtab_data.GetU16(&offset);
+        export_table.name = symtab_data.GetU32(&offset);
+        export_table.base = symtab_data.GetU32(&offset);
+        export_table.number_of_functions = symtab_data.GetU32(&offset);
+        export_table.number_of_names = symtab_data.GetU32(&offset);
+        export_table.address_of_functions = symtab_data.GetU32(&offset);
+        export_table.address_of_names = symtab_data.GetU32(&offset);
+        export_table.address_of_name_ordinals = symtab_data.GetU32(&offset);
+
+        bool has_ordinal = export_table.address_of_name_ordinals != 0;
+
+        lldb::offset_t name_offset = export_table.address_of_names - data_start;
+        lldb::offset_t name_ordinal_offset =
+            export_table.address_of_name_ordinals - data_start;
+
+        Symbol *symbols = m_symtab_ap->Resize(export_table.number_of_names);
+
+        std::string symbol_name;
+
+        // Read each export table entry
+        for (size_t i = 0; i < export_table.number_of_names; ++i) {
+          uint32_t name_ordinal =
+              has_ordinal ? symtab_data.GetU16(&name_ordinal_offset) : i;
+          uint32_t name_address = symtab_data.GetU32(&name_offset);
+
+          const char *symbol_name_cstr =
+              symtab_data.PeekCStr(name_address - data_start);
+          symbol_name.assign(symbol_name_cstr);
+
+          lldb::offset_t function_offset = export_table.address_of_functions -
+                                           data_start +
+                                           sizeof(uint32_t) * name_ordinal;
+          uint32_t function_rva = symtab_data.GetU32(&function_offset);
+
+          Address symbol_addr(m_coff_header_opt.image_base + function_rva,
+                              sect_list);
+          symbols[i].GetMangled().SetValue(ConstString(symbol_name.c_str()));
+          symbols[i].GetAddressRef() = symbol_addr;
+          symbols[i].SetType(lldb::eSymbolTypeCode);
+          symbols[i].SetDebug(true);
+        }
+      }
+      m_symtab_ap->CalculateSymbolSizes();
+    }
+  }
+  return m_symtab_ap.get();
 }
 
+bool ObjectFilePECOFF::IsStripped() {
+  // TODO: determine this for COFF
+  return false;
+}
 
+void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
+  if (!m_sections_ap.get()) {
+    m_sections_ap.reset(new SectionList());
 
-void
-ObjectFilePECOFF::CreateSections (SectionList &unified_section_list)
-{
-    if (!m_sections_ap.get())
-    {
-        m_sections_ap.reset(new SectionList());
-
-        ModuleSP module_sp(GetModule());
-        if (module_sp)
-        {
-            std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-            const uint32_t nsects = m_sect_headers.size();
-            ModuleSP module_sp (GetModule());
-            for (uint32_t idx = 0; idx<nsects; ++idx)
-            {
-                std::string sect_name;
-                GetSectionName (sect_name, m_sect_headers[idx]);
-                ConstString const_sect_name (sect_name.c_str());
-                static ConstString g_code_sect_name (".code");
-                static ConstString g_CODE_sect_name ("CODE");
-                static ConstString g_data_sect_name (".data");
-                static ConstString g_DATA_sect_name ("DATA");
-                static ConstString g_bss_sect_name (".bss");
-                static ConstString g_BSS_sect_name ("BSS");
-                static ConstString g_debug_sect_name (".debug");
-                static ConstString g_reloc_sect_name (".reloc");
-                static ConstString g_stab_sect_name (".stab");
-                static ConstString g_stabstr_sect_name (".stabstr");
-                static ConstString g_sect_name_dwarf_debug_abbrev (".debug_abbrev");
-                static ConstString g_sect_name_dwarf_debug_aranges (".debug_aranges");
-                static ConstString g_sect_name_dwarf_debug_frame (".debug_frame");
-                static ConstString g_sect_name_dwarf_debug_info (".debug_info");
-                static ConstString g_sect_name_dwarf_debug_line (".debug_line");
-                static ConstString g_sect_name_dwarf_debug_loc (".debug_loc");
-                static ConstString g_sect_name_dwarf_debug_macinfo (".debug_macinfo");
-                static ConstString g_sect_name_dwarf_debug_pubnames (".debug_pubnames");
-                static ConstString g_sect_name_dwarf_debug_pubtypes (".debug_pubtypes");
-                static ConstString g_sect_name_dwarf_debug_ranges (".debug_ranges");
-                static ConstString g_sect_name_dwarf_debug_str (".debug_str");
-                static ConstString g_sect_name_eh_frame (".eh_frame");
-                static ConstString g_sect_name_go_symtab (".gosymtab");
-                SectionType section_type = eSectionTypeOther;
-                if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_CODE &&
-                    ((const_sect_name == g_code_sect_name) || (const_sect_name == g_CODE_sect_name)))
-                {
-                    section_type = eSectionTypeCode;
-                }
-                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA &&
-                         ((const_sect_name == g_data_sect_name) || (const_sect_name == g_DATA_sect_name)))
-                {
-                    section_type = eSectionTypeData;
-                }
-                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA &&
-                         ((const_sect_name == g_bss_sect_name) || (const_sect_name == g_BSS_sect_name)))
-                {
-                    if (m_sect_headers[idx].size == 0)
-                        section_type = eSectionTypeZeroFill;
-                    else
-                        section_type = eSectionTypeData;
-                }
-                else if (const_sect_name == g_debug_sect_name)
-                {
-                    section_type = eSectionTypeDebug;
-                }
-                else if (const_sect_name == g_stabstr_sect_name)
-                {
-                    section_type = eSectionTypeDataCString;
-                }
-                else if (const_sect_name == g_reloc_sect_name)
-                {
-                    section_type = eSectionTypeOther;
-                }
-                else if (const_sect_name == g_sect_name_dwarf_debug_abbrev)    section_type = eSectionTypeDWARFDebugAbbrev;
-                else if (const_sect_name == g_sect_name_dwarf_debug_aranges)   section_type = eSectionTypeDWARFDebugAranges;
-                else if (const_sect_name == g_sect_name_dwarf_debug_frame)     section_type = eSectionTypeDWARFDebugFrame;
-                else if (const_sect_name == g_sect_name_dwarf_debug_info)      section_type = eSectionTypeDWARFDebugInfo;
-                else if (const_sect_name == g_sect_name_dwarf_debug_line)      section_type = eSectionTypeDWARFDebugLine;
-                else if (const_sect_name == g_sect_name_dwarf_debug_loc)       section_type = eSectionTypeDWARFDebugLoc;
-                else if (const_sect_name == g_sect_name_dwarf_debug_macinfo)   section_type = eSectionTypeDWARFDebugMacInfo;
-                else if (const_sect_name == g_sect_name_dwarf_debug_pubnames)  section_type = eSectionTypeDWARFDebugPubNames;
-                else if (const_sect_name == g_sect_name_dwarf_debug_pubtypes)  section_type = eSectionTypeDWARFDebugPubTypes;
-                else if (const_sect_name == g_sect_name_dwarf_debug_ranges)    section_type = eSectionTypeDWARFDebugRanges;
-                else if (const_sect_name == g_sect_name_dwarf_debug_str)       section_type = eSectionTypeDWARFDebugStr;
-                else if (const_sect_name == g_sect_name_eh_frame)              section_type = eSectionTypeEHFrame;
-                else if (const_sect_name == g_sect_name_go_symtab)             section_type = eSectionTypeGoSymtab;
-                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_CODE)
-                {
-                    section_type = eSectionTypeCode;
-                }
-                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
-                {
-                    section_type = eSectionTypeData;
-                }
-                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
-                {
-                    if (m_sect_headers[idx].size == 0)
-                        section_type = eSectionTypeZeroFill;
-                    else
-                        section_type = eSectionTypeData;
-                }
-
-                // Use a segment ID of the segment index shifted left by 8 so they
-                // never conflict with any of the sections.
-                SectionSP section_sp (new Section (module_sp,                    // Module to which this section belongs
-                                                   this,                         // Object file to which this section belongs
-                                                   idx + 1,                      // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
-                                                   const_sect_name,              // Name of this section
-                                                   section_type,                 // This section is a container of other sections.
-                                                   m_coff_header_opt.image_base + m_sect_headers[idx].vmaddr,   // File VM address == addresses as they are found in the object file
-                                                   m_sect_headers[idx].vmsize,   // VM size in bytes of this section
-                                                   m_sect_headers[idx].offset,   // Offset to the data for this section in the file
-                                                   m_sect_headers[idx].size,     // Size in bytes of this section as found in the file
-                                                   m_coff_header_opt.sect_alignment, // Section alignment
-                                                   m_sect_headers[idx].flags));  // Flags for this section
-
-                //section_sp->SetIsEncrypted (segment_is_encrypted);
-
-                unified_section_list.AddSection(section_sp);
-                m_sections_ap->AddSection (section_sp);
-            }
+    ModuleSP module_sp(GetModule());
+    if (module_sp) {
+      std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+      const uint32_t nsects = m_sect_headers.size();
+      ModuleSP module_sp(GetModule());
+      for (uint32_t idx = 0; idx < nsects; ++idx) {
+        std::string sect_name;
+        GetSectionName(sect_name, m_sect_headers[idx]);
+        ConstString const_sect_name(sect_name.c_str());
+        static ConstString g_code_sect_name(".code");
+        static ConstString g_CODE_sect_name("CODE");
+        static ConstString g_data_sect_name(".data");
+        static ConstString g_DATA_sect_name("DATA");
+        static ConstString g_bss_sect_name(".bss");
+        static ConstString g_BSS_sect_name("BSS");
+        static ConstString g_debug_sect_name(".debug");
+        static ConstString g_reloc_sect_name(".reloc");
+        static ConstString g_stab_sect_name(".stab");
+        static ConstString g_stabstr_sect_name(".stabstr");
+        static ConstString g_sect_name_dwarf_debug_abbrev(".debug_abbrev");
+        static ConstString g_sect_name_dwarf_debug_aranges(".debug_aranges");
+        static ConstString g_sect_name_dwarf_debug_frame(".debug_frame");
+        static ConstString g_sect_name_dwarf_debug_info(".debug_info");
+        static ConstString g_sect_name_dwarf_debug_line(".debug_line");
+        static ConstString g_sect_name_dwarf_debug_loc(".debug_loc");
+        static ConstString g_sect_name_dwarf_debug_macinfo(".debug_macinfo");
+        static ConstString g_sect_name_dwarf_debug_pubnames(".debug_pubnames");
+        static ConstString g_sect_name_dwarf_debug_pubtypes(".debug_pubtypes");
+        static ConstString g_sect_name_dwarf_debug_ranges(".debug_ranges");
+        static ConstString g_sect_name_dwarf_debug_str(".debug_str");
+        static ConstString g_sect_name_eh_frame(".eh_frame");
+        static ConstString g_sect_name_go_symtab(".gosymtab");
+        SectionType section_type = eSectionTypeOther;
+        if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_CODE &&
+            ((const_sect_name == g_code_sect_name) ||
+             (const_sect_name == g_CODE_sect_name))) {
+          section_type = eSectionTypeCode;
+        } else if (m_sect_headers[idx].flags &
+                       llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA &&
+                   ((const_sect_name == g_data_sect_name) ||
+                    (const_sect_name == g_DATA_sect_name))) {
+          section_type = eSectionTypeData;
+        } else if (m_sect_headers[idx].flags &
+                       llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA &&
+                   ((const_sect_name == g_bss_sect_name) ||
+                    (const_sect_name == g_BSS_sect_name))) {
+          if (m_sect_headers[idx].size == 0)
+            section_type = eSectionTypeZeroFill;
+          else
+            section_type = eSectionTypeData;
+        } else if (const_sect_name == g_debug_sect_name) {
+          section_type = eSectionTypeDebug;
+        } else if (const_sect_name == g_stabstr_sect_name) {
+          section_type = eSectionTypeDataCString;
+        } else if (const_sect_name == g_reloc_sect_name) {
+          section_type = eSectionTypeOther;
+        } else if (const_sect_name == g_sect_name_dwarf_debug_abbrev)
+          section_type = eSectionTypeDWARFDebugAbbrev;
+        else if (const_sect_name == g_sect_name_dwarf_debug_aranges)
+          section_type = eSectionTypeDWARFDebugAranges;
+        else if (const_sect_name == g_sect_name_dwarf_debug_frame)
+          section_type = eSectionTypeDWARFDebugFrame;
+        else if (const_sect_name == g_sect_name_dwarf_debug_info)
+          section_type = eSectionTypeDWARFDebugInfo;
+        else if (const_sect_name == g_sect_name_dwarf_debug_line)
+          section_type = eSectionTypeDWARFDebugLine;
+        else if (const_sect_name == g_sect_name_dwarf_debug_loc)
+          section_type = eSectionTypeDWARFDebugLoc;
+        else if (const_sect_name == g_sect_name_dwarf_debug_macinfo)
+          section_type = eSectionTypeDWARFDebugMacInfo;
+        else if (const_sect_name == g_sect_name_dwarf_debug_pubnames)
+          section_type = eSectionTypeDWARFDebugPubNames;
+        else if (const_sect_name == g_sect_name_dwarf_debug_pubtypes)
+          section_type = eSectionTypeDWARFDebugPubTypes;
+        else if (const_sect_name == g_sect_name_dwarf_debug_ranges)
+          section_type = eSectionTypeDWARFDebugRanges;
+        else if (const_sect_name == g_sect_name_dwarf_debug_str)
+          section_type = eSectionTypeDWARFDebugStr;
+        else if (const_sect_name == g_sect_name_eh_frame)
+          section_type = eSectionTypeEHFrame;
+        else if (const_sect_name == g_sect_name_go_symtab)
+          section_type = eSectionTypeGoSymtab;
+        else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_CODE) {
+          section_type = eSectionTypeCode;
+        } else if (m_sect_headers[idx].flags &
+                   llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA) {
+          section_type = eSectionTypeData;
+        } else if (m_sect_headers[idx].flags &
+                   llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) {
+          if (m_sect_headers[idx].size == 0)
+            section_type = eSectionTypeZeroFill;
+          else
+            section_type = eSectionTypeData;
         }
-    }
-}
 
-bool
-ObjectFilePECOFF::GetUUID (UUID* uuid)
-{
-    return false;
+        // Use a segment ID of the segment index shifted left by 8 so they
+        // never conflict with any of the sections.
+        SectionSP section_sp(new Section(
+            module_sp, // Module to which this section belongs
+            this,      // Object file to which this section belongs
+            idx + 1, // Section ID is the 1 based segment index shifted right by
+                     // 8 bits as not to collide with any of the 256 section IDs
+                     // that are possible
+            const_sect_name, // Name of this section
+            section_type,    // This section is a container of other sections.
+            m_coff_header_opt.image_base +
+                m_sect_headers[idx].vmaddr, // File VM address == addresses as
+                                            // they are found in the object file
+            m_sect_headers[idx].vmsize,     // VM size in bytes of this section
+            m_sect_headers[idx]
+                .offset, // Offset to the data for this section in the file
+            m_sect_headers[idx]
+                .size, // Size in bytes of this section as found in the file
+            m_coff_header_opt.sect_alignment, // Section alignment
+            m_sect_headers[idx].flags));      // Flags for this section
+
+        // section_sp->SetIsEncrypted (segment_is_encrypted);
+
+        unified_section_list.AddSection(section_sp);
+        m_sections_ap->AddSection(section_sp);
+      }
+    }
+  }
 }
 
-uint32_t
-ObjectFilePECOFF::GetDependentModules (FileSpecList& files)
-{
-    return 0;
+bool ObjectFilePECOFF::GetUUID(UUID *uuid) { return false; }
+
+uint32_t ObjectFilePECOFF::GetDependentModules(FileSpecList &files) {
+  return 0;
 }
 
-lldb_private::Address
-ObjectFilePECOFF::GetEntryPointAddress ()
-{
-    if (m_entry_point_address.IsValid())
-        return m_entry_point_address;
+lldb_private::Address ObjectFilePECOFF::GetEntryPointAddress() {
+  if (m_entry_point_address.IsValid())
+    return m_entry_point_address;
 
-    if (!ParseHeader() || !IsExecutable())
-        return m_entry_point_address;
+  if (!ParseHeader() || !IsExecutable())
+    return m_entry_point_address;
 
-    SectionList *section_list = GetSectionList();
-    addr_t offset = m_coff_header_opt.entry;
+  SectionList *section_list = GetSectionList();
+  addr_t offset = m_coff_header_opt.entry;
 
-    if (!section_list)
-        m_entry_point_address.SetOffset(offset);
-    else
-        m_entry_point_address.ResolveAddressUsingFileSections(offset, section_list);
-    return m_entry_point_address;
+  if (!section_list)
+    m_entry_point_address.SetOffset(offset);
+  else
+    m_entry_point_address.ResolveAddressUsingFileSections(offset, section_list);
+  return m_entry_point_address;
 }
 
-
 //----------------------------------------------------------------------
 // Dump
 //
 // Dump the specifics of the runtime file container (such as any headers
 // segments, sections, etc).
 //----------------------------------------------------------------------
-void 
-ObjectFilePECOFF::Dump(Stream *s)
-{
-    ModuleSP module_sp(GetModule());
-    if (module_sp)
-    {
-        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-        s->Printf("%p: ", static_cast<void*>(this));
-        s->Indent();
-        s->PutCString("ObjectFilePECOFF");
-
-        ArchSpec header_arch;
-        GetArchitecture (header_arch);
-
-        *s << ", file = '" << m_file << "', arch = " << header_arch.GetArchitectureName() << "\n";
-
-        SectionList *sections = GetSectionList();
-        if (sections)
-            sections->Dump(s, NULL, true, UINT32_MAX);
-
-        if (m_symtab_ap.get())
-            m_symtab_ap->Dump(s, NULL, eSortOrderNone);
-
-        if (m_dos_header.e_magic)
-            DumpDOSHeader (s, m_dos_header);
-        if (m_coff_header.machine)
-        {
-            DumpCOFFHeader (s, m_coff_header);
-            if (m_coff_header.hdrsize)
-                DumpOptCOFFHeader (s, m_coff_header_opt);
-        }
-        s->EOL();
-        DumpSectionHeaders(s);
-        s->EOL();
-    }
+void ObjectFilePECOFF::Dump(Stream *s) {
+  ModuleSP module_sp(GetModule());
+  if (module_sp) {
+    std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+    s->Printf("%p: ", static_cast<void *>(this));
+    s->Indent();
+    s->PutCString("ObjectFilePECOFF");
+
+    ArchSpec header_arch;
+    GetArchitecture(header_arch);
+
+    *s << ", file = '" << m_file
+       << "', arch = " << header_arch.GetArchitectureName() << "\n";
+
+    SectionList *sections = GetSectionList();
+    if (sections)
+      sections->Dump(s, NULL, true, UINT32_MAX);
+
+    if (m_symtab_ap.get())
+      m_symtab_ap->Dump(s, NULL, eSortOrderNone);
+
+    if (m_dos_header.e_magic)
+      DumpDOSHeader(s, m_dos_header);
+    if (m_coff_header.machine) {
+      DumpCOFFHeader(s, m_coff_header);
+      if (m_coff_header.hdrsize)
+        DumpOptCOFFHeader(s, m_coff_header_opt);
+    }
+    s->EOL();
+    DumpSectionHeaders(s);
+    s->EOL();
+  }
 }
 
 //----------------------------------------------------------------------
@@ -883,43 +805,33 @@ ObjectFilePECOFF::Dump(Stream *s)
 //
 // Dump the MS-DOS header to the specified output stream
 //----------------------------------------------------------------------
-void
-ObjectFilePECOFF::DumpDOSHeader(Stream *s, const dos_header_t& header)
-{
-    s->PutCString ("MSDOS Header\n");
-    s->Printf ("  e_magic    = 0x%4.4x\n", header.e_magic);
-    s->Printf ("  e_cblp     = 0x%4.4x\n", header.e_cblp);
-    s->Printf ("  e_cp       = 0x%4.4x\n", header.e_cp);
-    s->Printf ("  e_crlc     = 0x%4.4x\n", header.e_crlc);
-    s->Printf ("  e_cparhdr  = 0x%4.4x\n", header.e_cparhdr);
-    s->Printf ("  e_minalloc = 0x%4.4x\n", header.e_minalloc);
-    s->Printf ("  e_maxalloc = 0x%4.4x\n", header.e_maxalloc);
-    s->Printf ("  e_ss       = 0x%4.4x\n", header.e_ss);
-    s->Printf ("  e_sp       = 0x%4.4x\n", header.e_sp);
-    s->Printf ("  e_csum     = 0x%4.4x\n", header.e_csum);
-    s->Printf ("  e_ip       = 0x%4.4x\n", header.e_ip);
-    s->Printf ("  e_cs       = 0x%4.4x\n", header.e_cs);
-    s->Printf ("  e_lfarlc   = 0x%4.4x\n", header.e_lfarlc);
-    s->Printf ("  e_ovno     = 0x%4.4x\n", header.e_ovno);
-    s->Printf ("  e_res[4]   = { 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x }\n",
-               header.e_res[0],
-               header.e_res[1],
-               header.e_res[2],
-               header.e_res[3]);
-    s->Printf ("  e_oemid    = 0x%4.4x\n", header.e_oemid);
-    s->Printf ("  e_oeminfo  = 0x%4.4x\n", header.e_oeminfo);
-    s->Printf ("  e_res2[10] = { 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x }\n",
-               header.e_res2[0],
-               header.e_res2[1],
-               header.e_res2[2],
-               header.e_res2[3],
-               header.e_res2[4],
-               header.e_res2[5],
-               header.e_res2[6],
-               header.e_res2[7],
-               header.e_res2[8],
-               header.e_res2[9]);
-    s->Printf ("  e_lfanew   = 0x%8.8x\n", header.e_lfanew);
+void ObjectFilePECOFF::DumpDOSHeader(Stream *s, const dos_header_t &header) {
+  s->PutCString("MSDOS Header\n");
+  s->Printf("  e_magic    = 0x%4.4x\n", header.e_magic);
+  s->Printf("  e_cblp     = 0x%4.4x\n", header.e_cblp);
+  s->Printf("  e_cp       = 0x%4.4x\n", header.e_cp);
+  s->Printf("  e_crlc     = 0x%4.4x\n", header.e_crlc);
+  s->Printf("  e_cparhdr  = 0x%4.4x\n", header.e_cparhdr);
+  s->Printf("  e_minalloc = 0x%4.4x\n", header.e_minalloc);
+  s->Printf("  e_maxalloc = 0x%4.4x\n", header.e_maxalloc);
+  s->Printf("  e_ss       = 0x%4.4x\n", header.e_ss);
+  s->Printf("  e_sp       = 0x%4.4x\n", header.e_sp);
+  s->Printf("  e_csum     = 0x%4.4x\n", header.e_csum);
+  s->Printf("  e_ip       = 0x%4.4x\n", header.e_ip);
+  s->Printf("  e_cs       = 0x%4.4x\n", header.e_cs);
+  s->Printf("  e_lfarlc   = 0x%4.4x\n", header.e_lfarlc);
+  s->Printf("  e_ovno     = 0x%4.4x\n", header.e_ovno);
+  s->Printf("  e_res[4]   = { 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x }\n",
+            header.e_res[0], header.e_res[1], header.e_res[2], header.e_res[3]);
+  s->Printf("  e_oemid    = 0x%4.4x\n", header.e_oemid);
+  s->Printf("  e_oeminfo  = 0x%4.4x\n", header.e_oeminfo);
+  s->Printf("  e_res2[10] = { 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, "
+            "0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x }\n",
+            header.e_res2[0], header.e_res2[1], header.e_res2[2],
+            header.e_res2[3], header.e_res2[4], header.e_res2[5],
+            header.e_res2[6], header.e_res2[7], header.e_res2[8],
+            header.e_res2[9]);
+  s->Printf("  e_lfanew   = 0x%8.8x\n", header.e_lfanew);
 }
 
 //----------------------------------------------------------------------
@@ -927,16 +839,14 @@ ObjectFilePECOFF::DumpDOSHeader(Stream *
 //
 // Dump the COFF header to the specified output stream
 //----------------------------------------------------------------------
-void
-ObjectFilePECOFF::DumpCOFFHeader(Stream *s, const coff_header_t& header)
-{
-    s->PutCString ("COFF Header\n");
-    s->Printf ("  machine = 0x%4.4x\n", header.machine);
-    s->Printf ("  nsects  = 0x%4.4x\n", header.nsects);
-    s->Printf ("  modtime = 0x%8.8x\n", header.modtime);
-    s->Printf ("  symoff  = 0x%8.8x\n", header.symoff);
-    s->Printf ("  nsyms   = 0x%8.8x\n", header.nsyms);
-    s->Printf ("  hdrsize = 0x%4.4x\n", header.hdrsize);
+void ObjectFilePECOFF::DumpCOFFHeader(Stream *s, const coff_header_t &header) {
+  s->PutCString("COFF Header\n");
+  s->Printf("  machine = 0x%4.4x\n", header.machine);
+  s->Printf("  nsects  = 0x%4.4x\n", header.nsects);
+  s->Printf("  modtime = 0x%8.8x\n", header.modtime);
+  s->Printf("  symoff  = 0x%8.8x\n", header.symoff);
+  s->Printf("  nsyms   = 0x%8.8x\n", header.nsyms);
+  s->Printf("  hdrsize = 0x%4.4x\n", header.hdrsize);
 }
 
 //----------------------------------------------------------------------
@@ -944,147 +854,128 @@ ObjectFilePECOFF::DumpCOFFHeader(Stream
 //
 // Dump the optional COFF header to the specified output stream
 //----------------------------------------------------------------------
-void
-ObjectFilePECOFF::DumpOptCOFFHeader(Stream *s, const coff_opt_header_t& header)
-{
-    s->PutCString ("Optional COFF Header\n");
-    s->Printf ("  magic                   = 0x%4.4x\n", header.magic);
-    s->Printf ("  major_linker_version    = 0x%2.2x\n", header.major_linker_version);
-    s->Printf ("  minor_linker_version    = 0x%2.2x\n", header.minor_linker_version);
-    s->Printf ("  code_size               = 0x%8.8x\n", header.code_size);
-    s->Printf ("  data_size               = 0x%8.8x\n", header.data_size);
-    s->Printf ("  bss_size                = 0x%8.8x\n", header.bss_size);
-    s->Printf ("  entry                   = 0x%8.8x\n", header.entry);
-    s->Printf ("  code_offset             = 0x%8.8x\n", header.code_offset);
-    s->Printf ("  data_offset             = 0x%8.8x\n", header.data_offset);
-    s->Printf ("  image_base              = 0x%16.16" PRIx64 "\n", header.image_base);
-    s->Printf ("  sect_alignment          = 0x%8.8x\n", header.sect_alignment);
-    s->Printf ("  file_alignment          = 0x%8.8x\n", header.file_alignment);
-    s->Printf ("  major_os_system_version = 0x%4.4x\n", header.major_os_system_version);
-    s->Printf ("  minor_os_system_version = 0x%4.4x\n", header.minor_os_system_version);
-    s->Printf ("  major_image_version     = 0x%4.4x\n", header.major_image_version);
-    s->Printf ("  minor_image_version     = 0x%4.4x\n", header.minor_image_version);
-    s->Printf ("  major_subsystem_version = 0x%4.4x\n", header.major_subsystem_version);
-    s->Printf ("  minor_subsystem_version = 0x%4.4x\n", header.minor_subsystem_version);
-    s->Printf ("  reserved1               = 0x%8.8x\n", header.reserved1);
-    s->Printf ("  image_size              = 0x%8.8x\n", header.image_size);
-    s->Printf ("  header_size             = 0x%8.8x\n", header.header_size);
-    s->Printf ("  checksum                = 0x%8.8x\n", header.checksum);
-    s->Printf ("  subsystem               = 0x%4.4x\n", header.subsystem);
-    s->Printf ("  dll_flags               = 0x%4.4x\n", header.dll_flags);
-    s->Printf ("  stack_reserve_size      = 0x%16.16" PRIx64 "\n", header.stack_reserve_size);
-    s->Printf ("  stack_commit_size       = 0x%16.16" PRIx64 "\n", header.stack_commit_size);
-    s->Printf ("  heap_reserve_size       = 0x%16.16" PRIx64 "\n", header.heap_reserve_size);
-    s->Printf ("  heap_commit_size        = 0x%16.16" PRIx64 "\n", header.heap_commit_size);
-    s->Printf ("  loader_flags            = 0x%8.8x\n", header.loader_flags);
-    s->Printf ("  num_data_dir_entries    = 0x%8.8x\n", (uint32_t)header.data_dirs.size());
-    uint32_t i;
-    for (i=0; i<header.data_dirs.size(); i++)
-    {
-        s->Printf ("  data_dirs[%2u] vmaddr = 0x%8.8x, vmsize = 0x%8.8x\n", 
-                   i,
-                   header.data_dirs[i].vmaddr,
-                   header.data_dirs[i].vmsize);
-    }
+void ObjectFilePECOFF::DumpOptCOFFHeader(Stream *s,
+                                         const coff_opt_header_t &header) {
+  s->PutCString("Optional COFF Header\n");
+  s->Printf("  magic                   = 0x%4.4x\n", header.magic);
+  s->Printf("  major_linker_version    = 0x%2.2x\n",
+            header.major_linker_version);
+  s->Printf("  minor_linker_version    = 0x%2.2x\n",
+            header.minor_linker_version);
+  s->Printf("  code_size               = 0x%8.8x\n", header.code_size);
+  s->Printf("  data_size               = 0x%8.8x\n", header.data_size);
+  s->Printf("  bss_size                = 0x%8.8x\n", header.bss_size);
+  s->Printf("  entry                   = 0x%8.8x\n", header.entry);
+  s->Printf("  code_offset             = 0x%8.8x\n", header.code_offset);
+  s->Printf("  data_offset             = 0x%8.8x\n", header.data_offset);
+  s->Printf("  image_base              = 0x%16.16" PRIx64 "\n",
+            header.image_base);
+  s->Printf("  sect_alignment          = 0x%8.8x\n", header.sect_alignment);
+  s->Printf("  file_alignment          = 0x%8.8x\n", header.file_alignment);
+  s->Printf("  major_os_system_version = 0x%4.4x\n",
+            header.major_os_system_version);
+  s->Printf("  minor_os_system_version = 0x%4.4x\n",
+            header.minor_os_system_version);
+  s->Printf("  major_image_version     = 0x%4.4x\n",
+            header.major_image_version);
+  s->Printf("  minor_image_version     = 0x%4.4x\n",
+            header.minor_image_version);
+  s->Printf("  major_subsystem_version = 0x%4.4x\n",
+            header.major_subsystem_version);
+  s->Printf("  minor_subsystem_version = 0x%4.4x\n",
+            header.minor_subsystem_version);
+  s->Printf("  reserved1               = 0x%8.8x\n", header.reserved1);
+  s->Printf("  image_size              = 0x%8.8x\n", header.image_size);
+  s->Printf("  header_size             = 0x%8.8x\n", header.header_size);
+  s->Printf("  checksum                = 0x%8.8x\n", header.checksum);
+  s->Printf("  subsystem               = 0x%4.4x\n", header.subsystem);
+  s->Printf("  dll_flags               = 0x%4.4x\n", header.dll_flags);
+  s->Printf("  stack_reserve_size      = 0x%16.16" PRIx64 "\n",
+            header.stack_reserve_size);
+  s->Printf("  stack_commit_size       = 0x%16.16" PRIx64 "\n",
+            header.stack_commit_size);
+  s->Printf("  heap_reserve_size       = 0x%16.16" PRIx64 "\n",
+            header.heap_reserve_size);
+  s->Printf("  heap_commit_size        = 0x%16.16" PRIx64 "\n",
+            header.heap_commit_size);
+  s->Printf("  loader_flags            = 0x%8.8x\n", header.loader_flags);
+  s->Printf("  num_data_dir_entries    = 0x%8.8x\n",
+            (uint32_t)header.data_dirs.size());
+  uint32_t i;
+  for (i = 0; i < header.data_dirs.size(); i++) {
+    s->Printf("  data_dirs[%2u] vmaddr = 0x%8.8x, vmsize = 0x%8.8x\n", i,
+              header.data_dirs[i].vmaddr, header.data_dirs[i].vmsize);
+  }
 }
 //----------------------------------------------------------------------
 // DumpSectionHeader
 //
 // Dump a single ELF section header to the specified output stream
 //----------------------------------------------------------------------
-void
-ObjectFilePECOFF::DumpSectionHeader(Stream *s, const section_header_t& sh)
-{
-    std::string name;
-    GetSectionName(name, sh);
-    s->Printf ("%-16s 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%4.4x 0x%4.4x 0x%8.8x\n",
-               name.c_str(),
-               sh.vmaddr,
-               sh.vmsize,
-               sh.offset,
-               sh.size,
-               sh.reloff,
-               sh.lineoff,
-               sh.nreloc,
-               sh.nline,
-               sh.flags);
+void ObjectFilePECOFF::DumpSectionHeader(Stream *s,
+                                         const section_header_t &sh) {
+  std::string name;
+  GetSectionName(name, sh);
+  s->Printf("%-16s 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%4.4x "
+            "0x%4.4x 0x%8.8x\n",
+            name.c_str(), sh.vmaddr, sh.vmsize, sh.offset, sh.size, sh.reloff,
+            sh.lineoff, sh.nreloc, sh.nline, sh.flags);
 }
 
-
 //----------------------------------------------------------------------
 // DumpSectionHeaders
 //
 // Dump all of the ELF section header to the specified output stream
 //----------------------------------------------------------------------
-void
-ObjectFilePECOFF::DumpSectionHeaders(Stream *s)
-{
-    
-    s->PutCString ("Section Headers\n");
-    s->PutCString ("IDX  name             vm addr    vm size    file off   file size  reloc off  line off   nreloc nline  flags\n");
-    s->PutCString ("==== ---------------- ---------- ---------- ---------- ---------- ---------- ---------- ------ ------ ----------\n");
-    
-    uint32_t idx = 0;
-    SectionHeaderCollIter pos, end = m_sect_headers.end();
-    
-    for (pos = m_sect_headers.begin(); pos != end; ++pos, ++idx)
-    {
-        s->Printf ("[%2u] ", idx);
-        ObjectFilePECOFF::DumpSectionHeader(s, *pos);
-    }
-}
+void ObjectFilePECOFF::DumpSectionHeaders(Stream *s) {
 
-bool
-ObjectFilePECOFF::GetArchitecture (ArchSpec &arch)
-{
-    uint16_t machine = m_coff_header.machine;
-    switch (machine)
-    {
-        case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
-        case llvm::COFF::IMAGE_FILE_MACHINE_I386:
-        case llvm::COFF::IMAGE_FILE_MACHINE_POWERPC:
-        case llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP:
-        case llvm::COFF::IMAGE_FILE_MACHINE_ARM:
-        case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
-        case llvm::COFF::IMAGE_FILE_MACHINE_THUMB:
-            arch.SetArchitecture (eArchTypeCOFF, machine, LLDB_INVALID_CPUTYPE);
-            return true;
-        default:
-            break;
-    }
-    return false;
+  s->PutCString("Section Headers\n");
+  s->PutCString("IDX  name             vm addr    vm size    file off   file "
+                "size  reloc off  line off   nreloc nline  flags\n");
+  s->PutCString("==== ---------------- ---------- ---------- ---------- "
+                "---------- ---------- ---------- ------ ------ ----------\n");
+
+  uint32_t idx = 0;
+  SectionHeaderCollIter pos, end = m_sect_headers.end();
+
+  for (pos = m_sect_headers.begin(); pos != end; ++pos, ++idx) {
+    s->Printf("[%2u] ", idx);
+    ObjectFilePECOFF::DumpSectionHeader(s, *pos);
+  }
+}
+
+bool ObjectFilePECOFF::GetArchitecture(ArchSpec &arch) {
+  uint16_t machine = m_coff_header.machine;
+  switch (machine) {
+  case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+  case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+  case llvm::COFF::IMAGE_FILE_MACHINE_POWERPC:
+  case llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP:
+  case llvm::COFF::IMAGE_FILE_MACHINE_ARM:
+  case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
+  case llvm::COFF::IMAGE_FILE_MACHINE_THUMB:
+    arch.SetArchitecture(eArchTypeCOFF, machine, LLDB_INVALID_CPUTYPE);
+    return true;
+  default:
+    break;
+  }
+  return false;
 }
 
-ObjectFile::Type
-ObjectFilePECOFF::CalculateType()
-{
-    if (m_coff_header.machine != 0)
-    {
-        if ((m_coff_header.flags & llvm::COFF::IMAGE_FILE_DLL) == 0)
-            return eTypeExecutable;
-        else
-            return eTypeSharedLibrary;
-    }
-    return eTypeExecutable;
+ObjectFile::Type ObjectFilePECOFF::CalculateType() {
+  if (m_coff_header.machine != 0) {
+    if ((m_coff_header.flags & llvm::COFF::IMAGE_FILE_DLL) == 0)
+      return eTypeExecutable;
+    else
+      return eTypeSharedLibrary;
+  }
+  return eTypeExecutable;
 }
 
-ObjectFile::Strata
-ObjectFilePECOFF::CalculateStrata()
-{
-    return eStrataUser;
-}
+ObjectFile::Strata ObjectFilePECOFF::CalculateStrata() { return eStrataUser; }
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
-ConstString
-ObjectFilePECOFF::GetPluginName()
-{
-    return GetPluginNameStatic();
-}
-
-uint32_t
-ObjectFilePECOFF::GetPluginVersion()
-{
-    return 1;
-}
+ConstString ObjectFilePECOFF::GetPluginName() { return GetPluginNameStatic(); }
 
+uint32_t ObjectFilePECOFF::GetPluginVersion() { return 1; }

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h Tue Sep  6 15:57:50 2016
@@ -18,290 +18,262 @@
 // Project includes
 #include "lldb/Symbol/ObjectFile.h"
 
-class ObjectFilePECOFF : 
-    public lldb_private::ObjectFile
-{
+class ObjectFilePECOFF : public lldb_private::ObjectFile {
 public:
-    typedef enum MachineType
-    {
-        MachineUnknown = 0x0,
-        MachineAm33 = 0x1d3,
-        MachineAmd64 = 0x8664,
-        MachineArm = 0x1c0,
-        MachineArmNt = 0x1c4,
-        MachineArm64 = 0xaa64,
-        MachineEbc = 0xebc,
-        MachineX86 = 0x14c,
-        MachineIA64 = 0x200,
-        MachineM32R = 0x9041,
-        MachineMips16 = 0x266,
-        MachineMipsFpu = 0x366,
-        MachineMipsFpu16 = 0x466,
-        MachinePowerPc = 0x1f0,
-        MachinePowerPcfp = 0x1f1,
-        MachineR4000 = 0x166,
-        MachineSh3 = 0x1a2,
-        MachineSh3dsp = 0x1a3,
-        MachineSh4 = 0x1a6,
-        MachineSh5 = 0x1a8,
-        MachineThumb = 0x1c2,
-        MachineWcemIpsv2 = 0x169
-    } MachineType;
-    
-    ObjectFilePECOFF(const lldb::ModuleSP &module_sp,
-                     lldb::DataBufferSP& data_sp,
-                     lldb::offset_t data_offset,
-                     const lldb_private::FileSpec* file,
-                     lldb::offset_t file_offset,
-                     lldb::offset_t length);
-
-    ~ObjectFilePECOFF() override;
-
-    //------------------------------------------------------------------
-    // Static Functions
-    //------------------------------------------------------------------
-    static void
-    Initialize();
-    
-    static void
-    Terminate();
-    
-    static lldb_private::ConstString
-    GetPluginNameStatic();
-    
-    static const char *
-    GetPluginDescriptionStatic();
-    
-    static ObjectFile *
-    CreateInstance (const lldb::ModuleSP &module_sp,
-                    lldb::DataBufferSP& data_sp,
-                    lldb::offset_t data_offset,
-                    const lldb_private::FileSpec* file,
-                    lldb::offset_t offset,
-                    lldb::offset_t length);
-    
-    static lldb_private::ObjectFile *
-    CreateMemoryInstance (const lldb::ModuleSP &module_sp, 
-                          lldb::DataBufferSP& data_sp, 
-                          const lldb::ProcessSP &process_sp, 
-                          lldb::addr_t header_addr);
-    
-    static size_t
-    GetModuleSpecifications (const lldb_private::FileSpec& file,
-                             lldb::DataBufferSP& data_sp,
-                             lldb::offset_t data_offset,
-                             lldb::offset_t file_offset,
-                             lldb::offset_t length,
-                             lldb_private::ModuleSpecList &specs);
-
-    static bool
-    SaveCore (const lldb::ProcessSP &process_sp,
-              const lldb_private::FileSpec &outfile,
-              lldb_private::Error &error);
-
-    static bool
-    MagicBytesMatch (lldb::DataBufferSP& data_sp);
-
-    static lldb::SymbolType
-    MapSymbolType(uint16_t coff_symbol_type);
-
-    bool
-    ParseHeader() override;
-    
-    bool
-    SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset) override;
-
-    lldb::ByteOrder
-    GetByteOrder() const override;
-    
-    bool
-    IsExecutable() const override;
-    
-    uint32_t
-    GetAddressByteSize() const override;
-
-//    virtual lldb_private::AddressClass
-//    GetAddressClass (lldb::addr_t file_addr);
-
-    lldb_private::Symtab *
-    GetSymtab() override;
-    
-    bool
-    IsStripped() override;
-
-    void
-    CreateSections(lldb_private::SectionList &unified_section_list) override;
-    
-    void
-    Dump(lldb_private::Stream *s) override;
-    
-    bool
-    GetArchitecture(lldb_private::ArchSpec &arch) override;
-    
-    bool
-    GetUUID(lldb_private::UUID* uuid) override;
-    
-    uint32_t
-    GetDependentModules(lldb_private::FileSpecList& files) override;
-    
-    virtual lldb_private::Address
-    GetEntryPointAddress () override;
-    
-    ObjectFile::Type
-    CalculateType() override;
-    
-    ObjectFile::Strata
-    CalculateStrata() override;
-    
-    //------------------------------------------------------------------
-    // PluginInterface protocol
-    //------------------------------------------------------------------
-    lldb_private::ConstString
-    GetPluginName() override;
-    
-    uint32_t
-    GetPluginVersion() override;
+  typedef enum MachineType {
+    MachineUnknown = 0x0,
+    MachineAm33 = 0x1d3,
+    MachineAmd64 = 0x8664,
+    MachineArm = 0x1c0,
+    MachineArmNt = 0x1c4,
+    MachineArm64 = 0xaa64,
+    MachineEbc = 0xebc,
+    MachineX86 = 0x14c,
+    MachineIA64 = 0x200,
+    MachineM32R = 0x9041,
+    MachineMips16 = 0x266,
+    MachineMipsFpu = 0x366,
+    MachineMipsFpu16 = 0x466,
+    MachinePowerPc = 0x1f0,
+    MachinePowerPcfp = 0x1f1,
+    MachineR4000 = 0x166,
+    MachineSh3 = 0x1a2,
+    MachineSh3dsp = 0x1a3,
+    MachineSh4 = 0x1a6,
+    MachineSh5 = 0x1a8,
+    MachineThumb = 0x1c2,
+    MachineWcemIpsv2 = 0x169
+  } MachineType;
+
+  ObjectFilePECOFF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+                   lldb::offset_t data_offset,
+                   const lldb_private::FileSpec *file,
+                   lldb::offset_t file_offset, lldb::offset_t length);
+
+  ~ObjectFilePECOFF() override;
+
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static const char *GetPluginDescriptionStatic();
+
+  static ObjectFile *
+  CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+                 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
+                 lldb::offset_t offset, lldb::offset_t length);
+
+  static lldb_private::ObjectFile *CreateMemoryInstance(
+      const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+      const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+
+  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
+                                        lldb::DataBufferSP &data_sp,
+                                        lldb::offset_t data_offset,
+                                        lldb::offset_t file_offset,
+                                        lldb::offset_t length,
+                                        lldb_private::ModuleSpecList &specs);
+
+  static bool SaveCore(const lldb::ProcessSP &process_sp,
+                       const lldb_private::FileSpec &outfile,
+                       lldb_private::Error &error);
+
+  static bool MagicBytesMatch(lldb::DataBufferSP &data_sp);
+
+  static lldb::SymbolType MapSymbolType(uint16_t coff_symbol_type);
+
+  bool ParseHeader() override;
+
+  bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
+                      bool value_is_offset) override;
+
+  lldb::ByteOrder GetByteOrder() const override;
+
+  bool IsExecutable() const override;
+
+  uint32_t GetAddressByteSize() const override;
+
+  //    virtual lldb_private::AddressClass
+  //    GetAddressClass (lldb::addr_t file_addr);
+
+  lldb_private::Symtab *GetSymtab() override;
+
+  bool IsStripped() override;
+
+  void CreateSections(lldb_private::SectionList &unified_section_list) override;
+
+  void Dump(lldb_private::Stream *s) override;
+
+  bool GetArchitecture(lldb_private::ArchSpec &arch) override;
+
+  bool GetUUID(lldb_private::UUID *uuid) override;
+
+  uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
+
+  virtual lldb_private::Address GetEntryPointAddress() override;
+
+  ObjectFile::Type CalculateType() override;
+
+  ObjectFile::Strata CalculateStrata() override;
+
+  //------------------------------------------------------------------
+  // PluginInterface protocol
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
 
 protected:
-	bool NeedsEndianSwap() const;    
-    
-	typedef struct dos_header  {  // DOS .EXE header
-		uint16_t e_magic;         // Magic number
-		uint16_t e_cblp;          // Bytes on last page of file
-		uint16_t e_cp;            // Pages in file
-		uint16_t e_crlc;          // Relocations
-		uint16_t e_cparhdr;       // Size of header in paragraphs
-		uint16_t e_minalloc;      // Minimum extra paragraphs needed
-		uint16_t e_maxalloc;      // Maximum extra paragraphs needed
-		uint16_t e_ss;            // Initial (relative) SS value
-		uint16_t e_sp;            // Initial SP value
-		uint16_t e_csum;          // Checksum
-		uint16_t e_ip;            // Initial IP value
-		uint16_t e_cs;            // Initial (relative) CS value
-		uint16_t e_lfarlc;        // File address of relocation table
-		uint16_t e_ovno;          // Overlay number
-		uint16_t e_res[4];        // Reserved words
-		uint16_t e_oemid;         // OEM identifier (for e_oeminfo)
-		uint16_t e_oeminfo;       // OEM information; e_oemid specific
-		uint16_t e_res2[10];      // Reserved words
-		uint32_t e_lfanew;        // File address of new exe header
-    } dos_header_t;
-    
-	typedef struct coff_header {
-		uint16_t machine;
-		uint16_t nsects;
-		uint32_t modtime;
-		uint32_t symoff;
-		uint32_t nsyms;
-		uint16_t hdrsize;
-		uint16_t flags;
-	} coff_header_t;
-    
-	typedef struct data_directory {
-		uint32_t vmaddr;
-		uint32_t vmsize;
-	} data_directory_t;
-    
-	typedef struct coff_opt_header 
-	{
-		uint16_t	magic;
-		uint8_t		major_linker_version;
-		uint8_t		minor_linker_version;
-		uint32_t	code_size;
-		uint32_t	data_size;
-		uint32_t	bss_size;
-		uint32_t	entry;
-		uint32_t	code_offset;
-		uint32_t	data_offset;
-        
-		uint64_t	image_base;
-		uint32_t	sect_alignment;
-		uint32_t	file_alignment;
-		uint16_t	major_os_system_version;
-		uint16_t	minor_os_system_version;
-		uint16_t	major_image_version;
-		uint16_t	minor_image_version;
-		uint16_t	major_subsystem_version;
-		uint16_t	minor_subsystem_version;
-		uint32_t	reserved1;
-		uint32_t	image_size;
-		uint32_t	header_size;
-		uint32_t	checksum;
-		uint16_t	subsystem;
-		uint16_t	dll_flags;
-		uint64_t	stack_reserve_size;
-		uint64_t	stack_commit_size;
-		uint64_t	heap_reserve_size;
-		uint64_t	heap_commit_size;
-		uint32_t	loader_flags;
-        //    uint32_t	num_data_dir_entries;
-		std::vector<data_directory> data_dirs;	// will contain num_data_dir_entries entries
-	} coff_opt_header_t;
-
-    typedef enum coff_data_dir_type
-    {
-        coff_data_dir_export_table = 0,
-        coff_data_dir_import_table = 1,
-    } coff_data_dir_type;
-    
-	typedef struct section_header {
-		char		name[8];
-		uint32_t	vmsize;	// Virtual Size
-		uint32_t	vmaddr;	// Virtual Addr
-		uint32_t	size;	// File size
-		uint32_t	offset;	// File offset
-		uint32_t	reloff;	// Offset to relocations
-		uint32_t	lineoff;// Offset to line table entries
-		uint16_t	nreloc;	// Number of relocation entries
-		uint16_t	nline;	// Number of line table entries
-		uint32_t	flags;
-	} section_header_t;
-    
-	typedef struct coff_symbol {
-		char		name[8];
-		uint32_t	value;
-		uint16_t	sect;
-		uint16_t	type;
-		uint8_t		storage;
-		uint8_t		naux;		
-	} coff_symbol_t;
-
-    typedef struct export_directory_entry {
-        uint32_t   characteristics;
-        uint32_t   time_date_stamp;
-        uint16_t   major_version;
-        uint16_t   minor_version;
-        uint32_t   name;
-        uint32_t   base;
-        uint32_t   number_of_functions;
-        uint32_t   number_of_names;
-        uint32_t   address_of_functions;
-        uint32_t   address_of_names;
-        uint32_t   address_of_name_ordinals;
-    } export_directory_entry;
-    
-	static bool ParseDOSHeader (lldb_private::DataExtractor &data, dos_header_t &dos_header);
-	static bool ParseCOFFHeader (lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr, coff_header_t &coff_header);
-	bool ParseCOFFOptionalHeader (lldb::offset_t *offset_ptr);
-	bool ParseSectionHeaders (uint32_t offset);
-	
-	static	void DumpDOSHeader(lldb_private::Stream *s, const dos_header_t& header);
-	static	void DumpCOFFHeader(lldb_private::Stream *s, const coff_header_t& header);
-	static	void DumpOptCOFFHeader(lldb_private::Stream *s, const coff_opt_header_t& header);
-    void DumpSectionHeaders(lldb_private::Stream *s);
-    void DumpSectionHeader(lldb_private::Stream *s, const section_header_t& sh);
-    bool GetSectionName(std::string& sect_name, const section_header_t& sect);
-    
-	typedef std::vector<section_header_t>		SectionHeaderColl;
-	typedef SectionHeaderColl::iterator			SectionHeaderCollIter;
-	typedef SectionHeaderColl::const_iterator	SectionHeaderCollConstIter;
+  bool NeedsEndianSwap() const;
+
+  typedef struct dos_header { // DOS .EXE header
+    uint16_t e_magic;         // Magic number
+    uint16_t e_cblp;          // Bytes on last page of file
+    uint16_t e_cp;            // Pages in file
+    uint16_t e_crlc;          // Relocations
+    uint16_t e_cparhdr;       // Size of header in paragraphs
+    uint16_t e_minalloc;      // Minimum extra paragraphs needed
+    uint16_t e_maxalloc;      // Maximum extra paragraphs needed
+    uint16_t e_ss;            // Initial (relative) SS value
+    uint16_t e_sp;            // Initial SP value
+    uint16_t e_csum;          // Checksum
+    uint16_t e_ip;            // Initial IP value
+    uint16_t e_cs;            // Initial (relative) CS value
+    uint16_t e_lfarlc;        // File address of relocation table
+    uint16_t e_ovno;          // Overlay number
+    uint16_t e_res[4];        // Reserved words
+    uint16_t e_oemid;         // OEM identifier (for e_oeminfo)
+    uint16_t e_oeminfo;       // OEM information; e_oemid specific
+    uint16_t e_res2[10];      // Reserved words
+    uint32_t e_lfanew;        // File address of new exe header
+  } dos_header_t;
+
+  typedef struct coff_header {
+    uint16_t machine;
+    uint16_t nsects;
+    uint32_t modtime;
+    uint32_t symoff;
+    uint32_t nsyms;
+    uint16_t hdrsize;
+    uint16_t flags;
+  } coff_header_t;
+
+  typedef struct data_directory {
+    uint32_t vmaddr;
+    uint32_t vmsize;
+  } data_directory_t;
+
+  typedef struct coff_opt_header {
+    uint16_t magic;
+    uint8_t major_linker_version;
+    uint8_t minor_linker_version;
+    uint32_t code_size;
+    uint32_t data_size;
+    uint32_t bss_size;
+    uint32_t entry;
+    uint32_t code_offset;
+    uint32_t data_offset;
+
+    uint64_t image_base;
+    uint32_t sect_alignment;
+    uint32_t file_alignment;
+    uint16_t major_os_system_version;
+    uint16_t minor_os_system_version;
+    uint16_t major_image_version;
+    uint16_t minor_image_version;
+    uint16_t major_subsystem_version;
+    uint16_t minor_subsystem_version;
+    uint32_t reserved1;
+    uint32_t image_size;
+    uint32_t header_size;
+    uint32_t checksum;
+    uint16_t subsystem;
+    uint16_t dll_flags;
+    uint64_t stack_reserve_size;
+    uint64_t stack_commit_size;
+    uint64_t heap_reserve_size;
+    uint64_t heap_commit_size;
+    uint32_t loader_flags;
+    //    uint32_t	num_data_dir_entries;
+    std::vector<data_directory>
+        data_dirs; // will contain num_data_dir_entries entries
+  } coff_opt_header_t;
+
+  typedef enum coff_data_dir_type {
+    coff_data_dir_export_table = 0,
+    coff_data_dir_import_table = 1,
+  } coff_data_dir_type;
+
+  typedef struct section_header {
+    char name[8];
+    uint32_t vmsize;  // Virtual Size
+    uint32_t vmaddr;  // Virtual Addr
+    uint32_t size;    // File size
+    uint32_t offset;  // File offset
+    uint32_t reloff;  // Offset to relocations
+    uint32_t lineoff; // Offset to line table entries
+    uint16_t nreloc;  // Number of relocation entries
+    uint16_t nline;   // Number of line table entries
+    uint32_t flags;
+  } section_header_t;
+
+  typedef struct coff_symbol {
+    char name[8];
+    uint32_t value;
+    uint16_t sect;
+    uint16_t type;
+    uint8_t storage;
+    uint8_t naux;
+  } coff_symbol_t;
+
+  typedef struct export_directory_entry {
+    uint32_t characteristics;
+    uint32_t time_date_stamp;
+    uint16_t major_version;
+    uint16_t minor_version;
+    uint32_t name;
+    uint32_t base;
+    uint32_t number_of_functions;
+    uint32_t number_of_names;
+    uint32_t address_of_functions;
+    uint32_t address_of_names;
+    uint32_t address_of_name_ordinals;
+  } export_directory_entry;
+
+  static bool ParseDOSHeader(lldb_private::DataExtractor &data,
+                             dos_header_t &dos_header);
+  static bool ParseCOFFHeader(lldb_private::DataExtractor &data,
+                              lldb::offset_t *offset_ptr,
+                              coff_header_t &coff_header);
+  bool ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr);
+  bool ParseSectionHeaders(uint32_t offset);
+
+  static void DumpDOSHeader(lldb_private::Stream *s,
+                            const dos_header_t &header);
+  static void DumpCOFFHeader(lldb_private::Stream *s,
+                             const coff_header_t &header);
+  static void DumpOptCOFFHeader(lldb_private::Stream *s,
+                                const coff_opt_header_t &header);
+  void DumpSectionHeaders(lldb_private::Stream *s);
+  void DumpSectionHeader(lldb_private::Stream *s, const section_header_t &sh);
+  bool GetSectionName(std::string &sect_name, const section_header_t &sect);
+
+  typedef std::vector<section_header_t> SectionHeaderColl;
+  typedef SectionHeaderColl::iterator SectionHeaderCollIter;
+  typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
+
 private:
-	dos_header_t		m_dos_header;
-	coff_header_t		m_coff_header;
-	coff_opt_header_t	m_coff_header_opt;
-	SectionHeaderColl	m_sect_headers;
-    lldb::addr_t		m_image_base;
-    lldb_private::Address	m_entry_point_address;
+  dos_header_t m_dos_header;
+  coff_header_t m_coff_header;
+  coff_opt_header_t m_coff_header_opt;
+  SectionHeaderColl m_sect_headers;
+  lldb::addr_t m_image_base;
+  lldb_private::Address m_entry_point_address;
 };
 
 #endif // liblldb_ObjectFilePECOFF_h_

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp Tue Sep  6 15:57:50 2016
@@ -16,41 +16,44 @@
 
 #ifdef _WIN32
 #include "lldb/Host/windows/windows.h"
-#include <DbgHelp.h>  // for MiniDumpWriteDump
+#include <DbgHelp.h> // for MiniDumpWriteDump
 #endif
 
 namespace lldb_private {
 
-bool
-SaveMiniDump(const lldb::ProcessSP &process_sp,
-             const lldb_private::FileSpec &outfile,
-             lldb_private::Error &error)
-{
-    if (!process_sp) return false;
+bool SaveMiniDump(const lldb::ProcessSP &process_sp,
+                  const lldb_private::FileSpec &outfile,
+                  lldb_private::Error &error) {
+  if (!process_sp)
+    return false;
 #ifdef _WIN32
-    HANDLE process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_sp->GetID());
-    const std::string file_name = outfile.GetCString();
-    std::wstring wide_name;
-    wide_name.resize(file_name.size() + 1);
-    char * result_ptr = reinterpret_cast<char *>(&wide_name[0]);
-    const UTF8 *error_ptr = nullptr;
-    if (!llvm::ConvertUTF8toWide(sizeof(wchar_t), file_name, result_ptr, error_ptr)) {
-        error.SetErrorString("cannot convert file name");
-        return false;
-    }
-    HANDLE file_handle = ::CreateFileW(wide_name.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
-    const auto result = ::MiniDumpWriteDump(process_handle, process_sp->GetID(), file_handle,
-                                            MiniDumpWithFullMemoryInfo, NULL, NULL, NULL);
-    ::CloseHandle(file_handle);
-    ::CloseHandle(process_handle);
-    if (!result)
-    {
-        error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
-        return false;
-    }
-    return true;
-#endif
+  HANDLE process_handle = ::OpenProcess(
+      PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_sp->GetID());
+  const std::string file_name = outfile.GetCString();
+  std::wstring wide_name;
+  wide_name.resize(file_name.size() + 1);
+  char *result_ptr = reinterpret_cast<char *>(&wide_name[0]);
+  const UTF8 *error_ptr = nullptr;
+  if (!llvm::ConvertUTF8toWide(sizeof(wchar_t), file_name, result_ptr,
+                               error_ptr)) {
+    error.SetErrorString("cannot convert file name");
     return false;
+  }
+  HANDLE file_handle =
+      ::CreateFileW(wide_name.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL,
+                    CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+  const auto result =
+      ::MiniDumpWriteDump(process_handle, process_sp->GetID(), file_handle,
+                          MiniDumpWithFullMemoryInfo, NULL, NULL, NULL);
+  ::CloseHandle(file_handle);
+  ::CloseHandle(process_handle);
+  if (!result) {
+    error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+    return false;
+  }
+  return true;
+#endif
+  return false;
 }
 
-}  // namesapce lldb_private
+} // namesapce lldb_private

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.h Tue Sep  6 15:57:50 2016
@@ -14,11 +14,10 @@
 
 namespace lldb_private {
 
-bool
-SaveMiniDump(const lldb::ProcessSP &process_sp,
-             const lldb_private::FileSpec &outfile,
-             lldb_private::Error &error);
+bool SaveMiniDump(const lldb::ProcessSP &process_sp,
+                  const lldb_private::FileSpec &outfile,
+                  lldb_private::Error &error);
 
-}  // namespace lldb_private
+} // namespace lldb_private
 
 #endif

Modified: lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp (original)
+++ lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp Tue Sep  6 15:57:50 2016
@@ -15,6 +15,9 @@
 // Project includes
 #include "OperatingSystemGo.h"
 
+#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
+#include "Plugins/Process/Utility/RegisterContextMemory.h"
+#include "Plugins/Process/Utility/ThreadMemory.h"
 #include "lldb/Core/DataBufferHeap.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
@@ -24,10 +27,10 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/ValueObjectVariable.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
-#include "lldb/Interpreter/OptionValueProperties.h"
-#include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/OptionGroupBoolean.h"
 #include "lldb/Interpreter/OptionGroupUInt64.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/Property.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Type.h"
@@ -35,536 +38,462 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Target/ThreadList.h"
 #include "lldb/Target/Thread.h"
-#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
-#include "Plugins/Process/Utility/RegisterContextMemory.h"
-#include "Plugins/Process/Utility/ThreadMemory.h"
+#include "lldb/Target/ThreadList.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
-namespace
-{
+namespace {
+
+static PropertyDefinition g_properties[] = {
+    {"enable", OptionValue::eTypeBoolean, true, true, nullptr, nullptr,
+     "Specify whether goroutines should be treated as threads."},
+    {NULL, OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL}};
 
-static PropertyDefinition g_properties[] = {{"enable", OptionValue::eTypeBoolean, true, true, nullptr, nullptr,
-                                             "Specify whether goroutines should be treated as threads."},
-                                            {NULL, OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL}};
-
-enum
-{
-    ePropertyEnableGoroutines,
+enum {
+  ePropertyEnableGoroutines,
 };
 
-class PluginProperties : public Properties
-{
+class PluginProperties : public Properties {
 public:
-    PluginProperties()
-        : Properties()
-    {
-        m_collection_sp.reset(new OptionValueProperties(GetSettingName()));
-        m_collection_sp->Initialize(g_properties);
-    }
-
-    ~PluginProperties() override = default;
-
-    static ConstString
-    GetSettingName()
-    {
-        return OperatingSystemGo::GetPluginNameStatic();
-    }
-
-    bool
-    GetEnableGoroutines()
-    {
-        const uint32_t idx = ePropertyEnableGoroutines;
-        return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value);
-    }
-
-    bool
-    SetEnableGoroutines(bool enable)
-    {
-        const uint32_t idx = ePropertyEnableGoroutines;
-        return m_collection_sp->SetPropertyAtIndexAsUInt64(NULL, idx, enable);
-    }
+  PluginProperties() : Properties() {
+    m_collection_sp.reset(new OptionValueProperties(GetSettingName()));
+    m_collection_sp->Initialize(g_properties);
+  }
+
+  ~PluginProperties() override = default;
+
+  static ConstString GetSettingName() {
+    return OperatingSystemGo::GetPluginNameStatic();
+  }
+
+  bool GetEnableGoroutines() {
+    const uint32_t idx = ePropertyEnableGoroutines;
+    return m_collection_sp->GetPropertyAtIndexAsBoolean(
+        NULL, idx, g_properties[idx].default_uint_value);
+  }
+
+  bool SetEnableGoroutines(bool enable) {
+    const uint32_t idx = ePropertyEnableGoroutines;
+    return m_collection_sp->SetPropertyAtIndexAsUInt64(NULL, idx, enable);
+  }
 };
 
 typedef std::shared_ptr<PluginProperties> OperatingSystemGoPropertiesSP;
 
-static const OperatingSystemGoPropertiesSP &
-GetGlobalPluginProperties()
-{
-    static OperatingSystemGoPropertiesSP g_settings_sp;
-    if (!g_settings_sp)
-        g_settings_sp.reset(new PluginProperties());
-    return g_settings_sp;
+static const OperatingSystemGoPropertiesSP &GetGlobalPluginProperties() {
+  static OperatingSystemGoPropertiesSP g_settings_sp;
+  if (!g_settings_sp)
+    g_settings_sp.reset(new PluginProperties());
+  return g_settings_sp;
 }
 
-class RegisterContextGo : public RegisterContextMemory
-{
+class RegisterContextGo : public RegisterContextMemory {
 public:
-    RegisterContextGo(lldb_private::Thread &thread, uint32_t concrete_frame_idx, DynamicRegisterInfo &reg_info,
-                      lldb::addr_t reg_data_addr)
-        : RegisterContextMemory(thread, concrete_frame_idx, reg_info, reg_data_addr)
-    {
-        const RegisterInfo *sp = reg_info.GetRegisterInfoAtIndex(
-            reg_info.ConvertRegisterKindToRegisterNumber(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP));
-        const RegisterInfo *pc = reg_info.GetRegisterInfoAtIndex(
-            reg_info.ConvertRegisterKindToRegisterNumber(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC));
-        size_t byte_size = std::max(sp->byte_offset + sp->byte_size, pc->byte_offset + pc->byte_size);
-
-        DataBufferSP reg_data_sp(new DataBufferHeap(byte_size, 0));
-        m_reg_data.SetData(reg_data_sp);
-    }
-
-    ~RegisterContextGo() override = default;
-
-    bool
-    ReadRegister(const lldb_private::RegisterInfo *reg_info,
-                 lldb_private::RegisterValue &reg_value) override
-    {
-        switch (reg_info->kinds[eRegisterKindGeneric])
-        {
-            case LLDB_REGNUM_GENERIC_SP:
-            case LLDB_REGNUM_GENERIC_PC:
-                return RegisterContextMemory::ReadRegister(reg_info, reg_value);
-            default:
-                reg_value.SetValueToInvalid();
-                return true;
-        }
-    }
-
-    bool
-    WriteRegister(const lldb_private::RegisterInfo *reg_info,
-                  const lldb_private::RegisterValue &reg_value) override
-    {
-        switch (reg_info->kinds[eRegisterKindGeneric])
-        {
-            case LLDB_REGNUM_GENERIC_SP:
-            case LLDB_REGNUM_GENERIC_PC:
-                return RegisterContextMemory::WriteRegister(reg_info, reg_value);
-            default:
-                return false;
-        }
+  RegisterContextGo(lldb_private::Thread &thread, uint32_t concrete_frame_idx,
+                    DynamicRegisterInfo &reg_info, lldb::addr_t reg_data_addr)
+      : RegisterContextMemory(thread, concrete_frame_idx, reg_info,
+                              reg_data_addr) {
+    const RegisterInfo *sp = reg_info.GetRegisterInfoAtIndex(
+        reg_info.ConvertRegisterKindToRegisterNumber(eRegisterKindGeneric,
+                                                     LLDB_REGNUM_GENERIC_SP));
+    const RegisterInfo *pc = reg_info.GetRegisterInfoAtIndex(
+        reg_info.ConvertRegisterKindToRegisterNumber(eRegisterKindGeneric,
+                                                     LLDB_REGNUM_GENERIC_PC));
+    size_t byte_size = std::max(sp->byte_offset + sp->byte_size,
+                                pc->byte_offset + pc->byte_size);
+
+    DataBufferSP reg_data_sp(new DataBufferHeap(byte_size, 0));
+    m_reg_data.SetData(reg_data_sp);
+  }
+
+  ~RegisterContextGo() override = default;
+
+  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
+                    lldb_private::RegisterValue &reg_value) override {
+    switch (reg_info->kinds[eRegisterKindGeneric]) {
+    case LLDB_REGNUM_GENERIC_SP:
+    case LLDB_REGNUM_GENERIC_PC:
+      return RegisterContextMemory::ReadRegister(reg_info, reg_value);
+    default:
+      reg_value.SetValueToInvalid();
+      return true;
+    }
+  }
+
+  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
+                     const lldb_private::RegisterValue &reg_value) override {
+    switch (reg_info->kinds[eRegisterKindGeneric]) {
+    case LLDB_REGNUM_GENERIC_SP:
+    case LLDB_REGNUM_GENERIC_PC:
+      return RegisterContextMemory::WriteRegister(reg_info, reg_value);
+    default:
+      return false;
     }
+  }
 
 private:
-    DISALLOW_COPY_AND_ASSIGN(RegisterContextGo);
+  DISALLOW_COPY_AND_ASSIGN(RegisterContextGo);
 };
 
 } // anonymous namespace
 
-struct OperatingSystemGo::Goroutine
-{
-    uint64_t m_lostack;
-    uint64_t m_histack;
-    uint64_t m_goid;
-    addr_t m_gobuf;
-    uint32_t m_status;
+struct OperatingSystemGo::Goroutine {
+  uint64_t m_lostack;
+  uint64_t m_histack;
+  uint64_t m_goid;
+  addr_t m_gobuf;
+  uint32_t m_status;
 };
 
-void
-OperatingSystemGo::Initialize()
-{
-    PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
-                                  DebuggerInitialize);
-}
-
-void
-OperatingSystemGo::DebuggerInitialize(Debugger &debugger)
-{
-    if (!PluginManager::GetSettingForOperatingSystemPlugin(debugger, PluginProperties::GetSettingName()))
-    {
-        const bool is_global_setting = true;
-        PluginManager::CreateSettingForOperatingSystemPlugin(
-            debugger, GetGlobalPluginProperties()->GetValueProperties(),
-            ConstString("Properties for the goroutine thread plug-in."), is_global_setting);
-    }
-}
-
-void
-OperatingSystemGo::Terminate()
-{
-    PluginManager::UnregisterPlugin(CreateInstance);
-}
-
-OperatingSystem *
-OperatingSystemGo::CreateInstance(Process *process, bool force)
-{
-    if (!force)
-    {
-        TargetSP target_sp = process->CalculateTarget();
-        if (!target_sp)
-            return nullptr;
-        ModuleList &module_list = target_sp->GetImages();
-        std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
-        const size_t num_modules = module_list.GetSize();
-        bool found_go_runtime = false;
-        for (size_t i = 0; i < num_modules; ++i)
-        {
-            Module *module = module_list.GetModulePointerAtIndexUnlocked(i);
-            const SectionList *section_list = module->GetSectionList();
-            if (section_list)
-            {
-                SectionSP section_sp(section_list->FindSectionByType(eSectionTypeGoSymtab, true));
-                if (section_sp)
-                {
-                    found_go_runtime = true;
-                    break;
-                }
-            }
-        }
-        if (!found_go_runtime)
-            return nullptr;
-    }
-    return new OperatingSystemGo(process);
+void OperatingSystemGo::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                GetPluginDescriptionStatic(), CreateInstance,
+                                DebuggerInitialize);
+}
+
+void OperatingSystemGo::DebuggerInitialize(Debugger &debugger) {
+  if (!PluginManager::GetSettingForOperatingSystemPlugin(
+          debugger, PluginProperties::GetSettingName())) {
+    const bool is_global_setting = true;
+    PluginManager::CreateSettingForOperatingSystemPlugin(
+        debugger, GetGlobalPluginProperties()->GetValueProperties(),
+        ConstString("Properties for the goroutine thread plug-in."),
+        is_global_setting);
+  }
+}
+
+void OperatingSystemGo::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+OperatingSystem *OperatingSystemGo::CreateInstance(Process *process,
+                                                   bool force) {
+  if (!force) {
+    TargetSP target_sp = process->CalculateTarget();
+    if (!target_sp)
+      return nullptr;
+    ModuleList &module_list = target_sp->GetImages();
+    std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
+    const size_t num_modules = module_list.GetSize();
+    bool found_go_runtime = false;
+    for (size_t i = 0; i < num_modules; ++i) {
+      Module *module = module_list.GetModulePointerAtIndexUnlocked(i);
+      const SectionList *section_list = module->GetSectionList();
+      if (section_list) {
+        SectionSP section_sp(
+            section_list->FindSectionByType(eSectionTypeGoSymtab, true));
+        if (section_sp) {
+          found_go_runtime = true;
+          break;
+        }
+      }
+    }
+    if (!found_go_runtime)
+      return nullptr;
+  }
+  return new OperatingSystemGo(process);
 }
 
 OperatingSystemGo::OperatingSystemGo(lldb_private::Process *process)
-    : OperatingSystem(process)
-    , m_reginfo(new DynamicRegisterInfo)
-{
-}
+    : OperatingSystem(process), m_reginfo(new DynamicRegisterInfo) {}
 
 OperatingSystemGo::~OperatingSystemGo() = default;
 
-ConstString
-OperatingSystemGo::GetPluginNameStatic()
-{
-    static ConstString g_name("goroutines");
-    return g_name;
-}
-
-const char *
-OperatingSystemGo::GetPluginDescriptionStatic()
-{
-    return "Operating system plug-in that reads runtime data-structures for goroutines.";
-}
-
-bool
-OperatingSystemGo::Init(ThreadList &threads)
-{
-    if (threads.GetSize(false) < 1)
-        return false;
-    TargetSP target_sp = m_process->CalculateTarget();
-    if (!target_sp)
-        return false;
-    // Go 1.6 stores goroutines in a slice called runtime.allgs
-    ValueObjectSP allgs_sp = FindGlobal(target_sp, "runtime.allgs");
-    if (allgs_sp)
-    {
-        m_allg_sp = allgs_sp->GetChildMemberWithName(ConstString("array"), true);
-        m_allglen_sp = allgs_sp->GetChildMemberWithName(ConstString("len"), true);
-    }
-    else
-    {
-        // Go 1.4 stores goroutines in the variable runtime.allg.
-        m_allg_sp = FindGlobal(target_sp, "runtime.allg");
-        m_allglen_sp = FindGlobal(target_sp, "runtime.allglen");
-    }
-
-    if (m_allg_sp && !m_allglen_sp)
-    {
-        StreamSP error_sp = target_sp->GetDebugger().GetAsyncErrorStream();
-        error_sp->Printf("Unsupported Go runtime version detected.");
-        return false;
-    }
-
-    if (!m_allg_sp)
-        return false;
-
-    RegisterContextSP real_registers_sp = threads.GetThreadAtIndex(0, false)->GetRegisterContext();
-
-    std::unordered_map<size_t, ConstString> register_sets;
-    for (size_t set_idx = 0; set_idx < real_registers_sp->GetRegisterSetCount(); ++set_idx)
-    {
-        const RegisterSet *set = real_registers_sp->GetRegisterSet(set_idx);
-        ConstString name(set->name);
-        for (size_t reg_idx = 0; reg_idx < set->num_registers; ++reg_idx)
-        {
-            register_sets[reg_idx] = name;
-        }
-    }
-    TypeSP gobuf_sp = FindType(target_sp, "runtime.gobuf");
-    if (!gobuf_sp)
-    {
-        Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
-
-        if (log)
-            log->Printf("OperatingSystemGo unable to find struct Gobuf");
-        return false;
-    }
-    CompilerType gobuf_type(gobuf_sp->GetLayoutCompilerType());
-    for (size_t idx = 0; idx < real_registers_sp->GetRegisterCount(); ++idx)
-    {
-        RegisterInfo reg = *real_registers_sp->GetRegisterInfoAtIndex(idx);
-        int field_index = -1;
-        if (reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_SP)
-        {
-            field_index = 0;
-        }
-        else if (reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_PC)
-        {
-            field_index = 1;
-        }
-        if (field_index == -1)
-        {
-            reg.byte_offset = ~0;
-        }
-        else
-        {
-            std::string field_name;
-            uint64_t bit_offset = 0;
-            CompilerType field_type =
-                gobuf_type.GetFieldAtIndex(field_index, field_name, &bit_offset, nullptr, nullptr);
-            reg.byte_size = field_type.GetByteSize(nullptr);
-            reg.byte_offset = bit_offset / 8;
-        }
-        ConstString name(reg.name);
-        ConstString alt_name(reg.alt_name);
-        m_reginfo->AddRegister(reg, name, alt_name, register_sets[idx]);
-    }
-    return true;
+ConstString OperatingSystemGo::GetPluginNameStatic() {
+  static ConstString g_name("goroutines");
+  return g_name;
+}
+
+const char *OperatingSystemGo::GetPluginDescriptionStatic() {
+  return "Operating system plug-in that reads runtime data-structures for "
+         "goroutines.";
+}
+
+bool OperatingSystemGo::Init(ThreadList &threads) {
+  if (threads.GetSize(false) < 1)
+    return false;
+  TargetSP target_sp = m_process->CalculateTarget();
+  if (!target_sp)
+    return false;
+  // Go 1.6 stores goroutines in a slice called runtime.allgs
+  ValueObjectSP allgs_sp = FindGlobal(target_sp, "runtime.allgs");
+  if (allgs_sp) {
+    m_allg_sp = allgs_sp->GetChildMemberWithName(ConstString("array"), true);
+    m_allglen_sp = allgs_sp->GetChildMemberWithName(ConstString("len"), true);
+  } else {
+    // Go 1.4 stores goroutines in the variable runtime.allg.
+    m_allg_sp = FindGlobal(target_sp, "runtime.allg");
+    m_allglen_sp = FindGlobal(target_sp, "runtime.allglen");
+  }
+
+  if (m_allg_sp && !m_allglen_sp) {
+    StreamSP error_sp = target_sp->GetDebugger().GetAsyncErrorStream();
+    error_sp->Printf("Unsupported Go runtime version detected.");
+    return false;
+  }
+
+  if (!m_allg_sp)
+    return false;
+
+  RegisterContextSP real_registers_sp =
+      threads.GetThreadAtIndex(0, false)->GetRegisterContext();
+
+  std::unordered_map<size_t, ConstString> register_sets;
+  for (size_t set_idx = 0; set_idx < real_registers_sp->GetRegisterSetCount();
+       ++set_idx) {
+    const RegisterSet *set = real_registers_sp->GetRegisterSet(set_idx);
+    ConstString name(set->name);
+    for (size_t reg_idx = 0; reg_idx < set->num_registers; ++reg_idx) {
+      register_sets[reg_idx] = name;
+    }
+  }
+  TypeSP gobuf_sp = FindType(target_sp, "runtime.gobuf");
+  if (!gobuf_sp) {
+    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+
+    if (log)
+      log->Printf("OperatingSystemGo unable to find struct Gobuf");
+    return false;
+  }
+  CompilerType gobuf_type(gobuf_sp->GetLayoutCompilerType());
+  for (size_t idx = 0; idx < real_registers_sp->GetRegisterCount(); ++idx) {
+    RegisterInfo reg = *real_registers_sp->GetRegisterInfoAtIndex(idx);
+    int field_index = -1;
+    if (reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_SP) {
+      field_index = 0;
+    } else if (reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_PC) {
+      field_index = 1;
+    }
+    if (field_index == -1) {
+      reg.byte_offset = ~0;
+    } else {
+      std::string field_name;
+      uint64_t bit_offset = 0;
+      CompilerType field_type = gobuf_type.GetFieldAtIndex(
+          field_index, field_name, &bit_offset, nullptr, nullptr);
+      reg.byte_size = field_type.GetByteSize(nullptr);
+      reg.byte_offset = bit_offset / 8;
+    }
+    ConstString name(reg.name);
+    ConstString alt_name(reg.alt_name);
+    m_reginfo->AddRegister(reg, name, alt_name, register_sets[idx]);
+  }
+  return true;
 }
 
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
-ConstString
-OperatingSystemGo::GetPluginName()
-{
-    return GetPluginNameStatic();
-}
-
-uint32_t
-OperatingSystemGo::GetPluginVersion()
-{
-    return 1;
-}
-
-bool
-OperatingSystemGo::UpdateThreadList(ThreadList &old_thread_list, ThreadList &real_thread_list,
-                                    ThreadList &new_thread_list)
-{
-    new_thread_list = real_thread_list;
-    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+ConstString OperatingSystemGo::GetPluginName() { return GetPluginNameStatic(); }
 
-    if (!(m_allg_sp || Init(real_thread_list)) || (m_allg_sp && !m_allglen_sp) ||
-        !GetGlobalPluginProperties()->GetEnableGoroutines())
-    {
-        return new_thread_list.GetSize(false) > 0;
-    }
+uint32_t OperatingSystemGo::GetPluginVersion() { return 1; }
 
-    if (log)
-        log->Printf("OperatingSystemGo::UpdateThreadList(%d, %d, %d) fetching thread data from Go for pid %" PRIu64,
-                    old_thread_list.GetSize(false), real_thread_list.GetSize(false), new_thread_list.GetSize(0),
-                    m_process->GetID());
-    uint64_t allglen = m_allglen_sp->GetValueAsUnsigned(0);
-    if (allglen == 0)
-    {
-        return new_thread_list.GetSize(false) > 0;
-    }
-    std::vector<Goroutine> goroutines;
-    // The threads that are in "new_thread_list" upon entry are the threads from the
-    // lldb_private::Process subclass, no memory threads will be in this list.
-
-    Error err;
-    for (uint64_t i = 0; i < allglen; ++i)
-    {
-        goroutines.push_back(CreateGoroutineAtIndex(i, err));
-        if (err.Fail())
-        {
-            err.PutToLog(log, "OperatingSystemGo::UpdateThreadList");
-            return new_thread_list.GetSize(false) > 0;
-        }
-    }
-    // Make a map so we can match goroutines with backing threads.
-    std::map<uint64_t, ThreadSP> stack_map;
-    for (uint32_t i = 0; i < real_thread_list.GetSize(false); ++i)
-    {
-        ThreadSP thread = real_thread_list.GetThreadAtIndex(i, false);
-        stack_map[thread->GetRegisterContext()->GetSP()] = thread;
-    }
-    for (const Goroutine &goroutine : goroutines)
-    {
-        if (0 /* Gidle */ == goroutine.m_status || 6 /* Gdead */ == goroutine.m_status)
-        {
-            continue;
-        }
-        ThreadSP memory_thread = old_thread_list.FindThreadByID(goroutine.m_goid, false);
-        if (memory_thread && IsOperatingSystemPluginThread(memory_thread) && memory_thread->IsValid())
-        {
-            memory_thread->ClearBackingThread();
-        }
-        else
-        {
-            memory_thread.reset(new ThreadMemory(*m_process, goroutine.m_goid, nullptr, nullptr, goroutine.m_gobuf));
-        }
-        // Search for the backing thread if the goroutine is running.
-        if (2 == (goroutine.m_status & 0xfff))
-        {
-            auto backing_it = stack_map.lower_bound(goroutine.m_lostack);
-            if (backing_it != stack_map.end())
-            {
-                if (goroutine.m_histack >= backing_it->first)
-                {
-                    if (log)
-                        log->Printf("OperatingSystemGo::UpdateThreadList found backing thread %" PRIx64 " (%" PRIx64
-                                    ") for thread %" PRIx64 "",
-                                    backing_it->second->GetID(), backing_it->second->GetProtocolID(),
-                                    memory_thread->GetID());
-                    memory_thread->SetBackingThread(backing_it->second);
-                    new_thread_list.RemoveThreadByID(backing_it->second->GetID(), false);
-                }
-            }
-        }
-        new_thread_list.AddThread(memory_thread);
-    }
+bool OperatingSystemGo::UpdateThreadList(ThreadList &old_thread_list,
+                                         ThreadList &real_thread_list,
+                                         ThreadList &new_thread_list) {
+  new_thread_list = real_thread_list;
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
 
+  if (!(m_allg_sp || Init(real_thread_list)) || (m_allg_sp && !m_allglen_sp) ||
+      !GetGlobalPluginProperties()->GetEnableGoroutines()) {
     return new_thread_list.GetSize(false) > 0;
-}
-
-void
-OperatingSystemGo::ThreadWasSelected(Thread *thread)
-{
-}
-
-RegisterContextSP
-OperatingSystemGo::CreateRegisterContextForThread(Thread *thread, addr_t reg_data_addr)
-{
-    RegisterContextSP reg_ctx_sp;
-    if (!thread)
-        return reg_ctx_sp;
+  }
 
-    if (!IsOperatingSystemPluginThread(thread->shared_from_this()))
-        return reg_ctx_sp;
+  if (log)
+    log->Printf("OperatingSystemGo::UpdateThreadList(%d, %d, %d) fetching "
+                "thread data from Go for pid %" PRIu64,
+                old_thread_list.GetSize(false), real_thread_list.GetSize(false),
+                new_thread_list.GetSize(0), m_process->GetID());
+  uint64_t allglen = m_allglen_sp->GetValueAsUnsigned(0);
+  if (allglen == 0) {
+    return new_thread_list.GetSize(false) > 0;
+  }
+  std::vector<Goroutine> goroutines;
+  // The threads that are in "new_thread_list" upon entry are the threads from
+  // the
+  // lldb_private::Process subclass, no memory threads will be in this list.
+
+  Error err;
+  for (uint64_t i = 0; i < allglen; ++i) {
+    goroutines.push_back(CreateGoroutineAtIndex(i, err));
+    if (err.Fail()) {
+      err.PutToLog(log, "OperatingSystemGo::UpdateThreadList");
+      return new_thread_list.GetSize(false) > 0;
+    }
+  }
+  // Make a map so we can match goroutines with backing threads.
+  std::map<uint64_t, ThreadSP> stack_map;
+  for (uint32_t i = 0; i < real_thread_list.GetSize(false); ++i) {
+    ThreadSP thread = real_thread_list.GetThreadAtIndex(i, false);
+    stack_map[thread->GetRegisterContext()->GetSP()] = thread;
+  }
+  for (const Goroutine &goroutine : goroutines) {
+    if (0 /* Gidle */ == goroutine.m_status ||
+        6 /* Gdead */ == goroutine.m_status) {
+      continue;
+    }
+    ThreadSP memory_thread =
+        old_thread_list.FindThreadByID(goroutine.m_goid, false);
+    if (memory_thread && IsOperatingSystemPluginThread(memory_thread) &&
+        memory_thread->IsValid()) {
+      memory_thread->ClearBackingThread();
+    } else {
+      memory_thread.reset(new ThreadMemory(
+          *m_process, goroutine.m_goid, nullptr, nullptr, goroutine.m_gobuf));
+    }
+    // Search for the backing thread if the goroutine is running.
+    if (2 == (goroutine.m_status & 0xfff)) {
+      auto backing_it = stack_map.lower_bound(goroutine.m_lostack);
+      if (backing_it != stack_map.end()) {
+        if (goroutine.m_histack >= backing_it->first) {
+          if (log)
+            log->Printf(
+                "OperatingSystemGo::UpdateThreadList found backing thread "
+                "%" PRIx64 " (%" PRIx64 ") for thread %" PRIx64 "",
+                backing_it->second->GetID(),
+                backing_it->second->GetProtocolID(), memory_thread->GetID());
+          memory_thread->SetBackingThread(backing_it->second);
+          new_thread_list.RemoveThreadByID(backing_it->second->GetID(), false);
+        }
+      }
+    }
+    new_thread_list.AddThread(memory_thread);
+  }
 
-    reg_ctx_sp.reset(new RegisterContextGo(*thread, 0, *m_reginfo, reg_data_addr));
-    return reg_ctx_sp;
+  return new_thread_list.GetSize(false) > 0;
 }
 
-StopInfoSP
-OperatingSystemGo::CreateThreadStopReason(lldb_private::Thread *thread)
-{
-    StopInfoSP stop_info_sp;
-    return stop_info_sp;
-}
+void OperatingSystemGo::ThreadWasSelected(Thread *thread) {}
 
-lldb::ThreadSP
-OperatingSystemGo::CreateThread(lldb::tid_t tid, addr_t context)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+RegisterContextSP
+OperatingSystemGo::CreateRegisterContextForThread(Thread *thread,
+                                                  addr_t reg_data_addr) {
+  RegisterContextSP reg_ctx_sp;
+  if (!thread)
+    return reg_ctx_sp;
 
-    if (log)
-        log->Printf("OperatingSystemGo::CreateThread (tid = 0x%" PRIx64 ", context = 0x%" PRIx64 ") not implemented",
-                    tid, context);
+  if (!IsOperatingSystemPluginThread(thread->shared_from_this()))
+    return reg_ctx_sp;
 
-    return ThreadSP();
+  reg_ctx_sp.reset(
+      new RegisterContextGo(*thread, 0, *m_reginfo, reg_data_addr));
+  return reg_ctx_sp;
 }
 
-ValueObjectSP
-OperatingSystemGo::FindGlobal(TargetSP target, const char *name)
-{
-    VariableList variable_list;
-    const bool append = true;
-
-    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
-
-    if (log)
-    {
-        log->Printf("exe: %s", target->GetExecutableModule()->GetSpecificationDescription().c_str());
-        log->Printf("modules: %zu", target->GetImages().GetSize());
-    }
-
-    uint32_t match_count = target->GetImages().FindGlobalVariables(ConstString(name), append, 1, variable_list);
-    if (match_count > 0)
-    {
-        ExecutionContextScope *exe_scope = target->GetProcessSP().get();
-        if (exe_scope == NULL)
-            exe_scope = target.get();
-        return ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(0));
-    }
-    return ValueObjectSP();
-}
-
-TypeSP
-OperatingSystemGo::FindType(TargetSP target_sp, const char *name)
-{
-    ConstString const_typename(name);
-    SymbolContext sc;
-    const bool exact_match = false;
-
-    const ModuleList &module_list = target_sp->GetImages();
-    size_t count = module_list.GetSize();
-    for (size_t idx = 0; idx < count; idx++)
-    {
-        ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
-        if (module_sp)
-        {
-            TypeSP type_sp(module_sp->FindFirstType(sc, const_typename, exact_match));
-            if (type_sp)
-                return type_sp;
-        }
-    }
-    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
-
-    if (log)
-        log->Printf("OperatingSystemGo::FindType(%s): not found", name);
-    return TypeSP();
+StopInfoSP
+OperatingSystemGo::CreateThreadStopReason(lldb_private::Thread *thread) {
+  StopInfoSP stop_info_sp;
+  return stop_info_sp;
+}
+
+lldb::ThreadSP OperatingSystemGo::CreateThread(lldb::tid_t tid,
+                                               addr_t context) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+
+  if (log)
+    log->Printf("OperatingSystemGo::CreateThread (tid = 0x%" PRIx64
+                ", context = 0x%" PRIx64 ") not implemented",
+                tid, context);
+
+  return ThreadSP();
+}
+
+ValueObjectSP OperatingSystemGo::FindGlobal(TargetSP target, const char *name) {
+  VariableList variable_list;
+  const bool append = true;
+
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+
+  if (log) {
+    log->Printf(
+        "exe: %s",
+        target->GetExecutableModule()->GetSpecificationDescription().c_str());
+    log->Printf("modules: %zu", target->GetImages().GetSize());
+  }
+
+  uint32_t match_count = target->GetImages().FindGlobalVariables(
+      ConstString(name), append, 1, variable_list);
+  if (match_count > 0) {
+    ExecutionContextScope *exe_scope = target->GetProcessSP().get();
+    if (exe_scope == NULL)
+      exe_scope = target.get();
+    return ValueObjectVariable::Create(exe_scope,
+                                       variable_list.GetVariableAtIndex(0));
+  }
+  return ValueObjectSP();
+}
+
+TypeSP OperatingSystemGo::FindType(TargetSP target_sp, const char *name) {
+  ConstString const_typename(name);
+  SymbolContext sc;
+  const bool exact_match = false;
+
+  const ModuleList &module_list = target_sp->GetImages();
+  size_t count = module_list.GetSize();
+  for (size_t idx = 0; idx < count; idx++) {
+    ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+    if (module_sp) {
+      TypeSP type_sp(module_sp->FindFirstType(sc, const_typename, exact_match));
+      if (type_sp)
+        return type_sp;
+    }
+  }
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+
+  if (log)
+    log->Printf("OperatingSystemGo::FindType(%s): not found", name);
+  return TypeSP();
 }
 
 OperatingSystemGo::Goroutine
-OperatingSystemGo::CreateGoroutineAtIndex(uint64_t idx, Error &err)
-{
-    err.Clear();
-    Goroutine result = {};
-    ValueObjectSP g = m_allg_sp->GetSyntheticArrayMember(idx, true)->Dereference(err);
-    if (err.Fail())
-    {
-        return result;
-    }
-
-    ConstString name("goid");
-    ValueObjectSP val = g->GetChildMemberWithName(name, true);
-    bool success = false;
-    result.m_goid = val->GetValueAsUnsigned(0, &success);
-    if (!success)
-    {
-        err.SetErrorToGenericError();
-        err.SetErrorString("unable to read goid");
-        return result;
-    }
-    name.SetCString("atomicstatus");
-    val = g->GetChildMemberWithName(name, true);
-    result.m_status = (uint32_t)val->GetValueAsUnsigned(0, &success);
-    if (!success)
-    {
-        err.SetErrorToGenericError();
-        err.SetErrorString("unable to read atomicstatus");
-        return result;
-    }
-    name.SetCString("sched");
-    val = g->GetChildMemberWithName(name, true);
-    result.m_gobuf = val->GetAddressOf(false);
-    name.SetCString("stack");
-    val = g->GetChildMemberWithName(name, true);
-    name.SetCString("lo");
-    ValueObjectSP child = val->GetChildMemberWithName(name, true);
-    result.m_lostack = child->GetValueAsUnsigned(0, &success);
-    if (!success)
-    {
-        err.SetErrorToGenericError();
-        err.SetErrorString("unable to read stack.lo");
-        return result;
-    }
-    name.SetCString("hi");
-    child = val->GetChildMemberWithName(name, true);
-    result.m_histack = child->GetValueAsUnsigned(0, &success);
-    if (!success)
-    {
-        err.SetErrorToGenericError();
-        err.SetErrorString("unable to read stack.hi");
-        return result;
-    }
+OperatingSystemGo::CreateGoroutineAtIndex(uint64_t idx, Error &err) {
+  err.Clear();
+  Goroutine result = {};
+  ValueObjectSP g =
+      m_allg_sp->GetSyntheticArrayMember(idx, true)->Dereference(err);
+  if (err.Fail()) {
+    return result;
+  }
+
+  ConstString name("goid");
+  ValueObjectSP val = g->GetChildMemberWithName(name, true);
+  bool success = false;
+  result.m_goid = val->GetValueAsUnsigned(0, &success);
+  if (!success) {
+    err.SetErrorToGenericError();
+    err.SetErrorString("unable to read goid");
+    return result;
+  }
+  name.SetCString("atomicstatus");
+  val = g->GetChildMemberWithName(name, true);
+  result.m_status = (uint32_t)val->GetValueAsUnsigned(0, &success);
+  if (!success) {
+    err.SetErrorToGenericError();
+    err.SetErrorString("unable to read atomicstatus");
+    return result;
+  }
+  name.SetCString("sched");
+  val = g->GetChildMemberWithName(name, true);
+  result.m_gobuf = val->GetAddressOf(false);
+  name.SetCString("stack");
+  val = g->GetChildMemberWithName(name, true);
+  name.SetCString("lo");
+  ValueObjectSP child = val->GetChildMemberWithName(name, true);
+  result.m_lostack = child->GetValueAsUnsigned(0, &success);
+  if (!success) {
+    err.SetErrorToGenericError();
+    err.SetErrorString("unable to read stack.lo");
+    return result;
+  }
+  name.SetCString("hi");
+  child = val->GetChildMemberWithName(name, true);
+  result.m_histack = child->GetValueAsUnsigned(0, &success);
+  if (!success) {
+    err.SetErrorToGenericError();
+    err.SetErrorString("unable to read stack.hi");
     return result;
+  }
+  return result;
 }

Modified: lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h (original)
+++ lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h Tue Sep  6 15:57:50 2016
@@ -20,68 +20,71 @@
 
 class DynamicRegisterInfo;
 
-class OperatingSystemGo : public lldb_private::OperatingSystem
-{
+class OperatingSystemGo : public lldb_private::OperatingSystem {
 public:
-    OperatingSystemGo(lldb_private::Process *process);
+  OperatingSystemGo(lldb_private::Process *process);
 
-    ~OperatingSystemGo() override;
+  ~OperatingSystemGo() override;
 
-    //------------------------------------------------------------------
-    // Static Functions
-    //------------------------------------------------------------------
-    static lldb_private::OperatingSystem *CreateInstance(lldb_private::Process *process, bool force);
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+  static lldb_private::OperatingSystem *
+  CreateInstance(lldb_private::Process *process, bool force);
 
-    static void Initialize();
+  static void Initialize();
 
-    static void DebuggerInitialize(lldb_private::Debugger &debugger);
+  static void DebuggerInitialize(lldb_private::Debugger &debugger);
 
-    static void Terminate();
+  static void Terminate();
 
-    static lldb_private::ConstString GetPluginNameStatic();
+  static lldb_private::ConstString GetPluginNameStatic();
 
-    static const char *GetPluginDescriptionStatic();
+  static const char *GetPluginDescriptionStatic();
 
-    //------------------------------------------------------------------
-    // lldb_private::PluginInterface Methods
-    //------------------------------------------------------------------
-    lldb_private::ConstString GetPluginName() override;
+  //------------------------------------------------------------------
+  // lldb_private::PluginInterface Methods
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
 
-    uint32_t GetPluginVersion() override;
+  uint32_t GetPluginVersion() override;
 
-    //------------------------------------------------------------------
-    // lldb_private::OperatingSystem Methods
-    //------------------------------------------------------------------
-    bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
-                          lldb_private::ThreadList &real_thread_list,
-                          lldb_private::ThreadList &new_thread_list) override;
+  //------------------------------------------------------------------
+  // lldb_private::OperatingSystem Methods
+  //------------------------------------------------------------------
+  bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
+                        lldb_private::ThreadList &real_thread_list,
+                        lldb_private::ThreadList &new_thread_list) override;
 
-    void ThreadWasSelected(lldb_private::Thread *thread) override;
+  void ThreadWasSelected(lldb_private::Thread *thread) override;
 
-    lldb::RegisterContextSP CreateRegisterContextForThread(lldb_private::Thread *thread,
-                                                           lldb::addr_t reg_data_addr) override;
+  lldb::RegisterContextSP
+  CreateRegisterContextForThread(lldb_private::Thread *thread,
+                                 lldb::addr_t reg_data_addr) override;
 
-    lldb::StopInfoSP CreateThreadStopReason(lldb_private::Thread *thread) override;
+  lldb::StopInfoSP
+  CreateThreadStopReason(lldb_private::Thread *thread) override;
 
-    //------------------------------------------------------------------
-    // Method for lazy creation of threads on demand
-    //------------------------------------------------------------------
-    lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override;
+  //------------------------------------------------------------------
+  // Method for lazy creation of threads on demand
+  //------------------------------------------------------------------
+  lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override;
 
 private:
-    struct Goroutine;
+  struct Goroutine;
 
-    static lldb::ValueObjectSP FindGlobal(lldb::TargetSP target, const char *name);
+  static lldb::ValueObjectSP FindGlobal(lldb::TargetSP target,
+                                        const char *name);
 
-    static lldb::TypeSP FindType(lldb::TargetSP target_sp, const char *name);
+  static lldb::TypeSP FindType(lldb::TargetSP target_sp, const char *name);
 
-    bool Init(lldb_private::ThreadList &threads);
+  bool Init(lldb_private::ThreadList &threads);
 
-    Goroutine CreateGoroutineAtIndex(uint64_t idx, lldb_private::Error &err);
+  Goroutine CreateGoroutineAtIndex(uint64_t idx, lldb_private::Error &err);
 
-    std::unique_ptr<DynamicRegisterInfo> m_reginfo;
-    lldb::ValueObjectSP m_allg_sp;
-    lldb::ValueObjectSP m_allglen_sp;
+  std::unique_ptr<DynamicRegisterInfo> m_reginfo;
+  lldb::ValueObjectSP m_allg_sp;
+  lldb::ValueObjectSP m_allglen_sp;
 };
 
 #endif // liblldb_OperatingSystemGo_h_

Modified: lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp (original)
+++ lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- OperatingSystemPython.cpp --------------------------------*- C++ -*-===//
+//===-- OperatingSystemPython.cpp --------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -13,6 +14,10 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
+#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
+#include "Plugins/Process/Utility/RegisterContextDummy.h"
+#include "Plugins/Process/Utility/RegisterContextMemory.h"
+#include "Plugins/Process/Utility/ThreadMemory.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBufferHeap.h"
 #include "lldb/Core/Debugger.h"
@@ -29,395 +34,385 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Target/ThreadList.h"
 #include "lldb/Target/Thread.h"
-#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
-#include "Plugins/Process/Utility/RegisterContextDummy.h"
-#include "Plugins/Process/Utility/RegisterContextMemory.h"
-#include "Plugins/Process/Utility/ThreadMemory.h"
+#include "lldb/Target/ThreadList.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
-void
-OperatingSystemPython::Initialize()
-{
-    PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, nullptr);
-}
-
-void
-OperatingSystemPython::Terminate()
-{
-    PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-OperatingSystem *
-OperatingSystemPython::CreateInstance (Process *process, bool force)
-{
-    // Python OperatingSystem plug-ins must be requested by name, so force must be true
-    FileSpec python_os_plugin_spec (process->GetPythonOSPluginPath());
-    if (python_os_plugin_spec && python_os_plugin_spec.Exists())
-    {
-        std::unique_ptr<OperatingSystemPython> os_ap (new OperatingSystemPython (process, python_os_plugin_spec));
-        if (os_ap.get() && os_ap->IsValid())
-            return os_ap.release();
+void OperatingSystemPython::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                GetPluginDescriptionStatic(), CreateInstance,
+                                nullptr);
+}
+
+void OperatingSystemPython::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+OperatingSystem *OperatingSystemPython::CreateInstance(Process *process,
+                                                       bool force) {
+  // Python OperatingSystem plug-ins must be requested by name, so force must be
+  // true
+  FileSpec python_os_plugin_spec(process->GetPythonOSPluginPath());
+  if (python_os_plugin_spec && python_os_plugin_spec.Exists()) {
+    std::unique_ptr<OperatingSystemPython> os_ap(
+        new OperatingSystemPython(process, python_os_plugin_spec));
+    if (os_ap.get() && os_ap->IsValid())
+      return os_ap.release();
+  }
+  return NULL;
+}
+
+ConstString OperatingSystemPython::GetPluginNameStatic() {
+  static ConstString g_name("python");
+  return g_name;
+}
+
+const char *OperatingSystemPython::GetPluginDescriptionStatic() {
+  return "Operating system plug-in that gathers OS information from a python "
+         "class that implements the necessary OperatingSystem functionality.";
+}
+
+OperatingSystemPython::OperatingSystemPython(lldb_private::Process *process,
+                                             const FileSpec &python_module_path)
+    : OperatingSystem(process), m_thread_list_valobj_sp(), m_register_info_ap(),
+      m_interpreter(NULL), m_python_object_sp() {
+  if (!process)
+    return;
+  TargetSP target_sp = process->CalculateTarget();
+  if (!target_sp)
+    return;
+  m_interpreter =
+      target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+  if (m_interpreter) {
+
+    std::string os_plugin_class_name(
+        python_module_path.GetFilename().AsCString(""));
+    if (!os_plugin_class_name.empty()) {
+      const bool init_session = false;
+      const bool allow_reload = true;
+      char python_module_path_cstr[PATH_MAX];
+      python_module_path.GetPath(python_module_path_cstr,
+                                 sizeof(python_module_path_cstr));
+      Error error;
+      if (m_interpreter->LoadScriptingModule(
+              python_module_path_cstr, allow_reload, init_session, error)) {
+        // Strip the ".py" extension if there is one
+        size_t py_extension_pos = os_plugin_class_name.rfind(".py");
+        if (py_extension_pos != std::string::npos)
+          os_plugin_class_name.erase(py_extension_pos);
+        // Add ".OperatingSystemPlugIn" to the module name to get a string like
+        // "modulename.OperatingSystemPlugIn"
+        os_plugin_class_name += ".OperatingSystemPlugIn";
+        StructuredData::ObjectSP object_sp =
+            m_interpreter->OSPlugin_CreatePluginObject(
+                os_plugin_class_name.c_str(), process->CalculateProcess());
+        if (object_sp && object_sp->IsValid())
+          m_python_object_sp = object_sp;
+      }
     }
-    return NULL;
-}
-
-
-ConstString
-OperatingSystemPython::GetPluginNameStatic()
-{
-    static ConstString g_name("python");
-    return g_name;
-}
-
-const char *
-OperatingSystemPython::GetPluginDescriptionStatic()
-{
-    return "Operating system plug-in that gathers OS information from a python class that implements the necessary OperatingSystem functionality.";
+  }
 }
 
+OperatingSystemPython::~OperatingSystemPython() {}
 
-OperatingSystemPython::OperatingSystemPython (lldb_private::Process *process, const FileSpec &python_module_path) :
-    OperatingSystem (process),
-    m_thread_list_valobj_sp (),
-    m_register_info_ap (),
-    m_interpreter (NULL),
-    m_python_object_sp ()
-{
-    if (!process)
-        return;
-    TargetSP target_sp = process->CalculateTarget();
-    if (!target_sp)
-        return;
-    m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
-    if (m_interpreter)
-    {
-        
-        std::string os_plugin_class_name (python_module_path.GetFilename().AsCString(""));
-        if (!os_plugin_class_name.empty())
-        {
-            const bool init_session = false;
-            const bool allow_reload = true;
-            char python_module_path_cstr[PATH_MAX];
-            python_module_path.GetPath(python_module_path_cstr, sizeof(python_module_path_cstr));
-            Error error;
-            if (m_interpreter->LoadScriptingModule (python_module_path_cstr, allow_reload, init_session, error))
-            {
-                // Strip the ".py" extension if there is one
-                size_t py_extension_pos = os_plugin_class_name.rfind(".py");
-                if (py_extension_pos != std::string::npos)
-                    os_plugin_class_name.erase (py_extension_pos);
-                // Add ".OperatingSystemPlugIn" to the module name to get a string like "modulename.OperatingSystemPlugIn"
-                os_plugin_class_name += ".OperatingSystemPlugIn";
-                StructuredData::ObjectSP object_sp =
-                    m_interpreter->OSPlugin_CreatePluginObject(os_plugin_class_name.c_str(), process->CalculateProcess());
-                if (object_sp && object_sp->IsValid())
-                    m_python_object_sp = object_sp;
-            }
-        }
-    }
-}
-
-OperatingSystemPython::~OperatingSystemPython ()
-{
-}
+DynamicRegisterInfo *OperatingSystemPython::GetDynamicRegisterInfo() {
+  if (m_register_info_ap.get() == NULL) {
+    if (!m_interpreter || !m_python_object_sp)
+      return NULL;
+    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
 
-DynamicRegisterInfo *
-OperatingSystemPython::GetDynamicRegisterInfo ()
-{
-    if (m_register_info_ap.get() == NULL)
-    {
-        if (!m_interpreter || !m_python_object_sp)
-            return NULL;
-        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OS));
-        
-        if (log)
-            log->Printf ("OperatingSystemPython::GetDynamicRegisterInfo() fetching thread register definitions from python for pid %" PRIu64, m_process->GetID());
-
-        StructuredData::DictionarySP dictionary = m_interpreter->OSPlugin_RegisterInfo(m_python_object_sp);
-        if (!dictionary)
-            return NULL;
-
-        m_register_info_ap.reset(new DynamicRegisterInfo(*dictionary, m_process->GetTarget().GetArchitecture()));
-        assert (m_register_info_ap->GetNumRegisters() > 0);
-        assert (m_register_info_ap->GetNumRegisterSets() > 0);
-    }
-    return m_register_info_ap.get();
+    if (log)
+      log->Printf("OperatingSystemPython::GetDynamicRegisterInfo() fetching "
+                  "thread register definitions from python for pid %" PRIu64,
+                  m_process->GetID());
+
+    StructuredData::DictionarySP dictionary =
+        m_interpreter->OSPlugin_RegisterInfo(m_python_object_sp);
+    if (!dictionary)
+      return NULL;
+
+    m_register_info_ap.reset(new DynamicRegisterInfo(
+        *dictionary, m_process->GetTarget().GetArchitecture()));
+    assert(m_register_info_ap->GetNumRegisters() > 0);
+    assert(m_register_info_ap->GetNumRegisterSets() > 0);
+  }
+  return m_register_info_ap.get();
 }
 
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
-ConstString
-OperatingSystemPython::GetPluginName()
-{
-    return GetPluginNameStatic();
-}
-
-uint32_t
-OperatingSystemPython::GetPluginVersion()
-{
-    return 1;
-}
-
-bool
-OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
-                                         ThreadList &core_thread_list,
-                                         ThreadList &new_thread_list)
-{
-    if (!m_interpreter || !m_python_object_sp)
-        return false;
-    
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OS));
-    
-    // First thing we have to do is to try to get the API lock, and the run lock.
-    // We're going to change the thread content of the process, and we're going
-    // to use python, which requires the API lock to do it.
-    //
-    // If someone already has the API lock, that is ok, we just want to avoid
-    // external code from making new API calls while this call is happening.
-    //
-    // This is a recursive lock so we can grant it to any Python code called on
-    // the stack below us.
-    Target &target = m_process->GetTarget();
-    std::unique_lock<std::recursive_mutex> lock(target.GetAPIMutex(), std::defer_lock);
-    lock.try_lock();
-
-    if (log)
-        log->Printf ("OperatingSystemPython::UpdateThreadList() fetching thread data from python for pid %" PRIu64, m_process->GetID());
-
-    // The threads that are in "new_thread_list" upon entry are the threads from the
-    // lldb_private::Process subclass, no memory threads will be in this list.
-
-    auto interpreter_lock = m_interpreter->AcquireInterpreterLock(); // to make sure threads_list stays alive
-    StructuredData::ArraySP threads_list = m_interpreter->OSPlugin_ThreadsInfo(m_python_object_sp);
-
-    const uint32_t num_cores = core_thread_list.GetSize(false);
-    
-    // Make a map so we can keep track of which cores were used from the
-    // core_thread list. Any real threads/cores that weren't used should
-    // later be put back into the "new_thread_list".
-    std::vector<bool> core_used_map(num_cores, false);
-    if (threads_list)
-    {
-        if (log)
-        {
-            StreamString strm;
-            threads_list->Dump(strm);
-            log->Printf("threads_list = %s", strm.GetString().c_str());
-        }
-
-        const uint32_t num_threads = threads_list->GetSize();
-        for (uint32_t i = 0; i < num_threads; ++i)
-        {
-            StructuredData::ObjectSP thread_dict_obj = threads_list->GetItemAtIndex(i);
-            if (auto thread_dict = thread_dict_obj->GetAsDictionary())
-            {
-                ThreadSP thread_sp(CreateThreadFromThreadInfo(*thread_dict, core_thread_list, old_thread_list, core_used_map, NULL));
-                if (thread_sp)
-                    new_thread_list.AddThread(thread_sp);
-            }
-        }
-    }
-
-    // Any real core threads that didn't end up backing a memory thread should
-    // still be in the main thread list, and they should be inserted at the beginning
-    // of the list
-    uint32_t insert_idx = 0;
-    for (uint32_t core_idx = 0; core_idx < num_cores; ++core_idx)
-    {
-        if (core_used_map[core_idx] == false)
-        {
-            new_thread_list.InsertThread (core_thread_list.GetThreadAtIndex(core_idx, false), insert_idx);
-            ++insert_idx;
-        }
-    }
-
-    return new_thread_list.GetSize(false) > 0;
+ConstString OperatingSystemPython::GetPluginName() {
+  return GetPluginNameStatic();
 }
 
-ThreadSP
-OperatingSystemPython::CreateThreadFromThreadInfo(StructuredData::Dictionary &thread_dict, ThreadList &core_thread_list,
-                                                  ThreadList &old_thread_list, std::vector<bool> &core_used_map, bool *did_create_ptr)
-{
-    ThreadSP thread_sp;
-    tid_t tid = LLDB_INVALID_THREAD_ID;
-    if (!thread_dict.GetValueForKeyAsInteger("tid", tid))
-        return ThreadSP();
-
-    uint32_t core_number;
-    addr_t reg_data_addr;
-    std::string name;
-    std::string queue;
-
-    thread_dict.GetValueForKeyAsInteger("core", core_number, UINT32_MAX);
-    thread_dict.GetValueForKeyAsInteger("register_data_addr", reg_data_addr, LLDB_INVALID_ADDRESS);
-    thread_dict.GetValueForKeyAsString("name", name);
-    thread_dict.GetValueForKeyAsString("queue", queue);
-
-    // See if a thread already exists for "tid"
-    thread_sp = old_thread_list.FindThreadByID(tid, false);
-    if (thread_sp)
-    {
-        // A thread already does exist for "tid", make sure it was an operating system
-        // plug-in generated thread.
-        if (!IsOperatingSystemPluginThread(thread_sp))
-        {
-            // We have thread ID overlap between the protocol threads and the
-            // operating system threads, clear the thread so we create an
-            // operating system thread for this.
-            thread_sp.reset();
-        }
-    }
+uint32_t OperatingSystemPython::GetPluginVersion() { return 1; }
 
-    if (!thread_sp)
-    {
-        if (did_create_ptr)
-            *did_create_ptr = true;
-        thread_sp.reset(new ThreadMemory(*m_process, tid, name.c_str(), queue.c_str(), reg_data_addr));
-    }
+bool OperatingSystemPython::UpdateThreadList(ThreadList &old_thread_list,
+                                             ThreadList &core_thread_list,
+                                             ThreadList &new_thread_list) {
+  if (!m_interpreter || !m_python_object_sp)
+    return false;
+
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS));
+
+  // First thing we have to do is to try to get the API lock, and the run lock.
+  // We're going to change the thread content of the process, and we're going
+  // to use python, which requires the API lock to do it.
+  //
+  // If someone already has the API lock, that is ok, we just want to avoid
+  // external code from making new API calls while this call is happening.
+  //
+  // This is a recursive lock so we can grant it to any Python code called on
+  // the stack below us.
+  Target &target = m_process->GetTarget();
+  std::unique_lock<std::recursive_mutex> lock(target.GetAPIMutex(),
+                                              std::defer_lock);
+  lock.try_lock();
+
+  if (log)
+    log->Printf("OperatingSystemPython::UpdateThreadList() fetching thread "
+                "data from python for pid %" PRIu64,
+                m_process->GetID());
+
+  // The threads that are in "new_thread_list" upon entry are the threads from
+  // the
+  // lldb_private::Process subclass, no memory threads will be in this list.
+
+  auto interpreter_lock =
+      m_interpreter
+          ->AcquireInterpreterLock(); // to make sure threads_list stays alive
+  StructuredData::ArraySP threads_list =
+      m_interpreter->OSPlugin_ThreadsInfo(m_python_object_sp);
+
+  const uint32_t num_cores = core_thread_list.GetSize(false);
+
+  // Make a map so we can keep track of which cores were used from the
+  // core_thread list. Any real threads/cores that weren't used should
+  // later be put back into the "new_thread_list".
+  std::vector<bool> core_used_map(num_cores, false);
+  if (threads_list) {
+    if (log) {
+      StreamString strm;
+      threads_list->Dump(strm);
+      log->Printf("threads_list = %s", strm.GetString().c_str());
+    }
+
+    const uint32_t num_threads = threads_list->GetSize();
+    for (uint32_t i = 0; i < num_threads; ++i) {
+      StructuredData::ObjectSP thread_dict_obj =
+          threads_list->GetItemAtIndex(i);
+      if (auto thread_dict = thread_dict_obj->GetAsDictionary()) {
+        ThreadSP thread_sp(
+            CreateThreadFromThreadInfo(*thread_dict, core_thread_list,
+                                       old_thread_list, core_used_map, NULL));
+        if (thread_sp)
+          new_thread_list.AddThread(thread_sp);
+      }
+    }
+  }
+
+  // Any real core threads that didn't end up backing a memory thread should
+  // still be in the main thread list, and they should be inserted at the
+  // beginning
+  // of the list
+  uint32_t insert_idx = 0;
+  for (uint32_t core_idx = 0; core_idx < num_cores; ++core_idx) {
+    if (core_used_map[core_idx] == false) {
+      new_thread_list.InsertThread(
+          core_thread_list.GetThreadAtIndex(core_idx, false), insert_idx);
+      ++insert_idx;
+    }
+  }
+
+  return new_thread_list.GetSize(false) > 0;
+}
+
+ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo(
+    StructuredData::Dictionary &thread_dict, ThreadList &core_thread_list,
+    ThreadList &old_thread_list, std::vector<bool> &core_used_map,
+    bool *did_create_ptr) {
+  ThreadSP thread_sp;
+  tid_t tid = LLDB_INVALID_THREAD_ID;
+  if (!thread_dict.GetValueForKeyAsInteger("tid", tid))
+    return ThreadSP();
 
-    if (core_number < core_thread_list.GetSize(false))
-    {
-        ThreadSP core_thread_sp(core_thread_list.GetThreadAtIndex(core_number, false));
-        if (core_thread_sp)
-        {
-            // Keep track of which cores were set as the backing thread for memory threads...
-            if (core_number < core_used_map.size())
-                core_used_map[core_number] = true;
-
-            ThreadSP backing_core_thread_sp(core_thread_sp->GetBackingThread());
-            if (backing_core_thread_sp)
-            {
-                thread_sp->SetBackingThread(backing_core_thread_sp);
-            }
-            else
-            {
-                thread_sp->SetBackingThread(core_thread_sp);
-            }
-        }
+  uint32_t core_number;
+  addr_t reg_data_addr;
+  std::string name;
+  std::string queue;
+
+  thread_dict.GetValueForKeyAsInteger("core", core_number, UINT32_MAX);
+  thread_dict.GetValueForKeyAsInteger("register_data_addr", reg_data_addr,
+                                      LLDB_INVALID_ADDRESS);
+  thread_dict.GetValueForKeyAsString("name", name);
+  thread_dict.GetValueForKeyAsString("queue", queue);
+
+  // See if a thread already exists for "tid"
+  thread_sp = old_thread_list.FindThreadByID(tid, false);
+  if (thread_sp) {
+    // A thread already does exist for "tid", make sure it was an operating
+    // system
+    // plug-in generated thread.
+    if (!IsOperatingSystemPluginThread(thread_sp)) {
+      // We have thread ID overlap between the protocol threads and the
+      // operating system threads, clear the thread so we create an
+      // operating system thread for this.
+      thread_sp.reset();
+    }
+  }
+
+  if (!thread_sp) {
+    if (did_create_ptr)
+      *did_create_ptr = true;
+    thread_sp.reset(new ThreadMemory(*m_process, tid, name.c_str(),
+                                     queue.c_str(), reg_data_addr));
+  }
+
+  if (core_number < core_thread_list.GetSize(false)) {
+    ThreadSP core_thread_sp(
+        core_thread_list.GetThreadAtIndex(core_number, false));
+    if (core_thread_sp) {
+      // Keep track of which cores were set as the backing thread for memory
+      // threads...
+      if (core_number < core_used_map.size())
+        core_used_map[core_number] = true;
+
+      ThreadSP backing_core_thread_sp(core_thread_sp->GetBackingThread());
+      if (backing_core_thread_sp) {
+        thread_sp->SetBackingThread(backing_core_thread_sp);
+      } else {
+        thread_sp->SetBackingThread(core_thread_sp);
+      }
     }
-    return thread_sp;
+  }
+  return thread_sp;
 }
 
-
-
-void
-OperatingSystemPython::ThreadWasSelected (Thread *thread)
-{
-}
+void OperatingSystemPython::ThreadWasSelected(Thread *thread) {}
 
 RegisterContextSP
-OperatingSystemPython::CreateRegisterContextForThread (Thread *thread, addr_t reg_data_addr)
-{
-    RegisterContextSP reg_ctx_sp;
-    if (!m_interpreter || !m_python_object_sp || !thread)
-        return reg_ctx_sp;
-
-    if (!IsOperatingSystemPluginThread(thread->shared_from_this()))
-        return reg_ctx_sp;
-    
-    // First thing we have to do is get the API lock, and the run lock.  We're going to change the thread
-    // content of the process, and we're going to use python, which requires the API lock to do it.
-    // So get & hold that.  This is a recursive lock so we can grant it to any Python code called on the stack below us.
-    Target &target = m_process->GetTarget();
-    std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
+OperatingSystemPython::CreateRegisterContextForThread(Thread *thread,
+                                                      addr_t reg_data_addr) {
+  RegisterContextSP reg_ctx_sp;
+  if (!m_interpreter || !m_python_object_sp || !thread)
+    return reg_ctx_sp;
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
+  if (!IsOperatingSystemPluginThread(thread->shared_from_this()))
+    return reg_ctx_sp;
 
-    auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure python objects stays alive
-    if (reg_data_addr != LLDB_INVALID_ADDRESS)
-    {
-        // The registers data is in contiguous memory, just create the register
-        // context using the address provided
-        if (log)
-            log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ", 0x%" PRIx64 ", reg_data_addr = 0x%" PRIx64 ") creating memory register context",
-                         thread->GetID(),
-                         thread->GetProtocolID(),
-                         reg_data_addr);
-        reg_ctx_sp.reset (new RegisterContextMemory (*thread, 0, *GetDynamicRegisterInfo (), reg_data_addr));
-    }
-    else
-    {
-        // No register data address is provided, query the python plug-in to let
-        // it make up the data as it sees fit
-        if (log)
-            log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ", 0x%" PRIx64 ") fetching register data from python",
-                         thread->GetID(),
-                         thread->GetProtocolID());
-
-        StructuredData::StringSP reg_context_data = m_interpreter->OSPlugin_RegisterContextData(m_python_object_sp, thread->GetID());
-        if (reg_context_data)
-        {
-            std::string value = reg_context_data->GetValue();
-            DataBufferSP data_sp(new DataBufferHeap(value.c_str(), value.length()));
-            if (data_sp->GetByteSize())
-            {
-                RegisterContextMemory *reg_ctx_memory = new RegisterContextMemory (*thread, 0, *GetDynamicRegisterInfo (), LLDB_INVALID_ADDRESS);
-                if (reg_ctx_memory)
-                {
-                    reg_ctx_sp.reset(reg_ctx_memory);
-                    reg_ctx_memory->SetAllRegisterData (data_sp);
-                }
-            }
+  // First thing we have to do is get the API lock, and the run lock.  We're
+  // going to change the thread
+  // content of the process, and we're going to use python, which requires the
+  // API lock to do it.
+  // So get & hold that.  This is a recursive lock so we can grant it to any
+  // Python code called on the stack below us.
+  Target &target = m_process->GetTarget();
+  std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
+
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
+
+  auto lock =
+      m_interpreter
+          ->AcquireInterpreterLock(); // to make sure python objects stays alive
+  if (reg_data_addr != LLDB_INVALID_ADDRESS) {
+    // The registers data is in contiguous memory, just create the register
+    // context using the address provided
+    if (log)
+      log->Printf("OperatingSystemPython::CreateRegisterContextForThread (tid "
+                  "= 0x%" PRIx64 ", 0x%" PRIx64 ", reg_data_addr = 0x%" PRIx64
+                  ") creating memory register context",
+                  thread->GetID(), thread->GetProtocolID(), reg_data_addr);
+    reg_ctx_sp.reset(new RegisterContextMemory(
+        *thread, 0, *GetDynamicRegisterInfo(), reg_data_addr));
+  } else {
+    // No register data address is provided, query the python plug-in to let
+    // it make up the data as it sees fit
+    if (log)
+      log->Printf("OperatingSystemPython::CreateRegisterContextForThread (tid "
+                  "= 0x%" PRIx64 ", 0x%" PRIx64
+                  ") fetching register data from python",
+                  thread->GetID(), thread->GetProtocolID());
+
+    StructuredData::StringSP reg_context_data =
+        m_interpreter->OSPlugin_RegisterContextData(m_python_object_sp,
+                                                    thread->GetID());
+    if (reg_context_data) {
+      std::string value = reg_context_data->GetValue();
+      DataBufferSP data_sp(new DataBufferHeap(value.c_str(), value.length()));
+      if (data_sp->GetByteSize()) {
+        RegisterContextMemory *reg_ctx_memory = new RegisterContextMemory(
+            *thread, 0, *GetDynamicRegisterInfo(), LLDB_INVALID_ADDRESS);
+        if (reg_ctx_memory) {
+          reg_ctx_sp.reset(reg_ctx_memory);
+          reg_ctx_memory->SetAllRegisterData(data_sp);
         }
+      }
     }
-    // if we still have no register data, fallback on a dummy context to avoid crashing
-    if (!reg_ctx_sp)
-    {
-        if (log)
-            log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ") forcing a dummy register context", thread->GetID());
-        reg_ctx_sp.reset(new RegisterContextDummy(*thread,0,target.GetArchitecture().GetAddressByteSize()));
-    }
-    return reg_ctx_sp;
+  }
+  // if we still have no register data, fallback on a dummy context to avoid
+  // crashing
+  if (!reg_ctx_sp) {
+    if (log)
+      log->Printf("OperatingSystemPython::CreateRegisterContextForThread (tid "
+                  "= 0x%" PRIx64 ") forcing a dummy register context",
+                  thread->GetID());
+    reg_ctx_sp.reset(new RegisterContextDummy(
+        *thread, 0, target.GetArchitecture().GetAddressByteSize()));
+  }
+  return reg_ctx_sp;
 }
 
 StopInfoSP
-OperatingSystemPython::CreateThreadStopReason (lldb_private::Thread *thread)
-{
-    // We should have gotten the thread stop info from the dictionary of data for
-    // the thread in the initial call to get_thread_info(), this should have been
-    // cached so we can return it here
-    StopInfoSP stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP));
-    return stop_info_sp;
-}
+OperatingSystemPython::CreateThreadStopReason(lldb_private::Thread *thread) {
+  // We should have gotten the thread stop info from the dictionary of data for
+  // the thread in the initial call to get_thread_info(), this should have been
+  // cached so we can return it here
+  StopInfoSP
+      stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP));
+  return stop_info_sp;
+}
+
+lldb::ThreadSP OperatingSystemPython::CreateThread(lldb::tid_t tid,
+                                                   addr_t context) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
+
+  if (log)
+    log->Printf("OperatingSystemPython::CreateThread (tid = 0x%" PRIx64
+                ", context = 0x%" PRIx64 ") fetching register data from python",
+                tid, context);
+
+  if (m_interpreter && m_python_object_sp) {
+    // First thing we have to do is get the API lock, and the run lock.  We're
+    // going to change the thread
+    // content of the process, and we're going to use python, which requires the
+    // API lock to do it.
+    // So get & hold that.  This is a recursive lock so we can grant it to any
+    // Python code called on the stack below us.
+    Target &target = m_process->GetTarget();
+    std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
 
-lldb::ThreadSP
-OperatingSystemPython::CreateThread (lldb::tid_t tid, addr_t context)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
-    
-    if (log)
-        log->Printf ("OperatingSystemPython::CreateThread (tid = 0x%" PRIx64 ", context = 0x%" PRIx64 ") fetching register data from python", tid, context);
-    
-    if (m_interpreter && m_python_object_sp)
-    {
-        // First thing we have to do is get the API lock, and the run lock.  We're going to change the thread
-        // content of the process, and we're going to use python, which requires the API lock to do it.
-        // So get & hold that.  This is a recursive lock so we can grant it to any Python code called on the stack below us.
-        Target &target = m_process->GetTarget();
-        std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
-
-        auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure thread_info_dict stays alive
-        StructuredData::DictionarySP thread_info_dict = m_interpreter->OSPlugin_CreateThread(m_python_object_sp, tid, context);
-        std::vector<bool> core_used_map;
-        if (thread_info_dict)
-        {
-            ThreadList core_threads(m_process);
-            ThreadList &thread_list = m_process->GetThreadList();
-            bool did_create = false;
-            ThreadSP thread_sp(CreateThreadFromThreadInfo(*thread_info_dict, core_threads, thread_list, core_used_map, &did_create));
-            if (did_create)
-                thread_list.AddThread(thread_sp);
-            return thread_sp;
-        }
+    auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure
+                                                         // thread_info_dict
+                                                         // stays alive
+    StructuredData::DictionarySP thread_info_dict =
+        m_interpreter->OSPlugin_CreateThread(m_python_object_sp, tid, context);
+    std::vector<bool> core_used_map;
+    if (thread_info_dict) {
+      ThreadList core_threads(m_process);
+      ThreadList &thread_list = m_process->GetThreadList();
+      bool did_create = false;
+      ThreadSP thread_sp(
+          CreateThreadFromThreadInfo(*thread_info_dict, core_threads,
+                                     thread_list, core_used_map, &did_create));
+      if (did_create)
+        thread_list.AddThread(thread_sp);
+      return thread_sp;
     }
-    return ThreadSP();
+  }
+  return ThreadSP();
 }
 
-
-
 #endif // #ifndef LLDB_DISABLE_PYTHON

Modified: lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h (original)
+++ lldb/trunk/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h Tue Sep  6 15:57:50 2016
@@ -21,87 +21,76 @@
 
 class DynamicRegisterInfo;
 
-namespace lldb_private
-{
+namespace lldb_private {
 class ScriptInterpreter;
 }
 
-class OperatingSystemPython : public lldb_private::OperatingSystem
-{
+class OperatingSystemPython : public lldb_private::OperatingSystem {
 public:
-    OperatingSystemPython(lldb_private::Process *process,
-                          const lldb_private::FileSpec &python_module_path);
+  OperatingSystemPython(lldb_private::Process *process,
+                        const lldb_private::FileSpec &python_module_path);
 
-    ~OperatingSystemPython() override;
+  ~OperatingSystemPython() override;
 
-    //------------------------------------------------------------------
-    // Static Functions
-    //------------------------------------------------------------------
-    static lldb_private::OperatingSystem *
-    CreateInstance (lldb_private::Process *process, bool force);
-    
-    static void
-    Initialize();
-    
-    static void
-    Terminate();
-    
-    static lldb_private::ConstString
-    GetPluginNameStatic();
-    
-    static const char *
-    GetPluginDescriptionStatic();
-    
-    //------------------------------------------------------------------
-    // lldb_private::PluginInterface Methods
-    //------------------------------------------------------------------
-    lldb_private::ConstString
-    GetPluginName() override;
-    
-    uint32_t
-    GetPluginVersion() override;
-    
-    //------------------------------------------------------------------
-    // lldb_private::OperatingSystem Methods
-    //------------------------------------------------------------------
-    bool
-    UpdateThreadList(lldb_private::ThreadList &old_thread_list,
-                     lldb_private::ThreadList &real_thread_list,
-                     lldb_private::ThreadList &new_thread_list) override;
-    
-    void
-    ThreadWasSelected(lldb_private::Thread *thread) override;
-
-    lldb::RegisterContextSP
-    CreateRegisterContextForThread(lldb_private::Thread *thread,
-                                   lldb::addr_t reg_data_addr) override;
-
-    lldb::StopInfoSP
-    CreateThreadStopReason(lldb_private::Thread *thread) override;
-
-    //------------------------------------------------------------------
-    // Method for lazy creation of threads on demand
-    //------------------------------------------------------------------
-    lldb::ThreadSP
-    CreateThread(lldb::tid_t tid, lldb::addr_t context) override;
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+  static lldb_private::OperatingSystem *
+  CreateInstance(lldb_private::Process *process, bool force);
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static const char *GetPluginDescriptionStatic();
+
+  //------------------------------------------------------------------
+  // lldb_private::PluginInterface Methods
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+
+  //------------------------------------------------------------------
+  // lldb_private::OperatingSystem Methods
+  //------------------------------------------------------------------
+  bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
+                        lldb_private::ThreadList &real_thread_list,
+                        lldb_private::ThreadList &new_thread_list) override;
+
+  void ThreadWasSelected(lldb_private::Thread *thread) override;
+
+  lldb::RegisterContextSP
+  CreateRegisterContextForThread(lldb_private::Thread *thread,
+                                 lldb::addr_t reg_data_addr) override;
+
+  lldb::StopInfoSP
+  CreateThreadStopReason(lldb_private::Thread *thread) override;
+
+  //------------------------------------------------------------------
+  // Method for lazy creation of threads on demand
+  //------------------------------------------------------------------
+  lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override;
 
 protected:
-    bool IsValid() const
-    {
-        return m_python_object_sp && m_python_object_sp->IsValid();
-    }
-
-    lldb::ThreadSP CreateThreadFromThreadInfo(lldb_private::StructuredData::Dictionary &thread_dict,
-                                              lldb_private::ThreadList &core_thread_list, lldb_private::ThreadList &old_thread_list,
-                                              std::vector<bool> &core_used_map, bool *did_create_ptr);
-
-    DynamicRegisterInfo *
-    GetDynamicRegisterInfo ();
-
-    lldb::ValueObjectSP m_thread_list_valobj_sp;
-    std::unique_ptr<DynamicRegisterInfo> m_register_info_ap;
-    lldb_private::ScriptInterpreter *m_interpreter;
-    lldb_private::StructuredData::ObjectSP m_python_object_sp;
+  bool IsValid() const {
+    return m_python_object_sp && m_python_object_sp->IsValid();
+  }
+
+  lldb::ThreadSP CreateThreadFromThreadInfo(
+      lldb_private::StructuredData::Dictionary &thread_dict,
+      lldb_private::ThreadList &core_thread_list,
+      lldb_private::ThreadList &old_thread_list,
+      std::vector<bool> &core_used_map, bool *did_create_ptr);
+
+  DynamicRegisterInfo *GetDynamicRegisterInfo();
+
+  lldb::ValueObjectSP m_thread_list_valobj_sp;
+  std::unique_ptr<DynamicRegisterInfo> m_register_info_ap;
+  lldb_private::ScriptInterpreter *m_interpreter;
+  lldb_private::StructuredData::ObjectSP m_python_object_sp;
 };
 
 #endif // LLDB_DISABLE_PYTHON

Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Tue Sep  6 15:57:50 2016
@@ -10,9 +10,9 @@
 // Other libraries and framework includes
 #include "AdbClient.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FileUtilities.h"
 
 #include "lldb/Core/DataBuffer.h"
@@ -44,663 +44,602 @@ using namespace lldb_private::platform_a
 namespace {
 
 const std::chrono::seconds kReadTimeout(8);
-const char * kOKAY = "OKAY";
-const char * kFAIL = "FAIL";
-const char * kDATA = "DATA";
-const char * kDONE = "DONE";
-
-const char * kSEND = "SEND";
-const char * kRECV = "RECV";
-const char * kSTAT = "STAT";
+const char *kOKAY = "OKAY";
+const char *kFAIL = "FAIL";
+const char *kDATA = "DATA";
+const char *kDONE = "DONE";
+
+const char *kSEND = "SEND";
+const char *kRECV = "RECV";
+const char *kSTAT = "STAT";
 
 const size_t kSyncPacketLen = 8;
 // Maximum size of a filesync DATA packet.
-const size_t kMaxPushData = 2*1024;
+const size_t kMaxPushData = 2 * 1024;
 // Default mode for pushed files.
 const uint32_t kDefaultMode = 0100770; // S_IFREG | S_IRWXU | S_IRWXG
 
-const char * kSocketNamespaceAbstract = "localabstract";
-const char * kSocketNamespaceFileSystem = "localfilesystem";
+const char *kSocketNamespaceAbstract = "localabstract";
+const char *kSocketNamespaceFileSystem = "localfilesystem";
 
-Error
-ReadAllBytes (Connection &conn, void *buffer, size_t size)
-{
-    using namespace std::chrono;
-
-    Error error;
-    ConnectionStatus status;
-    char *read_buffer = static_cast<char*>(buffer);
-
-    auto now = steady_clock::now();
-    const auto deadline = now + kReadTimeout;
-    size_t total_read_bytes = 0;
-    while (total_read_bytes < size && now < deadline)
-    {
-        uint32_t timeout_usec = duration_cast<microseconds>(deadline - now).count();
-        auto read_bytes =
-            conn.Read(read_buffer + total_read_bytes, size - total_read_bytes, timeout_usec, status, &error);
-        if (error.Fail ())
-            return error;
-        total_read_bytes += read_bytes;
-        if (status != eConnectionStatusSuccess)
-            break;
-        now = steady_clock::now();
-    }
-    if (total_read_bytes < size)
-        error = Error("Unable to read requested number of bytes. Connection status: %d.", status);
-    return error;
-}
+Error ReadAllBytes(Connection &conn, void *buffer, size_t size) {
+  using namespace std::chrono;
 
-}  // namespace
-
-Error
-AdbClient::CreateByDeviceID(const std::string &device_id, AdbClient &adb)
-{
-    DeviceIDList connect_devices;
-    auto error = adb.GetDevices(connect_devices);
+  Error error;
+  ConnectionStatus status;
+  char *read_buffer = static_cast<char *>(buffer);
+
+  auto now = steady_clock::now();
+  const auto deadline = now + kReadTimeout;
+  size_t total_read_bytes = 0;
+  while (total_read_bytes < size && now < deadline) {
+    uint32_t timeout_usec = duration_cast<microseconds>(deadline - now).count();
+    auto read_bytes =
+        conn.Read(read_buffer + total_read_bytes, size - total_read_bytes,
+                  timeout_usec, status, &error);
     if (error.Fail())
-        return error;
-
-    std::string android_serial;
-    if (!device_id.empty())
-        android_serial = device_id;
-    else if (const char *env_serial = std::getenv("ANDROID_SERIAL"))
-        android_serial = env_serial;
-
-    if (android_serial.empty())
-    {
-        if (connect_devices.size() != 1)
-            return Error("Expected a single connected device, got instead %zu - try setting 'ANDROID_SERIAL'",
-                         connect_devices.size());
-        adb.SetDeviceID(connect_devices.front());
-    }
-    else
-    {
-        auto find_it = std::find(connect_devices.begin(), connect_devices.end(), android_serial);
-        if (find_it == connect_devices.end())
-            return Error("Device \"%s\" not found", android_serial.c_str());
-
-        adb.SetDeviceID(*find_it);
-    }
-    return error;
+      return error;
+    total_read_bytes += read_bytes;
+    if (status != eConnectionStatusSuccess)
+      break;
+    now = steady_clock::now();
+  }
+  if (total_read_bytes < size)
+    error = Error(
+        "Unable to read requested number of bytes. Connection status: %d.",
+        status);
+  return error;
+}
+
+} // namespace
+
+Error AdbClient::CreateByDeviceID(const std::string &device_id,
+                                  AdbClient &adb) {
+  DeviceIDList connect_devices;
+  auto error = adb.GetDevices(connect_devices);
+  if (error.Fail())
+    return error;
+
+  std::string android_serial;
+  if (!device_id.empty())
+    android_serial = device_id;
+  else if (const char *env_serial = std::getenv("ANDROID_SERIAL"))
+    android_serial = env_serial;
+
+  if (android_serial.empty()) {
+    if (connect_devices.size() != 1)
+      return Error("Expected a single connected device, got instead %zu - try "
+                   "setting 'ANDROID_SERIAL'",
+                   connect_devices.size());
+    adb.SetDeviceID(connect_devices.front());
+  } else {
+    auto find_it = std::find(connect_devices.begin(), connect_devices.end(),
+                             android_serial);
+    if (find_it == connect_devices.end())
+      return Error("Device \"%s\" not found", android_serial.c_str());
+
+    adb.SetDeviceID(*find_it);
+  }
+  return error;
 }
 
-AdbClient::AdbClient () {}
-
-AdbClient::AdbClient (const std::string &device_id)
-    : m_device_id (device_id)
-{
-}
+AdbClient::AdbClient() {}
+
+AdbClient::AdbClient(const std::string &device_id) : m_device_id(device_id) {}
 
 AdbClient::~AdbClient() {}
 
-void
-AdbClient::SetDeviceID (const std::string &device_id)
-{
-    m_device_id = device_id;
+void AdbClient::SetDeviceID(const std::string &device_id) {
+  m_device_id = device_id;
 }
 
-const std::string&
-AdbClient::GetDeviceID() const
-{
-    return m_device_id;
+const std::string &AdbClient::GetDeviceID() const { return m_device_id; }
+
+Error AdbClient::Connect() {
+  Error error;
+  m_conn.reset(new ConnectionFileDescriptor);
+  m_conn->Connect("connect://localhost:5037", &error);
+
+  return error;
 }
 
-Error
-AdbClient::Connect ()
-{
-    Error error;
-    m_conn.reset (new ConnectionFileDescriptor);
-    m_conn->Connect ("connect://localhost:5037", &error);
+Error AdbClient::GetDevices(DeviceIDList &device_list) {
+  device_list.clear();
 
+  auto error = SendMessage("host:devices");
+  if (error.Fail())
     return error;
-}
 
-Error
-AdbClient::GetDevices (DeviceIDList &device_list)
-{
-    device_list.clear ();
+  error = ReadResponseStatus();
+  if (error.Fail())
+    return error;
 
-    auto error = SendMessage ("host:devices");
-    if (error.Fail ())
-        return error;
+  std::vector<char> in_buffer;
+  error = ReadMessage(in_buffer);
 
-    error = ReadResponseStatus ();
-    if (error.Fail ())
-        return error;
+  llvm::StringRef response(&in_buffer[0], in_buffer.size());
+  llvm::SmallVector<llvm::StringRef, 4> devices;
+  response.split(devices, "\n", -1, false);
 
-    std::vector<char> in_buffer;
-    error = ReadMessage (in_buffer);
+  for (const auto device : devices)
+    device_list.push_back(device.split('\t').first);
 
-    llvm::StringRef response (&in_buffer[0], in_buffer.size ());
-    llvm::SmallVector<llvm::StringRef, 4> devices;
-    response.split (devices, "\n", -1, false);
+  // Force disconnect since ADB closes connection after host:devices
+  // response is sent.
+  m_conn.reset();
+  return error;
+}
 
-    for (const auto device: devices)
-        device_list.push_back (device.split ('\t').first);
+Error AdbClient::SetPortForwarding(const uint16_t local_port,
+                                   const uint16_t remote_port) {
+  char message[48];
+  snprintf(message, sizeof(message), "forward:tcp:%d;tcp:%d", local_port,
+           remote_port);
 
-    // Force disconnect since ADB closes connection after host:devices
-    // response is sent.
-    m_conn.reset ();
+  const auto error = SendDeviceMessage(message);
+  if (error.Fail())
     return error;
+
+  return ReadResponseStatus();
 }
 
-Error
-AdbClient::SetPortForwarding (const uint16_t local_port, const uint16_t remote_port)
-{
-    char message[48];
-    snprintf (message, sizeof (message), "forward:tcp:%d;tcp:%d", local_port, remote_port);
+Error AdbClient::SetPortForwarding(const uint16_t local_port,
+                                   const char *remote_socket_name,
+                                   const UnixSocketNamespace socket_namespace) {
+  char message[PATH_MAX];
+  const char *sock_namespace_str =
+      (socket_namespace == UnixSocketNamespaceAbstract)
+          ? kSocketNamespaceAbstract
+          : kSocketNamespaceFileSystem;
+  snprintf(message, sizeof(message), "forward:tcp:%d;%s:%s", local_port,
+           sock_namespace_str, remote_socket_name);
 
-    const auto error = SendDeviceMessage (message);
-    if (error.Fail ())
-        return error;
+  const auto error = SendDeviceMessage(message);
+  if (error.Fail())
+    return error;
 
-    return ReadResponseStatus ();
+  return ReadResponseStatus();
 }
 
-Error
-AdbClient::SetPortForwarding (const uint16_t local_port,
-                              const char* remote_socket_name,
-                              const UnixSocketNamespace socket_namespace)
-{
-    char message[PATH_MAX];
-    const char * sock_namespace_str = (socket_namespace == UnixSocketNamespaceAbstract) ?
-        kSocketNamespaceAbstract : kSocketNamespaceFileSystem;
-    snprintf (message, sizeof (message), "forward:tcp:%d;%s:%s",
-              local_port,
-              sock_namespace_str,
-              remote_socket_name);
+Error AdbClient::DeletePortForwarding(const uint16_t local_port) {
+  char message[32];
+  snprintf(message, sizeof(message), "killforward:tcp:%d", local_port);
 
-    const auto error = SendDeviceMessage (message);
-    if (error.Fail ())
-        return error;
+  const auto error = SendDeviceMessage(message);
+  if (error.Fail())
+    return error;
 
-    return ReadResponseStatus ();
+  return ReadResponseStatus();
 }
 
-Error
-AdbClient::DeletePortForwarding (const uint16_t local_port)
-{
-    char message[32];
-    snprintf (message, sizeof (message), "killforward:tcp:%d", local_port);
+Error AdbClient::SendMessage(const std::string &packet, const bool reconnect) {
+  Error error;
+  if (!m_conn || reconnect) {
+    error = Connect();
+    if (error.Fail())
+      return error;
+  }
 
-    const auto error = SendDeviceMessage (message);
-    if (error.Fail ())
-        return error;
+  char length_buffer[5];
+  snprintf(length_buffer, sizeof(length_buffer), "%04x",
+           static_cast<int>(packet.size()));
 
-    return ReadResponseStatus ();
-}
+  ConnectionStatus status;
+
+  m_conn->Write(length_buffer, 4, status, &error);
+  if (error.Fail())
+    return error;
 
-Error
-AdbClient::SendMessage (const std::string &packet, const bool reconnect)
-{
-    Error error;
-    if (!m_conn || reconnect)
-    {
-        error = Connect ();
-        if (error.Fail ())
-            return error;
-    }
+  m_conn->Write(packet.c_str(), packet.size(), status, &error);
+  return error;
+}
 
-    char length_buffer[5];
-    snprintf (length_buffer, sizeof (length_buffer), "%04x", static_cast<int>(packet.size ()));
+Error AdbClient::SendDeviceMessage(const std::string &packet) {
+  std::ostringstream msg;
+  msg << "host-serial:" << m_device_id << ":" << packet;
+  return SendMessage(msg.str());
+}
 
-    ConnectionStatus status;
+Error AdbClient::ReadMessage(std::vector<char> &message) {
+  message.clear();
 
-    m_conn->Write (length_buffer, 4, status, &error);
-    if (error.Fail ())
-        return error;
+  char buffer[5];
+  buffer[4] = 0;
 
-    m_conn->Write (packet.c_str (), packet.size (), status, &error);
+  auto error = ReadAllBytes(buffer, 4);
+  if (error.Fail())
     return error;
+
+  unsigned int packet_len = 0;
+  sscanf(buffer, "%x", &packet_len);
+
+  message.resize(packet_len, 0);
+  error = ReadAllBytes(&message[0], packet_len);
+  if (error.Fail())
+    message.clear();
+
+  return error;
 }
 
-Error
-AdbClient::SendDeviceMessage (const std::string &packet)
-{
-    std::ostringstream msg;
-    msg << "host-serial:" << m_device_id << ":" << packet;
-    return SendMessage (msg.str ());
+Error AdbClient::ReadMessageStream(std::vector<char> &message,
+                                   uint32_t timeout_ms) {
+  auto start = std::chrono::steady_clock::now();
+  message.clear();
+
+  Error error;
+  lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
+  char buffer[1024];
+  while (error.Success() && status == lldb::eConnectionStatusSuccess) {
+    auto end = std::chrono::steady_clock::now();
+    uint32_t elapsed_time =
+        std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
+            .count();
+    if (elapsed_time >= timeout_ms)
+      return Error("Timed out");
+
+    size_t n = m_conn->Read(buffer, sizeof(buffer),
+                            1000 * (timeout_ms - elapsed_time), status, &error);
+    if (n > 0)
+      message.insert(message.end(), &buffer[0], &buffer[n]);
+  }
+  return error;
 }
 
-Error
-AdbClient::ReadMessage (std::vector<char> &message)
-{
-    message.clear ();
+Error AdbClient::ReadResponseStatus() {
+  char response_id[5];
+
+  static const size_t packet_len = 4;
+  response_id[packet_len] = 0;
+
+  auto error = ReadAllBytes(response_id, packet_len);
+  if (error.Fail())
+    return error;
+
+  if (strncmp(response_id, kOKAY, packet_len) != 0)
+    return GetResponseError(response_id);
 
-    char buffer[5];
-    buffer[4] = 0;
+  return error;
+}
 
-    auto error = ReadAllBytes (buffer, 4);
-    if (error.Fail ())
-        return error;
+Error AdbClient::GetResponseError(const char *response_id) {
+  if (strcmp(response_id, kFAIL) != 0)
+    return Error("Got unexpected response id from adb: \"%s\"", response_id);
 
-    unsigned int packet_len = 0;
-    sscanf (buffer, "%x", &packet_len);
+  std::vector<char> error_message;
+  auto error = ReadMessage(error_message);
+  if (error.Success())
+    error.SetErrorString(
+        std::string(&error_message[0], error_message.size()).c_str());
+
+  return error;
+}
 
-    message.resize (packet_len, 0);
-    error = ReadAllBytes (&message[0], packet_len);
-    if (error.Fail ())
-        message.clear ();
+Error AdbClient::SwitchDeviceTransport() {
+  std::ostringstream msg;
+  msg << "host:transport:" << m_device_id;
 
+  auto error = SendMessage(msg.str());
+  if (error.Fail())
     return error;
+
+  return ReadResponseStatus();
 }
 
-Error
-AdbClient::ReadMessageStream (std::vector<char>& message, uint32_t timeout_ms)
-{
-    auto start = std::chrono::steady_clock::now();
-    message.clear();
+Error AdbClient::StartSync() {
+  auto error = SwitchDeviceTransport();
+  if (error.Fail())
+    return Error("Failed to switch to device transport: %s", error.AsCString());
 
-    Error error;
-    lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
-    char buffer[1024];
-    while (error.Success() && status == lldb::eConnectionStatusSuccess)
-    {
-        auto end = std::chrono::steady_clock::now();
-        uint32_t elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
-        if (elapsed_time >= timeout_ms)
-            return Error("Timed out");
+  error = Sync();
+  if (error.Fail())
+    return Error("Sync failed: %s", error.AsCString());
 
-        size_t n = m_conn->Read(buffer, sizeof(buffer), 1000 * (timeout_ms - elapsed_time), status, &error);
-        if (n > 0)
-            message.insert(message.end(), &buffer[0], &buffer[n]);
-    }
+  return error;
+}
+
+Error AdbClient::Sync() {
+  auto error = SendMessage("sync:", false);
+  if (error.Fail())
     return error;
+
+  return ReadResponseStatus();
 }
 
-Error
-AdbClient::ReadResponseStatus()
-{
-    char response_id[5];
+Error AdbClient::ReadAllBytes(void *buffer, size_t size) {
+  return ::ReadAllBytes(*m_conn, buffer, size);
+}
 
-    static const size_t packet_len = 4;
-    response_id[packet_len] = 0;
+Error AdbClient::internalShell(const char *command, uint32_t timeout_ms,
+                               std::vector<char> &output_buf) {
+  output_buf.clear();
 
-    auto error = ReadAllBytes (response_id, packet_len);
-    if (error.Fail ())
-        return error;
+  auto error = SwitchDeviceTransport();
+  if (error.Fail())
+    return Error("Failed to switch to device transport: %s", error.AsCString());
 
-    if (strncmp (response_id, kOKAY, packet_len) != 0)
-        return GetResponseError (response_id);
+  StreamString adb_command;
+  adb_command.Printf("shell:%s", command);
+  error = SendMessage(adb_command.GetData(), false);
+  if (error.Fail())
+    return error;
 
+  error = ReadResponseStatus();
+  if (error.Fail())
     return error;
+
+  error = ReadMessageStream(output_buf, timeout_ms);
+  if (error.Fail())
+    return error;
+
+  // ADB doesn't propagate return code of shell execution - if
+  // output starts with /system/bin/sh: most likely command failed.
+  static const char *kShellPrefix = "/system/bin/sh:";
+  if (output_buf.size() > strlen(kShellPrefix)) {
+    if (!memcmp(&output_buf[0], kShellPrefix, strlen(kShellPrefix)))
+      return Error("Shell command %s failed: %s", command,
+                   std::string(output_buf.begin(), output_buf.end()).c_str());
+  }
+
+  return Error();
 }
 
-Error
-AdbClient::GetResponseError (const char *response_id)
-{
-    if (strcmp (response_id, kFAIL) != 0)
-        return Error ("Got unexpected response id from adb: \"%s\"", response_id);
+Error AdbClient::Shell(const char *command, uint32_t timeout_ms,
+                       std::string *output) {
+  std::vector<char> output_buffer;
+  auto error = internalShell(command, timeout_ms, output_buffer);
+  if (error.Fail())
+    return error;
 
-    std::vector<char> error_message;
-    auto error = ReadMessage (error_message);
-    if (error.Success ())
-        error.SetErrorString (std::string (&error_message[0], error_message.size ()).c_str ());
+  if (output)
+    output->assign(output_buffer.begin(), output_buffer.end());
+  return error;
+}
 
+Error AdbClient::ShellToFile(const char *command, uint32_t timeout_ms,
+                             const FileSpec &output_file_spec) {
+  std::vector<char> output_buffer;
+  auto error = internalShell(command, timeout_ms, output_buffer);
+  if (error.Fail())
     return error;
+
+  const auto output_filename = output_file_spec.GetPath();
+  std::ofstream dst(output_filename, std::ios::out | std::ios::binary);
+  if (!dst.is_open())
+    return Error("Unable to open local file %s", output_filename.c_str());
+
+  dst.write(&output_buffer[0], output_buffer.size());
+  dst.close();
+  if (!dst)
+    return Error("Failed to write file %s", output_filename.c_str());
+  return Error();
 }
 
-Error
-AdbClient::SwitchDeviceTransport ()
-{
-    std::ostringstream msg;
-    msg << "host:transport:" << m_device_id;
+std::unique_ptr<AdbClient::SyncService>
+AdbClient::GetSyncService(Error &error) {
+  std::unique_ptr<SyncService> sync_service;
+  error = StartSync();
+  if (error.Success())
+    sync_service.reset(new SyncService(std::move(m_conn)));
+
+  return sync_service;
+}
+
+Error AdbClient::SyncService::internalPullFile(const FileSpec &remote_file,
+                                               const FileSpec &local_file) {
+  const auto local_file_path = local_file.GetPath();
+  llvm::FileRemover local_file_remover(local_file_path.c_str());
+
+  std::ofstream dst(local_file_path, std::ios::out | std::ios::binary);
+  if (!dst.is_open())
+    return Error("Unable to open local file %s", local_file_path.c_str());
+
+  const auto remote_file_path = remote_file.GetPath(false);
+  auto error = SendSyncRequest(kRECV, remote_file_path.length(),
+                               remote_file_path.c_str());
+  if (error.Fail())
+    return error;
+
+  std::vector<char> chunk;
+  bool eof = false;
+  while (!eof) {
+    error = PullFileChunk(chunk, eof);
+    if (error.Fail())
+      return error;
+    if (!eof)
+      dst.write(&chunk[0], chunk.size());
+  }
+
+  local_file_remover.releaseFile();
+  return error;
+}
+
+Error AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
+                                               const FileSpec &remote_file) {
+  const auto local_file_path(local_file.GetPath());
+  std::ifstream src(local_file_path.c_str(), std::ios::in | std::ios::binary);
+  if (!src.is_open())
+    return Error("Unable to open local file %s", local_file_path.c_str());
+
+  std::stringstream file_description;
+  file_description << remote_file.GetPath(false).c_str() << "," << kDefaultMode;
+  std::string file_description_str = file_description.str();
+  auto error = SendSyncRequest(kSEND, file_description_str.length(),
+                               file_description_str.c_str());
+  if (error.Fail())
+    return error;
+
+  char chunk[kMaxPushData];
+  while (!src.eof() && !src.read(chunk, kMaxPushData).bad()) {
+    size_t chunk_size = src.gcount();
+    error = SendSyncRequest(kDATA, chunk_size, chunk);
+    if (error.Fail())
+      return Error("Failed to send file chunk: %s", error.AsCString());
+  }
+  error = SendSyncRequest(kDONE, local_file.GetModificationTime().seconds(),
+                          nullptr);
+  if (error.Fail())
+    return error;
 
-    auto error = SendMessage (msg.str ());
-    if (error.Fail ())
-        return error;
+  std::string response_id;
+  uint32_t data_len;
+  error = ReadSyncHeader(response_id, data_len);
+  if (error.Fail())
+    return Error("Failed to read DONE response: %s", error.AsCString());
+  if (response_id == kFAIL) {
+    std::string error_message(data_len, 0);
+    error = ReadAllBytes(&error_message[0], data_len);
+    if (error.Fail())
+      return Error("Failed to read DONE error message: %s", error.AsCString());
+    return Error("Failed to push file: %s", error_message.c_str());
+  } else if (response_id != kOKAY)
+    return Error("Got unexpected DONE response: %s", response_id.c_str());
 
-    return ReadResponseStatus ();
+  // If there was an error reading the source file, finish the adb file
+  // transfer first so that adb isn't expecting any more data.
+  if (src.bad())
+    return Error("Failed read on %s", local_file_path.c_str());
+  return error;
 }
 
-Error
-AdbClient::StartSync ()
-{
-    auto error = SwitchDeviceTransport ();
-    if (error.Fail ())
-        return Error ("Failed to switch to device transport: %s", error.AsCString ());
+Error AdbClient::SyncService::internalStat(const FileSpec &remote_file,
+                                           uint32_t &mode, uint32_t &size,
+                                           uint32_t &mtime) {
+  const std::string remote_file_path(remote_file.GetPath(false));
+  auto error = SendSyncRequest(kSTAT, remote_file_path.length(),
+                               remote_file_path.c_str());
+  if (error.Fail())
+    return Error("Failed to send request: %s", error.AsCString());
 
-    error = Sync ();
-    if (error.Fail ())
-        return Error ("Sync failed: %s", error.AsCString ());
+  static const size_t stat_len = strlen(kSTAT);
+  static const size_t response_len = stat_len + (sizeof(uint32_t) * 3);
 
-    return error;
+  std::vector<char> buffer(response_len);
+  error = ReadAllBytes(&buffer[0], buffer.size());
+  if (error.Fail())
+    return Error("Failed to read response: %s", error.AsCString());
+
+  DataExtractor extractor(&buffer[0], buffer.size(), eByteOrderLittle,
+                          sizeof(void *));
+  offset_t offset = 0;
+
+  const void *command = extractor.GetData(&offset, stat_len);
+  if (!command)
+    return Error("Failed to get response command");
+  const char *command_str = static_cast<const char *>(command);
+  if (strncmp(command_str, kSTAT, stat_len))
+    return Error("Got invalid stat command: %s", command_str);
+
+  mode = extractor.GetU32(&offset);
+  size = extractor.GetU32(&offset);
+  mtime = extractor.GetU32(&offset);
+  return Error();
 }
 
-Error
-AdbClient::Sync ()
-{
-    auto error = SendMessage ("sync:", false);
-    if (error.Fail ())
-        return error;
+Error AdbClient::SyncService::PullFile(const FileSpec &remote_file,
+                                       const FileSpec &local_file) {
+  return executeCommand([this, &remote_file, &local_file]() {
+    return internalPullFile(remote_file, local_file);
+  });
+}
 
-    return ReadResponseStatus ();
+Error AdbClient::SyncService::PushFile(const FileSpec &local_file,
+                                       const FileSpec &remote_file) {
+  return executeCommand([this, &local_file, &remote_file]() {
+    return internalPushFile(local_file, remote_file);
+  });
 }
 
-Error
-AdbClient::ReadAllBytes (void *buffer, size_t size)
-{
-    return ::ReadAllBytes (*m_conn, buffer, size);
+Error AdbClient::SyncService::Stat(const FileSpec &remote_file, uint32_t &mode,
+                                   uint32_t &size, uint32_t &mtime) {
+  return executeCommand([this, &remote_file, &mode, &size, &mtime]() {
+    return internalStat(remote_file, mode, size, mtime);
+  });
 }
 
-Error
-AdbClient::internalShell(const char *command, uint32_t timeout_ms, std::vector<char> &output_buf)
-{
-    output_buf.clear();
+bool AdbClient::SyncService::IsConnected() const {
+  return m_conn && m_conn->IsConnected();
+}
 
-    auto error = SwitchDeviceTransport();
-    if (error.Fail())
-        return Error("Failed to switch to device transport: %s", error.AsCString());
+AdbClient::SyncService::SyncService(std::unique_ptr<Connection> &&conn)
+    : m_conn(std::move(conn)) {}
 
-    StreamString adb_command;
-    adb_command.Printf("shell:%s", command);
-    error = SendMessage(adb_command.GetData(), false);
-    if (error.Fail())
-        return error;
+Error AdbClient::SyncService::executeCommand(
+    const std::function<Error()> &cmd) {
+  if (!m_conn)
+    return Error("SyncService is disconnected");
 
-    error = ReadResponseStatus();
-    if (error.Fail())
-        return error;
+  const auto error = cmd();
+  if (error.Fail())
+    m_conn.reset();
 
-    error = ReadMessageStream(output_buf, timeout_ms);
-    if (error.Fail())
-        return error;
+  return error;
+}
 
-    // ADB doesn't propagate return code of shell execution - if
-    // output starts with /system/bin/sh: most likely command failed.
-    static const char *kShellPrefix = "/system/bin/sh:";
-    if (output_buf.size() > strlen(kShellPrefix))
-    {
-        if (!memcmp(&output_buf[0], kShellPrefix, strlen(kShellPrefix)))
-            return Error("Shell command %s failed: %s", command,
-                         std::string(output_buf.begin(), output_buf.end()).c_str());
-    }
-
-    return Error();
-}
-
-Error
-AdbClient::Shell(const char *command, uint32_t timeout_ms, std::string *output)
-{
-    std::vector<char> output_buffer;
-    auto error = internalShell(command, timeout_ms, output_buffer);
-    if (error.Fail())
-        return error;
+AdbClient::SyncService::~SyncService() {}
+
+Error AdbClient::SyncService::SendSyncRequest(const char *request_id,
+                                              const uint32_t data_len,
+                                              const void *data) {
+  const DataBufferSP data_sp(new DataBufferHeap(kSyncPacketLen, 0));
+  DataEncoder encoder(data_sp, eByteOrderLittle, sizeof(void *));
+  auto offset = encoder.PutData(0, request_id, strlen(request_id));
+  encoder.PutU32(offset, data_len);
 
-    if (output)
-        output->assign(output_buffer.begin(), output_buffer.end());
+  Error error;
+  ConnectionStatus status;
+  m_conn->Write(data_sp->GetBytes(), kSyncPacketLen, status, &error);
+  if (error.Fail())
     return error;
+
+  if (data)
+    m_conn->Write(data, data_len, status, &error);
+  return error;
 }
 
-Error
-AdbClient::ShellToFile(const char *command, uint32_t timeout_ms, const FileSpec &output_file_spec)
-{
-    std::vector<char> output_buffer;
-    auto error = internalShell(command, timeout_ms, output_buffer);
-    if (error.Fail())
-        return error;
+Error AdbClient::SyncService::ReadSyncHeader(std::string &response_id,
+                                             uint32_t &data_len) {
+  char buffer[kSyncPacketLen];
 
-    const auto output_filename = output_file_spec.GetPath();
-    std::ofstream dst(output_filename, std::ios::out | std::ios::binary);
-    if (!dst.is_open())
-        return Error("Unable to open local file %s", output_filename.c_str());
-
-    dst.write(&output_buffer[0], output_buffer.size());
-    dst.close();
-    if (!dst)
-        return Error("Failed to write file %s", output_filename.c_str());
-    return Error();
+  auto error = ReadAllBytes(buffer, kSyncPacketLen);
+  if (error.Success()) {
+    response_id.assign(&buffer[0], 4);
+    DataExtractor extractor(&buffer[4], 4, eByteOrderLittle, sizeof(void *));
+    offset_t offset = 0;
+    data_len = extractor.GetU32(&offset);
+  }
+
+  return error;
 }
 
-std::unique_ptr<AdbClient::SyncService>
-AdbClient::GetSyncService (Error &error)
-{
-    std::unique_ptr<SyncService> sync_service;
-    error = StartSync ();
-    if (error.Success ())
-        sync_service.reset (new SyncService(std::move(m_conn)));
-
-    return sync_service;
-}
-
-Error
-AdbClient::SyncService::internalPullFile (const FileSpec &remote_file, const FileSpec &local_file)
-{
-    const auto local_file_path = local_file.GetPath ();
-    llvm::FileRemover local_file_remover (local_file_path.c_str ());
-
-    std::ofstream dst (local_file_path, std::ios::out | std::ios::binary);
-    if (!dst.is_open ())
-        return Error ("Unable to open local file %s", local_file_path.c_str());
-
-    const auto remote_file_path = remote_file.GetPath (false);
-    auto error = SendSyncRequest (kRECV, remote_file_path.length (), remote_file_path.c_str ());
-    if (error.Fail ())
-        return error;
-
-    std::vector<char> chunk;
-    bool eof = false;
-    while (!eof)
-    {
-        error = PullFileChunk (chunk, eof);
-        if (error.Fail ())
-            return error;
-        if (!eof)
-            dst.write (&chunk[0], chunk.size ());
-    }
-
-    local_file_remover.releaseFile ();
-    return error;
-}
-
-Error
-AdbClient::SyncService::internalPushFile (const FileSpec &local_file, const FileSpec &remote_file)
-{
-    const auto local_file_path (local_file.GetPath ());
-    std::ifstream src (local_file_path.c_str(), std::ios::in | std::ios::binary);
-    if (!src.is_open ())
-        return Error ("Unable to open local file %s", local_file_path.c_str());
-
-    std::stringstream file_description;
-    file_description << remote_file.GetPath(false).c_str() << "," << kDefaultMode;
-    std::string file_description_str = file_description.str();
-    auto error = SendSyncRequest (kSEND, file_description_str.length(), file_description_str.c_str());
-    if (error.Fail ())
-        return error;
-
-    char chunk[kMaxPushData];
-    while (!src.eof() && !src.read(chunk, kMaxPushData).bad())
-    {
-        size_t chunk_size = src.gcount();
-        error = SendSyncRequest(kDATA, chunk_size, chunk);
-        if (error.Fail ())
-            return Error ("Failed to send file chunk: %s", error.AsCString ());
-    }
-    error = SendSyncRequest(kDONE, local_file.GetModificationTime().seconds(), nullptr);
-    if (error.Fail ())
-        return error;
-
-    std::string response_id;
-    uint32_t data_len;
-    error = ReadSyncHeader (response_id, data_len);
-    if (error.Fail ())
-        return Error ("Failed to read DONE response: %s", error.AsCString ());
-    if (response_id == kFAIL)
-    {
-        std::string error_message (data_len, 0);
-        error = ReadAllBytes (&error_message[0], data_len);
-        if (error.Fail ())
-            return Error ("Failed to read DONE error message: %s", error.AsCString ());
-        return Error ("Failed to push file: %s", error_message.c_str ());
-    }
-    else if (response_id != kOKAY)
-        return Error ("Got unexpected DONE response: %s", response_id.c_str ());
-
-    // If there was an error reading the source file, finish the adb file
-    // transfer first so that adb isn't expecting any more data.
-    if (src.bad())
-        return Error ("Failed read on %s", local_file_path.c_str());
-    return error;
-}
-
-Error
-AdbClient::SyncService::internalStat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime)
-{
-    const std::string remote_file_path (remote_file.GetPath (false));
-    auto error = SendSyncRequest (kSTAT, remote_file_path.length (), remote_file_path.c_str ());
-    if (error.Fail ())
-        return Error ("Failed to send request: %s", error.AsCString ());
-
-    static const size_t stat_len = strlen (kSTAT);
-    static const size_t response_len = stat_len + (sizeof (uint32_t) * 3);
-
-    std::vector<char> buffer (response_len);
-    error = ReadAllBytes (&buffer[0], buffer.size ());
-    if (error.Fail ())
-        return Error ("Failed to read response: %s", error.AsCString ());
+Error AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer,
+                                            bool &eof) {
+  buffer.clear();
 
-    DataExtractor extractor (&buffer[0], buffer.size (), eByteOrderLittle, sizeof (void*));
-    offset_t offset = 0;
+  std::string response_id;
+  uint32_t data_len;
+  auto error = ReadSyncHeader(response_id, data_len);
+  if (error.Fail())
+    return error;
 
-    const void* command = extractor.GetData (&offset, stat_len);
-    if (!command)
-        return Error ("Failed to get response command");
-    const char* command_str = static_cast<const char*> (command);
-    if (strncmp (command_str, kSTAT, stat_len))
-        return Error ("Got invalid stat command: %s", command_str);
-
-    mode = extractor.GetU32 (&offset);
-    size = extractor.GetU32 (&offset);
-    mtime = extractor.GetU32 (&offset);
-    return Error ();
-}
-
-Error
-AdbClient::SyncService::PullFile (const FileSpec &remote_file, const FileSpec &local_file)
-{
-    return executeCommand ([this, &remote_file, &local_file]() {
-        return internalPullFile (remote_file, local_file);
-    });
-}
-
-Error
-AdbClient::SyncService::PushFile (const FileSpec &local_file, const FileSpec &remote_file)
-{
-    return executeCommand ([this, &local_file, &remote_file]() {
-        return internalPushFile (local_file, remote_file);
-    });
-}
-
-Error
-AdbClient::SyncService::Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime)
-{
-    return executeCommand ([this, &remote_file, &mode, &size, &mtime]() {
-        return internalStat (remote_file, mode, size, mtime);
-    });
-}
-
-bool
-AdbClient::SyncService::IsConnected () const
-{
-    return m_conn && m_conn->IsConnected ();
-}
-
-AdbClient::SyncService::SyncService(std::unique_ptr<Connection> &&conn):
-m_conn(std::move(conn))
-{
-}
-
-Error
-AdbClient::SyncService::executeCommand (const std::function<Error()> &cmd)
-{
-    if (!m_conn)
-        return Error ("SyncService is disconnected");
-
-    const auto error = cmd ();
-    if (error.Fail ())
-        m_conn.reset ();
-
-    return error;
-}
-
-AdbClient::SyncService::~SyncService () {}
-
-Error
-AdbClient::SyncService::SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data)
-{
-    const DataBufferSP data_sp (new DataBufferHeap (kSyncPacketLen, 0));
-    DataEncoder encoder (data_sp, eByteOrderLittle, sizeof (void*));
-    auto offset = encoder.PutData (0, request_id, strlen(request_id));
-    encoder.PutU32 (offset, data_len);
-
-    Error error;
-    ConnectionStatus status;
-    m_conn->Write (data_sp->GetBytes (), kSyncPacketLen, status, &error);
-    if (error.Fail ())
-        return error;
-
-    if (data)
-        m_conn->Write (data, data_len, status, &error);
-    return error;
-}
-
-Error
-AdbClient::SyncService::ReadSyncHeader (std::string &response_id, uint32_t &data_len)
-{
-    char buffer[kSyncPacketLen];
-
-    auto error = ReadAllBytes (buffer, kSyncPacketLen);
-    if (error.Success ())
-    {
-        response_id.assign (&buffer[0], 4);
-        DataExtractor extractor (&buffer[4], 4, eByteOrderLittle, sizeof (void*));
-        offset_t offset = 0;
-        data_len = extractor.GetU32 (&offset);
-    }
-
-    return error;
-}
-
-Error
-AdbClient::SyncService::PullFileChunk (std::vector<char> &buffer, bool &eof)
-{
-    buffer.clear ();
-
-    std::string response_id;
-    uint32_t data_len;
-    auto error = ReadSyncHeader (response_id, data_len);
-    if (error.Fail ())
-        return error;
-
-    if (response_id == kDATA)
-    {
-        buffer.resize (data_len, 0);
-        error = ReadAllBytes (&buffer[0], data_len);
-        if (error.Fail ())
-            buffer.clear ();
-    }
-    else if (response_id == kDONE)
-    {
-        eof = true;
-    }
-    else if (response_id == kFAIL)
-    {
-        std::string error_message (data_len, 0);
-        error = ReadAllBytes (&error_message[0], data_len);
-        if (error.Fail ())
-            return Error ("Failed to read pull error message: %s", error.AsCString ());
-        return Error ("Failed to pull file: %s", error_message.c_str ());
-    }
-    else
-        return Error ("Pull failed with unknown response: %s", response_id.c_str ());
-
-    return Error ();
-}
-
-Error
-AdbClient::SyncService::ReadAllBytes (void *buffer, size_t size)
-{
-    return ::ReadAllBytes (*m_conn, buffer, size);
+  if (response_id == kDATA) {
+    buffer.resize(data_len, 0);
+    error = ReadAllBytes(&buffer[0], data_len);
+    if (error.Fail())
+      buffer.clear();
+  } else if (response_id == kDONE) {
+    eof = true;
+  } else if (response_id == kFAIL) {
+    std::string error_message(data_len, 0);
+    error = ReadAllBytes(&error_message[0], data_len);
+    if (error.Fail())
+      return Error("Failed to read pull error message: %s", error.AsCString());
+    return Error("Failed to pull file: %s", error_message.c_str());
+  } else
+    return Error("Pull failed with unknown response: %s", response_id.c_str());
+
+  return Error();
 }
 
+Error AdbClient::SyncService::ReadAllBytes(void *buffer, size_t size) {
+  return ::ReadAllBytes(*m_conn, buffer, size);
+}

Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.h Tue Sep  6 15:57:50 2016
@@ -31,146 +31,116 @@ class FileSpec;
 
 namespace platform_android {
 
-class AdbClient
-{
+class AdbClient {
 public:
-    enum UnixSocketNamespace
-    {
-        UnixSocketNamespaceAbstract,
-        UnixSocketNamespaceFileSystem,
-    };
+  enum UnixSocketNamespace {
+    UnixSocketNamespaceAbstract,
+    UnixSocketNamespaceFileSystem,
+  };
 
-    using DeviceIDList = std::list<std::string>;
+  using DeviceIDList = std::list<std::string>;
 
-    class SyncService
-    {
-        friend class AdbClient;
+  class SyncService {
+    friend class AdbClient;
 
-    public:
-        ~SyncService ();
+  public:
+    ~SyncService();
 
-        Error
-        PullFile (const FileSpec &remote_file, const FileSpec &local_file);
+    Error PullFile(const FileSpec &remote_file, const FileSpec &local_file);
 
-        Error
-        PushFile (const FileSpec &local_file, const FileSpec &remote_file);
+    Error PushFile(const FileSpec &local_file, const FileSpec &remote_file);
 
-        Error
-        Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime);
+    Error Stat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size,
+               uint32_t &mtime);
 
-        bool
-        IsConnected () const;
+    bool IsConnected() const;
 
-    private:
-        explicit SyncService (std::unique_ptr<Connection> &&conn);
+  private:
+    explicit SyncService(std::unique_ptr<Connection> &&conn);
 
-        Error
-        SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data);
+    Error SendSyncRequest(const char *request_id, const uint32_t data_len,
+                          const void *data);
 
-        Error
-        ReadSyncHeader (std::string &response_id, uint32_t &data_len); 
+    Error ReadSyncHeader(std::string &response_id, uint32_t &data_len);
 
-        Error
-        PullFileChunk (std::vector<char> &buffer, bool &eof);
+    Error PullFileChunk(std::vector<char> &buffer, bool &eof);
 
-        Error
-        ReadAllBytes (void *buffer, size_t size);
+    Error ReadAllBytes(void *buffer, size_t size);
 
-        Error
-        internalPullFile (const FileSpec &remote_file, const FileSpec &local_file);
+    Error internalPullFile(const FileSpec &remote_file,
+                           const FileSpec &local_file);
 
-        Error
-        internalPushFile (const FileSpec &local_file, const FileSpec &remote_file);
+    Error internalPushFile(const FileSpec &local_file,
+                           const FileSpec &remote_file);
 
-        Error
-        internalStat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime);
+    Error internalStat(const FileSpec &remote_file, uint32_t &mode,
+                       uint32_t &size, uint32_t &mtime);
 
-        Error
-        executeCommand (const std::function<Error()> &cmd);
+    Error executeCommand(const std::function<Error()> &cmd);
 
-        std::unique_ptr<Connection> m_conn;   
-    };
+    std::unique_ptr<Connection> m_conn;
+  };
 
-    static Error
-    CreateByDeviceID(const std::string &device_id, AdbClient &adb);
+  static Error CreateByDeviceID(const std::string &device_id, AdbClient &adb);
 
-    AdbClient ();
-    explicit AdbClient (const std::string &device_id);
+  AdbClient();
+  explicit AdbClient(const std::string &device_id);
 
-    ~AdbClient();
+  ~AdbClient();
 
-    const std::string&
-    GetDeviceID() const;
+  const std::string &GetDeviceID() const;
 
-    Error
-    GetDevices (DeviceIDList &device_list);
+  Error GetDevices(DeviceIDList &device_list);
 
-    Error
-    SetPortForwarding (const uint16_t local_port, const uint16_t remote_port);
+  Error SetPortForwarding(const uint16_t local_port,
+                          const uint16_t remote_port);
 
-    Error
-    SetPortForwarding (const uint16_t local_port,
-                       const char* remote_socket_name,
-                       const UnixSocketNamespace socket_namespace);
+  Error SetPortForwarding(const uint16_t local_port,
+                          const char *remote_socket_name,
+                          const UnixSocketNamespace socket_namespace);
 
-    Error
-    DeletePortForwarding (const uint16_t local_port);
+  Error DeletePortForwarding(const uint16_t local_port);
 
-    Error
-    Shell (const char* command, uint32_t timeout_ms, std::string* output);
+  Error Shell(const char *command, uint32_t timeout_ms, std::string *output);
 
-    Error
-    ShellToFile(const char *command, uint32_t timeout_ms, const FileSpec &output_file_spec);
+  Error ShellToFile(const char *command, uint32_t timeout_ms,
+                    const FileSpec &output_file_spec);
 
-    std::unique_ptr<SyncService>
-    GetSyncService (Error &error);
+  std::unique_ptr<SyncService> GetSyncService(Error &error);
 
-    Error
-    SwitchDeviceTransport ();
+  Error SwitchDeviceTransport();
 
 private:
-    Error
-    Connect ();
+  Error Connect();
 
-    void
-    SetDeviceID (const std::string &device_id);
+  void SetDeviceID(const std::string &device_id);
 
-    Error
-    SendMessage (const std::string &packet, const bool reconnect = true);
+  Error SendMessage(const std::string &packet, const bool reconnect = true);
 
-    Error
-    SendDeviceMessage (const std::string &packet);
+  Error SendDeviceMessage(const std::string &packet);
 
-    Error
-    ReadMessage (std::vector<char> &message);
+  Error ReadMessage(std::vector<char> &message);
 
-    Error
-    ReadMessageStream (std::vector<char> &message, uint32_t timeout_ms);
+  Error ReadMessageStream(std::vector<char> &message, uint32_t timeout_ms);
 
-    Error
-    GetResponseError (const char *response_id);
+  Error GetResponseError(const char *response_id);
 
-    Error
-    ReadResponseStatus ();
+  Error ReadResponseStatus();
 
-    Error
-    Sync ();
+  Error Sync();
 
-    Error
-    StartSync ();
+  Error StartSync();
 
-    Error
-    internalShell(const char *command, uint32_t timeout_ms, std::vector<char> &output_buf);
+  Error internalShell(const char *command, uint32_t timeout_ms,
+                      std::vector<char> &output_buf);
 
-    Error
-    ReadAllBytes(void *buffer, size_t size);
+  Error ReadAllBytes(void *buffer, size_t size);
 
-    std::string m_device_id;
-    std::unique_ptr<Connection> m_conn;
+  std::string m_device_id;
+  std::unique_ptr<Connection> m_conn;
 };
 
 } // namespace platform_android
 } // namespace lldb_private
 
-#endif  // liblldb_AdbClient_h_
-
+#endif // liblldb_AdbClient_h_

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp Tue Sep  6 15:57:50 2016
@@ -10,6 +10,7 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
+#include "Utility/UriParser.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
@@ -18,7 +19,6 @@
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/StringConvert.h"
-#include "Utility/UriParser.h"
 
 // Project includes
 #include "AdbClient.h"
@@ -30,388 +30,346 @@ using namespace lldb_private;
 using namespace lldb_private::platform_android;
 
 static uint32_t g_initialize_count = 0;
-static const unsigned int g_android_default_cache_size = 2048; // Fits inside 4k adb packet.
+static const unsigned int g_android_default_cache_size =
+    2048; // Fits inside 4k adb packet.
 
-void
-PlatformAndroid::Initialize ()
-{
-    PlatformLinux::Initialize ();
+void PlatformAndroid::Initialize() {
+  PlatformLinux::Initialize();
 
-    if (g_initialize_count++ == 0)
-    {
+  if (g_initialize_count++ == 0) {
 #if defined(__ANDROID__)
-        PlatformSP default_platform_sp (new PlatformAndroid(true));
-        default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
-        Platform::SetHostPlatform (default_platform_sp);
+    PlatformSP default_platform_sp(new PlatformAndroid(true));
+    default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+    Platform::SetHostPlatform(default_platform_sp);
 #endif
-        PluginManager::RegisterPlugin (PlatformAndroid::GetPluginNameStatic(false),
-                                       PlatformAndroid::GetPluginDescriptionStatic(false),
-                                       PlatformAndroid::CreateInstance);
-    }
+    PluginManager::RegisterPlugin(
+        PlatformAndroid::GetPluginNameStatic(false),
+        PlatformAndroid::GetPluginDescriptionStatic(false),
+        PlatformAndroid::CreateInstance);
+  }
 }
 
-void
-PlatformAndroid::Terminate ()
-{
-    if (g_initialize_count > 0)
-    {
-        if (--g_initialize_count == 0)
-        {
-            PluginManager::UnregisterPlugin (PlatformAndroid::CreateInstance);
-        }
+void PlatformAndroid::Terminate() {
+  if (g_initialize_count > 0) {
+    if (--g_initialize_count == 0) {
+      PluginManager::UnregisterPlugin(PlatformAndroid::CreateInstance);
     }
+  }
 
-    PlatformLinux::Terminate ();
+  PlatformLinux::Terminate();
 }
 
-PlatformSP
-PlatformAndroid::CreateInstance (bool force, const ArchSpec *arch)
-{
-    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
-    if (log)
-    {
-        const char *arch_name;
-        if (arch && arch->GetArchitectureName ())
-            arch_name = arch->GetArchitectureName ();
-        else
-            arch_name = "<null>";
-
-        const char *triple_cstr = arch ? arch->GetTriple ().getTriple ().c_str() : "<null>";
+PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
+  if (log) {
+    const char *arch_name;
+    if (arch && arch->GetArchitectureName())
+      arch_name = arch->GetArchitectureName();
+    else
+      arch_name = "<null>";
 
-        log->Printf ("PlatformAndroid::%s(force=%s, arch={%s,%s})", __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
-    }
+    const char *triple_cstr =
+        arch ? arch->GetTriple().getTriple().c_str() : "<null>";
 
-    bool create = force;
-    if (create == false && arch && arch->IsValid())
-    {
-        const llvm::Triple &triple = arch->GetTriple();
-        switch (triple.getVendor())
-        {
-            case llvm::Triple::PC:
-                create = true;
-                break;
+    log->Printf("PlatformAndroid::%s(force=%s, arch={%s,%s})", __FUNCTION__,
+                force ? "true" : "false", arch_name, triple_cstr);
+  }
+
+  bool create = force;
+  if (create == false && arch && arch->IsValid()) {
+    const llvm::Triple &triple = arch->GetTriple();
+    switch (triple.getVendor()) {
+    case llvm::Triple::PC:
+      create = true;
+      break;
 
 #if defined(__ANDROID__)
-            // Only accept "unknown" for the vendor if the host is android and
-            // it "unknown" wasn't specified (it was just returned because it
-            // was NOT specified_
-            case llvm::Triple::VendorType::UnknownVendor:
-                create = !arch->TripleVendorWasSpecified();
-                break;
+    // Only accept "unknown" for the vendor if the host is android and
+    // it "unknown" wasn't specified (it was just returned because it
+    // was NOT specified_
+    case llvm::Triple::VendorType::UnknownVendor:
+      create = !arch->TripleVendorWasSpecified();
+      break;
 #endif
-            default:
-                break;
-        }
-        
-        if (create)
-        {
-            switch (triple.getOS())
-            {
-                case llvm::Triple::Android:
-                    break;
+    default:
+      break;
+    }
+
+    if (create) {
+      switch (triple.getOS()) {
+      case llvm::Triple::Android:
+        break;
 
 #if defined(__ANDROID__)
-                // Only accept "unknown" for the OS if the host is android and
-                // it "unknown" wasn't specified (it was just returned because it
-                // was NOT specified)
-                case llvm::Triple::OSType::UnknownOS:
-                    create = !arch->TripleOSWasSpecified();
-                    break;
+      // Only accept "unknown" for the OS if the host is android and
+      // it "unknown" wasn't specified (it was just returned because it
+      // was NOT specified)
+      case llvm::Triple::OSType::UnknownOS:
+        create = !arch->TripleOSWasSpecified();
+        break;
 #endif
-                default:
-                    create = false;
-                    break;
-            }
-        }
-    }
-
-    if (create)
-    {
-        if (log)
-            log->Printf ("PlatformAndroid::%s() creating remote-android platform", __FUNCTION__);
-        return PlatformSP(new PlatformAndroid(false));
+      default:
+        create = false;
+        break;
+      }
     }
+  }
 
+  if (create) {
     if (log)
-        log->Printf ("PlatformAndroid::%s() aborting creation of remote-android platform", __FUNCTION__);
+      log->Printf("PlatformAndroid::%s() creating remote-android platform",
+                  __FUNCTION__);
+    return PlatformSP(new PlatformAndroid(false));
+  }
+
+  if (log)
+    log->Printf(
+        "PlatformAndroid::%s() aborting creation of remote-android platform",
+        __FUNCTION__);
+
+  return PlatformSP();
+}
+
+PlatformAndroid::PlatformAndroid(bool is_host)
+    : PlatformLinux(is_host), m_sdk_version(0) {}
+
+PlatformAndroid::~PlatformAndroid() {}
+
+ConstString PlatformAndroid::GetPluginNameStatic(bool is_host) {
+  if (is_host) {
+    static ConstString g_host_name(Platform::GetHostPlatformName());
+    return g_host_name;
+  } else {
+    static ConstString g_remote_name("remote-android");
+    return g_remote_name;
+  }
+}
+
+const char *PlatformAndroid::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+    return "Local Android user platform plug-in.";
+  else
+    return "Remote Android user platform plug-in.";
+}
+
+ConstString PlatformAndroid::GetPluginName() {
+  return GetPluginNameStatic(IsHost());
+}
+
+Error PlatformAndroid::ConnectRemote(Args &args) {
+  m_device_id.clear();
+
+  if (IsHost()) {
+    return Error("can't connect to the host platform '%s', always connected",
+                 GetPluginName().GetCString());
+  }
+
+  if (!m_remote_platform_sp)
+    m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+
+  int port;
+  std::string scheme, host, path;
+  const char *url = args.GetArgumentAtIndex(0);
+  if (!url)
+    return Error("URL is null.");
+  if (!UriParser::Parse(url, scheme, host, port, path))
+    return Error("Invalid URL: %s", url);
+  if (host != "localhost")
+    m_device_id = host;
+
+  auto error = PlatformLinux::ConnectRemote(args);
+  if (error.Success()) {
+    AdbClient adb;
+    error = AdbClient::CreateByDeviceID(m_device_id, adb);
+    if (error.Fail())
+      return error;
 
-    return PlatformSP();
-}
+    m_device_id = adb.GetDeviceID();
+  }
+  return error;
+}
+
+Error PlatformAndroid::GetFile(const FileSpec &source,
+                               const FileSpec &destination) {
+  if (IsHost() || !m_remote_platform_sp)
+    return PlatformLinux::GetFile(source, destination);
+
+  FileSpec source_spec(source.GetPath(false), false,
+                       FileSpec::ePathSyntaxPosix);
+  if (source_spec.IsRelative())
+    source_spec = GetRemoteWorkingDirectory().CopyByAppendingPathComponent(
+        source_spec.GetCString(false));
+
+  Error error;
+  auto sync_service = GetSyncService(error);
+  if (error.Fail())
+    return error;
 
-PlatformAndroid::PlatformAndroid (bool is_host) :
-    PlatformLinux(is_host),
-    m_sdk_version(0)
-{
-}
+  uint32_t mode = 0, size = 0, mtime = 0;
+  error = sync_service->Stat(source_spec, mode, size, mtime);
+  if (error.Fail())
+    return error;
 
-PlatformAndroid::~PlatformAndroid()
-{
-}
+  if (mode != 0)
+    return sync_service->PullFile(source_spec, destination);
 
-ConstString
-PlatformAndroid::GetPluginNameStatic (bool is_host)
-{
-    if (is_host)
-    {
-        static ConstString g_host_name(Platform::GetHostPlatformName ());
-        return g_host_name;
-    }
-    else
-    {
-        static ConstString g_remote_name("remote-android");
-        return g_remote_name;
-    }
-}
+  auto source_file = source_spec.GetCString(false);
 
-const char *
-PlatformAndroid::GetPluginDescriptionStatic (bool is_host)
-{
-    if (is_host)
-        return "Local Android user platform plug-in.";
-    else
-        return "Remote Android user platform plug-in.";
-}
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
+  if (log)
+    log->Printf("Got mode == 0 on '%s': try to get file via 'shell cat'",
+                source_file);
 
-ConstString
-PlatformAndroid::GetPluginName()
-{
-    return GetPluginNameStatic(IsHost());
-}
+  if (strchr(source_file, '\'') != nullptr)
+    return Error("Doesn't support single-quotes in filenames");
 
-Error
-PlatformAndroid::ConnectRemote(Args& args)
-{
-    m_device_id.clear();
+  // mode == 0 can signify that adbd cannot access the file
+  // due security constraints - try "cat ..." as a fallback.
+  AdbClient adb(m_device_id);
 
-    if (IsHost())
-    {
-        return Error ("can't connect to the host platform '%s', always connected", GetPluginName().GetCString());
-    }
+  char cmd[PATH_MAX];
+  snprintf(cmd, sizeof(cmd), "cat '%s'", source_file);
+
+  return adb.ShellToFile(cmd, 60000 /* ms */, destination);
+}
 
-    if (!m_remote_platform_sp)
-        m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+Error PlatformAndroid::PutFile(const FileSpec &source,
+                               const FileSpec &destination, uint32_t uid,
+                               uint32_t gid) {
+  if (IsHost() || !m_remote_platform_sp)
+    return PlatformLinux::PutFile(source, destination, uid, gid);
 
-    int port;
-    std::string scheme, host, path;
-    const char *url = args.GetArgumentAtIndex(0);
-    if (!url)
-        return Error("URL is null.");
-    if (!UriParser::Parse(url, scheme, host, port, path))
-        return Error("Invalid URL: %s", url);
-    if (host != "localhost")
-        m_device_id = host;
-
-    auto error = PlatformLinux::ConnectRemote(args);
-    if (error.Success())
-    {
-        AdbClient adb;
-        error = AdbClient::CreateByDeviceID(m_device_id, adb);
-        if (error.Fail())
-            return error;
+  FileSpec destination_spec(destination.GetPath(false), false,
+                            FileSpec::ePathSyntaxPosix);
+  if (destination_spec.IsRelative())
+    destination_spec = GetRemoteWorkingDirectory().CopyByAppendingPathComponent(
+        destination_spec.GetCString(false));
 
-        m_device_id = adb.GetDeviceID();
-    }
+  // TODO: Set correct uid and gid on remote file.
+  Error error;
+  auto sync_service = GetSyncService(error);
+  if (error.Fail())
     return error;
+  return sync_service->PushFile(source, destination_spec);
 }
 
-Error
-PlatformAndroid::GetFile (const FileSpec& source,
-                          const FileSpec& destination)
-{
-    if (IsHost() || !m_remote_platform_sp)
-        return PlatformLinux::GetFile(source, destination);
-
-    FileSpec source_spec (source.GetPath (false), false, FileSpec::ePathSyntaxPosix);
-    if (source_spec.IsRelative())
-        source_spec = GetRemoteWorkingDirectory ().CopyByAppendingPathComponent (source_spec.GetCString (false));
-
-    Error error;
-    auto sync_service = GetSyncService (error);
-    if (error.Fail ())
-        return error;
-
-    uint32_t mode = 0, size = 0, mtime = 0;
-    error = sync_service->Stat(source_spec, mode, size, mtime);
-    if (error.Fail())
-        return error;
-
-    if (mode != 0)
-        return sync_service->PullFile(source_spec, destination);
+const char *PlatformAndroid::GetCacheHostname() { return m_device_id.c_str(); }
 
-    auto source_file = source_spec.GetCString(false);
+Error PlatformAndroid::DownloadModuleSlice(const FileSpec &src_file_spec,
+                                           const uint64_t src_offset,
+                                           const uint64_t src_size,
+                                           const FileSpec &dst_file_spec) {
+  if (src_offset != 0)
+    return Error("Invalid offset - %" PRIu64, src_offset);
 
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
-    if (log)
-        log->Printf("Got mode == 0 on '%s': try to get file via 'shell cat'", source_file);
+  return GetFile(src_file_spec, dst_file_spec);
+}
 
-    if (strchr(source_file, '\'') != nullptr)
-        return Error("Doesn't support single-quotes in filenames");
+Error PlatformAndroid::DisconnectRemote() {
+  Error error = PlatformLinux::DisconnectRemote();
+  if (error.Success()) {
+    m_device_id.clear();
+    m_sdk_version = 0;
+  }
+  return error;
+}
 
-    // mode == 0 can signify that adbd cannot access the file
-    // due security constraints - try "cat ..." as a fallback.
-    AdbClient adb(m_device_id);
-
-    char cmd[PATH_MAX];
-    snprintf(cmd, sizeof(cmd), "cat '%s'", source_file);
-
-    return adb.ShellToFile(cmd, 60000 /* ms */, destination);
-}
-
-Error
-PlatformAndroid::PutFile (const FileSpec& source,
-                          const FileSpec& destination,
-                          uint32_t uid,
-                          uint32_t gid)
-{
-    if (IsHost() || !m_remote_platform_sp)
-        return PlatformLinux::PutFile (source, destination, uid, gid);
-
-    FileSpec destination_spec (destination.GetPath (false), false, FileSpec::ePathSyntaxPosix);
-    if (destination_spec.IsRelative())
-        destination_spec = GetRemoteWorkingDirectory ().CopyByAppendingPathComponent (destination_spec.GetCString (false));
-
-    // TODO: Set correct uid and gid on remote file.
-    Error error;
-    auto sync_service = GetSyncService (error);
-    if (error.Fail ())
-        return error;
-    return sync_service->PushFile(source, destination_spec);
-}
-
-const char *
-PlatformAndroid::GetCacheHostname ()
-{
-    return m_device_id.c_str ();
-}
-
-Error
-PlatformAndroid::DownloadModuleSlice (const FileSpec &src_file_spec,
-                                      const uint64_t src_offset,
-                                      const uint64_t src_size,
-                                      const FileSpec &dst_file_spec)
-{
-    if (src_offset != 0)
-        return Error ("Invalid offset - %" PRIu64, src_offset);
-
-    return GetFile (src_file_spec, dst_file_spec);
-}
-
-Error
-PlatformAndroid::DisconnectRemote()
-{
-    Error error = PlatformLinux::DisconnectRemote();
-    if (error.Success())
-    {
-        m_device_id.clear();
-        m_sdk_version = 0;
-    }
-    return error;
+uint32_t PlatformAndroid::GetDefaultMemoryCacheLineSize() {
+  return g_android_default_cache_size;
 }
 
-uint32_t
-PlatformAndroid::GetDefaultMemoryCacheLineSize()
-{
-    return g_android_default_cache_size;
-}
-
-uint32_t
-PlatformAndroid::GetSdkVersion()
-{
-    if (!IsConnected())
-        return 0;
-
-    if (m_sdk_version != 0)
-        return m_sdk_version;
-
-    std::string version_string;
-    AdbClient adb(m_device_id);
-    Error error = adb.Shell("getprop ro.build.version.sdk", 5000 /* ms */, &version_string);
-    version_string = llvm::StringRef(version_string).trim().str();
-
-    if (error.Fail() || version_string.empty())
-    {
-        Log* log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM);
-        if (log)
-            log->Printf("Get SDK version failed. (error: %s, output: %s)",
-                        error.AsCString(), version_string.c_str());
-        return 0;
-    }
+uint32_t PlatformAndroid::GetSdkVersion() {
+  if (!IsConnected())
+    return 0;
 
-    m_sdk_version = StringConvert::ToUInt32(version_string.c_str());
+  if (m_sdk_version != 0)
     return m_sdk_version;
-}
-
-Error
-PlatformAndroid::DownloadSymbolFile (const lldb::ModuleSP& module_sp,
-                                     const FileSpec& dst_file_spec)
-{
-    // For oat file we can try to fetch additional debug info from the device
-    ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
-    if (extension != ConstString("oat") && extension != ConstString("odex"))
-        return Error("Symbol file downloading only supported for oat and odex files");
-
-    // If we have no information about the platform file we can't execute oatdump
-    if (!module_sp->GetPlatformFileSpec())
-        return Error("No platform file specified");
-
-    // Symbolizer isn't available before SDK version 23
-    if (GetSdkVersion() < 23)
-        return Error("Symbol file generation only supported on SDK 23+");
-
-    // If we already have symtab then we don't have to try and generate one
-    if (module_sp->GetSectionList()->FindSectionByName(ConstString(".symtab")) != nullptr)
-        return Error("Symtab already available in the module");
-
-    AdbClient adb(m_device_id);
-    std::string tmpdir;
-    Error error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp", 5000 /* ms */, &tmpdir);
-    if (error.Fail() || tmpdir.empty())
-        return Error("Failed to generate temporary directory on the device (%s)", error.AsCString());
-    tmpdir = llvm::StringRef(tmpdir).trim().str();
-
-    // Create file remover for the temporary directory created on the device
-    std::unique_ptr<std::string, std::function<void(std::string*)>> tmpdir_remover(
-        &tmpdir,
-        [this, &adb](std::string* s) {
-            StreamString command;
-            command.Printf("rm -rf %s", s->c_str());
-            Error error = adb.Shell(command.GetData(), 5000 /* ms */, nullptr);
-
-            Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
-            if (log && error.Fail())
-                log->Printf("Failed to remove temp directory: %s", error.AsCString());
-        }
-    );
 
-    FileSpec symfile_platform_filespec(tmpdir.c_str(), false);
-    symfile_platform_filespec.AppendPathComponent("symbolized.oat");
+  std::string version_string;
+  AdbClient adb(m_device_id);
+  Error error =
+      adb.Shell("getprop ro.build.version.sdk", 5000 /* ms */, &version_string);
+  version_string = llvm::StringRef(version_string).trim().str();
 
-    // Execute oatdump on the remote device to generate a file with symtab
+  if (error.Fail() || version_string.empty()) {
+    Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM);
+    if (log)
+      log->Printf("Get SDK version failed. (error: %s, output: %s)",
+                  error.AsCString(), version_string.c_str());
+    return 0;
+  }
+
+  m_sdk_version = StringConvert::ToUInt32(version_string.c_str());
+  return m_sdk_version;
+}
+
+Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
+                                          const FileSpec &dst_file_spec) {
+  // For oat file we can try to fetch additional debug info from the device
+  ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
+  if (extension != ConstString("oat") && extension != ConstString("odex"))
+    return Error(
+        "Symbol file downloading only supported for oat and odex files");
+
+  // If we have no information about the platform file we can't execute oatdump
+  if (!module_sp->GetPlatformFileSpec())
+    return Error("No platform file specified");
+
+  // Symbolizer isn't available before SDK version 23
+  if (GetSdkVersion() < 23)
+    return Error("Symbol file generation only supported on SDK 23+");
+
+  // If we already have symtab then we don't have to try and generate one
+  if (module_sp->GetSectionList()->FindSectionByName(ConstString(".symtab")) !=
+      nullptr)
+    return Error("Symtab already available in the module");
+
+  AdbClient adb(m_device_id);
+  std::string tmpdir;
+  Error error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp",
+                          5000 /* ms */, &tmpdir);
+  if (error.Fail() || tmpdir.empty())
+    return Error("Failed to generate temporary directory on the device (%s)",
+                 error.AsCString());
+  tmpdir = llvm::StringRef(tmpdir).trim().str();
+
+  // Create file remover for the temporary directory created on the device
+  std::unique_ptr<std::string, std::function<void(std::string *)>>
+  tmpdir_remover(&tmpdir, [this, &adb](std::string *s) {
     StreamString command;
-    command.Printf("oatdump --symbolize=%s --output=%s",
-                   module_sp->GetPlatformFileSpec().GetCString(false),
-                   symfile_platform_filespec.GetCString(false));
-    error = adb.Shell(command.GetData(), 60000 /* ms */, nullptr);
-    if (error.Fail())
-        return Error("Oatdump failed: %s", error.AsCString());
-
-    // Download the symbolfile from the remote device
-    return GetFile(symfile_platform_filespec, dst_file_spec);
-}
+    command.Printf("rm -rf %s", s->c_str());
+    Error error = adb.Shell(command.GetData(), 5000 /* ms */, nullptr);
 
-bool
-PlatformAndroid::GetRemoteOSVersion ()
-{
-    m_major_os_version = GetSdkVersion();
-    m_minor_os_version = 0;
-    m_update_os_version = 0;
-    return m_major_os_version != 0;
+    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
+    if (log && error.Fail())
+      log->Printf("Failed to remove temp directory: %s", error.AsCString());
+  });
+
+  FileSpec symfile_platform_filespec(tmpdir.c_str(), false);
+  symfile_platform_filespec.AppendPathComponent("symbolized.oat");
+
+  // Execute oatdump on the remote device to generate a file with symtab
+  StreamString command;
+  command.Printf("oatdump --symbolize=%s --output=%s",
+                 module_sp->GetPlatformFileSpec().GetCString(false),
+                 symfile_platform_filespec.GetCString(false));
+  error = adb.Shell(command.GetData(), 60000 /* ms */, nullptr);
+  if (error.Fail())
+    return Error("Oatdump failed: %s", error.AsCString());
+
+  // Download the symbolfile from the remote device
+  return GetFile(symfile_platform_filespec, dst_file_spec);
+}
+
+bool PlatformAndroid::GetRemoteOSVersion() {
+  m_major_os_version = GetSdkVersion();
+  m_minor_os_version = 0;
+  m_update_os_version = 0;
+  return m_major_os_version != 0;
 }
 
-const char*
-PlatformAndroid::GetLibdlFunctionDeclarations() const
-{
-    return R"(
+const char *PlatformAndroid::GetLibdlFunctionDeclarations() const {
+  return R"(
               extern "C" void* dlopen(const char*, int) asm("__dl_dlopen");
               extern "C" void* dlsym(void*, const char*) asm("__dl_dlsym");
               extern "C" int   dlclose(void*) asm("__dl_dlclose");
@@ -419,14 +377,11 @@ PlatformAndroid::GetLibdlFunctionDeclara
              )";
 }
 
-AdbClient::SyncService*
-PlatformAndroid::GetSyncService (Error &error)
-{
-    if (m_adb_sync_svc && m_adb_sync_svc->IsConnected ())
-        return m_adb_sync_svc.get ();
-
-    AdbClient adb (m_device_id);
-    m_adb_sync_svc = adb.GetSyncService (error);
-    return (error.Success ()) ? m_adb_sync_svc.get () : nullptr;
+AdbClient::SyncService *PlatformAndroid::GetSyncService(Error &error) {
+  if (m_adb_sync_svc && m_adb_sync_svc->IsConnected())
+    return m_adb_sync_svc.get();
+
+  AdbClient adb(m_device_id);
+  m_adb_sync_svc = adb.GetSyncService(error);
+  return (error.Success()) ? m_adb_sync_svc.get() : nullptr;
 }
-

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h Tue Sep  6 15:57:50 2016
@@ -24,95 +24,69 @@
 namespace lldb_private {
 namespace platform_android {
 
-    class PlatformAndroid : public platform_linux::PlatformLinux
-    {
-    public:
-        PlatformAndroid(bool is_host);
-
-        ~PlatformAndroid() override;
-
-        static void
-        Initialize ();
-
-        static void
-        Terminate ();
-
-        //------------------------------------------------------------
-        // lldb_private::PluginInterface functions
-        //------------------------------------------------------------
-        static lldb::PlatformSP
-        CreateInstance (bool force, const ArchSpec *arch);
-
-        static ConstString
-        GetPluginNameStatic (bool is_host);
-
-        static const char *
-        GetPluginDescriptionStatic (bool is_host);
-
-        ConstString
-        GetPluginName() override;
-        
-        uint32_t
-        GetPluginVersion() override
-        {
-            return 1;
-        }
-
-        //------------------------------------------------------------
-        // lldb_private::Platform functions
-        //------------------------------------------------------------
-
-        Error
-        ConnectRemote (Args& args) override;
-
-        Error
-        GetFile (const FileSpec& source,
-                 const FileSpec& destination) override;
-
-        Error
-        PutFile (const FileSpec& source,
-                 const FileSpec& destination,
-                 uint32_t uid = UINT32_MAX,
-                 uint32_t gid = UINT32_MAX) override;
-        
-        uint32_t
-        GetSdkVersion();
-
-        bool
-        GetRemoteOSVersion() override;
-
-        Error
-        DisconnectRemote () override;
-
-        uint32_t
-        GetDefaultMemoryCacheLineSize() override;
-
-     protected:
-        const char *
-        GetCacheHostname () override;
-
-        Error
-        DownloadModuleSlice (const FileSpec &src_file_spec,
-                             const uint64_t src_offset,
-                             const uint64_t src_size,
-                             const FileSpec &dst_file_spec) override;
-
-        Error
-        DownloadSymbolFile (const lldb::ModuleSP& module_sp,
-                            const FileSpec& dst_file_spec) override;
-
-        const char*
-        GetLibdlFunctionDeclarations() const override;
-
-    private:
-        AdbClient::SyncService* GetSyncService (Error &error);
-
-        std::unique_ptr<AdbClient::SyncService> m_adb_sync_svc;
-        std::string m_device_id;
-        uint32_t m_sdk_version;
+class PlatformAndroid : public platform_linux::PlatformLinux {
+public:
+  PlatformAndroid(bool is_host);
 
-        DISALLOW_COPY_AND_ASSIGN (PlatformAndroid);
-    };
+  ~PlatformAndroid() override;
+
+  static void Initialize();
+
+  static void Terminate();
+
+  //------------------------------------------------------------
+  // lldb_private::PluginInterface functions
+  //------------------------------------------------------------
+  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
+
+  static ConstString GetPluginNameStatic(bool is_host);
+
+  static const char *GetPluginDescriptionStatic(bool is_host);
+
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override { return 1; }
+
+  //------------------------------------------------------------
+  // lldb_private::Platform functions
+  //------------------------------------------------------------
+
+  Error ConnectRemote(Args &args) override;
+
+  Error GetFile(const FileSpec &source, const FileSpec &destination) override;
+
+  Error PutFile(const FileSpec &source, const FileSpec &destination,
+                uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
+
+  uint32_t GetSdkVersion();
+
+  bool GetRemoteOSVersion() override;
+
+  Error DisconnectRemote() override;
+
+  uint32_t GetDefaultMemoryCacheLineSize() override;
+
+protected:
+  const char *GetCacheHostname() override;
+
+  Error DownloadModuleSlice(const FileSpec &src_file_spec,
+                            const uint64_t src_offset, const uint64_t src_size,
+                            const FileSpec &dst_file_spec) override;
+
+  Error DownloadSymbolFile(const lldb::ModuleSP &module_sp,
+                           const FileSpec &dst_file_spec) override;
+
+  const char *GetLibdlFunctionDeclarations() const override;
+
+private:
+  AdbClient::SyncService *GetSyncService(Error &error);
+
+  std::unique_ptr<AdbClient::SyncService> m_adb_sync_svc;
+  std::string m_device_id;
+  uint32_t m_sdk_version;
+
+  DISALLOW_COPY_AND_ASSIGN(PlatformAndroid);
+};
 
 } // namespace platofor_android
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp Tue Sep  6 15:57:50 2016
@@ -10,8 +10,8 @@
 // Other libraries and framework includes
 #include "lldb/Core/Error.h"
 #include "lldb/Core/Log.h"
-#include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/common/TCPSocket.h"
 
 #include "PlatformAndroidRemoteGDBServer.h"
 #include "Utility/UriParser.h"
@@ -22,241 +22,211 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace platform_android;
 
-static const lldb::pid_t g_remote_platform_pid = 0; // Alias for the process id of lldb-platform
+static const lldb::pid_t g_remote_platform_pid =
+    0; // Alias for the process id of lldb-platform
+
+static Error ForwardPortWithAdb(
+    const uint16_t local_port, const uint16_t remote_port,
+    const char *remote_socket_name,
+    const llvm::Optional<AdbClient::UnixSocketNamespace> &socket_namespace,
+    std::string &device_id) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
+
+  AdbClient adb;
+  auto error = AdbClient::CreateByDeviceID(device_id, adb);
+  if (error.Fail())
+    return error;
 
-static Error
-ForwardPortWithAdb (const uint16_t local_port,
-                    const uint16_t remote_port,
-                    const char* remote_socket_name,
-                    const llvm::Optional<AdbClient::UnixSocketNamespace>& socket_namespace,
-                    std::string& device_id)
-{
-    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
-
-    AdbClient adb;
-    auto error = AdbClient::CreateByDeviceID(device_id, adb);
-    if (error.Fail ())
-        return error;
+  device_id = adb.GetDeviceID();
+  if (log)
+    log->Printf("Connected to Android device \"%s\"", device_id.c_str());
 
-    device_id = adb.GetDeviceID();
+  if (remote_port != 0) {
     if (log)
-        log->Printf("Connected to Android device \"%s\"", device_id.c_str ());
+      log->Printf("Forwarding remote TCP port %d to local TCP port %d",
+                  remote_port, local_port);
+    return adb.SetPortForwarding(local_port, remote_port);
+  }
 
-    if (remote_port != 0)
-    {
-        if (log)
-            log->Printf("Forwarding remote TCP port %d to local TCP port %d", remote_port, local_port);
-        return adb.SetPortForwarding(local_port, remote_port);
-    }
+  if (log)
+    log->Printf("Forwarding remote socket \"%s\" to local TCP port %d",
+                remote_socket_name, local_port);
 
-    if (log)
-        log->Printf("Forwarding remote socket \"%s\" to local TCP port %d", remote_socket_name, local_port);
+  if (!socket_namespace)
+    return Error("Invalid socket namespace");
+
+  return adb.SetPortForwarding(local_port, remote_socket_name,
+                               *socket_namespace);
+}
 
-    if (!socket_namespace)
-        return Error("Invalid socket namespace");
+static Error DeleteForwardPortWithAdb(uint16_t local_port,
+                                      const std::string &device_id) {
+  AdbClient adb(device_id);
+  return adb.DeletePortForwarding(local_port);
+}
+
+static Error FindUnusedPort(uint16_t &port) {
+  Error error;
+  std::unique_ptr<TCPSocket> tcp_socket(new TCPSocket(false, error));
+  if (error.Fail())
+    return error;
+
+  error = tcp_socket->Listen("127.0.0.1:0", 1);
+  if (error.Success())
+    port = tcp_socket->GetLocalPortNumber();
 
-    return adb.SetPortForwarding(local_port, remote_socket_name, *socket_namespace);
+  return error;
 }
 
-static Error
-DeleteForwardPortWithAdb (uint16_t local_port, const std::string& device_id)
-{
-    AdbClient adb (device_id);
-    return adb.DeletePortForwarding (local_port);
+PlatformAndroidRemoteGDBServer::PlatformAndroidRemoteGDBServer() {}
+
+PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer() {
+  for (const auto &it : m_port_forwards)
+    DeleteForwardPortWithAdb(it.second, m_device_id);
 }
 
-static Error
-FindUnusedPort (uint16_t& port)
-{
-    Error error;
-    std::unique_ptr<TCPSocket> tcp_socket(new TCPSocket(false, error));
-    if (error.Fail())
-        return error;
+bool PlatformAndroidRemoteGDBServer::LaunchGDBServer(lldb::pid_t &pid,
+                                                     std::string &connect_url) {
+  uint16_t remote_port = 0;
+  std::string socket_name;
+  if (!m_gdb_client.LaunchGDBServer("127.0.0.1", pid, remote_port, socket_name))
+    return false;
 
-    error = tcp_socket->Listen("127.0.0.1:0", 1);
-    if (error.Success())
-        port = tcp_socket->GetLocalPortNumber();
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
 
-    return error;
+  auto error =
+      MakeConnectURL(pid, remote_port, socket_name.c_str(), connect_url);
+  if (error.Success() && log)
+    log->Printf("gdbserver connect URL: %s", connect_url.c_str());
+
+  return error.Success();
 }
 
-PlatformAndroidRemoteGDBServer::PlatformAndroidRemoteGDBServer ()
-{
+bool PlatformAndroidRemoteGDBServer::KillSpawnedProcess(lldb::pid_t pid) {
+  DeleteForwardPort(pid);
+  return m_gdb_client.KillSpawnedProcess(pid);
 }
 
-PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer ()
-{
-    for (const auto& it : m_port_forwards)
-        DeleteForwardPortWithAdb(it.second, m_device_id);
-}
-
-bool
-PlatformAndroidRemoteGDBServer::LaunchGDBServer (lldb::pid_t &pid, std::string &connect_url)
-{
-    uint16_t remote_port = 0;
-    std::string socket_name;
-    if (!m_gdb_client.LaunchGDBServer ("127.0.0.1", pid, remote_port, socket_name))
-        return false;
-
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
-
-    auto error = MakeConnectURL (pid,
-                                 remote_port,
-                                 socket_name.c_str (),
-                                 connect_url);
-    if (error.Success() && log)
-        log->Printf("gdbserver connect URL: %s", connect_url.c_str());
-
-    return error.Success();
-}
-
-bool
-PlatformAndroidRemoteGDBServer::KillSpawnedProcess (lldb::pid_t pid)
-{
-    DeleteForwardPort (pid);
-    return m_gdb_client.KillSpawnedProcess (pid);
-}
-
-Error
-PlatformAndroidRemoteGDBServer::ConnectRemote (Args& args)
-{
-    m_device_id.clear();
-
-    if (args.GetArgumentCount() != 1)
-        return Error("\"platform connect\" takes a single argument: <connect-url>");
-
-    int remote_port;
-    std::string scheme, host, path;
-    const char *url = args.GetArgumentAtIndex (0);
-    if (!url)
-        return Error("URL is null.");
-    if (!UriParser::Parse (url, scheme, host, remote_port, path))
-        return Error("Invalid URL: %s", url);
-    if (host != "localhost")
-        m_device_id = host;
-
-    m_socket_namespace.reset();
-    if (scheme == ConnectionFileDescriptor::UNIX_CONNECT_SCHEME)
-        m_socket_namespace = AdbClient::UnixSocketNamespaceFileSystem;
-    else if (scheme == ConnectionFileDescriptor::UNIX_ABSTRACT_CONNECT_SCHEME)
-        m_socket_namespace = AdbClient::UnixSocketNamespaceAbstract;
-
-    std::string connect_url;
-    auto error = MakeConnectURL (g_remote_platform_pid,
-                                 (remote_port < 0) ? 0 : remote_port,
-                                 path.c_str (),
-                                 connect_url);
+Error PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
+  m_device_id.clear();
 
-    if (error.Fail ())
-        return error;
+  if (args.GetArgumentCount() != 1)
+    return Error("\"platform connect\" takes a single argument: <connect-url>");
 
-    args.ReplaceArgumentAtIndex (0, connect_url.c_str ());
+  int remote_port;
+  std::string scheme, host, path;
+  const char *url = args.GetArgumentAtIndex(0);
+  if (!url)
+    return Error("URL is null.");
+  if (!UriParser::Parse(url, scheme, host, remote_port, path))
+    return Error("Invalid URL: %s", url);
+  if (host != "localhost")
+    m_device_id = host;
 
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
-    if (log)
-        log->Printf("Rewritten platform connect URL: %s", connect_url.c_str());
+  m_socket_namespace.reset();
+  if (scheme == ConnectionFileDescriptor::UNIX_CONNECT_SCHEME)
+    m_socket_namespace = AdbClient::UnixSocketNamespaceFileSystem;
+  else if (scheme == ConnectionFileDescriptor::UNIX_ABSTRACT_CONNECT_SCHEME)
+    m_socket_namespace = AdbClient::UnixSocketNamespaceAbstract;
 
-    error = PlatformRemoteGDBServer::ConnectRemote(args);
-    if (error.Fail ())
-        DeleteForwardPort (g_remote_platform_pid);
+  std::string connect_url;
+  auto error =
+      MakeConnectURL(g_remote_platform_pid, (remote_port < 0) ? 0 : remote_port,
+                     path.c_str(), connect_url);
 
+  if (error.Fail())
     return error;
+
+  args.ReplaceArgumentAtIndex(0, connect_url.c_str());
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
+  if (log)
+    log->Printf("Rewritten platform connect URL: %s", connect_url.c_str());
+
+  error = PlatformRemoteGDBServer::ConnectRemote(args);
+  if (error.Fail())
+    DeleteForwardPort(g_remote_platform_pid);
+
+  return error;
 }
 
-Error
-PlatformAndroidRemoteGDBServer::DisconnectRemote ()
-{
-    DeleteForwardPort (g_remote_platform_pid);
-    return PlatformRemoteGDBServer::DisconnectRemote ();
-}
-
-void
-PlatformAndroidRemoteGDBServer::DeleteForwardPort (lldb::pid_t pid)
-{
-    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
-
-    auto it = m_port_forwards.find(pid);
-    if (it == m_port_forwards.end())
-        return;
-
-    const auto port = it->second;
-    const auto error = DeleteForwardPortWithAdb(port, m_device_id);
-    if (error.Fail()) {
-        if (log)
-            log->Printf("Failed to delete port forwarding (pid=%" PRIu64 ", port=%d, device=%s): %s",
-                         pid, port, m_device_id.c_str(), error.AsCString());
-    }
-    m_port_forwards.erase(it);
+Error PlatformAndroidRemoteGDBServer::DisconnectRemote() {
+  DeleteForwardPort(g_remote_platform_pid);
+  return PlatformRemoteGDBServer::DisconnectRemote();
 }
 
-Error
-PlatformAndroidRemoteGDBServer::MakeConnectURL(const lldb::pid_t pid,
-                                               const uint16_t remote_port,
-                                               const char* remote_socket_name,
-                                               std::string& connect_url)
-{
-    static const int kAttempsNum = 5;
-
-    Error error;
-    // There is a race possibility that somebody will occupy
-    // a port while we're in between FindUnusedPort and ForwardPortWithAdb -
-    // adding the loop to mitigate such problem.
-    for (auto i = 0; i < kAttempsNum; ++i)
-    {
-        uint16_t local_port = 0;
-        error = FindUnusedPort(local_port);
-        if (error.Fail())
-            return error;
-
-        error = ForwardPortWithAdb(local_port,
-                                   remote_port,
-                                   remote_socket_name,
-                                   m_socket_namespace,
-                                   m_device_id);
-        if (error.Success())
-        {
-            m_port_forwards[pid] = local_port;
-            std::ostringstream url_str;
-            url_str << "connect://localhost:" << local_port;
-            connect_url = url_str.str();
-            break;
-        }
-    }
+void PlatformAndroidRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) {
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
 
-    return error;
-}
+  auto it = m_port_forwards.find(pid);
+  if (it == m_port_forwards.end())
+    return;
+
+  const auto port = it->second;
+  const auto error = DeleteForwardPortWithAdb(port, m_device_id);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("Failed to delete port forwarding (pid=%" PRIu64
+                  ", port=%d, device=%s): %s",
+                  pid, port, m_device_id.c_str(), error.AsCString());
+  }
+  m_port_forwards.erase(it);
+}
+
+Error PlatformAndroidRemoteGDBServer::MakeConnectURL(
+    const lldb::pid_t pid, const uint16_t remote_port,
+    const char *remote_socket_name, std::string &connect_url) {
+  static const int kAttempsNum = 5;
+
+  Error error;
+  // There is a race possibility that somebody will occupy
+  // a port while we're in between FindUnusedPort and ForwardPortWithAdb -
+  // adding the loop to mitigate such problem.
+  for (auto i = 0; i < kAttempsNum; ++i) {
+    uint16_t local_port = 0;
+    error = FindUnusedPort(local_port);
+    if (error.Fail())
+      return error;
 
-lldb::ProcessSP
-PlatformAndroidRemoteGDBServer::ConnectProcess(const char* connect_url,
-                                               const char* plugin_name,
-                                               lldb_private::Debugger &debugger,
-                                               lldb_private::Target *target,
-                                               lldb_private::Error &error)
-{
-    // We don't have the pid of the remote gdbserver when it isn't started by us but we still want
-    // to store the list of port forwards we set up in our port forward map. Generate a fake pid for
-    // these cases what won't collide with any other valid pid on android.
-    static lldb::pid_t s_remote_gdbserver_fake_pid = 0xffffffffffffffffULL;
-
-    int remote_port;
-    std::string scheme, host, path;
-    if (!UriParser::Parse(connect_url, scheme, host, remote_port, path))
-    {
-        error.SetErrorStringWithFormat("Invalid URL: %s", connect_url);
-        return nullptr;
+    error = ForwardPortWithAdb(local_port, remote_port, remote_socket_name,
+                               m_socket_namespace, m_device_id);
+    if (error.Success()) {
+      m_port_forwards[pid] = local_port;
+      std::ostringstream url_str;
+      url_str << "connect://localhost:" << local_port;
+      connect_url = url_str.str();
+      break;
     }
+  }
 
-    std::string new_connect_url;
-    error = MakeConnectURL(s_remote_gdbserver_fake_pid--,
-                           (remote_port < 0) ? 0 : remote_port,
-                           path.c_str(),
-                           new_connect_url);
-    if (error.Fail())
-        return nullptr;
+  return error;
+}
+
+lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess(
+    const char *connect_url, const char *plugin_name,
+    lldb_private::Debugger &debugger, lldb_private::Target *target,
+    lldb_private::Error &error) {
+  // We don't have the pid of the remote gdbserver when it isn't started by us
+  // but we still want
+  // to store the list of port forwards we set up in our port forward map.
+  // Generate a fake pid for
+  // these cases what won't collide with any other valid pid on android.
+  static lldb::pid_t s_remote_gdbserver_fake_pid = 0xffffffffffffffffULL;
+
+  int remote_port;
+  std::string scheme, host, path;
+  if (!UriParser::Parse(connect_url, scheme, host, remote_port, path)) {
+    error.SetErrorStringWithFormat("Invalid URL: %s", connect_url);
+    return nullptr;
+  }
+
+  std::string new_connect_url;
+  error = MakeConnectURL(s_remote_gdbserver_fake_pid--,
+                         (remote_port < 0) ? 0 : remote_port, path.c_str(),
+                         new_connect_url);
+  if (error.Fail())
+    return nullptr;
 
-    return PlatformRemoteGDBServer::ConnectProcess(new_connect_url.c_str(),
-                                                   plugin_name,
-                                                   debugger,
-                                                   target,
-                                                   error);
+  return PlatformRemoteGDBServer::ConnectProcess(
+      new_connect_url.c_str(), plugin_name, debugger, target, error);
 }

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h Tue Sep  6 15:57:50 2016
@@ -26,48 +26,40 @@
 namespace lldb_private {
 namespace platform_android {
 
-class PlatformAndroidRemoteGDBServer : public platform_gdb_server::PlatformRemoteGDBServer
-{
+class PlatformAndroidRemoteGDBServer
+    : public platform_gdb_server::PlatformRemoteGDBServer {
 public:
-    PlatformAndroidRemoteGDBServer();
+  PlatformAndroidRemoteGDBServer();
 
-    ~PlatformAndroidRemoteGDBServer() override;
+  ~PlatformAndroidRemoteGDBServer() override;
 
-    Error
-    ConnectRemote (Args& args) override;
+  Error ConnectRemote(Args &args) override;
 
-    Error
-    DisconnectRemote () override;
-
-    lldb::ProcessSP
-    ConnectProcess (const char* connect_url,
-                    const char* plugin_name,
-                    lldb_private::Debugger &debugger,
-                    lldb_private::Target *target,
-                    lldb_private::Error &error) override;
+  Error DisconnectRemote() override;
+
+  lldb::ProcessSP ConnectProcess(const char *connect_url,
+                                 const char *plugin_name,
+                                 lldb_private::Debugger &debugger,
+                                 lldb_private::Target *target,
+                                 lldb_private::Error &error) override;
 
 protected:
-    std::string m_device_id;
-    std::map<lldb::pid_t, uint16_t> m_port_forwards;
-    llvm::Optional<AdbClient::UnixSocketNamespace> m_socket_namespace;
-
-    bool
-    LaunchGDBServer (lldb::pid_t &pid, std::string &connect_url) override;
-
-    bool
-    KillSpawnedProcess (lldb::pid_t pid) override;
-
-    void
-    DeleteForwardPort (lldb::pid_t pid);
-
-    Error
-    MakeConnectURL(const lldb::pid_t pid,
-                   const uint16_t remote_port,
-                   const char* remote_socket_name,
-                   std::string& connect_url);
+  std::string m_device_id;
+  std::map<lldb::pid_t, uint16_t> m_port_forwards;
+  llvm::Optional<AdbClient::UnixSocketNamespace> m_socket_namespace;
+
+  bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url) override;
+
+  bool KillSpawnedProcess(lldb::pid_t pid) override;
+
+  void DeleteForwardPort(lldb::pid_t pid);
+
+  Error MakeConnectURL(const lldb::pid_t pid, const uint16_t remote_port,
+                       const char *remote_socket_name,
+                       std::string &connect_url);
 
 private:
-    DISALLOW_COPY_AND_ASSIGN (PlatformAndroidRemoteGDBServer);
+  DISALLOW_COPY_AND_ASSIGN(PlatformAndroidRemoteGDBServer);
 };
 
 } // namespace platform_android

Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp Tue Sep  6 15:57:50 2016
@@ -21,8 +21,8 @@
 // Project includes
 #include "lldb/Breakpoint/BreakpointLocation.h"
 #include "lldb/Breakpoint/BreakpointSite.h"
-#include "lldb/Core/Error.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/Error.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
@@ -34,271 +34,232 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::platform_freebsd;
 
-PlatformSP
-PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch)
-{
-    // The only time we create an instance is when we are creating a remote
-    // freebsd platform
-    const bool is_host = false;
-
-    bool create = force;
-    if (create == false && arch && arch->IsValid())
-    {
-        const llvm::Triple &triple = arch->GetTriple();
-        switch (triple.getOS())
-        {
-            case llvm::Triple::FreeBSD:
-                create = true;
-                break;
+PlatformSP PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch) {
+  // The only time we create an instance is when we are creating a remote
+  // freebsd platform
+  const bool is_host = false;
+
+  bool create = force;
+  if (create == false && arch && arch->IsValid()) {
+    const llvm::Triple &triple = arch->GetTriple();
+    switch (triple.getOS()) {
+    case llvm::Triple::FreeBSD:
+      create = true;
+      break;
 
 #if defined(__FreeBSD__) || defined(__OpenBSD__)
-            // Only accept "unknown" for the OS if the host is BSD and
-            // it "unknown" wasn't specified (it was just returned because it
-            // was NOT specified)
-            case llvm::Triple::OSType::UnknownOS:
-                create = !arch->TripleOSWasSpecified();
-                break;
+    // Only accept "unknown" for the OS if the host is BSD and
+    // it "unknown" wasn't specified (it was just returned because it
+    // was NOT specified)
+    case llvm::Triple::OSType::UnknownOS:
+      create = !arch->TripleOSWasSpecified();
+      break;
 #endif
-            default:
-                break;
-        }
-    }
-    if (create)
-        return PlatformSP(new PlatformFreeBSD (is_host));
-    return PlatformSP();
-
-}
-
-ConstString
-PlatformFreeBSD::GetPluginNameStatic(bool is_host)
-{
-    if (is_host)
-    {
-        static ConstString g_host_name(Platform::GetHostPlatformName ());
-        return g_host_name;
-    }
-    else
-    {
-        static ConstString g_remote_name("remote-freebsd");
-        return g_remote_name;
+    default:
+      break;
     }
-}
-
-const char *
-PlatformFreeBSD::GetDescriptionStatic (bool is_host)
-{
-    if (is_host)
-        return "Local FreeBSD user platform plug-in.";
-    else
-        return "Remote FreeBSD user platform plug-in.";
+  }
+  if (create)
+    return PlatformSP(new PlatformFreeBSD(is_host));
+  return PlatformSP();
+}
+
+ConstString PlatformFreeBSD::GetPluginNameStatic(bool is_host) {
+  if (is_host) {
+    static ConstString g_host_name(Platform::GetHostPlatformName());
+    return g_host_name;
+  } else {
+    static ConstString g_remote_name("remote-freebsd");
+    return g_remote_name;
+  }
+}
+
+const char *PlatformFreeBSD::GetDescriptionStatic(bool is_host) {
+  if (is_host)
+    return "Local FreeBSD user platform plug-in.";
+  else
+    return "Remote FreeBSD user platform plug-in.";
 }
 
 static uint32_t g_initialize_count = 0;
 
-void
-PlatformFreeBSD::Initialize ()
-{
-    Platform::Initialize ();
-
-    if (g_initialize_count++ == 0)
-    {
-#if defined (__FreeBSD__)
-    	// Force a host flag to true for the default platform object.
-        PlatformSP default_platform_sp (new PlatformFreeBSD(true));
-        default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
-        Platform::SetHostPlatform (default_platform_sp);
-#endif
-        PluginManager::RegisterPlugin(PlatformFreeBSD::GetPluginNameStatic(false),
-                                      PlatformFreeBSD::GetDescriptionStatic(false),
-                                      PlatformFreeBSD::CreateInstance);
-    }
-}
-
-void
-PlatformFreeBSD::Terminate ()
-{
-    if (g_initialize_count > 0 && --g_initialize_count == 0)
-    	PluginManager::UnregisterPlugin (PlatformFreeBSD::CreateInstance);
-
-    Platform::Terminate ();
-}
+void PlatformFreeBSD::Initialize() {
+  Platform::Initialize();
 
-bool
-PlatformFreeBSD::GetModuleSpec (const FileSpec& module_file_spec,
-                                const ArchSpec& arch,
-                                ModuleSpec &module_spec)
-{
+  if (g_initialize_count++ == 0) {
+#if defined(__FreeBSD__)
+    // Force a host flag to true for the default platform object.
+    PlatformSP default_platform_sp(new PlatformFreeBSD(true));
+    default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+    Platform::SetHostPlatform(default_platform_sp);
+#endif
+    PluginManager::RegisterPlugin(PlatformFreeBSD::GetPluginNameStatic(false),
+                                  PlatformFreeBSD::GetDescriptionStatic(false),
+                                  PlatformFreeBSD::CreateInstance);
+  }
+}
+
+void PlatformFreeBSD::Terminate() {
+  if (g_initialize_count > 0 && --g_initialize_count == 0)
+    PluginManager::UnregisterPlugin(PlatformFreeBSD::CreateInstance);
+
+  Platform::Terminate();
+}
+
+bool PlatformFreeBSD::GetModuleSpec(const FileSpec &module_file_spec,
+                                    const ArchSpec &arch,
+                                    ModuleSpec &module_spec) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
+                                               module_spec);
+
+  return Platform::GetModuleSpec(module_file_spec, arch, module_spec);
+}
+
+Error PlatformFreeBSD::RunShellCommand(const char *command,
+                                       const FileSpec &working_dir,
+                                       int *status_ptr, int *signo_ptr,
+                                       std::string *command_output,
+                                       uint32_t timeout_sec) {
+  if (IsHost())
+    return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr,
+                                 command_output, timeout_sec);
+  else {
     if (m_remote_platform_sp)
-        return m_remote_platform_sp->GetModuleSpec (module_file_spec, arch, module_spec);
-
-    return Platform::GetModuleSpec (module_file_spec, arch, module_spec);
-}
-
-Error
-PlatformFreeBSD::RunShellCommand(const char *command,
-                                 const FileSpec &working_dir,
-                                 int *status_ptr,
-                                 int *signo_ptr,
-                                 std::string *command_output,
-                                 uint32_t timeout_sec)
-{
-    if (IsHost())
-        return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
+      return m_remote_platform_sp->RunShellCommand(command, working_dir,
+                                                   status_ptr, signo_ptr,
+                                                   command_output, timeout_sec);
     else
-    {
-        if (m_remote_platform_sp)
-            return m_remote_platform_sp->RunShellCommand(command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
-        else
-            return Error("unable to run a remote command without a platform");
-    }
+      return Error("unable to run a remote command without a platform");
+  }
 }
 
-Error
-PlatformFreeBSD::ResolveExecutable (const ModuleSpec &module_spec,
-                                    lldb::ModuleSP &exe_module_sp,
-                                    const FileSpecList *module_search_paths_ptr)
-{
-    Error error;
-    // Nothing special to do here, just use the actual file and architecture
-
-    char exe_path[PATH_MAX];
-    ModuleSpec resolved_module_spec(module_spec);
-
-    if (IsHost())
-    {
-        // If we have "ls" as the module_spec's file, resolve the executable location based on
-        // the current path variables
-        if (!resolved_module_spec.GetFileSpec().Exists())
-        {
-            module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
-            resolved_module_spec.GetFileSpec().SetFile(exe_path, true);
-        }
-
-        if (!resolved_module_spec.GetFileSpec().Exists())
-            resolved_module_spec.GetFileSpec().ResolveExecutableLocation ();
-
-        if (resolved_module_spec.GetFileSpec().Exists())
-            error.Clear();
-        else
-        {
-            error.SetErrorStringWithFormat("unable to find executable for '%s'", resolved_module_spec.GetFileSpec().GetPath().c_str());
-        }
-    }
-    else
-    {
-        if (m_remote_platform_sp)
-        {
-            error = GetCachedExecutable (resolved_module_spec, exe_module_sp, module_search_paths_ptr, *m_remote_platform_sp);
-        }
-        else
-        {
-            // We may connect to a process and use the provided executable (Don't use local $PATH).
-
-            // Resolve any executable within a bundle on MacOSX
-            Host::ResolveExecutableInBundle (resolved_module_spec.GetFileSpec());
-
-            if (resolved_module_spec.GetFileSpec().Exists())
-            {
-                error.Clear();
-            }
-            else
-            {
-                error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", resolved_module_spec.GetFileSpec().GetPath().c_str());
-            }
-        }
-    }
-
-    if (error.Success())
-    {
-        if (resolved_module_spec.GetArchitecture().IsValid())
-        {
-            error = ModuleList::GetSharedModule (resolved_module_spec,
-                                                 exe_module_sp,
-                                                 module_search_paths_ptr,
-                                                 NULL,
-                                                 NULL);
-
-            if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
-            {
-                exe_module_sp.reset();
-                error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s",
-                                                resolved_module_spec.GetFileSpec().GetPath().c_str(),
-                                                resolved_module_spec.GetArchitecture().GetArchitectureName());
-            }
-        }
-        else
-        {
-            // No valid architecture was specified, ask the platform for
-            // the architectures that we should be using (in the correct order)
-            // and see if we can find a match that way
-            StreamString arch_names;
-            for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx)
-            {
-                error = ModuleList::GetSharedModule (resolved_module_spec,
-                                                     exe_module_sp,
-                                                     module_search_paths_ptr,
-                                                     NULL,
-                                                     NULL);
-                // Did we find an executable using one of the
-                if (error.Success())
-                {
-                    if (exe_module_sp && exe_module_sp->GetObjectFile())
-                        break;
-                    else
-                        error.SetErrorToGenericError();
-                }
-
-                if (idx > 0)
-                    arch_names.PutCString (", ");
-                arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName());
-            }
-
-            if (error.Fail() || !exe_module_sp)
-            {
-                if (resolved_module_spec.GetFileSpec().Readable())
-                {
-                    error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
-                                                    resolved_module_spec.GetFileSpec().GetPath().c_str(),
-                                                    GetPluginName().GetCString(),
-                                                    arch_names.GetString().c_str());
-                }
-                else
-                {
-                    error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str());
-                }
-            }
+Error PlatformFreeBSD::ResolveExecutable(
+    const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
+    const FileSpecList *module_search_paths_ptr) {
+  Error error;
+  // Nothing special to do here, just use the actual file and architecture
+
+  char exe_path[PATH_MAX];
+  ModuleSpec resolved_module_spec(module_spec);
+
+  if (IsHost()) {
+    // If we have "ls" as the module_spec's file, resolve the executable
+    // location based on
+    // the current path variables
+    if (!resolved_module_spec.GetFileSpec().Exists()) {
+      module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
+      resolved_module_spec.GetFileSpec().SetFile(exe_path, true);
+    }
+
+    if (!resolved_module_spec.GetFileSpec().Exists())
+      resolved_module_spec.GetFileSpec().ResolveExecutableLocation();
+
+    if (resolved_module_spec.GetFileSpec().Exists())
+      error.Clear();
+    else {
+      error.SetErrorStringWithFormat(
+          "unable to find executable for '%s'",
+          resolved_module_spec.GetFileSpec().GetPath().c_str());
+    }
+  } else {
+    if (m_remote_platform_sp) {
+      error =
+          GetCachedExecutable(resolved_module_spec, exe_module_sp,
+                              module_search_paths_ptr, *m_remote_platform_sp);
+    } else {
+      // We may connect to a process and use the provided executable (Don't use
+      // local $PATH).
+
+      // Resolve any executable within a bundle on MacOSX
+      Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
+
+      if (resolved_module_spec.GetFileSpec().Exists()) {
+        error.Clear();
+      } else {
+        error.SetErrorStringWithFormat(
+            "the platform is not currently connected, and '%s' doesn't exist "
+            "in the system root.",
+            resolved_module_spec.GetFileSpec().GetPath().c_str());
+      }
+    }
+  }
+
+  if (error.Success()) {
+    if (resolved_module_spec.GetArchitecture().IsValid()) {
+      error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+                                          module_search_paths_ptr, NULL, NULL);
+
+      if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) {
+        exe_module_sp.reset();
+        error.SetErrorStringWithFormat(
+            "'%s' doesn't contain the architecture %s",
+            resolved_module_spec.GetFileSpec().GetPath().c_str(),
+            resolved_module_spec.GetArchitecture().GetArchitectureName());
+      }
+    } else {
+      // No valid architecture was specified, ask the platform for
+      // the architectures that we should be using (in the correct order)
+      // and see if we can find a match that way
+      StreamString arch_names;
+      for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
+               idx, resolved_module_spec.GetArchitecture());
+           ++idx) {
+        error =
+            ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+                                        module_search_paths_ptr, NULL, NULL);
+        // Did we find an executable using one of the
+        if (error.Success()) {
+          if (exe_module_sp && exe_module_sp->GetObjectFile())
+            break;
+          else
+            error.SetErrorToGenericError();
+        }
+
+        if (idx > 0)
+          arch_names.PutCString(", ");
+        arch_names.PutCString(
+            resolved_module_spec.GetArchitecture().GetArchitectureName());
+      }
+
+      if (error.Fail() || !exe_module_sp) {
+        if (resolved_module_spec.GetFileSpec().Readable()) {
+          error.SetErrorStringWithFormat(
+              "'%s' doesn't contain any '%s' platform architectures: %s",
+              resolved_module_spec.GetFileSpec().GetPath().c_str(),
+              GetPluginName().GetCString(), arch_names.GetString().c_str());
+        } else {
+          error.SetErrorStringWithFormat(
+              "'%s' is not readable",
+              resolved_module_spec.GetFileSpec().GetPath().c_str());
         }
+      }
     }
+  }
 
-    return error;
+  return error;
 }
 
 // From PlatformMacOSX only
-Error
-PlatformFreeBSD::GetFileWithUUID (const FileSpec &platform_file,
-                                  const UUID *uuid_ptr,
-                                  FileSpec &local_file)
-{
-    if (IsRemote())
-    {
-        if (m_remote_platform_sp)
-            return m_remote_platform_sp->GetFileWithUUID (platform_file, uuid_ptr, local_file);
-    }
-
-    // Default to the local case
-    local_file = platform_file;
-    return Error();
+Error PlatformFreeBSD::GetFileWithUUID(const FileSpec &platform_file,
+                                       const UUID *uuid_ptr,
+                                       FileSpec &local_file) {
+  if (IsRemote()) {
+    if (m_remote_platform_sp)
+      return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
+                                                   local_file);
+  }
+
+  // Default to the local case
+  local_file = platform_file;
+  return Error();
 }
 
-
 //------------------------------------------------------------------
 /// Default Constructor
 //------------------------------------------------------------------
-PlatformFreeBSD::PlatformFreeBSD (bool is_host) :
-    Platform(is_host),
-    m_remote_platform_sp()
-{
-}
+PlatformFreeBSD::PlatformFreeBSD(bool is_host)
+    : Platform(is_host), m_remote_platform_sp() {}
 
 //------------------------------------------------------------------
 /// Destructor.
@@ -306,409 +267,345 @@ PlatformFreeBSD::PlatformFreeBSD (bool i
 /// The destructor is virtual since this class is designed to be
 /// inherited from by the plug-in instance.
 //------------------------------------------------------------------
-PlatformFreeBSD::~PlatformFreeBSD()
-{
-}
-
-//TODO:VK: inherit PlatformPOSIX
+PlatformFreeBSD::~PlatformFreeBSD() {}
 
+// TODO:VK: inherit PlatformPOSIX
 
-bool
-PlatformFreeBSD::GetRemoteOSVersion ()
-{
-    if (m_remote_platform_sp)
-        return m_remote_platform_sp->GetOSVersion (m_major_os_version,
-                                                   m_minor_os_version,
-                                                   m_update_os_version);
-    return false;
+bool PlatformFreeBSD::GetRemoteOSVersion() {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetOSVersion(
+        m_major_os_version, m_minor_os_version, m_update_os_version);
+  return false;
 }
 
-bool
-PlatformFreeBSD::GetRemoteOSBuildString (std::string &s)
-{
-    if (m_remote_platform_sp)
-        return m_remote_platform_sp->GetRemoteOSBuildString (s);
-    s.clear();
-    return false;
+bool PlatformFreeBSD::GetRemoteOSBuildString(std::string &s) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetRemoteOSBuildString(s);
+  s.clear();
+  return false;
 }
 
-bool
-PlatformFreeBSD::GetRemoteOSKernelDescription (std::string &s)
-{
-    if (m_remote_platform_sp)
-        return m_remote_platform_sp->GetRemoteOSKernelDescription (s);
-    s.clear();
-    return false;
+bool PlatformFreeBSD::GetRemoteOSKernelDescription(std::string &s) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
+  s.clear();
+  return false;
 }
 
 // Remote Platform subclasses need to override this function
-ArchSpec
-PlatformFreeBSD::GetRemoteSystemArchitecture ()
-{
-    if (m_remote_platform_sp)
-        return m_remote_platform_sp->GetRemoteSystemArchitecture ();
-    return ArchSpec();
-}
-
-
-const char *
-PlatformFreeBSD::GetHostname ()
-{
-    if (IsHost())
-        return Platform::GetHostname();
-
+ArchSpec PlatformFreeBSD::GetRemoteSystemArchitecture() {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetRemoteSystemArchitecture();
+  return ArchSpec();
+}
+
+const char *PlatformFreeBSD::GetHostname() {
+  if (IsHost())
+    return Platform::GetHostname();
+
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetHostname();
+  return NULL;
+}
+
+bool PlatformFreeBSD::IsConnected() const {
+  if (IsHost())
+    return true;
+  else if (m_remote_platform_sp)
+    return m_remote_platform_sp->IsConnected();
+  return false;
+}
+
+Error PlatformFreeBSD::ConnectRemote(Args &args) {
+  Error error;
+  if (IsHost()) {
+    error.SetErrorStringWithFormat(
+        "can't connect to the host platform '%s', always connected",
+        GetPluginName().GetCString());
+  } else {
+    if (!m_remote_platform_sp)
+      m_remote_platform_sp =
+          Platform::Create(ConstString("remote-gdb-server"), error);
+
+    if (m_remote_platform_sp) {
+      if (error.Success()) {
+        if (m_remote_platform_sp) {
+          error = m_remote_platform_sp->ConnectRemote(args);
+        } else {
+          error.SetErrorString(
+              "\"platform connect\" takes a single argument: <connect-url>");
+        }
+      }
+    } else
+      error.SetErrorString("failed to create a 'remote-gdb-server' platform");
+
+    if (error.Fail())
+      m_remote_platform_sp.reset();
+  }
+
+  return error;
+}
+
+Error PlatformFreeBSD::DisconnectRemote() {
+  Error error;
+
+  if (IsHost()) {
+    error.SetErrorStringWithFormat(
+        "can't disconnect from the host platform '%s', always connected",
+        GetPluginName().GetCString());
+  } else {
     if (m_remote_platform_sp)
-        return m_remote_platform_sp->GetHostname ();
-    return NULL;
-}
-
-bool
-PlatformFreeBSD::IsConnected () const
-{
-    if (IsHost())
-        return true;
-    else if (m_remote_platform_sp)
-        return m_remote_platform_sp->IsConnected();
-    return false;
-}
-
-Error
-PlatformFreeBSD::ConnectRemote (Args& args)
-{
-    Error error;
-    if (IsHost())
-    {
-        error.SetErrorStringWithFormat ("can't connect to the host platform '%s', always connected", GetPluginName().GetCString());
-    }
+      error = m_remote_platform_sp->DisconnectRemote();
     else
-    {
-        if (!m_remote_platform_sp)
-            m_remote_platform_sp = Platform::Create (ConstString("remote-gdb-server"), error);
-
-        if (m_remote_platform_sp)
-        {
-            if (error.Success())
-            {
-                if (m_remote_platform_sp)
-                {
-                    error = m_remote_platform_sp->ConnectRemote (args);
-                }
-                else
-                {
-                    error.SetErrorString ("\"platform connect\" takes a single argument: <connect-url>");
-                }
-            }
-        }
-        else
-            error.SetErrorString ("failed to create a 'remote-gdb-server' platform");
-
-        if (error.Fail())
-            m_remote_platform_sp.reset();
-    }
-
-    return error;
+      error.SetErrorString("the platform is not currently connected");
+  }
+  return error;
 }
 
-Error
-PlatformFreeBSD::DisconnectRemote ()
-{
-    Error error;
-
-    if (IsHost())
-    {
-        error.SetErrorStringWithFormat ("can't disconnect from the host platform '%s', always connected", GetPluginName().GetCString());
-    }
-    else
-    {
-        if (m_remote_platform_sp)
-            error = m_remote_platform_sp->DisconnectRemote ();
-        else
-            error.SetErrorString ("the platform is not currently connected");
-    }
-    return error;
-}
-
-bool
-PlatformFreeBSD::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
-{
-    bool success = false;
-    if (IsHost())
-    {
-        success = Platform::GetProcessInfo (pid, process_info);
-    }
-    else if (m_remote_platform_sp)
-    {
-        success = m_remote_platform_sp->GetProcessInfo (pid, process_info);
-    }
-    return success;
+bool PlatformFreeBSD::GetProcessInfo(lldb::pid_t pid,
+                                     ProcessInstanceInfo &process_info) {
+  bool success = false;
+  if (IsHost()) {
+    success = Platform::GetProcessInfo(pid, process_info);
+  } else if (m_remote_platform_sp) {
+    success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
+  }
+  return success;
 }
 
 uint32_t
-PlatformFreeBSD::FindProcesses (const ProcessInstanceInfoMatch &match_info,
-                               ProcessInstanceInfoList &process_infos)
-{
-    uint32_t match_count = 0;
-    if (IsHost())
-    {
-        // Let the base class figure out the host details
-        match_count = Platform::FindProcesses (match_info, process_infos);
-    }
-    else
-    {
-        // If we are remote, we can only return results if we are connected
-        if (m_remote_platform_sp)
-            match_count = m_remote_platform_sp->FindProcesses (match_info, process_infos);
-    }
-    return match_count;
-}
-
-const char *
-PlatformFreeBSD::GetUserName (uint32_t uid)
-{
-    // Check the cache in Platform in case we have already looked this uid up
-    const char *user_name = Platform::GetUserName(uid);
-    if (user_name)
-        return user_name;
-
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->GetUserName(uid);
-    return NULL;
-}
-
-const char *
-PlatformFreeBSD::GetGroupName (uint32_t gid)
-{
-    const char *group_name = Platform::GetGroupName(gid);
-    if (group_name)
-        return group_name;
-
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->GetGroupName(gid);
-    return NULL;
-}
-
-
-Error
-PlatformFreeBSD::GetSharedModule (const ModuleSpec &module_spec,
-                                  Process* process,
-                                  ModuleSP &module_sp,
-                                  const FileSpecList *module_search_paths_ptr,
-                                  ModuleSP *old_module_sp_ptr,
-                                  bool *did_create_ptr)
-{
-    Error error;
-    module_sp.reset();
-
-    if (IsRemote())
-    {
-        // If we have a remote platform always, let it try and locate
-        // the shared module first.
-        if (m_remote_platform_sp)
-        {
-            error = m_remote_platform_sp->GetSharedModule (module_spec,
-                                                           process,
-                                                           module_sp,
-                                                           module_search_paths_ptr,
-                                                           old_module_sp_ptr,
-                                                           did_create_ptr);
-        }
-    }
-
-    if (!module_sp)
-    {
-        // Fall back to the local platform and find the file locally
-        error = Platform::GetSharedModule (module_spec,
-                                           process,
-                                           module_sp,
-                                           module_search_paths_ptr,
-                                           old_module_sp_ptr,
-                                           did_create_ptr);
-    }
-    if (module_sp)
-        module_sp->SetPlatformFileSpec(module_spec.GetFileSpec());
-    return error;
-}
-
-
-bool
-PlatformFreeBSD::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
-{
-    if (IsHost())
-    {
-        ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
-        if (hostArch.GetTriple().isOSFreeBSD())
-        {
-            if (idx == 0)
-            {
-                arch = hostArch;
-                return arch.IsValid();
-            }
-            else if (idx == 1)
-            {
-                // If the default host architecture is 64-bit, look for a 32-bit variant
-                if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit())
-                {
-                    arch = HostInfo::GetArchitecture(HostInfo::eArchKind32);
-                    return arch.IsValid();
-                }
-            }
+PlatformFreeBSD::FindProcesses(const ProcessInstanceInfoMatch &match_info,
+                               ProcessInstanceInfoList &process_infos) {
+  uint32_t match_count = 0;
+  if (IsHost()) {
+    // Let the base class figure out the host details
+    match_count = Platform::FindProcesses(match_info, process_infos);
+  } else {
+    // If we are remote, we can only return results if we are connected
+    if (m_remote_platform_sp)
+      match_count =
+          m_remote_platform_sp->FindProcesses(match_info, process_infos);
+  }
+  return match_count;
+}
+
+const char *PlatformFreeBSD::GetUserName(uint32_t uid) {
+  // Check the cache in Platform in case we have already looked this uid up
+  const char *user_name = Platform::GetUserName(uid);
+  if (user_name)
+    return user_name;
+
+  if (IsRemote() && m_remote_platform_sp)
+    return m_remote_platform_sp->GetUserName(uid);
+  return NULL;
+}
+
+const char *PlatformFreeBSD::GetGroupName(uint32_t gid) {
+  const char *group_name = Platform::GetGroupName(gid);
+  if (group_name)
+    return group_name;
+
+  if (IsRemote() && m_remote_platform_sp)
+    return m_remote_platform_sp->GetGroupName(gid);
+  return NULL;
+}
+
+Error PlatformFreeBSD::GetSharedModule(
+    const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
+    const FileSpecList *module_search_paths_ptr, ModuleSP *old_module_sp_ptr,
+    bool *did_create_ptr) {
+  Error error;
+  module_sp.reset();
+
+  if (IsRemote()) {
+    // If we have a remote platform always, let it try and locate
+    // the shared module first.
+    if (m_remote_platform_sp) {
+      error = m_remote_platform_sp->GetSharedModule(
+          module_spec, process, module_sp, module_search_paths_ptr,
+          old_module_sp_ptr, did_create_ptr);
+    }
+  }
+
+  if (!module_sp) {
+    // Fall back to the local platform and find the file locally
+    error = Platform::GetSharedModule(module_spec, process, module_sp,
+                                      module_search_paths_ptr,
+                                      old_module_sp_ptr, did_create_ptr);
+  }
+  if (module_sp)
+    module_sp->SetPlatformFileSpec(module_spec.GetFileSpec());
+  return error;
+}
+
+bool PlatformFreeBSD::GetSupportedArchitectureAtIndex(uint32_t idx,
+                                                      ArchSpec &arch) {
+  if (IsHost()) {
+    ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+    if (hostArch.GetTriple().isOSFreeBSD()) {
+      if (idx == 0) {
+        arch = hostArch;
+        return arch.IsValid();
+      } else if (idx == 1) {
+        // If the default host architecture is 64-bit, look for a 32-bit variant
+        if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) {
+          arch = HostInfo::GetArchitecture(HostInfo::eArchKind32);
+          return arch.IsValid();
         }
+      }
     }
-    else
-    {
-        if (m_remote_platform_sp)
-            return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch);
-
-        llvm::Triple triple;
-        // Set the OS to FreeBSD
-        triple.setOS(llvm::Triple::FreeBSD);
-        // Set the architecture
-        switch (idx)
-        {
-            case 0: triple.setArchName("x86_64"); break;
-            case 1: triple.setArchName("i386"); break;
-            case 2: triple.setArchName("aarch64"); break;
-            case 3: triple.setArchName("arm"); break;
-            case 4: triple.setArchName("mips64"); break;
-            case 5: triple.setArchName("mips"); break;
-            case 6: triple.setArchName("ppc64"); break;
-            case 7: triple.setArchName("ppc"); break;
-            default: return false;
-        }
-        // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the vendor by
-        // calling triple.SetVendorName("unknown") so that it is a "unspecified unknown".
-        // This means when someone calls triple.GetVendorName() it will return an empty string
-        // which indicates that the vendor can be set when two architectures are merged
+  } else {
+    if (m_remote_platform_sp)
+      return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch);
 
-        // Now set the triple into "arch" and return true
-        arch.SetTriple(triple);
-        return true;
+    llvm::Triple triple;
+    // Set the OS to FreeBSD
+    triple.setOS(llvm::Triple::FreeBSD);
+    // Set the architecture
+    switch (idx) {
+    case 0:
+      triple.setArchName("x86_64");
+      break;
+    case 1:
+      triple.setArchName("i386");
+      break;
+    case 2:
+      triple.setArchName("aarch64");
+      break;
+    case 3:
+      triple.setArchName("arm");
+      break;
+    case 4:
+      triple.setArchName("mips64");
+      break;
+    case 5:
+      triple.setArchName("mips");
+      break;
+    case 6:
+      triple.setArchName("ppc64");
+      break;
+    case 7:
+      triple.setArchName("ppc");
+      break;
+    default:
+      return false;
     }
-    return false;
+    // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the
+    // vendor by
+    // calling triple.SetVendorName("unknown") so that it is a "unspecified
+    // unknown".
+    // This means when someone calls triple.GetVendorName() it will return an
+    // empty string
+    // which indicates that the vendor can be set when two architectures are
+    // merged
+
+    // Now set the triple into "arch" and return true
+    arch.SetTriple(triple);
+    return true;
+  }
+  return false;
 }
 
-void
-PlatformFreeBSD::GetStatus (Stream &strm)
-{
+void PlatformFreeBSD::GetStatus(Stream &strm) {
 #ifndef LLDB_DISABLE_POSIX
-    struct utsname un;
+  struct utsname un;
 
-    strm << "      Host: ";
+  strm << "      Host: ";
 
-    ::memset(&un, 0, sizeof(utsname));
-    if (uname(&un) == -1)
-        strm << "FreeBSD" << '\n';
-
-    strm << un.sysname << ' ' << un.release;
-    if (un.nodename[0] != '\0')
-        strm << " (" << un.nodename << ')';
-    strm << '\n';
-
-    // Dump a common information about the platform status.
-    strm << "Host: " << un.sysname << ' ' << un.release << ' ' << un.version << '\n';
+  ::memset(&un, 0, sizeof(utsname));
+  if (uname(&un) == -1)
+    strm << "FreeBSD" << '\n';
+
+  strm << un.sysname << ' ' << un.release;
+  if (un.nodename[0] != '\0')
+    strm << " (" << un.nodename << ')';
+  strm << '\n';
+
+  // Dump a common information about the platform status.
+  strm << "Host: " << un.sysname << ' ' << un.release << ' ' << un.version
+       << '\n';
 #endif
 
-    Platform::GetStatus(strm);
+  Platform::GetStatus(strm);
 }
 
 size_t
-PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site)
-{
-    switch (target.GetArchitecture().GetMachine())
-    {
-    case llvm::Triple::arm:
-        {
-            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 == eAddressClassUnknown && (bp_loc_sp->GetAddress().GetFileAddress() & 1))
-                    addr_class = eAddressClassCodeAlternateISA;
-            }
-
-            if (addr_class == eAddressClassCodeAlternateISA)
-            {
-                // TODO: Enable when FreeBSD supports thumb breakpoints.
-                // FreeBSD kernel as of 10.x, does not support thumb breakpoints
-                return 0;
-            }
-        }
-        LLVM_FALLTHROUGH;
-    default:
-        return Platform::GetSoftwareBreakpointTrapOpcode(target, bp_site);
-    }
-}
-
-
-void
-PlatformFreeBSD::CalculateTrapHandlerSymbolNames ()
-{
-    m_trap_handlers.push_back (ConstString ("_sigtramp"));
-}
-
-Error
-PlatformFreeBSD::LaunchProcess (ProcessLaunchInfo &launch_info)
-{
-    Error error;
-    if (IsHost())
-    {
-        error = Platform::LaunchProcess (launch_info);
-    }
+PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode(Target &target,
+                                                 BreakpointSite *bp_site) {
+  switch (target.GetArchitecture().GetMachine()) {
+  case llvm::Triple::arm: {
+    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 == eAddressClassUnknown &&
+          (bp_loc_sp->GetAddress().GetFileAddress() & 1))
+        addr_class = eAddressClassCodeAlternateISA;
+    }
+
+    if (addr_class == eAddressClassCodeAlternateISA) {
+      // TODO: Enable when FreeBSD supports thumb breakpoints.
+      // FreeBSD kernel as of 10.x, does not support thumb breakpoints
+      return 0;
+    }
+  }
+    LLVM_FALLTHROUGH;
+  default:
+    return Platform::GetSoftwareBreakpointTrapOpcode(target, bp_site);
+  }
+}
+
+void PlatformFreeBSD::CalculateTrapHandlerSymbolNames() {
+  m_trap_handlers.push_back(ConstString("_sigtramp"));
+}
+
+Error PlatformFreeBSD::LaunchProcess(ProcessLaunchInfo &launch_info) {
+  Error error;
+  if (IsHost()) {
+    error = Platform::LaunchProcess(launch_info);
+  } else {
+    if (m_remote_platform_sp)
+      error = m_remote_platform_sp->LaunchProcess(launch_info);
     else
-    {
-        if (m_remote_platform_sp)
-            error = m_remote_platform_sp->LaunchProcess (launch_info);
-        else
-            error.SetErrorString ("the platform is not currently connected");
-    }
-    return error;
-}
-
-lldb::ProcessSP
-PlatformFreeBSD::Attach(ProcessAttachInfo &attach_info,
-                        Debugger &debugger,
-                        Target *target,
-                        Error &error)
-{
-    lldb::ProcessSP process_sp;
-    if (IsHost())
-    {
-        if (target == NULL)
-        {
-            TargetSP new_target_sp;
-            ArchSpec emptyArchSpec;
-
-            error = debugger.GetTargetList().CreateTarget (debugger,
-                                                           NULL,
-                                                           emptyArchSpec,
-                                                           false,
-                                                           m_remote_platform_sp,
-                                                           new_target_sp);
-            target = new_target_sp.get();
-        }
-        else
-            error.Clear();
-
-        if (target && error.Success())
-        {
-            debugger.GetTargetList().SetSelectedTarget(target);
-            // The freebsd always currently uses the GDB remote debugger plug-in
-            // so even when debugging locally we are debugging remotely!
-            // Just like the darwin plugin.
-            process_sp = target->CreateProcess (attach_info.GetListenerForProcess(debugger), "gdb-remote", NULL);
+      error.SetErrorString("the platform is not currently connected");
+  }
+  return error;
+}
+
+lldb::ProcessSP PlatformFreeBSD::Attach(ProcessAttachInfo &attach_info,
+                                        Debugger &debugger, Target *target,
+                                        Error &error) {
+  lldb::ProcessSP process_sp;
+  if (IsHost()) {
+    if (target == NULL) {
+      TargetSP new_target_sp;
+      ArchSpec emptyArchSpec;
+
+      error = debugger.GetTargetList().CreateTarget(
+          debugger, NULL, emptyArchSpec, false, m_remote_platform_sp,
+          new_target_sp);
+      target = new_target_sp.get();
+    } else
+      error.Clear();
+
+    if (target && error.Success()) {
+      debugger.GetTargetList().SetSelectedTarget(target);
+      // The freebsd always currently uses the GDB remote debugger plug-in
+      // so even when debugging locally we are debugging remotely!
+      // Just like the darwin plugin.
+      process_sp = target->CreateProcess(
+          attach_info.GetListenerForProcess(debugger), "gdb-remote", NULL);
 
-            if (process_sp)
-                error = process_sp->Attach (attach_info);
-        }
+      if (process_sp)
+        error = process_sp->Attach(attach_info);
     }
+  } else {
+    if (m_remote_platform_sp)
+      process_sp =
+          m_remote_platform_sp->Attach(attach_info, debugger, target, error);
     else
-    {
-        if (m_remote_platform_sp)
-            process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, error);
-        else
-            error.SetErrorString ("the platform is not currently connected");
-    }
-    return process_sp;
+      error.SetErrorString("the platform is not currently connected");
+  }
+  return process_sp;
 }

Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h (original)
+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h Tue Sep  6 15:57:50 2016
@@ -19,157 +19,111 @@
 namespace lldb_private {
 namespace platform_freebsd {
 
-    class PlatformFreeBSD : public Platform
-    {
-    public:
-        PlatformFreeBSD(bool is_host);
-
-        ~PlatformFreeBSD() override;
-
-        //------------------------------------------------------------
-        // Class functions
-        //------------------------------------------------------------
-        static lldb::PlatformSP
-        CreateInstance(bool force, const ArchSpec *arch);
-
-        static void
-        Initialize ();
-
-        static void
-        Terminate ();
-
-        static ConstString
-        GetPluginNameStatic (bool is_host);
-
-        static const char *
-        GetDescriptionStatic (bool is_host);
-
-        //------------------------------------------------------------
-        // lldb_private::PluginInterface functions
-        //------------------------------------------------------------
-        ConstString
-        GetPluginName() override
-        {
-            return GetPluginNameStatic (IsHost());
-        }
-
-        uint32_t
-        GetPluginVersion() override
-        {
-            return 1;
-        }
-
-        const char *
-        GetDescription () override
-        {
-            return GetDescriptionStatic(IsHost());
-        }
-
-        //------------------------------------------------------------
-        // lldb_private::Platform functions
-        //------------------------------------------------------------
-        bool
-        GetModuleSpec(const FileSpec& module_file_spec,
-                      const ArchSpec& arch,
-                      ModuleSpec &module_spec) override;
-
-        Error
-        RunShellCommand(const char *command,
-                        const FileSpec &working_dir,
-                        int *status_ptr,
-                        int *signo_ptr,
+class PlatformFreeBSD : public Platform {
+public:
+  PlatformFreeBSD(bool is_host);
+
+  ~PlatformFreeBSD() override;
+
+  //------------------------------------------------------------
+  // Class functions
+  //------------------------------------------------------------
+  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static ConstString GetPluginNameStatic(bool is_host);
+
+  static const char *GetDescriptionStatic(bool is_host);
+
+  //------------------------------------------------------------
+  // lldb_private::PluginInterface functions
+  //------------------------------------------------------------
+  ConstString GetPluginName() override { return GetPluginNameStatic(IsHost()); }
+
+  uint32_t GetPluginVersion() override { return 1; }
+
+  const char *GetDescription() override {
+    return GetDescriptionStatic(IsHost());
+  }
+
+  //------------------------------------------------------------
+  // lldb_private::Platform functions
+  //------------------------------------------------------------
+  bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
+                     ModuleSpec &module_spec) override;
+
+  Error RunShellCommand(const char *command, const FileSpec &working_dir,
+                        int *status_ptr, int *signo_ptr,
                         std::string *command_output,
                         uint32_t timeout_sec) override;
 
-        Error
-        ResolveExecutable(const ModuleSpec &module_spec,
+  Error ResolveExecutable(const ModuleSpec &module_spec,
                           lldb::ModuleSP &module_sp,
                           const FileSpecList *module_search_paths_ptr) override;
 
-        size_t
-        GetSoftwareBreakpointTrapOpcode(Target &target,
-                                        BreakpointSite *bp_site) override;
+  size_t GetSoftwareBreakpointTrapOpcode(Target &target,
+                                         BreakpointSite *bp_site) override;
 
-        bool
-        GetRemoteOSVersion () override;
+  bool GetRemoteOSVersion() override;
 
-        bool
-        GetRemoteOSBuildString (std::string &s) override;
+  bool GetRemoteOSBuildString(std::string &s) override;
 
-        bool
-        GetRemoteOSKernelDescription (std::string &s) override;
+  bool GetRemoteOSKernelDescription(std::string &s) override;
 
-        // Remote Platform subclasses need to override this function
-        ArchSpec
-        GetRemoteSystemArchitecture() override;
+  // Remote Platform subclasses need to override this function
+  ArchSpec GetRemoteSystemArchitecture() override;
 
-        bool
-        IsConnected () const override;
+  bool IsConnected() const override;
 
-        Error
-        ConnectRemote(Args& args) override;
+  Error ConnectRemote(Args &args) override;
 
-        Error
-        DisconnectRemote() override;
+  Error DisconnectRemote() override;
 
-        const char *
-        GetHostname () override;
+  const char *GetHostname() override;
 
-        const char *
-        GetUserName (uint32_t uid) override;
+  const char *GetUserName(uint32_t uid) override;
 
-        const char *
-        GetGroupName (uint32_t gid) override;
+  const char *GetGroupName(uint32_t gid) override;
 
-        bool
-        GetProcessInfo(lldb::pid_t pid,
-                       ProcessInstanceInfo &proc_info) override;
+  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
 
-        uint32_t
-        FindProcesses(const ProcessInstanceInfoMatch &match_info,
-                      ProcessInstanceInfoList &process_infos) override;
+  uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
+                         ProcessInstanceInfoList &process_infos) override;
 
-        Error
-        LaunchProcess(ProcessLaunchInfo &launch_info) override;
+  Error LaunchProcess(ProcessLaunchInfo &launch_info) override;
 
-        lldb::ProcessSP
-        Attach(ProcessAttachInfo &attach_info,
-               Debugger &debugger,
-               Target *target,
-               Error &error) override;
+  lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
+                         Target *target, Error &error) override;
 
-        // FreeBSD processes can not be launched by spawning and attaching.
-        bool
-        CanDebugProcess () override { return false; }
+  // FreeBSD processes can not be launched by spawning and attaching.
+  bool CanDebugProcess() override { return false; }
 
-        // Only on PlatformMacOSX:
-        Error
-        GetFileWithUUID(const FileSpec &platform_file,
-                        const UUID* uuid, FileSpec &local_file) override;
+  // Only on PlatformMacOSX:
+  Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
+                        FileSpec &local_file) override;
 
-        Error
-        GetSharedModule(const ModuleSpec &module_spec,
-                        Process* process,
+  Error GetSharedModule(const ModuleSpec &module_spec, Process *process,
                         lldb::ModuleSP &module_sp,
                         const FileSpecList *module_search_paths_ptr,
                         lldb::ModuleSP *old_module_sp_ptr,
                         bool *did_create_ptr) override;
 
-        bool
-        GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
+  bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
 
-        void
-        GetStatus(Stream &strm) override;
+  void GetStatus(Stream &strm) override;
 
-        void
-        CalculateTrapHandlerSymbolNames () override;
+  void CalculateTrapHandlerSymbolNames() override;
 
-    protected:
-        lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote freebsd OS
+protected:
+  lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a
+                                         // remote freebsd OS
 
-    private:
-        DISALLOW_COPY_AND_ASSIGN (PlatformFreeBSD);
-    };
+private:
+  DISALLOW_COPY_AND_ASSIGN(PlatformFreeBSD);
+};
 
 } // namespace platform_freebsd
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- PlatformKalimba.cpp ---------------------------------------*- C++ -*-===//
+//===-- PlatformKalimba.cpp ---------------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -13,8 +14,8 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Core/Error.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/Error.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/ModuleSpec.h"
@@ -22,202 +23,171 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Target/Target.h"
 #include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
 static uint32_t g_initialize_count = 0;
 
-PlatformSP
-PlatformKalimba::CreateInstance (bool force, const ArchSpec *arch)
-{
-    bool create = force;
-    if (create == false && arch && arch->IsValid())
-    {
-        const llvm::Triple &triple = arch->GetTriple();
-        switch (triple.getVendor())
-        {
-            case llvm::Triple::CSR:
-                create = true;
-                break;
-
-            default:
-                break;
-        }
-    }
-    if (create)
-        return PlatformSP(new PlatformKalimba(false));
-    return PlatformSP();
+PlatformSP PlatformKalimba::CreateInstance(bool force, const ArchSpec *arch) {
+  bool create = force;
+  if (create == false && arch && arch->IsValid()) {
+    const llvm::Triple &triple = arch->GetTriple();
+    switch (triple.getVendor()) {
+    case llvm::Triple::CSR:
+      create = true;
+      break;
+
+    default:
+      break;
+    }
+  }
+  if (create)
+    return PlatformSP(new PlatformKalimba(false));
+  return PlatformSP();
 }
 
 lldb_private::ConstString
-PlatformKalimba::GetPluginNameStatic (bool /*is_host*/)
-{
-    static ConstString g_remote_name("kalimba");
-    return g_remote_name;
-}
+PlatformKalimba::GetPluginNameStatic(bool /*is_host*/) {
+  static ConstString g_remote_name("kalimba");
+  return g_remote_name;
+}
+
+const char *PlatformKalimba::GetPluginDescriptionStatic(bool /*is_host*/) {
+  return "Kalimba user platform plug-in.";
+}
+
+lldb_private::ConstString PlatformKalimba::GetPluginName() {
+  return GetPluginNameStatic(false);
+}
+
+void PlatformKalimba::Initialize() {
+  Platform::Initialize();
+
+  if (g_initialize_count++ == 0) {
+    PluginManager::RegisterPlugin(
+        PlatformKalimba::GetPluginNameStatic(false),
+        PlatformKalimba::GetPluginDescriptionStatic(false),
+        PlatformKalimba::CreateInstance);
+  }
+}
+
+void PlatformKalimba::Terminate() {
+  if (g_initialize_count > 0) {
+    if (--g_initialize_count == 0) {
+      PluginManager::UnregisterPlugin(PlatformKalimba::CreateInstance);
+    }
+  }
+
+  Platform::Terminate();
+}
+
+Error PlatformKalimba::ResolveExecutable(
+    const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp,
+    const FileSpecList *module_search_paths_ptr) {
+  Error error;
+  char exe_path[PATH_MAX];
+  ModuleSpec resolved_module_spec(ms);
+
+  if (!resolved_module_spec.GetFileSpec().Exists()) {
+    resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
+    error.SetErrorStringWithFormat("unable to find executable for '%s'",
+                                   exe_path);
+  }
+
+  if (error.Success()) {
+    if (resolved_module_spec.GetArchitecture().IsValid()) {
+      error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+                                          NULL, NULL, NULL);
+      if (error.Fail()) {
+        // If we failed, it may be because the vendor and os aren't known. If
+        // that is the
+        // case, try setting them to the host architecture and give it another
+        // try.
+        llvm::Triple &module_triple =
+            resolved_module_spec.GetArchitecture().GetTriple();
+        bool is_vendor_specified =
+            (module_triple.getVendor() != llvm::Triple::UnknownVendor);
+        bool is_os_specified =
+            (module_triple.getOS() != llvm::Triple::UnknownOS);
+        if (!is_vendor_specified || !is_os_specified) {
+          const llvm::Triple &host_triple =
+              HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple();
+
+          if (!is_vendor_specified)
+            module_triple.setVendorName(host_triple.getVendorName());
+          if (!is_os_specified)
+            module_triple.setOSName(host_triple.getOSName());
 
-const char *
-PlatformKalimba::GetPluginDescriptionStatic (bool /*is_host*/)
-{
-    return "Kalimba user platform plug-in.";
-}
-
-lldb_private::ConstString
-PlatformKalimba::GetPluginName()
-{
-    return GetPluginNameStatic(false);
-}
-
-void
-PlatformKalimba::Initialize ()
-{
-    Platform::Initialize ();
-
-    if (g_initialize_count++ == 0)
-    {
-        PluginManager::RegisterPlugin(PlatformKalimba::GetPluginNameStatic(false),
-                                      PlatformKalimba::GetPluginDescriptionStatic(false),
-                                      PlatformKalimba::CreateInstance);
-    }
-}
-
-void
-PlatformKalimba::Terminate ()
-{
-    if (g_initialize_count > 0)
-    {
-        if (--g_initialize_count == 0)
-        {
-            PluginManager::UnregisterPlugin (PlatformKalimba::CreateInstance);
+          error = ModuleList::GetSharedModule(resolved_module_spec,
+                                              exe_module_sp, NULL, NULL, NULL);
         }
-    }
-
-    Platform::Terminate ();
-}
-
-Error
-PlatformKalimba::ResolveExecutable (const ModuleSpec &ms,
-                                    lldb::ModuleSP &exe_module_sp,
-                                    const FileSpecList *module_search_paths_ptr)
-{
-    Error error;
-    char exe_path[PATH_MAX];
-    ModuleSpec resolved_module_spec(ms);
-
-    if (!resolved_module_spec.GetFileSpec().Exists())
-    {
-        resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
-        error.SetErrorStringWithFormat("unable to find executable for '%s'", exe_path);
-    }
+      }
 
-    if (error.Success())
-    {
-        if (resolved_module_spec.GetArchitecture().IsValid())
-        {
-            error = ModuleList::GetSharedModule (resolved_module_spec,
-                                                 exe_module_sp, 
-                                                 NULL, 
-                                                 NULL,
-                                                 NULL);
-            if (error.Fail())
-            {
-                // If we failed, it may be because the vendor and os aren't known. If that is the
-                // case, try setting them to the host architecture and give it another try.
-                llvm::Triple &module_triple = resolved_module_spec.GetArchitecture().GetTriple();
-                bool is_vendor_specified = (module_triple.getVendor() != llvm::Triple::UnknownVendor);
-                bool is_os_specified = (module_triple.getOS() != llvm::Triple::UnknownOS);
-                if (!is_vendor_specified || !is_os_specified)
-                {
-                    const llvm::Triple &host_triple = HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple();
-
-                    if (!is_vendor_specified)
-                        module_triple.setVendorName (host_triple.getVendorName());
-                    if (!is_os_specified)
-                        module_triple.setOSName (host_triple.getOSName());
-
-                    error = ModuleList::GetSharedModule (resolved_module_spec,
-                                                         exe_module_sp, 
-                                                         NULL, 
-                                                         NULL,
-                                                         NULL);
-                }
-            }
-        
-            // TODO find out why exe_module_sp might be NULL            
-            if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
-            {
-                exe_module_sp.reset();
-                error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s",
-                                                resolved_module_spec.GetFileSpec().GetPath().c_str(),
-                                                resolved_module_spec.GetArchitecture().GetArchitectureName());
-            }
+      // TODO find out why exe_module_sp might be NULL
+      if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) {
+        exe_module_sp.reset();
+        error.SetErrorStringWithFormat(
+            "'%s' doesn't contain the architecture %s",
+            resolved_module_spec.GetFileSpec().GetPath().c_str(),
+            resolved_module_spec.GetArchitecture().GetArchitectureName());
+      }
+    } else {
+      // No valid architecture was specified, ask the platform for
+      // the architectures that we should be using (in the correct order)
+      // and see if we can find a match that way
+      StreamString arch_names;
+      for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
+               idx, resolved_module_spec.GetArchitecture());
+           ++idx) {
+        error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+                                            NULL, NULL, NULL);
+        // Did we find an executable using one of the
+        if (error.Success()) {
+          if (exe_module_sp && exe_module_sp->GetObjectFile())
+            break;
+          else
+            error.SetErrorToGenericError();
         }
-        else
-        {
-            // No valid architecture was specified, ask the platform for
-            // the architectures that we should be using (in the correct order)
-            // and see if we can find a match that way
-            StreamString arch_names;
-            for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx)
-            {
-                error = ModuleList::GetSharedModule (resolved_module_spec,
-                                                     exe_module_sp, 
-                                                     NULL, 
-                                                     NULL,
-                                                     NULL);
-                // Did we find an executable using one of the 
-                if (error.Success())
-                {
-                    if (exe_module_sp && exe_module_sp->GetObjectFile())
-                        break;
-                    else
-                        error.SetErrorToGenericError();
-                }
-                
-                if (idx > 0)
-                    arch_names.PutCString (", ");
-                arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName());
-            }
-            
-            if (error.Fail() || !exe_module_sp)
-            {
-                if (resolved_module_spec.GetFileSpec().Readable())
-                {
-                    error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
-                                                    resolved_module_spec.GetFileSpec().GetPath().c_str(),
-                                                    GetPluginName().GetCString(),
-                                                    arch_names.GetString().c_str());
-                }
-                else
-                {
-                    error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str());
-                }
-            }
+
+        if (idx > 0)
+          arch_names.PutCString(", ");
+        arch_names.PutCString(
+            resolved_module_spec.GetArchitecture().GetArchitectureName());
+      }
+
+      if (error.Fail() || !exe_module_sp) {
+        if (resolved_module_spec.GetFileSpec().Readable()) {
+          error.SetErrorStringWithFormat(
+              "'%s' doesn't contain any '%s' platform architectures: %s",
+              resolved_module_spec.GetFileSpec().GetPath().c_str(),
+              GetPluginName().GetCString(), arch_names.GetString().c_str());
+        } else {
+          error.SetErrorStringWithFormat(
+              "'%s' is not readable",
+              resolved_module_spec.GetFileSpec().GetPath().c_str());
         }
+      }
     }
+  }
 
-    return error;
+  return error;
 }
 
-Error
-PlatformKalimba::GetFileWithUUID (const FileSpec & /*platform_file*/, 
-                                const UUID * /*uuid_ptr*/, FileSpec & /*local_file*/)
-{
-    return Error();
+Error PlatformKalimba::GetFileWithUUID(const FileSpec & /*platform_file*/,
+                                       const UUID * /*uuid_ptr*/,
+                                       FileSpec & /*local_file*/) {
+  return Error();
 }
 
-
 //------------------------------------------------------------------
 /// Default Constructor
 //------------------------------------------------------------------
-PlatformKalimba::PlatformKalimba (bool is_host) :
-    Platform(is_host),  // This is the local host platform
-    m_remote_platform_sp ()
-{
-}
+PlatformKalimba::PlatformKalimba(bool is_host)
+    : Platform(is_host), // This is the local host platform
+      m_remote_platform_sp() {}
 
 //------------------------------------------------------------------
 /// Destructor.
@@ -225,100 +195,73 @@ PlatformKalimba::PlatformKalimba (bool i
 /// The destructor is virtual since this class is designed to be
 /// inherited from by the plug-in instance.
 //------------------------------------------------------------------
-PlatformKalimba::~PlatformKalimba()
-{
-}
+PlatformKalimba::~PlatformKalimba() {}
 
-bool
-PlatformKalimba::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
-{
-    bool success = false;
-    if (IsHost())
-    {
-        success = false;
-    }
-    else
-    {
-        if (m_remote_platform_sp) 
-            success = m_remote_platform_sp->GetProcessInfo (pid, process_info);
-    }
-    return success;
+bool PlatformKalimba::GetProcessInfo(lldb::pid_t pid,
+                                     ProcessInstanceInfo &process_info) {
+  bool success = false;
+  if (IsHost()) {
+    success = false;
+  } else {
+    if (m_remote_platform_sp)
+      success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
+  }
+  return success;
+}
+
+bool PlatformKalimba::GetSupportedArchitectureAtIndex(uint32_t idx,
+                                                      ArchSpec &arch) {
+  if (idx == 0) {
+    arch = ArchSpec("kalimba3-csr-unknown");
+    return true;
+  }
+  if (idx == 1) {
+    arch = ArchSpec("kalimba4-csr-unknown");
+    return true;
+  }
+  if (idx == 2) {
+    arch = ArchSpec("kalimba5-csr-unknown");
+    return true;
+  }
+  return false;
 }
 
-bool
-PlatformKalimba::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
-{
-    if (idx == 0)
-    {
-        arch = ArchSpec("kalimba3-csr-unknown");
-        return true;
-    }
-    if (idx == 1)
-    {
-        arch = ArchSpec("kalimba4-csr-unknown");
-        return true;
-    }
-    if (idx == 2)
-    {
-        arch = ArchSpec("kalimba5-csr-unknown");
-        return true;
-    }
-    return false;
-}
-
-void
-PlatformKalimba::GetStatus (Stream &strm)
-{
-    Platform::GetStatus(strm);
-}
+void PlatformKalimba::GetStatus(Stream &strm) { Platform::GetStatus(strm); }
 
 size_t
-PlatformKalimba::GetSoftwareBreakpointTrapOpcode (Target & /*target*/, 
-                                                BreakpointSite * /*bp_site*/)
-{
-    // the target hardware does not support software breakpoints
-    return 0;
-}
-
-Error
-PlatformKalimba::LaunchProcess (ProcessLaunchInfo &launch_info)
-{
-    Error error;
-    
-    if (IsHost())
-    {
-        error.SetErrorString ("native execution is not possible");
-    }
+PlatformKalimba::GetSoftwareBreakpointTrapOpcode(Target & /*target*/,
+                                                 BreakpointSite * /*bp_site*/) {
+  // the target hardware does not support software breakpoints
+  return 0;
+}
+
+Error PlatformKalimba::LaunchProcess(ProcessLaunchInfo &launch_info) {
+  Error error;
+
+  if (IsHost()) {
+    error.SetErrorString("native execution is not possible");
+  } else {
+    error.SetErrorString("the platform is not currently connected");
+  }
+  return error;
+}
+
+lldb::ProcessSP PlatformKalimba::Attach(ProcessAttachInfo &attach_info,
+                                        Debugger &debugger, Target *target,
+                                        Error &error) {
+  lldb::ProcessSP process_sp;
+  if (IsHost()) {
+    error.SetErrorString("native execution is not possible");
+  } else {
+    if (m_remote_platform_sp)
+      process_sp =
+          m_remote_platform_sp->Attach(attach_info, debugger, target, error);
     else
-    {
-        error.SetErrorString ("the platform is not currently connected");
-    }
-    return error;
+      error.SetErrorString("the platform is not currently connected");
+  }
+  return process_sp;
 }
 
-lldb::ProcessSP
-PlatformKalimba::Attach(ProcessAttachInfo &attach_info,
-                        Debugger &debugger,
-                        Target *target,
-                        Error &error)
-{
-    lldb::ProcessSP process_sp;
-    if (IsHost())
-    {
-        error.SetErrorString ("native execution is not possible");
-    }
-    else
-    {
-        if (m_remote_platform_sp)
-            process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, error);
-        else
-            error.SetErrorString ("the platform is not currently connected");
-    }
-    return process_sp;
+void PlatformKalimba::CalculateTrapHandlerSymbolNames() {
+  // TODO Research this sometime.
 }
-
-void
-PlatformKalimba::CalculateTrapHandlerSymbolNames ()
-{   
-    // TODO Research this sometime.
-}   

Modified: lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.h (original)
+++ lldb/trunk/source/Plugins/Platform/Kalimba/PlatformKalimba.h Tue Sep  6 15:57:50 2016
@@ -18,81 +18,70 @@
 
 namespace lldb_private {
 
-    class PlatformKalimba : public Platform
-    {
-    public:
-        PlatformKalimba(bool is_host);
+class PlatformKalimba : public Platform {
+public:
+  PlatformKalimba(bool is_host);
 
-        ~PlatformKalimba() override;
+  ~PlatformKalimba() override;
 
-        static void
-        Initialize ();
+  static void Initialize();
 
-        static void
-        Terminate ();
-        
-        //------------------------------------------------------------
-        // lldb_private::PluginInterface functions
-        //------------------------------------------------------------
-        static lldb::PlatformSP
-        CreateInstance (bool force, const lldb_private::ArchSpec *arch);
+  static void Terminate();
 
-        static lldb_private::ConstString
-        GetPluginNameStatic (bool is_host);
+  //------------------------------------------------------------
+  // lldb_private::PluginInterface functions
+  //------------------------------------------------------------
+  static lldb::PlatformSP CreateInstance(bool force,
+                                         const lldb_private::ArchSpec *arch);
 
-        static const char *
-        GetPluginDescriptionStatic (bool is_host);
+  static lldb_private::ConstString GetPluginNameStatic(bool is_host);
 
-        lldb_private::ConstString GetPluginName() override;
+  static const char *GetPluginDescriptionStatic(bool is_host);
 
-        uint32_t
-        GetPluginVersion() override
-        {
-            return 1;
-        }
+  lldb_private::ConstString GetPluginName() override;
 
-        //------------------------------------------------------------
-        // lldb_private::Platform functions
-        //------------------------------------------------------------
-        Error ResolveExecutable(const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
-                                const FileSpecList *module_search_paths_ptr) override;
+  uint32_t GetPluginVersion() override { return 1; }
 
-        const char *
-        GetDescription() override
-        {
-            return GetPluginDescriptionStatic(IsHost());
-        }
+  //------------------------------------------------------------
+  // lldb_private::Platform functions
+  //------------------------------------------------------------
+  Error ResolveExecutable(const lldb_private::ModuleSpec &module_spec,
+                          lldb::ModuleSP &module_sp,
+                          const FileSpecList *module_search_paths_ptr) override;
 
-        void GetStatus(Stream &strm) override;
+  const char *GetDescription() override {
+    return GetPluginDescriptionStatic(IsHost());
+  }
 
-        Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, FileSpec &local_file) override;
+  void GetStatus(Stream &strm) override;
 
-        bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
+  Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
+                        FileSpec &local_file) override;
 
-        bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
+  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
 
-        size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override;
+  bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
 
-        lldb_private::Error LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
+  size_t GetSoftwareBreakpointTrapOpcode(Target &target,
+                                         BreakpointSite *bp_site) override;
 
-        lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target,
-                               Error &error) override;
+  lldb_private::Error
+  LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
 
-        // Kalimba processes can not be launched by spawning and attaching.
-        bool
-        CanDebugProcess() override
-        {
-            return false;
-        }
+  lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
+                         Target *target, Error &error) override;
 
-        void CalculateTrapHandlerSymbolNames() override;
+  // Kalimba processes can not be launched by spawning and attaching.
+  bool CanDebugProcess() override { return false; }
 
-    protected:
-        lldb::PlatformSP m_remote_platform_sp;
+  void CalculateTrapHandlerSymbolNames() override;
 
-    private:
-        DISALLOW_COPY_AND_ASSIGN (PlatformKalimba);
-    };
+protected:
+  lldb::PlatformSP m_remote_platform_sp;
+
+private:
+  DISALLOW_COPY_AND_ASSIGN(PlatformKalimba);
+};
 
 } // namespace lldb_private
 




More information about the lldb-commits mailing list