[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/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Tue Sep  6 15:57:50 2016
@@ -20,21 +20,21 @@
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
-#include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/ABI.h"
+#include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadPlanRunToAddress.h"
-#include "lldb/Target/StackFrame.h"
 
-#include "DynamicLoaderMacOSXDYLD.h"
 #include "DynamicLoaderDarwin.h"
+#include "DynamicLoaderMacOSXDYLD.h"
 
 //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
 #ifdef ENABLE_DEBUG_PRINTF
 #include <stdio.h>
-#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
+#define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
 #else
 #define DEBUG_PRINTF(fmt, ...)
 #endif
@@ -48,169 +48,140 @@
 using namespace lldb;
 using namespace lldb_private;
 
-
 //----------------------------------------------------------------------
 // Create an instance of this class. This function is filled into
 // the plugin info class that gets handed out by the plugin factory and
 // allows the lldb to instantiate an instance of this class.
 //----------------------------------------------------------------------
-DynamicLoader *
-DynamicLoaderMacOSXDYLD::CreateInstance (Process* process, bool force)
-{
-    bool create = force;
-    if (!create)
-    {
-        create = true;
-        Module* exe_module = process->GetTarget().GetExecutableModulePointer();
-        if (exe_module)
-        {
-            ObjectFile *object_file = exe_module->GetObjectFile();
-            if (object_file)
-            {
-                create = (object_file->GetStrata() == ObjectFile::eStrataUser);
-            }
-        }
-        
-        if (create)
-        {
-            const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
-            switch (triple_ref.getOS())
-            {
-                case llvm::Triple::Darwin:
-                case llvm::Triple::MacOSX:
-                case llvm::Triple::IOS:
-                case llvm::Triple::TvOS:
-                case llvm::Triple::WatchOS:
-                    create = triple_ref.getVendor() == llvm::Triple::Apple;
-                    break;
-                default:
-                    create = false;
-                    break;
-            }
-        }
-    }
-
-    if (UseDYLDSPI (process) == true)
-    {
+DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process,
+                                                       bool force) {
+  bool create = force;
+  if (!create) {
+    create = true;
+    Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+    if (exe_module) {
+      ObjectFile *object_file = exe_module->GetObjectFile();
+      if (object_file) {
+        create = (object_file->GetStrata() == ObjectFile::eStrataUser);
+      }
+    }
+
+    if (create) {
+      const llvm::Triple &triple_ref =
+          process->GetTarget().GetArchitecture().GetTriple();
+      switch (triple_ref.getOS()) {
+      case llvm::Triple::Darwin:
+      case llvm::Triple::MacOSX:
+      case llvm::Triple::IOS:
+      case llvm::Triple::TvOS:
+      case llvm::Triple::WatchOS:
+        create = triple_ref.getVendor() == llvm::Triple::Apple;
+        break;
+      default:
         create = false;
+        break;
+      }
     }
-    
-    if (create)
-        return new DynamicLoaderMacOSXDYLD (process);
-    return NULL;
+  }
+
+  if (UseDYLDSPI(process) == true) {
+    create = false;
+  }
+
+  if (create)
+    return new DynamicLoaderMacOSXDYLD(process);
+  return NULL;
 }
 
 //----------------------------------------------------------------------
 // Constructor
 //----------------------------------------------------------------------
-DynamicLoaderMacOSXDYLD::DynamicLoaderMacOSXDYLD (Process* process) :
-    DynamicLoaderDarwin(process),
-    m_dyld_all_image_infos_addr(LLDB_INVALID_ADDRESS),
-    m_dyld_all_image_infos(),
-    m_dyld_all_image_infos_stop_id (UINT32_MAX),
-    m_break_id(LLDB_INVALID_BREAK_ID),
-    m_mutex(),
-    m_process_image_addr_is_all_images_infos (false)
-{
-}
+DynamicLoaderMacOSXDYLD::DynamicLoaderMacOSXDYLD(Process *process)
+    : DynamicLoaderDarwin(process),
+      m_dyld_all_image_infos_addr(LLDB_INVALID_ADDRESS),
+      m_dyld_all_image_infos(), m_dyld_all_image_infos_stop_id(UINT32_MAX),
+      m_break_id(LLDB_INVALID_BREAK_ID), m_mutex(),
+      m_process_image_addr_is_all_images_infos(false) {}
 
 //----------------------------------------------------------------------
 // Destructor
 //----------------------------------------------------------------------
-DynamicLoaderMacOSXDYLD::~DynamicLoaderMacOSXDYLD()
-{
-    if (LLDB_BREAK_ID_IS_VALID(m_break_id))
-        m_process->GetTarget().RemoveBreakpointByID (m_break_id);
-}
-
-bool
-DynamicLoaderMacOSXDYLD::ProcessDidExec ()
-{
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    bool did_exec = false;
-    if (m_process)
-    {
-        // If we are stopped after an exec, we will have only one thread...
-        if (m_process->GetThreadList().GetSize() == 1)
-        {
-            // We know if a process has exec'ed if our "m_dyld_all_image_infos_addr"
-            // value differs from the Process' image info address. When a process
-            // execs itself it might cause a change if ASLR is enabled.
-            const addr_t shlib_addr = m_process->GetImageInfoAddress ();
-            if (m_process_image_addr_is_all_images_infos == true && shlib_addr != m_dyld_all_image_infos_addr)
-            {
-                // The image info address from the process is the 'dyld_all_image_infos'
-                // address and it has changed.
+DynamicLoaderMacOSXDYLD::~DynamicLoaderMacOSXDYLD() {
+  if (LLDB_BREAK_ID_IS_VALID(m_break_id))
+    m_process->GetTarget().RemoveBreakpointByID(m_break_id);
+}
+
+bool DynamicLoaderMacOSXDYLD::ProcessDidExec() {
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  bool did_exec = false;
+  if (m_process) {
+    // If we are stopped after an exec, we will have only one thread...
+    if (m_process->GetThreadList().GetSize() == 1) {
+      // We know if a process has exec'ed if our "m_dyld_all_image_infos_addr"
+      // value differs from the Process' image info address. When a process
+      // execs itself it might cause a change if ASLR is enabled.
+      const addr_t shlib_addr = m_process->GetImageInfoAddress();
+      if (m_process_image_addr_is_all_images_infos == true &&
+          shlib_addr != m_dyld_all_image_infos_addr) {
+        // The image info address from the process is the 'dyld_all_image_infos'
+        // address and it has changed.
+        did_exec = true;
+      } else if (m_process_image_addr_is_all_images_infos == false &&
+                 shlib_addr == m_dyld.address) {
+        // The image info address from the process is the mach_header
+        // address for dyld and it has changed.
+        did_exec = true;
+      } else {
+        // ASLR might be disabled and dyld could have ended up in the same
+        // location. We should try and detect if we are stopped at '_dyld_start'
+        ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
+        if (thread_sp) {
+          lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
+          if (frame_sp) {
+            const Symbol *symbol =
+                frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
+            if (symbol) {
+              if (symbol->GetName() == ConstString("_dyld_start"))
                 did_exec = true;
             }
-            else if (m_process_image_addr_is_all_images_infos == false && shlib_addr == m_dyld.address)
-            {
-                // The image info address from the process is the mach_header
-                // address for dyld and it has changed.
-                did_exec = true;
-            }
-            else
-            {
-                // ASLR might be disabled and dyld could have ended up in the same
-                // location. We should try and detect if we are stopped at '_dyld_start'
-                ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
-                if (thread_sp)
-                {
-                    lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
-                    if (frame_sp)
-                    {
-                        const Symbol *symbol = frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
-                        if (symbol)
-                        {
-                            if (symbol->GetName() == ConstString("_dyld_start"))
-                                did_exec = true;
-                        }
-                    }
-                }
-            }
-
-            if (did_exec)
-            {
-                m_libpthread_module_wp.reset();
-                m_pthread_getspecific_addr.Clear();
-            }
+          }
         }
+      }
+
+      if (did_exec) {
+        m_libpthread_module_wp.reset();
+        m_pthread_getspecific_addr.Clear();
+      }
     }
-    return did_exec;
+  }
+  return did_exec;
 }
 
 //----------------------------------------------------------------------
 // Clear out the state of this class.
 //----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXDYLD::DoClear ()
-{
-    std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
-    if (LLDB_BREAK_ID_IS_VALID(m_break_id))
-        m_process->GetTarget().RemoveBreakpointByID (m_break_id);
-
-    m_dyld_all_image_infos_addr = LLDB_INVALID_ADDRESS;
-    m_dyld_all_image_infos.Clear();
-    m_break_id = LLDB_INVALID_BREAK_ID;
+void DynamicLoaderMacOSXDYLD::DoClear() {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+
+  if (LLDB_BREAK_ID_IS_VALID(m_break_id))
+    m_process->GetTarget().RemoveBreakpointByID(m_break_id);
+
+  m_dyld_all_image_infos_addr = LLDB_INVALID_ADDRESS;
+  m_dyld_all_image_infos.Clear();
+  m_break_id = LLDB_INVALID_BREAK_ID;
 }
 
 //----------------------------------------------------------------------
 // Check if we have found DYLD yet
 //----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXDYLD::DidSetNotificationBreakpoint()
-{
-    return LLDB_BREAK_ID_IS_VALID (m_break_id);
+bool DynamicLoaderMacOSXDYLD::DidSetNotificationBreakpoint() {
+  return LLDB_BREAK_ID_IS_VALID(m_break_id);
 }
 
-void
-DynamicLoaderMacOSXDYLD::ClearNotificationBreakpoint ()
-{
-    if (LLDB_BREAK_ID_IS_VALID (m_break_id))
-    {
-        m_process->GetTarget().RemoveBreakpointByID (m_break_id);
-    }
+void DynamicLoaderMacOSXDYLD::ClearNotificationBreakpoint() {
+  if (LLDB_BREAK_ID_IS_VALID(m_break_id)) {
+    m_process->GetTarget().RemoveBreakpointByID(m_break_id);
+  }
 }
 
 //----------------------------------------------------------------------
@@ -219,143 +190,127 @@ DynamicLoaderMacOSXDYLD::ClearNotificati
 // to get the DYLD info (available on SnowLeopard only). If that fails,
 // then check in the default addresses.
 //----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXDYLD::DoInitialImageFetch()
-{
-    if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS)
-    {
-        // Check the image info addr as it might point to the 
-        // mach header for dyld, or it might point to the 
-        // dyld_all_image_infos struct
-        const addr_t shlib_addr = m_process->GetImageInfoAddress ();
-        if (shlib_addr != LLDB_INVALID_ADDRESS)
-        {
-            ByteOrder byte_order = m_process->GetTarget().GetArchitecture().GetByteOrder();
-            uint8_t buf[4];
-            DataExtractor data (buf, sizeof(buf), byte_order, 4);
-            Error error;
-            if (m_process->ReadMemory (shlib_addr, buf, 4, error) == 4)
-            {
-                lldb::offset_t offset = 0;
-                uint32_t magic = data.GetU32 (&offset);
-                switch (magic)
-                {
-                case llvm::MachO::MH_MAGIC:
-                case llvm::MachO::MH_MAGIC_64:
-                case llvm::MachO::MH_CIGAM:
-                case llvm::MachO::MH_CIGAM_64:
-                    m_process_image_addr_is_all_images_infos = false;
-                    ReadDYLDInfoFromMemoryAndSetNotificationCallback(shlib_addr);
-                    return;
-                    
-                default:
-                    break;
-                }
-            }
-            // Maybe it points to the all image infos?
-            m_dyld_all_image_infos_addr = shlib_addr;
-            m_process_image_addr_is_all_images_infos = true;
-        }
-    }
-
-    if (m_dyld_all_image_infos_addr != LLDB_INVALID_ADDRESS)
-    {
-        if (ReadAllImageInfosStructure ())
-        {
-            if (m_dyld_all_image_infos.dyldImageLoadAddress != LLDB_INVALID_ADDRESS)
-                ReadDYLDInfoFromMemoryAndSetNotificationCallback (m_dyld_all_image_infos.dyldImageLoadAddress);
-            else
-                ReadDYLDInfoFromMemoryAndSetNotificationCallback (m_dyld_all_image_infos_addr & 0xfffffffffff00000ull);
-            return;
-        }
-    }
-
-    // Check some default values
-    Module *executable = m_process->GetTarget().GetExecutableModulePointer();
+void DynamicLoaderMacOSXDYLD::DoInitialImageFetch() {
+  if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS) {
+    // Check the image info addr as it might point to the
+    // mach header for dyld, or it might point to the
+    // dyld_all_image_infos struct
+    const addr_t shlib_addr = m_process->GetImageInfoAddress();
+    if (shlib_addr != LLDB_INVALID_ADDRESS) {
+      ByteOrder byte_order =
+          m_process->GetTarget().GetArchitecture().GetByteOrder();
+      uint8_t buf[4];
+      DataExtractor data(buf, sizeof(buf), byte_order, 4);
+      Error error;
+      if (m_process->ReadMemory(shlib_addr, buf, 4, error) == 4) {
+        lldb::offset_t offset = 0;
+        uint32_t magic = data.GetU32(&offset);
+        switch (magic) {
+        case llvm::MachO::MH_MAGIC:
+        case llvm::MachO::MH_MAGIC_64:
+        case llvm::MachO::MH_CIGAM:
+        case llvm::MachO::MH_CIGAM_64:
+          m_process_image_addr_is_all_images_infos = false;
+          ReadDYLDInfoFromMemoryAndSetNotificationCallback(shlib_addr);
+          return;
 
-    if (executable)
-    {
-        const ArchSpec &exe_arch = executable->GetArchitecture();
-        if (exe_arch.GetAddressByteSize() == 8)
-        {
-            ReadDYLDInfoFromMemoryAndSetNotificationCallback(0x7fff5fc00000ull);
-        }
-        else if (exe_arch.GetMachine() == llvm::Triple::arm || exe_arch.GetMachine() == llvm::Triple::thumb || exe_arch.GetMachine() == llvm::Triple::aarch64)
-        {
-            ReadDYLDInfoFromMemoryAndSetNotificationCallback(0x2fe00000);
-        }
-        else
-        {
-            ReadDYLDInfoFromMemoryAndSetNotificationCallback(0x8fe00000);
+        default:
+          break;
         }
+      }
+      // Maybe it points to the all image infos?
+      m_dyld_all_image_infos_addr = shlib_addr;
+      m_process_image_addr_is_all_images_infos = true;
+    }
+  }
+
+  if (m_dyld_all_image_infos_addr != LLDB_INVALID_ADDRESS) {
+    if (ReadAllImageInfosStructure()) {
+      if (m_dyld_all_image_infos.dyldImageLoadAddress != LLDB_INVALID_ADDRESS)
+        ReadDYLDInfoFromMemoryAndSetNotificationCallback(
+            m_dyld_all_image_infos.dyldImageLoadAddress);
+      else
+        ReadDYLDInfoFromMemoryAndSetNotificationCallback(
+            m_dyld_all_image_infos_addr & 0xfffffffffff00000ull);
+      return;
+    }
+  }
+
+  // Check some default values
+  Module *executable = m_process->GetTarget().GetExecutableModulePointer();
+
+  if (executable) {
+    const ArchSpec &exe_arch = executable->GetArchitecture();
+    if (exe_arch.GetAddressByteSize() == 8) {
+      ReadDYLDInfoFromMemoryAndSetNotificationCallback(0x7fff5fc00000ull);
+    } else if (exe_arch.GetMachine() == llvm::Triple::arm ||
+               exe_arch.GetMachine() == llvm::Triple::thumb ||
+               exe_arch.GetMachine() == llvm::Triple::aarch64) {
+      ReadDYLDInfoFromMemoryAndSetNotificationCallback(0x2fe00000);
+    } else {
+      ReadDYLDInfoFromMemoryAndSetNotificationCallback(0x8fe00000);
     }
-    return;
+  }
+  return;
 }
 
 //----------------------------------------------------------------------
 // Assume that dyld is in memory at ADDR and try to parse it's load
 // commands
 //----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb::addr_t addr)
-{
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    DataExtractor data; // Load command data
-    static ConstString g_dyld_all_image_infos ("dyld_all_image_infos");
-    if (ReadMachHeader (addr, &m_dyld.header, &data))
-    {
-        if (m_dyld.header.filetype == llvm::MachO::MH_DYLINKER)
-        {
-            m_dyld.address = addr;
-            ModuleSP dyld_module_sp;
-            if (ParseLoadCommands (data, m_dyld, &m_dyld.file_spec))
-            {
-                if (m_dyld.file_spec)
-                {
-                    UpdateDYLDImageInfoFromNewImageInfo (m_dyld);
-
-                }
-            }
-            dyld_module_sp = GetDYLDModule();
-
-            Target &target = m_process->GetTarget();
-
-            if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS && dyld_module_sp.get())
-            {
-                const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType (g_dyld_all_image_infos, eSymbolTypeData);
-                if (symbol)
-                    m_dyld_all_image_infos_addr = symbol->GetLoadAddress(&target);
-            }
-
-            // Update all image infos
-            InitializeFromAllImageInfos ();
+bool DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(
+    lldb::addr_t addr) {
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  DataExtractor data; // Load command data
+  static ConstString g_dyld_all_image_infos("dyld_all_image_infos");
+  if (ReadMachHeader(addr, &m_dyld.header, &data)) {
+    if (m_dyld.header.filetype == llvm::MachO::MH_DYLINKER) {
+      m_dyld.address = addr;
+      ModuleSP dyld_module_sp;
+      if (ParseLoadCommands(data, m_dyld, &m_dyld.file_spec)) {
+        if (m_dyld.file_spec) {
+          UpdateDYLDImageInfoFromNewImageInfo(m_dyld);
+        }
+      }
+      dyld_module_sp = GetDYLDModule();
+
+      Target &target = m_process->GetTarget();
+
+      if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS &&
+          dyld_module_sp.get()) {
+        const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType(
+            g_dyld_all_image_infos, eSymbolTypeData);
+        if (symbol)
+          m_dyld_all_image_infos_addr = symbol->GetLoadAddress(&target);
+      }
+
+      // Update all image infos
+      InitializeFromAllImageInfos();
+
+      // If we didn't have an executable before, but now we do, then the
+      // dyld module shared pointer might be unique and we may need to add
+      // it again (since Target::SetExecutableModule() will clear the
+      // images). So append the dyld module back to the list if it is
+      /// unique!
+      if (dyld_module_sp) {
+        target.GetImages().AppendIfNeeded(dyld_module_sp);
+
+        // At this point we should have read in dyld's module, and so we should
+        // set breakpoints in it:
+        ModuleList modules;
+        modules.Append(dyld_module_sp);
+        target.ModulesDidLoad(modules);
+        SetDYLDModule(dyld_module_sp);
+      }
 
-            // If we didn't have an executable before, but now we do, then the
-            // dyld module shared pointer might be unique and we may need to add
-            // it again (since Target::SetExecutableModule() will clear the
-            // images). So append the dyld module back to the list if it is
-            /// unique!
-            if (dyld_module_sp)
-            {
-                target.GetImages().AppendIfNeeded (dyld_module_sp);
-
-                // At this point we should have read in dyld's module, and so we should set breakpoints in it:
-                ModuleList modules;
-                modules.Append(dyld_module_sp);
-                target.ModulesDidLoad(modules);
-                SetDYLDModule (dyld_module_sp);
-            }
-
-            return true;
-        }
+      return true;
     }
-    return false;
+  }
+  return false;
 }
 
-bool
-DynamicLoaderMacOSXDYLD::NeedToDoInitialImageFetch ()
-{
-    return m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS;
+bool DynamicLoaderMacOSXDYLD::NeedToDoInitialImageFetch() {
+  return m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS;
 }
 
 //----------------------------------------------------------------------
@@ -364,392 +319,398 @@ DynamicLoaderMacOSXDYLD::NeedToDoInitial
 // let our super class DynamicLoader class decide if we should stop
 // or not (based on global preference).
 //----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXDYLD::NotifyBreakpointHit (void *baton, 
-                                              StoppointCallbackContext *context, 
-                                              lldb::user_id_t break_id, 
-                                              lldb::user_id_t break_loc_id)
-{
-    // Let the event know that the images have changed
-    // DYLD passes three arguments to the notification breakpoint.
-    // Arg1: enum dyld_image_mode mode - 0 = adding, 1 = removing 
-    // Arg2: uint32_t infoCount        - Number of shared libraries added  
-    // Arg3: dyld_image_info info[]    - Array of structs of the form:
-    //                                     const struct mach_header *imageLoadAddress
-    //                                     const char               *imageFilePath
-    //                                     uintptr_t                 imageFileModDate (a time_t)
-    
-    DynamicLoaderMacOSXDYLD* dyld_instance = (DynamicLoaderMacOSXDYLD*) baton;
-    
-    // First step is to see if we've already initialized the all image infos.  If we haven't then this function
-    // will do so and return true.  In the course of initializing the all_image_infos it will read the complete
-    // current state, so we don't need to figure out what has changed from the data passed in to us.
-    
-    ExecutionContext exe_ctx (context->exe_ctx_ref);
-    Process *process = exe_ctx.GetProcessPtr();
-
-    // This is a sanity check just in case this dyld_instance is an old dyld plugin's breakpoint still lying around.
-    if (process != dyld_instance->m_process)
-        return false;
-
-    if (dyld_instance->InitializeFromAllImageInfos())
-        return dyld_instance->GetStopWhenImagesChange(); 
-
-    const lldb::ABISP &abi = process->GetABI();
-    if (abi)
-    {
-        // Build up the value array to store the three arguments given above, then get the values from the ABI:
-        
-        ClangASTContext *clang_ast_context = process->GetTarget().GetScratchClangASTContext();
-        ValueList argument_values;
-        Value input_value;
-        
-        CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
-        CompilerType clang_uint32_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint, 32);
-        input_value.SetValueType (Value::eValueTypeScalar);
-        input_value.SetCompilerType (clang_uint32_type);
-//        input_value.SetContext (Value::eContextTypeClangType, clang_uint32_type);
-        argument_values.PushValue (input_value);
-        argument_values.PushValue (input_value);
-        input_value.SetCompilerType (clang_void_ptr_type);
-        //        input_value.SetContext (Value::eContextTypeClangType, clang_void_ptr_type);
-        argument_values.PushValue (input_value);
-        
-        if (abi->GetArgumentValues (exe_ctx.GetThreadRef(), argument_values))
-        {
-            uint32_t dyld_mode = argument_values.GetValueAtIndex(0)->GetScalar().UInt (-1);
-            if (dyld_mode != static_cast<uint32_t>(-1))
-            {
-                // Okay the mode was right, now get the number of elements, and the array of new elements...
-                uint32_t image_infos_count = argument_values.GetValueAtIndex(1)->GetScalar().UInt (-1);
-                if (image_infos_count != static_cast<uint32_t>(-1))
-                {
-                    // Got the number added, now go through the array of added elements, putting out the mach header 
-                    // address, and adding the image.
-                    // Note, I'm not putting in logging here, since the AddModules & RemoveModules functions do
-                    // all the logging internally.
-                    
-                    lldb::addr_t image_infos_addr = argument_values.GetValueAtIndex(2)->GetScalar().ULongLong();
-                    if (dyld_mode == 0)
-                    {
-                        // This is add:
-                        dyld_instance->AddModulesUsingImageInfosAddress (image_infos_addr, image_infos_count);
-                    }
-                    else
-                    {
-                        // This is remove:
-                        dyld_instance->RemoveModulesUsingImageInfosAddress (image_infos_addr, image_infos_count);
-                    }
-                    
-                }
-            }
-        }
-    }
-    else
-    {
-        process->GetTarget().GetDebugger().GetAsyncErrorStream()->Printf("No ABI plugin located for triple %s -- shared libraries will not be registered!\n", process->GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
-    }
-    
-    // Return true to stop the target, false to just let the target run
+bool DynamicLoaderMacOSXDYLD::NotifyBreakpointHit(
+    void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
+    lldb::user_id_t break_loc_id) {
+  // Let the event know that the images have changed
+  // DYLD passes three arguments to the notification breakpoint.
+  // Arg1: enum dyld_image_mode mode - 0 = adding, 1 = removing
+  // Arg2: uint32_t infoCount        - Number of shared libraries added
+  // Arg3: dyld_image_info info[]    - Array of structs of the form:
+  //                                     const struct mach_header
+  //                                     *imageLoadAddress
+  //                                     const char               *imageFilePath
+  //                                     uintptr_t imageFileModDate (a time_t)
+
+  DynamicLoaderMacOSXDYLD *dyld_instance = (DynamicLoaderMacOSXDYLD *)baton;
+
+  // First step is to see if we've already initialized the all image infos.  If
+  // we haven't then this function
+  // will do so and return true.  In the course of initializing the
+  // all_image_infos it will read the complete
+  // current state, so we don't need to figure out what has changed from the
+  // data passed in to us.
+
+  ExecutionContext exe_ctx(context->exe_ctx_ref);
+  Process *process = exe_ctx.GetProcessPtr();
+
+  // This is a sanity check just in case this dyld_instance is an old dyld
+  // plugin's breakpoint still lying around.
+  if (process != dyld_instance->m_process)
+    return false;
+
+  if (dyld_instance->InitializeFromAllImageInfos())
     return dyld_instance->GetStopWhenImagesChange();
+
+  const lldb::ABISP &abi = process->GetABI();
+  if (abi) {
+    // Build up the value array to store the three arguments given above, then
+    // get the values from the ABI:
+
+    ClangASTContext *clang_ast_context =
+        process->GetTarget().GetScratchClangASTContext();
+    ValueList argument_values;
+    Value input_value;
+
+    CompilerType clang_void_ptr_type =
+        clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
+    CompilerType clang_uint32_type =
+        clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
+            lldb::eEncodingUint, 32);
+    input_value.SetValueType(Value::eValueTypeScalar);
+    input_value.SetCompilerType(clang_uint32_type);
+    //        input_value.SetContext (Value::eContextTypeClangType,
+    //        clang_uint32_type);
+    argument_values.PushValue(input_value);
+    argument_values.PushValue(input_value);
+    input_value.SetCompilerType(clang_void_ptr_type);
+    //        input_value.SetContext (Value::eContextTypeClangType,
+    //        clang_void_ptr_type);
+    argument_values.PushValue(input_value);
+
+    if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
+      uint32_t dyld_mode =
+          argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
+      if (dyld_mode != static_cast<uint32_t>(-1)) {
+        // Okay the mode was right, now get the number of elements, and the
+        // array of new elements...
+        uint32_t image_infos_count =
+            argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
+        if (image_infos_count != static_cast<uint32_t>(-1)) {
+          // Got the number added, now go through the array of added elements,
+          // putting out the mach header
+          // address, and adding the image.
+          // Note, I'm not putting in logging here, since the AddModules &
+          // RemoveModules functions do
+          // all the logging internally.
+
+          lldb::addr_t image_infos_addr =
+              argument_values.GetValueAtIndex(2)->GetScalar().ULongLong();
+          if (dyld_mode == 0) {
+            // This is add:
+            dyld_instance->AddModulesUsingImageInfosAddress(image_infos_addr,
+                                                            image_infos_count);
+          } else {
+            // This is remove:
+            dyld_instance->RemoveModulesUsingImageInfosAddress(
+                image_infos_addr, image_infos_count);
+          }
+        }
+      }
+    }
+  } else {
+    process->GetTarget().GetDebugger().GetAsyncErrorStream()->Printf(
+        "No ABI plugin located for triple %s -- shared libraries will not be "
+        "registered!\n",
+        process->GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
+  }
+
+  // Return true to stop the target, false to just let the target run
+  return dyld_instance->GetStopWhenImagesChange();
 }
 
-bool
-DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure ()
-{
-    std::lock_guard<std::recursive_mutex> guard(m_mutex);
+bool DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure() {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
 
-    // the all image infos is already valid for this process stop ID
-    if (m_process->GetStopID() == m_dyld_all_image_infos_stop_id)
-        return true;
+  // the all image infos is already valid for this process stop ID
+  if (m_process->GetStopID() == m_dyld_all_image_infos_stop_id)
+    return true;
 
-    m_dyld_all_image_infos.Clear();
-    if (m_dyld_all_image_infos_addr != LLDB_INVALID_ADDRESS)
-    {
-        ByteOrder byte_order = m_process->GetTarget().GetArchitecture().GetByteOrder();
-        uint32_t addr_size = 4;
-        if (m_dyld_all_image_infos_addr > UINT32_MAX)
-            addr_size = 8;
+  m_dyld_all_image_infos.Clear();
+  if (m_dyld_all_image_infos_addr != LLDB_INVALID_ADDRESS) {
+    ByteOrder byte_order =
+        m_process->GetTarget().GetArchitecture().GetByteOrder();
+    uint32_t addr_size = 4;
+    if (m_dyld_all_image_infos_addr > UINT32_MAX)
+      addr_size = 8;
 
-        uint8_t buf[256];
-        DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
-        lldb::offset_t offset = 0;
+    uint8_t buf[256];
+    DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
+    lldb::offset_t offset = 0;
 
-        const size_t count_v2 =  sizeof (uint32_t) + // version
-                                 sizeof (uint32_t) + // infoArrayCount
-                                 addr_size +         // infoArray
-                                 addr_size +         // notification
-                                 addr_size +         // processDetachedFromSharedRegion + libSystemInitialized + pad
-                                 addr_size;          // dyldImageLoadAddress
-        const size_t count_v11 = count_v2 +
-                                 addr_size +         // jitInfo
-                                 addr_size +         // dyldVersion
-                                 addr_size +         // errorMessage
-                                 addr_size +         // terminationFlags
-                                 addr_size +         // coreSymbolicationShmPage
-                                 addr_size +         // systemOrderFlag
-                                 addr_size +         // uuidArrayCount
-                                 addr_size +         // uuidArray
-                                 addr_size +         // dyldAllImageInfosAddress
-                                 addr_size +         // initialImageCount
-                                 addr_size +         // errorKind
-                                 addr_size +         // errorClientOfDylibPath
-                                 addr_size +         // errorTargetDylibPath
-                                 addr_size;          // errorSymbol
-        const size_t count_v13 = count_v11 +
-                                 addr_size +         // sharedCacheSlide
-                                 sizeof (uuid_t);    // sharedCacheUUID
-        UNUSED_IF_ASSERT_DISABLED(count_v13);
-        assert (sizeof (buf) >= count_v13);
-
-        Error error;
-        if (m_process->ReadMemory (m_dyld_all_image_infos_addr, buf, 4, error) == 4)
-        {
-            m_dyld_all_image_infos.version = data.GetU32(&offset);
-            // If anything in the high byte is set, we probably got the byte 
-            // order incorrect (the process might not have it set correctly 
-            // yet due to attaching to a program without a specified file).
-            if (m_dyld_all_image_infos.version & 0xff000000)
-            {
-                // We have guessed the wrong byte order. Swap it and try
-                // reading the version again.
-                if (byte_order == eByteOrderLittle)
-                    byte_order = eByteOrderBig;
-                else
-                    byte_order = eByteOrderLittle;
-
-                data.SetByteOrder (byte_order);
-                offset = 0;
-                m_dyld_all_image_infos.version = data.GetU32(&offset);
-            }
-        }
+    const size_t count_v2 = sizeof(uint32_t) + // version
+                            sizeof(uint32_t) + // infoArrayCount
+                            addr_size +        // infoArray
+                            addr_size +        // notification
+                            addr_size + // processDetachedFromSharedRegion +
+                                        // libSystemInitialized + pad
+                            addr_size;  // dyldImageLoadAddress
+    const size_t count_v11 = count_v2 + addr_size +  // jitInfo
+                             addr_size +             // dyldVersion
+                             addr_size +             // errorMessage
+                             addr_size +             // terminationFlags
+                             addr_size +             // coreSymbolicationShmPage
+                             addr_size +             // systemOrderFlag
+                             addr_size +             // uuidArrayCount
+                             addr_size +             // uuidArray
+                             addr_size +             // dyldAllImageInfosAddress
+                             addr_size +             // initialImageCount
+                             addr_size +             // errorKind
+                             addr_size +             // errorClientOfDylibPath
+                             addr_size +             // errorTargetDylibPath
+                             addr_size;              // errorSymbol
+    const size_t count_v13 = count_v11 + addr_size + // sharedCacheSlide
+                             sizeof(uuid_t);         // sharedCacheUUID
+    UNUSED_IF_ASSERT_DISABLED(count_v13);
+    assert(sizeof(buf) >= count_v13);
+
+    Error error;
+    if (m_process->ReadMemory(m_dyld_all_image_infos_addr, buf, 4, error) ==
+        4) {
+      m_dyld_all_image_infos.version = data.GetU32(&offset);
+      // If anything in the high byte is set, we probably got the byte
+      // order incorrect (the process might not have it set correctly
+      // yet due to attaching to a program without a specified file).
+      if (m_dyld_all_image_infos.version & 0xff000000) {
+        // We have guessed the wrong byte order. Swap it and try
+        // reading the version again.
+        if (byte_order == eByteOrderLittle)
+          byte_order = eByteOrderBig;
         else
-        {
-            return false;
-        }
+          byte_order = eByteOrderLittle;
 
-        const size_t count = (m_dyld_all_image_infos.version >= 11) ? count_v11 : count_v2;
+        data.SetByteOrder(byte_order);
+        offset = 0;
+        m_dyld_all_image_infos.version = data.GetU32(&offset);
+      }
+    } else {
+      return false;
+    }
+
+    const size_t count =
+        (m_dyld_all_image_infos.version >= 11) ? count_v11 : count_v2;
+
+    const size_t bytes_read =
+        m_process->ReadMemory(m_dyld_all_image_infos_addr, buf, count, error);
+    if (bytes_read == count) {
+      offset = 0;
+      m_dyld_all_image_infos.version = data.GetU32(&offset);
+      m_dyld_all_image_infos.dylib_info_count = data.GetU32(&offset);
+      m_dyld_all_image_infos.dylib_info_addr = data.GetPointer(&offset);
+      m_dyld_all_image_infos.notification = data.GetPointer(&offset);
+      m_dyld_all_image_infos.processDetachedFromSharedRegion =
+          data.GetU8(&offset);
+      m_dyld_all_image_infos.libSystemInitialized = data.GetU8(&offset);
+      // Adjust for padding.
+      offset += addr_size - 2;
+      m_dyld_all_image_infos.dyldImageLoadAddress = data.GetPointer(&offset);
+      if (m_dyld_all_image_infos.version >= 11) {
+        offset += addr_size * 8;
+        uint64_t dyld_all_image_infos_addr = data.GetPointer(&offset);
+
+        // When we started, we were given the actual address of the
+        // all_image_infos
+        // struct (probably via TASK_DYLD_INFO) in memory - this address is
+        // stored in
+        // m_dyld_all_image_infos_addr and is the most accurate address we have.
+
+        // We read the dyld_all_image_infos struct from memory; it contains its
+        // own address.
+        // If the address in the struct does not match the actual address,
+        // the dyld we're looking at has been loaded at a different location
+        // (slid) from
+        // where it intended to load.  The addresses in the dyld_all_image_infos
+        // struct
+        // are the original, non-slid addresses, and need to be adjusted.  Most
+        // importantly
+        // the address of dyld and the notification address need to be adjusted.
+
+        if (dyld_all_image_infos_addr != m_dyld_all_image_infos_addr) {
+          uint64_t image_infos_offset =
+              dyld_all_image_infos_addr -
+              m_dyld_all_image_infos.dyldImageLoadAddress;
+          uint64_t notification_offset =
+              m_dyld_all_image_infos.notification -
+              m_dyld_all_image_infos.dyldImageLoadAddress;
+          m_dyld_all_image_infos.dyldImageLoadAddress =
+              m_dyld_all_image_infos_addr - image_infos_offset;
+          m_dyld_all_image_infos.notification =
+              m_dyld_all_image_infos.dyldImageLoadAddress + notification_offset;
+        }
+      }
+      m_dyld_all_image_infos_stop_id = m_process->GetStopID();
+      return true;
+    }
+  }
+  return false;
+}
+
+bool DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfosAddress(
+    lldb::addr_t image_infos_addr, uint32_t image_infos_count) {
+  ImageInfo::collection image_infos;
+  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  if (log)
+    log->Printf("Adding %d modules.\n", image_infos_count);
+
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
+    return true;
 
-        const size_t bytes_read = m_process->ReadMemory (m_dyld_all_image_infos_addr, buf, count, error);
-        if (bytes_read == count)
-        {
-            offset = 0;
-            m_dyld_all_image_infos.version = data.GetU32(&offset);
-            m_dyld_all_image_infos.dylib_info_count = data.GetU32(&offset);
-            m_dyld_all_image_infos.dylib_info_addr = data.GetPointer(&offset);
-            m_dyld_all_image_infos.notification = data.GetPointer(&offset);
-            m_dyld_all_image_infos.processDetachedFromSharedRegion = data.GetU8(&offset);
-            m_dyld_all_image_infos.libSystemInitialized = data.GetU8(&offset);
-            // Adjust for padding.
-            offset += addr_size - 2;
-            m_dyld_all_image_infos.dyldImageLoadAddress = data.GetPointer(&offset);
-            if (m_dyld_all_image_infos.version >= 11)
-            {
-                offset += addr_size * 8;
-                uint64_t dyld_all_image_infos_addr = data.GetPointer(&offset);
-
-                // When we started, we were given the actual address of the all_image_infos
-                // struct (probably via TASK_DYLD_INFO) in memory - this address is stored in
-                // m_dyld_all_image_infos_addr and is the most accurate address we have.
-
-                // We read the dyld_all_image_infos struct from memory; it contains its own address.
-                // If the address in the struct does not match the actual address,
-                // the dyld we're looking at has been loaded at a different location (slid) from
-                // where it intended to load.  The addresses in the dyld_all_image_infos struct
-                // are the original, non-slid addresses, and need to be adjusted.  Most importantly
-                // the address of dyld and the notification address need to be adjusted.
-
-                if (dyld_all_image_infos_addr != m_dyld_all_image_infos_addr)
-                {
-                    uint64_t image_infos_offset = dyld_all_image_infos_addr - m_dyld_all_image_infos.dyldImageLoadAddress;
-                    uint64_t notification_offset = m_dyld_all_image_infos.notification - m_dyld_all_image_infos.dyldImageLoadAddress;
-                    m_dyld_all_image_infos.dyldImageLoadAddress = m_dyld_all_image_infos_addr - image_infos_offset;
-                    m_dyld_all_image_infos.notification = m_dyld_all_image_infos.dyldImageLoadAddress + notification_offset;
-                }
-            }
-            m_dyld_all_image_infos_stop_id = m_process->GetStopID();
-            return true;
-        }
+  StructuredData::ObjectSP image_infos_json_sp =
+      m_process->GetLoadedDynamicLibrariesInfos(image_infos_addr,
+                                                image_infos_count);
+  if (image_infos_json_sp.get() && image_infos_json_sp->GetAsDictionary() &&
+      image_infos_json_sp->GetAsDictionary()->HasKey("images") &&
+      image_infos_json_sp->GetAsDictionary()
+          ->GetValueForKey("images")
+          ->GetAsArray() &&
+      image_infos_json_sp->GetAsDictionary()
+              ->GetValueForKey("images")
+              ->GetAsArray()
+              ->GetSize() == image_infos_count) {
+    bool return_value = false;
+    if (JSONImageInformationIntoImageInfo(image_infos_json_sp, image_infos)) {
+      UpdateSpecialBinariesFromNewImageInfos(image_infos);
+      return_value = AddModulesUsingImageInfos(image_infos);
     }
+    m_dyld_image_infos_stop_id = m_process->GetStopID();
+    return return_value;
+  }
+
+  if (!ReadImageInfos(image_infos_addr, image_infos_count, image_infos))
     return false;
+
+  UpdateImageInfosHeaderAndLoadCommands(image_infos, image_infos_count, false);
+  bool return_value = AddModulesUsingImageInfos(image_infos);
+  m_dyld_image_infos_stop_id = m_process->GetStopID();
+  return return_value;
 }
 
+bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
+    lldb::addr_t image_infos_addr, uint32_t image_infos_count) {
+  ImageInfo::collection image_infos;
+  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
+    return true;
 
-bool
-DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfosAddress (lldb::addr_t image_infos_addr, uint32_t image_infos_count)
-{
-    ImageInfo::collection image_infos;
-    Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
+  // First read in the image_infos for the removed modules, and their headers &
+  // load commands.
+  if (!ReadImageInfos(image_infos_addr, image_infos_count, image_infos)) {
     if (log)
-        log->Printf ("Adding %d modules.\n", image_infos_count);
-        
-    std::lock_guard<std::recursive_mutex> guard(m_mutex);
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
-        return true;
-
-    StructuredData::ObjectSP image_infos_json_sp = m_process->GetLoadedDynamicLibrariesInfos (image_infos_addr, image_infos_count);
-    if (image_infos_json_sp.get() 
-        && image_infos_json_sp->GetAsDictionary() 
-        && image_infos_json_sp->GetAsDictionary()->HasKey("images")
-        && image_infos_json_sp->GetAsDictionary()->GetValueForKey("images")->GetAsArray()
-        && image_infos_json_sp->GetAsDictionary()->GetValueForKey("images")->GetAsArray()->GetSize() == image_infos_count)
-    {
-        bool return_value = false;
-        if (JSONImageInformationIntoImageInfo (image_infos_json_sp, image_infos))
-        {
-            UpdateSpecialBinariesFromNewImageInfos (image_infos);
-            return_value = AddModulesUsingImageInfos (image_infos);
-        }
-        m_dyld_image_infos_stop_id = m_process->GetStopID();
-        return return_value;
-    }
-
-    if (!ReadImageInfos (image_infos_addr, image_infos_count, image_infos))
-        return false;
-        
-    UpdateImageInfosHeaderAndLoadCommands (image_infos, image_infos_count, false);
-    bool return_value = AddModulesUsingImageInfos (image_infos);
-    m_dyld_image_infos_stop_id = m_process->GetStopID();
-    return return_value;
-}
+      log->PutCString("Failed reading image infos array.");
+    return false;
+  }
 
-bool
-DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress (lldb::addr_t image_infos_addr, uint32_t image_infos_count)
-{
-    ImageInfo::collection image_infos;
-    Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
-    
-    std::lock_guard<std::recursive_mutex> guard(m_mutex);
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
-        return true;
+  if (log)
+    log->Printf("Removing %d modules.", image_infos_count);
 
-    // First read in the image_infos for the removed modules, and their headers & load commands.
-    if (!ReadImageInfos (image_infos_addr, image_infos_count, image_infos))
-    {
-        if (log)
-            log->PutCString ("Failed reading image infos array.");
-        return false;
-    }
-    
-    if (log)
-        log->Printf ("Removing %d modules.", image_infos_count);
-    
-    ModuleList unloaded_module_list;
-    for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
-    {        
-        if (log)
-        {
-            log->Printf ("Removing module at address=0x%16.16" PRIx64 ".", image_infos[idx].address);
-            image_infos[idx].PutToLog (log);
-        }
-            
-        // Remove this image_infos from the m_all_image_infos.  We do the comparison by address
-        // rather than by file spec because we can have many modules with the same "file spec" in the
-        // case that they are modules loaded from memory.
-        //
-        // Also copy over the uuid from the old entry to the removed entry so we can 
-        // use it to lookup the module in the module list.
-        
-        ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
-        for (pos = m_dyld_image_infos.begin(); pos != end; pos++)
-        {
-            if (image_infos[idx].address == (*pos).address)
-            {
-                image_infos[idx].uuid = (*pos).uuid;
-
-                // Add the module from this image_info to the "unloaded_module_list".  We'll remove them all at
-                // one go later on.
-                
-                ModuleSP unload_image_module_sp (FindTargetModuleForImageInfo (image_infos[idx], false, NULL));
-                if (unload_image_module_sp.get())
-                {
-                    // When we unload, be sure to use the image info from the old list,
-                    // since that has sections correctly filled in.
-                    UnloadModuleSections (unload_image_module_sp.get(), *pos);
-                    unloaded_module_list.AppendIfNeeded (unload_image_module_sp);
-                }
-                else
-                {
-                    if (log)
-                    {
-                        log->Printf ("Could not find module for unloading info entry:");
-                        image_infos[idx].PutToLog(log);
-                    }
-                }
-                
-                // Then remove it from the m_dyld_image_infos:
-                
-                m_dyld_image_infos.erase(pos);
-                break;
-            }
-        }
-        
-        if (pos == end)
-        {
-            if (log)
-            {
-                log->Printf ("Could not find image_info entry for unloading image:");
-                image_infos[idx].PutToLog(log);
-            }
-        }
+  ModuleList unloaded_module_list;
+  for (uint32_t idx = 0; idx < image_infos.size(); ++idx) {
+    if (log) {
+      log->Printf("Removing module at address=0x%16.16" PRIx64 ".",
+                  image_infos[idx].address);
+      image_infos[idx].PutToLog(log);
+    }
+
+    // Remove this image_infos from the m_all_image_infos.  We do the comparison
+    // by address
+    // rather than by file spec because we can have many modules with the same
+    // "file spec" in the
+    // case that they are modules loaded from memory.
+    //
+    // Also copy over the uuid from the old entry to the removed entry so we can
+    // use it to lookup the module in the module list.
+
+    ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
+    for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
+      if (image_infos[idx].address == (*pos).address) {
+        image_infos[idx].uuid = (*pos).uuid;
+
+        // Add the module from this image_info to the "unloaded_module_list".
+        // We'll remove them all at
+        // one go later on.
+
+        ModuleSP unload_image_module_sp(
+            FindTargetModuleForImageInfo(image_infos[idx], false, NULL));
+        if (unload_image_module_sp.get()) {
+          // When we unload, be sure to use the image info from the old list,
+          // since that has sections correctly filled in.
+          UnloadModuleSections(unload_image_module_sp.get(), *pos);
+          unloaded_module_list.AppendIfNeeded(unload_image_module_sp);
+        } else {
+          if (log) {
+            log->Printf("Could not find module for unloading info entry:");
+            image_infos[idx].PutToLog(log);
+          }
+        }
+
+        // Then remove it from the m_dyld_image_infos:
+
+        m_dyld_image_infos.erase(pos);
+        break;
+      }
+    }
+
+    if (pos == end) {
+      if (log) {
+        log->Printf("Could not find image_info entry for unloading image:");
+        image_infos[idx].PutToLog(log);
+      }
+    }
+  }
+  if (unloaded_module_list.GetSize() > 0) {
+    if (log) {
+      log->PutCString("Unloaded:");
+      unloaded_module_list.LogUUIDAndPaths(
+          log, "DynamicLoaderMacOSXDYLD::ModulesDidUnload");
+    }
+    m_process->GetTarget().GetImages().Remove(unloaded_module_list);
+  }
+  m_dyld_image_infos_stop_id = m_process->GetStopID();
+  return true;
+}
+
+bool DynamicLoaderMacOSXDYLD::ReadImageInfos(
+    lldb::addr_t image_infos_addr, uint32_t image_infos_count,
+    ImageInfo::collection &image_infos) {
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  const ByteOrder endian = GetByteOrderFromMagic(m_dyld.header.magic);
+  const uint32_t addr_size = m_dyld.GetAddressByteSize();
+
+  image_infos.resize(image_infos_count);
+  const size_t count = image_infos.size() * 3 * addr_size;
+  DataBufferHeap info_data(count, 0);
+  Error error;
+  const size_t bytes_read = m_process->ReadMemory(
+      image_infos_addr, info_data.GetBytes(), info_data.GetByteSize(), error);
+  if (bytes_read == count) {
+    lldb::offset_t info_data_offset = 0;
+    DataExtractor info_data_ref(info_data.GetBytes(), info_data.GetByteSize(),
+                                endian, addr_size);
+    for (size_t i = 0;
+         i < image_infos.size() && info_data_ref.ValidOffset(info_data_offset);
+         i++) {
+      image_infos[i].address = info_data_ref.GetPointer(&info_data_offset);
+      lldb::addr_t path_addr = info_data_ref.GetPointer(&info_data_offset);
+      image_infos[i].mod_date = info_data_ref.GetPointer(&info_data_offset);
+
+      char raw_path[PATH_MAX];
+      m_process->ReadCStringFromMemory(path_addr, raw_path, sizeof(raw_path),
+                                       error);
+      // don't resolve the path
+      if (error.Success()) {
+        const bool resolve_path = false;
+        image_infos[i].file_spec.SetFile(raw_path, resolve_path);
+      }
     }
-    if (unloaded_module_list.GetSize() > 0)
-    {
-        if (log)
-        {
-            log->PutCString("Unloaded:");
-            unloaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderMacOSXDYLD::ModulesDidUnload");
-        }
-        m_process->GetTarget().GetImages().Remove (unloaded_module_list);
-    }
-    m_dyld_image_infos_stop_id = m_process->GetStopID();
     return true;
-}
-
-bool
-DynamicLoaderMacOSXDYLD::ReadImageInfos (lldb::addr_t image_infos_addr, 
-                                         uint32_t image_infos_count, 
-                                         ImageInfo::collection &image_infos)
-{
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    const ByteOrder endian = GetByteOrderFromMagic (m_dyld.header.magic);
-    const uint32_t addr_size = m_dyld.GetAddressByteSize();
-
-    image_infos.resize(image_infos_count);
-    const size_t count = image_infos.size() * 3 * addr_size;
-    DataBufferHeap info_data(count, 0);
-    Error error;
-    const size_t bytes_read = m_process->ReadMemory (image_infos_addr, 
-                                                     info_data.GetBytes(), 
-                                                     info_data.GetByteSize(),
-                                                     error);
-    if (bytes_read == count)
-    {
-        lldb::offset_t info_data_offset = 0;
-        DataExtractor info_data_ref(info_data.GetBytes(), info_data.GetByteSize(), endian, addr_size);
-        for (size_t i = 0; i < image_infos.size() && info_data_ref.ValidOffset(info_data_offset); i++)
-        {
-            image_infos[i].address = info_data_ref.GetPointer(&info_data_offset);
-            lldb::addr_t path_addr = info_data_ref.GetPointer(&info_data_offset);
-            image_infos[i].mod_date = info_data_ref.GetPointer(&info_data_offset);
-
-            char raw_path[PATH_MAX];
-            m_process->ReadCStringFromMemory (path_addr, raw_path, sizeof(raw_path), error);
-            // don't resolve the path
-            if (error.Success())
-            {
-                const bool resolve_path = false;
-                image_infos[i].file_spec.SetFile(raw_path, resolve_path);
-            }
-        }
-        return true;
-    }
-    else
-    {
-        return false;
-    }
+  } else {
+    return false;
+  }
 }
 
 //----------------------------------------------------------------------
@@ -759,74 +720,68 @@ DynamicLoaderMacOSXDYLD::ReadImageInfos
 // we're reading the dyld infos.  Return true if we actually read anything,
 // and false otherwise.
 //----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos ()
-{
-    Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
-    
-    std::lock_guard<std::recursive_mutex> guard(m_mutex);
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    if (m_process->GetStopID() == m_dyld_image_infos_stop_id
-          || m_dyld_image_infos.size() != 0)
-        return false;
-
-    if (ReadAllImageInfosStructure ())
-    {
-        // Nothing to load or unload?
-        if (m_dyld_all_image_infos.dylib_info_count == 0)
-            return true;
-        
-        if (m_dyld_all_image_infos.dylib_info_addr == 0)
-        {
-            // DYLD is updating the images now.  So we should say we have no images, and then we'll 
-            // figure it out when we hit the added breakpoint.
-            return false;
-        }
-        else
-        {
-            if (!AddModulesUsingImageInfosAddress (m_dyld_all_image_infos.dylib_info_addr, 
-                                                   m_dyld_all_image_infos.dylib_info_count))
-            {
-                DEBUG_PRINTF("%s", "unable to read all data for all_dylib_infos.");
-                m_dyld_image_infos.clear();
-            }
-        }
+bool DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos() {
+  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
 
-        // Now we have one more bit of business.  If there is a library left in the images for our target that
-        // doesn't have a load address, then it must be something that we were expecting to load (for instance we
-        // read a load command for it) but it didn't in fact load - probably because DYLD_*_PATH pointed
-        // to an equivalent version.  We don't want it to stay in the target's module list or it will confuse
-        // us, so unload it here.
-        Target &target = m_process->GetTarget();
-        const ModuleList &target_modules = target.GetImages();
-        ModuleList not_loaded_modules;
-        std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
-        
-        size_t num_modules = target_modules.GetSize();
-        for (size_t i = 0; i < num_modules; i++)
-        {
-            ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked (i);
-            if (!module_sp->IsLoadedInTarget (&target))
-            {
-                if (log)
-                {
-                    StreamString s;
-                    module_sp->GetDescription (&s);
-                    log->Printf ("Unloading pre-run module: %s.", s.GetData ());
-                }
-                not_loaded_modules.Append (module_sp);
-            }
-        }
-        
-        if (not_loaded_modules.GetSize() != 0)
-        {
-            target.GetImages().Remove(not_loaded_modules);
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  if (m_process->GetStopID() == m_dyld_image_infos_stop_id ||
+      m_dyld_image_infos.size() != 0)
+    return false;
+
+  if (ReadAllImageInfosStructure()) {
+    // Nothing to load or unload?
+    if (m_dyld_all_image_infos.dylib_info_count == 0)
+      return true;
+
+    if (m_dyld_all_image_infos.dylib_info_addr == 0) {
+      // DYLD is updating the images now.  So we should say we have no images,
+      // and then we'll
+      // figure it out when we hit the added breakpoint.
+      return false;
+    } else {
+      if (!AddModulesUsingImageInfosAddress(
+              m_dyld_all_image_infos.dylib_info_addr,
+              m_dyld_all_image_infos.dylib_info_count)) {
+        DEBUG_PRINTF("%s", "unable to read all data for all_dylib_infos.");
+        m_dyld_image_infos.clear();
+      }
+    }
+
+    // Now we have one more bit of business.  If there is a library left in the
+    // images for our target that
+    // doesn't have a load address, then it must be something that we were
+    // expecting to load (for instance we
+    // read a load command for it) but it didn't in fact load - probably because
+    // DYLD_*_PATH pointed
+    // to an equivalent version.  We don't want it to stay in the target's
+    // module list or it will confuse
+    // us, so unload it here.
+    Target &target = m_process->GetTarget();
+    const ModuleList &target_modules = target.GetImages();
+    ModuleList not_loaded_modules;
+    std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+
+    size_t num_modules = target_modules.GetSize();
+    for (size_t i = 0; i < num_modules; i++) {
+      ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
+      if (!module_sp->IsLoadedInTarget(&target)) {
+        if (log) {
+          StreamString s;
+          module_sp->GetDescription(&s);
+          log->Printf("Unloading pre-run module: %s.", s.GetData());
         }
+        not_loaded_modules.Append(module_sp);
+      }
+    }
 
-        return true;
+    if (not_loaded_modules.GetSize() != 0) {
+      target.GetImages().Remove(not_loaded_modules);
     }
-    else
-        return false;
+
+    return true;
+  } else
+    return false;
 }
 
 //----------------------------------------------------------------------
@@ -835,166 +790,161 @@ DynamicLoaderMacOSXDYLD::InitializeFromA
 //
 // Returns true if we succeed, false if we fail for any reason.
 //----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXDYLD::ReadMachHeader (lldb::addr_t addr, llvm::MachO::mach_header *header, DataExtractor *load_command_data)
-{
-    DataBufferHeap header_bytes(sizeof(llvm::MachO::mach_header), 0);
-    Error error;
-    size_t bytes_read = m_process->ReadMemory (addr, 
-                                               header_bytes.GetBytes(), 
-                                               header_bytes.GetByteSize(), 
-                                               error);
-    if (bytes_read == sizeof(llvm::MachO::mach_header))
-    {
-        lldb::offset_t offset = 0;
-        ::memset (header, 0, sizeof(llvm::MachO::mach_header));
-
-        // Get the magic byte unswapped so we can figure out what we are dealing with
-        DataExtractor data(header_bytes.GetBytes(), header_bytes.GetByteSize(), endian::InlHostByteOrder(), 4);
-        header->magic = data.GetU32(&offset);
-        lldb::addr_t load_cmd_addr = addr;
-        data.SetByteOrder(DynamicLoaderMacOSXDYLD::GetByteOrderFromMagic(header->magic));
-        switch (header->magic)
-        {
-        case llvm::MachO::MH_MAGIC:
-        case llvm::MachO::MH_CIGAM:
-            data.SetAddressByteSize(4);
-            load_cmd_addr += sizeof(llvm::MachO::mach_header);
-            break;
-
-        case llvm::MachO::MH_MAGIC_64:
-        case llvm::MachO::MH_CIGAM_64:
-            data.SetAddressByteSize(8);
-            load_cmd_addr += sizeof(llvm::MachO::mach_header_64);
-            break;
-
-        default:
-            return false;
-        }
+bool DynamicLoaderMacOSXDYLD::ReadMachHeader(lldb::addr_t addr,
+                                             llvm::MachO::mach_header *header,
+                                             DataExtractor *load_command_data) {
+  DataBufferHeap header_bytes(sizeof(llvm::MachO::mach_header), 0);
+  Error error;
+  size_t bytes_read = m_process->ReadMemory(addr, header_bytes.GetBytes(),
+                                            header_bytes.GetByteSize(), error);
+  if (bytes_read == sizeof(llvm::MachO::mach_header)) {
+    lldb::offset_t offset = 0;
+    ::memset(header, 0, sizeof(llvm::MachO::mach_header));
 
-        // Read the rest of dyld's mach header
-        if (data.GetU32(&offset, &header->cputype, (sizeof(llvm::MachO::mach_header)/sizeof(uint32_t)) - 1))
-        {
-            if (load_command_data == NULL)
-                return true; // We were able to read the mach_header and weren't asked to read the load command bytes
-
-            DataBufferSP load_cmd_data_sp(new DataBufferHeap(header->sizeofcmds, 0));
-
-            size_t load_cmd_bytes_read = m_process->ReadMemory (load_cmd_addr, 
-                                                                load_cmd_data_sp->GetBytes(), 
-                                                                load_cmd_data_sp->GetByteSize(),
-                                                                error);
-            
-            if (load_cmd_bytes_read == header->sizeofcmds)
-            {
-                // Set the load command data and also set the correct endian
-                // swap settings and the correct address size
-                load_command_data->SetData(load_cmd_data_sp, 0, header->sizeofcmds);
-                load_command_data->SetByteOrder(data.GetByteOrder());
-                load_command_data->SetAddressByteSize(data.GetAddressByteSize());
-                return true; // We successfully read the mach_header and the load command data
-            }
+    // Get the magic byte unswapped so we can figure out what we are dealing
+    // with
+    DataExtractor data(header_bytes.GetBytes(), header_bytes.GetByteSize(),
+                       endian::InlHostByteOrder(), 4);
+    header->magic = data.GetU32(&offset);
+    lldb::addr_t load_cmd_addr = addr;
+    data.SetByteOrder(
+        DynamicLoaderMacOSXDYLD::GetByteOrderFromMagic(header->magic));
+    switch (header->magic) {
+    case llvm::MachO::MH_MAGIC:
+    case llvm::MachO::MH_CIGAM:
+      data.SetAddressByteSize(4);
+      load_cmd_addr += sizeof(llvm::MachO::mach_header);
+      break;
+
+    case llvm::MachO::MH_MAGIC_64:
+    case llvm::MachO::MH_CIGAM_64:
+      data.SetAddressByteSize(8);
+      load_cmd_addr += sizeof(llvm::MachO::mach_header_64);
+      break;
+
+    default:
+      return false;
+    }
+
+    // Read the rest of dyld's mach header
+    if (data.GetU32(&offset, &header->cputype,
+                    (sizeof(llvm::MachO::mach_header) / sizeof(uint32_t)) -
+                        1)) {
+      if (load_command_data == NULL)
+        return true; // We were able to read the mach_header and weren't asked
+                     // to read the load command bytes
+
+      DataBufferSP load_cmd_data_sp(new DataBufferHeap(header->sizeofcmds, 0));
+
+      size_t load_cmd_bytes_read =
+          m_process->ReadMemory(load_cmd_addr, load_cmd_data_sp->GetBytes(),
+                                load_cmd_data_sp->GetByteSize(), error);
+
+      if (load_cmd_bytes_read == header->sizeofcmds) {
+        // Set the load command data and also set the correct endian
+        // swap settings and the correct address size
+        load_command_data->SetData(load_cmd_data_sp, 0, header->sizeofcmds);
+        load_command_data->SetByteOrder(data.GetByteOrder());
+        load_command_data->SetAddressByteSize(data.GetAddressByteSize());
+        return true; // We successfully read the mach_header and the load
+                     // command data
+      }
 
-            return false; // We weren't able to read the load command data
-        }
+      return false; // We weren't able to read the load command data
     }
-    return false; // We failed the read the mach_header
+  }
+  return false; // We failed the read the mach_header
 }
 
-
 //----------------------------------------------------------------------
 // Parse the load commands for an image
 //----------------------------------------------------------------------
-uint32_t
-DynamicLoaderMacOSXDYLD::ParseLoadCommands (const DataExtractor& data, ImageInfo& dylib_info, FileSpec *lc_id_dylinker)
-{
-    lldb::offset_t offset = 0;
-    uint32_t cmd_idx;
-    Segment segment;
-    dylib_info.Clear (true);
-
-    for (cmd_idx = 0; cmd_idx < dylib_info.header.ncmds; cmd_idx++)
-    {
-        // Clear out any load command specific data from DYLIB_INFO since
-        // we are about to read it.
-
-        if (data.ValidOffsetForDataOfSize (offset, sizeof(llvm::MachO::load_command)))
-        {
-            llvm::MachO::load_command load_cmd;
-            lldb::offset_t load_cmd_offset = offset;
-            load_cmd.cmd = data.GetU32 (&offset);
-            load_cmd.cmdsize = data.GetU32 (&offset);
-            switch (load_cmd.cmd)
-            {
-            case llvm::MachO::LC_SEGMENT:
-                {
-                    segment.name.SetTrimmedCStringWithLength ((const char *)data.GetData(&offset, 16), 16);
-                    // We are putting 4 uint32_t values 4 uint64_t values so
-                    // we have to use multiple 32 bit gets below.
-                    segment.vmaddr = data.GetU32 (&offset);
-                    segment.vmsize = data.GetU32 (&offset);
-                    segment.fileoff = data.GetU32 (&offset);
-                    segment.filesize = data.GetU32 (&offset);
-                    // Extract maxprot, initprot, nsects and flags all at once
-                    data.GetU32(&offset, &segment.maxprot, 4);
-                    dylib_info.segments.push_back (segment);
-                }
-                break;
-
-            case llvm::MachO::LC_SEGMENT_64:
-                {
-                    segment.name.SetTrimmedCStringWithLength ((const char *)data.GetData(&offset, 16), 16);
-                    // Extract vmaddr, vmsize, fileoff, and filesize all at once
-                    data.GetU64(&offset, &segment.vmaddr, 4);
-                    // Extract maxprot, initprot, nsects and flags all at once
-                    data.GetU32(&offset, &segment.maxprot, 4);
-                    dylib_info.segments.push_back (segment);
-                }
-                break;
-
-            case llvm::MachO::LC_ID_DYLINKER:
-                if (lc_id_dylinker)
-                {
-                    const lldb::offset_t name_offset = load_cmd_offset + data.GetU32 (&offset);
-                    const char *path = data.PeekCStr (name_offset);
-                    lc_id_dylinker->SetFile (path, true);
-                }
-                break;
-
-            case llvm::MachO::LC_UUID:
-                dylib_info.uuid.SetBytes(data.GetData (&offset, 16));
-                break;
-
-            default:
-                break;
-            }
-            // Set offset to be the beginning of the next load command.
-            offset = load_cmd_offset + load_cmd.cmdsize;
-        }
-    }
-    
-    // All sections listed in the dyld image info structure will all
-    // either be fixed up already, or they will all be off by a single
-    // slide amount that is determined by finding the first segment
-    // that is at file offset zero which also has bytes (a file size
-    // that is greater than zero) in the object file.
-    
-    // Determine the slide amount (if any)
-    const size_t num_sections = dylib_info.segments.size();
-    for (size_t i = 0; i < num_sections; ++i)
-    {
-        // Iterate through the object file sections to find the
-        // first section that starts of file offset zero and that
-        // has bytes in the file...
-        if ((dylib_info.segments[i].fileoff == 0 && dylib_info.segments[i].filesize > 0) || (dylib_info.segments[i].name == ConstString("__TEXT")))
-        {
-            dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr;
-            // We have found the slide amount, so we can exit
-            // this for loop.
-            break;
-        }
+uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data,
+                                                    ImageInfo &dylib_info,
+                                                    FileSpec *lc_id_dylinker) {
+  lldb::offset_t offset = 0;
+  uint32_t cmd_idx;
+  Segment segment;
+  dylib_info.Clear(true);
+
+  for (cmd_idx = 0; cmd_idx < dylib_info.header.ncmds; cmd_idx++) {
+    // Clear out any load command specific data from DYLIB_INFO since
+    // we are about to read it.
+
+    if (data.ValidOffsetForDataOfSize(offset,
+                                      sizeof(llvm::MachO::load_command))) {
+      llvm::MachO::load_command load_cmd;
+      lldb::offset_t load_cmd_offset = offset;
+      load_cmd.cmd = data.GetU32(&offset);
+      load_cmd.cmdsize = data.GetU32(&offset);
+      switch (load_cmd.cmd) {
+      case llvm::MachO::LC_SEGMENT: {
+        segment.name.SetTrimmedCStringWithLength(
+            (const char *)data.GetData(&offset, 16), 16);
+        // We are putting 4 uint32_t values 4 uint64_t values so
+        // we have to use multiple 32 bit gets below.
+        segment.vmaddr = data.GetU32(&offset);
+        segment.vmsize = data.GetU32(&offset);
+        segment.fileoff = data.GetU32(&offset);
+        segment.filesize = data.GetU32(&offset);
+        // Extract maxprot, initprot, nsects and flags all at once
+        data.GetU32(&offset, &segment.maxprot, 4);
+        dylib_info.segments.push_back(segment);
+      } break;
+
+      case llvm::MachO::LC_SEGMENT_64: {
+        segment.name.SetTrimmedCStringWithLength(
+            (const char *)data.GetData(&offset, 16), 16);
+        // Extract vmaddr, vmsize, fileoff, and filesize all at once
+        data.GetU64(&offset, &segment.vmaddr, 4);
+        // Extract maxprot, initprot, nsects and flags all at once
+        data.GetU32(&offset, &segment.maxprot, 4);
+        dylib_info.segments.push_back(segment);
+      } break;
+
+      case llvm::MachO::LC_ID_DYLINKER:
+        if (lc_id_dylinker) {
+          const lldb::offset_t name_offset =
+              load_cmd_offset + data.GetU32(&offset);
+          const char *path = data.PeekCStr(name_offset);
+          lc_id_dylinker->SetFile(path, true);
+        }
+        break;
+
+      case llvm::MachO::LC_UUID:
+        dylib_info.uuid.SetBytes(data.GetData(&offset, 16));
+        break;
+
+      default:
+        break;
+      }
+      // Set offset to be the beginning of the next load command.
+      offset = load_cmd_offset + load_cmd.cmdsize;
+    }
+  }
+
+  // All sections listed in the dyld image info structure will all
+  // either be fixed up already, or they will all be off by a single
+  // slide amount that is determined by finding the first segment
+  // that is at file offset zero which also has bytes (a file size
+  // that is greater than zero) in the object file.
+
+  // Determine the slide amount (if any)
+  const size_t num_sections = dylib_info.segments.size();
+  for (size_t i = 0; i < num_sections; ++i) {
+    // Iterate through the object file sections to find the
+    // first section that starts of file offset zero and that
+    // has bytes in the file...
+    if ((dylib_info.segments[i].fileoff == 0 &&
+         dylib_info.segments[i].filesize > 0) ||
+        (dylib_info.segments[i].name == ConstString("__TEXT"))) {
+      dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr;
+      // We have found the slide amount, so we can exit
+      // this for loop.
+      break;
     }
-    return cmd_idx;
+  }
+  return cmd_idx;
 }
 
 //----------------------------------------------------------------------
@@ -1002,313 +952,278 @@ DynamicLoaderMacOSXDYLD::ParseLoadComman
 // _dyld_all_image_infos structure points to and cache the results.
 //----------------------------------------------------------------------
 
-void
-DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos, 
-                                                               uint32_t infos_count, 
-                                                               bool update_executable)
-{
-    uint32_t exe_idx = UINT32_MAX;
-    // Read any UUID values that we can get
-    for (uint32_t i = 0; i < infos_count; i++)
-    {
-        if (!image_infos[i].UUIDValid())
-        {
-            DataExtractor data; // Load command data
-            if (!ReadMachHeader (image_infos[i].address, &image_infos[i].header, &data))
-                continue;
-
-            ParseLoadCommands (data, image_infos[i], NULL);
-
-            if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE)
-                exe_idx = i;
-            
-        }
-    }
-
-    Target &target = m_process->GetTarget();
-
-    if (exe_idx < image_infos.size())
-    {
-        const bool can_create = true;
-        ModuleSP exe_module_sp (FindTargetModuleForImageInfo (image_infos[exe_idx], can_create, NULL));
-
-        if (exe_module_sp)
-        {
-            UpdateImageLoadAddress (exe_module_sp.get(), image_infos[exe_idx]);
-
-            if (exe_module_sp.get() != target.GetExecutableModulePointer())
-            {
-                // Don't load dependent images since we are in dyld where we will know
-                // and find out about all images that are loaded. Also when setting the
-                // executable module, it will clear the targets module list, and if we
-                // have an in memory dyld module, it will get removed from the list
-                // so we will need to add it back after setting the executable module,
-                // so we first try and see if we already have a weak pointer to the
-                // dyld module, make it into a shared pointer, then add the executable,
-                // then re-add it back to make sure it is always in the list.
-                ModuleSP dyld_module_sp(GetDYLDModule ());
-                
-                const bool get_dependent_images = false;
-                m_process->GetTarget().SetExecutableModule (exe_module_sp, 
-                                                            get_dependent_images);
-
-                if (dyld_module_sp)
-                {
-                   if(target.GetImages().AppendIfNeeded (dyld_module_sp))
-                   {
-                        std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-
-                        // Also add it to the section list.
-                        UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
-                   }
-                }
-            }
+void DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands(
+    ImageInfo::collection &image_infos, uint32_t infos_count,
+    bool update_executable) {
+  uint32_t exe_idx = UINT32_MAX;
+  // Read any UUID values that we can get
+  for (uint32_t i = 0; i < infos_count; i++) {
+    if (!image_infos[i].UUIDValid()) {
+      DataExtractor data; // Load command data
+      if (!ReadMachHeader(image_infos[i].address, &image_infos[i].header,
+                          &data))
+        continue;
+
+      ParseLoadCommands(data, image_infos[i], NULL);
+
+      if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE)
+        exe_idx = i;
+    }
+  }
+
+  Target &target = m_process->GetTarget();
+
+  if (exe_idx < image_infos.size()) {
+    const bool can_create = true;
+    ModuleSP exe_module_sp(
+        FindTargetModuleForImageInfo(image_infos[exe_idx], can_create, NULL));
+
+    if (exe_module_sp) {
+      UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]);
+
+      if (exe_module_sp.get() != target.GetExecutableModulePointer()) {
+        // Don't load dependent images since we are in dyld where we will know
+        // and find out about all images that are loaded. Also when setting the
+        // executable module, it will clear the targets module list, and if we
+        // have an in memory dyld module, it will get removed from the list
+        // so we will need to add it back after setting the executable module,
+        // so we first try and see if we already have a weak pointer to the
+        // dyld module, make it into a shared pointer, then add the executable,
+        // then re-add it back to make sure it is always in the list.
+        ModuleSP dyld_module_sp(GetDYLDModule());
+
+        const bool get_dependent_images = false;
+        m_process->GetTarget().SetExecutableModule(exe_module_sp,
+                                                   get_dependent_images);
+
+        if (dyld_module_sp) {
+          if (target.GetImages().AppendIfNeeded(dyld_module_sp)) {
+            std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+
+            // Also add it to the section list.
+            UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
+          }
         }
+      }
     }
+  }
 }
 
-
 //----------------------------------------------------------------------
 // Dump the _dyld_all_image_infos members and all current image infos
 // that we have parsed to the file handle provided.
 //----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXDYLD::PutToLog(Log *log) const
-{
-    if (log == NULL)
-        return;
-
-    std::lock_guard<std::recursive_mutex> guard(m_mutex);
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-    log->Printf("dyld_all_image_infos = { version=%d, count=%d, addr=0x%8.8" PRIx64 ", notify=0x%8.8" PRIx64 " }",
-                    m_dyld_all_image_infos.version,
-                    m_dyld_all_image_infos.dylib_info_count,
-                    (uint64_t)m_dyld_all_image_infos.dylib_info_addr,
-                    (uint64_t)m_dyld_all_image_infos.notification);
-    size_t i;
-    const size_t count = m_dyld_image_infos.size();
-    if (count > 0)
-    {
-        log->PutCString("Loaded:");
-        for (i = 0; i<count; i++)
-            m_dyld_image_infos[i].PutToLog(log);
-    }
-}
-
-bool
-DynamicLoaderMacOSXDYLD::SetNotificationBreakpoint ()
-{
-    DEBUG_PRINTF("DynamicLoaderMacOSXDYLD::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
-    if (m_break_id == LLDB_INVALID_BREAK_ID)
-    {
-        if (m_dyld_all_image_infos.notification != LLDB_INVALID_ADDRESS)
-        {
-            Address so_addr;
-            // Set the notification breakpoint and install a breakpoint
-            // callback function that will get called each time the
-            // breakpoint gets hit. We will use this to track when shared
-            // libraries get loaded/unloaded.
-            bool resolved = m_process->GetTarget().ResolveLoadAddress(m_dyld_all_image_infos.notification, so_addr);
-            if (!resolved)
-            {
-                ModuleSP dyld_module_sp = GetDYLDModule();
-                if (dyld_module_sp)
-                {
-                    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
-
-                    UpdateImageLoadAddress (dyld_module_sp.get(), m_dyld);
-                    resolved = m_process->GetTarget().ResolveLoadAddress(m_dyld_all_image_infos.notification, so_addr);
-                }
-            }
+void DynamicLoaderMacOSXDYLD::PutToLog(Log *log) const {
+  if (log == NULL)
+    return;
 
-            if (resolved)
-            {
-                Breakpoint *dyld_break = m_process->GetTarget().CreateBreakpoint (so_addr, true, false).get();
-                dyld_break->SetCallback (DynamicLoaderMacOSXDYLD::NotifyBreakpointHit, this, true);
-                dyld_break->SetBreakpointKind ("shared-library-event");
-                m_break_id = dyld_break->GetID();
-            }
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+  log->Printf(
+      "dyld_all_image_infos = { version=%d, count=%d, addr=0x%8.8" PRIx64
+      ", notify=0x%8.8" PRIx64 " }",
+      m_dyld_all_image_infos.version, m_dyld_all_image_infos.dylib_info_count,
+      (uint64_t)m_dyld_all_image_infos.dylib_info_addr,
+      (uint64_t)m_dyld_all_image_infos.notification);
+  size_t i;
+  const size_t count = m_dyld_image_infos.size();
+  if (count > 0) {
+    log->PutCString("Loaded:");
+    for (i = 0; i < count; i++)
+      m_dyld_image_infos[i].PutToLog(log);
+  }
+}
+
+bool DynamicLoaderMacOSXDYLD::SetNotificationBreakpoint() {
+  DEBUG_PRINTF("DynamicLoaderMacOSXDYLD::%s() process state = %s\n",
+               __FUNCTION__, StateAsCString(m_process->GetState()));
+  if (m_break_id == LLDB_INVALID_BREAK_ID) {
+    if (m_dyld_all_image_infos.notification != LLDB_INVALID_ADDRESS) {
+      Address so_addr;
+      // Set the notification breakpoint and install a breakpoint
+      // callback function that will get called each time the
+      // breakpoint gets hit. We will use this to track when shared
+      // libraries get loaded/unloaded.
+      bool resolved = m_process->GetTarget().ResolveLoadAddress(
+          m_dyld_all_image_infos.notification, so_addr);
+      if (!resolved) {
+        ModuleSP dyld_module_sp = GetDYLDModule();
+        if (dyld_module_sp) {
+          std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+
+          UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
+          resolved = m_process->GetTarget().ResolveLoadAddress(
+              m_dyld_all_image_infos.notification, so_addr);
+        }
+      }
+
+      if (resolved) {
+        Breakpoint *dyld_break =
+            m_process->GetTarget().CreateBreakpoint(so_addr, true, false).get();
+        dyld_break->SetCallback(DynamicLoaderMacOSXDYLD::NotifyBreakpointHit,
+                                this, true);
+        dyld_break->SetBreakpointKind("shared-library-event");
+        m_break_id = dyld_break->GetID();
+      }
+    }
+  }
+  return m_break_id != LLDB_INVALID_BREAK_ID;
+}
+
+Error DynamicLoaderMacOSXDYLD::CanLoadImage() {
+  Error error;
+  // In order for us to tell if we can load a shared library we verify that
+  // the dylib_info_addr isn't zero (which means no shared libraries have
+  // been set yet, or dyld is currently mucking with the shared library list).
+  if (ReadAllImageInfosStructure()) {
+    // TODO: also check the _dyld_global_lock_held variable in
+    // libSystem.B.dylib?
+    // TODO: check the malloc lock?
+    // TODO: check the objective C lock?
+    if (m_dyld_all_image_infos.dylib_info_addr != 0)
+      return error; // Success
+  }
+
+  error.SetErrorString("unsafe to load or unload shared libraries");
+  return error;
+}
+
+bool DynamicLoaderMacOSXDYLD::GetSharedCacheInformation(
+    lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
+    LazyBool &private_shared_cache) {
+  base_address = LLDB_INVALID_ADDRESS;
+  uuid.Clear();
+  using_shared_cache = eLazyBoolCalculate;
+  private_shared_cache = eLazyBoolCalculate;
+
+  if (m_process) {
+    addr_t all_image_infos = m_process->GetImageInfoAddress();
+
+    // The address returned by GetImageInfoAddress may be the address of dyld
+    // (don't want)
+    // or it may be the address of the dyld_all_image_infos structure (want).
+    // The first four
+    // bytes will be either the version field (all_image_infos) or a Mach-O file
+    // magic constant.
+    // Version 13 and higher of dyld_all_image_infos is required to get the
+    // sharedCacheUUID field.
+
+    Error err;
+    uint32_t version_or_magic =
+        m_process->ReadUnsignedIntegerFromMemory(all_image_infos, 4, -1, err);
+    if (version_or_magic != static_cast<uint32_t>(-1) &&
+        version_or_magic != llvm::MachO::MH_MAGIC &&
+        version_or_magic != llvm::MachO::MH_CIGAM &&
+        version_or_magic != llvm::MachO::MH_MAGIC_64 &&
+        version_or_magic != llvm::MachO::MH_CIGAM_64 &&
+        version_or_magic >= 13) {
+      addr_t sharedCacheUUID_address = LLDB_INVALID_ADDRESS;
+      int wordsize = m_process->GetAddressByteSize();
+      if (wordsize == 8) {
+        sharedCacheUUID_address =
+            all_image_infos + 160; // sharedCacheUUID <mach-o/dyld_images.h>
+      }
+      if (wordsize == 4) {
+        sharedCacheUUID_address =
+            all_image_infos + 84; // sharedCacheUUID <mach-o/dyld_images.h>
+      }
+      if (sharedCacheUUID_address != LLDB_INVALID_ADDRESS) {
+        uuid_t shared_cache_uuid;
+        if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid,
+                                  sizeof(uuid_t), err) == sizeof(uuid_t)) {
+          uuid.SetBytes(shared_cache_uuid);
+          if (uuid.IsValid()) {
+            using_shared_cache = eLazyBoolYes;
+          }
+        }
+
+        if (version_or_magic >= 15) {
+          // The sharedCacheBaseAddress field is the next one in the
+          // dyld_all_image_infos struct.
+          addr_t sharedCacheBaseAddr_address = sharedCacheUUID_address + 16;
+          Error error;
+          base_address = m_process->ReadUnsignedIntegerFromMemory(
+              sharedCacheBaseAddr_address, wordsize, LLDB_INVALID_ADDRESS,
+              error);
+          if (error.Fail())
+            base_address = LLDB_INVALID_ADDRESS;
         }
-    }
-    return m_break_id != LLDB_INVALID_BREAK_ID;
-}
 
-Error
-DynamicLoaderMacOSXDYLD::CanLoadImage ()
-{
-    Error error;
-    // In order for us to tell if we can load a shared library we verify that
-    // the dylib_info_addr isn't zero (which means no shared libraries have
-    // been set yet, or dyld is currently mucking with the shared library list).
-    if (ReadAllImageInfosStructure ())
-    {
-        // TODO: also check the _dyld_global_lock_held variable in libSystem.B.dylib?
-        // TODO: check the malloc lock?
-        // TODO: check the objective C lock?
-        if (m_dyld_all_image_infos.dylib_info_addr != 0)
-            return error; // Success
-    }
-
-    error.SetErrorString("unsafe to load or unload shared libraries");
-    return error;
-}
-
-bool
-DynamicLoaderMacOSXDYLD::GetSharedCacheInformation (lldb::addr_t &base_address,
-                                               UUID &uuid,
-                                               LazyBool &using_shared_cache,
-                                               LazyBool &private_shared_cache)
-{
-    base_address = LLDB_INVALID_ADDRESS;
-    uuid.Clear();
-    using_shared_cache = eLazyBoolCalculate;
-    private_shared_cache = eLazyBoolCalculate;
-
-    if (m_process)
-    {
-        addr_t all_image_infos = m_process->GetImageInfoAddress();
-
-        // The address returned by GetImageInfoAddress may be the address of dyld (don't want)
-        // or it may be the address of the dyld_all_image_infos structure (want).  The first four
-        // bytes will be either the version field (all_image_infos) or a Mach-O file magic constant.
-        // Version 13 and higher of dyld_all_image_infos is required to get the sharedCacheUUID field.
-
-        Error err;
-        uint32_t version_or_magic = m_process->ReadUnsignedIntegerFromMemory (all_image_infos, 4, -1, err);
-        if (version_or_magic != static_cast<uint32_t>(-1)
-            && version_or_magic != llvm::MachO::MH_MAGIC
-            && version_or_magic != llvm::MachO::MH_CIGAM
-            && version_or_magic != llvm::MachO::MH_MAGIC_64
-            && version_or_magic != llvm::MachO::MH_CIGAM_64
-            && version_or_magic >= 13)
-        {
-            addr_t sharedCacheUUID_address = LLDB_INVALID_ADDRESS;
-            int wordsize = m_process->GetAddressByteSize();
-            if (wordsize == 8)
-            {
-                sharedCacheUUID_address = all_image_infos + 160;  // sharedCacheUUID <mach-o/dyld_images.h>
-            }
-            if (wordsize == 4)
-            {
-                sharedCacheUUID_address = all_image_infos + 84;   // sharedCacheUUID <mach-o/dyld_images.h>
-            }
-            if (sharedCacheUUID_address != LLDB_INVALID_ADDRESS)
-            {
-                uuid_t shared_cache_uuid;
-                if (m_process->ReadMemory (sharedCacheUUID_address, shared_cache_uuid, sizeof (uuid_t), err) == sizeof (uuid_t))
-                {
-                    uuid.SetBytes (shared_cache_uuid);
-                    if (uuid.IsValid ())
-                    {
-                        using_shared_cache = eLazyBoolYes;
-                    }
-                }
-
-                if (version_or_magic >= 15)
-                {
-                    // The sharedCacheBaseAddress field is the next one in the dyld_all_image_infos struct.
-                    addr_t sharedCacheBaseAddr_address = sharedCacheUUID_address + 16;
-                    Error error;
-                    base_address = m_process->ReadUnsignedIntegerFromMemory (sharedCacheBaseAddr_address, wordsize, LLDB_INVALID_ADDRESS, error);
-                    if (error.Fail())
-                        base_address = LLDB_INVALID_ADDRESS;
-                }
-
-                return true;
-            }
+        return true;
+      }
 
-            //
-            // add
-            // NB: sharedCacheBaseAddress is the next field in dyld_all_image_infos after
-            // sharedCacheUUID -- that is, 16 bytes after it, if we wanted to fetch it.
-        }
+      //
+      // add
+      // NB: sharedCacheBaseAddress is the next field in dyld_all_image_infos
+      // after
+      // sharedCacheUUID -- that is, 16 bytes after it, if we wanted to fetch
+      // it.
     }
-    return false;
+  }
+  return false;
 }
 
-void
-DynamicLoaderMacOSXDYLD::Initialize()
-{
-    PluginManager::RegisterPlugin (GetPluginNameStatic(),
-                                   GetPluginDescriptionStatic(),
-                                   CreateInstance);
+void DynamicLoaderMacOSXDYLD::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                GetPluginDescriptionStatic(), CreateInstance);
 }
 
-void
-DynamicLoaderMacOSXDYLD::Terminate()
-{
-    PluginManager::UnregisterPlugin (CreateInstance);
+void DynamicLoaderMacOSXDYLD::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
 }
 
-
-lldb_private::ConstString
-DynamicLoaderMacOSXDYLD::GetPluginNameStatic()
-{
-    static ConstString g_name("macosx-dyld");
-    return g_name;
+lldb_private::ConstString DynamicLoaderMacOSXDYLD::GetPluginNameStatic() {
+  static ConstString g_name("macosx-dyld");
+  return g_name;
 }
 
-const char *
-DynamicLoaderMacOSXDYLD::GetPluginDescriptionStatic()
-{
-    return "Dynamic loader plug-in that watches for shared library loads/unloads in MacOSX user processes.";
+const char *DynamicLoaderMacOSXDYLD::GetPluginDescriptionStatic() {
+  return "Dynamic loader plug-in that watches for shared library loads/unloads "
+         "in MacOSX user processes.";
 }
 
-
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
-lldb_private::ConstString
-DynamicLoaderMacOSXDYLD::GetPluginName()
-{
-    return GetPluginNameStatic();
+lldb_private::ConstString DynamicLoaderMacOSXDYLD::GetPluginName() {
+  return GetPluginNameStatic();
 }
 
-uint32_t
-DynamicLoaderMacOSXDYLD::GetPluginVersion()
-{
-    return 1;
-}
+uint32_t DynamicLoaderMacOSXDYLD::GetPluginVersion() { return 1; }
 
-uint32_t
-DynamicLoaderMacOSXDYLD::AddrByteSize()
-{
-    std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+uint32_t DynamicLoaderMacOSXDYLD::AddrByteSize() {
+  std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
 
-    switch (m_dyld.header.magic)
-    {
-        case llvm::MachO::MH_MAGIC:
-        case llvm::MachO::MH_CIGAM:
-            return 4;
-            
-        case llvm::MachO::MH_MAGIC_64:
-        case llvm::MachO::MH_CIGAM_64:
-            return 8;
-            
-        default:
-            break;
-    }
-    return 0;
+  switch (m_dyld.header.magic) {
+  case llvm::MachO::MH_MAGIC:
+  case llvm::MachO::MH_CIGAM:
+    return 4;
+
+  case llvm::MachO::MH_MAGIC_64:
+  case llvm::MachO::MH_CIGAM_64:
+    return 8;
+
+  default:
+    break;
+  }
+  return 0;
 }
 
-lldb::ByteOrder
-DynamicLoaderMacOSXDYLD::GetByteOrderFromMagic(uint32_t magic)
-{
-    switch (magic)
-    {
-        case llvm::MachO::MH_MAGIC:
-        case llvm::MachO::MH_MAGIC_64:
-            return endian::InlHostByteOrder();
-            
-        case llvm::MachO::MH_CIGAM:
-        case llvm::MachO::MH_CIGAM_64:
-            if (endian::InlHostByteOrder() == lldb::eByteOrderBig)
-                return lldb::eByteOrderLittle;
-            else
-                return lldb::eByteOrderBig;
-            
-        default:
-            break;
-    }
-    return lldb::eByteOrderInvalid;
+lldb::ByteOrder DynamicLoaderMacOSXDYLD::GetByteOrderFromMagic(uint32_t magic) {
+  switch (magic) {
+  case llvm::MachO::MH_MAGIC:
+  case llvm::MachO::MH_MAGIC_64:
+    return endian::InlHostByteOrder();
+
+  case llvm::MachO::MH_CIGAM:
+  case llvm::MachO::MH_CIGAM_64:
+    if (endian::InlHostByteOrder() == lldb::eByteOrderBig)
+      return lldb::eByteOrderLittle;
+    else
+      return lldb::eByteOrderBig;
+
+  default:
+    break;
+  }
+  return lldb::eByteOrderInvalid;
 }

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h Tue Sep  6 15:57:50 2016
@@ -7,10 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-
-// This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS / watchOS)
+// This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS /
+// watchOS)
 // platforms earlier than 2016, where lldb would read the "dyld_all_image_infos"
-// dyld internal structure to understand where things were loaded and the 
+// dyld internal structure to understand where things were loaded and the
 // solib loaded/unloaded notification function we put a breakpoint on gives us
 // an array of (load address, mod time, file path) tuples.
 //
@@ -23,198 +23,164 @@
 
 // C Includes
 // C++ Includes
-#include <vector>
 #include <mutex>
+#include <vector>
 
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Target/DynamicLoader.h"
-#include "lldb/Host/FileSpec.h"
 #include "lldb/Core/StructuredData.h"
 #include "lldb/Core/UUID.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/SafeMachO.h"
 
 #include "DynamicLoaderDarwin.h"
 
-class DynamicLoaderMacOSXDYLD : public lldb_private::DynamicLoaderDarwin
-{
+class DynamicLoaderMacOSXDYLD : public lldb_private::DynamicLoaderDarwin {
 public:
-    DynamicLoaderMacOSXDYLD(lldb_private::Process *process);
+  DynamicLoaderMacOSXDYLD(lldb_private::Process *process);
+
+  virtual ~DynamicLoaderMacOSXDYLD() override;
 
-    virtual ~DynamicLoaderMacOSXDYLD() override;
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+  static void Initialize();
 
-    //------------------------------------------------------------------
-    // Static Functions
-    //------------------------------------------------------------------
-    static void
-    Initialize();
-
-    static void
-    Terminate();
-
-    static lldb_private::ConstString
-    GetPluginNameStatic();
-
-    static const char *
-    GetPluginDescriptionStatic();
-
-    static lldb_private::DynamicLoader *
-    CreateInstance (lldb_private::Process *process, bool force);
-
-    //------------------------------------------------------------------
-    /// Called after attaching a process.
-    ///
-    /// Allow DynamicLoader plug-ins to execute some code after
-    /// attaching to a process.
-    //------------------------------------------------------------------
-    bool
-    ProcessDidExec() override;
-
-    lldb_private::Error
-    CanLoadImage() override;
-
-    bool
-    GetSharedCacheInformation (lldb::addr_t &base_address,
-                               lldb_private::UUID &uuid,
-                               lldb_private::LazyBool &using_shared_cache,
-                               lldb_private::LazyBool &private_shared_cache) override;
-
-    //------------------------------------------------------------------
-    // PluginInterface protocol
-    //------------------------------------------------------------------
-    lldb_private::ConstString
-    GetPluginName() override;
+  static void Terminate();
 
-    uint32_t
-    GetPluginVersion() override;
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static const char *GetPluginDescriptionStatic();
+
+  static lldb_private::DynamicLoader *
+  CreateInstance(lldb_private::Process *process, bool force);
+
+  //------------------------------------------------------------------
+  /// Called after attaching a process.
+  ///
+  /// Allow DynamicLoader plug-ins to execute some code after
+  /// attaching to a process.
+  //------------------------------------------------------------------
+  bool ProcessDidExec() override;
+
+  lldb_private::Error CanLoadImage() override;
+
+  bool GetSharedCacheInformation(
+      lldb::addr_t &base_address, lldb_private::UUID &uuid,
+      lldb_private::LazyBool &using_shared_cache,
+      lldb_private::LazyBool &private_shared_cache) override;
+
+  //------------------------------------------------------------------
+  // PluginInterface protocol
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
 
 protected:
-    void
-    PutToLog(lldb_private::Log *log) const;
+  void PutToLog(lldb_private::Log *log) const;
+
+  void DoInitialImageFetch() override;
 
-    void
-    DoInitialImageFetch () override;
+  bool NeedToDoInitialImageFetch() override;
 
-    bool
-    NeedToDoInitialImageFetch () override;
+  bool DidSetNotificationBreakpoint() override;
 
-    bool
-    DidSetNotificationBreakpoint () override;
-
-    void
-    DoClear () override;
-
-    bool
-    ReadDYLDInfoFromMemoryAndSetNotificationCallback (lldb::addr_t addr);
-
-    static bool
-    NotifyBreakpointHit (void *baton,
-                         lldb_private::StoppointCallbackContext *context,
-                         lldb::user_id_t break_id,
-                         lldb::user_id_t break_loc_id);
-
-    uint32_t
-    AddrByteSize();
-
-    bool
-    ReadMachHeader (lldb::addr_t addr,
-                    llvm::MachO::mach_header *header,
-                    lldb_private::DataExtractor *load_command_data);
-
-    uint32_t
-    ParseLoadCommands (const lldb_private::DataExtractor& data,
-                       ImageInfo& dylib_info,
-                       lldb_private::FileSpec *lc_id_dylinker);
-
-    struct DYLDAllImageInfos
-    {
-        uint32_t version;
-        uint32_t dylib_info_count;              // Version >= 1
-        lldb::addr_t dylib_info_addr;           // Version >= 1
-        lldb::addr_t notification;              // Version >= 1
-        bool processDetachedFromSharedRegion;   // Version >= 1
-        bool libSystemInitialized;              // Version >= 2
-        lldb::addr_t dyldImageLoadAddress;      // Version >= 2
-
-        DYLDAllImageInfos() :
-            version (0),
-            dylib_info_count (0),
-            dylib_info_addr (LLDB_INVALID_ADDRESS),
-            notification (LLDB_INVALID_ADDRESS),
-            processDetachedFromSharedRegion (false),
-            libSystemInitialized (false),
-            dyldImageLoadAddress (LLDB_INVALID_ADDRESS)
-        {
-        }
-
-        void
-        Clear()
-        {
-            version = 0;
-            dylib_info_count = 0;
-            dylib_info_addr = LLDB_INVALID_ADDRESS;
-            notification = LLDB_INVALID_ADDRESS;
-            processDetachedFromSharedRegion = false;
-            libSystemInitialized = false;
-            dyldImageLoadAddress = LLDB_INVALID_ADDRESS;
-        }
-
-        bool
-        IsValid() const
-        {
-            return version >= 1 || version <= 6;
-        }
-    };
-
-    static lldb::ByteOrder
-    GetByteOrderFromMagic(uint32_t magic);
-
-    bool
-    SetNotificationBreakpoint () override;
-
-    void
-    ClearNotificationBreakpoint () override;
-
-    // There is a little tricky bit where you might initially attach while dyld is updating
-    // the all_image_infos, and you can't read the infos, so you have to continue and pick it
-    // up when you hit the update breakpoint.  At that point, you need to run this initialize
-    // function, but when you do it that way you DON'T need to do the extra work you would at
-    // the breakpoint.
-    // So this function will only do actual work if the image infos haven't been read yet.
-    // If it does do any work, then it will return true, and false otherwise.  That way you can
-    // call it in the breakpoint action, and if it returns true you're done.
-    bool
-    InitializeFromAllImageInfos ();
-
-    bool
-    ReadAllImageInfosStructure ();
-    
-    bool
-    AddModulesUsingImageInfosAddress (lldb::addr_t image_infos_addr, uint32_t image_infos_count);
-    
-    bool
-    RemoveModulesUsingImageInfosAddress (lldb::addr_t image_infos_addr, uint32_t image_infos_count);
-
-    void
-    UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos, 
-                                          uint32_t infos_count, 
-                                          bool update_executable);
-
-    bool
-    ReadImageInfos (lldb::addr_t image_infos_addr, 
-                    uint32_t image_infos_count, 
-                    ImageInfo::collection &image_infos);
-
-    lldb::addr_t m_dyld_all_image_infos_addr;
-    DYLDAllImageInfos m_dyld_all_image_infos;
-    uint32_t m_dyld_all_image_infos_stop_id;
-    lldb::user_id_t m_break_id;
-    mutable std::recursive_mutex m_mutex;
-    bool m_process_image_addr_is_all_images_infos;
+  void DoClear() override;
+
+  bool ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb::addr_t addr);
+
+  static bool
+  NotifyBreakpointHit(void *baton,
+                      lldb_private::StoppointCallbackContext *context,
+                      lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+  uint32_t AddrByteSize();
+
+  bool ReadMachHeader(lldb::addr_t addr, llvm::MachO::mach_header *header,
+                      lldb_private::DataExtractor *load_command_data);
+
+  uint32_t ParseLoadCommands(const lldb_private::DataExtractor &data,
+                             ImageInfo &dylib_info,
+                             lldb_private::FileSpec *lc_id_dylinker);
+
+  struct DYLDAllImageInfos {
+    uint32_t version;
+    uint32_t dylib_info_count;            // Version >= 1
+    lldb::addr_t dylib_info_addr;         // Version >= 1
+    lldb::addr_t notification;            // Version >= 1
+    bool processDetachedFromSharedRegion; // Version >= 1
+    bool libSystemInitialized;            // Version >= 2
+    lldb::addr_t dyldImageLoadAddress;    // Version >= 2
+
+    DYLDAllImageInfos()
+        : version(0), dylib_info_count(0),
+          dylib_info_addr(LLDB_INVALID_ADDRESS),
+          notification(LLDB_INVALID_ADDRESS),
+          processDetachedFromSharedRegion(false), libSystemInitialized(false),
+          dyldImageLoadAddress(LLDB_INVALID_ADDRESS) {}
+
+    void Clear() {
+      version = 0;
+      dylib_info_count = 0;
+      dylib_info_addr = LLDB_INVALID_ADDRESS;
+      notification = LLDB_INVALID_ADDRESS;
+      processDetachedFromSharedRegion = false;
+      libSystemInitialized = false;
+      dyldImageLoadAddress = LLDB_INVALID_ADDRESS;
+    }
+
+    bool IsValid() const { return version >= 1 || version <= 6; }
+  };
+
+  static lldb::ByteOrder GetByteOrderFromMagic(uint32_t magic);
+
+  bool SetNotificationBreakpoint() override;
+
+  void ClearNotificationBreakpoint() override;
+
+  // There is a little tricky bit where you might initially attach while dyld is
+  // updating
+  // the all_image_infos, and you can't read the infos, so you have to continue
+  // and pick it
+  // up when you hit the update breakpoint.  At that point, you need to run this
+  // initialize
+  // function, but when you do it that way you DON'T need to do the extra work
+  // you would at
+  // the breakpoint.
+  // So this function will only do actual work if the image infos haven't been
+  // read yet.
+  // If it does do any work, then it will return true, and false otherwise.
+  // That way you can
+  // call it in the breakpoint action, and if it returns true you're done.
+  bool InitializeFromAllImageInfos();
+
+  bool ReadAllImageInfosStructure();
+
+  bool AddModulesUsingImageInfosAddress(lldb::addr_t image_infos_addr,
+                                        uint32_t image_infos_count);
+
+  bool RemoveModulesUsingImageInfosAddress(lldb::addr_t image_infos_addr,
+                                           uint32_t image_infos_count);
+
+  void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos,
+                                             uint32_t infos_count,
+                                             bool update_executable);
+
+  bool ReadImageInfos(lldb::addr_t image_infos_addr, uint32_t image_infos_count,
+                      ImageInfo::collection &image_infos);
+
+  lldb::addr_t m_dyld_all_image_infos_addr;
+  DYLDAllImageInfos m_dyld_all_image_infos;
+  uint32_t m_dyld_all_image_infos_stop_id;
+  lldb::user_id_t m_break_id;
+  mutable std::recursive_mutex m_mutex;
+  bool m_process_image_addr_is_all_images_infos;
 
 private:
-    DISALLOW_COPY_AND_ASSIGN (DynamicLoaderMacOSXDYLD);
+  DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOSXDYLD);
 };
 
 #endif // liblldb_DynamicLoaderMacOSXDYLD_h_

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp Tue Sep  6 15:57:50 2016
@@ -28,113 +28,92 @@
 using namespace lldb;
 using namespace lldb_private;
 
-static bool
-GetMaxU64(DataExtractor &data,
-          lldb::offset_t *offset_ptr,
-          uint64_t *value,
-          unsigned int byte_size)
-{
-    lldb::offset_t saved_offset = *offset_ptr;
-    *value = data.GetMaxU64(offset_ptr, byte_size);
-    return *offset_ptr != saved_offset;
-}
-
-static bool
-ParseAuxvEntry(DataExtractor &data,
-               AuxVector::Entry &entry,
-               lldb::offset_t *offset_ptr,
-               unsigned int byte_size)
-{
-    if (!GetMaxU64(data, offset_ptr, &entry.type, byte_size))
-        return false;
-
-    if (!GetMaxU64(data, offset_ptr, &entry.value, byte_size))
-        return false;
-
-    return true;
-}
-
-DataBufferSP
-AuxVector::GetAuxvData()
-{
-    if (m_process)
-        return m_process->GetAuxvData ();
-    else
-        return DataBufferSP ();
-}
-
-void
-AuxVector::ParseAuxv(DataExtractor &data)
-{
-    const unsigned int byte_size  = m_process->GetAddressByteSize();
-    lldb::offset_t offset = 0;
-
-    for (;;) 
-    {
-        Entry entry;
-
-        if (!ParseAuxvEntry(data, entry, &offset, byte_size))
-            break;
+static bool GetMaxU64(DataExtractor &data, lldb::offset_t *offset_ptr,
+                      uint64_t *value, unsigned int byte_size) {
+  lldb::offset_t saved_offset = *offset_ptr;
+  *value = data.GetMaxU64(offset_ptr, byte_size);
+  return *offset_ptr != saved_offset;
+}
 
-        if (entry.type == AT_NULL)
-            break;
+static bool ParseAuxvEntry(DataExtractor &data, AuxVector::Entry &entry,
+                           lldb::offset_t *offset_ptr, unsigned int byte_size) {
+  if (!GetMaxU64(data, offset_ptr, &entry.type, byte_size))
+    return false;
 
-        if (entry.type == AT_IGNORE)
-            continue;
+  if (!GetMaxU64(data, offset_ptr, &entry.value, byte_size))
+    return false;
 
-        m_auxv.push_back(entry);
-    }
+  return true;
 }
 
-AuxVector::AuxVector(Process *process)
-    : m_process(process)
-{
-    DataExtractor data;
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-
-    data.SetData(GetAuxvData());
-    data.SetByteOrder(m_process->GetByteOrder());
-    data.SetAddressByteSize(m_process->GetAddressByteSize());
-    
-    ParseAuxv(data);
-
-    if (log)
-        DumpToLog(log);
-}
-
-AuxVector::iterator 
-AuxVector::FindEntry(EntryType type) const
-{
-    for (iterator I = begin(); I != end(); ++I)
-    {
-        if (I->type == static_cast<uint64_t>(type))
-            return I;
-    }
+DataBufferSP AuxVector::GetAuxvData() {
+  if (m_process)
+    return m_process->GetAuxvData();
+  else
+    return DataBufferSP();
+}
+
+void AuxVector::ParseAuxv(DataExtractor &data) {
+  const unsigned int byte_size = m_process->GetAddressByteSize();
+  lldb::offset_t offset = 0;
+
+  for (;;) {
+    Entry entry;
 
-    return end();
+    if (!ParseAuxvEntry(data, entry, &offset, byte_size))
+      break;
+
+    if (entry.type == AT_NULL)
+      break;
+
+    if (entry.type == AT_IGNORE)
+      continue;
+
+    m_auxv.push_back(entry);
+  }
 }
 
-void
-AuxVector::DumpToLog(Log *log) const
-{
-    if (!log)
-        return;
-
-    log->PutCString("AuxVector: ");
-    for (iterator I = begin(); I != end(); ++I)
-    {
-        log->Printf("   %s [%" PRIu64 "]: %" PRIx64, GetEntryName(*I), I->type, I->value);
-    }
+AuxVector::AuxVector(Process *process) : m_process(process) {
+  DataExtractor data;
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+
+  data.SetData(GetAuxvData());
+  data.SetByteOrder(m_process->GetByteOrder());
+  data.SetAddressByteSize(m_process->GetAddressByteSize());
+
+  ParseAuxv(data);
+
+  if (log)
+    DumpToLog(log);
+}
+
+AuxVector::iterator AuxVector::FindEntry(EntryType type) const {
+  for (iterator I = begin(); I != end(); ++I) {
+    if (I->type == static_cast<uint64_t>(type))
+      return I;
+  }
+
+  return end();
 }
 
-const char *
-AuxVector::GetEntryName(EntryType type)
-{
-    const char *name = "AT_???";
-
-#define ENTRY_NAME(_type) _type: name = #_type
-    switch (type) 
-    {
+void AuxVector::DumpToLog(Log *log) const {
+  if (!log)
+    return;
+
+  log->PutCString("AuxVector: ");
+  for (iterator I = begin(); I != end(); ++I) {
+    log->Printf("   %s [%" PRIu64 "]: %" PRIx64, GetEntryName(*I), I->type,
+                I->value);
+  }
+}
+
+const char *AuxVector::GetEntryName(EntryType type) {
+  const char *name = "AT_???";
+
+#define ENTRY_NAME(_type)                                                      \
+  _type:                                                                       \
+  name = #_type
+  switch (type) {
     case ENTRY_NAME(AT_NULL);           break;
     case ENTRY_NAME(AT_IGNORE);         break;
     case ENTRY_NAME(AT_EXECFD);         break;
@@ -173,4 +152,3 @@ AuxVector::GetEntryName(EntryType type)
 
     return name;
 }
-

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h Tue Sep  6 15:57:50 2016
@@ -19,7 +19,7 @@
 
 namespace lldb_private {
 class DataExtractor;
-} 
+}
 
 /// @class AuxVector
 /// @brief Represents a processes auxiliary vector.
@@ -31,85 +31,80 @@ class DataExtractor;
 class AuxVector {
 
 public:
-    AuxVector(lldb_private::Process *process);
+  AuxVector(lldb_private::Process *process);
 
-    struct Entry {
-        uint64_t type;
-        uint64_t value;
-
-        Entry() : type(0), value(0) { }
-    };
-
-    /// Constants describing the type of entry.
-    /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX information.
-    enum EntryType {
-        AT_NULL           = 0,   ///< End of auxv.
-        AT_IGNORE         = 1,   ///< Ignore entry.
-        AT_EXECFD         = 2,   ///< File descriptor of program.
-        AT_PHDR           = 3,   ///< Program headers.
-        AT_PHENT          = 4,   ///< Size of program header.
-        AT_PHNUM          = 5,   ///< Number of program headers.
-        AT_PAGESZ         = 6,   ///< Page size.
-        AT_BASE           = 7,   ///< Interpreter base address.
-        AT_FLAGS          = 8,   ///< Flags.
-        AT_ENTRY          = 9,   ///< Program entry point.
-        AT_NOTELF         = 10,  ///< Set if program is not an ELF.
-        AT_UID            = 11,  ///< UID.
-        AT_EUID           = 12,  ///< Effective UID.
-        AT_GID            = 13,  ///< GID.
-        AT_EGID           = 14,  ///< Effective GID.
-        AT_CLKTCK         = 17,  ///< Clock frequency (e.g. times(2)).
-        AT_PLATFORM       = 15,  ///< String identifying platform.
-        AT_HWCAP          = 16,  ///< Machine dependent hints about processor capabilities.
-        AT_FPUCW          = 18,  ///< Used FPU control word.
-        AT_DCACHEBSIZE    = 19,  ///< Data cache block size.
-        AT_ICACHEBSIZE    = 20,  ///< Instruction cache block size.
-        AT_UCACHEBSIZE    = 21,  ///< Unified cache block size.
-        AT_IGNOREPPC      = 22,  ///< Entry should be ignored.
-        AT_SECURE         = 23,  ///< Boolean, was exec setuid-like?
-        AT_BASE_PLATFORM  = 24,  ///< String identifying real platforms.
-        AT_RANDOM         = 25,  ///< Address of 16 random bytes.
-        AT_EXECFN         = 31,  ///< Filename of executable.
-        AT_SYSINFO        = 32,  ///< Pointer to the global system page used for system calls and other nice things.
-        AT_SYSINFO_EHDR   = 33,  
-        AT_L1I_CACHESHAPE = 34,  ///< Shapes of the caches.
-        AT_L1D_CACHESHAPE = 35,
-        AT_L2_CACHESHAPE  = 36,
-        AT_L3_CACHESHAPE  = 37,
-    };
+  struct Entry {
+    uint64_t type;
+    uint64_t value;
+
+    Entry() : type(0), value(0) {}
+  };
+
+  /// Constants describing the type of entry.
+  /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX information.
+  enum EntryType {
+    AT_NULL = 0,      ///< End of auxv.
+    AT_IGNORE = 1,    ///< Ignore entry.
+    AT_EXECFD = 2,    ///< File descriptor of program.
+    AT_PHDR = 3,      ///< Program headers.
+    AT_PHENT = 4,     ///< Size of program header.
+    AT_PHNUM = 5,     ///< Number of program headers.
+    AT_PAGESZ = 6,    ///< Page size.
+    AT_BASE = 7,      ///< Interpreter base address.
+    AT_FLAGS = 8,     ///< Flags.
+    AT_ENTRY = 9,     ///< Program entry point.
+    AT_NOTELF = 10,   ///< Set if program is not an ELF.
+    AT_UID = 11,      ///< UID.
+    AT_EUID = 12,     ///< Effective UID.
+    AT_GID = 13,      ///< GID.
+    AT_EGID = 14,     ///< Effective GID.
+    AT_CLKTCK = 17,   ///< Clock frequency (e.g. times(2)).
+    AT_PLATFORM = 15, ///< String identifying platform.
+    AT_HWCAP = 16,    ///< Machine dependent hints about processor capabilities.
+    AT_FPUCW = 18,    ///< Used FPU control word.
+    AT_DCACHEBSIZE = 19,   ///< Data cache block size.
+    AT_ICACHEBSIZE = 20,   ///< Instruction cache block size.
+    AT_UCACHEBSIZE = 21,   ///< Unified cache block size.
+    AT_IGNOREPPC = 22,     ///< Entry should be ignored.
+    AT_SECURE = 23,        ///< Boolean, was exec setuid-like?
+    AT_BASE_PLATFORM = 24, ///< String identifying real platforms.
+    AT_RANDOM = 25,        ///< Address of 16 random bytes.
+    AT_EXECFN = 31,        ///< Filename of executable.
+    AT_SYSINFO = 32, ///< Pointer to the global system page used for system
+                     ///calls and other nice things.
+    AT_SYSINFO_EHDR = 33,
+    AT_L1I_CACHESHAPE = 34, ///< Shapes of the caches.
+    AT_L1D_CACHESHAPE = 35,
+    AT_L2_CACHESHAPE = 36,
+    AT_L3_CACHESHAPE = 37,
+  };
 
 private:
-    typedef std::vector<Entry> EntryVector;
+  typedef std::vector<Entry> EntryVector;
 
 public:
-    typedef EntryVector::const_iterator iterator;
+  typedef EntryVector::const_iterator iterator;
 
-    iterator begin() const { return m_auxv.begin(); }
-    iterator end() const { return m_auxv.end(); }
+  iterator begin() const { return m_auxv.begin(); }
+  iterator end() const { return m_auxv.end(); }
 
-    iterator 
-    FindEntry(EntryType type) const;
+  iterator FindEntry(EntryType type) const;
 
-    static const char *
-    GetEntryName(const Entry &entry) { 
-        return GetEntryName(static_cast<EntryType>(entry.type)); 
-    }
+  static const char *GetEntryName(const Entry &entry) {
+    return GetEntryName(static_cast<EntryType>(entry.type));
+  }
 
-    static const char *
-    GetEntryName(EntryType type);
+  static const char *GetEntryName(EntryType type);
 
-    void
-    DumpToLog(lldb_private::Log *log) const;
+  void DumpToLog(lldb_private::Log *log) const;
 
 private:
-    lldb_private::Process *m_process;
-    EntryVector m_auxv;
+  lldb_private::Process *m_process;
+  EntryVector m_auxv;
 
-    lldb::DataBufferSP
-    GetAuxvData();
+  lldb::DataBufferSP GetAuxvData();
 
-    void
-    ParseAuxv(lldb_private::DataExtractor &data);
+  void ParseAuxv(lldb_private::DataExtractor &data);
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp Tue Sep  6 15:57:50 2016
@@ -30,631 +30,582 @@ using namespace lldb_private;
 
 /// Locates the address of the rendezvous structure.  Returns the address on
 /// success and LLDB_INVALID_ADDRESS on failure.
-static addr_t
-ResolveRendezvousAddress(Process *process)
-{
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-    addr_t info_location;
-    addr_t info_addr;
-    Error error;
+static addr_t ResolveRendezvousAddress(Process *process) {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  addr_t info_location;
+  addr_t info_addr;
+  Error error;
 
-    if (!process)
-    {
-        if (log)
-            log->Printf ("%s null process provided", __FUNCTION__);
-        return LLDB_INVALID_ADDRESS;
-    }
-
-    // Try to get it from our process.  This might be a remote process and might
-    // grab it via some remote-specific mechanism.
-    info_location = process->GetImageInfoAddress();
+  if (!process) {
     if (log)
-        log->Printf ("%s info_location = 0x%" PRIx64, __FUNCTION__, info_location);
+      log->Printf("%s null process provided", __FUNCTION__);
+    return LLDB_INVALID_ADDRESS;
+  }
+
+  // Try to get it from our process.  This might be a remote process and might
+  // grab it via some remote-specific mechanism.
+  info_location = process->GetImageInfoAddress();
+  if (log)
+    log->Printf("%s info_location = 0x%" PRIx64, __FUNCTION__, info_location);
+
+  // If the process fails to return an address, fall back to seeing if the local
+  // object file can help us find it.
+  if (info_location == LLDB_INVALID_ADDRESS) {
+    Target *target = &process->GetTarget();
+    if (target) {
+      ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile();
+      Address addr = obj_file->GetImageInfoAddress(target);
 
-    // If the process fails to return an address, fall back to seeing if the local object file can help us find it.
-    if (info_location == LLDB_INVALID_ADDRESS)
-    {
-        Target *target = &process->GetTarget();
-        if (target)
-        {
-            ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile();
-            Address addr = obj_file->GetImageInfoAddress(target);
-
-            if (addr.IsValid())
-            {
-                info_location = addr.GetLoadAddress(target);
-                if (log)
-                    log->Printf ("%s resolved via direct object file approach to 0x%" PRIx64, __FUNCTION__, info_location);
-            }
-            else
-            {
-                if (log)
-                    log->Printf ("%s FAILED - direct object file approach did not yield a valid address", __FUNCTION__);
-            }
-        }
-    }
-
-    if (info_location == LLDB_INVALID_ADDRESS)
-    {
+      if (addr.IsValid()) {
+        info_location = addr.GetLoadAddress(target);
+        if (log)
+          log->Printf(
+              "%s resolved via direct object file approach to 0x%" PRIx64,
+              __FUNCTION__, info_location);
+      } else {
         if (log)
-            log->Printf ("%s FAILED - invalid info address", __FUNCTION__);
-        return LLDB_INVALID_ADDRESS;
+          log->Printf("%s FAILED - direct object file approach did not yield a "
+                      "valid address",
+                      __FUNCTION__);
+      }
     }
+  }
 
+  if (info_location == LLDB_INVALID_ADDRESS) {
     if (log)
-        log->Printf ("%s reading pointer (%" PRIu32 " bytes) from 0x%" PRIx64, __FUNCTION__, process->GetAddressByteSize(), info_location);
+      log->Printf("%s FAILED - invalid info address", __FUNCTION__);
+    return LLDB_INVALID_ADDRESS;
+  }
+
+  if (log)
+    log->Printf("%s reading pointer (%" PRIu32 " bytes) from 0x%" PRIx64,
+                __FUNCTION__, process->GetAddressByteSize(), info_location);
 
-    info_addr = process->ReadPointerFromMemory(info_location, error);
-    if (error.Fail())
-    {
-        if (log)
-            log->Printf ("%s FAILED - could not read from the info location: %s", __FUNCTION__, error.AsCString ());
-        return LLDB_INVALID_ADDRESS;
-    }
+  info_addr = process->ReadPointerFromMemory(info_location, error);
+  if (error.Fail()) {
+    if (log)
+      log->Printf("%s FAILED - could not read from the info location: %s",
+                  __FUNCTION__, error.AsCString());
+    return LLDB_INVALID_ADDRESS;
+  }
 
-    if (info_addr == 0)
-    {
-        if (log)
-            log->Printf ("%s FAILED - the rendezvous address contained at 0x%" PRIx64 " returned a null value", __FUNCTION__, info_location);
-        return LLDB_INVALID_ADDRESS;
-    }
+  if (info_addr == 0) {
+    if (log)
+      log->Printf("%s FAILED - the rendezvous address contained at 0x%" PRIx64
+                  " returned a null value",
+                  __FUNCTION__, info_location);
+    return LLDB_INVALID_ADDRESS;
+  }
 
-    return info_addr;
+  return info_addr;
 }
 
 DYLDRendezvous::DYLDRendezvous(Process *process)
-    : m_process(process),
-      m_rendezvous_addr(LLDB_INVALID_ADDRESS),
-      m_current(),
-      m_previous(),
-      m_loaded_modules(),
-      m_soentries(),
-      m_added_soentries(),
-      m_removed_soentries()
-{
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-
-    m_thread_info.valid = false;
-
-    // Cache a copy of the executable path
-    if (m_process)
-    {
-        Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();
-        if (exe_mod)
-        {
-            m_exe_file_spec = exe_mod->GetPlatformFileSpec();
-            if (log)
-                log->Printf ("DYLDRendezvous::%s exe module executable path set: '%s'",
-                        __FUNCTION__, m_exe_file_spec.GetCString());
-        }
-        else
-        {
-            if (log)
-                log->Printf ("DYLDRendezvous::%s cannot cache exe module path: null executable module pointer", __FUNCTION__);
-        }
-    }
-}
+    : m_process(process), m_rendezvous_addr(LLDB_INVALID_ADDRESS), m_current(),
+      m_previous(), m_loaded_modules(), m_soentries(), m_added_soentries(),
+      m_removed_soentries() {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+
+  m_thread_info.valid = false;
+
+  // Cache a copy of the executable path
+  if (m_process) {
+    Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();
+    if (exe_mod) {
+      m_exe_file_spec = exe_mod->GetPlatformFileSpec();
+      if (log)
+        log->Printf("DYLDRendezvous::%s exe module executable path set: '%s'",
+                    __FUNCTION__, m_exe_file_spec.GetCString());
+    } else {
+      if (log)
+        log->Printf("DYLDRendezvous::%s cannot cache exe module path: null "
+                    "executable module pointer",
+                    __FUNCTION__);
+    }
+  }
+}
+
+bool DYLDRendezvous::Resolve() {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+
+  const size_t word_size = 4;
+  Rendezvous info;
+  size_t address_size;
+  size_t padding;
+  addr_t info_addr;
+  addr_t cursor;
+
+  address_size = m_process->GetAddressByteSize();
+  padding = address_size - word_size;
+  if (log)
+    log->Printf("DYLDRendezvous::%s address size: %" PRIu64
+                ", padding %" PRIu64,
+                __FUNCTION__, uint64_t(address_size), uint64_t(padding));
+
+  if (m_rendezvous_addr == LLDB_INVALID_ADDRESS)
+    cursor = info_addr = ResolveRendezvousAddress(m_process);
+  else
+    cursor = info_addr = m_rendezvous_addr;
+  if (log)
+    log->Printf("DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__, cursor);
 
-bool
-DYLDRendezvous::Resolve()
-{
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-
-    const size_t word_size = 4;
-    Rendezvous info;
-    size_t address_size;
-    size_t padding;
-    addr_t info_addr;
-    addr_t cursor;
-
-    address_size = m_process->GetAddressByteSize();
-    padding = address_size - word_size;
-    if (log)
-        log->Printf ("DYLDRendezvous::%s address size: %" PRIu64 ", padding %" PRIu64, __FUNCTION__, uint64_t(address_size), uint64_t(padding));
-
-    if (m_rendezvous_addr == LLDB_INVALID_ADDRESS)
-        cursor = info_addr = ResolveRendezvousAddress(m_process);
-    else
-        cursor = info_addr = m_rendezvous_addr;
-    if (log)
-        log->Printf ("DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__, cursor);
-
-    if (cursor == LLDB_INVALID_ADDRESS)
-        return false;
+  if (cursor == LLDB_INVALID_ADDRESS)
+    return false;
 
-    if (!(cursor = ReadWord(cursor, &info.version, word_size)))
-        return false;
+  if (!(cursor = ReadWord(cursor, &info.version, word_size)))
+    return false;
 
-    if (!(cursor = ReadPointer(cursor + padding, &info.map_addr)))
-        return false;
+  if (!(cursor = ReadPointer(cursor + padding, &info.map_addr)))
+    return false;
 
-    if (!(cursor = ReadPointer(cursor, &info.brk)))
-        return false;
+  if (!(cursor = ReadPointer(cursor, &info.brk)))
+    return false;
 
-    if (!(cursor = ReadWord(cursor, &info.state, word_size)))
-        return false;
+  if (!(cursor = ReadWord(cursor, &info.state, word_size)))
+    return false;
 
-    if (!(cursor = ReadPointer(cursor + padding, &info.ldbase)))
-        return false;
+  if (!(cursor = ReadPointer(cursor + padding, &info.ldbase)))
+    return false;
 
-    // The rendezvous was successfully read.  Update our internal state.
-    m_rendezvous_addr = info_addr;
-    m_previous = m_current;
-    m_current = info;
+  // The rendezvous was successfully read.  Update our internal state.
+  m_rendezvous_addr = info_addr;
+  m_previous = m_current;
+  m_current = info;
 
-   if (UpdateSOEntries (true))
-       return true;
+  if (UpdateSOEntries(true))
+    return true;
 
-    return UpdateSOEntries();
+  return UpdateSOEntries();
 }
 
-bool
-DYLDRendezvous::IsValid()
-{
-    return m_rendezvous_addr != LLDB_INVALID_ADDRESS;
+bool DYLDRendezvous::IsValid() {
+  return m_rendezvous_addr != LLDB_INVALID_ADDRESS;
 }
 
-bool
-DYLDRendezvous::UpdateSOEntries(bool fromRemote)
-{
-    SOEntry entry;
-    LoadedModuleInfoList module_list;
-
-    // If we can't get the SO info from the remote, return failure.
-    if (fromRemote && m_process->LoadModules (module_list) == 0)
-        return false;
+bool DYLDRendezvous::UpdateSOEntries(bool fromRemote) {
+  SOEntry entry;
+  LoadedModuleInfoList module_list;
 
-    if (!fromRemote && m_current.map_addr == 0)
-        return false;
+  // If we can't get the SO info from the remote, return failure.
+  if (fromRemote && m_process->LoadModules(module_list) == 0)
+    return false;
 
-    // When the previous and current states are consistent this is the first
-    // time we have been asked to update.  Just take a snapshot of the currently
-    // loaded modules.
-    if (m_previous.state == eConsistent && m_current.state == eConsistent)
-        return fromRemote ? SaveSOEntriesFromRemote(module_list) : TakeSnapshot(m_soentries);
-
-    // If we are about to add or remove a shared object clear out the current
-    // state and take a snapshot of the currently loaded images.
-    if (m_current.state == eAdd || m_current.state == eDelete)
-    {
-        // Some versions of the android dynamic linker might send two
-        // notifications with state == eAdd back to back. Ignore them
-        // until we get an eConsistent notification.
-        if (!(m_previous.state == eConsistent || (m_previous.state == eAdd && m_current.state == eDelete)))
-            return false;
-
-        m_soentries.clear();
-        if (fromRemote)
-            return SaveSOEntriesFromRemote(module_list);
-
-        m_added_soentries.clear();
-        m_removed_soentries.clear();
-        return TakeSnapshot(m_soentries);
-    }
-    assert(m_current.state == eConsistent);
+  if (!fromRemote && m_current.map_addr == 0)
+    return false;
 
-    // Otherwise check the previous state to determine what to expect and update
-    // accordingly.
-    if (m_previous.state == eAdd)
-        return fromRemote ? AddSOEntriesFromRemote(module_list) : AddSOEntries();
-    else if (m_previous.state == eDelete)
-        return fromRemote ? RemoveSOEntriesFromRemote(module_list) : RemoveSOEntries();
+  // When the previous and current states are consistent this is the first
+  // time we have been asked to update.  Just take a snapshot of the currently
+  // loaded modules.
+  if (m_previous.state == eConsistent && m_current.state == eConsistent)
+    return fromRemote ? SaveSOEntriesFromRemote(module_list)
+                      : TakeSnapshot(m_soentries);
+
+  // If we are about to add or remove a shared object clear out the current
+  // state and take a snapshot of the currently loaded images.
+  if (m_current.state == eAdd || m_current.state == eDelete) {
+    // Some versions of the android dynamic linker might send two
+    // notifications with state == eAdd back to back. Ignore them
+    // until we get an eConsistent notification.
+    if (!(m_previous.state == eConsistent ||
+          (m_previous.state == eAdd && m_current.state == eDelete)))
+      return false;
+
+    m_soentries.clear();
+    if (fromRemote)
+      return SaveSOEntriesFromRemote(module_list);
+
+    m_added_soentries.clear();
+    m_removed_soentries.clear();
+    return TakeSnapshot(m_soentries);
+  }
+  assert(m_current.state == eConsistent);
+
+  // Otherwise check the previous state to determine what to expect and update
+  // accordingly.
+  if (m_previous.state == eAdd)
+    return fromRemote ? AddSOEntriesFromRemote(module_list) : AddSOEntries();
+  else if (m_previous.state == eDelete)
+    return fromRemote ? RemoveSOEntriesFromRemote(module_list)
+                      : RemoveSOEntries();
+
+  return false;
+}
+
+bool DYLDRendezvous::FillSOEntryFromModuleInfo(
+    LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry) {
+  addr_t link_map_addr;
+  addr_t base_addr;
+  addr_t dyn_addr;
+  std::string name;
 
+  if (!modInfo.get_link_map(link_map_addr) || !modInfo.get_base(base_addr) ||
+      !modInfo.get_dynamic(dyn_addr) || !modInfo.get_name(name))
     return false;
-}
 
-bool
-DYLDRendezvous::FillSOEntryFromModuleInfo (LoadedModuleInfoList::LoadedModuleInfo const & modInfo,
-                                           SOEntry &entry)
-{
-    addr_t link_map_addr;
-    addr_t base_addr;
-    addr_t dyn_addr;
-    std::string name;
-
-    if (!modInfo.get_link_map (link_map_addr) ||
-        !modInfo.get_base (base_addr) ||
-        !modInfo.get_dynamic (dyn_addr) ||
-        !modInfo.get_name (name))
-        return false;
+  entry.link_addr = link_map_addr;
+  entry.base_addr = base_addr;
+  entry.dyn_addr = dyn_addr;
 
-    entry.link_addr = link_map_addr;
-    entry.base_addr = base_addr;
-    entry.dyn_addr = dyn_addr;
-
-    entry.file_spec.SetFile(name, false);
-
-    UpdateBaseAddrIfNecessary(entry, name);
-
-    // not needed if we're using ModuleInfos
-    entry.next = 0;
-    entry.prev = 0;
-    entry.path_addr = 0;
+  entry.file_spec.SetFile(name, false);
 
-    return true;
-}
-
-bool
-DYLDRendezvous::SaveSOEntriesFromRemote(LoadedModuleInfoList &module_list)
-{
-    for (auto const & modInfo : module_list.m_list)
-    {
-        SOEntry entry;
-        if (!FillSOEntryFromModuleInfo(modInfo, entry))
-            return false;
-
-        // Only add shared libraries and not the executable.
-        if (!SOEntryIsMainExecutable(entry))
-            m_soentries.push_back(entry);
-    }
+  UpdateBaseAddrIfNecessary(entry, name);
 
-    m_loaded_modules = module_list;
-    return true;
+  // not needed if we're using ModuleInfos
+  entry.next = 0;
+  entry.prev = 0;
+  entry.path_addr = 0;
 
+  return true;
 }
 
-bool
-DYLDRendezvous::AddSOEntriesFromRemote(LoadedModuleInfoList &module_list)
-{
-    for (auto const & modInfo : module_list.m_list)
-    {
-        bool found = false;
-        for (auto const & existing : m_loaded_modules.m_list)
-        {
-            if (modInfo == existing)
-            {
-                found = true;
-                break;
-            }
-        }
-
-        if (found)
-            continue;
-
-        SOEntry entry;
-        if (!FillSOEntryFromModuleInfo(modInfo, entry))
-            return false;
-
-        // Only add shared libraries and not the executable.
-        if (!SOEntryIsMainExecutable(entry))
-            m_soentries.push_back(entry);
+bool DYLDRendezvous::SaveSOEntriesFromRemote(
+    LoadedModuleInfoList &module_list) {
+  for (auto const &modInfo : module_list.m_list) {
+    SOEntry entry;
+    if (!FillSOEntryFromModuleInfo(modInfo, entry))
+      return false;
+
+    // Only add shared libraries and not the executable.
+    if (!SOEntryIsMainExecutable(entry))
+      m_soentries.push_back(entry);
+  }
+
+  m_loaded_modules = module_list;
+  return true;
+}
+
+bool DYLDRendezvous::AddSOEntriesFromRemote(LoadedModuleInfoList &module_list) {
+  for (auto const &modInfo : module_list.m_list) {
+    bool found = false;
+    for (auto const &existing : m_loaded_modules.m_list) {
+      if (modInfo == existing) {
+        found = true;
+        break;
+      }
     }
 
-    m_loaded_modules = module_list;
-    return true;
-}
+    if (found)
+      continue;
 
-bool
-DYLDRendezvous::RemoveSOEntriesFromRemote(LoadedModuleInfoList &module_list)
-{
-    for (auto const & existing : m_loaded_modules.m_list)
-    {
-        bool found = false;
-        for (auto const & modInfo : module_list.m_list)
-        {
-            if (modInfo == existing)
-            {
-                found = true;
-                break;
-            }
-        }
-
-        if (found)
-            continue;
-
-        SOEntry entry;
-        if (!FillSOEntryFromModuleInfo(existing, entry))
-            return false;
-
-        // Only add shared libraries and not the executable.
-        if (!SOEntryIsMainExecutable(entry))
-        {
-            auto pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
-            if (pos == m_soentries.end())
-                return false;
+    SOEntry entry;
+    if (!FillSOEntryFromModuleInfo(modInfo, entry))
+      return false;
 
-            m_soentries.erase(pos);
-        }
+    // Only add shared libraries and not the executable.
+    if (!SOEntryIsMainExecutable(entry))
+      m_soentries.push_back(entry);
+  }
+
+  m_loaded_modules = module_list;
+  return true;
+}
+
+bool DYLDRendezvous::RemoveSOEntriesFromRemote(
+    LoadedModuleInfoList &module_list) {
+  for (auto const &existing : m_loaded_modules.m_list) {
+    bool found = false;
+    for (auto const &modInfo : module_list.m_list) {
+      if (modInfo == existing) {
+        found = true;
+        break;
+      }
     }
 
-    m_loaded_modules = module_list;
-    return true;
-}
+    if (found)
+      continue;
 
-bool
-DYLDRendezvous::AddSOEntries()
-{
     SOEntry entry;
-    iterator pos;
-
-    assert(m_previous.state == eAdd);
+    if (!FillSOEntryFromModuleInfo(existing, entry))
+      return false;
 
-    if (m_current.map_addr == 0)
+    // Only add shared libraries and not the executable.
+    if (!SOEntryIsMainExecutable(entry)) {
+      auto pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
+      if (pos == m_soentries.end())
         return false;
 
-    for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next)
-    {
-        if (!ReadSOEntryFromMemory(cursor, entry))
-            return false;
-
-        // Only add shared libraries and not the executable.
-        if (SOEntryIsMainExecutable(entry))
-            continue;
-
-        pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
-        if (pos == m_soentries.end())
-        {
-            m_soentries.push_back(entry);
-            m_added_soentries.push_back(entry);
-        }
+      m_soentries.erase(pos);
     }
+  }
 
-    return true;
+  m_loaded_modules = module_list;
+  return true;
 }
 
-bool
-DYLDRendezvous::RemoveSOEntries()
-{
-    SOEntryList entry_list;
-    iterator pos;
+bool DYLDRendezvous::AddSOEntries() {
+  SOEntry entry;
+  iterator pos;
 
-    assert(m_previous.state == eDelete);
+  assert(m_previous.state == eAdd);
 
-    if (!TakeSnapshot(entry_list))
-        return false;
+  if (m_current.map_addr == 0)
+    return false;
+
+  for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
+    if (!ReadSOEntryFromMemory(cursor, entry))
+      return false;
+
+    // Only add shared libraries and not the executable.
+    if (SOEntryIsMainExecutable(entry))
+      continue;
 
-    for (iterator I = begin(); I != end(); ++I)
-    {
-        pos = std::find(entry_list.begin(), entry_list.end(), *I);
-        if (pos == entry_list.end())
-            m_removed_soentries.push_back(*I);
+    pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
+    if (pos == m_soentries.end()) {
+      m_soentries.push_back(entry);
+      m_added_soentries.push_back(entry);
     }
+  }
 
-    m_soentries = entry_list;
-    return true;
+  return true;
 }
 
-bool
-DYLDRendezvous::SOEntryIsMainExecutable(const SOEntry &entry)
-{
-    // On Linux the executable is indicated by an empty path in the entry. On
-    // FreeBSD and on Android it is the full path to the executable.
-
-    auto triple = m_process->GetTarget().GetArchitecture().GetTriple();
-    switch (triple.getOS())
-    {
-        case llvm::Triple::FreeBSD:
-            return entry.file_spec == m_exe_file_spec;
-        case llvm::Triple::Linux:
-            if (triple.isAndroid())
-                return entry.file_spec == m_exe_file_spec;
-            return !entry.file_spec;
-        default:
-            return false;
-    }
+bool DYLDRendezvous::RemoveSOEntries() {
+  SOEntryList entry_list;
+  iterator pos;
+
+  assert(m_previous.state == eDelete);
+
+  if (!TakeSnapshot(entry_list))
+    return false;
+
+  for (iterator I = begin(); I != end(); ++I) {
+    pos = std::find(entry_list.begin(), entry_list.end(), *I);
+    if (pos == entry_list.end())
+      m_removed_soentries.push_back(*I);
+  }
+
+  m_soentries = entry_list;
+  return true;
+}
+
+bool DYLDRendezvous::SOEntryIsMainExecutable(const SOEntry &entry) {
+  // On Linux the executable is indicated by an empty path in the entry. On
+  // FreeBSD and on Android it is the full path to the executable.
+
+  auto triple = m_process->GetTarget().GetArchitecture().GetTriple();
+  switch (triple.getOS()) {
+  case llvm::Triple::FreeBSD:
+    return entry.file_spec == m_exe_file_spec;
+  case llvm::Triple::Linux:
+    if (triple.isAndroid())
+      return entry.file_spec == m_exe_file_spec;
+    return !entry.file_spec;
+  default:
+    return false;
+  }
 }
 
-bool
-DYLDRendezvous::TakeSnapshot(SOEntryList &entry_list)
-{
-    SOEntry entry;
+bool DYLDRendezvous::TakeSnapshot(SOEntryList &entry_list) {
+  SOEntry entry;
 
-    if (m_current.map_addr == 0)
-        return false;
+  if (m_current.map_addr == 0)
+    return false;
 
-    // Clear previous entries since we are about to obtain an up to date list.
-    entry_list.clear();
+  // Clear previous entries since we are about to obtain an up to date list.
+  entry_list.clear();
 
-    for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next)
-    {
-        if (!ReadSOEntryFromMemory(cursor, entry))
-            return false;
-
-        // Only add shared libraries and not the executable.
-        if (SOEntryIsMainExecutable(entry))
-            continue;
+  for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
+    if (!ReadSOEntryFromMemory(cursor, entry))
+      return false;
 
-        entry_list.push_back(entry);
-    }
+    // Only add shared libraries and not the executable.
+    if (SOEntryIsMainExecutable(entry))
+      continue;
 
-    return true;
+    entry_list.push_back(entry);
+  }
+
+  return true;
 }
 
-addr_t
-DYLDRendezvous::ReadWord(addr_t addr, uint64_t *dst, size_t size)
-{
-    Error error;
-
-    *dst = m_process->ReadUnsignedIntegerFromMemory(addr, size, 0, error);
-    if (error.Fail())
-        return 0;
-
-    return addr + size;
-}
-
-addr_t
-DYLDRendezvous::ReadPointer(addr_t addr, addr_t *dst)
-{
-    Error error;
- 
-    *dst = m_process->ReadPointerFromMemory(addr, error);
-    if (error.Fail())
-        return 0;
-
-    return addr + m_process->GetAddressByteSize();
-}
-
-std::string
-DYLDRendezvous::ReadStringFromMemory(addr_t addr)
-{
-    std::string str;
-    Error error;
-
-    if (addr == LLDB_INVALID_ADDRESS)
-        return std::string();
-
-    m_process->ReadCStringFromMemory(addr, str, error);
-
-    return str;
-}
-
-// Returns true if the load bias reported by the linker is incorrect for the given entry. This
-// function is used to handle cases where we want to work around a bug in the system linker.
-static bool
-isLoadBiasIncorrect(Target& target, const std::string& file_path)
-{
-    // On Android L (API 21, 22) the load address of the "/system/bin/linker" isn't filled in
-    // correctly.
-    uint32_t os_major = 0, os_minor = 0, os_update = 0;
-    if (target.GetArchitecture().GetTriple().isAndroid() &&
-        target.GetPlatform()->GetOSVersion(os_major, os_minor, os_update) &&
-        (os_major == 21 || os_major == 22) &&
-        (file_path == "/system/bin/linker" || file_path == "/system/bin/linker64"))
-    {
-        return true;
-    }
+addr_t DYLDRendezvous::ReadWord(addr_t addr, uint64_t *dst, size_t size) {
+  Error error;
 
-    return false;
+  *dst = m_process->ReadUnsignedIntegerFromMemory(addr, size, 0, error);
+  if (error.Fail())
+    return 0;
+
+  return addr + size;
 }
 
-void
-DYLDRendezvous::UpdateBaseAddrIfNecessary(SOEntry &entry, std::string const &file_path)
-{
-    // If the load bias reported by the linker is incorrect then fetch the load address of the file
-    // from the proc file system.
-    if (isLoadBiasIncorrect(m_process->GetTarget(), file_path))
-    {
-        lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
-        bool is_loaded = false;
-        Error error = m_process->GetFileLoadAddress(entry.file_spec, is_loaded, load_addr);
-        if (error.Success() && is_loaded)
-            entry.base_addr = load_addr;
-    }
+addr_t DYLDRendezvous::ReadPointer(addr_t addr, addr_t *dst) {
+  Error error;
+
+  *dst = m_process->ReadPointerFromMemory(addr, error);
+  if (error.Fail())
+    return 0;
+
+  return addr + m_process->GetAddressByteSize();
 }
 
-bool
-DYLDRendezvous::ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry)
-{
-    entry.clear();
-
-    entry.link_addr = addr;
-    
-    if (!(addr = ReadPointer(addr, &entry.base_addr)))
-        return false;
+std::string DYLDRendezvous::ReadStringFromMemory(addr_t addr) {
+  std::string str;
+  Error error;
 
-    // mips adds an extra load offset field to the link map struct on
-    // FreeBSD and NetBSD (need to validate other OSes).
-    // http://svnweb.freebsd.org/base/head/sys/sys/link_elf.h?revision=217153&view=markup#l57
-    const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
-    if ((arch.GetTriple().getOS() == llvm::Triple::FreeBSD 
-        || arch.GetTriple().getOS() == llvm::Triple::NetBSD) && 
-        (arch.GetMachine() == llvm::Triple::mips || arch.GetMachine() == llvm::Triple::mipsel
-        || arch.GetMachine() == llvm::Triple::mips64 || arch.GetMachine() == llvm::Triple::mips64el))
-    {
-        addr_t mips_l_offs;
-        if (!(addr = ReadPointer(addr, &mips_l_offs)))
-            return false;
-        if (mips_l_offs != 0 && mips_l_offs != entry.base_addr)
-            return false;
-    }
-    
-    if (!(addr = ReadPointer(addr, &entry.path_addr)))
-        return false;
-    
-    if (!(addr = ReadPointer(addr, &entry.dyn_addr)))
-        return false;
-    
-    if (!(addr = ReadPointer(addr, &entry.next)))
-        return false;
-    
-    if (!(addr = ReadPointer(addr, &entry.prev)))
-        return false;
+  if (addr == LLDB_INVALID_ADDRESS)
+    return std::string();
 
-    std::string file_path = ReadStringFromMemory(entry.path_addr);
-    entry.file_spec.SetFile(file_path, false);
+  m_process->ReadCStringFromMemory(addr, str, error);
 
-    UpdateBaseAddrIfNecessary(entry, file_path);
+  return str;
+}
 
+// Returns true if the load bias reported by the linker is incorrect for the
+// given entry. This
+// function is used to handle cases where we want to work around a bug in the
+// system linker.
+static bool isLoadBiasIncorrect(Target &target, const std::string &file_path) {
+  // On Android L (API 21, 22) the load address of the "/system/bin/linker"
+  // isn't filled in
+  // correctly.
+  uint32_t os_major = 0, os_minor = 0, os_update = 0;
+  if (target.GetArchitecture().GetTriple().isAndroid() &&
+      target.GetPlatform()->GetOSVersion(os_major, os_minor, os_update) &&
+      (os_major == 21 || os_major == 22) &&
+      (file_path == "/system/bin/linker" ||
+       file_path == "/system/bin/linker64")) {
     return true;
+  }
+
+  return false;
 }
 
+void DYLDRendezvous::UpdateBaseAddrIfNecessary(SOEntry &entry,
+                                               std::string const &file_path) {
+  // If the load bias reported by the linker is incorrect then fetch the load
+  // address of the file
+  // from the proc file system.
+  if (isLoadBiasIncorrect(m_process->GetTarget(), file_path)) {
+    lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
+    bool is_loaded = false;
+    Error error =
+        m_process->GetFileLoadAddress(entry.file_spec, is_loaded, load_addr);
+    if (error.Success() && is_loaded)
+      entry.base_addr = load_addr;
+  }
+}
 
-bool
-DYLDRendezvous::FindMetadata(const char *name, PThreadField field, uint32_t& value)
-{
-    Target& target = m_process->GetTarget();
+bool DYLDRendezvous::ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry) {
+  entry.clear();
 
-    SymbolContextList list;
-    if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), eSymbolTypeAny, list))
-        return false;
+  entry.link_addr = addr;
 
-    Address address = list[0].symbol->GetAddress();
-    addr_t addr = address.GetLoadAddress (&target);
-    if (addr == LLDB_INVALID_ADDRESS)
-        return false;
+  if (!(addr = ReadPointer(addr, &entry.base_addr)))
+    return false;
 
-    Error error;
-    value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(addr + field*sizeof(uint32_t), sizeof(uint32_t), 0, error);
-    if (error.Fail())
-        return false;
+  // mips adds an extra load offset field to the link map struct on
+  // FreeBSD and NetBSD (need to validate other OSes).
+  // http://svnweb.freebsd.org/base/head/sys/sys/link_elf.h?revision=217153&view=markup#l57
+  const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
+  if ((arch.GetTriple().getOS() == llvm::Triple::FreeBSD ||
+       arch.GetTriple().getOS() == llvm::Triple::NetBSD) &&
+      (arch.GetMachine() == llvm::Triple::mips ||
+       arch.GetMachine() == llvm::Triple::mipsel ||
+       arch.GetMachine() == llvm::Triple::mips64 ||
+       arch.GetMachine() == llvm::Triple::mips64el)) {
+    addr_t mips_l_offs;
+    if (!(addr = ReadPointer(addr, &mips_l_offs)))
+      return false;
+    if (mips_l_offs != 0 && mips_l_offs != entry.base_addr)
+      return false;
+  }
 
-    if (field == eSize)
-        value /= 8; // convert bits to bytes
+  if (!(addr = ReadPointer(addr, &entry.path_addr)))
+    return false;
 
-    return true;
+  if (!(addr = ReadPointer(addr, &entry.dyn_addr)))
+    return false;
+
+  if (!(addr = ReadPointer(addr, &entry.next)))
+    return false;
+
+  if (!(addr = ReadPointer(addr, &entry.prev)))
+    return false;
+
+  std::string file_path = ReadStringFromMemory(entry.path_addr);
+  entry.file_spec.SetFile(file_path, false);
+
+  UpdateBaseAddrIfNecessary(entry, file_path);
+
+  return true;
 }
 
-const DYLDRendezvous::ThreadInfo&
-DYLDRendezvous::GetThreadInfo()
-{
-    if (!m_thread_info.valid)
-    {
-        bool ok = true;
-
-        ok &= FindMetadata ("_thread_db_pthread_dtvp", eOffset, m_thread_info.dtv_offset);
-        ok &= FindMetadata ("_thread_db_dtv_dtv", eSize, m_thread_info.dtv_slot_size);
-        ok &= FindMetadata ("_thread_db_link_map_l_tls_modid", eOffset, m_thread_info.modid_offset);
-        ok &= FindMetadata ("_thread_db_dtv_t_pointer_val", eOffset, m_thread_info.tls_offset);
+bool DYLDRendezvous::FindMetadata(const char *name, PThreadField field,
+                                  uint32_t &value) {
+  Target &target = m_process->GetTarget();
 
-        if (ok)
-            m_thread_info.valid = true;
-    }
+  SymbolContextList list;
+  if (!target.GetImages().FindSymbolsWithNameAndType(ConstString(name),
+                                                     eSymbolTypeAny, list))
+    return false;
 
-    return m_thread_info;
+  Address address = list[0].symbol->GetAddress();
+  addr_t addr = address.GetLoadAddress(&target);
+  if (addr == LLDB_INVALID_ADDRESS)
+    return false;
+
+  Error error;
+  value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
+      addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
+  if (error.Fail())
+    return false;
+
+  if (field == eSize)
+    value /= 8; // convert bits to bytes
+
+  return true;
 }
 
-void
-DYLDRendezvous::DumpToLog(Log *log) const
-{
-    int state = GetState();
-
-    if (!log)
-        return;
-
-    log->PutCString("DYLDRendezvous:");
-    log->Printf("   Address: %" PRIx64, GetRendezvousAddress());
-    log->Printf("   Version: %" PRIu64, GetVersion());
-    log->Printf("   Link   : %" PRIx64, GetLinkMapAddress());
-    log->Printf("   Break  : %" PRIx64, GetBreakAddress());
-    log->Printf("   LDBase : %" PRIx64, GetLDBase());
-    log->Printf("   State  : %s", 
-                (state == eConsistent) ? "consistent" :
-                (state == eAdd)        ? "add"        :
-                (state == eDelete)     ? "delete"     : "unknown");
-    
-    iterator I = begin();
-    iterator E = end();
-
-    if (I != E) 
-        log->PutCString("DYLDRendezvous SOEntries:");
-    
-    for (int i = 1; I != E; ++I, ++i) 
-    {
-        log->Printf("\n   SOEntry [%d] %s", i, I->file_spec.GetCString());
-        log->Printf("      Base : %" PRIx64, I->base_addr);
-        log->Printf("      Path : %" PRIx64, I->path_addr);
-        log->Printf("      Dyn  : %" PRIx64, I->dyn_addr);
-        log->Printf("      Next : %" PRIx64, I->next);
-        log->Printf("      Prev : %" PRIx64, I->prev);
-    }
+const DYLDRendezvous::ThreadInfo &DYLDRendezvous::GetThreadInfo() {
+  if (!m_thread_info.valid) {
+    bool ok = true;
+
+    ok &= FindMetadata("_thread_db_pthread_dtvp", eOffset,
+                       m_thread_info.dtv_offset);
+    ok &=
+        FindMetadata("_thread_db_dtv_dtv", eSize, m_thread_info.dtv_slot_size);
+    ok &= FindMetadata("_thread_db_link_map_l_tls_modid", eOffset,
+                       m_thread_info.modid_offset);
+    ok &= FindMetadata("_thread_db_dtv_t_pointer_val", eOffset,
+                       m_thread_info.tls_offset);
+
+    if (ok)
+      m_thread_info.valid = true;
+  }
+
+  return m_thread_info;
+}
+
+void DYLDRendezvous::DumpToLog(Log *log) const {
+  int state = GetState();
+
+  if (!log)
+    return;
+
+  log->PutCString("DYLDRendezvous:");
+  log->Printf("   Address: %" PRIx64, GetRendezvousAddress());
+  log->Printf("   Version: %" PRIu64, GetVersion());
+  log->Printf("   Link   : %" PRIx64, GetLinkMapAddress());
+  log->Printf("   Break  : %" PRIx64, GetBreakAddress());
+  log->Printf("   LDBase : %" PRIx64, GetLDBase());
+  log->Printf("   State  : %s",
+              (state == eConsistent)
+                  ? "consistent"
+                  : (state == eAdd) ? "add" : (state == eDelete) ? "delete"
+                                                                 : "unknown");
+
+  iterator I = begin();
+  iterator E = end();
+
+  if (I != E)
+    log->PutCString("DYLDRendezvous SOEntries:");
+
+  for (int i = 1; I != E; ++I, ++i) {
+    log->Printf("\n   SOEntry [%d] %s", i, I->file_spec.GetCString());
+    log->Printf("      Base : %" PRIx64, I->base_addr);
+    log->Printf("      Path : %" PRIx64, I->path_addr);
+    log->Printf("      Dyn  : %" PRIx64, I->dyn_addr);
+    log->Printf("      Next : %" PRIx64, I->next);
+    log->Printf("      Prev : %" PRIx64, I->prev);
+  }
 }

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h Tue Sep  6 15:57:50 2016
@@ -16,9 +16,9 @@
 #include <string>
 
 // Other libraries and framework includes
+#include "lldb/Host/FileSpec.h"
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-types.h"
-#include "lldb/Host/FileSpec.h"
 
 #include "lldb/Core/LoadedModuleInfoList.h"
 
@@ -37,251 +37,220 @@ class Process;
 /// currently loaded modules.
 class DYLDRendezvous {
 
-    // This structure is used to hold the contents of the debug rendezvous
-    // information (struct r_debug) as found in the inferiors memory.  Note that
-    // the layout of this struct is not binary compatible, it is simply large
-    // enough to hold the information on both 32 and 64 bit platforms.
-    struct Rendezvous {
-        uint64_t     version;
-        lldb::addr_t map_addr;
-        lldb::addr_t brk;
-        uint64_t     state;
-        lldb::addr_t ldbase;
-
-        Rendezvous()
-            : version(0), map_addr(0), brk(0), state(0), ldbase(0) { }
-    };
+  // This structure is used to hold the contents of the debug rendezvous
+  // information (struct r_debug) as found in the inferiors memory.  Note that
+  // the layout of this struct is not binary compatible, it is simply large
+  // enough to hold the information on both 32 and 64 bit platforms.
+  struct Rendezvous {
+    uint64_t version;
+    lldb::addr_t map_addr;
+    lldb::addr_t brk;
+    uint64_t state;
+    lldb::addr_t ldbase;
+
+    Rendezvous() : version(0), map_addr(0), brk(0), state(0), ldbase(0) {}
+  };
 
 public:
-    // Various metadata supplied by the inferior's threading library to describe
-    // the per-thread state.
-    struct ThreadInfo {
-        bool     valid;         // whether we read valid metadata
-        uint32_t dtv_offset;    // offset of DTV pointer within pthread
-        uint32_t dtv_slot_size; // size of one DTV slot
-        uint32_t modid_offset;  // offset of module ID within link_map
-        uint32_t tls_offset;    // offset of TLS pointer within DTV slot
-    };
-
-    DYLDRendezvous(lldb_private::Process *process);
-
-    /// Update the internal snapshot of runtime linker rendezvous and recompute
-    /// the currently loaded modules.
-    ///
-    /// This method should be called once one start up, then once each time the
-    /// runtime linker enters the function given by GetBreakAddress().
-    ///
-    /// @returns true on success and false on failure.
-    ///
-    /// @see GetBreakAddress().
-    bool 
-    Resolve();
-
-    /// @returns true if this rendezvous has been located in the inferiors
-    /// address space and false otherwise.
-    bool 
-    IsValid();
-
-    /// @returns the address of the rendezvous structure in the inferiors
-    /// address space.
-    lldb::addr_t
-    GetRendezvousAddress() const { return m_rendezvous_addr; }
-
-    /// @returns the version of the rendezvous protocol being used.
-    uint64_t
-    GetVersion() const { return m_current.version; }
-
-    /// @returns address in the inferiors address space containing the linked
-    /// list of shared object descriptors.
-    lldb::addr_t 
-    GetLinkMapAddress() const { return m_current.map_addr; }
-
-    /// A breakpoint should be set at this address and Resolve called on each
-    /// hit.
-    ///
-    /// @returns the address of a function called by the runtime linker each
-    /// time a module is loaded/unloaded, or about to be loaded/unloaded.
-    ///
-    /// @see Resolve()
-    lldb::addr_t
-    GetBreakAddress() const { return m_current.brk; }
-
-    /// Returns the current state of the rendezvous structure.
-    uint64_t
-    GetState() const { return m_current.state; }
-
-    /// @returns the base address of the runtime linker in the inferiors address
-    /// space.
-    lldb::addr_t
-    GetLDBase() const { return m_current.ldbase; }
-
-    /// @returns the thread layout metadata from the inferiors thread library.
-    const ThreadInfo&
-    GetThreadInfo();
-
-    /// @returns true if modules have been loaded into the inferior since the
-    /// last call to Resolve().
-    bool
-    ModulesDidLoad() const { return !m_added_soentries.empty(); }
-
-    /// @returns true if modules have been unloaded from the inferior since the
-    /// last call to Resolve().
-    bool
-    ModulesDidUnload() const { return !m_removed_soentries.empty(); }
-
-    void
-    DumpToLog(lldb_private::Log *log) const;
-
-    /// @brief Constants describing the state of the rendezvous.
-    ///
-    /// @see GetState().
-    enum RendezvousState {
-        eConsistent,
-        eAdd,
-        eDelete
-    };
-
-    /// @brief Structure representing the shared objects currently loaded into
-    /// the inferior process.
-    ///
-    /// This object is a rough analogue to the struct link_map object which
-    /// actually lives in the inferiors memory.
-    struct SOEntry {
-        lldb::addr_t link_addr;           ///< Address of this link_map.
-        lldb::addr_t base_addr;           ///< Base address of the loaded object.
-        lldb::addr_t path_addr;           ///< String naming the shared object.
-        lldb::addr_t dyn_addr;            ///< Dynamic section of shared object.
-        lldb::addr_t next;                ///< Address of next so_entry.
-        lldb::addr_t prev;                ///< Address of previous so_entry.
-        lldb_private::FileSpec file_spec; ///< File spec of shared object.
-
-        SOEntry() { clear(); }
-
-        bool operator ==(const SOEntry &entry) {
-            return file_spec == entry.file_spec;
-        }
-
-        void clear() {
-            link_addr = 0;
-            base_addr = 0;
-            path_addr = 0;
-            dyn_addr  = 0;
-            next = 0;
-            prev = 0;
-            file_spec.Clear();
-        }
-    };
+  // Various metadata supplied by the inferior's threading library to describe
+  // the per-thread state.
+  struct ThreadInfo {
+    bool valid;             // whether we read valid metadata
+    uint32_t dtv_offset;    // offset of DTV pointer within pthread
+    uint32_t dtv_slot_size; // size of one DTV slot
+    uint32_t modid_offset;  // offset of module ID within link_map
+    uint32_t tls_offset;    // offset of TLS pointer within DTV slot
+  };
+
+  DYLDRendezvous(lldb_private::Process *process);
+
+  /// Update the internal snapshot of runtime linker rendezvous and recompute
+  /// the currently loaded modules.
+  ///
+  /// This method should be called once one start up, then once each time the
+  /// runtime linker enters the function given by GetBreakAddress().
+  ///
+  /// @returns true on success and false on failure.
+  ///
+  /// @see GetBreakAddress().
+  bool Resolve();
+
+  /// @returns true if this rendezvous has been located in the inferiors
+  /// address space and false otherwise.
+  bool IsValid();
+
+  /// @returns the address of the rendezvous structure in the inferiors
+  /// address space.
+  lldb::addr_t GetRendezvousAddress() const { return m_rendezvous_addr; }
+
+  /// @returns the version of the rendezvous protocol being used.
+  uint64_t GetVersion() const { return m_current.version; }
+
+  /// @returns address in the inferiors address space containing the linked
+  /// list of shared object descriptors.
+  lldb::addr_t GetLinkMapAddress() const { return m_current.map_addr; }
+
+  /// A breakpoint should be set at this address and Resolve called on each
+  /// hit.
+  ///
+  /// @returns the address of a function called by the runtime linker each
+  /// time a module is loaded/unloaded, or about to be loaded/unloaded.
+  ///
+  /// @see Resolve()
+  lldb::addr_t GetBreakAddress() const { return m_current.brk; }
+
+  /// Returns the current state of the rendezvous structure.
+  uint64_t GetState() const { return m_current.state; }
+
+  /// @returns the base address of the runtime linker in the inferiors address
+  /// space.
+  lldb::addr_t GetLDBase() const { return m_current.ldbase; }
+
+  /// @returns the thread layout metadata from the inferiors thread library.
+  const ThreadInfo &GetThreadInfo();
+
+  /// @returns true if modules have been loaded into the inferior since the
+  /// last call to Resolve().
+  bool ModulesDidLoad() const { return !m_added_soentries.empty(); }
+
+  /// @returns true if modules have been unloaded from the inferior since the
+  /// last call to Resolve().
+  bool ModulesDidUnload() const { return !m_removed_soentries.empty(); }
+
+  void DumpToLog(lldb_private::Log *log) const;
+
+  /// @brief Constants describing the state of the rendezvous.
+  ///
+  /// @see GetState().
+  enum RendezvousState { eConsistent, eAdd, eDelete };
+
+  /// @brief Structure representing the shared objects currently loaded into
+  /// the inferior process.
+  ///
+  /// This object is a rough analogue to the struct link_map object which
+  /// actually lives in the inferiors memory.
+  struct SOEntry {
+    lldb::addr_t link_addr;           ///< Address of this link_map.
+    lldb::addr_t base_addr;           ///< Base address of the loaded object.
+    lldb::addr_t path_addr;           ///< String naming the shared object.
+    lldb::addr_t dyn_addr;            ///< Dynamic section of shared object.
+    lldb::addr_t next;                ///< Address of next so_entry.
+    lldb::addr_t prev;                ///< Address of previous so_entry.
+    lldb_private::FileSpec file_spec; ///< File spec of shared object.
+
+    SOEntry() { clear(); }
+
+    bool operator==(const SOEntry &entry) {
+      return file_spec == entry.file_spec;
+    }
+
+    void clear() {
+      link_addr = 0;
+      base_addr = 0;
+      path_addr = 0;
+      dyn_addr = 0;
+      next = 0;
+      prev = 0;
+      file_spec.Clear();
+    }
+  };
 
 protected:
-    typedef std::list<SOEntry> SOEntryList;
+  typedef std::list<SOEntry> SOEntryList;
 
 public:
-    typedef SOEntryList::const_iterator iterator;
+  typedef SOEntryList::const_iterator iterator;
+
+  /// Iterators over all currently loaded modules.
+  iterator begin() const { return m_soentries.begin(); }
+  iterator end() const { return m_soentries.end(); }
+
+  /// Iterators over all modules loaded into the inferior since the last call
+  /// to Resolve().
+  iterator loaded_begin() const { return m_added_soentries.begin(); }
+  iterator loaded_end() const { return m_added_soentries.end(); }
+
+  /// Iterators over all modules unloaded from the inferior since the last
+  /// call to Resolve().
+  iterator unloaded_begin() const { return m_removed_soentries.begin(); }
+  iterator unloaded_end() const { return m_removed_soentries.end(); }
 
-    /// Iterators over all currently loaded modules.
-    iterator begin() const { return m_soentries.begin(); }
-    iterator end() const { return m_soentries.end(); }
-
-    /// Iterators over all modules loaded into the inferior since the last call
-    /// to Resolve().
-    iterator loaded_begin() const { return m_added_soentries.begin(); }
-    iterator loaded_end() const { return m_added_soentries.end(); }
-
-    /// Iterators over all modules unloaded from the inferior since the last
-    /// call to Resolve().
-    iterator unloaded_begin() const { return m_removed_soentries.begin(); }
-    iterator unloaded_end() const { return m_removed_soentries.end(); }
-    
 protected:
-    lldb_private::Process *m_process;
+  lldb_private::Process *m_process;
 
-    // Cached copy of executable file spec
-    lldb_private::FileSpec m_exe_file_spec;
+  // Cached copy of executable file spec
+  lldb_private::FileSpec m_exe_file_spec;
 
-    /// Location of the r_debug structure in the inferiors address space.
-    lldb::addr_t m_rendezvous_addr;
+  /// Location of the r_debug structure in the inferiors address space.
+  lldb::addr_t m_rendezvous_addr;
 
-    /// Current and previous snapshots of the rendezvous structure.
-    Rendezvous m_current;
-    Rendezvous m_previous;
+  /// Current and previous snapshots of the rendezvous structure.
+  Rendezvous m_current;
+  Rendezvous m_previous;
 
-    /// List of currently loaded SO modules
-    LoadedModuleInfoList m_loaded_modules;
+  /// List of currently loaded SO modules
+  LoadedModuleInfoList m_loaded_modules;
 
-    /// List of SOEntry objects corresponding to the current link map state.
-    SOEntryList m_soentries;
+  /// List of SOEntry objects corresponding to the current link map state.
+  SOEntryList m_soentries;
 
-    /// List of SOEntry's added to the link map since the last call to Resolve().
-    SOEntryList m_added_soentries;
+  /// List of SOEntry's added to the link map since the last call to Resolve().
+  SOEntryList m_added_soentries;
 
-    /// List of SOEntry's removed from the link map since the last call to
-    /// Resolve().
-    SOEntryList m_removed_soentries;
+  /// List of SOEntry's removed from the link map since the last call to
+  /// Resolve().
+  SOEntryList m_removed_soentries;
 
-    /// Threading metadata read from the inferior.
-    ThreadInfo  m_thread_info;
+  /// Threading metadata read from the inferior.
+  ThreadInfo m_thread_info;
 
-    /// Reads an unsigned integer of @p size bytes from the inferior's address
-    /// space starting at @p addr.
-    ///
-    /// @returns addr + size if the read was successful and false otherwise.
-    lldb::addr_t
-    ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size);
+  /// Reads an unsigned integer of @p size bytes from the inferior's address
+  /// space starting at @p addr.
+  ///
+  /// @returns addr + size if the read was successful and false otherwise.
+  lldb::addr_t ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size);
 
-    /// Reads an address from the inferior's address space starting at @p addr.
-    ///
-    /// @returns addr + target address size if the read was successful and
-    /// 0 otherwise.
-    lldb::addr_t
-    ReadPointer(lldb::addr_t addr, lldb::addr_t *dst);
+  /// Reads an address from the inferior's address space starting at @p addr.
+  ///
+  /// @returns addr + target address size if the read was successful and
+  /// 0 otherwise.
+  lldb::addr_t ReadPointer(lldb::addr_t addr, lldb::addr_t *dst);
 
-    /// Reads a null-terminated C string from the memory location starting at @p
-    /// addr.
-    std::string
-    ReadStringFromMemory(lldb::addr_t addr);
+  /// Reads a null-terminated C string from the memory location starting at @p
+  /// addr.
+  std::string ReadStringFromMemory(lldb::addr_t addr);
 
-    /// Reads an SOEntry starting at @p addr.
-    bool
-    ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry);
+  /// Reads an SOEntry starting at @p addr.
+  bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry);
 
-    /// Updates the current set of SOEntries, the set of added entries, and the
-    /// set of removed entries.
-    bool
-    UpdateSOEntries(bool fromRemote = false);
+  /// Updates the current set of SOEntries, the set of added entries, and the
+  /// set of removed entries.
+  bool UpdateSOEntries(bool fromRemote = false);
 
-    bool
-    FillSOEntryFromModuleInfo (LoadedModuleInfoList::LoadedModuleInfo const & modInfo,
-                               SOEntry &entry);
+  bool FillSOEntryFromModuleInfo(
+      LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry);
 
-    bool
-    SaveSOEntriesFromRemote(LoadedModuleInfoList &module_list);
+  bool SaveSOEntriesFromRemote(LoadedModuleInfoList &module_list);
 
-    bool
-    AddSOEntriesFromRemote(LoadedModuleInfoList &module_list);
+  bool AddSOEntriesFromRemote(LoadedModuleInfoList &module_list);
 
-    bool
-    RemoveSOEntriesFromRemote(LoadedModuleInfoList &module_list);
+  bool RemoveSOEntriesFromRemote(LoadedModuleInfoList &module_list);
 
-    bool
-    AddSOEntries();
+  bool AddSOEntries();
 
-    bool
-    RemoveSOEntries();
+  bool RemoveSOEntries();
 
-    void
-    UpdateBaseAddrIfNecessary(SOEntry &entry, std::string const &file_path);
+  void UpdateBaseAddrIfNecessary(SOEntry &entry, std::string const &file_path);
 
-    bool
-    SOEntryIsMainExecutable(const SOEntry &entry);
+  bool SOEntryIsMainExecutable(const SOEntry &entry);
 
-    /// Reads the current list of shared objects according to the link map
-    /// supplied by the runtime linker.
-    bool
-    TakeSnapshot(SOEntryList &entry_list);
+  /// Reads the current list of shared objects according to the link map
+  /// supplied by the runtime linker.
+  bool TakeSnapshot(SOEntryList &entry_list);
 
-    enum PThreadField { eSize, eNElem, eOffset };
+  enum PThreadField { eSize, eNElem, eOffset };
 
-    bool FindMetadata(const char *name, PThreadField field, uint32_t& value);
+  bool FindMetadata(const char *name, PThreadField field, uint32_t &value);
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp Tue Sep  6 15:57:50 2016
@@ -14,19 +14,19 @@
 #include "AuxVector.h"
 
 // Other libraries and framework includes
-#include "lldb/Core/PluginManager.h"
+#include "lldb/Breakpoint/BreakpointLocation.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
-#include "lldb/Target/Platform.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Section.h"
+#include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadPlanRunToAddress.h"
-#include "lldb/Breakpoint/BreakpointLocation.h"
-#include "lldb/Symbol/Function.h"
 
 // C++ Includes
 // C Includes
@@ -34,258 +34,240 @@
 using namespace lldb;
 using namespace lldb_private;
 
-void
-DynamicLoaderPOSIXDYLD::Initialize()
-{
-    PluginManager::RegisterPlugin(GetPluginNameStatic(),
-                                  GetPluginDescriptionStatic(),
-                                  CreateInstance);
-}
-
-void
-DynamicLoaderPOSIXDYLD::Terminate()
-{
-}
-
-lldb_private::ConstString
-DynamicLoaderPOSIXDYLD::GetPluginName()
-{
-    return GetPluginNameStatic();
-}
-
-lldb_private::ConstString
-DynamicLoaderPOSIXDYLD::GetPluginNameStatic()
-{
-    static ConstString g_name("linux-dyld");
-    return g_name;
-}
-
-const char *
-DynamicLoaderPOSIXDYLD::GetPluginDescriptionStatic()
-{
-    return "Dynamic loader plug-in that watches for shared library "
-           "loads/unloads in POSIX processes.";
-}
-
-uint32_t
-DynamicLoaderPOSIXDYLD::GetPluginVersion()
-{
-    return 1;
-}
-
-DynamicLoader *
-DynamicLoaderPOSIXDYLD::CreateInstance(Process *process, bool force)
-{
-    bool create = force;
-    if (!create)
-    {
-        const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
-        if (triple_ref.getOS() == llvm::Triple::Linux ||
-            triple_ref.getOS() == llvm::Triple::FreeBSD)
-            create = true;
-    }
-    
-    if (create)
-        return new DynamicLoaderPOSIXDYLD (process);
-    return NULL;
-}
-
-DynamicLoaderPOSIXDYLD::DynamicLoaderPOSIXDYLD(Process *process)
-    : DynamicLoader(process),
-      m_rendezvous(process),
-      m_load_offset(LLDB_INVALID_ADDRESS),
-      m_entry_point(LLDB_INVALID_ADDRESS),
-      m_auxv(),
-      m_dyld_bid(LLDB_INVALID_BREAK_ID),
-      m_vdso_base(LLDB_INVALID_ADDRESS)
-{
-}
-
-DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD()
-{
-    if (m_dyld_bid != LLDB_INVALID_BREAK_ID)
-    {
-        m_process->GetTarget().RemoveBreakpointByID (m_dyld_bid);
-        m_dyld_bid = LLDB_INVALID_BREAK_ID;
-    }
+void DynamicLoaderPOSIXDYLD::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                GetPluginDescriptionStatic(), CreateInstance);
 }
 
-void
-DynamicLoaderPOSIXDYLD::DidAttach()
-{
-    Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
+void DynamicLoaderPOSIXDYLD::Terminate() {}
 
-    m_auxv.reset(new AuxVector(m_process));
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
+lldb_private::ConstString DynamicLoaderPOSIXDYLD::GetPluginName() {
+  return GetPluginNameStatic();
+}
 
-    // ask the process if it can load any of its own modules
-    m_process->LoadModules ();
+lldb_private::ConstString DynamicLoaderPOSIXDYLD::GetPluginNameStatic() {
+  static ConstString g_name("linux-dyld");
+  return g_name;
+}
 
-    ModuleSP executable_sp = GetTargetExecutable ();
-    ResolveExecutableModule (executable_sp);
+const char *DynamicLoaderPOSIXDYLD::GetPluginDescriptionStatic() {
+  return "Dynamic loader plug-in that watches for shared library "
+         "loads/unloads in POSIX processes.";
+}
 
-    // find the main process load offset
-    addr_t load_offset = ComputeLoadOffset ();
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " executable '%s', load_offset 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, executable_sp ? executable_sp->GetFileSpec().GetPath().c_str () : "<null executable>", load_offset);
+uint32_t DynamicLoaderPOSIXDYLD::GetPluginVersion() { return 1; }
 
-    EvalVdsoStatus();
+DynamicLoader *DynamicLoaderPOSIXDYLD::CreateInstance(Process *process,
+                                                      bool force) {
+  bool create = force;
+  if (!create) {
+    const llvm::Triple &triple_ref =
+        process->GetTarget().GetArchitecture().GetTriple();
+    if (triple_ref.getOS() == llvm::Triple::Linux ||
+        triple_ref.getOS() == llvm::Triple::FreeBSD)
+      create = true;
+  }
 
-    // if we dont have a load address we cant re-base
-    bool rebase_exec = (load_offset == LLDB_INVALID_ADDRESS) ? false : true;
+  if (create)
+    return new DynamicLoaderPOSIXDYLD(process);
+  return NULL;
+}
 
-    // if we have a valid executable
-    if (executable_sp.get())
-    {
-        lldb_private::ObjectFile * obj = executable_sp->GetObjectFile();
-        if (obj)
-        {
-            // don't rebase if the module already has a load address
-            Target & target = m_process->GetTarget ();
-            Address addr = obj->GetImageInfoAddress (&target);
-            if (addr.GetLoadAddress (&target) != LLDB_INVALID_ADDRESS)
-                rebase_exec = false;
-        }
-    }
-    else
-    {
-        // no executable, nothing to re-base
+DynamicLoaderPOSIXDYLD::DynamicLoaderPOSIXDYLD(Process *process)
+    : DynamicLoader(process), m_rendezvous(process),
+      m_load_offset(LLDB_INVALID_ADDRESS), m_entry_point(LLDB_INVALID_ADDRESS),
+      m_auxv(), m_dyld_bid(LLDB_INVALID_BREAK_ID),
+      m_vdso_base(LLDB_INVALID_ADDRESS) {}
+
+DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD() {
+  if (m_dyld_bid != LLDB_INVALID_BREAK_ID) {
+    m_process->GetTarget().RemoveBreakpointByID(m_dyld_bid);
+    m_dyld_bid = LLDB_INVALID_BREAK_ID;
+  }
+}
+
+void DynamicLoaderPOSIXDYLD::DidAttach() {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__,
+                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
+
+  m_auxv.reset(new AuxVector(m_process));
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data",
+                __FUNCTION__,
+                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
+
+  // ask the process if it can load any of its own modules
+  m_process->LoadModules();
+
+  ModuleSP executable_sp = GetTargetExecutable();
+  ResolveExecutableModule(executable_sp);
+
+  // find the main process load offset
+  addr_t load_offset = ComputeLoadOffset();
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                " executable '%s', load_offset 0x%" PRIx64,
+                __FUNCTION__,
+                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
+                executable_sp ? executable_sp->GetFileSpec().GetPath().c_str()
+                              : "<null executable>",
+                load_offset);
+
+  EvalVdsoStatus();
+
+  // if we dont have a load address we cant re-base
+  bool rebase_exec = (load_offset == LLDB_INVALID_ADDRESS) ? false : true;
+
+  // if we have a valid executable
+  if (executable_sp.get()) {
+    lldb_private::ObjectFile *obj = executable_sp->GetObjectFile();
+    if (obj) {
+      // don't rebase if the module already has a load address
+      Target &target = m_process->GetTarget();
+      Address addr = obj->GetImageInfoAddress(&target);
+      if (addr.GetLoadAddress(&target) != LLDB_INVALID_ADDRESS)
         rebase_exec = false;
     }
+  } else {
+    // no executable, nothing to re-base
+    rebase_exec = false;
+  }
 
-    // if the target executable should be re-based
-    if (rebase_exec)
-    {
-        ModuleList module_list;
-
-        module_list.Append(executable_sp);
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " added executable '%s' to module load list",
-                         __FUNCTION__,
-                         m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID,
-                         executable_sp->GetFileSpec().GetPath().c_str ());
-
-        UpdateLoadedSections(executable_sp, LLDB_INVALID_ADDRESS, load_offset, true);
-
-        // When attaching to a target, there are two possible states:
-        // (1) We already crossed the entry point and therefore the rendezvous
-        //     structure is ready to be used and we can load the list of modules
-        //     and place the rendezvous breakpoint.
-        // (2) We didn't cross the entry point yet, so these structures are not
-        //     ready; we should behave as if we just launched the target and
-        //     call ProbeEntry(). This will place a breakpoint on the entry
-        //     point which itself will be hit after the rendezvous structure is
-        //     set up and will perform actions described in (1).
-        if (m_rendezvous.Resolve())
-        {
-            if (log)
-                log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64 " rendezvous could resolve: attach assuming dynamic loader info is available now", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
-            LoadAllCurrentModules();
-            SetRendezvousBreakpoint();
-        }
-        else
-        {
-            if (log)
-                log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64 " rendezvous could not yet resolve: adding breakpoint to catch future rendezvous setup", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
-            ProbeEntry();
-        }
-
-        m_process->GetTarget().ModulesDidLoad(module_list);
-        if (log)
-        {
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s told the target about the modules that loaded:", __FUNCTION__);
-            for (auto module_sp : module_list.Modules ())
-            {
-                log->Printf ("-- [module] %s (pid %" PRIu64 ")",
-                             module_sp ? module_sp->GetFileSpec().GetPath().c_str () : "<null>",
-                             m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
-            }
-        }
-    }
-}
+  // if the target executable should be re-based
+  if (rebase_exec) {
+    ModuleList module_list;
 
-void
-DynamicLoaderPOSIXDYLD::DidLaunch()
-{
-    Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+    module_list.Append(executable_sp);
     if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__);
+      log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                  " added executable '%s' to module load list",
+                  __FUNCTION__,
+                  m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
+                  executable_sp->GetFileSpec().GetPath().c_str());
+
+    UpdateLoadedSections(executable_sp, LLDB_INVALID_ADDRESS, load_offset,
+                         true);
+
+    // When attaching to a target, there are two possible states:
+    // (1) We already crossed the entry point and therefore the rendezvous
+    //     structure is ready to be used and we can load the list of modules
+    //     and place the rendezvous breakpoint.
+    // (2) We didn't cross the entry point yet, so these structures are not
+    //     ready; we should behave as if we just launched the target and
+    //     call ProbeEntry(). This will place a breakpoint on the entry
+    //     point which itself will be hit after the rendezvous structure is
+    //     set up and will perform actions described in (1).
+    if (m_rendezvous.Resolve()) {
+      if (log)
+        log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64
+                    " rendezvous could resolve: attach assuming dynamic loader "
+                    "info is available now",
+                    __FUNCTION__,
+                    m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
+      LoadAllCurrentModules();
+      SetRendezvousBreakpoint();
+    } else {
+      if (log)
+        log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64
+                    " rendezvous could not yet resolve: adding breakpoint to "
+                    "catch future rendezvous setup",
+                    __FUNCTION__,
+                    m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
+      ProbeEntry();
+    }
 
-    ModuleSP executable;
-    addr_t load_offset;
+    m_process->GetTarget().ModulesDidLoad(module_list);
+    if (log) {
+      log->Printf("DynamicLoaderPOSIXDYLD::%s told the target about the "
+                  "modules that loaded:",
+                  __FUNCTION__);
+      for (auto module_sp : module_list.Modules()) {
+        log->Printf("-- [module] %s (pid %" PRIu64 ")",
+                    module_sp ? module_sp->GetFileSpec().GetPath().c_str()
+                              : "<null>",
+                    m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
+      }
+    }
+  }
+}
+
+void DynamicLoaderPOSIXDYLD::DidLaunch() {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__);
+
+  ModuleSP executable;
+  addr_t load_offset;
+
+  m_auxv.reset(new AuxVector(m_process));
+
+  executable = GetTargetExecutable();
+  load_offset = ComputeLoadOffset();
+  EvalVdsoStatus();
 
-    m_auxv.reset(new AuxVector(m_process));
+  if (executable.get() && load_offset != LLDB_INVALID_ADDRESS) {
+    ModuleList module_list;
+    module_list.Append(executable);
+    UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset, true);
 
-    executable = GetTargetExecutable();
-    load_offset = ComputeLoadOffset();
-    EvalVdsoStatus();
+    if (log)
+      log->Printf("DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()",
+                  __FUNCTION__);
+    ProbeEntry();
 
-    if (executable.get() && load_offset != LLDB_INVALID_ADDRESS)
-    {
-        ModuleList module_list;
-        module_list.Append(executable);
-        UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset, true);
+    m_process->GetTarget().ModulesDidLoad(module_list);
+  }
+}
 
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()", __FUNCTION__);
-        ProbeEntry();
+Error DynamicLoaderPOSIXDYLD::CanLoadImage() { return Error(); }
 
-        m_process->GetTarget().ModulesDidLoad(module_list);
-    }
+void DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module,
+                                                  addr_t link_map_addr,
+                                                  addr_t base_addr,
+                                                  bool base_addr_is_offset) {
+  m_loaded_modules[module] = link_map_addr;
+  UpdateLoadedSectionsCommon(module, base_addr, base_addr_is_offset);
 }
 
-Error
-DynamicLoaderPOSIXDYLD::CanLoadImage()
-{
-    return Error();
-}
-
-void
-DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module,
-                                             addr_t link_map_addr,
-                                             addr_t base_addr,
-                                             bool base_addr_is_offset)
-{
-    m_loaded_modules[module] = link_map_addr;
-    UpdateLoadedSectionsCommon(module, base_addr, base_addr_is_offset);
-}
-
-void
-DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module)
-{
-    m_loaded_modules.erase(module);
-
-    UnloadSectionsCommon(module);
-}
-
-void
-DynamicLoaderPOSIXDYLD::ProbeEntry()
-{
-    Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-
-    const addr_t entry = GetEntryPoint();
-    if (entry == LLDB_INVALID_ADDRESS)
-    {
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " GetEntryPoint() returned no address, not setting entry breakpoint", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
-        return;
-    }
+void DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module) {
+  m_loaded_modules.erase(module);
 
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " GetEntryPoint() returned address 0x%" PRIx64 ", setting entry breakpoint", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, entry);
+  UnloadSectionsCommon(module);
+}
 
-    if (m_process)
-    {
-        Breakpoint *const entry_break = m_process->GetTarget().CreateBreakpoint(entry, true, false).get();
-        entry_break->SetCallback(EntryBreakpointHit, this, true);
-        entry_break->SetBreakpointKind("shared-library-event");
+void DynamicLoaderPOSIXDYLD::ProbeEntry() {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
 
-        // Shoudn't hit this more than once.
-        entry_break->SetOneShot (true);
-    }
+  const addr_t entry = GetEntryPoint();
+  if (entry == LLDB_INVALID_ADDRESS) {
+    if (log)
+      log->Printf(
+          "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+          " GetEntryPoint() returned no address, not setting entry breakpoint",
+          __FUNCTION__,
+          m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
+    return;
+  }
+
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                " GetEntryPoint() returned address 0x%" PRIx64
+                ", setting entry breakpoint",
+                __FUNCTION__,
+                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
+                entry);
+
+  if (m_process) {
+    Breakpoint *const entry_break =
+        m_process->GetTarget().CreateBreakpoint(entry, true, false).get();
+    entry_break->SetCallback(EntryBreakpointHit, this, true);
+    entry_break->SetBreakpointKind("shared-library-event");
+
+    // Shoudn't hit this more than once.
+    entry_break->SetOneShot(true);
+  }
 }
 
 // The runtime linker has run and initialized the rendezvous structure once the
@@ -294,419 +276,422 @@ DynamicLoaderPOSIXDYLD::ProbeEntry()
 // dependent modules for the process.  Similarly, we can discover the runtime
 // linker function and setup a breakpoint to notify us of any dynamically loaded
 // modules (via dlopen).
-bool
-DynamicLoaderPOSIXDYLD::EntryBreakpointHit(void *baton, 
-                                           StoppointCallbackContext *context, 
-                                           user_id_t break_id, 
-                                           user_id_t break_loc_id)
-{
-    assert(baton && "null baton");
-    if (!baton)
-        return false;
-
-    Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-    DynamicLoaderPOSIXDYLD *const dyld_instance = static_cast<DynamicLoaderPOSIXDYLD*>(baton);
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, __FUNCTION__, dyld_instance->m_process ? dyld_instance->m_process->GetID () : LLDB_INVALID_PROCESS_ID);
-
-    // Disable the breakpoint --- if a stop happens right after this, which we've seen on occasion, we don't
-    // want the breakpoint stepping thread-plan logic to show a breakpoint instruction at the disassembled
-    // entry point to the program.  Disabling it prevents it.  (One-shot is not enough - one-shot removal logic
-    // only happens after the breakpoint goes public, which wasn't happening in our scenario).
-    if (dyld_instance->m_process)
-    {
-        BreakpointSP breakpoint_sp = dyld_instance->m_process->GetTarget().GetBreakpointByID (break_id);
-        if (breakpoint_sp)
-        {
-            if (log)
-                log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " disabling breakpoint id %" PRIu64, __FUNCTION__, dyld_instance->m_process->GetID (), break_id);
-            breakpoint_sp->SetEnabled (false);
-        }
-        else
-        {
-            if (log)
-                log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " failed to find breakpoint for breakpoint id %" PRIu64, __FUNCTION__, dyld_instance->m_process->GetID (), break_id);
-        }
-    }
-    else
-    {
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64 " no Process instance!  Cannot disable breakpoint", __FUNCTION__, break_id);
-    }
-
-    dyld_instance->LoadAllCurrentModules();
-    dyld_instance->SetRendezvousBreakpoint();
-    return false; // Continue running.
-}
-
-void
-DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint()
-{
-    Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-
-    addr_t break_addr = m_rendezvous.GetBreakAddress();
-    Target &target = m_process->GetTarget();
-
-    if (m_dyld_bid == LLDB_INVALID_BREAK_ID)
-    {
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " setting rendezvous break address at 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, break_addr);
-        Breakpoint *dyld_break = target.CreateBreakpoint (break_addr, true, false).get();
-        dyld_break->SetCallback(RendezvousBreakpointHit, this, true);
-        dyld_break->SetBreakpointKind ("shared-library-event");
-        m_dyld_bid = dyld_break->GetID();
-    }
-    else
-    {
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reusing break id %" PRIu32 ", address at 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, m_dyld_bid, break_addr);
+bool DynamicLoaderPOSIXDYLD::EntryBreakpointHit(
+    void *baton, StoppointCallbackContext *context, user_id_t break_id,
+    user_id_t break_loc_id) {
+  assert(baton && "null baton");
+  if (!baton)
+    return false;
+
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  DynamicLoaderPOSIXDYLD *const dyld_instance =
+      static_cast<DynamicLoaderPOSIXDYLD *>(baton);
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64,
+                __FUNCTION__,
+                dyld_instance->m_process ? dyld_instance->m_process->GetID()
+                                         : LLDB_INVALID_PROCESS_ID);
+
+  // Disable the breakpoint --- if a stop happens right after this, which we've
+  // seen on occasion, we don't
+  // want the breakpoint stepping thread-plan logic to show a breakpoint
+  // instruction at the disassembled
+  // entry point to the program.  Disabling it prevents it.  (One-shot is not
+  // enough - one-shot removal logic
+  // only happens after the breakpoint goes public, which wasn't happening in
+  // our scenario).
+  if (dyld_instance->m_process) {
+    BreakpointSP breakpoint_sp =
+        dyld_instance->m_process->GetTarget().GetBreakpointByID(break_id);
+    if (breakpoint_sp) {
+      if (log)
+        log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                    " disabling breakpoint id %" PRIu64,
+                    __FUNCTION__, dyld_instance->m_process->GetID(), break_id);
+      breakpoint_sp->SetEnabled(false);
+    } else {
+      if (log)
+        log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                    " failed to find breakpoint for breakpoint id %" PRIu64,
+                    __FUNCTION__, dyld_instance->m_process->GetID(), break_id);
     }
+  } else {
+    if (log)
+      log->Printf("DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64
+                  " no Process instance!  Cannot disable breakpoint",
+                  __FUNCTION__, break_id);
+  }
 
-    // Make sure our breakpoint is at the right address.
-    assert (target.GetBreakpointByID(m_dyld_bid)->FindLocationByAddress(break_addr)->GetBreakpoint().GetID() == m_dyld_bid);
+  dyld_instance->LoadAllCurrentModules();
+  dyld_instance->SetRendezvousBreakpoint();
+  return false; // Continue running.
 }
 
-bool
-DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(void *baton, 
-                                                StoppointCallbackContext *context, 
-                                                user_id_t break_id, 
-                                                user_id_t break_loc_id)
-{
-    assert (baton && "null baton");
-    if (!baton)
-        return false;
-
-    Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-    DynamicLoaderPOSIXDYLD *const dyld_instance = static_cast<DynamicLoaderPOSIXDYLD*>(baton);
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, __FUNCTION__, dyld_instance->m_process ? dyld_instance->m_process->GetID () : LLDB_INVALID_PROCESS_ID);
+void DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint() {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
 
-    dyld_instance->RefreshModules();
+  addr_t break_addr = m_rendezvous.GetBreakAddress();
+  Target &target = m_process->GetTarget();
 
-    // Return true to stop the target, false to just let the target run.
-    const bool stop_when_images_change = dyld_instance->GetStopWhenImagesChange();
+  if (m_dyld_bid == LLDB_INVALID_BREAK_ID) {
     if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " stop_when_images_change=%s", __FUNCTION__, dyld_instance->m_process ? dyld_instance->m_process->GetID () : LLDB_INVALID_PROCESS_ID, stop_when_images_change ? "true" : "false");
-    return stop_when_images_change;
-}
-
-void
-DynamicLoaderPOSIXDYLD::RefreshModules()
-{
-    if (!m_rendezvous.Resolve())
-        return;
-
-    DYLDRendezvous::iterator I;
-    DYLDRendezvous::iterator E;
-
-    ModuleList &loaded_modules = m_process->GetTarget().GetImages();
-
-    if (m_rendezvous.ModulesDidLoad()) 
-    {
-        ModuleList new_modules;
-
-        E = m_rendezvous.loaded_end();
-        for (I = m_rendezvous.loaded_begin(); I != E; ++I)
-        {
-            ModuleSP module_sp = LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
-            if (module_sp.get())
-            {
-                loaded_modules.AppendIfNeeded(module_sp);
-                new_modules.Append(module_sp);
-            }
-        }
-        m_process->GetTarget().ModulesDidLoad(new_modules);
-    }
-    
-    if (m_rendezvous.ModulesDidUnload())
-    {
-        ModuleList old_modules;
-
-        E = m_rendezvous.unloaded_end();
-        for (I = m_rendezvous.unloaded_begin(); I != E; ++I)
-        {
-            ModuleSpec module_spec{I->file_spec};
-            ModuleSP module_sp = loaded_modules.FindFirstModule (module_spec);
-
-            if (module_sp.get())
-            {
-                old_modules.Append(module_sp);
-                UnloadSections(module_sp);
-            }
-        }
-        loaded_modules.Remove(old_modules);
-        m_process->GetTarget().ModulesDidUnload(old_modules, false);
-    }
+      log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                  " setting rendezvous break address at 0x%" PRIx64,
+                  __FUNCTION__,
+                  m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
+                  break_addr);
+    Breakpoint *dyld_break =
+        target.CreateBreakpoint(break_addr, true, false).get();
+    dyld_break->SetCallback(RendezvousBreakpointHit, this, true);
+    dyld_break->SetBreakpointKind("shared-library-event");
+    m_dyld_bid = dyld_break->GetID();
+  } else {
+    if (log)
+      log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                  " reusing break id %" PRIu32 ", address at 0x%" PRIx64,
+                  __FUNCTION__,
+                  m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,
+                  m_dyld_bid, break_addr);
+  }
+
+  // Make sure our breakpoint is at the right address.
+  assert(target.GetBreakpointByID(m_dyld_bid)
+             ->FindLocationByAddress(break_addr)
+             ->GetBreakpoint()
+             .GetID() == m_dyld_bid);
+}
+
+bool DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(
+    void *baton, StoppointCallbackContext *context, user_id_t break_id,
+    user_id_t break_loc_id) {
+  assert(baton && "null baton");
+  if (!baton)
+    return false;
+
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  DynamicLoaderPOSIXDYLD *const dyld_instance =
+      static_cast<DynamicLoaderPOSIXDYLD *>(baton);
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64,
+                __FUNCTION__,
+                dyld_instance->m_process ? dyld_instance->m_process->GetID()
+                                         : LLDB_INVALID_PROCESS_ID);
+
+  dyld_instance->RefreshModules();
+
+  // Return true to stop the target, false to just let the target run.
+  const bool stop_when_images_change = dyld_instance->GetStopWhenImagesChange();
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64
+                " stop_when_images_change=%s",
+                __FUNCTION__,
+                dyld_instance->m_process ? dyld_instance->m_process->GetID()
+                                         : LLDB_INVALID_PROCESS_ID,
+                stop_when_images_change ? "true" : "false");
+  return stop_when_images_change;
+}
+
+void DynamicLoaderPOSIXDYLD::RefreshModules() {
+  if (!m_rendezvous.Resolve())
+    return;
+
+  DYLDRendezvous::iterator I;
+  DYLDRendezvous::iterator E;
+
+  ModuleList &loaded_modules = m_process->GetTarget().GetImages();
+
+  if (m_rendezvous.ModulesDidLoad()) {
+    ModuleList new_modules;
+
+    E = m_rendezvous.loaded_end();
+    for (I = m_rendezvous.loaded_begin(); I != E; ++I) {
+      ModuleSP module_sp =
+          LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
+      if (module_sp.get()) {
+        loaded_modules.AppendIfNeeded(module_sp);
+        new_modules.Append(module_sp);
+      }
+    }
+    m_process->GetTarget().ModulesDidLoad(new_modules);
+  }
+
+  if (m_rendezvous.ModulesDidUnload()) {
+    ModuleList old_modules;
+
+    E = m_rendezvous.unloaded_end();
+    for (I = m_rendezvous.unloaded_begin(); I != E; ++I) {
+      ModuleSpec module_spec{I->file_spec};
+      ModuleSP module_sp = loaded_modules.FindFirstModule(module_spec);
+
+      if (module_sp.get()) {
+        old_modules.Append(module_sp);
+        UnloadSections(module_sp);
+      }
+    }
+    loaded_modules.Remove(old_modules);
+    m_process->GetTarget().ModulesDidUnload(old_modules, false);
+  }
 }
 
 ThreadPlanSP
-DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread, bool stop)
-{
-    ThreadPlanSP thread_plan_sp;
-
-    StackFrame *frame = thread.GetStackFrameAtIndex(0).get();
-    const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol);
-    Symbol *sym = context.symbol;
-
-    if (sym == NULL || !sym->IsTrampoline())
-        return thread_plan_sp;
-
-    ConstString sym_name = sym->GetName();
-    if (!sym_name)
-        return thread_plan_sp;
-
-    SymbolContextList target_symbols;
-    Target &target = thread.GetProcess()->GetTarget();
-    const ModuleList &images = target.GetImages();
-
-    images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
-    size_t num_targets = target_symbols.GetSize();
-    if (!num_targets)
-        return thread_plan_sp;
-
-    typedef std::vector<lldb::addr_t> AddressVector;
-    AddressVector addrs;
-    for (size_t i = 0; i < num_targets; ++i)
-    {
-        SymbolContext context;
-        AddressRange range;
-        if (target_symbols.GetContextAtIndex(i, context))
-        {
-            context.GetAddressRange(eSymbolContextEverything, 0, false, range);
-            lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
-            if (addr != LLDB_INVALID_ADDRESS)
-                addrs.push_back(addr);
-        }
-    }
+DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
+                                                     bool stop) {
+  ThreadPlanSP thread_plan_sp;
+
+  StackFrame *frame = thread.GetStackFrameAtIndex(0).get();
+  const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol);
+  Symbol *sym = context.symbol;
 
-    if (addrs.size() > 0) 
-    {
-        AddressVector::iterator start = addrs.begin();
-        AddressVector::iterator end = addrs.end();
-
-        std::sort(start, end);
-        addrs.erase(std::unique(start, end), end);
-        thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop));
-    }
+  if (sym == NULL || !sym->IsTrampoline())
+    return thread_plan_sp;
 
+  ConstString sym_name = sym->GetName();
+  if (!sym_name)
     return thread_plan_sp;
-}
 
-void
-DynamicLoaderPOSIXDYLD::LoadAllCurrentModules()
-{
-    DYLDRendezvous::iterator I;
-    DYLDRendezvous::iterator E;
-    ModuleList module_list;
-    
-    if (!m_rendezvous.Resolve())
-    {
-        Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-        if (log)
-            log->Printf("DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD rendezvous address",
-                        __FUNCTION__);
-        return;
-    }
+  SymbolContextList target_symbols;
+  Target &target = thread.GetProcess()->GetTarget();
+  const ModuleList &images = target.GetImages();
+
+  images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
+  size_t num_targets = target_symbols.GetSize();
+  if (!num_targets)
+    return thread_plan_sp;
 
-    // The rendezvous class doesn't enumerate the main module, so track
-    // that ourselves here.
-    ModuleSP executable = GetTargetExecutable();
-    m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
-    if (m_vdso_base != LLDB_INVALID_ADDRESS)
-    {
-        FileSpec file_spec("[vdso]", false);
-        ModuleSP module_sp = LoadModuleAtAddress(file_spec, LLDB_INVALID_ADDRESS, m_vdso_base, false);
-        if (module_sp.get())
-        {
-            module_list.Append(module_sp);
-        }
-    }
-    for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
-    {
-        ModuleSP module_sp = LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
-        if (module_sp.get())
-        {
-            module_list.Append(module_sp);
-        }
-        else
-        {
-            Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-            if (log)
-                log->Printf("DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64,
-                            __FUNCTION__, I->file_spec.GetCString(), I->base_addr);
-        }
-    }
+  typedef std::vector<lldb::addr_t> AddressVector;
+  AddressVector addrs;
+  for (size_t i = 0; i < num_targets; ++i) {
+    SymbolContext context;
+    AddressRange range;
+    if (target_symbols.GetContextAtIndex(i, context)) {
+      context.GetAddressRange(eSymbolContextEverything, 0, false, range);
+      lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
+      if (addr != LLDB_INVALID_ADDRESS)
+        addrs.push_back(addr);
+    }
+  }
+
+  if (addrs.size() > 0) {
+    AddressVector::iterator start = addrs.begin();
+    AddressVector::iterator end = addrs.end();
+
+    std::sort(start, end);
+    addrs.erase(std::unique(start, end), end);
+    thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop));
+  }
+
+  return thread_plan_sp;
+}
+
+void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {
+  DYLDRendezvous::iterator I;
+  DYLDRendezvous::iterator E;
+  ModuleList module_list;
 
-    m_process->GetTarget().ModulesDidLoad(module_list);
-}
+  if (!m_rendezvous.Resolve()) {
+    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+    if (log)
+      log->Printf("DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD "
+                  "rendezvous address",
+                  __FUNCTION__);
+    return;
+  }
+
+  // The rendezvous class doesn't enumerate the main module, so track
+  // that ourselves here.
+  ModuleSP executable = GetTargetExecutable();
+  m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
+  if (m_vdso_base != LLDB_INVALID_ADDRESS) {
+    FileSpec file_spec("[vdso]", false);
+    ModuleSP module_sp = LoadModuleAtAddress(file_spec, LLDB_INVALID_ADDRESS,
+                                             m_vdso_base, false);
+    if (module_sp.get()) {
+      module_list.Append(module_sp);
+    }
+  }
+  for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) {
+    ModuleSP module_sp =
+        LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
+    if (module_sp.get()) {
+      module_list.Append(module_sp);
+    } else {
+      Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+      if (log)
+        log->Printf(
+            "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64,
+            __FUNCTION__, I->file_spec.GetCString(), I->base_addr);
+    }
+  }
 
-addr_t
-DynamicLoaderPOSIXDYLD::ComputeLoadOffset()
-{
-    addr_t virt_entry;
-
-    if (m_load_offset != LLDB_INVALID_ADDRESS)
-        return m_load_offset;
-
-    if ((virt_entry = GetEntryPoint()) == LLDB_INVALID_ADDRESS)
-        return LLDB_INVALID_ADDRESS;
-
-    ModuleSP module = m_process->GetTarget().GetExecutableModule();
-    if (!module)
-        return LLDB_INVALID_ADDRESS;
-
-    ObjectFile *exe = module->GetObjectFile();
-    if (!exe)
-        return LLDB_INVALID_ADDRESS;
-
-    Address file_entry = exe->GetEntryPointAddress();
-
-    if (!file_entry.IsValid())
-        return LLDB_INVALID_ADDRESS;
-            
-    m_load_offset = virt_entry - file_entry.GetFileAddress();
-    return m_load_offset;
+  m_process->GetTarget().ModulesDidLoad(module_list);
 }
 
-void
-DynamicLoaderPOSIXDYLD::EvalVdsoStatus()
-{
-    AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AT_SYSINFO_EHDR);
+addr_t DynamicLoaderPOSIXDYLD::ComputeLoadOffset() {
+  addr_t virt_entry;
 
-    if (I != m_auxv->end())
-        m_vdso_base = I->value;
+  if (m_load_offset != LLDB_INVALID_ADDRESS)
+    return m_load_offset;
 
-}
+  if ((virt_entry = GetEntryPoint()) == LLDB_INVALID_ADDRESS)
+    return LLDB_INVALID_ADDRESS;
 
-addr_t
-DynamicLoaderPOSIXDYLD::GetEntryPoint()
-{
-    if (m_entry_point != LLDB_INVALID_ADDRESS)
-        return m_entry_point;
+  ModuleSP module = m_process->GetTarget().GetExecutableModule();
+  if (!module)
+    return LLDB_INVALID_ADDRESS;
 
-    if (m_auxv.get() == NULL)
-        return LLDB_INVALID_ADDRESS;
+  ObjectFile *exe = module->GetObjectFile();
+  if (!exe)
+    return LLDB_INVALID_ADDRESS;
 
-    AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AT_ENTRY);
+  Address file_entry = exe->GetEntryPointAddress();
 
-    if (I == m_auxv->end())
-        return LLDB_INVALID_ADDRESS;
+  if (!file_entry.IsValid())
+    return LLDB_INVALID_ADDRESS;
 
-    m_entry_point = static_cast<addr_t>(I->value);
+  m_load_offset = virt_entry - file_entry.GetFileAddress();
+  return m_load_offset;
+}
 
-    const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
+void DynamicLoaderPOSIXDYLD::EvalVdsoStatus() {
+  AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AT_SYSINFO_EHDR);
 
-    // On ppc64, the entry point is actually a descriptor.  Dereference it.
-    if (arch.GetMachine() == llvm::Triple::ppc64)
-        m_entry_point = ReadUnsignedIntWithSizeInBytes(m_entry_point, 8);
+  if (I != m_auxv->end())
+    m_vdso_base = I->value;
+}
 
+addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() {
+  if (m_entry_point != LLDB_INVALID_ADDRESS)
     return m_entry_point;
-}
 
-lldb::addr_t
-DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp, const lldb::ThreadSP thread,
-                                           lldb::addr_t tls_file_addr)
-{
-    auto it = m_loaded_modules.find (module_sp);
-    if (it == m_loaded_modules.end())
-        return LLDB_INVALID_ADDRESS;
-
-    addr_t link_map = it->second;
-    if (link_map == LLDB_INVALID_ADDRESS)
-        return LLDB_INVALID_ADDRESS;
-
-    const DYLDRendezvous::ThreadInfo &metadata = m_rendezvous.GetThreadInfo();
-    if (!metadata.valid)
-        return LLDB_INVALID_ADDRESS;
-
-    // Get the thread pointer.
-    addr_t tp = thread->GetThreadPointer ();
-    if (tp == LLDB_INVALID_ADDRESS)
-        return LLDB_INVALID_ADDRESS;
-
-    // Find the module's modid.
-    int modid_size = 4;  // FIXME(spucci): This isn't right for big-endian 64-bit
-    int64_t modid = ReadUnsignedIntWithSizeInBytes (link_map + metadata.modid_offset, modid_size);
-    if (modid == -1)
-        return LLDB_INVALID_ADDRESS;
-
-    // Lookup the DTV structure for this thread.
-    addr_t dtv_ptr = tp + metadata.dtv_offset;
-    addr_t dtv = ReadPointer (dtv_ptr);
-    if (dtv == LLDB_INVALID_ADDRESS)
-        return LLDB_INVALID_ADDRESS;
-
-    // Find the TLS block for this module.
-    addr_t dtv_slot = dtv + metadata.dtv_slot_size*modid;
-    addr_t tls_block = ReadPointer (dtv_slot + metadata.tls_offset);
+  if (m_auxv.get() == NULL)
+    return LLDB_INVALID_ADDRESS;
 
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-    if (log)
-        log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: "
-                    "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n",
-                    module_sp->GetObjectName().AsCString(""), link_map, tp, (int64_t)modid, tls_block);
-
-    if (tls_block == LLDB_INVALID_ADDRESS)
-        return LLDB_INVALID_ADDRESS;
-    else
-        return tls_block + tls_file_addr;
-}
+  AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AT_ENTRY);
 
-void
-DynamicLoaderPOSIXDYLD::ResolveExecutableModule (lldb::ModuleSP &module_sp)
-{
-    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  if (I == m_auxv->end())
+    return LLDB_INVALID_ADDRESS;
 
-    if (m_process == nullptr)
-        return;
+  m_entry_point = static_cast<addr_t>(I->value);
 
-    auto &target = m_process->GetTarget ();
-    const auto platform_sp = target.GetPlatform ();
+  const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
 
-    ProcessInstanceInfo process_info;
-    if (!m_process->GetProcessInfo(process_info))
-    {
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s - failed to get process info for pid %" PRIu64,
-                         __FUNCTION__, m_process->GetID ());
-        return;
-    }
+  // On ppc64, the entry point is actually a descriptor.  Dereference it.
+  if (arch.GetMachine() == llvm::Triple::ppc64)
+    m_entry_point = ReadUnsignedIntWithSizeInBytes(m_entry_point, 8);
 
-    if (log)
-        log->Printf ("DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64 ": %s",
-                     __FUNCTION__, m_process->GetID (), process_info.GetExecutableFile ().GetPath ().c_str ());
+  return m_entry_point;
+}
 
-    ModuleSpec module_spec (process_info.GetExecutableFile (), process_info.GetArchitecture ());
-    if (module_sp && module_sp->MatchesModuleSpec (module_spec))
-        return;
-
-    const auto executable_search_paths (Target::GetDefaultExecutableSearchPaths());
-    auto error = platform_sp->ResolveExecutable (
-        module_spec, module_sp, !executable_search_paths.IsEmpty() ? &executable_search_paths : nullptr);
-    if (error.Fail ())
-    {
-        StreamString stream;
-        module_spec.Dump (stream);
-
-        if (log)
-            log->Printf ("DynamicLoaderPOSIXDYLD::%s - failed to resolve executable with module spec \"%s\": %s",
-                         __FUNCTION__, stream.GetString ().c_str (), error.AsCString ());
-        return;
-    }
+lldb::addr_t
+DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,
+                                           const lldb::ThreadSP thread,
+                                           lldb::addr_t tls_file_addr) {
+  auto it = m_loaded_modules.find(module_sp);
+  if (it == m_loaded_modules.end())
+    return LLDB_INVALID_ADDRESS;
+
+  addr_t link_map = it->second;
+  if (link_map == LLDB_INVALID_ADDRESS)
+    return LLDB_INVALID_ADDRESS;
+
+  const DYLDRendezvous::ThreadInfo &metadata = m_rendezvous.GetThreadInfo();
+  if (!metadata.valid)
+    return LLDB_INVALID_ADDRESS;
+
+  // Get the thread pointer.
+  addr_t tp = thread->GetThreadPointer();
+  if (tp == LLDB_INVALID_ADDRESS)
+    return LLDB_INVALID_ADDRESS;
+
+  // Find the module's modid.
+  int modid_size = 4; // FIXME(spucci): This isn't right for big-endian 64-bit
+  int64_t modid = ReadUnsignedIntWithSizeInBytes(
+      link_map + metadata.modid_offset, modid_size);
+  if (modid == -1)
+    return LLDB_INVALID_ADDRESS;
+
+  // Lookup the DTV structure for this thread.
+  addr_t dtv_ptr = tp + metadata.dtv_offset;
+  addr_t dtv = ReadPointer(dtv_ptr);
+  if (dtv == LLDB_INVALID_ADDRESS)
+    return LLDB_INVALID_ADDRESS;
+
+  // Find the TLS block for this module.
+  addr_t dtv_slot = dtv + metadata.dtv_slot_size * modid;
+  addr_t tls_block = ReadPointer(dtv_slot + metadata.tls_offset);
+
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: "
+                "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64
+                ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n",
+                module_sp->GetObjectName().AsCString(""), link_map, tp,
+                (int64_t)modid, tls_block);
+
+  if (tls_block == LLDB_INVALID_ADDRESS)
+    return LLDB_INVALID_ADDRESS;
+  else
+    return tls_block + tls_file_addr;
+}
+
+void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(
+    lldb::ModuleSP &module_sp) {
+  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
 
-    target.SetExecutableModule (module_sp, false);
-}
+  if (m_process == nullptr)
+    return;
+
+  auto &target = m_process->GetTarget();
+  const auto platform_sp = target.GetPlatform();
 
-bool
-DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx)
-{
-    ModuleSP module_sp;
-    if (sym_ctx.symbol)
-        module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
-    if (!module_sp && sym_ctx.function)
-        module_sp = sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
-    if (!module_sp)
-        return false;
+  ProcessInstanceInfo process_info;
+  if (!m_process->GetProcessInfo(process_info)) {
+    if (log)
+      log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to get process info for "
+                  "pid %" PRIu64,
+                  __FUNCTION__, m_process->GetID());
+    return;
+  }
+
+  if (log)
+    log->Printf("DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64
+                ": %s",
+                __FUNCTION__, m_process->GetID(),
+                process_info.GetExecutableFile().GetPath().c_str());
+
+  ModuleSpec module_spec(process_info.GetExecutableFile(),
+                         process_info.GetArchitecture());
+  if (module_sp && module_sp->MatchesModuleSpec(module_spec))
+    return;
+
+  const auto executable_search_paths(Target::GetDefaultExecutableSearchPaths());
+  auto error = platform_sp->ResolveExecutable(
+      module_spec, module_sp,
+      !executable_search_paths.IsEmpty() ? &executable_search_paths : nullptr);
+  if (error.Fail()) {
+    StreamString stream;
+    module_spec.Dump(stream);
+
+    if (log)
+      log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to resolve executable "
+                  "with module spec \"%s\": %s",
+                  __FUNCTION__, stream.GetString().c_str(), error.AsCString());
+    return;
+  }
+
+  target.SetExecutableModule(module_sp, false);
+}
+
+bool DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo(
+    lldb_private::SymbolContext &sym_ctx) {
+  ModuleSP module_sp;
+  if (sym_ctx.symbol)
+    module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
+  if (!module_sp && sym_ctx.function)
+    module_sp =
+        sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
+  if (!module_sp)
+    return false;
 
-    return module_sp->GetFileSpec().GetPath() == "[vdso]";
+  return module_sp->GetFileSpec().GetPath() == "[vdso]";
 }

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h Tue Sep  6 15:57:50 2016
@@ -21,162 +21,139 @@
 
 class AuxVector;
 
-class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader
-{
+class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
 public:
-    DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
+  DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
 
-    ~DynamicLoaderPOSIXDYLD() override;
+  ~DynamicLoaderPOSIXDYLD() override;
 
-    static void
-    Initialize();
+  static void Initialize();
 
-    static void
-    Terminate();
+  static void Terminate();
 
-    static lldb_private::ConstString
-    GetPluginNameStatic();
+  static lldb_private::ConstString GetPluginNameStatic();
 
-    static const char *
-    GetPluginDescriptionStatic();
+  static const char *GetPluginDescriptionStatic();
 
-    static lldb_private::DynamicLoader *
-    CreateInstance(lldb_private::Process *process, bool force);
+  static lldb_private::DynamicLoader *
+  CreateInstance(lldb_private::Process *process, bool force);
 
-    //------------------------------------------------------------------
-    // DynamicLoader protocol
-    //------------------------------------------------------------------
+  //------------------------------------------------------------------
+  // DynamicLoader protocol
+  //------------------------------------------------------------------
 
-    void
-    DidAttach() override;
+  void DidAttach() override;
 
-    void
-    DidLaunch() override;
+  void DidLaunch() override;
 
-    lldb::ThreadPlanSP
-    GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
-                                 bool stop_others) override;
+  lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
+                                                  bool stop_others) override;
 
-    lldb_private::Error
-    CanLoadImage() override;
+  lldb_private::Error CanLoadImage() override;
 
-    lldb::addr_t
-    GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override;
+  lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
+                                  const lldb::ThreadSP thread,
+                                  lldb::addr_t tls_file_addr) override;
 
-    //------------------------------------------------------------------
-    // PluginInterface protocol
-    //------------------------------------------------------------------
-    lldb_private::ConstString
-    GetPluginName() override;
+  //------------------------------------------------------------------
+  // PluginInterface protocol
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
 
-    uint32_t
-    GetPluginVersion() override;
+  uint32_t GetPluginVersion() override;
 
 protected:
-    /// Runtime linker rendezvous structure.
-    DYLDRendezvous m_rendezvous;
+  /// Runtime linker rendezvous structure.
+  DYLDRendezvous m_rendezvous;
 
-    /// Virtual load address of the inferior process.
-    lldb::addr_t m_load_offset;
+  /// Virtual load address of the inferior process.
+  lldb::addr_t m_load_offset;
 
-    /// Virtual entry address of the inferior process.
-    lldb::addr_t m_entry_point;
+  /// Virtual entry address of the inferior process.
+  lldb::addr_t m_entry_point;
 
-    /// Auxiliary vector of the inferior process.
-    std::unique_ptr<AuxVector> m_auxv;
-
-    /// Rendezvous breakpoint.
-    lldb::break_id_t m_dyld_bid;
-
-    /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
-    /// mapped to the address space
-    lldb::addr_t m_vdso_base;
-
-    /// Loaded module list. (link map for each module)
-    std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> m_loaded_modules;
-
-    /// Enables a breakpoint on a function called by the runtime
-    /// linker each time a module is loaded or unloaded.
-    virtual void
-    SetRendezvousBreakpoint();
-
-    /// Callback routine which updates the current list of loaded modules based
-    /// on the information supplied by the runtime linker.
-    static bool
-    RendezvousBreakpointHit(void *baton, 
-                            lldb_private::StoppointCallbackContext *context, 
-                            lldb::user_id_t break_id, 
-                            lldb::user_id_t break_loc_id);
-    
-    /// Helper method for RendezvousBreakpointHit.  Updates LLDB's current set
-    /// of loaded modules.
-    void
-    RefreshModules();
-
-    /// Updates the load address of every allocatable section in @p module.
-    ///
-    /// @param module The module to traverse.
-    ///
-    /// @param link_map_addr The virtual address of the link map for the @p module.
-    ///
-    /// @param base_addr The virtual base address @p module is loaded at.
-    void
-    UpdateLoadedSections(lldb::ModuleSP module,
-                         lldb::addr_t link_map_addr,
-                         lldb::addr_t base_addr,
-                         bool base_addr_is_offset) override;
-
-    /// Removes the loaded sections from the target in @p module.
-    ///
-    /// @param module The module to traverse.
-    void
-    UnloadSections(const lldb::ModuleSP module) override;
-
-    /// Resolves the entry point for the current inferior process and sets a
-    /// breakpoint at that address.
-    void
-    ProbeEntry();
-
-    /// Callback routine invoked when we hit the breakpoint on process entry.
-    ///
-    /// This routine is responsible for resolving the load addresses of all
-    /// dependent modules required by the inferior and setting up the rendezvous
-    /// breakpoint.
-    static bool
-    EntryBreakpointHit(void *baton, 
-                       lldb_private::StoppointCallbackContext *context, 
-                       lldb::user_id_t break_id, 
-                       lldb::user_id_t break_loc_id);
-
-    /// Helper for the entry breakpoint callback.  Resolves the load addresses
-    /// of all dependent modules.
-    virtual void
-    LoadAllCurrentModules();
-
-    /// Computes a value for m_load_offset returning the computed address on
-    /// success and LLDB_INVALID_ADDRESS on failure.
-    lldb::addr_t
-    ComputeLoadOffset();
-
-    /// Computes a value for m_entry_point returning the computed address on
-    /// success and LLDB_INVALID_ADDRESS on failure.
-    lldb::addr_t
-    GetEntryPoint();
-
-    /// Evaluate if Aux vectors contain vDSO information
-    /// in case they do, read and assign the address to m_vdso_base
-    void
-    EvalVdsoStatus();
-
-    /// Loads Module from inferior process.
-    void
-    ResolveExecutableModule(lldb::ModuleSP &module_sp);
+  /// Auxiliary vector of the inferior process.
+  std::unique_ptr<AuxVector> m_auxv;
+
+  /// Rendezvous breakpoint.
+  lldb::break_id_t m_dyld_bid;
+
+  /// Contains AT_SYSINFO_EHDR, which means a vDSO has been
+  /// mapped to the address space
+  lldb::addr_t m_vdso_base;
+
+  /// Loaded module list. (link map for each module)
+  std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
+      m_loaded_modules;
+
+  /// Enables a breakpoint on a function called by the runtime
+  /// linker each time a module is loaded or unloaded.
+  virtual void SetRendezvousBreakpoint();
+
+  /// Callback routine which updates the current list of loaded modules based
+  /// on the information supplied by the runtime linker.
+  static bool RendezvousBreakpointHit(
+      void *baton, lldb_private::StoppointCallbackContext *context,
+      lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+  /// Helper method for RendezvousBreakpointHit.  Updates LLDB's current set
+  /// of loaded modules.
+  void RefreshModules();
+
+  /// Updates the load address of every allocatable section in @p module.
+  ///
+  /// @param module The module to traverse.
+  ///
+  /// @param link_map_addr The virtual address of the link map for the @p
+  /// module.
+  ///
+  /// @param base_addr The virtual base address @p module is loaded at.
+  void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,
+                            lldb::addr_t base_addr,
+                            bool base_addr_is_offset) override;
+
+  /// Removes the loaded sections from the target in @p module.
+  ///
+  /// @param module The module to traverse.
+  void UnloadSections(const lldb::ModuleSP module) override;
+
+  /// Resolves the entry point for the current inferior process and sets a
+  /// breakpoint at that address.
+  void ProbeEntry();
+
+  /// Callback routine invoked when we hit the breakpoint on process entry.
+  ///
+  /// This routine is responsible for resolving the load addresses of all
+  /// dependent modules required by the inferior and setting up the rendezvous
+  /// breakpoint.
+  static bool
+  EntryBreakpointHit(void *baton,
+                     lldb_private::StoppointCallbackContext *context,
+                     lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+  /// Helper for the entry breakpoint callback.  Resolves the load addresses
+  /// of all dependent modules.
+  virtual void LoadAllCurrentModules();
+
+  /// Computes a value for m_load_offset returning the computed address on
+  /// success and LLDB_INVALID_ADDRESS on failure.
+  lldb::addr_t ComputeLoadOffset();
+
+  /// Computes a value for m_entry_point returning the computed address on
+  /// success and LLDB_INVALID_ADDRESS on failure.
+  lldb::addr_t GetEntryPoint();
+
+  /// Evaluate if Aux vectors contain vDSO information
+  /// in case they do, read and assign the address to m_vdso_base
+  void EvalVdsoStatus();
 
-    bool
-    AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
+  /// Loads Module from inferior process.
+  void ResolveExecutableModule(lldb::ModuleSP &module_sp);
+
+  bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
 
 private:
-    DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
+  DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
 };
 
 #endif // liblldb_DynamicLoaderPOSIXDYLD_h_

Modified: lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp Tue Sep  6 15:57:50 2016
@@ -23,50 +23,42 @@ using namespace lldb_private;
 // the plugin info class that gets handed out by the plugin factory and
 // allows the lldb to instantiate an instance of this class.
 //----------------------------------------------------------------------
-DynamicLoader *
-DynamicLoaderStatic::CreateInstance (Process* process, bool force)
-{
-    bool create = force;
-    if (!create)
-    {
-        const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
-        const llvm::Triple::OSType os_type = triple_ref.getOS();
-        if ((os_type == llvm::Triple::UnknownOS))
-            create = true;
+DynamicLoader *DynamicLoaderStatic::CreateInstance(Process *process,
+                                                   bool force) {
+  bool create = force;
+  if (!create) {
+    const llvm::Triple &triple_ref =
+        process->GetTarget().GetArchitecture().GetTriple();
+    const llvm::Triple::OSType os_type = triple_ref.getOS();
+    if ((os_type == llvm::Triple::UnknownOS))
+      create = true;
+  }
+
+  if (!create) {
+    Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+    if (exe_module) {
+      ObjectFile *object_file = exe_module->GetObjectFile();
+      if (object_file) {
+        create = (object_file->GetStrata() == ObjectFile::eStrataRawImage);
+      }
     }
-    
-    if (!create)
-    {
-        Module *exe_module = process->GetTarget().GetExecutableModulePointer();
-        if (exe_module)
-        {
-            ObjectFile *object_file = exe_module->GetObjectFile();
-            if (object_file)
-            {
-                create = (object_file->GetStrata() == ObjectFile::eStrataRawImage);
-            }
-        }
-    }
-    
-    if (create)
-        return new DynamicLoaderStatic (process);
-    return NULL;
+  }
+
+  if (create)
+    return new DynamicLoaderStatic(process);
+  return NULL;
 }
 
 //----------------------------------------------------------------------
 // Constructor
 //----------------------------------------------------------------------
-DynamicLoaderStatic::DynamicLoaderStatic (Process* process) :
-    DynamicLoader(process)
-{
-}
+DynamicLoaderStatic::DynamicLoaderStatic(Process *process)
+    : DynamicLoader(process) {}
 
 //----------------------------------------------------------------------
 // Destructor
 //----------------------------------------------------------------------
-DynamicLoaderStatic::~DynamicLoaderStatic()
-{
-}
+DynamicLoaderStatic::~DynamicLoaderStatic() {}
 
 //------------------------------------------------------------------
 /// Called after attaching a process.
@@ -74,11 +66,7 @@ DynamicLoaderStatic::~DynamicLoaderStati
 /// Allow DynamicLoader plug-ins to execute some code after
 /// attaching to a process.
 //------------------------------------------------------------------
-void
-DynamicLoaderStatic::DidAttach ()
-{
-    LoadAllImagesAtFileAddresses();
-}
+void DynamicLoaderStatic::DidAttach() { LoadAllImagesAtFileAddresses(); }
 
 //------------------------------------------------------------------
 /// Called after attaching a process.
@@ -86,124 +74,94 @@ DynamicLoaderStatic::DidAttach ()
 /// Allow DynamicLoader plug-ins to execute some code after
 /// attaching to a process.
 //------------------------------------------------------------------
-void
-DynamicLoaderStatic::DidLaunch ()
-{
-    LoadAllImagesAtFileAddresses();
-}
-
-void
-DynamicLoaderStatic::LoadAllImagesAtFileAddresses ()
-{
-    const ModuleList &module_list = m_process->GetTarget().GetImages();
-    
-    ModuleList loaded_module_list;
-
-    // Disable JIT for static dynamic loader targets
-    m_process->SetCanJIT(false);
-
-    std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
-
-    const size_t num_modules = module_list.GetSize();
-    for (uint32_t idx = 0; idx < num_modules; ++idx)
-    {
-        ModuleSP module_sp (module_list.GetModuleAtIndexUnlocked (idx));
-        if (module_sp)
-        {
-            bool changed = false;
-            ObjectFile *image_object_file = module_sp->GetObjectFile();
-            if (image_object_file)
-            {
-                SectionList *section_list = image_object_file->GetSectionList ();
-                if (section_list)
-                {
-                    // All sections listed in the dyld image info structure will all
-                    // either be fixed up already, or they will all be off by a single
-                    // slide amount that is determined by finding the first segment
-                    // that is at file offset zero which also has bytes (a file size
-                    // that is greater than zero) in the object file.
-
-                    // Determine the slide amount (if any)
-                    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 the
-                        // first section that starts of file offset zero and that
-                        // has bytes in the file...
-                        SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
-                        if (section_sp)
-                        {
-                            if (m_process->GetTarget().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress()))
-                                changed = true;
-                        }
-                    }
-                }
+void DynamicLoaderStatic::DidLaunch() { LoadAllImagesAtFileAddresses(); }
+
+void DynamicLoaderStatic::LoadAllImagesAtFileAddresses() {
+  const ModuleList &module_list = m_process->GetTarget().GetImages();
+
+  ModuleList loaded_module_list;
+
+  // Disable JIT for static dynamic loader targets
+  m_process->SetCanJIT(false);
+
+  std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
+
+  const size_t num_modules = module_list.GetSize();
+  for (uint32_t idx = 0; idx < num_modules; ++idx) {
+    ModuleSP module_sp(module_list.GetModuleAtIndexUnlocked(idx));
+    if (module_sp) {
+      bool changed = false;
+      ObjectFile *image_object_file = module_sp->GetObjectFile();
+      if (image_object_file) {
+        SectionList *section_list = image_object_file->GetSectionList();
+        if (section_list) {
+          // All sections listed in the dyld image info structure will all
+          // either be fixed up already, or they will all be off by a single
+          // slide amount that is determined by finding the first segment
+          // that is at file offset zero which also has bytes (a file size
+          // that is greater than zero) in the object file.
+
+          // Determine the slide amount (if any)
+          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 the
+            // first section that starts of file offset zero and that
+            // has bytes in the file...
+            SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
+            if (section_sp) {
+              if (m_process->GetTarget().SetSectionLoadAddress(
+                      section_sp, section_sp->GetFileAddress()))
+                changed = true;
             }
-            
-            if (changed)
-                loaded_module_list.AppendIfNeeded (module_sp);
+          }
         }
+      }
+
+      if (changed)
+        loaded_module_list.AppendIfNeeded(module_sp);
     }
+  }
 
-    m_process->GetTarget().ModulesDidLoad (loaded_module_list);
+  m_process->GetTarget().ModulesDidLoad(loaded_module_list);
 }
 
 ThreadPlanSP
-DynamicLoaderStatic::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
-{
-    return ThreadPlanSP();
+DynamicLoaderStatic::GetStepThroughTrampolinePlan(Thread &thread,
+                                                  bool stop_others) {
+  return ThreadPlanSP();
 }
 
-Error
-DynamicLoaderStatic::CanLoadImage ()
-{
-    Error error;
-    error.SetErrorString ("can't load images on with a static debug session");
-    return error;
+Error DynamicLoaderStatic::CanLoadImage() {
+  Error error;
+  error.SetErrorString("can't load images on with a static debug session");
+  return error;
 }
 
-void
-DynamicLoaderStatic::Initialize()
-{
-    PluginManager::RegisterPlugin (GetPluginNameStatic(),
-                                   GetPluginDescriptionStatic(),
-                                   CreateInstance);
+void DynamicLoaderStatic::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                GetPluginDescriptionStatic(), CreateInstance);
 }
 
-void
-DynamicLoaderStatic::Terminate()
-{
-    PluginManager::UnregisterPlugin (CreateInstance);
+void DynamicLoaderStatic::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
 }
 
-
-lldb_private::ConstString
-DynamicLoaderStatic::GetPluginNameStatic()
-{
-    static ConstString g_name("static");
-    return g_name;
+lldb_private::ConstString DynamicLoaderStatic::GetPluginNameStatic() {
+  static ConstString g_name("static");
+  return g_name;
 }
 
-const char *
-DynamicLoaderStatic::GetPluginDescriptionStatic()
-{
-    return "Dynamic loader plug-in that will load any images at the static addresses contained in each image.";
+const char *DynamicLoaderStatic::GetPluginDescriptionStatic() {
+  return "Dynamic loader plug-in that will load any images at the static "
+         "addresses contained in each image.";
 }
 
-
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
-lldb_private::ConstString
-DynamicLoaderStatic::GetPluginName()
-{
-    return GetPluginNameStatic();
-}
-
-uint32_t
-DynamicLoaderStatic::GetPluginVersion()
-{
-    return 1;
+lldb_private::ConstString DynamicLoaderStatic::GetPluginName() {
+  return GetPluginNameStatic();
 }
 
+uint32_t DynamicLoaderStatic::GetPluginVersion() { return 1; }

Modified: lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h Tue Sep  6 15:57:50 2016
@@ -14,69 +14,57 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Target/DynamicLoader.h"
-#include "lldb/Host/FileSpec.h"
 #include "lldb/Core/UUID.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/Process.h"
 
-class DynamicLoaderStatic : public lldb_private::DynamicLoader
-{
+class DynamicLoaderStatic : public lldb_private::DynamicLoader {
 public:
-    DynamicLoaderStatic(lldb_private::Process *process);
+  DynamicLoaderStatic(lldb_private::Process *process);
+
+  ~DynamicLoaderStatic() override;
+
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static const char *GetPluginDescriptionStatic();
+
+  static lldb_private::DynamicLoader *
+  CreateInstance(lldb_private::Process *process, bool force);
+
+  //------------------------------------------------------------------
+  /// Called after attaching a process.
+  ///
+  /// Allow DynamicLoader plug-ins to execute some code after
+  /// attaching to a process.
+  //------------------------------------------------------------------
+  void DidAttach() override;
+
+  void DidLaunch() override;
+
+  lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
+                                                  bool stop_others) override;
 
-    ~DynamicLoaderStatic() override;
+  lldb_private::Error CanLoadImage() override;
 
-    //------------------------------------------------------------------
-    // Static Functions
-    //------------------------------------------------------------------
-    static void
-    Initialize();
-
-    static void
-    Terminate();
-
-    static lldb_private::ConstString
-    GetPluginNameStatic();
-
-    static const char *
-    GetPluginDescriptionStatic();
-
-    static lldb_private::DynamicLoader *
-    CreateInstance (lldb_private::Process *process, bool force);
-
-    //------------------------------------------------------------------
-    /// Called after attaching a process.
-    ///
-    /// Allow DynamicLoader plug-ins to execute some code after
-    /// attaching to a process.
-    //------------------------------------------------------------------
-    void
-    DidAttach() override;
-
-    void
-    DidLaunch() override;
-
-    lldb::ThreadPlanSP
-    GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
-                                 bool stop_others) override;
-
-    lldb_private::Error
-    CanLoadImage() override;
-
-    //------------------------------------------------------------------
-    // PluginInterface protocol
-    //------------------------------------------------------------------
-    lldb_private::ConstString
-    GetPluginName() override;
+  //------------------------------------------------------------------
+  // PluginInterface protocol
+  //------------------------------------------------------------------
+  lldb_private::ConstString GetPluginName() override;
 
-    uint32_t
-    GetPluginVersion() override;
+  uint32_t GetPluginVersion() override;
 
 private:
-    void
-    LoadAllImagesAtFileAddresses ();
+  void LoadAllImagesAtFileAddresses();
 
-    DISALLOW_COPY_AND_ASSIGN (DynamicLoaderStatic);
+  DISALLOW_COPY_AND_ASSIGN(DynamicLoaderStatic);
 };
 
 #endif // liblldb_DynamicLoaderStatic_h_

Modified: lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- DynamicLoaderWindowsDYLD.cpp --------------------------------*- C++ -*-===//
+//===-- DynamicLoaderWindowsDYLD.cpp --------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -19,86 +20,57 @@ using namespace lldb;
 using namespace lldb_private;
 
 DynamicLoaderWindowsDYLD::DynamicLoaderWindowsDYLD(Process *process)
-    : DynamicLoader(process)
-{
-}
+    : DynamicLoader(process) {}
 
-DynamicLoaderWindowsDYLD::~DynamicLoaderWindowsDYLD()
-{
-}
+DynamicLoaderWindowsDYLD::~DynamicLoaderWindowsDYLD() {}
 
-void
-DynamicLoaderWindowsDYLD::Initialize()
-{
-    PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance);
+void DynamicLoaderWindowsDYLD::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                GetPluginDescriptionStatic(), CreateInstance);
 }
 
-void
-DynamicLoaderWindowsDYLD::Terminate()
-{
-}
+void DynamicLoaderWindowsDYLD::Terminate() {}
 
-ConstString
-DynamicLoaderWindowsDYLD::GetPluginNameStatic()
-{
-    static ConstString g_plugin_name("windows-dyld");
-    return g_plugin_name;
+ConstString DynamicLoaderWindowsDYLD::GetPluginNameStatic() {
+  static ConstString g_plugin_name("windows-dyld");
+  return g_plugin_name;
 }
 
-const char *
-DynamicLoaderWindowsDYLD::GetPluginDescriptionStatic()
-{
-    return "Dynamic loader plug-in that watches for shared library "
-           "loads/unloads in Windows processes.";
+const char *DynamicLoaderWindowsDYLD::GetPluginDescriptionStatic() {
+  return "Dynamic loader plug-in that watches for shared library "
+         "loads/unloads in Windows processes.";
 }
 
-DynamicLoader *
-DynamicLoaderWindowsDYLD::CreateInstance(Process *process, bool force)
-{
-    bool should_create = force;
-    if (!should_create)
-    {
-        const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
-        if (triple_ref.getOS() == llvm::Triple::Win32)
-            should_create = true;
-    }
+DynamicLoader *DynamicLoaderWindowsDYLD::CreateInstance(Process *process,
+                                                        bool force) {
+  bool should_create = force;
+  if (!should_create) {
+    const llvm::Triple &triple_ref =
+        process->GetTarget().GetArchitecture().GetTriple();
+    if (triple_ref.getOS() == llvm::Triple::Win32)
+      should_create = true;
+  }
 
-    if (should_create)
-        return new DynamicLoaderWindowsDYLD(process);
+  if (should_create)
+    return new DynamicLoaderWindowsDYLD(process);
 
-    return nullptr;
+  return nullptr;
 }
 
-void
-DynamicLoaderWindowsDYLD::DidAttach()
-{
-}
+void DynamicLoaderWindowsDYLD::DidAttach() {}
 
-void
-DynamicLoaderWindowsDYLD::DidLaunch()
-{
-}
+void DynamicLoaderWindowsDYLD::DidLaunch() {}
 
-Error
-DynamicLoaderWindowsDYLD::CanLoadImage()
-{
-    return Error();
-}
+Error DynamicLoaderWindowsDYLD::CanLoadImage() { return Error(); }
 
-ConstString
-DynamicLoaderWindowsDYLD::GetPluginName()
-{
-    return GetPluginNameStatic();
+ConstString DynamicLoaderWindowsDYLD::GetPluginName() {
+  return GetPluginNameStatic();
 }
 
-uint32_t
-DynamicLoaderWindowsDYLD::GetPluginVersion()
-{
-    return 1;
-}
+uint32_t DynamicLoaderWindowsDYLD::GetPluginVersion() { return 1; }
 
 ThreadPlanSP
-DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread, bool stop)
-{
-    return ThreadPlanSP();
+DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
+                                                       bool stop) {
+  return ThreadPlanSP();
 }

Modified: lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h Tue Sep  6 15:57:50 2016
@@ -14,33 +14,32 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
-#include "lldb/lldb-forward.h"
 #include "lldb/Target/DynamicLoader.h"
+#include "lldb/lldb-forward.h"
 
-namespace lldb_private
-{
+namespace lldb_private {
 
-class DynamicLoaderWindowsDYLD : public DynamicLoader
-{
+class DynamicLoaderWindowsDYLD : public DynamicLoader {
 public:
-    DynamicLoaderWindowsDYLD(Process *process);
+  DynamicLoaderWindowsDYLD(Process *process);
 
-    ~DynamicLoaderWindowsDYLD() override;
+  ~DynamicLoaderWindowsDYLD() override;
 
-    static void Initialize();
-    static void Terminate();
-    static ConstString GetPluginNameStatic();
-    static const char *GetPluginDescriptionStatic();
+  static void Initialize();
+  static void Terminate();
+  static ConstString GetPluginNameStatic();
+  static const char *GetPluginDescriptionStatic();
 
-    static DynamicLoader *CreateInstance(Process *process, bool force);
+  static DynamicLoader *CreateInstance(Process *process, bool force);
 
-    void DidAttach() override;
-    void DidLaunch() override;
-    Error CanLoadImage() override;
-    lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop) override;
+  void DidAttach() override;
+  void DidLaunch() override;
+  Error CanLoadImage() override;
+  lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
+                                                  bool stop) override;
 
-    ConstString GetPluginName() override;
-    uint32_t GetPluginVersion() override;
+  ConstString GetPluginName() override;
+  uint32_t GetPluginVersion() override;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp Tue Sep  6 15:57:50 2016
@@ -18,118 +18,94 @@
 
 using namespace lldb_private;
 
-ASTDumper::ASTDumper (clang::Decl *decl)
-{
-    clang::DeclContext *decl_ctx = llvm::dyn_cast<clang::DeclContext>(decl);
-    
-    bool has_external_lexical_storage;
-    bool has_external_visible_storage;
-    
-    if (decl_ctx)
-    {
-        has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
-        has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
-        decl_ctx->setHasExternalLexicalStorage(false);
-        decl_ctx->setHasExternalVisibleStorage(false);
-    }
-    
-    llvm::raw_string_ostream os(m_dump);
-    decl->print (os);
-    os.flush();
-    
-    if (decl_ctx)
-    {
-        decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
-        decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
-    }
-}
+ASTDumper::ASTDumper(clang::Decl *decl) {
+  clang::DeclContext *decl_ctx = llvm::dyn_cast<clang::DeclContext>(decl);
+
+  bool has_external_lexical_storage;
+  bool has_external_visible_storage;
 
-ASTDumper::ASTDumper (clang::DeclContext *decl_ctx)
-{
-    bool has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
-    bool has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
-    
+  if (decl_ctx) {
+    has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
+    has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
     decl_ctx->setHasExternalLexicalStorage(false);
     decl_ctx->setHasExternalVisibleStorage(false);
-    
-    if (clang::Decl *decl = llvm::dyn_cast<clang::Decl>(decl_ctx))
-    {
-        llvm::raw_string_ostream os(m_dump);
-        decl->print (os);
-        os.flush();
-    }
-    else
-    {
-        m_dump.assign("<DeclContext is not a Decl>");
-    }
-    
+  }
+
+  llvm::raw_string_ostream os(m_dump);
+  decl->print(os);
+  os.flush();
+
+  if (decl_ctx) {
     decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
     decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
+  }
 }
 
-ASTDumper::ASTDumper (const clang::Type *type)
-{
-    m_dump = clang::QualType(type, 0).getAsString();
-}
+ASTDumper::ASTDumper(clang::DeclContext *decl_ctx) {
+  bool has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
+  bool has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
 
-ASTDumper::ASTDumper (clang::QualType type)
-{
-    m_dump = type.getAsString();
-}
+  decl_ctx->setHasExternalLexicalStorage(false);
+  decl_ctx->setHasExternalVisibleStorage(false);
+
+  if (clang::Decl *decl = llvm::dyn_cast<clang::Decl>(decl_ctx)) {
+    llvm::raw_string_ostream os(m_dump);
+    decl->print(os);
+    os.flush();
+  } else {
+    m_dump.assign("<DeclContext is not a Decl>");
+  }
 
-ASTDumper::ASTDumper (lldb::opaque_compiler_type_t type)
-{
-    m_dump = clang::QualType::getFromOpaquePtr(type).getAsString();
+  decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
+  decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
 }
 
-ASTDumper::ASTDumper (const CompilerType &compiler_type)
-{
-    m_dump = ClangUtil::GetQualType(compiler_type).getAsString();
+ASTDumper::ASTDumper(const clang::Type *type) {
+  m_dump = clang::QualType(type, 0).getAsString();
 }
 
+ASTDumper::ASTDumper(clang::QualType type) { m_dump = type.getAsString(); }
 
-const char *
-ASTDumper::GetCString()
-{
-    return m_dump.c_str();
+ASTDumper::ASTDumper(lldb::opaque_compiler_type_t type) {
+  m_dump = clang::QualType::getFromOpaquePtr(type).getAsString();
 }
 
-void ASTDumper::ToSTDERR()
-{
-    fprintf(stderr, "%s\n", m_dump.c_str());
+ASTDumper::ASTDumper(const CompilerType &compiler_type) {
+  m_dump = ClangUtil::GetQualType(compiler_type).getAsString();
 }
 
-void ASTDumper::ToLog(Log *log, const char *prefix)
-{
-    size_t len = m_dump.length() + 1;
-    
-    char *alloc = (char*)malloc(len);
-    char *str = alloc;
-    
-    memcpy(str, m_dump.c_str(), len);
-    
-    char *end = NULL;
-    
-    end = strchr(str, '\n');
-    
-    while (end)
-    {
-        *end = '\0';
-        
-        log->Printf("%s%s", prefix, str);
-        
-        *end = '\n';
-        
-        str = end + 1;
-        end = strchr(str, '\n');
-    }
-    
+const char *ASTDumper::GetCString() { return m_dump.c_str(); }
+
+void ASTDumper::ToSTDERR() { fprintf(stderr, "%s\n", m_dump.c_str()); }
+
+void ASTDumper::ToLog(Log *log, const char *prefix) {
+  size_t len = m_dump.length() + 1;
+
+  char *alloc = (char *)malloc(len);
+  char *str = alloc;
+
+  memcpy(str, m_dump.c_str(), len);
+
+  char *end = NULL;
+
+  end = strchr(str, '\n');
+
+  while (end) {
+    *end = '\0';
+
     log->Printf("%s%s", prefix, str);
-                    
-    free(alloc);
+
+    *end = '\n';
+
+    str = end + 1;
+    end = strchr(str, '\n');
+  }
+
+  log->Printf("%s%s", prefix, str);
+
+  free(alloc);
 }
 
-void ASTDumper::ToStream(lldb::StreamSP &stream)
-{
-    stream->PutCString(m_dump.c_str());
+void ASTDumper::ToStream(lldb::StreamSP &stream) {
+  stream->PutCString(m_dump.c_str());
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTDumper.h Tue Sep  6 15:57:50 2016
@@ -16,25 +16,24 @@
 #include "lldb/Core/Stream.h"
 #include "llvm/ADT/DenseSet.h"
 
-namespace lldb_private
-{
-    
-class ASTDumper
-{
+namespace lldb_private {
+
+class ASTDumper {
 public:
-    ASTDumper (clang::Decl *decl);
-    ASTDumper (clang::DeclContext *decl_ctx);
-    ASTDumper (const clang::Type *type);
-    ASTDumper (clang::QualType type);
-    ASTDumper (lldb::opaque_compiler_type_t type);
-    ASTDumper (const CompilerType &compiler_type);
-    
-    const char *GetCString();
-    void ToSTDERR();
-    void ToLog(Log *log, const char *prefix);
-    void ToStream(lldb::StreamSP &stream);
+  ASTDumper(clang::Decl *decl);
+  ASTDumper(clang::DeclContext *decl_ctx);
+  ASTDumper(const clang::Type *type);
+  ASTDumper(clang::QualType type);
+  ASTDumper(lldb::opaque_compiler_type_t type);
+  ASTDumper(const CompilerType &compiler_type);
+
+  const char *GetCString();
+  void ToSTDERR();
+  void ToLog(Log *log, const char *prefix);
+  void ToStream(lldb::StreamSP &stream);
+
 private:
-    std::string m_dump;
+  std::string m_dump;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp Tue Sep  6 15:57:50 2016
@@ -33,542 +33,485 @@ using namespace llvm;
 using namespace clang;
 using namespace lldb_private;
 
-ASTResultSynthesizer::ASTResultSynthesizer(ASTConsumer *passthrough, bool top_level, Target &target)
-    : m_ast_context(NULL),
-      m_passthrough(passthrough),
-      m_passthrough_sema(NULL),
-      m_target(target),
-      m_sema(NULL),
-      m_top_level(top_level)
-{
-    if (!m_passthrough)
-        return;
-
-    m_passthrough_sema = dyn_cast<SemaConsumer>(passthrough);
-}
-
-ASTResultSynthesizer::~ASTResultSynthesizer()
-{
-}
-
-void
-ASTResultSynthesizer::Initialize(ASTContext &Context)
-{
-    m_ast_context = &Context;
-
-    if (m_passthrough)
-        m_passthrough->Initialize(Context);
-}
-
-void
-ASTResultSynthesizer::TransformTopLevelDecl(Decl* D)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    if (NamedDecl *named_decl = dyn_cast<NamedDecl>(D))
-    {
-        if (log && log->GetVerbose())
-        {
-            if (named_decl->getIdentifier())
-                log->Printf("TransformTopLevelDecl(%s)", named_decl->getIdentifier()->getNameStart());
-            else if (ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(D))
-                log->Printf("TransformTopLevelDecl(%s)", method_decl->getSelector().getAsString().c_str());
-            else
-                log->Printf("TransformTopLevelDecl(<complex>)");
-        }
-
-        if (m_top_level)
-        {
-            RecordPersistentDecl(named_decl);
-        }
+ASTResultSynthesizer::ASTResultSynthesizer(ASTConsumer *passthrough,
+                                           bool top_level, Target &target)
+    : m_ast_context(NULL), m_passthrough(passthrough), m_passthrough_sema(NULL),
+      m_target(target), m_sema(NULL), m_top_level(top_level) {
+  if (!m_passthrough)
+    return;
+
+  m_passthrough_sema = dyn_cast<SemaConsumer>(passthrough);
+}
+
+ASTResultSynthesizer::~ASTResultSynthesizer() {}
+
+void ASTResultSynthesizer::Initialize(ASTContext &Context) {
+  m_ast_context = &Context;
+
+  if (m_passthrough)
+    m_passthrough->Initialize(Context);
+}
+
+void ASTResultSynthesizer::TransformTopLevelDecl(Decl *D) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  if (NamedDecl *named_decl = dyn_cast<NamedDecl>(D)) {
+    if (log && log->GetVerbose()) {
+      if (named_decl->getIdentifier())
+        log->Printf("TransformTopLevelDecl(%s)",
+                    named_decl->getIdentifier()->getNameStart());
+      else if (ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(D))
+        log->Printf("TransformTopLevelDecl(%s)",
+                    method_decl->getSelector().getAsString().c_str());
+      else
+        log->Printf("TransformTopLevelDecl(<complex>)");
+    }
+
+    if (m_top_level) {
+      RecordPersistentDecl(named_decl);
     }
+  }
+
+  if (LinkageSpecDecl *linkage_spec_decl = dyn_cast<LinkageSpecDecl>(D)) {
+    RecordDecl::decl_iterator decl_iterator;
 
-    if (LinkageSpecDecl *linkage_spec_decl = dyn_cast<LinkageSpecDecl>(D))
-    {
-        RecordDecl::decl_iterator decl_iterator;
-
-        for (decl_iterator = linkage_spec_decl->decls_begin();
-             decl_iterator != linkage_spec_decl->decls_end();
-             ++decl_iterator)
-        {
-            TransformTopLevelDecl(*decl_iterator);
-        }
+    for (decl_iterator = linkage_spec_decl->decls_begin();
+         decl_iterator != linkage_spec_decl->decls_end(); ++decl_iterator) {
+      TransformTopLevelDecl(*decl_iterator);
     }
-    else if (!m_top_level)
-    {
-        if (ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(D))
-        {
-            if (m_ast_context && !method_decl->getSelector().getAsString().compare("$__lldb_expr:"))
-            {
-                RecordPersistentTypes(method_decl);
-                SynthesizeObjCMethodResult(method_decl);
-            }
-        }
-        else if (FunctionDecl *function_decl = dyn_cast<FunctionDecl>(D))
-        {
-            if (m_ast_context && !function_decl->getNameInfo().getAsString().compare("$__lldb_expr"))
-            {
-                RecordPersistentTypes(function_decl);
-                SynthesizeFunctionResult(function_decl);
-            }
-        }
+  } else if (!m_top_level) {
+    if (ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(D)) {
+      if (m_ast_context &&
+          !method_decl->getSelector().getAsString().compare("$__lldb_expr:")) {
+        RecordPersistentTypes(method_decl);
+        SynthesizeObjCMethodResult(method_decl);
+      }
+    } else if (FunctionDecl *function_decl = dyn_cast<FunctionDecl>(D)) {
+      if (m_ast_context &&
+          !function_decl->getNameInfo().getAsString().compare("$__lldb_expr")) {
+        RecordPersistentTypes(function_decl);
+        SynthesizeFunctionResult(function_decl);
+      }
     }
+  }
 }
 
-bool
-ASTResultSynthesizer::HandleTopLevelDecl(DeclGroupRef D)
-{
-    DeclGroupRef::iterator decl_iterator;
-
-    for (decl_iterator = D.begin();
-         decl_iterator != D.end();
-         ++decl_iterator)
-    {
-        Decl *decl = *decl_iterator;
+bool ASTResultSynthesizer::HandleTopLevelDecl(DeclGroupRef D) {
+  DeclGroupRef::iterator decl_iterator;
 
-        TransformTopLevelDecl(decl);
-    }
+  for (decl_iterator = D.begin(); decl_iterator != D.end(); ++decl_iterator) {
+    Decl *decl = *decl_iterator;
 
-    if (m_passthrough)
-        return m_passthrough->HandleTopLevelDecl(D);
-    return true;
+    TransformTopLevelDecl(decl);
+  }
+
+  if (m_passthrough)
+    return m_passthrough->HandleTopLevelDecl(D);
+  return true;
 }
 
-bool
-ASTResultSynthesizer::SynthesizeFunctionResult (FunctionDecl *FunDecl)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+bool ASTResultSynthesizer::SynthesizeFunctionResult(FunctionDecl *FunDecl) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (!m_sema)
-        return false;
+  if (!m_sema)
+    return false;
 
-    FunctionDecl *function_decl = FunDecl;
+  FunctionDecl *function_decl = FunDecl;
 
-    if (!function_decl)
-        return false;
+  if (!function_decl)
+    return false;
 
-    if (log && log->GetVerbose())
-    {
-        std::string s;
-        raw_string_ostream os(s);
+  if (log && log->GetVerbose()) {
+    std::string s;
+    raw_string_ostream os(s);
 
-        function_decl->print(os);
+    function_decl->print(os);
 
-        os.flush();
+    os.flush();
 
-        log->Printf ("Untransformed function AST:\n%s", s.c_str());
-    }
+    log->Printf("Untransformed function AST:\n%s", s.c_str());
+  }
 
-    Stmt *function_body = function_decl->getBody();
-    CompoundStmt *compound_stmt = dyn_cast<CompoundStmt>(function_body);
+  Stmt *function_body = function_decl->getBody();
+  CompoundStmt *compound_stmt = dyn_cast<CompoundStmt>(function_body);
 
-    bool ret = SynthesizeBodyResult (compound_stmt,
-                                     function_decl);
+  bool ret = SynthesizeBodyResult(compound_stmt, function_decl);
 
-    if (log && log->GetVerbose())
-    {
-        std::string s;
-        raw_string_ostream os(s);
+  if (log && log->GetVerbose()) {
+    std::string s;
+    raw_string_ostream os(s);
 
-        function_decl->print(os);
+    function_decl->print(os);
 
-        os.flush();
+    os.flush();
 
-        log->Printf ("Transformed function AST:\n%s", s.c_str());
-    }
+    log->Printf("Transformed function AST:\n%s", s.c_str());
+  }
 
-    return ret;
+  return ret;
 }
 
-bool
-ASTResultSynthesizer::SynthesizeObjCMethodResult (ObjCMethodDecl *MethodDecl)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+bool ASTResultSynthesizer::SynthesizeObjCMethodResult(
+    ObjCMethodDecl *MethodDecl) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (!m_sema)
-        return false;
+  if (!m_sema)
+    return false;
 
-    if (!MethodDecl)
-        return false;
+  if (!MethodDecl)
+    return false;
 
-    if (log && log->GetVerbose())
-    {
-        std::string s;
-        raw_string_ostream os(s);
+  if (log && log->GetVerbose()) {
+    std::string s;
+    raw_string_ostream os(s);
 
-        MethodDecl->print(os);
+    MethodDecl->print(os);
 
-        os.flush();
+    os.flush();
 
-        log->Printf ("Untransformed method AST:\n%s", s.c_str());
-    }
+    log->Printf("Untransformed method AST:\n%s", s.c_str());
+  }
 
-    Stmt *method_body = MethodDecl->getBody();
+  Stmt *method_body = MethodDecl->getBody();
 
-    if (!method_body)
-        return false;
+  if (!method_body)
+    return false;
 
-    CompoundStmt *compound_stmt = dyn_cast<CompoundStmt>(method_body);
+  CompoundStmt *compound_stmt = dyn_cast<CompoundStmt>(method_body);
 
-    bool ret = SynthesizeBodyResult (compound_stmt,
-                                     MethodDecl);
+  bool ret = SynthesizeBodyResult(compound_stmt, MethodDecl);
 
-    if (log && log->GetVerbose())
-    {
-        std::string s;
-        raw_string_ostream os(s);
+  if (log && log->GetVerbose()) {
+    std::string s;
+    raw_string_ostream os(s);
 
-        MethodDecl->print(os);
+    MethodDecl->print(os);
 
-        os.flush();
+    os.flush();
 
-        log->Printf("Transformed method AST:\n%s", s.c_str());
-    }
+    log->Printf("Transformed method AST:\n%s", s.c_str());
+  }
 
-    return ret;
+  return ret;
 }
 
-bool
-ASTResultSynthesizer::SynthesizeBodyResult (CompoundStmt *Body,
-                                            DeclContext *DC)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    ASTContext &Ctx(*m_ast_context);
-
-    if (!Body)
-        return false;
-
-    if (Body->body_empty())
-        return false;
-
-    Stmt **last_stmt_ptr = Body->body_end() - 1;
-    Stmt *last_stmt = *last_stmt_ptr;
-
-    while (dyn_cast<NullStmt>(last_stmt))
-    {
-        if (last_stmt_ptr != Body->body_begin())
-        {
-            last_stmt_ptr--;
-            last_stmt = *last_stmt_ptr;
-        }
-        else
-        {
-            return false;
-        }
-    }
+bool ASTResultSynthesizer::SynthesizeBodyResult(CompoundStmt *Body,
+                                                DeclContext *DC) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    Expr *last_expr = dyn_cast<Expr>(last_stmt);
+  ASTContext &Ctx(*m_ast_context);
 
-    if (!last_expr)
-        // No auxiliary variable necessary; expression returns void
-        return true;
-
-    // In C++11, last_expr can be a LValueToRvalue implicit cast.  Strip that off if that's the
-    // case.
-
-    do {
-        ImplicitCastExpr *implicit_cast = dyn_cast<ImplicitCastExpr>(last_expr);
-
-        if (!implicit_cast)
-            break;
-
-        if (implicit_cast->getCastKind() != CK_LValueToRValue)
-            break;
-
-        last_expr = implicit_cast->getSubExpr();
-    } while (0);
-
-    // is_lvalue is used to record whether the expression returns an assignable Lvalue or an
-    // Rvalue.  This is relevant because they are handled differently.
-    //
-    // For Lvalues
-    //
-    //   - In AST result synthesis (here!) the expression E is transformed into an initialization
-    //     T *$__lldb_expr_result_ptr = &E.
-    //
-    //   - In structure allocation, a pointer-sized slot is allocated in the struct that is to be
-    //     passed into the expression.
-    //
-    //   - In IR transformations, reads and writes to $__lldb_expr_result_ptr are redirected at
-    //     an entry in the struct ($__lldb_arg) passed into the expression.  (Other persistent
-    //     variables are treated similarly, having been materialized as references, but in those
-    //     cases the value of the reference itself is never modified.)
-    //
-    //   - During materialization, $0 (the result persistent variable) is ignored.
-    //
-    //   - During dematerialization, $0 is marked up as a load address with value equal to the
-    //     contents of the structure entry.
-    //
-    // For Rvalues
-    //
-    //   - In AST result synthesis the expression E is transformed into an initialization
-    //     static T $__lldb_expr_result = E.
-    //
-    //   - In structure allocation, a pointer-sized slot is allocated in the struct that is to be
-    //     passed into the expression.
-    //
-    //   - In IR transformations, an instruction is inserted at the beginning of the function to
-    //     dereference the pointer resident in the slot.  Reads and writes to $__lldb_expr_result
-    //     are redirected at that dereferenced version.  Guard variables for the static variable
-    //     are excised.
-    //
-    //   - During materialization, $0 (the result persistent variable) is populated with the location
-    //     of a newly-allocated area of memory.
-    //
-    //   - During dematerialization, $0 is ignored.
-
-    bool is_lvalue =
-        (last_expr->getValueKind() == VK_LValue || last_expr->getValueKind() == VK_XValue) &&
-        (last_expr->getObjectKind() == OK_Ordinary);
-
-    QualType expr_qual_type = last_expr->getType();
-    const clang::Type *expr_type = expr_qual_type.getTypePtr();
-
-    if (!expr_type)
-        return false;
-
-    if (expr_type->isVoidType())
-        return true;
-
-    if (log)
-    {
-        std::string s = expr_qual_type.getAsString();
+  if (!Body)
+    return false;
 
-        log->Printf("Last statement is an %s with type: %s", (is_lvalue ? "lvalue" : "rvalue"), s.c_str());
-    }
+  if (Body->body_empty())
+    return false;
 
-    clang::VarDecl *result_decl = NULL;
+  Stmt **last_stmt_ptr = Body->body_end() - 1;
+  Stmt *last_stmt = *last_stmt_ptr;
 
-    if (is_lvalue)
-    {
-        IdentifierInfo *result_ptr_id;
-
-        if (expr_type->isFunctionType())
-            result_ptr_id = &Ctx.Idents.get("$__lldb_expr_result"); // functions actually should be treated like function pointers
-        else
-            result_ptr_id = &Ctx.Idents.get("$__lldb_expr_result_ptr");
-
-        m_sema->RequireCompleteType(SourceLocation(), expr_qual_type, clang::diag::err_incomplete_type);
-
-        QualType ptr_qual_type;
-
-        if (expr_qual_type->getAs<ObjCObjectType>() != NULL)
-            ptr_qual_type = Ctx.getObjCObjectPointerType(expr_qual_type);
-        else
-            ptr_qual_type = Ctx.getPointerType(expr_qual_type);
-
-        result_decl = VarDecl::Create(Ctx,
-                                      DC,
-                                      SourceLocation(),
-                                      SourceLocation(),
-                                      result_ptr_id,
-                                      ptr_qual_type,
-                                      NULL,
-                                      SC_Static);
-
-        if (!result_decl)
-            return false;
-
-        ExprResult address_of_expr = m_sema->CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf, last_expr);
-        if (address_of_expr.get())
-            m_sema->AddInitializerToDecl(result_decl, address_of_expr.get(), true, false);
-        else
-            return false;
+  while (dyn_cast<NullStmt>(last_stmt)) {
+    if (last_stmt_ptr != Body->body_begin()) {
+      last_stmt_ptr--;
+      last_stmt = *last_stmt_ptr;
+    } else {
+      return false;
     }
+  }
+
+  Expr *last_expr = dyn_cast<Expr>(last_stmt);
+
+  if (!last_expr)
+    // No auxiliary variable necessary; expression returns void
+    return true;
+
+  // In C++11, last_expr can be a LValueToRvalue implicit cast.  Strip that off
+  // if that's the
+  // case.
+
+  do {
+    ImplicitCastExpr *implicit_cast = dyn_cast<ImplicitCastExpr>(last_expr);
+
+    if (!implicit_cast)
+      break;
+
+    if (implicit_cast->getCastKind() != CK_LValueToRValue)
+      break;
+
+    last_expr = implicit_cast->getSubExpr();
+  } while (0);
+
+  // is_lvalue is used to record whether the expression returns an assignable
+  // Lvalue or an
+  // Rvalue.  This is relevant because they are handled differently.
+  //
+  // For Lvalues
+  //
+  //   - In AST result synthesis (here!) the expression E is transformed into an
+  //   initialization
+  //     T *$__lldb_expr_result_ptr = &E.
+  //
+  //   - In structure allocation, a pointer-sized slot is allocated in the
+  //   struct that is to be
+  //     passed into the expression.
+  //
+  //   - In IR transformations, reads and writes to $__lldb_expr_result_ptr are
+  //   redirected at
+  //     an entry in the struct ($__lldb_arg) passed into the expression.
+  //     (Other persistent
+  //     variables are treated similarly, having been materialized as
+  //     references, but in those
+  //     cases the value of the reference itself is never modified.)
+  //
+  //   - During materialization, $0 (the result persistent variable) is ignored.
+  //
+  //   - During dematerialization, $0 is marked up as a load address with value
+  //   equal to the
+  //     contents of the structure entry.
+  //
+  // For Rvalues
+  //
+  //   - In AST result synthesis the expression E is transformed into an
+  //   initialization
+  //     static T $__lldb_expr_result = E.
+  //
+  //   - In structure allocation, a pointer-sized slot is allocated in the
+  //   struct that is to be
+  //     passed into the expression.
+  //
+  //   - In IR transformations, an instruction is inserted at the beginning of
+  //   the function to
+  //     dereference the pointer resident in the slot.  Reads and writes to
+  //     $__lldb_expr_result
+  //     are redirected at that dereferenced version.  Guard variables for the
+  //     static variable
+  //     are excised.
+  //
+  //   - During materialization, $0 (the result persistent variable) is
+  //   populated with the location
+  //     of a newly-allocated area of memory.
+  //
+  //   - During dematerialization, $0 is ignored.
+
+  bool is_lvalue = (last_expr->getValueKind() == VK_LValue ||
+                    last_expr->getValueKind() == VK_XValue) &&
+                   (last_expr->getObjectKind() == OK_Ordinary);
+
+  QualType expr_qual_type = last_expr->getType();
+  const clang::Type *expr_type = expr_qual_type.getTypePtr();
+
+  if (!expr_type)
+    return false;
+
+  if (expr_type->isVoidType())
+    return true;
+
+  if (log) {
+    std::string s = expr_qual_type.getAsString();
+
+    log->Printf("Last statement is an %s with type: %s",
+                (is_lvalue ? "lvalue" : "rvalue"), s.c_str());
+  }
+
+  clang::VarDecl *result_decl = NULL;
+
+  if (is_lvalue) {
+    IdentifierInfo *result_ptr_id;
+
+    if (expr_type->isFunctionType())
+      result_ptr_id =
+          &Ctx.Idents.get("$__lldb_expr_result"); // functions actually should
+                                                  // be treated like function
+                                                  // pointers
     else
-    {
-        IdentifierInfo &result_id = Ctx.Idents.get("$__lldb_expr_result");
+      result_ptr_id = &Ctx.Idents.get("$__lldb_expr_result_ptr");
 
-        result_decl = VarDecl::Create(Ctx,
-                                      DC,
-                                      SourceLocation(),
-                                      SourceLocation(),
-                                      &result_id,
-                                      expr_qual_type,
-                                      NULL,
-                                      SC_Static);
+    m_sema->RequireCompleteType(SourceLocation(), expr_qual_type,
+                                clang::diag::err_incomplete_type);
 
-        if (!result_decl)
-            return false;
+    QualType ptr_qual_type;
 
-        m_sema->AddInitializerToDecl(result_decl, last_expr, true, false);
-    }
+    if (expr_qual_type->getAs<ObjCObjectType>() != NULL)
+      ptr_qual_type = Ctx.getObjCObjectPointerType(expr_qual_type);
+    else
+      ptr_qual_type = Ctx.getPointerType(expr_qual_type);
+
+    result_decl =
+        VarDecl::Create(Ctx, DC, SourceLocation(), SourceLocation(),
+                        result_ptr_id, ptr_qual_type, NULL, SC_Static);
+
+    if (!result_decl)
+      return false;
+
+    ExprResult address_of_expr =
+        m_sema->CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf, last_expr);
+    if (address_of_expr.get())
+      m_sema->AddInitializerToDecl(result_decl, address_of_expr.get(), true,
+                                   false);
+    else
+      return false;
+  } else {
+    IdentifierInfo &result_id = Ctx.Idents.get("$__lldb_expr_result");
 
-    DC->addDecl(result_decl);
+    result_decl = VarDecl::Create(Ctx, DC, SourceLocation(), SourceLocation(),
+                                  &result_id, expr_qual_type, NULL, SC_Static);
 
-    ///////////////////////////////
-    // call AddInitializerToDecl
-    //
+    if (!result_decl)
+      return false;
 
-    //m_sema->AddInitializerToDecl(result_decl, last_expr);
+    m_sema->AddInitializerToDecl(result_decl, last_expr, true, false);
+  }
 
-    /////////////////////////////////
-    // call ConvertDeclToDeclGroup
-    //
+  DC->addDecl(result_decl);
 
-    Sema::DeclGroupPtrTy result_decl_group_ptr;
+  ///////////////////////////////
+  // call AddInitializerToDecl
+  //
 
-    result_decl_group_ptr = m_sema->ConvertDeclToDeclGroup(result_decl);
+  // m_sema->AddInitializerToDecl(result_decl, last_expr);
 
-    ////////////////////////
-    // call ActOnDeclStmt
-    //
+  /////////////////////////////////
+  // call ConvertDeclToDeclGroup
+  //
 
-    StmtResult result_initialization_stmt_result(m_sema->ActOnDeclStmt(result_decl_group_ptr,
-                                                                       SourceLocation(),
-                                                                       SourceLocation()));
+  Sema::DeclGroupPtrTy result_decl_group_ptr;
 
-    ////////////////////////////////////////////////
-    // replace the old statement with the new one
-    //
+  result_decl_group_ptr = m_sema->ConvertDeclToDeclGroup(result_decl);
 
-    *last_stmt_ptr = reinterpret_cast<Stmt*>(result_initialization_stmt_result.get());
+  ////////////////////////
+  // call ActOnDeclStmt
+  //
 
-    return true;
+  StmtResult result_initialization_stmt_result(m_sema->ActOnDeclStmt(
+      result_decl_group_ptr, SourceLocation(), SourceLocation()));
+
+  ////////////////////////////////////////////////
+  // replace the old statement with the new one
+  //
+
+  *last_stmt_ptr =
+      reinterpret_cast<Stmt *>(result_initialization_stmt_result.get());
+
+  return true;
 }
 
-void
-ASTResultSynthesizer::HandleTranslationUnit(ASTContext &Ctx)
-{
-    if (m_passthrough)
-        m_passthrough->HandleTranslationUnit(Ctx);
-}
-
-void
-ASTResultSynthesizer::RecordPersistentTypes(DeclContext *FunDeclCtx)
-{
-    typedef DeclContext::specific_decl_iterator<TypeDecl> TypeDeclIterator;
-
-    for (TypeDeclIterator i = TypeDeclIterator(FunDeclCtx->decls_begin()),
-         e = TypeDeclIterator(FunDeclCtx->decls_end());
-         i != e;
-         ++i)
-    {
-        MaybeRecordPersistentType(*i);
-    }
+void ASTResultSynthesizer::HandleTranslationUnit(ASTContext &Ctx) {
+  if (m_passthrough)
+    m_passthrough->HandleTranslationUnit(Ctx);
 }
 
-void
-ASTResultSynthesizer::MaybeRecordPersistentType(TypeDecl *D)
-{
-    if (!D->getIdentifier())
-        return;
+void ASTResultSynthesizer::RecordPersistentTypes(DeclContext *FunDeclCtx) {
+  typedef DeclContext::specific_decl_iterator<TypeDecl> TypeDeclIterator;
+
+  for (TypeDeclIterator i = TypeDeclIterator(FunDeclCtx->decls_begin()),
+                        e = TypeDeclIterator(FunDeclCtx->decls_end());
+       i != e; ++i) {
+    MaybeRecordPersistentType(*i);
+  }
+}
 
-    StringRef name = D->getName();
+void ASTResultSynthesizer::MaybeRecordPersistentType(TypeDecl *D) {
+  if (!D->getIdentifier())
+    return;
 
-    if (name.size() == 0 || name[0] != '$')
-        return;
+  StringRef name = D->getName();
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  if (name.size() == 0 || name[0] != '$')
+    return;
 
-    ConstString name_cs(name.str().c_str());
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (log)
-        log->Printf("Recording persistent type %s\n", name_cs.GetCString());
+  ConstString name_cs(name.str().c_str());
 
-    m_decls.push_back(D);
+  if (log)
+    log->Printf("Recording persistent type %s\n", name_cs.GetCString());
+
+  m_decls.push_back(D);
 }
 
-void
-ASTResultSynthesizer::RecordPersistentDecl(NamedDecl *D)
-{
-    lldbassert(m_top_level);
+void ASTResultSynthesizer::RecordPersistentDecl(NamedDecl *D) {
+  lldbassert(m_top_level);
 
-    if (!D->getIdentifier())
-        return;
+  if (!D->getIdentifier())
+    return;
 
-    StringRef name = D->getName();
+  StringRef name = D->getName();
 
-    if (name.size() == 0)
-        return;
+  if (name.size() == 0)
+    return;
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    ConstString name_cs(name.str().c_str());
+  ConstString name_cs(name.str().c_str());
 
-    if (log)
-        log->Printf("Recording persistent decl %s\n", name_cs.GetCString());
+  if (log)
+    log->Printf("Recording persistent decl %s\n", name_cs.GetCString());
 
-    m_decls.push_back(D);
+  m_decls.push_back(D);
 }
 
-void
-ASTResultSynthesizer::CommitPersistentDecls()
-{
-    for (clang::NamedDecl *decl : m_decls)
-    {
-        StringRef name = decl->getName();
-        ConstString name_cs(name.str().c_str());
-
-        Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl(
-            m_target.GetScratchClangASTContext()->getASTContext(), m_ast_context, decl);
-
-        if (!D_scratch)
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
-
-            if (log)
-            {
-                std::string s;
-                llvm::raw_string_ostream ss(s);
-                decl->dump(ss);
-                ss.flush();
-
-                log->Printf("Couldn't commit persistent  decl: %s\n", s.c_str());
-            }
-
-            continue;
-        }
-
-        if (NamedDecl *NamedDecl_scratch = dyn_cast<NamedDecl>(D_scratch))
-            llvm::cast<ClangPersistentVariables>(m_target.GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))
-                ->RegisterPersistentDecl(name_cs, NamedDecl_scratch);
+void ASTResultSynthesizer::CommitPersistentDecls() {
+  for (clang::NamedDecl *decl : m_decls) {
+    StringRef name = decl->getName();
+    ConstString name_cs(name.str().c_str());
+
+    Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl(
+        m_target.GetScratchClangASTContext()->getASTContext(), m_ast_context,
+        decl);
+
+    if (!D_scratch) {
+      Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+      if (log) {
+        std::string s;
+        llvm::raw_string_ostream ss(s);
+        decl->dump(ss);
+        ss.flush();
+
+        log->Printf("Couldn't commit persistent  decl: %s\n", s.c_str());
+      }
+
+      continue;
     }
+
+    if (NamedDecl *NamedDecl_scratch = dyn_cast<NamedDecl>(D_scratch))
+      llvm::cast<ClangPersistentVariables>(
+          m_target.GetPersistentExpressionStateForLanguage(
+              lldb::eLanguageTypeC))
+          ->RegisterPersistentDecl(name_cs, NamedDecl_scratch);
+  }
 }
 
-void
-ASTResultSynthesizer::HandleTagDeclDefinition(TagDecl *D)
-{
-    if (m_passthrough)
-        m_passthrough->HandleTagDeclDefinition(D);
+void ASTResultSynthesizer::HandleTagDeclDefinition(TagDecl *D) {
+  if (m_passthrough)
+    m_passthrough->HandleTagDeclDefinition(D);
 }
 
-void
-ASTResultSynthesizer::CompleteTentativeDefinition(VarDecl *D)
-{
-    if (m_passthrough)
-        m_passthrough->CompleteTentativeDefinition(D);
+void ASTResultSynthesizer::CompleteTentativeDefinition(VarDecl *D) {
+  if (m_passthrough)
+    m_passthrough->CompleteTentativeDefinition(D);
 }
 
-void
-ASTResultSynthesizer::HandleVTable(CXXRecordDecl *RD)
-{
-    if (m_passthrough)
-        m_passthrough->HandleVTable(RD);
+void ASTResultSynthesizer::HandleVTable(CXXRecordDecl *RD) {
+  if (m_passthrough)
+    m_passthrough->HandleVTable(RD);
 }
 
-void
-ASTResultSynthesizer::PrintStats()
-{
-    if (m_passthrough)
-        m_passthrough->PrintStats();
+void ASTResultSynthesizer::PrintStats() {
+  if (m_passthrough)
+    m_passthrough->PrintStats();
 }
 
-void
-ASTResultSynthesizer::InitializeSema(Sema &S)
-{
-    m_sema = &S;
+void ASTResultSynthesizer::InitializeSema(Sema &S) {
+  m_sema = &S;
 
-    if (m_passthrough_sema)
-        m_passthrough_sema->InitializeSema(S);
+  if (m_passthrough_sema)
+    m_passthrough_sema->InitializeSema(S);
 }
 
-void
-ASTResultSynthesizer::ForgetSema()
-{
-    m_sema = NULL;
+void ASTResultSynthesizer::ForgetSema() {
+  m_sema = NULL;
 
-    if (m_passthrough_sema)
-        m_passthrough_sema->ForgetSema();
+  if (m_passthrough_sema)
+    m_passthrough_sema->ForgetSema();
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.h Tue Sep  6 15:57:50 2016
@@ -10,201 +10,204 @@
 #ifndef liblldb_ASTResultSynthesizer_h_
 #define liblldb_ASTResultSynthesizer_h_
 
-#include "clang/Sema/SemaConsumer.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Target/Target.h"
+#include "clang/Sema/SemaConsumer.h"
 
 namespace lldb_private {
 
 //----------------------------------------------------------------------
-/// @class ASTResultSynthesizer ASTResultSynthesizer.h "lldb/Expression/ASTResultSynthesizer.h"
+/// @class ASTResultSynthesizer ASTResultSynthesizer.h
+/// "lldb/Expression/ASTResultSynthesizer.h"
 /// @brief Adds a result variable declaration to the ASTs for an expression.
 ///
 /// Users expect the expression "i + 3" to return a result, even if a result
-/// variable wasn't specifically declared.  To fulfil this requirement, LLDB adds
-/// a result variable to the expression, transforming it to 
+/// variable wasn't specifically declared.  To fulfil this requirement, LLDB
+/// adds
+/// a result variable to the expression, transforming it to
 /// "int $__lldb_expr_result = i + 3."  The IR transformers ensure that the
 /// resulting variable is mapped to the right piece of memory.
 /// ASTResultSynthesizer's job is to add the variable and its initialization to
 /// the ASTs for the expression, and it does so by acting as a SemaConsumer for
 /// Clang.
 //----------------------------------------------------------------------
-class ASTResultSynthesizer : public clang::SemaConsumer
-{
+class ASTResultSynthesizer : public clang::SemaConsumer {
 public:
-    //----------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// @param[in] passthrough
-    ///     Since the ASTs must typically go through to the Clang code generator
-    ///     in order to produce LLVM IR, this SemaConsumer must allow them to
-    ///     pass to the next step in the chain after processing.  Passthrough is
-    ///     the next ASTConsumer, or NULL if none is required.
-    ///
-    /// @param[in] top_level
-    ///     If true, register all top-level Decls and don't try to handle the
-    ///     main function.
-    ///
-    /// @param[in] target
-    ///     The target, which contains the persistent variable store and the
-    ///     AST importer.
-    //----------------------------------------------------------------------
-    ASTResultSynthesizer(clang::ASTConsumer *passthrough, bool top_level, Target &target);
-
-    //----------------------------------------------------------------------
-    /// Destructor
-    //----------------------------------------------------------------------
-    ~ASTResultSynthesizer() override;
-    
-    //----------------------------------------------------------------------
-    /// Link this consumer with a particular AST context
-    ///
-    /// @param[in] Context
-    ///     This AST context will be used for types and identifiers, and also
-    ///     forwarded to the passthrough consumer, if one exists.
-    //----------------------------------------------------------------------
-    void Initialize(clang::ASTContext &Context) override;
-    
-    //----------------------------------------------------------------------
-    /// Examine a list of Decls to find the function $__lldb_expr and 
-    /// transform its code
-    ///
-    /// @param[in] D
-    ///     The list of Decls to search.  These may contain LinkageSpecDecls,
-    ///     which need to be searched recursively.  That job falls to
-    ///     TransformTopLevelDecl.
-    //----------------------------------------------------------------------
-    bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void HandleTranslationUnit(clang::ASTContext &Ctx) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void HandleTagDeclDefinition(clang::TagDecl *D) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void CompleteTentativeDefinition(clang::VarDecl *D) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void HandleVTable(clang::CXXRecordDecl *RD) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void PrintStats() override;
-    
-    //----------------------------------------------------------------------
-    /// Set the Sema object to use when performing transforms, and pass it on
-    ///
-    /// @param[in] S
-    ///     The Sema to use.  Because Sema isn't externally visible, this class
-    ///     casts it to an Action for actual use.
-    //----------------------------------------------------------------------
-    void InitializeSema(clang::Sema &S) override;
-
-    //----------------------------------------------------------------------
-    /// Reset the Sema to NULL now that transformations are done
-    //----------------------------------------------------------------------
-    void
-    ForgetSema() override;
-
-    //----------------------------------------------------------------------
-    /// The parse has succeeded, so record its persistent decls
-    //----------------------------------------------------------------------
-    void
-    CommitPersistentDecls();
+  //----------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// @param[in] passthrough
+  ///     Since the ASTs must typically go through to the Clang code generator
+  ///     in order to produce LLVM IR, this SemaConsumer must allow them to
+  ///     pass to the next step in the chain after processing.  Passthrough is
+  ///     the next ASTConsumer, or NULL if none is required.
+  ///
+  /// @param[in] top_level
+  ///     If true, register all top-level Decls and don't try to handle the
+  ///     main function.
+  ///
+  /// @param[in] target
+  ///     The target, which contains the persistent variable store and the
+  ///     AST importer.
+  //----------------------------------------------------------------------
+  ASTResultSynthesizer(clang::ASTConsumer *passthrough, bool top_level,
+                       Target &target);
+
+  //----------------------------------------------------------------------
+  /// Destructor
+  //----------------------------------------------------------------------
+  ~ASTResultSynthesizer() override;
+
+  //----------------------------------------------------------------------
+  /// Link this consumer with a particular AST context
+  ///
+  /// @param[in] Context
+  ///     This AST context will be used for types and identifiers, and also
+  ///     forwarded to the passthrough consumer, if one exists.
+  //----------------------------------------------------------------------
+  void Initialize(clang::ASTContext &Context) override;
+
+  //----------------------------------------------------------------------
+  /// Examine a list of Decls to find the function $__lldb_expr and
+  /// transform its code
+  ///
+  /// @param[in] D
+  ///     The list of Decls to search.  These may contain LinkageSpecDecls,
+  ///     which need to be searched recursively.  That job falls to
+  ///     TransformTopLevelDecl.
+  //----------------------------------------------------------------------
+  bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void HandleTranslationUnit(clang::ASTContext &Ctx) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void HandleTagDeclDefinition(clang::TagDecl *D) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void CompleteTentativeDefinition(clang::VarDecl *D) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void HandleVTable(clang::CXXRecordDecl *RD) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void PrintStats() override;
+
+  //----------------------------------------------------------------------
+  /// Set the Sema object to use when performing transforms, and pass it on
+  ///
+  /// @param[in] S
+  ///     The Sema to use.  Because Sema isn't externally visible, this class
+  ///     casts it to an Action for actual use.
+  //----------------------------------------------------------------------
+  void InitializeSema(clang::Sema &S) override;
+
+  //----------------------------------------------------------------------
+  /// Reset the Sema to NULL now that transformations are done
+  //----------------------------------------------------------------------
+  void ForgetSema() override;
+
+  //----------------------------------------------------------------------
+  /// The parse has succeeded, so record its persistent decls
+  //----------------------------------------------------------------------
+  void CommitPersistentDecls();
 
 private:
-    //----------------------------------------------------------------------
-    /// Hunt the given Decl for FunctionDecls named $__lldb_expr, recursing
-    /// as necessary through LinkageSpecDecls, and calling SynthesizeResult on
-    /// anything that was found
-    ///
-    /// @param[in] D
-    ///     The Decl to hunt.
-    //----------------------------------------------------------------------
-    void TransformTopLevelDecl(clang::Decl *D);
-    
-    //----------------------------------------------------------------------
-    /// Process an Objective-C method and produce the result variable and
-    /// initialization
-    ///
-    /// @param[in] MethodDecl
-    ///     The method to process.
-    //----------------------------------------------------------------------
-    bool SynthesizeObjCMethodResult(clang::ObjCMethodDecl *MethodDecl);
-    
-    //----------------------------------------------------------------------
-    /// Process a function and produce the result variable and initialization
-    ///
-    /// @param[in] FunDecl
-    ///     The function to process.
-    //----------------------------------------------------------------------
-    bool SynthesizeFunctionResult(clang::FunctionDecl *FunDecl);
-    
-    //----------------------------------------------------------------------
-    /// Process a function body and produce the result variable and 
-    /// initialization
-    ///
-    /// @param[in] Body
-    ///     The body of the function.
-    ///
-    /// @param[in] DC
-    ///     The DeclContext of the function, into which the result variable
-    ///     is inserted.
-    //----------------------------------------------------------------------
-    bool SynthesizeBodyResult(clang::CompoundStmt *Body,
-                              clang::DeclContext *DC);
-    
-    //----------------------------------------------------------------------
-    /// Given a DeclContext for a function or method, find all types
-    /// declared in the context and record any persistent types found.
-    ///
-    /// @param[in] FunDeclCtx
-    ///     The context for the function to process.
-    //----------------------------------------------------------------------
-    void RecordPersistentTypes(clang::DeclContext *FunDeclCtx);
-    
-    //----------------------------------------------------------------------
-    /// Given a TypeDecl, if it declares a type whose name starts with a
-    /// dollar sign, register it as a pointer type in the target's scratch
-    /// AST context.
-    ///
-    /// @param[in] Body
-    ///     The body of the function.
-    //----------------------------------------------------------------------
-    void
-    MaybeRecordPersistentType(clang::TypeDecl *D);
-
-    //----------------------------------------------------------------------
-    /// Given a NamedDecl, register it as a pointer type in the target's scratch
-    /// AST context.
-    ///
-    /// @param[in] Body
-    ///     The body of the function.
-    //----------------------------------------------------------------------
-    void
-    RecordPersistentDecl(clang::NamedDecl *D);
-
-    clang::ASTContext *m_ast_context; ///< The AST context to use for identifiers and types.
-    clang::ASTConsumer
-        *m_passthrough; ///< The ASTConsumer down the chain, for passthrough.  NULL if it's a SemaConsumer.
-    clang::SemaConsumer
-        *m_passthrough_sema; ///< The SemaConsumer down the chain, for passthrough.  NULL if it's an ASTConsumer.
-
-    std::vector<clang::NamedDecl *> m_decls; ///< Persistent declarations to register assuming the expression succeeds.
-
-    Target &m_target;    ///< The target, which contains the persistent variable store and the
-    clang::Sema *m_sema; ///< The Sema to use.
-    bool m_top_level;
+  //----------------------------------------------------------------------
+  /// Hunt the given Decl for FunctionDecls named $__lldb_expr, recursing
+  /// as necessary through LinkageSpecDecls, and calling SynthesizeResult on
+  /// anything that was found
+  ///
+  /// @param[in] D
+  ///     The Decl to hunt.
+  //----------------------------------------------------------------------
+  void TransformTopLevelDecl(clang::Decl *D);
+
+  //----------------------------------------------------------------------
+  /// Process an Objective-C method and produce the result variable and
+  /// initialization
+  ///
+  /// @param[in] MethodDecl
+  ///     The method to process.
+  //----------------------------------------------------------------------
+  bool SynthesizeObjCMethodResult(clang::ObjCMethodDecl *MethodDecl);
+
+  //----------------------------------------------------------------------
+  /// Process a function and produce the result variable and initialization
+  ///
+  /// @param[in] FunDecl
+  ///     The function to process.
+  //----------------------------------------------------------------------
+  bool SynthesizeFunctionResult(clang::FunctionDecl *FunDecl);
+
+  //----------------------------------------------------------------------
+  /// Process a function body and produce the result variable and
+  /// initialization
+  ///
+  /// @param[in] Body
+  ///     The body of the function.
+  ///
+  /// @param[in] DC
+  ///     The DeclContext of the function, into which the result variable
+  ///     is inserted.
+  //----------------------------------------------------------------------
+  bool SynthesizeBodyResult(clang::CompoundStmt *Body, clang::DeclContext *DC);
+
+  //----------------------------------------------------------------------
+  /// Given a DeclContext for a function or method, find all types
+  /// declared in the context and record any persistent types found.
+  ///
+  /// @param[in] FunDeclCtx
+  ///     The context for the function to process.
+  //----------------------------------------------------------------------
+  void RecordPersistentTypes(clang::DeclContext *FunDeclCtx);
+
+  //----------------------------------------------------------------------
+  /// Given a TypeDecl, if it declares a type whose name starts with a
+  /// dollar sign, register it as a pointer type in the target's scratch
+  /// AST context.
+  ///
+  /// @param[in] Body
+  ///     The body of the function.
+  //----------------------------------------------------------------------
+  void MaybeRecordPersistentType(clang::TypeDecl *D);
+
+  //----------------------------------------------------------------------
+  /// Given a NamedDecl, register it as a pointer type in the target's scratch
+  /// AST context.
+  ///
+  /// @param[in] Body
+  ///     The body of the function.
+  //----------------------------------------------------------------------
+  void RecordPersistentDecl(clang::NamedDecl *D);
+
+  clang::ASTContext
+      *m_ast_context; ///< The AST context to use for identifiers and types.
+  clang::ASTConsumer *m_passthrough; ///< The ASTConsumer down the chain, for
+                                     ///passthrough.  NULL if it's a
+                                     ///SemaConsumer.
+  clang::SemaConsumer *m_passthrough_sema; ///< The SemaConsumer down the chain,
+                                           ///for passthrough.  NULL if it's an
+                                           ///ASTConsumer.
+
+  std::vector<clang::NamedDecl *> m_decls; ///< Persistent declarations to
+                                           ///register assuming the expression
+                                           ///succeeds.
+
+  Target &m_target;    ///< The target, which contains the persistent variable
+                       ///store and the
+  clang::Sema *m_sema; ///< The Sema to use.
+  bool m_top_level;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp Tue Sep  6 15:57:50 2016
@@ -9,6 +9,7 @@
 
 #include "ASTStructExtractor.h"
 
+#include "lldb/Core/Log.h"
 #include "stdlib.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
@@ -21,7 +22,6 @@
 #include "clang/Sema/Sema.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
-#include "lldb/Core/Log.h"
 
 using namespace llvm;
 using namespace clang;
@@ -29,193 +29,158 @@ using namespace lldb_private;
 
 ASTStructExtractor::ASTStructExtractor(ASTConsumer *passthrough,
                                        const char *struct_name,
-                                       ClangFunctionCaller &function) :
-    m_ast_context (NULL),
-    m_passthrough (passthrough),
-    m_passthrough_sema (NULL),
-    m_sema (NULL),
-    m_action (NULL),
-    m_function (function),
-    m_struct_name (struct_name)
-{
-    if (!m_passthrough)
-        return;
-
-    m_passthrough_sema = dyn_cast<SemaConsumer>(passthrough);
-}
-
-ASTStructExtractor::~ASTStructExtractor()
-{
-}
-
-void
-ASTStructExtractor::Initialize(ASTContext &Context)
-{
-    m_ast_context = &Context;
-
-    if (m_passthrough)
-        m_passthrough->Initialize(Context);
-}
-
-void
-ASTStructExtractor::ExtractFromFunctionDecl(FunctionDecl *F)
-{
-    if (!F->hasBody())
-        return;
-
-    Stmt *body_stmt = F->getBody();
-    CompoundStmt *body_compound_stmt = dyn_cast<CompoundStmt>(body_stmt);
-
-    if (!body_compound_stmt)
-        return; // do we have to handle this?
-
-    RecordDecl *struct_decl = NULL;
-
-    StringRef desired_name(m_struct_name.c_str());
-
-    for (CompoundStmt::const_body_iterator bi = body_compound_stmt->body_begin(), be = body_compound_stmt->body_end();
-         bi != be;
-         ++bi)
-    {
-        Stmt *curr_stmt = *bi;
-        DeclStmt *curr_decl_stmt = dyn_cast<DeclStmt>(curr_stmt);
-        if (!curr_decl_stmt)
-            continue;
-        DeclGroupRef decl_group = curr_decl_stmt->getDeclGroup();
-        for (Decl *candidate_decl : decl_group)
-        {
-            RecordDecl *candidate_record_decl = dyn_cast<RecordDecl>(candidate_decl);
-            if (!candidate_record_decl)
-                continue;
-            if (candidate_record_decl->getName() == desired_name)
-            {
-                struct_decl = candidate_record_decl;
-                break;
-            }
-        }
-        if (struct_decl)
-            break;
+                                       ClangFunctionCaller &function)
+    : m_ast_context(NULL), m_passthrough(passthrough), m_passthrough_sema(NULL),
+      m_sema(NULL), m_action(NULL), m_function(function),
+      m_struct_name(struct_name) {
+  if (!m_passthrough)
+    return;
+
+  m_passthrough_sema = dyn_cast<SemaConsumer>(passthrough);
+}
+
+ASTStructExtractor::~ASTStructExtractor() {}
+
+void ASTStructExtractor::Initialize(ASTContext &Context) {
+  m_ast_context = &Context;
+
+  if (m_passthrough)
+    m_passthrough->Initialize(Context);
+}
+
+void ASTStructExtractor::ExtractFromFunctionDecl(FunctionDecl *F) {
+  if (!F->hasBody())
+    return;
+
+  Stmt *body_stmt = F->getBody();
+  CompoundStmt *body_compound_stmt = dyn_cast<CompoundStmt>(body_stmt);
+
+  if (!body_compound_stmt)
+    return; // do we have to handle this?
+
+  RecordDecl *struct_decl = NULL;
+
+  StringRef desired_name(m_struct_name.c_str());
+
+  for (CompoundStmt::const_body_iterator bi = body_compound_stmt->body_begin(),
+                                         be = body_compound_stmt->body_end();
+       bi != be; ++bi) {
+    Stmt *curr_stmt = *bi;
+    DeclStmt *curr_decl_stmt = dyn_cast<DeclStmt>(curr_stmt);
+    if (!curr_decl_stmt)
+      continue;
+    DeclGroupRef decl_group = curr_decl_stmt->getDeclGroup();
+    for (Decl *candidate_decl : decl_group) {
+      RecordDecl *candidate_record_decl = dyn_cast<RecordDecl>(candidate_decl);
+      if (!candidate_record_decl)
+        continue;
+      if (candidate_record_decl->getName() == desired_name) {
+        struct_decl = candidate_record_decl;
+        break;
+      }
     }
+    if (struct_decl)
+      break;
+  }
 
-    if (!struct_decl)
-        return;
+  if (!struct_decl)
+    return;
 
-    const ASTRecordLayout* struct_layout(&m_ast_context->getASTRecordLayout (struct_decl));
+  const ASTRecordLayout *struct_layout(
+      &m_ast_context->getASTRecordLayout(struct_decl));
 
-    if (!struct_layout)
-        return;
+  if (!struct_layout)
+    return;
 
-    m_function.m_struct_size = struct_layout->getSize().getQuantity(); // TODO Store m_struct_size as CharUnits
-    m_function.m_return_offset = struct_layout->getFieldOffset(struct_layout->getFieldCount() - 1) / 8;
-    m_function.m_return_size = struct_layout->getDataSize().getQuantity() - m_function.m_return_offset;
-
-    for (unsigned field_index = 0, num_fields = struct_layout->getFieldCount();
-         field_index < num_fields;
-         ++field_index)
-    {
-        m_function.m_member_offsets.push_back(struct_layout->getFieldOffset(field_index) / 8);
-    }
+  m_function.m_struct_size =
+      struct_layout->getSize()
+          .getQuantity(); // TODO Store m_struct_size as CharUnits
+  m_function.m_return_offset =
+      struct_layout->getFieldOffset(struct_layout->getFieldCount() - 1) / 8;
+  m_function.m_return_size =
+      struct_layout->getDataSize().getQuantity() - m_function.m_return_offset;
 
-    m_function.m_struct_valid = true;
+  for (unsigned field_index = 0, num_fields = struct_layout->getFieldCount();
+       field_index < num_fields; ++field_index) {
+    m_function.m_member_offsets.push_back(
+        struct_layout->getFieldOffset(field_index) / 8);
+  }
+
+  m_function.m_struct_valid = true;
 }
 
-void
-ASTStructExtractor::ExtractFromTopLevelDecl(Decl* D)
-{
-    LinkageSpecDecl *linkage_spec_decl = dyn_cast<LinkageSpecDecl>(D);
-
-    if (linkage_spec_decl)
-    {
-        RecordDecl::decl_iterator decl_iterator;
-
-        for (decl_iterator = linkage_spec_decl->decls_begin();
-             decl_iterator != linkage_spec_decl->decls_end();
-             ++decl_iterator)
-        {
-            ExtractFromTopLevelDecl(*decl_iterator);
-        }
-    }
+void ASTStructExtractor::ExtractFromTopLevelDecl(Decl *D) {
+  LinkageSpecDecl *linkage_spec_decl = dyn_cast<LinkageSpecDecl>(D);
 
-    FunctionDecl *function_decl = dyn_cast<FunctionDecl>(D);
+  if (linkage_spec_decl) {
+    RecordDecl::decl_iterator decl_iterator;
 
-    if (m_ast_context &&
-        function_decl &&
-        !m_function.m_wrapper_function_name.compare(function_decl->getNameAsString().c_str()))
-    {
-        ExtractFromFunctionDecl(function_decl);
+    for (decl_iterator = linkage_spec_decl->decls_begin();
+         decl_iterator != linkage_spec_decl->decls_end(); ++decl_iterator) {
+      ExtractFromTopLevelDecl(*decl_iterator);
     }
+  }
+
+  FunctionDecl *function_decl = dyn_cast<FunctionDecl>(D);
+
+  if (m_ast_context && function_decl &&
+      !m_function.m_wrapper_function_name.compare(
+          function_decl->getNameAsString().c_str())) {
+    ExtractFromFunctionDecl(function_decl);
+  }
 }
 
-bool
-ASTStructExtractor::HandleTopLevelDecl(DeclGroupRef D)
-{
-    DeclGroupRef::iterator decl_iterator;
-
-    for (decl_iterator = D.begin();
-         decl_iterator != D.end();
-         ++decl_iterator)
-    {
-        Decl *decl = *decl_iterator;
+bool ASTStructExtractor::HandleTopLevelDecl(DeclGroupRef D) {
+  DeclGroupRef::iterator decl_iterator;
 
-        ExtractFromTopLevelDecl(decl);
-    }
+  for (decl_iterator = D.begin(); decl_iterator != D.end(); ++decl_iterator) {
+    Decl *decl = *decl_iterator;
+
+    ExtractFromTopLevelDecl(decl);
+  }
 
-    if (m_passthrough)
-        return m_passthrough->HandleTopLevelDecl(D);
-    return true;
+  if (m_passthrough)
+    return m_passthrough->HandleTopLevelDecl(D);
+  return true;
 }
 
-void
-ASTStructExtractor::HandleTranslationUnit(ASTContext &Ctx)
-{
-    if (m_passthrough)
-        m_passthrough->HandleTranslationUnit(Ctx);
+void ASTStructExtractor::HandleTranslationUnit(ASTContext &Ctx) {
+  if (m_passthrough)
+    m_passthrough->HandleTranslationUnit(Ctx);
 }
 
-void
-ASTStructExtractor::HandleTagDeclDefinition(TagDecl *D)
-{
-    if (m_passthrough)
-        m_passthrough->HandleTagDeclDefinition(D);
+void ASTStructExtractor::HandleTagDeclDefinition(TagDecl *D) {
+  if (m_passthrough)
+    m_passthrough->HandleTagDeclDefinition(D);
 }
 
-void
-ASTStructExtractor::CompleteTentativeDefinition(VarDecl *D)
-{
-    if (m_passthrough)
-        m_passthrough->CompleteTentativeDefinition(D);
+void ASTStructExtractor::CompleteTentativeDefinition(VarDecl *D) {
+  if (m_passthrough)
+    m_passthrough->CompleteTentativeDefinition(D);
 }
 
-void
-ASTStructExtractor::HandleVTable(CXXRecordDecl *RD)
-{
-    if (m_passthrough)
-        m_passthrough->HandleVTable(RD);
+void ASTStructExtractor::HandleVTable(CXXRecordDecl *RD) {
+  if (m_passthrough)
+    m_passthrough->HandleVTable(RD);
 }
 
-void
-ASTStructExtractor::PrintStats()
-{
-    if (m_passthrough)
-        m_passthrough->PrintStats();
+void ASTStructExtractor::PrintStats() {
+  if (m_passthrough)
+    m_passthrough->PrintStats();
 }
 
-void
-ASTStructExtractor::InitializeSema(Sema &S)
-{
-    m_sema = &S;
-    m_action = reinterpret_cast<Action*>(m_sema);
+void ASTStructExtractor::InitializeSema(Sema &S) {
+  m_sema = &S;
+  m_action = reinterpret_cast<Action *>(m_sema);
 
-    if (m_passthrough_sema)
-        m_passthrough_sema->InitializeSema(S);
+  if (m_passthrough_sema)
+    m_passthrough_sema->InitializeSema(S);
 }
 
-void
-ASTStructExtractor::ForgetSema()
-{
-    m_sema = NULL;
-    m_action = NULL;
+void ASTStructExtractor::ForgetSema() {
+  m_sema = NULL;
+  m_action = NULL;
 
-    if (m_passthrough_sema)
-        m_passthrough_sema->ForgetSema();
+  if (m_passthrough_sema)
+    m_passthrough_sema->ForgetSema();
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.h Tue Sep  6 15:57:50 2016
@@ -13,16 +13,18 @@
 #include "ClangExpressionVariable.h"
 #include "ClangFunctionCaller.h"
 
-#include "clang/Sema/SemaConsumer.h"
 #include "lldb/Core/ClangForward.h"
+#include "clang/Sema/SemaConsumer.h"
 
 namespace lldb_private {
-    
+
 //----------------------------------------------------------------------
-/// @class ASTStructExtractor ASTStructExtractor.h "lldb/Expression/ASTStructExtractor.h"
+/// @class ASTStructExtractor ASTStructExtractor.h
+/// "lldb/Expression/ASTStructExtractor.h"
 /// @brief Extracts and describes the argument structure for a wrapped function.
 ///
-/// This pass integrates with ClangFunctionCaller, which calls functions with custom
+/// This pass integrates with ClangFunctionCaller, which calls functions with
+/// custom
 /// sets of arguments.  To avoid having to implement the full calling convention
 /// for the target's architecture, ClangFunctionCaller writes a simple wrapper
 /// function that takes a pointer to an argument structure that contains room
@@ -33,126 +35,130 @@ namespace lldb_private {
 /// so Clang does the structure layout itself.  ASTStructExtractor reads through
 /// the AST for the wrapper function and finds the struct.
 //----------------------------------------------------------------------
-class ASTStructExtractor : public clang::SemaConsumer
-{
+class ASTStructExtractor : public clang::SemaConsumer {
 public:
-    //----------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// @param[in] passthrough
-    ///     Since the ASTs must typically go through to the Clang code generator
-    ///     in order to produce LLVM IR, this SemaConsumer must allow them to
-    ///     pass to the next step in the chain after processing.  Passthrough is
-    ///     the next ASTConsumer, or NULL if none is required.
-    ///
-    /// @param[in] struct_name
-    ///     The name of the structure to extract from the wrapper function.
-    ///
-    /// @param[in] function
-    ///     The caller object whose members should be populated with information
-    ///     about the argument struct.  ClangFunctionCaller friends ASTStructExtractor
-    ///     for this purpose.
-    //----------------------------------------------------------------------
-    ASTStructExtractor(clang::ASTConsumer *passthrough,
-                       const char *struct_name,
-                       ClangFunctionCaller &function);
-    
-    //----------------------------------------------------------------------
-    /// Destructor
-    //----------------------------------------------------------------------
-    ~ASTStructExtractor() override;
-    
-    //----------------------------------------------------------------------
-    /// Link this consumer with a particular AST context
-    ///
-    /// @param[in] Context
-    ///     This AST context will be used for types and identifiers, and also
-    ///     forwarded to the passthrough consumer, if one exists.
-    //----------------------------------------------------------------------
-    void Initialize(clang::ASTContext &Context) override;
-    
-    //----------------------------------------------------------------------
-    /// Examine a list of Decls to find the function $__lldb_expr and 
-    /// transform its code
-    ///
-    /// @param[in] D
-    ///     The list of Decls to search.  These may contain LinkageSpecDecls,
-    ///     which need to be searched recursively.  That job falls to
-    ///     TransformTopLevelDecl.
-    //----------------------------------------------------------------------
-    bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void HandleTranslationUnit(clang::ASTContext &Ctx) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void HandleTagDeclDefinition(clang::TagDecl *D) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void CompleteTentativeDefinition(clang::VarDecl *D) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void HandleVTable(clang::CXXRecordDecl *RD) override;
-    
-    //----------------------------------------------------------------------
-    /// Passthrough stub
-    //----------------------------------------------------------------------
-    void PrintStats() override;
-    
-    //----------------------------------------------------------------------
-    /// Set the Sema object to use when performing transforms, and pass it on
-    ///
-    /// @param[in] S
-    ///     The Sema to use.  Because Sema isn't externally visible, this class
-    ///     casts it to an Action for actual use.
-    //----------------------------------------------------------------------
-    void InitializeSema(clang::Sema &S) override;
-    
-    //----------------------------------------------------------------------
-    /// Reset the Sema to NULL now that transformations are done
-    //----------------------------------------------------------------------
-    void ForgetSema() override;
+  //----------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// @param[in] passthrough
+  ///     Since the ASTs must typically go through to the Clang code generator
+  ///     in order to produce LLVM IR, this SemaConsumer must allow them to
+  ///     pass to the next step in the chain after processing.  Passthrough is
+  ///     the next ASTConsumer, or NULL if none is required.
+  ///
+  /// @param[in] struct_name
+  ///     The name of the structure to extract from the wrapper function.
+  ///
+  /// @param[in] function
+  ///     The caller object whose members should be populated with information
+  ///     about the argument struct.  ClangFunctionCaller friends
+  ///     ASTStructExtractor
+  ///     for this purpose.
+  //----------------------------------------------------------------------
+  ASTStructExtractor(clang::ASTConsumer *passthrough, const char *struct_name,
+                     ClangFunctionCaller &function);
+
+  //----------------------------------------------------------------------
+  /// Destructor
+  //----------------------------------------------------------------------
+  ~ASTStructExtractor() override;
+
+  //----------------------------------------------------------------------
+  /// Link this consumer with a particular AST context
+  ///
+  /// @param[in] Context
+  ///     This AST context will be used for types and identifiers, and also
+  ///     forwarded to the passthrough consumer, if one exists.
+  //----------------------------------------------------------------------
+  void Initialize(clang::ASTContext &Context) override;
+
+  //----------------------------------------------------------------------
+  /// Examine a list of Decls to find the function $__lldb_expr and
+  /// transform its code
+  ///
+  /// @param[in] D
+  ///     The list of Decls to search.  These may contain LinkageSpecDecls,
+  ///     which need to be searched recursively.  That job falls to
+  ///     TransformTopLevelDecl.
+  //----------------------------------------------------------------------
+  bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void HandleTranslationUnit(clang::ASTContext &Ctx) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void HandleTagDeclDefinition(clang::TagDecl *D) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void CompleteTentativeDefinition(clang::VarDecl *D) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void HandleVTable(clang::CXXRecordDecl *RD) override;
+
+  //----------------------------------------------------------------------
+  /// Passthrough stub
+  //----------------------------------------------------------------------
+  void PrintStats() override;
+
+  //----------------------------------------------------------------------
+  /// Set the Sema object to use when performing transforms, and pass it on
+  ///
+  /// @param[in] S
+  ///     The Sema to use.  Because Sema isn't externally visible, this class
+  ///     casts it to an Action for actual use.
+  //----------------------------------------------------------------------
+  void InitializeSema(clang::Sema &S) override;
+
+  //----------------------------------------------------------------------
+  /// Reset the Sema to NULL now that transformations are done
+  //----------------------------------------------------------------------
+  void ForgetSema() override;
 
 private:
-    //----------------------------------------------------------------------
-    /// Hunt the given FunctionDecl for the argument struct and place
-    /// information about it into m_function
-    ///
-    /// @param[in] F
-    ///     The FunctionDecl to hunt.
-    //----------------------------------------------------------------------
-    void
-    ExtractFromFunctionDecl(clang::FunctionDecl* F);
-    
-    //----------------------------------------------------------------------
-    /// Hunt the given Decl for FunctionDecls named the same as the wrapper
-    /// function name, recursing as necessary through LinkageSpecDecls, and 
-    /// calling ExtractFromFunctionDecl on anything that was found
-    ///
-    /// @param[in] D
-    ///     The Decl to hunt.
-    //----------------------------------------------------------------------
-    void
-    ExtractFromTopLevelDecl(clang::Decl* D);
-    
-    clang::ASTContext              *m_ast_context;          ///< The AST context to use for identifiers and types.
-    clang::ASTConsumer             *m_passthrough;          ///< The ASTConsumer down the chain, for passthrough.  NULL if it's a SemaConsumer.
-    clang::SemaConsumer            *m_passthrough_sema;     ///< The SemaConsumer down the chain, for passthrough.  NULL if it's an ASTConsumer.
-    clang::Sema                    *m_sema;                 ///< The Sema to use.
-    clang::Action                  *m_action;               ///< The Sema to use, cast to an Action so it's usable.
-    
-    ClangFunctionCaller            &m_function;             ///< The function to populate with information about the argument structure.
-    std::string                     m_struct_name;          ///< The name of the structure to extract.
+  //----------------------------------------------------------------------
+  /// Hunt the given FunctionDecl for the argument struct and place
+  /// information about it into m_function
+  ///
+  /// @param[in] F
+  ///     The FunctionDecl to hunt.
+  //----------------------------------------------------------------------
+  void ExtractFromFunctionDecl(clang::FunctionDecl *F);
+
+  //----------------------------------------------------------------------
+  /// Hunt the given Decl for FunctionDecls named the same as the wrapper
+  /// function name, recursing as necessary through LinkageSpecDecls, and
+  /// calling ExtractFromFunctionDecl on anything that was found
+  ///
+  /// @param[in] D
+  ///     The Decl to hunt.
+  //----------------------------------------------------------------------
+  void ExtractFromTopLevelDecl(clang::Decl *D);
+
+  clang::ASTContext
+      *m_ast_context; ///< The AST context to use for identifiers and types.
+  clang::ASTConsumer *m_passthrough; ///< The ASTConsumer down the chain, for
+                                     ///passthrough.  NULL if it's a
+                                     ///SemaConsumer.
+  clang::SemaConsumer *m_passthrough_sema; ///< The SemaConsumer down the chain,
+                                           ///for passthrough.  NULL if it's an
+                                           ///ASTConsumer.
+  clang::Sema *m_sema;                     ///< The Sema to use.
+  clang::Action
+      *m_action; ///< The Sema to use, cast to an Action so it's usable.
+
+  ClangFunctionCaller &m_function; ///< The function to populate with
+                                   ///information about the argument structure.
+  std::string m_struct_name;       ///< The name of the structure to extract.
 };
-    
+
 } // namespace lldb_private
 
 #endif // liblldb_ASTStructExtractor_h_

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Tue Sep  6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- ClangASTSource.cpp ---------------------------------------*- C++ -*-===//
+//===-- ClangASTSource.cpp ---------------------------------------*- C++
+//-*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -37,884 +38,833 @@ using namespace lldb_private;
 // when it goes out of scope.
 //------------------------------------------------------------------
 namespace {
-    class ScopedLexicalDeclEraser
-    {
-    public:
-        ScopedLexicalDeclEraser(std::set<const clang::Decl *> &decls,
-                                const clang::Decl *decl)
-            : m_active_lexical_decls(decls), m_decl(decl)
-        {
-        }
-
-        ~ScopedLexicalDeclEraser()
-        {
-            m_active_lexical_decls.erase(m_decl);
-        }
-
-    private:
-        std::set<const clang::Decl *> &m_active_lexical_decls;
-        const clang::Decl *m_decl;
-    };
+class ScopedLexicalDeclEraser {
+public:
+  ScopedLexicalDeclEraser(std::set<const clang::Decl *> &decls,
+                          const clang::Decl *decl)
+      : m_active_lexical_decls(decls), m_decl(decl) {}
+
+  ~ScopedLexicalDeclEraser() { m_active_lexical_decls.erase(m_decl); }
+
+private:
+  std::set<const clang::Decl *> &m_active_lexical_decls;
+  const clang::Decl *m_decl;
+};
 }
 
-ClangASTSource::~ClangASTSource()
-{
-    m_ast_importer_sp->ForgetDestination(m_ast_context);
+ClangASTSource::~ClangASTSource() {
+  m_ast_importer_sp->ForgetDestination(m_ast_context);
 
-    // We are in the process of destruction, don't create clang ast context on demand
-    // by passing false to Target::GetScratchClangASTContext(create_on_demand).
-    ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false);
+  // We are in the process of destruction, don't create clang ast context on
+  // demand
+  // by passing false to Target::GetScratchClangASTContext(create_on_demand).
+  ClangASTContext *scratch_clang_ast_context =
+      m_target->GetScratchClangASTContext(false);
 
-    if (!scratch_clang_ast_context)
-        return;
+  if (!scratch_clang_ast_context)
+    return;
 
-    clang::ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext();
+  clang::ASTContext *scratch_ast_context =
+      scratch_clang_ast_context->getASTContext();
 
-    if (!scratch_ast_context)
-        return;
+  if (!scratch_ast_context)
+    return;
 
-    if (m_ast_context != scratch_ast_context)
-        m_ast_importer_sp->ForgetSource(scratch_ast_context, m_ast_context);
+  if (m_ast_context != scratch_ast_context)
+    m_ast_importer_sp->ForgetSource(scratch_ast_context, m_ast_context);
 }
 
-void
-ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer)
-{
-    if (!m_ast_context)
-        return;
+void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) {
+  if (!m_ast_context)
+    return;
 
-    m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage();
-    m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage();
+  m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage();
+  m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage();
 }
 
 // The core lookup interface.
-bool
-ClangASTSource::FindExternalVisibleDeclsByName
-(
-    const DeclContext *decl_ctx,
-    DeclarationName clang_decl_name
-)
-{
-    if (!m_ast_context)
-    {
-        SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
-        return false;
-    }
-
-    if (GetImportInProgress())
-    {
-        SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
-        return false;
-    }
-
-    std::string decl_name (clang_decl_name.getAsString());
+bool ClangASTSource::FindExternalVisibleDeclsByName(
+    const DeclContext *decl_ctx, DeclarationName clang_decl_name) {
+  if (!m_ast_context) {
+    SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+    return false;
+  }
+
+  if (GetImportInProgress()) {
+    SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+    return false;
+  }
+
+  std::string decl_name(clang_decl_name.getAsString());
+
+  //    if (m_decl_map.DoingASTImport ())
+  //      return DeclContext::lookup_result();
+  //
+  switch (clang_decl_name.getNameKind()) {
+  // Normal identifiers.
+  case DeclarationName::Identifier: {
+    clang::IdentifierInfo *identifier_info =
+        clang_decl_name.getAsIdentifierInfo();
 
-//    if (m_decl_map.DoingASTImport ())
-//      return DeclContext::lookup_result();
-//
-    switch (clang_decl_name.getNameKind()) {
-    // Normal identifiers.
-    case DeclarationName::Identifier:
-        {
-            clang::IdentifierInfo *identifier_info = clang_decl_name.getAsIdentifierInfo();
-
-            if (!identifier_info ||
-                identifier_info->getBuiltinID() != 0)
-            {
-                SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
-                return false;
-            }
-        }
-        break;
-
-    // Operator names.
-    case DeclarationName::CXXOperatorName:
-    case DeclarationName::CXXLiteralOperatorName:
-        break;
-
-    // Using directives found in this context.
-    // Tell Sema we didn't find any or we'll end up getting asked a *lot*.
-    case DeclarationName::CXXUsingDirective:
+    if (!identifier_info || identifier_info->getBuiltinID() != 0) {
       SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
       return false;
+    }
+  } break;
 
-    case DeclarationName::ObjCZeroArgSelector:
-    case DeclarationName::ObjCOneArgSelector:
-    case DeclarationName::ObjCMultiArgSelector:
-    {
-      llvm::SmallVector<NamedDecl*, 1> method_decls;
-
-      NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx);
-
-      FindObjCMethodDecls(method_search_context);
-
-      SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls);
-      return (method_decls.size() > 0);
-    }
-    // These aren't possible in the global context.
-    case DeclarationName::CXXConstructorName:
-    case DeclarationName::CXXDestructorName:
-    case DeclarationName::CXXConversionFunctionName:
+  // Operator names.
+  case DeclarationName::CXXOperatorName:
+  case DeclarationName::CXXLiteralOperatorName:
+    break;
+
+  // Using directives found in this context.
+  // Tell Sema we didn't find any or we'll end up getting asked a *lot*.
+  case DeclarationName::CXXUsingDirective:
+    SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+    return false;
+
+  case DeclarationName::ObjCZeroArgSelector:
+  case DeclarationName::ObjCOneArgSelector:
+  case DeclarationName::ObjCMultiArgSelector: {
+    llvm::SmallVector<NamedDecl *, 1> method_decls;
+
+    NameSearchContext method_search_context(*this, method_decls,
+                                            clang_decl_name, decl_ctx);
+
+    FindObjCMethodDecls(method_search_context);
+
+    SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, method_decls);
+    return (method_decls.size() > 0);
+  }
+  // These aren't possible in the global context.
+  case DeclarationName::CXXConstructorName:
+  case DeclarationName::CXXDestructorName:
+  case DeclarationName::CXXConversionFunctionName:
+    SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+    return false;
+  }
+
+  if (!GetLookupsEnabled()) {
+    // Wait until we see a '$' at the start of a name before we start doing
+    // any lookups so we can avoid lookup up all of the builtin types.
+    if (!decl_name.empty() && decl_name[0] == '$') {
+      SetLookupsEnabled(true);
+    } else {
       SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
       return false;
     }
+  }
 
+  ConstString const_decl_name(decl_name.c_str());
 
-    if (!GetLookupsEnabled())
-    {
-        // Wait until we see a '$' at the start of a name before we start doing
-        // any lookups so we can avoid lookup up all of the builtin types.
-        if (!decl_name.empty() && decl_name[0] == '$')
-        {
-            SetLookupsEnabled (true);
-        }
-        else
-        {
-            SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
-            return false;
-        }
-    }
+  const char *uniqued_const_decl_name = const_decl_name.GetCString();
+  if (m_active_lookups.find(uniqued_const_decl_name) !=
+      m_active_lookups.end()) {
+    // We are currently looking up this name...
+    SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+    return false;
+  }
+  m_active_lookups.insert(uniqued_const_decl_name);
+  //  static uint32_t g_depth = 0;
+  //  ++g_depth;
+  //  printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth,
+  //  uniqued_const_decl_name);
+  llvm::SmallVector<NamedDecl *, 4> name_decls;
+  NameSearchContext name_search_context(*this, name_decls, clang_decl_name,
+                                        decl_ctx);
+  FindExternalVisibleDecls(name_search_context);
+  SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, name_decls);
+  //  --g_depth;
+  m_active_lookups.erase(uniqued_const_decl_name);
+  return (name_decls.size() != 0);
+}
+
+void ClangASTSource::CompleteType(TagDecl *tag_decl) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
+
+  if (log) {
+    log->Printf("    CompleteTagDecl[%u] on (ASTContext*)%p Completing "
+                "(TagDecl*)%p named %s",
+                current_id, static_cast<void *>(m_ast_context),
+                static_cast<void *>(tag_decl),
+                tag_decl->getName().str().c_str());
+
+    log->Printf("      CTD[%u] Before:", current_id);
+    ASTDumper dumper((Decl *)tag_decl);
+    dumper.ToLog(log, "      [CTD] ");
+  }
 
-    ConstString const_decl_name(decl_name.c_str());
-
-    const char *uniqued_const_decl_name = const_decl_name.GetCString();
-    if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end())
-    {
-        // We are currently looking up this name...
-        SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
-        return false;
-    }
-    m_active_lookups.insert(uniqued_const_decl_name);
-//  static uint32_t g_depth = 0;
-//  ++g_depth;
-//  printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name);
-    llvm::SmallVector<NamedDecl*, 4> name_decls;
-    NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx);
-    FindExternalVisibleDecls(name_search_context);
-    SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls);
-//  --g_depth;
-    m_active_lookups.erase (uniqued_const_decl_name);
-    return (name_decls.size() != 0);
-}
-
-void
-ClangASTSource::CompleteType (TagDecl *tag_decl)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  auto iter = m_active_lexical_decls.find(tag_decl);
+  if (iter != m_active_lexical_decls.end())
+    return;
+  m_active_lexical_decls.insert(tag_decl);
+  ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl);
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+  if (!m_ast_importer_sp->CompleteTagDecl(tag_decl)) {
+    // We couldn't complete the type.  Maybe there's a definition
+    // somewhere else that can be completed.
 
     if (log)
-    {
-        log->Printf("    CompleteTagDecl[%u] on (ASTContext*)%p Completing (TagDecl*)%p named %s",
-                    current_id, static_cast<void*>(m_ast_context),
-                    static_cast<void*>(tag_decl),
-                    tag_decl->getName().str().c_str());
-
-        log->Printf("      CTD[%u] Before:", current_id);
-        ASTDumper dumper((Decl*)tag_decl);
-        dumper.ToLog(log, "      [CTD] ");
-    }
-
-    auto iter = m_active_lexical_decls.find(tag_decl);
-    if (iter != m_active_lexical_decls.end())
-        return;
-    m_active_lexical_decls.insert(tag_decl);
-    ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl);
-
-    if (!m_ast_importer_sp->CompleteTagDecl (tag_decl))
-    {
-        // We couldn't complete the type.  Maybe there's a definition
-        // somewhere else that can be completed.
-
-        if (log)
-            log->Printf("      CTD[%u] Type could not be completed in the module in which it was first found.", current_id);
+      log->Printf("      CTD[%u] Type could not be completed in the module in "
+                  "which it was first found.",
+                  current_id);
 
-        bool found = false;
-
-        DeclContext *decl_ctx = tag_decl->getDeclContext();
+    bool found = false;
 
-        if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx))
-        {
-            ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer_sp->GetNamespaceMap(namespace_context);
+    DeclContext *decl_ctx = tag_decl->getDeclContext();
 
-            if (log && log->GetVerbose())
-                log->Printf("      CTD[%u] Inspecting namespace map %p (%d entries)",
-                            current_id, static_cast<void*>(namespace_map.get()),
-                            static_cast<int>(namespace_map->size()));
+    if (const NamespaceDecl *namespace_context =
+            dyn_cast<NamespaceDecl>(decl_ctx)) {
+      ClangASTImporter::NamespaceMapSP namespace_map =
+          m_ast_importer_sp->GetNamespaceMap(namespace_context);
+
+      if (log && log->GetVerbose())
+        log->Printf("      CTD[%u] Inspecting namespace map %p (%d entries)",
+                    current_id, static_cast<void *>(namespace_map.get()),
+                    static_cast<int>(namespace_map->size()));
 
-            if (!namespace_map)
-                return;
+      if (!namespace_map)
+        return;
 
-            for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
-                 i != e && !found;
-                 ++i)
-            {
-                if (log)
-                    log->Printf("      CTD[%u] Searching namespace %s in module %s",
-                                current_id,
-                                i->second.GetName().AsCString(),
-                                i->first->GetFileSpec().GetFilename().GetCString());
+      for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
+                                                    e = namespace_map->end();
+           i != e && !found; ++i) {
+        if (log)
+          log->Printf("      CTD[%u] Searching namespace %s in module %s",
+                      current_id, i->second.GetName().AsCString(),
+                      i->first->GetFileSpec().GetFilename().GetCString());
 
-                TypeList types;
+        TypeList types;
 
-                SymbolContext null_sc;
-                ConstString name(tag_decl->getName().str().c_str());
+        SymbolContext null_sc;
+        ConstString name(tag_decl->getName().str().c_str());
 
-                i->first->FindTypesInNamespace(null_sc, name, &i->second, UINT32_MAX, types);
+        i->first->FindTypesInNamespace(null_sc, name, &i->second, UINT32_MAX,
+                                       types);
 
-                for (uint32_t ti = 0, te = types.GetSize();
-                     ti != te && !found;
-                     ++ti)
-                {
-                    lldb::TypeSP type = types.GetTypeAtIndex(ti);
+        for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
+          lldb::TypeSP type = types.GetTypeAtIndex(ti);
 
-                    if (!type)
-                        continue;
+          if (!type)
+            continue;
 
-                    CompilerType clang_type (type->GetFullCompilerType ());
+          CompilerType clang_type(type->GetFullCompilerType());
 
-                    if (!ClangUtil::IsClangType(clang_type))
-                        continue;
+          if (!ClangUtil::IsClangType(clang_type))
+            continue;
 
-                    const TagType *tag_type = ClangUtil::GetQualType(clang_type)->getAs<TagType>();
+          const TagType *tag_type =
+              ClangUtil::GetQualType(clang_type)->getAs<TagType>();
 
-                    if (!tag_type)
-                        continue;
+          if (!tag_type)
+            continue;
 
-                    TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
+          TagDecl *candidate_tag_decl =
+              const_cast<TagDecl *>(tag_type->getDecl());
 
-                    if (m_ast_importer_sp->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
-                        found = true;
-                }
-            }
+          if (m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl,
+                                                           candidate_tag_decl))
+            found = true;
         }
-        else
-        {
-            TypeList types;
+      }
+    } else {
+      TypeList types;
 
-            SymbolContext null_sc;
-            ConstString name(tag_decl->getName().str().c_str());
-            CompilerDeclContext namespace_decl;
+      SymbolContext null_sc;
+      ConstString name(tag_decl->getName().str().c_str());
+      CompilerDeclContext namespace_decl;
 
-            const ModuleList &module_list = m_target->GetImages();
+      const ModuleList &module_list = m_target->GetImages();
 
-            bool exact_match = false;
-            llvm::DenseSet<SymbolFile *> searched_symbol_files;
-            module_list.FindTypes (null_sc, name, exact_match, UINT32_MAX, searched_symbol_files, types);
+      bool exact_match = false;
+      llvm::DenseSet<SymbolFile *> searched_symbol_files;
+      module_list.FindTypes(null_sc, name, exact_match, UINT32_MAX,
+                            searched_symbol_files, types);
 
-            for (uint32_t ti = 0, te = types.GetSize();
-                 ti != te && !found;
-                 ++ti)
-            {
-                lldb::TypeSP type = types.GetTypeAtIndex(ti);
+      for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
+        lldb::TypeSP type = types.GetTypeAtIndex(ti);
 
-                if (!type)
-                    continue;
+        if (!type)
+          continue;
 
-                CompilerType clang_type (type->GetFullCompilerType ());
+        CompilerType clang_type(type->GetFullCompilerType());
 
-                if (!ClangUtil::IsClangType(clang_type))
-                    continue;
+        if (!ClangUtil::IsClangType(clang_type))
+          continue;
 
-                const TagType *tag_type = ClangUtil::GetQualType(clang_type)->getAs<TagType>();
+        const TagType *tag_type =
+            ClangUtil::GetQualType(clang_type)->getAs<TagType>();
 
-                if (!tag_type)
-                    continue;
+        if (!tag_type)
+          continue;
 
-                TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
+        TagDecl *candidate_tag_decl =
+            const_cast<TagDecl *>(tag_type->getDecl());
 
-                // We have found a type by basename and we need to make sure the decl contexts
-                // are the same before we can try to complete this type with another
-                if (!ClangASTContext::DeclsAreEquivalent (tag_decl, candidate_tag_decl))
-                    continue;
+        // We have found a type by basename and we need to make sure the decl
+        // contexts
+        // are the same before we can try to complete this type with another
+        if (!ClangASTContext::DeclsAreEquivalent(tag_decl, candidate_tag_decl))
+          continue;
 
-                if (m_ast_importer_sp->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
-                    found = true;
-            }
-        }
+        if (m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl,
+                                                         candidate_tag_decl))
+          found = true;
+      }
     }
+  }
 
-    if (log)
-    {
-        log->Printf("      [CTD] After:");
-        ASTDumper dumper((Decl*)tag_decl);
-        dumper.ToLog(log, "      [CTD] ");
-    }
+  if (log) {
+    log->Printf("      [CTD] After:");
+    ASTDumper dumper((Decl *)tag_decl);
+    dumper.ToLog(log, "      [CTD] ");
+  }
 }
 
-void
-ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (log)
-    {
-        log->Printf("    [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing an ObjCInterfaceDecl named %s",
-                    static_cast<void*>(m_ast_context),
-                    interface_decl->getName().str().c_str());
-        log->Printf("      [COID] Before:");
-        ASTDumper dumper((Decl*)interface_decl);
-        dumper.ToLog(log, "      [COID] ");
-    }
+  if (log) {
+    log->Printf("    [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing "
+                "an ObjCInterfaceDecl named %s",
+                static_cast<void *>(m_ast_context),
+                interface_decl->getName().str().c_str());
+    log->Printf("      [COID] Before:");
+    ASTDumper dumper((Decl *)interface_decl);
+    dumper.ToLog(log, "      [COID] ");
+  }
 
-    Decl *original_decl = NULL;
-    ASTContext *original_ctx = NULL;
+  Decl *original_decl = NULL;
+  ASTContext *original_ctx = NULL;
 
-    if (m_ast_importer_sp->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx))
-    {
-        if (ObjCInterfaceDecl *original_iface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl))
-        {
-            ObjCInterfaceDecl *complete_iface_decl = GetCompleteObjCInterface(original_iface_decl);
-
-            if (complete_iface_decl && (complete_iface_decl != original_iface_decl))
-            {
-                m_ast_importer_sp->SetDeclOrigin(interface_decl, original_iface_decl);
-            }
-        }
+  if (m_ast_importer_sp->ResolveDeclOrigin(interface_decl, &original_decl,
+                                           &original_ctx)) {
+    if (ObjCInterfaceDecl *original_iface_decl =
+            dyn_cast<ObjCInterfaceDecl>(original_decl)) {
+      ObjCInterfaceDecl *complete_iface_decl =
+          GetCompleteObjCInterface(original_iface_decl);
+
+      if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
+        m_ast_importer_sp->SetDeclOrigin(interface_decl, original_iface_decl);
+      }
     }
+  }
 
-    m_ast_importer_sp->CompleteObjCInterfaceDecl (interface_decl);
+  m_ast_importer_sp->CompleteObjCInterfaceDecl(interface_decl);
 
-    if (interface_decl->getSuperClass() &&
-        interface_decl->getSuperClass() != interface_decl)
-        CompleteType(interface_decl->getSuperClass());
+  if (interface_decl->getSuperClass() &&
+      interface_decl->getSuperClass() != interface_decl)
+    CompleteType(interface_decl->getSuperClass());
 
-    if (log)
-    {
-        log->Printf("      [COID] After:");
-        ASTDumper dumper((Decl*)interface_decl);
-        dumper.ToLog(log, "      [COID] ");
-    }
+  if (log) {
+    log->Printf("      [COID] After:");
+    ASTDumper dumper((Decl *)interface_decl);
+    dumper.ToLog(log, "      [COID] ");
+  }
 }
 
-clang::ObjCInterfaceDecl *
-ClangASTSource::GetCompleteObjCInterface (clang::ObjCInterfaceDecl *interface_decl)
-{
-    lldb::ProcessSP process(m_target->GetProcessSP());
+clang::ObjCInterfaceDecl *ClangASTSource::GetCompleteObjCInterface(
+    clang::ObjCInterfaceDecl *interface_decl) {
+  lldb::ProcessSP process(m_target->GetProcessSP());
 
-    if (!process)
-        return NULL;
+  if (!process)
+    return NULL;
 
-    ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
+  ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
 
-    if (!language_runtime)
-        return NULL;
+  if (!language_runtime)
+    return NULL;
 
-    ConstString class_name(interface_decl->getNameAsString().c_str());
+  ConstString class_name(interface_decl->getNameAsString().c_str());
 
-    lldb::TypeSP complete_type_sp(language_runtime->LookupInCompleteClassCache(class_name));
+  lldb::TypeSP complete_type_sp(
+      language_runtime->LookupInCompleteClassCache(class_name));
 
-    if (!complete_type_sp)
-        return NULL;
+  if (!complete_type_sp)
+    return NULL;
 
-    TypeFromUser complete_type = TypeFromUser(complete_type_sp->GetFullCompilerType ());
-    lldb::opaque_compiler_type_t complete_opaque_type = complete_type.GetOpaqueQualType();
+  TypeFromUser complete_type =
+      TypeFromUser(complete_type_sp->GetFullCompilerType());
+  lldb::opaque_compiler_type_t complete_opaque_type =
+      complete_type.GetOpaqueQualType();
 
-    if (!complete_opaque_type)
-        return NULL;
+  if (!complete_opaque_type)
+    return NULL;
 
-    const clang::Type *complete_clang_type = QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr();
-    const ObjCInterfaceType *complete_interface_type = dyn_cast<ObjCInterfaceType>(complete_clang_type);
+  const clang::Type *complete_clang_type =
+      QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr();
+  const ObjCInterfaceType *complete_interface_type =
+      dyn_cast<ObjCInterfaceType>(complete_clang_type);
 
-    if (!complete_interface_type)
-        return NULL;
+  if (!complete_interface_type)
+    return NULL;
 
-    ObjCInterfaceDecl *complete_iface_decl(complete_interface_type->getDecl());
+  ObjCInterfaceDecl *complete_iface_decl(complete_interface_type->getDecl());
 
-    return complete_iface_decl;
+  return complete_iface_decl;
 }
 
-void
-ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context,
-                                          llvm::function_ref<bool(Decl::Kind)> predicate,
-                                          llvm::SmallVectorImpl<Decl*> &decls)
-{
-    ClangASTMetrics::RegisterLexicalQuery();
+void ClangASTSource::FindExternalLexicalDecls(
+    const DeclContext *decl_context,
+    llvm::function_ref<bool(Decl::Kind)> predicate,
+    llvm::SmallVectorImpl<Decl *> &decls) {
+  ClangASTMetrics::RegisterLexicalQuery();
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    const Decl *context_decl = dyn_cast<Decl>(decl_context);
+  const Decl *context_decl = dyn_cast<Decl>(decl_context);
 
-    if (!context_decl)
-        return;
+  if (!context_decl)
+    return;
 
-    auto iter = m_active_lexical_decls.find(context_decl);
-    if (iter != m_active_lexical_decls.end())
-        return;
-    m_active_lexical_decls.insert(context_decl);
-    ScopedLexicalDeclEraser eraser(m_active_lexical_decls, context_decl);
+  auto iter = m_active_lexical_decls.find(context_decl);
+  if (iter != m_active_lexical_decls.end())
+    return;
+  m_active_lexical_decls.insert(context_decl);
+  ScopedLexicalDeclEraser eraser(m_active_lexical_decls, context_decl);
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
 
-    if (log)
-    {
-        if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
-            log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p",
-                        current_id, static_cast<void*>(m_ast_context),
-                        context_named_decl->getNameAsString().c_str(),
-                        context_decl->getDeclKindName(),
-                        static_cast<const void*>(context_decl));
-        else if(context_decl)
-            log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p",
-                        current_id, static_cast<void*>(m_ast_context),
-                        context_decl->getDeclKindName(),
-                        static_cast<const void*>(context_decl));
-        else
-            log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context",
-                        current_id, static_cast<const void*>(m_ast_context));
-    }
+  if (log) {
+    if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
+      log->Printf(
+          "FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p",
+          current_id, static_cast<void *>(m_ast_context),
+          context_named_decl->getNameAsString().c_str(),
+          context_decl->getDeclKindName(),
+          static_cast<const void *>(context_decl));
+    else if (context_decl)
+      log->Printf(
+          "FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p",
+          current_id, static_cast<void *>(m_ast_context),
+          context_decl->getDeclKindName(),
+          static_cast<const void *>(context_decl));
+    else
+      log->Printf(
+          "FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context",
+          current_id, static_cast<const void *>(m_ast_context));
+  }
 
-    Decl *original_decl = NULL;
-    ASTContext *original_ctx = NULL;
+  Decl *original_decl = NULL;
+  ASTContext *original_ctx = NULL;
 
-    if (!m_ast_importer_sp->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
-        return;
+  if (!m_ast_importer_sp->ResolveDeclOrigin(context_decl, &original_decl,
+                                            &original_ctx))
+    return;
 
-    if (log)
-    {
-        log->Printf("  FELD[%u] Original decl (ASTContext*)%p (Decl*)%p:",
-                    current_id, static_cast<void*>(original_ctx),
-                    static_cast<void*>(original_decl));
-        ASTDumper(original_decl).ToLog(log, "    ");
-    }
-
-    if (ObjCInterfaceDecl *original_iface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl))
-    {
-        ObjCInterfaceDecl *complete_iface_decl = GetCompleteObjCInterface(original_iface_decl);
-
-        if (complete_iface_decl && (complete_iface_decl != original_iface_decl))
-        {
-            original_decl = complete_iface_decl;
-            original_ctx = &complete_iface_decl->getASTContext();
+  if (log) {
+    log->Printf("  FELD[%u] Original decl (ASTContext*)%p (Decl*)%p:",
+                current_id, static_cast<void *>(original_ctx),
+                static_cast<void *>(original_decl));
+    ASTDumper(original_decl).ToLog(log, "    ");
+  }
 
-            m_ast_importer_sp->SetDeclOrigin(context_decl, original_iface_decl);
-        }
-    }
+  if (ObjCInterfaceDecl *original_iface_decl =
+          dyn_cast<ObjCInterfaceDecl>(original_decl)) {
+    ObjCInterfaceDecl *complete_iface_decl =
+        GetCompleteObjCInterface(original_iface_decl);
 
-    if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
-    {
-        ExternalASTSource *external_source = original_ctx->getExternalSource();
+    if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
+      original_decl = complete_iface_decl;
+      original_ctx = &complete_iface_decl->getASTContext();
 
-        if (external_source)
-            external_source->CompleteType (original_tag_decl);
+      m_ast_importer_sp->SetDeclOrigin(context_decl, original_iface_decl);
     }
+  }
 
-    const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
+  if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) {
+    ExternalASTSource *external_source = original_ctx->getExternalSource();
 
-    if (!original_decl_context)
-        return;
+    if (external_source)
+      external_source->CompleteType(original_tag_decl);
+  }
 
-    for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
-         iter != original_decl_context->decls_end();
-         ++iter)
-    {
-        Decl *decl = *iter;
-
-        if (predicate(decl->getKind()))
-        {
-            if (log)
-            {
-                ASTDumper ast_dumper(decl);
-                if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
-                    log->Printf("  FELD[%d] Adding [to %sDecl %s] lexical %sDecl %s", current_id, context_named_decl->getDeclKindName(), context_named_decl->getNameAsString().c_str(), decl->getDeclKindName(), ast_dumper.GetCString());
-                else
-                    log->Printf("  FELD[%d] Adding lexical %sDecl %s", current_id, decl->getDeclKindName(), ast_dumper.GetCString());
-            }
-            
-            Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, original_ctx, decl);
+  const DeclContext *original_decl_context =
+      dyn_cast<DeclContext>(original_decl);
 
-            if (!copied_decl)
-                continue;
+  if (!original_decl_context)
+    return;
 
-            if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl))
-            {
-                QualType copied_field_type = copied_field->getType();
+  for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+       iter != original_decl_context->decls_end(); ++iter) {
+    Decl *decl = *iter;
+
+    if (predicate(decl->getKind())) {
+      if (log) {
+        ASTDumper ast_dumper(decl);
+        if (const NamedDecl *context_named_decl =
+                dyn_cast<NamedDecl>(context_decl))
+          log->Printf("  FELD[%d] Adding [to %sDecl %s] lexical %sDecl %s",
+                      current_id, context_named_decl->getDeclKindName(),
+                      context_named_decl->getNameAsString().c_str(),
+                      decl->getDeclKindName(), ast_dumper.GetCString());
+        else
+          log->Printf("  FELD[%d] Adding lexical %sDecl %s", current_id,
+                      decl->getDeclKindName(), ast_dumper.GetCString());
+      }
 
-                m_ast_importer_sp->RequireCompleteType(copied_field_type);
-            }
+      Decl *copied_decl =
+          m_ast_importer_sp->CopyDecl(m_ast_context, original_ctx, decl);
 
-            DeclContext *decl_context_non_const = const_cast<DeclContext *>(decl_context);
+      if (!copied_decl)
+        continue;
 
-            if (copied_decl->getDeclContext() != decl_context)
-            {
-                if (copied_decl->getDeclContext()->containsDecl(copied_decl))
-                    copied_decl->getDeclContext()->removeDecl(copied_decl);
-                copied_decl->setDeclContext(decl_context_non_const);
-            }
+      if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) {
+        QualType copied_field_type = copied_field->getType();
 
-            if (!decl_context_non_const->containsDecl(copied_decl))
-                decl_context_non_const->addDeclInternal(copied_decl);
-        }
+        m_ast_importer_sp->RequireCompleteType(copied_field_type);
+      }
+
+      DeclContext *decl_context_non_const =
+          const_cast<DeclContext *>(decl_context);
+
+      if (copied_decl->getDeclContext() != decl_context) {
+        if (copied_decl->getDeclContext()->containsDecl(copied_decl))
+          copied_decl->getDeclContext()->removeDecl(copied_decl);
+        copied_decl->setDeclContext(decl_context_non_const);
+      }
+
+      if (!decl_context_non_const->containsDecl(copied_decl))
+        decl_context_non_const->addDeclInternal(copied_decl);
     }
+  }
 
-    return;
+  return;
 }
 
-void
-ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context)
-{
-    assert (m_ast_context);
+void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) {
+  assert(m_ast_context);
 
-    ClangASTMetrics::RegisterVisibleQuery();
+  ClangASTMetrics::RegisterVisibleQuery();
 
-    const ConstString name(context.m_decl_name.getAsString().c_str());
+  const ConstString name(context.m_decl_name.getAsString().c_str());
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
 
-    if (log)
-    {
-        if (!context.m_decl_context)
-            log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a NULL DeclContext",
-                        current_id, static_cast<void*>(m_ast_context),
-                        name.GetCString());
-        else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
-            log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in '%s'",
-                        current_id, static_cast<void*>(m_ast_context),
-                        name.GetCString(),
-                        context_named_decl->getNameAsString().c_str());
-        else
-            log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a '%s'",
-                        current_id, static_cast<void*>(m_ast_context),
-                        name.GetCString(),
-                        context.m_decl_context->getDeclKindName());
-    }
-
-    context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
-
-    if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
-    {
-        ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer_sp->GetNamespaceMap(namespace_context);
-
-        if (log && log->GetVerbose())
-            log->Printf("  CAS::FEVD[%u] Inspecting namespace map %p (%d entries)",
-                        current_id, static_cast<void*>(namespace_map.get()),
-                        static_cast<int>(namespace_map->size()));
-
-        if (!namespace_map)
-            return;
-
-        for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
-             i != e;
-             ++i)
-        {
-            if (log)
-                log->Printf("  CAS::FEVD[%u] Searching namespace %s in module %s",
-                            current_id,
-                            i->second.GetName().AsCString(),
-                            i->first->GetFileSpec().GetFilename().GetCString());
-
-            FindExternalVisibleDecls(context,
-                                     i->first,
-                                     i->second,
-                                     current_id);
-        }
-    }
-    else if (isa<ObjCInterfaceDecl>(context.m_decl_context))
-    {
-        FindObjCPropertyAndIvarDecls(context);
-    }
-    else if (!isa<TranslationUnitDecl>(context.m_decl_context))
-    {
-        // we shouldn't be getting FindExternalVisibleDecls calls for these
-        return;
-    }
+  if (log) {
+    if (!context.m_decl_context)
+      log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on "
+                  "(ASTContext*)%p for '%s' in a NULL DeclContext",
+                  current_id, static_cast<void *>(m_ast_context),
+                  name.GetCString());
+    else if (const NamedDecl *context_named_decl =
+                 dyn_cast<NamedDecl>(context.m_decl_context))
+      log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on "
+                  "(ASTContext*)%p for '%s' in '%s'",
+                  current_id, static_cast<void *>(m_ast_context),
+                  name.GetCString(),
+                  context_named_decl->getNameAsString().c_str());
     else
-    {
-        CompilerDeclContext namespace_decl;
+      log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on "
+                  "(ASTContext*)%p for '%s' in a '%s'",
+                  current_id, static_cast<void *>(m_ast_context),
+                  name.GetCString(), context.m_decl_context->getDeclKindName());
+  }
+
+  context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
+
+  if (const NamespaceDecl *namespace_context =
+          dyn_cast<NamespaceDecl>(context.m_decl_context)) {
+    ClangASTImporter::NamespaceMapSP namespace_map =
+        m_ast_importer_sp->GetNamespaceMap(namespace_context);
+
+    if (log && log->GetVerbose())
+      log->Printf("  CAS::FEVD[%u] Inspecting namespace map %p (%d entries)",
+                  current_id, static_cast<void *>(namespace_map.get()),
+                  static_cast<int>(namespace_map->size()));
+
+    if (!namespace_map)
+      return;
+
+    for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
+                                                  e = namespace_map->end();
+         i != e; ++i) {
+      if (log)
+        log->Printf("  CAS::FEVD[%u] Searching namespace %s in module %s",
+                    current_id, i->second.GetName().AsCString(),
+                    i->first->GetFileSpec().GetFilename().GetCString());
+
+      FindExternalVisibleDecls(context, i->first, i->second, current_id);
+    }
+  } else if (isa<ObjCInterfaceDecl>(context.m_decl_context)) {
+    FindObjCPropertyAndIvarDecls(context);
+  } else if (!isa<TranslationUnitDecl>(context.m_decl_context)) {
+    // we shouldn't be getting FindExternalVisibleDecls calls for these
+    return;
+  } else {
+    CompilerDeclContext namespace_decl;
 
-        if (log)
-            log->Printf("  CAS::FEVD[%u] Searching the root namespace", current_id);
+    if (log)
+      log->Printf("  CAS::FEVD[%u] Searching the root namespace", current_id);
 
-        FindExternalVisibleDecls(context,
-                                 lldb::ModuleSP(),
-                                 namespace_decl,
-                                 current_id);
-    }
+    FindExternalVisibleDecls(context, lldb::ModuleSP(), namespace_decl,
+                             current_id);
+  }
 
-    if (!context.m_namespace_map->empty())
-    {
-        if (log && log->GetVerbose())
-            log->Printf("  CAS::FEVD[%u] Registering namespace map %p (%d entries)",
-                        current_id,
-                        static_cast<void*>(context.m_namespace_map.get()),
-                        static_cast<int>(context.m_namespace_map->size()));
+  if (!context.m_namespace_map->empty()) {
+    if (log && log->GetVerbose())
+      log->Printf("  CAS::FEVD[%u] Registering namespace map %p (%d entries)",
+                  current_id,
+                  static_cast<void *>(context.m_namespace_map.get()),
+                  static_cast<int>(context.m_namespace_map->size()));
 
-        NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map);
+    NamespaceDecl *clang_namespace_decl =
+        AddNamespace(context, context.m_namespace_map);
 
-        if (clang_namespace_decl)
-            clang_namespace_decl->setHasExternalVisibleStorage();
-    }
+    if (clang_namespace_decl)
+      clang_namespace_decl->setHasExternalVisibleStorage();
+  }
 }
 
-void
-ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
-                                          lldb::ModuleSP module_sp,
-                                          CompilerDeclContext &namespace_decl,
-                                          unsigned int current_id)
-{
-    assert (m_ast_context);
+void ClangASTSource::FindExternalVisibleDecls(
+    NameSearchContext &context, lldb::ModuleSP module_sp,
+    CompilerDeclContext &namespace_decl, unsigned int current_id) {
+  assert(m_ast_context);
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    SymbolContextList sc_list;
+  SymbolContextList sc_list;
 
-    const ConstString name(context.m_decl_name.getAsString().c_str());
+  const ConstString name(context.m_decl_name.getAsString().c_str());
 
-    const char *name_unique_cstr = name.GetCString();
+  const char *name_unique_cstr = name.GetCString();
 
-    static ConstString id_name("id");
-    static ConstString Class_name("Class");
+  static ConstString id_name("id");
+  static ConstString Class_name("Class");
 
-    if (name == id_name || name == Class_name)
-        return;
+  if (name == id_name || name == Class_name)
+    return;
 
-    if (name_unique_cstr == NULL)
-        return;
+  if (name_unique_cstr == NULL)
+    return;
 
-    // The ClangASTSource is not responsible for finding $-names.
-    if (name_unique_cstr[0] == '$')
-        return;
+  // The ClangASTSource is not responsible for finding $-names.
+  if (name_unique_cstr[0] == '$')
+    return;
 
-    if (module_sp && namespace_decl)
-    {
-        CompilerDeclContext found_namespace_decl;
+  if (module_sp && namespace_decl) {
+    CompilerDeclContext found_namespace_decl;
 
-        SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
+    SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
 
-        if (symbol_vendor)
-        {
-            SymbolContext null_sc;
-
-            found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
-
-            if (found_namespace_decl)
-            {
-                context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(module_sp, found_namespace_decl));
-
-                if (log)
-                    log->Printf("  CAS::FEVD[%u] Found namespace %s in module %s",
-                                current_id,
-                                name.GetCString(),
-                                module_sp->GetFileSpec().GetFilename().GetCString());
-            }
-        }
+    if (symbol_vendor) {
+      SymbolContext null_sc;
+
+      found_namespace_decl =
+          symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
+
+      if (found_namespace_decl) {
+        context.m_namespace_map->push_back(
+            std::pair<lldb::ModuleSP, CompilerDeclContext>(
+                module_sp, found_namespace_decl));
+
+        if (log)
+          log->Printf("  CAS::FEVD[%u] Found namespace %s in module %s",
+                      current_id, name.GetCString(),
+                      module_sp->GetFileSpec().GetFilename().GetCString());
+      }
     }
-    else
-    {
-        const ModuleList &target_images = m_target->GetImages();
-        std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
+  } else {
+    const ModuleList &target_images = m_target->GetImages();
+    std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
 
-        for (size_t i = 0, e = target_images.GetSize(); i < e; ++i)
-        {
-            lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
+    for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) {
+      lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
 
-            if (!image)
-                continue;
+      if (!image)
+        continue;
 
-            CompilerDeclContext found_namespace_decl;
+      CompilerDeclContext found_namespace_decl;
 
-            SymbolVendor *symbol_vendor = image->GetSymbolVendor();
+      SymbolVendor *symbol_vendor = image->GetSymbolVendor();
 
-            if (!symbol_vendor)
-                continue;
+      if (!symbol_vendor)
+        continue;
 
-            SymbolContext null_sc;
+      SymbolContext null_sc;
 
-            found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
+      found_namespace_decl =
+          symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
 
-            if (found_namespace_decl)
-            {
-                context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(image, found_namespace_decl));
+      if (found_namespace_decl) {
+        context.m_namespace_map->push_back(
+            std::pair<lldb::ModuleSP, CompilerDeclContext>(
+                image, found_namespace_decl));
 
-                if (log)
-                    log->Printf("  CAS::FEVD[%u] Found namespace %s in module %s",
-                                current_id,
-                                name.GetCString(),
-                                image->GetFileSpec().GetFilename().GetCString());
-            }
+        if (log)
+          log->Printf("  CAS::FEVD[%u] Found namespace %s in module %s",
+                      current_id, name.GetCString(),
+                      image->GetFileSpec().GetFilename().GetCString());
+      }
+    }
+  }
+
+  do {
+    if (context.m_found.type)
+      break;
+
+    TypeList types;
+    SymbolContext null_sc;
+    const bool exact_match = false;
+    llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
+    if (module_sp && namespace_decl)
+      module_sp->FindTypesInNamespace(null_sc, name, &namespace_decl, 1, types);
+    else
+      m_target->GetImages().FindTypes(null_sc, name, exact_match, 1,
+                                      searched_symbol_files, types);
+
+    if (size_t num_types = types.GetSize()) {
+      for (size_t ti = 0; ti < num_types; ++ti) {
+        lldb::TypeSP type_sp = types.GetTypeAtIndex(ti);
+
+        if (log) {
+          const char *name_string = type_sp->GetName().GetCString();
+
+          log->Printf("  CAS::FEVD[%u] Matching type found for \"%s\": %s",
+                      current_id, name.GetCString(),
+                      (name_string ? name_string : "<anonymous>"));
         }
+
+        CompilerType full_type = type_sp->GetFullCompilerType();
+
+        CompilerType copied_clang_type(GuardedCopyType(full_type));
+
+        if (!copied_clang_type) {
+          if (log)
+            log->Printf("  CAS::FEVD[%u] - Couldn't export a type", current_id);
+
+          continue;
+        }
+
+        context.AddTypeDecl(copied_clang_type);
+
+        context.m_found.type = true;
+        break;
+      }
     }
 
-    do
-    {
-        if (context.m_found.type)
+    if (!context.m_found.type) {
+      // Try the modules next.
+
+      do {
+        if (ClangModulesDeclVendor *modules_decl_vendor =
+                m_target->GetClangModulesDeclVendor()) {
+          bool append = false;
+          uint32_t max_matches = 1;
+          std::vector<clang::NamedDecl *> decls;
+
+          if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
             break;
-        
-        TypeList types;
-        SymbolContext null_sc;
-        const bool exact_match = false;
-        llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
-        if (module_sp && namespace_decl)
-            module_sp->FindTypesInNamespace(null_sc, name, &namespace_decl, 1, types);
-        else
-            m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, searched_symbol_files, types);
-        
-        if (size_t num_types = types.GetSize())
-        {
-            for (size_t ti = 0; ti < num_types; ++ti)
-            {
-                lldb::TypeSP type_sp = types.GetTypeAtIndex(ti);
-                
-                if (log)
-                {
-                    const char *name_string = type_sp->GetName().GetCString();
-                    
-                    log->Printf("  CAS::FEVD[%u] Matching type found for \"%s\": %s",
-                                current_id,
-                                name.GetCString(),
-                                (name_string ? name_string : "<anonymous>"));
-                }
-                
-                CompilerType full_type = type_sp->GetFullCompilerType();
-                
-                CompilerType copied_clang_type (GuardedCopyType(full_type));
-                
-                if (!copied_clang_type)
-                {
-                    if (log)
-                        log->Printf("  CAS::FEVD[%u] - Couldn't export a type",
-                                    current_id);
-                    
-                    continue;
-                }
-                
-                context.AddTypeDecl(copied_clang_type);
-                
-                context.m_found.type = true;
-                break;
+
+          if (log) {
+            log->Printf("  CAS::FEVD[%u] Matching entity found for \"%s\" in "
+                        "the modules",
+                        current_id, name.GetCString());
+          }
+
+          clang::NamedDecl *const decl_from_modules = decls[0];
+
+          if (llvm::isa<clang::TypeDecl>(decl_from_modules) ||
+              llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
+              llvm::isa<clang::EnumConstantDecl>(decl_from_modules)) {
+            clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(
+                m_ast_context, &decl_from_modules->getASTContext(),
+                decl_from_modules);
+            clang::NamedDecl *copied_named_decl =
+                copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr;
+
+            if (!copied_named_decl) {
+              if (log)
+                log->Printf(
+                    "  CAS::FEVD[%u] - Couldn't export a type from the modules",
+                    current_id);
+
+              break;
             }
+
+            context.AddNamedDecl(copied_named_decl);
+
+            context.m_found.type = true;
+          }
         }
+      } while (0);
+    }
+
+    if (!context.m_found.type) {
+      do {
+        // Couldn't find any types elsewhere.  Try the Objective-C runtime if
+        // one exists.
+
+        lldb::ProcessSP process(m_target->GetProcessSP());
+
+        if (!process)
+          break;
+
+        ObjCLanguageRuntime *language_runtime(
+            process->GetObjCLanguageRuntime());
+
+        if (!language_runtime)
+          break;
+
+        DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
+
+        if (!decl_vendor)
+          break;
+
+        bool append = false;
+        uint32_t max_matches = 1;
+        std::vector<clang::NamedDecl *> decls;
+
+        if (!decl_vendor->FindDecls(name, append, max_matches, decls))
+          break;
 
-        if (!context.m_found.type)
-        {
-            // Try the modules next.
-            
-            do
-            {
-                if (ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor())
-                {
-                    bool append = false;
-                    uint32_t max_matches = 1;
-                    std::vector <clang::NamedDecl *> decls;
-                    
-                    if (!modules_decl_vendor->FindDecls(name,
-                                                        append,
-                                                        max_matches,
-                                                        decls))
-                        break;
-
-                    if (log)
-                    {
-                        log->Printf("  CAS::FEVD[%u] Matching entity found for \"%s\" in the modules",
-                                    current_id,
-                                    name.GetCString());
-                    }
-                    
-                    clang::NamedDecl *const decl_from_modules = decls[0];
-                    
-                    if (llvm::isa<clang::TypeDecl>(decl_from_modules) ||
-                        llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
-                        llvm::isa<clang::EnumConstantDecl>(decl_from_modules))
-                    {
-                        clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, &decl_from_modules->getASTContext(), decl_from_modules);
-                        clang::NamedDecl *copied_named_decl = copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr;
-                        
-                        if (!copied_named_decl)
-                        {
-                            if (log)
-                                log->Printf("  CAS::FEVD[%u] - Couldn't export a type from the modules",
-                                            current_id);
-                            
-                            break;
-                        }
-                        
-                        context.AddNamedDecl(copied_named_decl);
-                        
-                        context.m_found.type = true;
-                    }
-                }
-            } while (0);
+        if (log) {
+          log->Printf(
+              "  CAS::FEVD[%u] Matching type found for \"%s\" in the runtime",
+              current_id, name.GetCString());
         }
-        
-        if (!context.m_found.type)
-        {
-            do
-            {
-                // Couldn't find any types elsewhere.  Try the Objective-C runtime if one exists.
-
-                lldb::ProcessSP process(m_target->GetProcessSP());
-
-                if (!process)
-                    break;
-
-                ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
-
-                if (!language_runtime)
-                    break;
-
-                DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
-
-                if (!decl_vendor)
-                    break;
-
-                bool append = false;
-                uint32_t max_matches = 1;
-                std::vector <clang::NamedDecl *> decls;
-
-                if (!decl_vendor->FindDecls(name,
-                                            append,
-                                            max_matches,
-                                            decls))
-                    break;
-
-                if (log)
-                {
-                    log->Printf("  CAS::FEVD[%u] Matching type found for \"%s\" in the runtime",
-                                current_id,
-                                name.GetCString());
-                }
-                
-                clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, &decls[0]->getASTContext(), decls[0]);
-                clang::NamedDecl *copied_named_decl = copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr;
-                
-                if (!copied_named_decl)
-                {
-                    if (log)
-                        log->Printf("  CAS::FEVD[%u] - Couldn't export a type from the runtime",
-                                    current_id);
 
-                    break;
-                }
+        clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(
+            m_ast_context, &decls[0]->getASTContext(), decls[0]);
+        clang::NamedDecl *copied_named_decl =
+            copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr;
 
-                context.AddNamedDecl(copied_named_decl);
-            }
-            while(0);
+        if (!copied_named_decl) {
+          if (log)
+            log->Printf(
+                "  CAS::FEVD[%u] - Couldn't export a type from the runtime",
+                current_id);
+
+          break;
         }
 
-    } while(0);
+        context.AddNamedDecl(copied_named_decl);
+      } while (0);
+    }
+
+  } while (0);
 }
 
 template <class D> class TaggedASTDecl {
 public:
-    TaggedASTDecl() : decl(NULL) { }
-    TaggedASTDecl(D *_decl) : decl(_decl) { }
-    bool IsValid() const { return (decl != NULL); }
-    bool IsInvalid() const { return !IsValid(); }
-    D *operator->() const { return decl; }
-    D *decl;
+  TaggedASTDecl() : decl(NULL) {}
+  TaggedASTDecl(D *_decl) : decl(_decl) {}
+  bool IsValid() const { return (decl != NULL); }
+  bool IsInvalid() const { return !IsValid(); }
+  D *operator->() const { return decl; }
+  D *decl;
 };
 
 template <class D2, template <class D> class TD, class D1>
-TD<D2>
-DynCast(TD<D1> source)
-{
-    return TD<D2> (dyn_cast<D2>(source.decl));
+TD<D2> DynCast(TD<D1> source) {
+  return TD<D2>(dyn_cast<D2>(source.decl));
 }
 
 template <class D = Decl> class DeclFromParser;
@@ -922,1179 +872,1141 @@ template <class D = Decl> class DeclFrom
 
 template <class D> class DeclFromParser : public TaggedASTDecl<D> {
 public:
-    DeclFromParser() : TaggedASTDecl<D>() { }
-    DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) { }
+  DeclFromParser() : TaggedASTDecl<D>() {}
+  DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) {}
 
-    DeclFromUser<D> GetOrigin(ClangASTImporter *importer);
+  DeclFromUser<D> GetOrigin(ClangASTImporter *importer);
 };
 
 template <class D> class DeclFromUser : public TaggedASTDecl<D> {
 public:
-    DeclFromUser() : TaggedASTDecl<D>() { }
-    DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) { }
+  DeclFromUser() : TaggedASTDecl<D>() {}
+  DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) {}
 
-    DeclFromParser<D> Import(ClangASTImporter *importer, ASTContext &dest_ctx);
+  DeclFromParser<D> Import(ClangASTImporter *importer, ASTContext &dest_ctx);
 };
 
 template <class D>
-DeclFromUser<D>
-DeclFromParser<D>::GetOrigin(ClangASTImporter *importer)
-{
-    DeclFromUser <> origin_decl;
-    importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL);
-    if (origin_decl.IsInvalid())
-        return DeclFromUser<D>();
-    return DeclFromUser<D>(dyn_cast<D>(origin_decl.decl));
+DeclFromUser<D> DeclFromParser<D>::GetOrigin(ClangASTImporter *importer) {
+  DeclFromUser<> origin_decl;
+  importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL);
+  if (origin_decl.IsInvalid())
+    return DeclFromUser<D>();
+  return DeclFromUser<D>(dyn_cast<D>(origin_decl.decl));
 }
 
 template <class D>
-DeclFromParser<D>
-DeclFromUser<D>::Import(ClangASTImporter *importer, ASTContext &dest_ctx)
-{
-    DeclFromParser <> parser_generic_decl(importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl));
-    if (parser_generic_decl.IsInvalid())
-        return DeclFromParser<D>();
-    return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl));
-}
-
-static bool
-FindObjCMethodDeclsWithOrigin (unsigned int current_id,
-                               NameSearchContext &context,
-                               ObjCInterfaceDecl *original_interface_decl,
-                               clang::ASTContext *ast_context,
-                               ClangASTImporter *ast_importer,
-                               const char *log_info)
-{
-    const DeclarationName &decl_name(context.m_decl_name);
-    clang::ASTContext *original_ctx = &original_interface_decl->getASTContext();
-
-    Selector original_selector;
-
-    if (decl_name.isObjCZeroArgSelector())
-    {
-        IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString());
-        original_selector = original_ctx->Selectors.getSelector(0, &ident);
-    }
-    else if (decl_name.isObjCOneArgSelector())
-    {
-        const std::string &decl_name_string = decl_name.getAsString();
-        std::string decl_name_string_without_colon(decl_name_string.c_str(), decl_name_string.length() - 1);
-        IdentifierInfo *ident = &original_ctx->Idents.get(decl_name_string_without_colon.c_str());
-        original_selector = original_ctx->Selectors.getSelector(1, &ident);
-    }
-    else
-    {
-        SmallVector<IdentifierInfo *, 4> idents;
+DeclFromParser<D> DeclFromUser<D>::Import(ClangASTImporter *importer,
+                                          ASTContext &dest_ctx) {
+  DeclFromParser<> parser_generic_decl(
+      importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl));
+  if (parser_generic_decl.IsInvalid())
+    return DeclFromParser<D>();
+  return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl));
+}
+
+static bool FindObjCMethodDeclsWithOrigin(
+    unsigned int current_id, NameSearchContext &context,
+    ObjCInterfaceDecl *original_interface_decl, clang::ASTContext *ast_context,
+    ClangASTImporter *ast_importer, const char *log_info) {
+  const DeclarationName &decl_name(context.m_decl_name);
+  clang::ASTContext *original_ctx = &original_interface_decl->getASTContext();
+
+  Selector original_selector;
+
+  if (decl_name.isObjCZeroArgSelector()) {
+    IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString());
+    original_selector = original_ctx->Selectors.getSelector(0, &ident);
+  } else if (decl_name.isObjCOneArgSelector()) {
+    const std::string &decl_name_string = decl_name.getAsString();
+    std::string decl_name_string_without_colon(decl_name_string.c_str(),
+                                               decl_name_string.length() - 1);
+    IdentifierInfo *ident =
+        &original_ctx->Idents.get(decl_name_string_without_colon.c_str());
+    original_selector = original_ctx->Selectors.getSelector(1, &ident);
+  } else {
+    SmallVector<IdentifierInfo *, 4> idents;
+
+    clang::Selector sel = decl_name.getObjCSelector();
+
+    unsigned num_args = sel.getNumArgs();
+
+    for (unsigned i = 0; i != num_args; ++i) {
+      idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
+    }
+
+    original_selector =
+        original_ctx->Selectors.getSelector(num_args, idents.data());
+  }
+
+  DeclarationName original_decl_name(original_selector);
+
+  llvm::SmallVector<NamedDecl *, 1> methods;
+
+  ClangASTContext::GetCompleteDecl(original_ctx, original_interface_decl);
+
+  if (ObjCMethodDecl *instance_method_decl =
+          original_interface_decl->lookupInstanceMethod(original_selector)) {
+    methods.push_back(instance_method_decl);
+  } else if (ObjCMethodDecl *class_method_decl =
+                 original_interface_decl->lookupClassMethod(
+                     original_selector)) {
+    methods.push_back(class_method_decl);
+  }
+
+  if (methods.empty()) {
+    return false;
+  }
+
+  for (NamedDecl *named_decl : methods) {
+    if (!named_decl)
+      continue;
 
-        clang::Selector sel = decl_name.getObjCSelector();
+    ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl);
 
-        unsigned num_args = sel.getNumArgs();
+    if (!result_method)
+      continue;
 
-        for (unsigned i = 0;
-             i != num_args;
-             ++i)
-        {
-            idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
-        }
+    Decl *copied_decl = ast_importer->CopyDecl(
+        ast_context, &result_method->getASTContext(), result_method);
+
+    if (!copied_decl)
+      continue;
+
+    ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
+
+    if (!copied_method_decl)
+      continue;
+
+    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-        original_selector = original_ctx->Selectors.getSelector(num_args, idents.data());
+    if (log) {
+      ASTDumper dumper((Decl *)copied_method_decl);
+      log->Printf("  CAS::FOMD[%d] found (%s) %s", current_id, log_info,
+                  dumper.GetCString());
     }
 
-    DeclarationName original_decl_name(original_selector);
-    
-    llvm::SmallVector<NamedDecl *, 1> methods;
-    
-    ClangASTContext::GetCompleteDecl(original_ctx, original_interface_decl);
-    
-    if (ObjCMethodDecl *instance_method_decl = original_interface_decl->lookupInstanceMethod(original_selector))
-    {
-        methods.push_back(instance_method_decl);
-    }
-    else if (ObjCMethodDecl *class_method_decl = original_interface_decl->lookupClassMethod(original_selector))
-    {
-        methods.push_back(class_method_decl);
-    }
-    
-    if (methods.empty())
-    {
-        return false;
-    }
-    
-    for (NamedDecl *named_decl : methods)
-    {
-        if (!named_decl)
-            continue;
-        
-        ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl);
+    context.AddNamedDecl(copied_method_decl);
+  }
 
-        if (!result_method)
-            continue;
+  return true;
+}
 
-        Decl *copied_decl = ast_importer->CopyDecl(ast_context, &result_method->getASTContext(), result_method);
+void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-        if (!copied_decl)
-            continue;
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
 
-        ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
+  const DeclarationName &decl_name(context.m_decl_name);
+  const DeclContext *decl_ctx(context.m_decl_context);
 
-        if (!copied_method_decl)
-            continue;
+  const ObjCInterfaceDecl *interface_decl =
+      dyn_cast<ObjCInterfaceDecl>(decl_ctx);
 
-        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  if (!interface_decl)
+    return;
 
-        if (log)
-        {
-            ASTDumper dumper((Decl*)copied_method_decl);
-            log->Printf("  CAS::FOMD[%d] found (%s) %s", current_id, log_info, dumper.GetCString());
-        }
+  do {
+    Decl *original_decl = NULL;
+    ASTContext *original_ctx = NULL;
 
-        context.AddNamedDecl(copied_method_decl);
-    }
+    m_ast_importer_sp->ResolveDeclOrigin(interface_decl, &original_decl,
+                                         &original_ctx);
 
-    return true;
-}
+    if (!original_decl)
+      break;
 
-void
-ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+    ObjCInterfaceDecl *original_interface_decl =
+        dyn_cast<ObjCInterfaceDecl>(original_decl);
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+    if (FindObjCMethodDeclsWithOrigin(current_id, context,
+                                      original_interface_decl, m_ast_context,
+                                      m_ast_importer_sp.get(), "at origin"))
+      return; // found it, no need to look any further
+  } while (0);
+
+  StreamString ss;
+
+  if (decl_name.isObjCZeroArgSelector()) {
+    ss.Printf("%s", decl_name.getAsString().c_str());
+  } else if (decl_name.isObjCOneArgSelector()) {
+    ss.Printf("%s", decl_name.getAsString().c_str());
+  } else {
+    clang::Selector sel = decl_name.getObjCSelector();
+
+    for (unsigned i = 0, e = sel.getNumArgs(); i != e; ++i) {
+      llvm::StringRef r = sel.getNameForSlot(i);
+      ss.Printf("%s:", r.str().c_str());
+    }
+  }
+  ss.Flush();
+
+  if (strstr(ss.GetData(), "$__lldb"))
+    return; // we don't need any results
+
+  ConstString selector_name(ss.GetData());
+
+  if (log)
+    log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p "
+                "for selector [%s %s]",
+                current_id, static_cast<void *>(m_ast_context),
+                interface_decl->getNameAsString().c_str(),
+                selector_name.AsCString());
+  SymbolContextList sc_list;
+
+  const bool include_symbols = false;
+  const bool include_inlines = false;
+  const bool append = false;
+
+  std::string interface_name = interface_decl->getNameAsString();
+
+  do {
+    StreamString ms;
+    ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString());
+    ms.Flush();
+    ConstString instance_method_name(ms.GetData());
+
+    m_target->GetImages().FindFunctions(
+        instance_method_name, lldb::eFunctionNameTypeFull, include_symbols,
+        include_inlines, append, sc_list);
 
-    const DeclarationName &decl_name(context.m_decl_name);
-    const DeclContext *decl_ctx(context.m_decl_context);
+    if (sc_list.GetSize())
+      break;
 
-    const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx);
+    ms.Clear();
+    ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString());
+    ms.Flush();
+    ConstString class_method_name(ms.GetData());
+
+    m_target->GetImages().FindFunctions(
+        class_method_name, lldb::eFunctionNameTypeFull, include_symbols,
+        include_inlines, append, sc_list);
 
-    if (!interface_decl)
-        return;
+    if (sc_list.GetSize())
+      break;
 
-    do
-    {
-        Decl *original_decl = NULL;
-        ASTContext *original_ctx = NULL;
+    // Fall back and check for methods in categories.  If we find methods this
+    // way, we need to check that they're actually in
+    // categories on the desired class.
 
-        m_ast_importer_sp->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx);
+    SymbolContextList candidate_sc_list;
 
-        if (!original_decl)
-            break;
+    m_target->GetImages().FindFunctions(
+        selector_name, lldb::eFunctionNameTypeSelector, include_symbols,
+        include_inlines, append, candidate_sc_list);
 
-        ObjCInterfaceDecl *original_interface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl);
+    for (uint32_t ci = 0, ce = candidate_sc_list.GetSize(); ci != ce; ++ci) {
+      SymbolContext candidate_sc;
 
-        if (FindObjCMethodDeclsWithOrigin(current_id,
-                                          context,
-                                          original_interface_decl,
-                                          m_ast_context,
-                                          m_ast_importer_sp.get(),
-                                          "at origin"))
-            return; // found it, no need to look any further
-    } while (0);
-
-    StreamString ss;
-
-    if (decl_name.isObjCZeroArgSelector())
-    {
-        ss.Printf("%s", decl_name.getAsString().c_str());
-    }
-    else if (decl_name.isObjCOneArgSelector())
-    {
-        ss.Printf("%s", decl_name.getAsString().c_str());
-    }
-    else
-    {
-        clang::Selector sel = decl_name.getObjCSelector();
+      if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc))
+        continue;
 
-        for (unsigned i = 0, e = sel.getNumArgs();
-             i != e;
-             ++i)
-        {
-            llvm::StringRef r = sel.getNameForSlot(i);
-            ss.Printf("%s:", r.str().c_str());
-        }
-    }
-    ss.Flush();
+      if (!candidate_sc.function)
+        continue;
 
-    if (strstr(ss.GetData(), "$__lldb"))
-        return; // we don't need any results
+      const char *candidate_name = candidate_sc.function->GetName().AsCString();
 
-    ConstString selector_name(ss.GetData());
+      const char *cursor = candidate_name;
 
-    if (log)
-        log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]",
-                    current_id, static_cast<void*>(m_ast_context),
-                    interface_decl->getNameAsString().c_str(),
-                    selector_name.AsCString());
-    SymbolContextList sc_list;
-
-    const bool include_symbols = false;
-    const bool include_inlines = false;
-    const bool append = false;
-
-    std::string interface_name = interface_decl->getNameAsString();
-
-    do
-    {
-        StreamString ms;
-        ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString());
-        ms.Flush();
-        ConstString instance_method_name(ms.GetData());
+      if (*cursor != '+' && *cursor != '-')
+        continue;
 
-        m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list);
+      ++cursor;
 
-        if (sc_list.GetSize())
-            break;
+      if (*cursor != '[')
+        continue;
 
-        ms.Clear();
-        ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString());
-        ms.Flush();
-        ConstString class_method_name(ms.GetData());
+      ++cursor;
 
-        m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list);
+      size_t interface_len = interface_name.length();
 
-        if (sc_list.GetSize())
-            break;
+      if (strncmp(cursor, interface_name.c_str(), interface_len))
+        continue;
 
-        // Fall back and check for methods in categories.  If we find methods this way, we need to check that they're actually in
-        // categories on the desired class.
+      cursor += interface_len;
 
-        SymbolContextList candidate_sc_list;
+      if (*cursor == ' ' || *cursor == '(')
+        sc_list.Append(candidate_sc);
+    }
+  } while (0);
 
-        m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list);
+  if (sc_list.GetSize()) {
+    // We found a good function symbol.  Use that.
 
-        for (uint32_t ci = 0, ce = candidate_sc_list.GetSize();
-             ci != ce;
-             ++ci)
-        {
-            SymbolContext candidate_sc;
+    for (uint32_t i = 0, e = sc_list.GetSize(); i != e; ++i) {
+      SymbolContext sc;
 
-            if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc))
-                continue;
+      if (!sc_list.GetContextAtIndex(i, sc))
+        continue;
 
-            if (!candidate_sc.function)
-                continue;
+      if (!sc.function)
+        continue;
 
-            const char *candidate_name = candidate_sc.function->GetName().AsCString();
+      CompilerDeclContext function_decl_ctx = sc.function->GetDeclContext();
+      if (!function_decl_ctx)
+        continue;
 
-            const char *cursor = candidate_name;
+      ObjCMethodDecl *method_decl =
+          ClangASTContext::DeclContextGetAsObjCMethodDecl(function_decl_ctx);
 
-            if (*cursor != '+' && *cursor != '-')
-                continue;
+      if (!method_decl)
+        continue;
 
-            ++cursor;
+      ObjCInterfaceDecl *found_interface_decl =
+          method_decl->getClassInterface();
 
-            if (*cursor != '[')
-                continue;
+      if (!found_interface_decl)
+        continue;
 
-            ++cursor;
+      if (found_interface_decl->getName() == interface_decl->getName()) {
+        Decl *copied_decl = m_ast_importer_sp->CopyDecl(
+            m_ast_context, &method_decl->getASTContext(), method_decl);
 
-            size_t interface_len = interface_name.length();
+        if (!copied_decl)
+          continue;
 
-            if (strncmp(cursor, interface_name.c_str(), interface_len))
-                continue;
+        ObjCMethodDecl *copied_method_decl =
+            dyn_cast<ObjCMethodDecl>(copied_decl);
 
-            cursor += interface_len;
+        if (!copied_method_decl)
+          continue;
 
-            if (*cursor == ' ' || *cursor == '(')
-                sc_list.Append(candidate_sc);
+        if (log) {
+          ASTDumper dumper((Decl *)copied_method_decl);
+          log->Printf("  CAS::FOMD[%d] found (in symbols) %s", current_id,
+                      dumper.GetCString());
         }
-    }
-    while (0);
-
-    if (sc_list.GetSize())
-    {
-        // We found a good function symbol.  Use that.
 
-        for (uint32_t i = 0, e = sc_list.GetSize();
-             i != e;
-             ++i)
-        {
-            SymbolContext sc;
+        context.AddNamedDecl(copied_method_decl);
+      }
+    }
 
-            if (!sc_list.GetContextAtIndex(i, sc))
-                continue;
+    return;
+  }
 
-            if (!sc.function)
-                continue;
+  // Try the debug information.
 
-            CompilerDeclContext function_decl_ctx = sc.function->GetDeclContext();
-            if (!function_decl_ctx)
-                continue;
+  do {
+    ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface(
+        const_cast<ObjCInterfaceDecl *>(interface_decl));
 
-            ObjCMethodDecl *method_decl = ClangASTContext::DeclContextGetAsObjCMethodDecl(function_decl_ctx);
+    if (!complete_interface_decl)
+      break;
 
-            if (!method_decl)
-                continue;
+    // We found the complete interface.  The runtime never needs to be queried
+    // in this scenario.
 
-            ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface();
+    DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(
+        complete_interface_decl);
 
-            if (!found_interface_decl)
-                continue;
+    if (complete_interface_decl == interface_decl)
+      break; // already checked this one
 
-            if (found_interface_decl->getName() == interface_decl->getName())
-            {
-                Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl);
+    if (log)
+      log->Printf("CAS::FOPD[%d] trying origin "
+                  "(ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
+                  current_id, static_cast<void *>(complete_interface_decl),
+                  static_cast<void *>(&complete_iface_decl->getASTContext()));
+
+    FindObjCMethodDeclsWithOrigin(current_id, context, complete_interface_decl,
+                                  m_ast_context, m_ast_importer_sp.get(),
+                                  "in debug info");
 
-                if (!copied_decl)
-                    continue;
+    return;
+  } while (0);
 
-                ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
+  do {
+    // Check the modules only if the debug information didn't have a complete
+    // interface.
+
+    if (ClangModulesDeclVendor *modules_decl_vendor =
+            m_target->GetClangModulesDeclVendor()) {
+      ConstString interface_name(interface_decl->getNameAsString().c_str());
+      bool append = false;
+      uint32_t max_matches = 1;
+      std::vector<clang::NamedDecl *> decls;
 
-                if (!copied_method_decl)
-                    continue;
+      if (!modules_decl_vendor->FindDecls(interface_name, append, max_matches,
+                                          decls))
+        break;
 
-                if (log)
-                {
-                    ASTDumper dumper((Decl*)copied_method_decl);
-                    log->Printf("  CAS::FOMD[%d] found (in symbols) %s", current_id, dumper.GetCString());
-                }
+      ObjCInterfaceDecl *interface_decl_from_modules =
+          dyn_cast<ObjCInterfaceDecl>(decls[0]);
 
-                context.AddNamedDecl(copied_method_decl);
-            }
-        }
+      if (!interface_decl_from_modules)
+        break;
 
+      if (FindObjCMethodDeclsWithOrigin(
+              current_id, context, interface_decl_from_modules, m_ast_context,
+              m_ast_importer_sp.get(), "in modules"))
         return;
     }
+  } while (0);
 
-    // Try the debug information.
+  do {
+    // Check the runtime only if the debug information didn't have a complete
+    // interface and the modules don't get us anywhere.
 
-    do
-    {
-        ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface(const_cast<ObjCInterfaceDecl*>(interface_decl));
+    lldb::ProcessSP process(m_target->GetProcessSP());
 
-        if (!complete_interface_decl)
-            break;
+    if (!process)
+      break;
 
-        // We found the complete interface.  The runtime never needs to be queried in this scenario.
+    ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
 
-        DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_decl);
+    if (!language_runtime)
+      break;
 
-        if (complete_interface_decl == interface_decl)
-            break; // already checked this one
+    DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
 
-        if (log)
-            log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
-                        current_id, static_cast<void*>(complete_interface_decl),
-                        static_cast<void*>(&complete_iface_decl->getASTContext()));
-
-        FindObjCMethodDeclsWithOrigin(current_id,
-                                      context,
-                                      complete_interface_decl,
-                                      m_ast_context,
-                                      m_ast_importer_sp.get(),
-                                      "in debug info");
+    if (!decl_vendor)
+      break;
 
-        return;
-    }
-    while (0);
-    
-    do
-    {
-        // Check the modules only if the debug information didn't have a complete interface.
-        
-        if (ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor())
-        {
-            ConstString interface_name(interface_decl->getNameAsString().c_str());
-            bool append = false;
-            uint32_t max_matches = 1;
-            std::vector <clang::NamedDecl *> decls;
-            
-            if (!modules_decl_vendor->FindDecls(interface_name,
-                                                append,
-                                                max_matches,
-                                                decls))
-                break;
-
-            ObjCInterfaceDecl *interface_decl_from_modules = dyn_cast<ObjCInterfaceDecl>(decls[0]);
-            
-            if (!interface_decl_from_modules)
-                break;
-            
-            if (FindObjCMethodDeclsWithOrigin(current_id,
-                                              context,
-                                              interface_decl_from_modules,
-                                              m_ast_context,
-                                              m_ast_importer_sp.get(),
-                                              "in modules"))
-                return;
-        }
-    }
-    while (0);
-
-    do
-    {
-        // Check the runtime only if the debug information didn't have a complete interface and the modules don't get us anywhere.
+    ConstString interface_name(interface_decl->getNameAsString().c_str());
+    bool append = false;
+    uint32_t max_matches = 1;
+    std::vector<clang::NamedDecl *> decls;
 
-        lldb::ProcessSP process(m_target->GetProcessSP());
+    if (!decl_vendor->FindDecls(interface_name, append, max_matches, decls))
+      break;
 
-        if (!process)
-            break;
+    ObjCInterfaceDecl *runtime_interface_decl =
+        dyn_cast<ObjCInterfaceDecl>(decls[0]);
 
-        ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
+    if (!runtime_interface_decl)
+      break;
 
-        if (!language_runtime)
-            break;
+    FindObjCMethodDeclsWithOrigin(current_id, context, runtime_interface_decl,
+                                  m_ast_context, m_ast_importer_sp.get(),
+                                  "in runtime");
+  } while (0);
+}
 
-        DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
+static bool FindObjCPropertyAndIvarDeclsWithOrigin(
+    unsigned int current_id, NameSearchContext &context,
+    clang::ASTContext &ast_context, ClangASTImporter *ast_importer,
+    DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-        if (!decl_vendor)
-            break;
+  if (origin_iface_decl.IsInvalid())
+    return false;
 
-        ConstString interface_name(interface_decl->getNameAsString().c_str());
-        bool append = false;
-        uint32_t max_matches = 1;
-        std::vector <clang::NamedDecl *> decls;
+  std::string name_str = context.m_decl_name.getAsString();
+  StringRef name(name_str.c_str());
+  IdentifierInfo &name_identifier(
+      origin_iface_decl->getASTContext().Idents.get(name));
 
-        if (!decl_vendor->FindDecls(interface_name,
-                                    append,
-                                    max_matches,
-                                    decls))
-            break;
+  DeclFromUser<ObjCPropertyDecl> origin_property_decl(
+      origin_iface_decl->FindPropertyDeclaration(
+          &name_identifier, ObjCPropertyQueryKind::OBJC_PR_query_instance));
 
-        ObjCInterfaceDecl *runtime_interface_decl = dyn_cast<ObjCInterfaceDecl>(decls[0]);
-        
-        if (!runtime_interface_decl)
-            break;
+  bool found = false;
 
-        FindObjCMethodDeclsWithOrigin(current_id,
-                                      context,
-                                      runtime_interface_decl,
-                                      m_ast_context,
-                                      m_ast_importer_sp.get(),
-                                      "in runtime");
-    }
-    while(0);
-}
-
-static bool
-FindObjCPropertyAndIvarDeclsWithOrigin (unsigned int current_id,
-                                        NameSearchContext &context,
-                                        clang::ASTContext &ast_context,
-                                        ClangASTImporter *ast_importer,
-                                        DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    if (origin_iface_decl.IsInvalid())
-        return false;
-
-    std::string name_str = context.m_decl_name.getAsString();
-    StringRef name(name_str.c_str());
-    IdentifierInfo &name_identifier(origin_iface_decl->getASTContext().Idents.get(name));
+  if (origin_property_decl.IsValid()) {
+    DeclFromParser<ObjCPropertyDecl> parser_property_decl(
+        origin_property_decl.Import(ast_importer, ast_context));
+    if (parser_property_decl.IsValid()) {
+      if (log) {
+        ASTDumper dumper((Decl *)parser_property_decl.decl);
+        log->Printf("  CAS::FOPD[%d] found %s", current_id,
+                    dumper.GetCString());
+      }
 
-    DeclFromUser<ObjCPropertyDecl> origin_property_decl(origin_iface_decl->FindPropertyDeclaration(&name_identifier, ObjCPropertyQueryKind::OBJC_PR_query_instance));
+      context.AddNamedDecl(parser_property_decl.decl);
+      found = true;
+    }
+  }
 
-    bool found = false;
+  DeclFromUser<ObjCIvarDecl> origin_ivar_decl(
+      origin_iface_decl->getIvarDecl(&name_identifier));
 
-    if (origin_property_decl.IsValid())
-    {
-        DeclFromParser<ObjCPropertyDecl> parser_property_decl(origin_property_decl.Import(ast_importer, ast_context));
-        if (parser_property_decl.IsValid())
-        {
-            if (log)
-            {
-                ASTDumper dumper((Decl*)parser_property_decl.decl);
-                log->Printf("  CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
-            }
+  if (origin_ivar_decl.IsValid()) {
+    DeclFromParser<ObjCIvarDecl> parser_ivar_decl(
+        origin_ivar_decl.Import(ast_importer, ast_context));
+    if (parser_ivar_decl.IsValid()) {
+      if (log) {
+        ASTDumper dumper((Decl *)parser_ivar_decl.decl);
+        log->Printf("  CAS::FOPD[%d] found %s", current_id,
+                    dumper.GetCString());
+      }
 
-            context.AddNamedDecl(parser_property_decl.decl);
-            found = true;
-        }
+      context.AddNamedDecl(parser_ivar_decl.decl);
+      found = true;
     }
+  }
 
-    DeclFromUser<ObjCIvarDecl> origin_ivar_decl(origin_iface_decl->getIvarDecl(&name_identifier));
+  return found;
+}
 
-    if (origin_ivar_decl.IsValid())
-    {
-        DeclFromParser<ObjCIvarDecl> parser_ivar_decl(origin_ivar_decl.Import(ast_importer, ast_context));
-        if (parser_ivar_decl.IsValid())
-        {
-            if (log)
-            {
-                ASTDumper dumper((Decl*)parser_ivar_decl.decl);
-                log->Printf("  CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
-            }
+void ClangASTSource::FindObjCPropertyAndIvarDecls(NameSearchContext &context) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-            context.AddNamedDecl(parser_ivar_decl.decl);
-            found = true;
-        }
-    }
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
 
-    return found;
-}
+  DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl(
+      cast<ObjCInterfaceDecl>(context.m_decl_context));
+  DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl(
+      parser_iface_decl.GetOrigin(m_ast_importer_sp.get()));
 
-void
-ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  ConstString class_name(parser_iface_decl->getNameAsString().c_str());
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+  if (log)
+    log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on "
+                "(ASTContext*)%p for '%s.%s'",
+                current_id, static_cast<void *>(m_ast_context),
+                parser_iface_decl->getNameAsString().c_str(),
+                context.m_decl_name.getAsString().c_str());
 
-    DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl(cast<ObjCInterfaceDecl>(context.m_decl_context));
-    DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl(parser_iface_decl.GetOrigin(m_ast_importer_sp.get()));
+  if (FindObjCPropertyAndIvarDeclsWithOrigin(
+          current_id, context, *m_ast_context, m_ast_importer_sp.get(),
+          origin_iface_decl))
+    return;
 
-    ConstString class_name(parser_iface_decl->getNameAsString().c_str());
+  if (log)
+    log->Printf("CAS::FOPD[%d] couldn't find the property on origin "
+                "(ObjCInterfaceDecl*)%p/(ASTContext*)%p, searching "
+                "elsewhere...",
+                current_id, static_cast<const void *>(origin_iface_decl.decl),
+                static_cast<void *>(&origin_iface_decl->getASTContext()));
+
+  SymbolContext null_sc;
+  TypeList type_list;
+
+  do {
+    ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface(
+        const_cast<ObjCInterfaceDecl *>(parser_iface_decl.decl));
+
+    if (!complete_interface_decl)
+      break;
 
-    if (log)
-        log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on (ASTContext*)%p for '%s.%s'",
-                    current_id, static_cast<void*>(m_ast_context),
-                    parser_iface_decl->getNameAsString().c_str(),
-                    context.m_decl_name.getAsString().c_str());
-
-    if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
-                                               context,
-                                               *m_ast_context,
-                                               m_ast_importer_sp.get(),
-                                               origin_iface_decl))
-        return;
+    // We found the complete interface.  The runtime never needs to be queried
+    // in this scenario.
+
+    DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(
+        complete_interface_decl);
+
+    if (complete_iface_decl.decl == origin_iface_decl.decl)
+      break; // already checked this one
 
     if (log)
-        log->Printf("CAS::FOPD[%d] couldn't find the property on origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p, searching elsewhere...",
-                    current_id, static_cast<const void*>(origin_iface_decl.decl),
-                    static_cast<void*>(&origin_iface_decl->getASTContext()));
+      log->Printf("CAS::FOPD[%d] trying origin "
+                  "(ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
+                  current_id,
+                  static_cast<const void *>(complete_iface_decl.decl),
+                  static_cast<void *>(&complete_iface_decl->getASTContext()));
+
+    FindObjCPropertyAndIvarDeclsWithOrigin(current_id, context, *m_ast_context,
+                                           m_ast_importer_sp.get(),
+                                           complete_iface_decl);
 
-    SymbolContext null_sc;
-    TypeList type_list;
+    return;
+  } while (0);
 
-    do
-    {
-        ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface(const_cast<ObjCInterfaceDecl*>(parser_iface_decl.decl));
+  do {
+    // Check the modules only if the debug information didn't have a complete
+    // interface.
 
-        if (!complete_interface_decl)
-            break;
+    ClangModulesDeclVendor *modules_decl_vendor =
+        m_target->GetClangModulesDeclVendor();
 
-        // We found the complete interface.  The runtime never needs to be queried in this scenario.
+    if (!modules_decl_vendor)
+      break;
 
-        DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_decl);
+    bool append = false;
+    uint32_t max_matches = 1;
+    std::vector<clang::NamedDecl *> decls;
 
-        if (complete_iface_decl.decl == origin_iface_decl.decl)
-            break; // already checked this one
+    if (!modules_decl_vendor->FindDecls(class_name, append, max_matches, decls))
+      break;
 
-        if (log)
-            log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
-                        current_id,
-                        static_cast<const void*>(complete_iface_decl.decl),
-                        static_cast<void*>(&complete_iface_decl->getASTContext()));
-
-        FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
-                                               context,
-                                               *m_ast_context,
-                                               m_ast_importer_sp.get(),
-                                               complete_iface_decl);
+    DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_modules(
+        dyn_cast<ObjCInterfaceDecl>(decls[0]));
 
-        return;
-    }
-    while(0);
-    
-    do
-    {
-        // Check the modules only if the debug information didn't have a complete interface.
-        
-        ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor();
-        
-        if (!modules_decl_vendor)
-            break;
-        
-        bool append = false;
-        uint32_t max_matches = 1;
-        std::vector <clang::NamedDecl *> decls;
-        
-        if (!modules_decl_vendor->FindDecls(class_name,
-                                            append,
-                                            max_matches,
-                                            decls))
-            break;
-        
-        DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_modules(dyn_cast<ObjCInterfaceDecl>(decls[0]));
-        
-        if (!interface_decl_from_modules.IsValid())
-            break;
-        
-        if (log)
-            log->Printf("CAS::FOPD[%d] trying module (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
-                        current_id,
-                        static_cast<const void*>(interface_decl_from_modules.decl),
-                        static_cast<void*>(&interface_decl_from_modules->getASTContext()));
-        
-        if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
-                                                   context,
-                                                   *m_ast_context,
-                                                   m_ast_importer_sp.get(),
-                                                   interface_decl_from_modules))
-            return;
-    }
-    while(0);
-
-    do
-    {
-        // Check the runtime only if the debug information didn't have a complete interface
-        // and nothing was in the modules.
+    if (!interface_decl_from_modules.IsValid())
+      break;
 
-        lldb::ProcessSP process(m_target->GetProcessSP());
+    if (log)
+      log->Printf(
+          "CAS::FOPD[%d] trying module "
+          "(ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
+          current_id,
+          static_cast<const void *>(interface_decl_from_modules.decl),
+          static_cast<void *>(&interface_decl_from_modules->getASTContext()));
+
+    if (FindObjCPropertyAndIvarDeclsWithOrigin(
+            current_id, context, *m_ast_context, m_ast_importer_sp.get(),
+            interface_decl_from_modules))
+      return;
+  } while (0);
+
+  do {
+    // Check the runtime only if the debug information didn't have a complete
+    // interface
+    // and nothing was in the modules.
 
-        if (!process)
-            return;
+    lldb::ProcessSP process(m_target->GetProcessSP());
 
-        ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
+    if (!process)
+      return;
 
-        if (!language_runtime)
-            return;
+    ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
 
-        DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
+    if (!language_runtime)
+      return;
 
-        if (!decl_vendor)
-            break;
+    DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
 
-        bool append = false;
-        uint32_t max_matches = 1;
-        std::vector <clang::NamedDecl *> decls;
+    if (!decl_vendor)
+      break;
 
-        if (!decl_vendor->FindDecls(class_name,
-                                    append,
-                                    max_matches,
-                                    decls))
-            break;
+    bool append = false;
+    uint32_t max_matches = 1;
+    std::vector<clang::NamedDecl *> decls;
 
-        DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_runtime(dyn_cast<ObjCInterfaceDecl>(decls[0]));
-        
-        if (!interface_decl_from_runtime.IsValid())
-            break;
+    if (!decl_vendor->FindDecls(class_name, append, max_matches, decls))
+      break;
 
-        if (log)
-            log->Printf("CAS::FOPD[%d] trying runtime (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
-                        current_id,
-                        static_cast<const void*>(interface_decl_from_runtime.decl),
-                        static_cast<void*>(&interface_decl_from_runtime->getASTContext()));
-
-        if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
-                                                   context,
-                                                   *m_ast_context,
-                                                   m_ast_importer_sp.get(),
-                                                   interface_decl_from_runtime))
-            return;
-    }
-    while(0);
+    DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_runtime(
+        dyn_cast<ObjCInterfaceDecl>(decls[0]));
+
+    if (!interface_decl_from_runtime.IsValid())
+      break;
+
+    if (log)
+      log->Printf(
+          "CAS::FOPD[%d] trying runtime "
+          "(ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
+          current_id,
+          static_cast<const void *>(interface_decl_from_runtime.decl),
+          static_cast<void *>(&interface_decl_from_runtime->getASTContext()));
+
+    if (FindObjCPropertyAndIvarDeclsWithOrigin(
+            current_id, context, *m_ast_context, m_ast_importer_sp.get(),
+            interface_decl_from_runtime))
+      return;
+  } while (0);
 }
 
 typedef llvm::DenseMap<const FieldDecl *, uint64_t> FieldOffsetMap;
 typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetMap;
 
 template <class D, class O>
-static bool
-ImportOffsetMap(llvm::DenseMap<const D *, O> &destination_map, llvm::DenseMap<const D *, O> &source_map,
-                ClangASTImporter *importer, ASTContext &dest_ctx)
-{
-    // When importing fields into a new record, clang has a hard requirement that
-    // fields be imported in field offset order.  Since they are stored in a DenseMap
-    // with a pointer as the key type, this means we cannot simply iterate over the
-    // map, as the order will be non-deterministic.  Instead we have to sort by the offset
-    // and then insert in sorted order.
-    typedef llvm::DenseMap<const D *, O> MapType;
-    typedef typename MapType::value_type PairType;
-    std::vector<PairType> sorted_items;
-    sorted_items.reserve(source_map.size());
-    sorted_items.assign(source_map.begin(), source_map.end());
-    std::sort(sorted_items.begin(), sorted_items.end(),
-              [](const PairType &lhs, const PairType &rhs)
-              {
-                  return lhs.second < rhs.second;
-              });
-
-    for (const auto &item : sorted_items)
-    {
-        DeclFromUser<D> user_decl(const_cast<D *>(item.first));
-        DeclFromParser <D> parser_decl(user_decl.Import(importer, dest_ctx));
-        if (parser_decl.IsInvalid())
-            return false;
-        destination_map.insert(std::pair<const D *, O>(parser_decl.decl, item.second));
-    }
+static bool ImportOffsetMap(llvm::DenseMap<const D *, O> &destination_map,
+                            llvm::DenseMap<const D *, O> &source_map,
+                            ClangASTImporter *importer, ASTContext &dest_ctx) {
+  // When importing fields into a new record, clang has a hard requirement that
+  // fields be imported in field offset order.  Since they are stored in a
+  // DenseMap
+  // with a pointer as the key type, this means we cannot simply iterate over
+  // the
+  // map, as the order will be non-deterministic.  Instead we have to sort by
+  // the offset
+  // and then insert in sorted order.
+  typedef llvm::DenseMap<const D *, O> MapType;
+  typedef typename MapType::value_type PairType;
+  std::vector<PairType> sorted_items;
+  sorted_items.reserve(source_map.size());
+  sorted_items.assign(source_map.begin(), source_map.end());
+  std::sort(sorted_items.begin(), sorted_items.end(),
+            [](const PairType &lhs, const PairType &rhs) {
+              return lhs.second < rhs.second;
+            });
+
+  for (const auto &item : sorted_items) {
+    DeclFromUser<D> user_decl(const_cast<D *>(item.first));
+    DeclFromParser<D> parser_decl(user_decl.Import(importer, dest_ctx));
+    if (parser_decl.IsInvalid())
+      return false;
+    destination_map.insert(
+        std::pair<const D *, O>(parser_decl.decl, item.second));
+  }
 
-    return true;
+  return true;
 }
 
 template <bool IsVirtual>
-bool
-ExtractBaseOffsets(const ASTRecordLayout &record_layout, DeclFromUser<const CXXRecordDecl> &record,
-                   BaseOffsetMap &base_offsets)
-{
-    for (CXXRecordDecl::base_class_const_iterator bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()),
-                                                  be = (IsVirtual ? record->vbases_end() : record->bases_end());
-         bi != be; ++bi)
-    {
-        if (!IsVirtual && bi->isVirtual())
-            continue;
-
-        const clang::Type *origin_base_type = bi->getType().getTypePtr();
-        const clang::RecordType *origin_base_record_type = origin_base_type->getAs<RecordType>();
+bool ExtractBaseOffsets(const ASTRecordLayout &record_layout,
+                        DeclFromUser<const CXXRecordDecl> &record,
+                        BaseOffsetMap &base_offsets) {
+  for (CXXRecordDecl::base_class_const_iterator
+           bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()),
+           be = (IsVirtual ? record->vbases_end() : record->bases_end());
+       bi != be; ++bi) {
+    if (!IsVirtual && bi->isVirtual())
+      continue;
+
+    const clang::Type *origin_base_type = bi->getType().getTypePtr();
+    const clang::RecordType *origin_base_record_type =
+        origin_base_type->getAs<RecordType>();
 
-        if (!origin_base_record_type)
-            return false;
+    if (!origin_base_record_type)
+      return false;
 
-        DeclFromUser <RecordDecl> origin_base_record(origin_base_record_type->getDecl());
+    DeclFromUser<RecordDecl> origin_base_record(
+        origin_base_record_type->getDecl());
 
-        if (origin_base_record.IsInvalid())
-            return false;
+    if (origin_base_record.IsInvalid())
+      return false;
 
-        DeclFromUser <CXXRecordDecl> origin_base_cxx_record(DynCast<CXXRecordDecl>(origin_base_record));
+    DeclFromUser<CXXRecordDecl> origin_base_cxx_record(
+        DynCast<CXXRecordDecl>(origin_base_record));
 
-        if (origin_base_cxx_record.IsInvalid())
-            return false;
+    if (origin_base_cxx_record.IsInvalid())
+      return false;
 
-        CharUnits base_offset;
+    CharUnits base_offset;
 
-        if (IsVirtual)
-            base_offset = record_layout.getVBaseClassOffset(origin_base_cxx_record.decl);
-        else
-            base_offset = record_layout.getBaseClassOffset(origin_base_cxx_record.decl);
+    if (IsVirtual)
+      base_offset =
+          record_layout.getVBaseClassOffset(origin_base_cxx_record.decl);
+    else
+      base_offset =
+          record_layout.getBaseClassOffset(origin_base_cxx_record.decl);
 
-        base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>(origin_base_cxx_record.decl, base_offset));
-    }
+    base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>(
+        origin_base_cxx_record.decl, base_offset));
+  }
 
-    return true;
+  return true;
 }
 
-bool
-ClangASTSource::layoutRecordType(const RecordDecl *record, uint64_t &size, uint64_t &alignment,
-                                 FieldOffsetMap &field_offsets, BaseOffsetMap &base_offsets,
-                                 BaseOffsetMap &virtual_base_offsets)
-{
-    ClangASTMetrics::RegisterRecordLayout();
+bool ClangASTSource::layoutRecordType(const RecordDecl *record, uint64_t &size,
+                                      uint64_t &alignment,
+                                      FieldOffsetMap &field_offsets,
+                                      BaseOffsetMap &base_offsets,
+                                      BaseOffsetMap &virtual_base_offsets) {
+  ClangASTMetrics::RegisterRecordLayout();
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (log)
-        log->Printf("LayoutRecordType[%u] on (ASTContext*)%p for (RecordDecl*)%p [name = '%s']",
-                    current_id, static_cast<void*>(m_ast_context),
-                    static_cast<const void*>(record),
-                    record->getNameAsString().c_str());
+  if (log)
+    log->Printf("LayoutRecordType[%u] on (ASTContext*)%p for (RecordDecl*)%p "
+                "[name = '%s']",
+                current_id, static_cast<void *>(m_ast_context),
+                static_cast<const void *>(record),
+                record->getNameAsString().c_str());
 
-    DeclFromParser <const RecordDecl> parser_record(record);
-    DeclFromUser <const RecordDecl> origin_record(parser_record.GetOrigin(m_ast_importer_sp.get()));
+  DeclFromParser<const RecordDecl> parser_record(record);
+  DeclFromUser<const RecordDecl> origin_record(
+      parser_record.GetOrigin(m_ast_importer_sp.get()));
 
-    if (origin_record.IsInvalid())
-        return false;
+  if (origin_record.IsInvalid())
+    return false;
 
-    FieldOffsetMap origin_field_offsets;
-    BaseOffsetMap origin_base_offsets;
-    BaseOffsetMap origin_virtual_base_offsets;
+  FieldOffsetMap origin_field_offsets;
+  BaseOffsetMap origin_base_offsets;
+  BaseOffsetMap origin_virtual_base_offsets;
 
-    ClangASTContext::GetCompleteDecl(&origin_record->getASTContext(), const_cast<RecordDecl*>(origin_record.decl));
+  ClangASTContext::GetCompleteDecl(
+      &origin_record->getASTContext(),
+      const_cast<RecordDecl *>(origin_record.decl));
 
-    clang::RecordDecl* definition = origin_record.decl->getDefinition();
-    if (!definition || !definition->isCompleteDefinition())
-        return false;
+  clang::RecordDecl *definition = origin_record.decl->getDefinition();
+  if (!definition || !definition->isCompleteDefinition())
+    return false;
 
-    const ASTRecordLayout &record_layout(origin_record->getASTContext().getASTRecordLayout(origin_record.decl));
+  const ASTRecordLayout &record_layout(
+      origin_record->getASTContext().getASTRecordLayout(origin_record.decl));
 
-    int field_idx = 0, field_count = record_layout.getFieldCount();
+  int field_idx = 0, field_count = record_layout.getFieldCount();
 
-    for (RecordDecl::field_iterator fi = origin_record->field_begin(), fe = origin_record->field_end(); fi != fe; ++fi)
-    {
-        if (field_idx >= field_count)
-            return false; // Layout didn't go well.  Bail out.
+  for (RecordDecl::field_iterator fi = origin_record->field_begin(),
+                                  fe = origin_record->field_end();
+       fi != fe; ++fi) {
+    if (field_idx >= field_count)
+      return false; // Layout didn't go well.  Bail out.
 
-        uint64_t field_offset = record_layout.getFieldOffset(field_idx);
+    uint64_t field_offset = record_layout.getFieldOffset(field_idx);
 
-        origin_field_offsets.insert(std::pair<const FieldDecl *, uint64_t>(*fi, field_offset));
+    origin_field_offsets.insert(
+        std::pair<const FieldDecl *, uint64_t>(*fi, field_offset));
 
-        field_idx++;
-    }
+    field_idx++;
+  }
 
-    ASTContext &parser_ast_context(record->getASTContext());
+  ASTContext &parser_ast_context(record->getASTContext());
 
-    DeclFromUser <const CXXRecordDecl> origin_cxx_record(DynCast<const CXXRecordDecl>(origin_record));
+  DeclFromUser<const CXXRecordDecl> origin_cxx_record(
+      DynCast<const CXXRecordDecl>(origin_record));
 
-    if (origin_cxx_record.IsValid())
-    {
-        if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record, origin_base_offsets) ||
-            !ExtractBaseOffsets<true>(record_layout, origin_cxx_record, origin_virtual_base_offsets))
-            return false;
-    }
+  if (origin_cxx_record.IsValid()) {
+    if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record,
+                                   origin_base_offsets) ||
+        !ExtractBaseOffsets<true>(record_layout, origin_cxx_record,
+                                  origin_virtual_base_offsets))
+      return false;
+  }
+
+  if (!ImportOffsetMap(field_offsets, origin_field_offsets,
+                       m_ast_importer_sp.get(), parser_ast_context) ||
+      !ImportOffsetMap(base_offsets, origin_base_offsets,
+                       m_ast_importer_sp.get(), parser_ast_context) ||
+      !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets,
+                       m_ast_importer_sp.get(), parser_ast_context))
+    return false;
+
+  size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth();
+  alignment = record_layout.getAlignment().getQuantity() *
+              m_ast_context->getCharWidth();
+
+  if (log) {
+    log->Printf("LRT[%u] returned:", current_id);
+    log->Printf("LRT[%u]   Original = (RecordDecl*)%p", current_id,
+                static_cast<const void *>(origin_record.decl));
+    log->Printf("LRT[%u]   Size = %" PRId64, current_id, size);
+    log->Printf("LRT[%u]   Alignment = %" PRId64, current_id, alignment);
+    log->Printf("LRT[%u]   Fields:", current_id);
+    for (RecordDecl::field_iterator fi = record->field_begin(),
+                                    fe = record->field_end();
+         fi != fe; ++fi) {
+      log->Printf("LRT[%u]     (FieldDecl*)%p, Name = '%s', Offset = %" PRId64
+                  " bits",
+                  current_id, static_cast<void *>(*fi),
+                  fi->getNameAsString().c_str(), field_offsets[*fi]);
+    }
+    DeclFromParser<const CXXRecordDecl> parser_cxx_record =
+        DynCast<const CXXRecordDecl>(parser_record);
+    if (parser_cxx_record.IsValid()) {
+      log->Printf("LRT[%u]   Bases:", current_id);
+      for (CXXRecordDecl::base_class_const_iterator
+               bi = parser_cxx_record->bases_begin(),
+               be = parser_cxx_record->bases_end();
+           bi != be; ++bi) {
+        bool is_virtual = bi->isVirtual();
+
+        QualType base_type = bi->getType();
+        const RecordType *base_record_type = base_type->getAs<RecordType>();
+        DeclFromParser<RecordDecl> base_record(base_record_type->getDecl());
+        DeclFromParser<CXXRecordDecl> base_cxx_record =
+            DynCast<CXXRecordDecl>(base_record);
+
+        log->Printf(
+            "LRT[%u]     %s(CXXRecordDecl*)%p, Name = '%s', Offset = %" PRId64
+            " chars",
+            current_id, (is_virtual ? "Virtual " : ""),
+            static_cast<void *>(base_cxx_record.decl),
+            base_cxx_record.decl->getNameAsString().c_str(),
+            (is_virtual
+                 ? virtual_base_offsets[base_cxx_record.decl].getQuantity()
+                 : base_offsets[base_cxx_record.decl].getQuantity()));
+      }
+    } else {
+      log->Printf("LRD[%u]   Not a CXXRecord, so no bases", current_id);
+    }
+  }
+
+  return true;
+}
+
+void ClangASTSource::CompleteNamespaceMap(
+    ClangASTImporter::NamespaceMapSP &namespace_map, const ConstString &name,
+    ClangASTImporter::NamespaceMapSP &parent_map) const {
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
+
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  if (log) {
+    if (parent_map && parent_map->size())
+      log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for "
+                  "namespace %s in namespace %s",
+                  current_id, static_cast<void *>(m_ast_context),
+                  name.GetCString(),
+                  parent_map->begin()->second.GetName().AsCString());
+    else
+      log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for "
+                  "namespace %s",
+                  current_id, static_cast<void *>(m_ast_context),
+                  name.GetCString());
+  }
 
-    if (!ImportOffsetMap(field_offsets, origin_field_offsets, m_ast_importer_sp.get(), parser_ast_context) ||
-        !ImportOffsetMap(base_offsets, origin_base_offsets, m_ast_importer_sp.get(), parser_ast_context) ||
-        !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, m_ast_importer_sp.get(), parser_ast_context))
-        return false;
+  if (parent_map) {
+    for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(),
+                                                  e = parent_map->end();
+         i != e; ++i) {
+      CompilerDeclContext found_namespace_decl;
 
-    size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth();
-    alignment = record_layout.getAlignment().getQuantity() * m_ast_context->getCharWidth();
+      lldb::ModuleSP module_sp = i->first;
+      CompilerDeclContext module_parent_namespace_decl = i->second;
 
-    if (log)
-    {
-        log->Printf("LRT[%u] returned:", current_id);
-        log->Printf("LRT[%u]   Original = (RecordDecl*)%p", current_id,
-                    static_cast<const void*>(origin_record.decl));
-        log->Printf("LRT[%u]   Size = %" PRId64, current_id, size);
-        log->Printf("LRT[%u]   Alignment = %" PRId64, current_id, alignment);
-        log->Printf("LRT[%u]   Fields:", current_id);
-        for (RecordDecl::field_iterator fi = record->field_begin(), fe = record->field_end();
-             fi != fe;
-             ++fi)
-        {
-            log->Printf("LRT[%u]     (FieldDecl*)%p, Name = '%s', Offset = %" PRId64 " bits", current_id,
-                        static_cast<void *>(*fi), fi->getNameAsString().c_str(), field_offsets[*fi]);
-        }
-        DeclFromParser <const CXXRecordDecl> parser_cxx_record = DynCast<const CXXRecordDecl>(parser_record);
-        if (parser_cxx_record.IsValid())
-        {
-            log->Printf("LRT[%u]   Bases:", current_id);
-            for (CXXRecordDecl::base_class_const_iterator bi = parser_cxx_record->bases_begin(), be = parser_cxx_record->bases_end();
-                 bi != be;
-                 ++bi)
-            {
-                bool is_virtual = bi->isVirtual();
-
-                QualType base_type = bi->getType();
-                const RecordType *base_record_type = base_type->getAs<RecordType>();
-                DeclFromParser <RecordDecl> base_record(base_record_type->getDecl());
-                DeclFromParser <CXXRecordDecl> base_cxx_record = DynCast<CXXRecordDecl>(base_record);
-
-                log->Printf("LRT[%u]     %s(CXXRecordDecl*)%p, Name = '%s', Offset = %" PRId64 " chars", current_id,
-                            (is_virtual ? "Virtual " : ""), static_cast<void *>(base_cxx_record.decl),
-                            base_cxx_record.decl->getNameAsString().c_str(),
-                            (is_virtual ? virtual_base_offsets[base_cxx_record.decl].getQuantity()
-                                        : base_offsets[base_cxx_record.decl].getQuantity()));
-            }
-        }
-        else
-        {
-            log->Printf("LRD[%u]   Not a CXXRecord, so no bases", current_id);
-        }
-    }
+      SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
 
-    return true;
-}
+      if (!symbol_vendor)
+        continue;
 
-void
-ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
-                                      const ConstString &name,
-                                      ClangASTImporter::NamespaceMapSP &parent_map) const
-{
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+      SymbolContext null_sc;
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+      found_namespace_decl = symbol_vendor->FindNamespace(
+          null_sc, name, &module_parent_namespace_decl);
 
-    if (log)
-    {
-        if (parent_map && parent_map->size())
-            log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s",
-                        current_id, static_cast<void*>(m_ast_context),
-                        name.GetCString(),
-                        parent_map->begin()->second.GetName().AsCString());
-        else
-            log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s",
-                        current_id, static_cast<void*>(m_ast_context),
-                        name.GetCString());
+      if (!found_namespace_decl)
+        continue;
+
+      namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(
+          module_sp, found_namespace_decl));
+
+      if (log)
+        log->Printf("  CMN[%u] Found namespace %s in module %s", current_id,
+                    name.GetCString(),
+                    module_sp->GetFileSpec().GetFilename().GetCString());
     }
+  } else {
+    const ModuleList &target_images = m_target->GetImages();
+    std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
 
-    if (parent_map)
-    {
-        for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
-             i != e;
-             ++i)
-        {
-            CompilerDeclContext found_namespace_decl;
+    CompilerDeclContext null_namespace_decl;
 
-            lldb::ModuleSP module_sp = i->first;
-            CompilerDeclContext module_parent_namespace_decl = i->second;
+    for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) {
+      lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
 
-            SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
+      if (!image)
+        continue;
 
-            if (!symbol_vendor)
-                continue;
+      CompilerDeclContext found_namespace_decl;
 
-            SymbolContext null_sc;
+      SymbolVendor *symbol_vendor = image->GetSymbolVendor();
 
-            found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
+      if (!symbol_vendor)
+        continue;
 
-            if (!found_namespace_decl)
-                continue;
+      SymbolContext null_sc;
 
-            namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(module_sp, found_namespace_decl));
+      found_namespace_decl =
+          symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
 
-            if (log)
-                log->Printf("  CMN[%u] Found namespace %s in module %s",
-                            current_id,
-                            name.GetCString(),
-                            module_sp->GetFileSpec().GetFilename().GetCString());
-        }
+      if (!found_namespace_decl)
+        continue;
+
+      namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(
+          image, found_namespace_decl));
+
+      if (log)
+        log->Printf("  CMN[%u] Found namespace %s in module %s", current_id,
+                    name.GetCString(),
+                    image->GetFileSpec().GetFilename().GetCString());
     }
-    else
-    {
-        const ModuleList &target_images = m_target->GetImages();
-        std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
+  }
+}
 
-        CompilerDeclContext null_namespace_decl;
+NamespaceDecl *ClangASTSource::AddNamespace(
+    NameSearchContext &context,
+    ClangASTImporter::NamespaceMapSP &namespace_decls) {
+  if (!namespace_decls)
+    return nullptr;
 
-        for (size_t i = 0, e = target_images.GetSize(); i < e; ++i)
-        {
-            lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
+  const CompilerDeclContext &namespace_decl = namespace_decls->begin()->second;
 
-            if (!image)
-                continue;
+  clang::ASTContext *src_ast =
+      ClangASTContext::DeclContextGetClangASTContext(namespace_decl);
+  if (!src_ast)
+    return nullptr;
+  clang::NamespaceDecl *src_namespace_decl =
+      ClangASTContext::DeclContextGetAsNamespaceDecl(namespace_decl);
 
-            CompilerDeclContext found_namespace_decl;
+  if (!src_namespace_decl)
+    return nullptr;
 
-            SymbolVendor *symbol_vendor = image->GetSymbolVendor();
+  Decl *copied_decl =
+      m_ast_importer_sp->CopyDecl(m_ast_context, src_ast, src_namespace_decl);
 
-            if (!symbol_vendor)
-                continue;
+  if (!copied_decl)
+    return nullptr;
 
-            SymbolContext null_sc;
+  NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
 
-            found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
+  if (!copied_namespace_decl)
+    return nullptr;
 
-            if (!found_namespace_decl)
-                continue;
+  context.m_decls.push_back(copied_namespace_decl);
 
-            namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>(image, found_namespace_decl));
+  m_ast_importer_sp->RegisterNamespaceMap(copied_namespace_decl,
+                                          namespace_decls);
 
-            if (log)
-                log->Printf("  CMN[%u] Found namespace %s in module %s",
-                            current_id,
-                            name.GetCString(),
-                            image->GetFileSpec().GetFilename().GetCString());
-        }
-    }
+  return dyn_cast<NamespaceDecl>(copied_decl);
 }
 
-NamespaceDecl *
-ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
-{
-    if (!namespace_decls)
-        return nullptr;
-
-    const CompilerDeclContext &namespace_decl = namespace_decls->begin()->second;
-
-    clang::ASTContext *src_ast = ClangASTContext::DeclContextGetClangASTContext(namespace_decl);
-    if (!src_ast)
-        return nullptr;
-    clang::NamespaceDecl *src_namespace_decl = ClangASTContext::DeclContextGetAsNamespaceDecl(namespace_decl);
+CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
+  ClangASTContext *src_ast =
+      llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
+  if (src_ast == nullptr)
+    return CompilerType();
 
-    if (!src_namespace_decl)
-        return nullptr;
+  ClangASTMetrics::RegisterLLDBImport();
 
-    Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, src_ast, src_namespace_decl);
+  SetImportInProgress(true);
 
-    if (!copied_decl)
-        return nullptr;
+  QualType copied_qual_type =
+      m_ast_importer_sp->CopyType(m_ast_context, src_ast->getASTContext(),
+                                  ClangUtil::GetQualType(src_type));
+
+  SetImportInProgress(false);
 
-    NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
+  if (copied_qual_type.getAsOpaquePtr() &&
+      copied_qual_type->getCanonicalTypeInternal().isNull())
+    // this shouldn't happen, but we're hardening because the AST importer seems
+    // to be generating bad types
+    // on occasion.
+    return CompilerType();
 
-    if (!copied_namespace_decl)
-        return nullptr;
+  return CompilerType(m_ast_context, copied_qual_type);
+}
+
+clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
+  assert(type && "Type for variable must be valid!");
+
+  if (!type.IsValid())
+    return NULL;
+
+  ClangASTContext *lldb_ast =
+      llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+  if (!lldb_ast)
+    return NULL;
 
-    context.m_decls.push_back(copied_namespace_decl);
+  IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
 
-    m_ast_importer_sp->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
+  clang::ASTContext *ast = lldb_ast->getASTContext();
 
-    return dyn_cast<NamespaceDecl>(copied_decl);
+  clang::NamedDecl *Decl = VarDecl::Create(
+      *ast, const_cast<DeclContext *>(m_decl_context), SourceLocation(),
+      SourceLocation(), ii, ClangUtil::GetQualType(type), 0, SC_Static);
+  m_decls.push_back(Decl);
+
+  return Decl;
 }
 
-CompilerType
-ClangASTSource::GuardedCopyType (const CompilerType &src_type)
-{
-    ClangASTContext *src_ast = llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
-    if (src_ast == nullptr)
-        return CompilerType();
+clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
+                                                bool extern_c) {
+  assert(type && "Type for variable must be valid!");
 
-    ClangASTMetrics::RegisterLLDBImport();
+  if (!type.IsValid())
+    return NULL;
 
-    SetImportInProgress(true);
+  if (m_function_types.count(type))
+    return NULL;
 
-    QualType copied_qual_type =
-        m_ast_importer_sp->CopyType(m_ast_context, src_ast->getASTContext(), ClangUtil::GetQualType(src_type));
+  ClangASTContext *lldb_ast =
+      llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+  if (!lldb_ast)
+    return NULL;
 
-    SetImportInProgress(false);
+  m_function_types.insert(type);
 
-    if (copied_qual_type.getAsOpaquePtr() && copied_qual_type->getCanonicalTypeInternal().isNull())
-        // this shouldn't happen, but we're hardening because the AST importer seems to be generating bad types
-        // on occasion.
-        return CompilerType();
+  QualType qual_type(ClangUtil::GetQualType(type));
 
-    return CompilerType(m_ast_context, copied_qual_type);
-}
+  clang::ASTContext *ast = lldb_ast->getASTContext();
 
-clang::NamedDecl *
-NameSearchContext::AddVarDecl(const CompilerType &type)
-{
-    assert (type && "Type for variable must be valid!");
-
-    if (!type.IsValid())
-        return NULL;
-
-    ClangASTContext* lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
-    if (!lldb_ast)
-        return NULL;
-    
-    IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
-
-    clang::ASTContext *ast = lldb_ast->getASTContext();
-
-    clang::NamedDecl *Decl = VarDecl::Create(*ast, const_cast<DeclContext *>(m_decl_context), SourceLocation(),
-                                             SourceLocation(), ii, ClangUtil::GetQualType(type), 0, SC_Static);
-    m_decls.push_back(Decl);
+  const bool isInlineSpecified = false;
+  const bool hasWrittenPrototype = true;
+  const bool isConstexprSpecified = false;
 
-    return Decl;
-}
+  clang::DeclContext *context = const_cast<DeclContext *>(m_decl_context);
 
-clang::NamedDecl *
-NameSearchContext::AddFunDecl (const CompilerType &type, bool extern_c)
-{
-    assert (type && "Type for variable must be valid!");
-
-    if (!type.IsValid())
-        return NULL;
-
-    if (m_function_types.count(type))
-        return NULL;
-    
-    ClangASTContext* lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
-    if (!lldb_ast)
-        return NULL;
-
-    m_function_types.insert(type);
-
-    QualType qual_type(ClangUtil::GetQualType(type));
-
-    clang::ASTContext *ast = lldb_ast->getASTContext();
-
-    const bool isInlineSpecified = false;
-    const bool hasWrittenPrototype = true;
-    const bool isConstexprSpecified = false;
-    
-    clang::DeclContext *context = const_cast<DeclContext*>(m_decl_context);
-    
-    if (extern_c) {
-        context = LinkageSpecDecl::Create(*ast,
-                                          context,
-                                          SourceLocation(),
-                                          SourceLocation(),
-                                          clang::LinkageSpecDecl::LanguageIDs::lang_c,
-                                          false);
-    }
-
-    // Pass the identifier info for functions the decl_name is needed for operators
-    clang::DeclarationName decl_name = m_decl_name.getNameKind() == DeclarationName::Identifier ? m_decl_name.getAsIdentifierInfo() : m_decl_name;
-
-    clang::FunctionDecl *func_decl = FunctionDecl::Create (*ast,
-                                                           context,
-                                                           SourceLocation(),
-                                                           SourceLocation(),
-                                                           decl_name,
-                                                           qual_type,
-                                                           NULL,
-                                                           SC_Extern,
-                                                           isInlineSpecified,
-                                                           hasWrittenPrototype,
-                                                           isConstexprSpecified);
-
-    // We have to do more than just synthesize the FunctionDecl.  We have to
-    // synthesize ParmVarDecls for all of the FunctionDecl's arguments.  To do
-    // this, we raid the function's FunctionProtoType for types.
-
-    const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>();
-
-    if (func_proto_type)
-    {
-        unsigned NumArgs = func_proto_type->getNumParams();
-        unsigned ArgIndex;
-
-        SmallVector<ParmVarDecl *, 5> parm_var_decls;
-
-        for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
-        {
-            QualType arg_qual_type (func_proto_type->getParamType(ArgIndex));
-
-            parm_var_decls.push_back(ParmVarDecl::Create (*ast,
-                                                          const_cast<DeclContext*>(context),
-                                                          SourceLocation(),
-                                                          SourceLocation(),
-                                                          NULL,
-                                                          arg_qual_type,
-                                                          NULL,
-                                                          SC_Static,
-                                                          NULL));
-        }
+  if (extern_c) {
+    context = LinkageSpecDecl::Create(
+        *ast, context, SourceLocation(), SourceLocation(),
+        clang::LinkageSpecDecl::LanguageIDs::lang_c, false);
+  }
 
-        func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls));
-    }
-    else
-    {
-        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  // Pass the identifier info for functions the decl_name is needed for
+  // operators
+  clang::DeclarationName decl_name =
+      m_decl_name.getNameKind() == DeclarationName::Identifier
+          ? m_decl_name.getAsIdentifierInfo()
+          : m_decl_name;
 
-        if (log)
-            log->Printf("Function type wasn't a FunctionProtoType");
+  clang::FunctionDecl *func_decl = FunctionDecl::Create(
+      *ast, context, SourceLocation(), SourceLocation(), decl_name, qual_type,
+      NULL, SC_Extern, isInlineSpecified, hasWrittenPrototype,
+      isConstexprSpecified);
+
+  // We have to do more than just synthesize the FunctionDecl.  We have to
+  // synthesize ParmVarDecls for all of the FunctionDecl's arguments.  To do
+  // this, we raid the function's FunctionProtoType for types.
+
+  const FunctionProtoType *func_proto_type =
+      qual_type.getTypePtr()->getAs<FunctionProtoType>();
+
+  if (func_proto_type) {
+    unsigned NumArgs = func_proto_type->getNumParams();
+    unsigned ArgIndex;
+
+    SmallVector<ParmVarDecl *, 5> parm_var_decls;
+
+    for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex) {
+      QualType arg_qual_type(func_proto_type->getParamType(ArgIndex));
+
+      parm_var_decls.push_back(ParmVarDecl::Create(
+          *ast, const_cast<DeclContext *>(context), SourceLocation(),
+          SourceLocation(), NULL, arg_qual_type, NULL, SC_Static, NULL));
     }
 
-    m_decls.push_back(func_decl);
+    func_decl->setParams(ArrayRef<ParmVarDecl *>(parm_var_decls));
+  } else {
+    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+    if (log)
+      log->Printf("Function type wasn't a FunctionProtoType");
+  }
+
+  m_decls.push_back(func_decl);
 
-    return func_decl;
+  return func_decl;
 }
 
-clang::NamedDecl *
-NameSearchContext::AddGenericFunDecl()
-{
-    FunctionProtoType::ExtProtoInfo proto_info;
+clang::NamedDecl *NameSearchContext::AddGenericFunDecl() {
+  FunctionProtoType::ExtProtoInfo proto_info;
 
-    proto_info.Variadic = true;
+  proto_info.Variadic = true;
 
-    QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy,    // result
-                                                                                ArrayRef<QualType>(),                                        // argument types
-                                                                                proto_info));
+  QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType(
+      m_ast_source.m_ast_context->UnknownAnyTy, // result
+      ArrayRef<QualType>(),                     // argument types
+      proto_info));
 
-    return AddFunDecl(CompilerType (m_ast_source.m_ast_context, generic_function_type), true);
+  return AddFunDecl(
+      CompilerType(m_ast_source.m_ast_context, generic_function_type), true);
 }
 
 clang::NamedDecl *
-NameSearchContext::AddTypeDecl(const CompilerType &clang_type)
-{
-    if (ClangUtil::IsClangType(clang_type))
-    {
-        QualType qual_type = ClangUtil::GetQualType(clang_type);
-
-        if (const TypedefType *typedef_type = llvm::dyn_cast<TypedefType>(qual_type))
-        {
-            TypedefNameDecl *typedef_name_decl = typedef_type->getDecl();
+NameSearchContext::AddTypeDecl(const CompilerType &clang_type) {
+  if (ClangUtil::IsClangType(clang_type)) {
+    QualType qual_type = ClangUtil::GetQualType(clang_type);
 
-            m_decls.push_back(typedef_name_decl);
+    if (const TypedefType *typedef_type =
+            llvm::dyn_cast<TypedefType>(qual_type)) {
+      TypedefNameDecl *typedef_name_decl = typedef_type->getDecl();
 
-            return (NamedDecl*)typedef_name_decl;
-        }
-        else if (const TagType *tag_type = qual_type->getAs<TagType>())
-        {
-            TagDecl *tag_decl = tag_type->getDecl();
+      m_decls.push_back(typedef_name_decl);
 
-            m_decls.push_back(tag_decl);
+      return (NamedDecl *)typedef_name_decl;
+    } else if (const TagType *tag_type = qual_type->getAs<TagType>()) {
+      TagDecl *tag_decl = tag_type->getDecl();
 
-            return tag_decl;
-        }
-        else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>())
-        {
-            ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
+      m_decls.push_back(tag_decl);
 
-            m_decls.push_back((NamedDecl*)interface_decl);
+      return tag_decl;
+    } else if (const ObjCObjectType *objc_object_type =
+                   qual_type->getAs<ObjCObjectType>()) {
+      ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
 
-            return (NamedDecl*)interface_decl;
-        }
+      m_decls.push_back((NamedDecl *)interface_decl);
+
+      return (NamedDecl *)interface_decl;
     }
-    return NULL;
+  }
+  return NULL;
 }
 
-void
-NameSearchContext::AddLookupResult (clang::DeclContextLookupResult result)
-{
-    for (clang::NamedDecl *decl : result)
-        m_decls.push_back (decl);
+void NameSearchContext::AddLookupResult(clang::DeclContextLookupResult result) {
+  for (clang::NamedDecl *decl : result)
+    m_decls.push_back(decl);
 }
 
-void
-NameSearchContext::AddNamedDecl (clang::NamedDecl *decl)
-{
-    m_decls.push_back (decl);
+void NameSearchContext::AddNamedDecl(clang::NamedDecl *decl) {
+  m_decls.push_back(decl);
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h Tue Sep  6 15:57:50 2016
@@ -12,16 +12,16 @@
 
 #include <set>
 
-#include "clang/Basic/IdentifierTable.h"
-#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/ClangASTImporter.h"
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Target/Target.h"
+#include "clang/Basic/IdentifierTable.h"
 
 #include "llvm/ADT/SmallSet.h"
 
 namespace lldb_private {
-    
+
 //----------------------------------------------------------------------
 /// @class ClangASTSource ClangASTSource.h "lldb/Expression/ClangASTSource.h"
 /// @brief Provider for named objects defined in the debug info for Clang
@@ -33,494 +33,479 @@ namespace lldb_private {
 /// to Clang for these names, consulting the ClangExpressionDeclMap to do
 /// the actual lookups.
 //----------------------------------------------------------------------
-class ClangASTSource : 
-    public ClangExternalASTSourceCommon,
-    public ClangASTImporter::MapCompleter
-{
+class ClangASTSource : public ClangExternalASTSourceCommon,
+                       public ClangASTImporter::MapCompleter {
 public:
-    //------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// Initializes class variables.
-    ///
-    /// @param[in] declMap
-    ///     A reference to the LLDB object that handles entity lookup.
-    //------------------------------------------------------------------
-    ClangASTSource (const lldb::TargetSP &target) :
-        m_import_in_progress (false),
-        m_lookups_enabled (false),
-        m_target (target),
-        m_ast_context (NULL),
-        m_active_lexical_decls (),
-        m_active_lookups ()
-    {
-        m_ast_importer_sp = m_target->GetClangASTImporter();
-    }
-  
-    //------------------------------------------------------------------
-    /// Destructor
-    //------------------------------------------------------------------
-    ~ClangASTSource() override;
-    
-    //------------------------------------------------------------------
-    /// Interface stubs.
-    //------------------------------------------------------------------
-    clang::Decl *GetExternalDecl (uint32_t) override {   return NULL;                }
-    clang::Stmt *GetExternalDeclStmt (uint64_t) override {   return NULL;                }
-    clang::Selector GetExternalSelector (uint32_t) override {   return clang::Selector();   }
-    uint32_t GetNumExternalSelectors () override {   return 0;                   }
-    clang::CXXBaseSpecifier *GetExternalCXXBaseSpecifiers (uint64_t Offset) override
-                                                    {   return NULL;                }
-    void MaterializeVisibleDecls (const clang::DeclContext *DC)
-                                                    {   return;                     }
-      
-    void InstallASTContext (clang::ASTContext *ast_context)
-    {
-        m_ast_context = ast_context;
-        m_ast_importer_sp->InstallMapCompleter(ast_context, *this);
+  //------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// Initializes class variables.
+  ///
+  /// @param[in] declMap
+  ///     A reference to the LLDB object that handles entity lookup.
+  //------------------------------------------------------------------
+  ClangASTSource(const lldb::TargetSP &target)
+      : m_import_in_progress(false), m_lookups_enabled(false), m_target(target),
+        m_ast_context(NULL), m_active_lexical_decls(), m_active_lookups() {
+    m_ast_importer_sp = m_target->GetClangASTImporter();
+  }
+
+  //------------------------------------------------------------------
+  /// Destructor
+  //------------------------------------------------------------------
+  ~ClangASTSource() override;
+
+  //------------------------------------------------------------------
+  /// Interface stubs.
+  //------------------------------------------------------------------
+  clang::Decl *GetExternalDecl(uint32_t) override { return NULL; }
+  clang::Stmt *GetExternalDeclStmt(uint64_t) override { return NULL; }
+  clang::Selector GetExternalSelector(uint32_t) override {
+    return clang::Selector();
+  }
+  uint32_t GetNumExternalSelectors() override { return 0; }
+  clang::CXXBaseSpecifier *
+  GetExternalCXXBaseSpecifiers(uint64_t Offset) override {
+    return NULL;
+  }
+  void MaterializeVisibleDecls(const clang::DeclContext *DC) { return; }
+
+  void InstallASTContext(clang::ASTContext *ast_context) {
+    m_ast_context = ast_context;
+    m_ast_importer_sp->InstallMapCompleter(ast_context, *this);
+  }
+
+  //
+  // APIs for ExternalASTSource
+  //
+
+  //------------------------------------------------------------------
+  /// Look up all Decls that match a particular name.  Only handles
+  /// Identifiers and DeclContexts that are either NamespaceDecls or
+  /// TranslationUnitDecls.  Calls SetExternalVisibleDeclsForName with
+  /// the result.
+  ///
+  /// The work for this function is done by
+  /// void FindExternalVisibleDecls (NameSearchContext &);
+  ///
+  /// @param[in] DC
+  ///     The DeclContext to register the found Decls in.
+  ///
+  /// @param[in] Name
+  ///     The name to find entries for.
+  ///
+  /// @return
+  ///     Whatever SetExternalVisibleDeclsForName returns.
+  //------------------------------------------------------------------
+  bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
+                                      clang::DeclarationName Name) override;
+
+  //------------------------------------------------------------------
+  /// Enumerate all Decls in a given lexical context.
+  ///
+  /// @param[in] DC
+  ///     The DeclContext being searched.
+  ///
+  /// @param[in] isKindWeWant
+  ///     A callback function that returns true given the
+  ///     DeclKinds of desired Decls, and false otherwise.
+  ///
+  /// @param[in] Decls
+  ///     A vector that is filled in with matching Decls.
+  //------------------------------------------------------------------
+  void FindExternalLexicalDecls(
+      const clang::DeclContext *DC,
+      llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
+      llvm::SmallVectorImpl<clang::Decl *> &Decls) override;
+
+  //------------------------------------------------------------------
+  /// Specify the layout of the contents of a RecordDecl.
+  ///
+  /// @param[in] Record
+  ///     The record (in the parser's AST context) that needs to be
+  ///     laid out.
+  ///
+  /// @param[out] Size
+  ///     The total size of the record in bits.
+  ///
+  /// @param[out] Alignment
+  ///     The alignment of the record in bits.
+  ///
+  /// @param[in] FieldOffsets
+  ///     A map that must be populated with pairs of the record's
+  ///     fields (in the parser's AST context) and their offsets
+  ///     (measured in bits).
+  ///
+  /// @param[in] BaseOffsets
+  ///     A map that must be populated with pairs of the record's
+  ///     C++ concrete base classes (in the parser's AST context,
+  ///     and only if the record is a CXXRecordDecl and has base
+  ///     classes) and their offsets (measured in bytes).
+  ///
+  /// @param[in] VirtualBaseOffsets
+  ///     A map that must be populated with pairs of the record's
+  ///     C++ virtual base classes (in the parser's AST context,
+  ///     and only if the record is a CXXRecordDecl and has base
+  ///     classes) and their offsets (measured in bytes).
+  ///
+  /// @return
+  ///     True <=> the layout is valid.
+  //-----------------------------------------------------------------
+  bool layoutRecordType(
+      const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
+      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
+      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
+          &BaseOffsets,
+      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
+          &VirtualBaseOffsets) override;
+
+  //------------------------------------------------------------------
+  /// Complete a TagDecl.
+  ///
+  /// @param[in] Tag
+  ///     The Decl to be completed in place.
+  //------------------------------------------------------------------
+  void CompleteType(clang::TagDecl *Tag) override;
+
+  //------------------------------------------------------------------
+  /// Complete an ObjCInterfaceDecl.
+  ///
+  /// @param[in] Class
+  ///     The Decl to be completed in place.
+  //------------------------------------------------------------------
+  void CompleteType(clang::ObjCInterfaceDecl *Class) override;
+
+  //------------------------------------------------------------------
+  /// Called on entering a translation unit.  Tells Clang by calling
+  /// setHasExternalVisibleStorage() and setHasExternalLexicalStorage()
+  /// that this object has something to say about undefined names.
+  ///
+  /// @param[in] ASTConsumer
+  ///     Unused.
+  //------------------------------------------------------------------
+  void StartTranslationUnit(clang::ASTConsumer *Consumer) override;
+
+  //
+  // APIs for NamespaceMapCompleter
+  //
+
+  //------------------------------------------------------------------
+  /// Look up the modules containing a given namespace and put the
+  /// appropriate entries in the namespace map.
+  ///
+  /// @param[in] namespace_map
+  ///     The map to be completed.
+  ///
+  /// @param[in] name
+  ///     The name of the namespace to be found.
+  ///
+  /// @param[in] parent_map
+  ///     The map for the namespace's parent namespace, if there is
+  ///     one.
+  //------------------------------------------------------------------
+  void CompleteNamespaceMap(
+      ClangASTImporter::NamespaceMapSP &namespace_map, const ConstString &name,
+      ClangASTImporter::NamespaceMapSP &parent_map) const override;
+
+  //
+  // Helper APIs
+  //
+
+  clang::NamespaceDecl *
+  AddNamespace(NameSearchContext &context,
+               ClangASTImporter::NamespaceMapSP &namespace_decls);
+
+  //------------------------------------------------------------------
+  /// The worker function for FindExternalVisibleDeclsByName.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when filing results.
+  //------------------------------------------------------------------
+  virtual void FindExternalVisibleDecls(NameSearchContext &context);
+
+  void SetImportInProgress(bool import_in_progress) {
+    m_import_in_progress = import_in_progress;
+  }
+  bool GetImportInProgress() { return m_import_in_progress; }
+
+  void SetLookupsEnabled(bool lookups_enabled) {
+    m_lookups_enabled = lookups_enabled;
+  }
+  bool GetLookupsEnabled() { return m_lookups_enabled; }
+
+  //----------------------------------------------------------------------
+  /// @class ClangASTSourceProxy ClangASTSource.h
+  /// "lldb/Expression/ClangASTSource.h"
+  /// @brief Proxy for ClangASTSource
+  ///
+  /// Clang AST contexts like to own their AST sources, so this is a
+  /// state-free proxy object.
+  //----------------------------------------------------------------------
+  class ClangASTSourceProxy : public ClangExternalASTSourceCommon {
+  public:
+    ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {}
+
+    bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
+                                        clang::DeclarationName Name) override {
+      return m_original.FindExternalVisibleDeclsByName(DC, Name);
     }
-  
-    //
-    // APIs for ExternalASTSource
-    //
-
-    //------------------------------------------------------------------
-    /// Look up all Decls that match a particular name.  Only handles
-    /// Identifiers and DeclContexts that are either NamespaceDecls or
-    /// TranslationUnitDecls.  Calls SetExternalVisibleDeclsForName with
-    /// the result.
-    ///
-    /// The work for this function is done by
-    /// void FindExternalVisibleDecls (NameSearchContext &);
-    ///
-    /// @param[in] DC
-    ///     The DeclContext to register the found Decls in.
-    ///
-    /// @param[in] Name
-    ///     The name to find entries for.
-    ///
-    /// @return
-    ///     Whatever SetExternalVisibleDeclsForName returns.
-    //------------------------------------------------------------------
-    bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override;
-
-    //------------------------------------------------------------------
-    /// Enumerate all Decls in a given lexical context.
-    ///
-    /// @param[in] DC
-    ///     The DeclContext being searched.
-    ///
-    /// @param[in] isKindWeWant
-    ///     A callback function that returns true given the
-    ///     DeclKinds of desired Decls, and false otherwise.
-    ///
-    /// @param[in] Decls
-    ///     A vector that is filled in with matching Decls.
-    //------------------------------------------------------------------
+
     void FindExternalLexicalDecls(
-        const clang::DeclContext *DC, llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
-        llvm::SmallVectorImpl<clang::Decl *> &Decls) override;
+        const clang::DeclContext *DC,
+        llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
+        llvm::SmallVectorImpl<clang::Decl *> &Decls) override {
+      return m_original.FindExternalLexicalDecls(DC, IsKindWeWant, Decls);
+    }
+
+    void CompleteType(clang::TagDecl *Tag) override {
+      return m_original.CompleteType(Tag);
+    }
+
+    void CompleteType(clang::ObjCInterfaceDecl *Class) override {
+      return m_original.CompleteType(Class);
+    }
 
-    //------------------------------------------------------------------
-    /// Specify the layout of the contents of a RecordDecl.
-    ///
-    /// @param[in] Record
-    ///     The record (in the parser's AST context) that needs to be
-    ///     laid out.
-    ///
-    /// @param[out] Size
-    ///     The total size of the record in bits.
-    ///
-    /// @param[out] Alignment
-    ///     The alignment of the record in bits.
-    ///
-    /// @param[in] FieldOffsets
-    ///     A map that must be populated with pairs of the record's
-    ///     fields (in the parser's AST context) and their offsets
-    ///     (measured in bits).
-    ///
-    /// @param[in] BaseOffsets
-    ///     A map that must be populated with pairs of the record's
-    ///     C++ concrete base classes (in the parser's AST context, 
-    ///     and only if the record is a CXXRecordDecl and has base
-    ///     classes) and their offsets (measured in bytes).
-    ///
-    /// @param[in] VirtualBaseOffsets
-    ///     A map that must be populated with pairs of the record's
-    ///     C++ virtual base classes (in the parser's AST context, 
-    ///     and only if the record is a CXXRecordDecl and has base
-    ///     classes) and their offsets (measured in bytes).
-    ///
-    /// @return
-    ///     True <=> the layout is valid.
-    //-----------------------------------------------------------------
-    bool layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
-                          llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
-                          llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
-                          llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets) override;
-
-    //------------------------------------------------------------------
-    /// Complete a TagDecl.
-    ///
-    /// @param[in] Tag
-    ///     The Decl to be completed in place.
-    //------------------------------------------------------------------
-    void CompleteType(clang::TagDecl *Tag) override;
-
-    //------------------------------------------------------------------
-    /// Complete an ObjCInterfaceDecl.
-    ///
-    /// @param[in] Class
-    ///     The Decl to be completed in place.
-    //------------------------------------------------------------------
-    void CompleteType(clang::ObjCInterfaceDecl *Class) override;
-
-    //------------------------------------------------------------------
-    /// Called on entering a translation unit.  Tells Clang by calling
-    /// setHasExternalVisibleStorage() and setHasExternalLexicalStorage()
-    /// that this object has something to say about undefined names.
-    ///
-    /// @param[in] ASTConsumer
-    ///     Unused.
-    //------------------------------------------------------------------
-    void StartTranslationUnit(clang::ASTConsumer *Consumer) override;
-
-    //
-    // APIs for NamespaceMapCompleter
-    //
-    
-    //------------------------------------------------------------------
-    /// Look up the modules containing a given namespace and put the 
-    /// appropriate entries in the namespace map.
-    ///
-    /// @param[in] namespace_map
-    ///     The map to be completed.
-    ///
-    /// @param[in] name
-    ///     The name of the namespace to be found.
-    ///
-    /// @param[in] parent_map
-    ///     The map for the namespace's parent namespace, if there is
-    ///     one.
-    //------------------------------------------------------------------
-    void CompleteNamespaceMap(ClangASTImporter::NamespaceMapSP &namespace_map, const ConstString &name,
-                              ClangASTImporter::NamespaceMapSP &parent_map) const override;
-
-    //
-    // Helper APIs
-    //
-    
-    clang::NamespaceDecl *
-    AddNamespace (NameSearchContext &context, 
-                  ClangASTImporter::NamespaceMapSP &namespace_decls);
-    
-    //------------------------------------------------------------------
-    /// The worker function for FindExternalVisibleDeclsByName.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when filing results.
-    //------------------------------------------------------------------
-    virtual void FindExternalVisibleDecls (NameSearchContext &context);
-    
-    void SetImportInProgress (bool import_in_progress) { m_import_in_progress = import_in_progress; }
-    bool GetImportInProgress () { return m_import_in_progress; }
-    
-    void SetLookupsEnabled (bool lookups_enabled) { m_lookups_enabled = lookups_enabled; }
-    bool GetLookupsEnabled () { return m_lookups_enabled; } 
-    
-    //----------------------------------------------------------------------
-    /// @class ClangASTSourceProxy ClangASTSource.h "lldb/Expression/ClangASTSource.h"
-    /// @brief Proxy for ClangASTSource
-    ///
-    /// Clang AST contexts like to own their AST sources, so this is a
-    /// state-free proxy object.
-    //----------------------------------------------------------------------
-    class ClangASTSourceProxy : public ClangExternalASTSourceCommon
-    {
-    public:
-        ClangASTSourceProxy (ClangASTSource &original) :
-            m_original(original)
-        {
-        }
-
-        bool
-        FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override
-        {
-            return m_original.FindExternalVisibleDeclsByName(DC, Name);
-        }
-
-        void
-        FindExternalLexicalDecls(const clang::DeclContext *DC,
-                                 llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
-                                 llvm::SmallVectorImpl<clang::Decl *> &Decls) override
-        {
-            return m_original.FindExternalLexicalDecls(DC, IsKindWeWant, Decls);
-        }
-
-        void
-        CompleteType(clang::TagDecl *Tag) override
-        {
-            return m_original.CompleteType(Tag);
-        }
-
-        void
-        CompleteType(clang::ObjCInterfaceDecl *Class) override
-        {
-            return m_original.CompleteType(Class);
-        }
-
-        bool
-        layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
-                         llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
-                         llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
-                         llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets) override
-        {
-            return m_original.layoutRecordType(Record,
-                                               Size, 
-                                               Alignment, 
-                                               FieldOffsets, 
-                                               BaseOffsets, 
-                                               VirtualBaseOffsets);
-        }
-
-        void
-        StartTranslationUnit(clang::ASTConsumer *Consumer) override
-        {
-            return m_original.StartTranslationUnit(Consumer);
-        }
-        
-        ClangASTMetadata *
-        GetMetadata(const void * object)
-        {
-            return m_original.GetMetadata(object);
-        }
-        
-        void
-        SetMetadata(const void * object, ClangASTMetadata &metadata)
-        {
-            return m_original.SetMetadata(object, metadata);
-        }
-        
-        bool
-        HasMetadata(const void * object)
-        {
-            return m_original.HasMetadata(object);
-        }
-    private:
-        ClangASTSource &m_original;
-    };
-    
-    clang::ExternalASTSource *CreateProxy()
-    {
-        return new ClangASTSourceProxy(*this);
+    bool layoutRecordType(
+        const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
+        llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
+        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
+            &BaseOffsets,
+        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
+            &VirtualBaseOffsets) override {
+      return m_original.layoutRecordType(Record, Size, Alignment, FieldOffsets,
+                                         BaseOffsets, VirtualBaseOffsets);
     }
-    
+
+    void StartTranslationUnit(clang::ASTConsumer *Consumer) override {
+      return m_original.StartTranslationUnit(Consumer);
+    }
+
+    ClangASTMetadata *GetMetadata(const void *object) {
+      return m_original.GetMetadata(object);
+    }
+
+    void SetMetadata(const void *object, ClangASTMetadata &metadata) {
+      return m_original.SetMetadata(object, metadata);
+    }
+
+    bool HasMetadata(const void *object) {
+      return m_original.HasMetadata(object);
+    }
+
+  private:
+    ClangASTSource &m_original;
+  };
+
+  clang::ExternalASTSource *CreateProxy() {
+    return new ClangASTSourceProxy(*this);
+  }
+
 protected:
-    //------------------------------------------------------------------
-    /// Look for the complete version of an Objective-C interface, and
-    /// return it if found.
-    ///
-    /// @param[in] interface_decl
-    ///     An ObjCInterfaceDecl that may not be the complete one.
-    ///
-    /// @return
-    ///     NULL if the complete interface couldn't be found;
-    ///     the complete interface otherwise.
-    //------------------------------------------------------------------
-    clang::ObjCInterfaceDecl *
-    GetCompleteObjCInterface (clang::ObjCInterfaceDecl *interface_decl);
-    
-    //------------------------------------------------------------------
-    /// Find all entities matching a given name in a given module,
-    /// using a NameSearchContext to make Decls for them.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext that can construct Decls for this name.
-    ///
-    /// @param[in] module
-    ///     If non-NULL, the module to query.
-    ///
-    /// @param[in] namespace_decl
-    ///     If valid and module is non-NULL, the parent namespace.
-    ///
-    /// @param[in] current_id
-    ///     The ID for the current FindExternalVisibleDecls invocation,
-    ///     for logging purposes.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    void 
-    FindExternalVisibleDecls (NameSearchContext &context, 
-                              lldb::ModuleSP module,
-                              CompilerDeclContext &namespace_decl,
-                              unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Find all Objective-C methods matching a given selector.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext that can construct Decls for this name.
-    ///     Its m_decl_name contains the selector and its m_decl_context
-    ///     is the containing object.
-    //------------------------------------------------------------------
-    void
-    FindObjCMethodDecls (NameSearchContext &context);
-    
-    //------------------------------------------------------------------
-    /// Find all Objective-C properties and ivars with a given name.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext that can construct Decls for this name.
-    ///     Its m_decl_name contains the name and its m_decl_context
-    ///     is the containing object.
-    //------------------------------------------------------------------
-    void
-    FindObjCPropertyAndIvarDecls (NameSearchContext &context);
-    
-    //------------------------------------------------------------------
-    /// A wrapper for ClangASTContext::CopyType that sets a flag that
-    /// indicates that we should not respond to queries during import.
-    ///
-    /// @param[in] dest_context
-    ///     The target AST context, typically the parser's AST context.
-    ///
-    /// @param[in] source_context
-    ///     The source AST context, typically the AST context of whatever
-    ///     symbol file the type was found in.
-    ///
-    /// @param[in] src_type
-    ///     The source type.
-    ///
-    /// @return
-    ///     The imported type.
-    //------------------------------------------------------------------
-    CompilerType
-    GuardedCopyType (const CompilerType &src_type);
-    
-    friend struct NameSearchContext;
-    
-    bool                    m_import_in_progress;
-    bool                    m_lookups_enabled;
-
-    const lldb::TargetSP                m_target;           ///< The target to use in finding variables and types.
-    clang::ASTContext                  *m_ast_context;      ///< The AST context requests are coming in for.
-    lldb::ClangASTImporterSP            m_ast_importer_sp;  ///< The target's AST importer.
-    std::set<const clang::Decl *>       m_active_lexical_decls;
-    std::set<const char *>              m_active_lookups;
+  //------------------------------------------------------------------
+  /// Look for the complete version of an Objective-C interface, and
+  /// return it if found.
+  ///
+  /// @param[in] interface_decl
+  ///     An ObjCInterfaceDecl that may not be the complete one.
+  ///
+  /// @return
+  ///     NULL if the complete interface couldn't be found;
+  ///     the complete interface otherwise.
+  //------------------------------------------------------------------
+  clang::ObjCInterfaceDecl *
+  GetCompleteObjCInterface(clang::ObjCInterfaceDecl *interface_decl);
+
+  //------------------------------------------------------------------
+  /// Find all entities matching a given name in a given module,
+  /// using a NameSearchContext to make Decls for them.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext that can construct Decls for this name.
+  ///
+  /// @param[in] module
+  ///     If non-NULL, the module to query.
+  ///
+  /// @param[in] namespace_decl
+  ///     If valid and module is non-NULL, the parent namespace.
+  ///
+  /// @param[in] current_id
+  ///     The ID for the current FindExternalVisibleDecls invocation,
+  ///     for logging purposes.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  void FindExternalVisibleDecls(NameSearchContext &context,
+                                lldb::ModuleSP module,
+                                CompilerDeclContext &namespace_decl,
+                                unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Find all Objective-C methods matching a given selector.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext that can construct Decls for this name.
+  ///     Its m_decl_name contains the selector and its m_decl_context
+  ///     is the containing object.
+  //------------------------------------------------------------------
+  void FindObjCMethodDecls(NameSearchContext &context);
+
+  //------------------------------------------------------------------
+  /// Find all Objective-C properties and ivars with a given name.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext that can construct Decls for this name.
+  ///     Its m_decl_name contains the name and its m_decl_context
+  ///     is the containing object.
+  //------------------------------------------------------------------
+  void FindObjCPropertyAndIvarDecls(NameSearchContext &context);
+
+  //------------------------------------------------------------------
+  /// A wrapper for ClangASTContext::CopyType that sets a flag that
+  /// indicates that we should not respond to queries during import.
+  ///
+  /// @param[in] dest_context
+  ///     The target AST context, typically the parser's AST context.
+  ///
+  /// @param[in] source_context
+  ///     The source AST context, typically the AST context of whatever
+  ///     symbol file the type was found in.
+  ///
+  /// @param[in] src_type
+  ///     The source type.
+  ///
+  /// @return
+  ///     The imported type.
+  //------------------------------------------------------------------
+  CompilerType GuardedCopyType(const CompilerType &src_type);
+
+  friend struct NameSearchContext;
+
+  bool m_import_in_progress;
+  bool m_lookups_enabled;
+
+  const lldb::TargetSP
+      m_target; ///< The target to use in finding variables and types.
+  clang::ASTContext
+      *m_ast_context; ///< The AST context requests are coming in for.
+  lldb::ClangASTImporterSP m_ast_importer_sp; ///< The target's AST importer.
+  std::set<const clang::Decl *> m_active_lexical_decls;
+  std::set<const char *> m_active_lookups;
 };
 
 //----------------------------------------------------------------------
 /// @class NameSearchContext ClangASTSource.h "lldb/Expression/ClangASTSource.h"
 /// @brief Container for all objects relevant to a single name lookup
-///     
+///
 /// LLDB needs to create Decls for entities it finds.  This class communicates
 /// what name is being searched for and provides helper functions to construct
 /// Decls given appropriate type information.
 //----------------------------------------------------------------------
 struct NameSearchContext {
-    ClangASTSource &m_ast_source;                               ///< The AST source making the request
-    llvm::SmallVectorImpl<clang::NamedDecl*> &m_decls;          ///< The list of declarations already constructed
-    ClangASTImporter::NamespaceMapSP m_namespace_map;           ///< The mapping of all namespaces found for this request back to their modules
-    const clang::DeclarationName &m_decl_name;                  ///< The name being looked for
-    const clang::DeclContext *m_decl_context;                   ///< The DeclContext to put declarations into
-    llvm::SmallSet <CompilerType, 5> m_function_types;    ///< All the types of functions that have been reported, so we don't report conflicts
-    
-    struct {
-        bool variable                   : 1;
-        bool function_with_type_info    : 1;
-        bool function                   : 1;
-        bool local_vars_nsp             : 1;
-        bool type                       : 1;
-    } m_found;
-    
-    //------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// Initializes class variables.
-    ///
-    /// @param[in] astSource
-    ///     A reference to the AST source making a request.
-    ///
-    /// @param[in] decls
-    ///     A reference to a list into which new Decls will be placed.  This
-    ///     list is typically empty when the function is called.
-    ///
-    /// @param[in] name
-    ///     The name being searched for (always an Identifier).
-    ///
-    /// @param[in] dc
-    ///     The DeclContext to register Decls in.
-    //------------------------------------------------------------------
-    NameSearchContext (ClangASTSource &astSource,
-                       llvm::SmallVectorImpl<clang::NamedDecl*> &decls,
-                       clang::DeclarationName &name,
-                       const clang::DeclContext *dc) :
-        m_ast_source(astSource),
-        m_decls(decls),
-        m_decl_name(name),
-        m_decl_context(dc)
-    {
-        memset(&m_found, 0, sizeof(m_found));
-    }
-    
-    //------------------------------------------------------------------
-    /// Create a VarDecl with the name being searched for and the provided
-    /// type and register it in the right places.
-    ///
-    /// @param[in] type
-    ///     The opaque QualType for the VarDecl being registered.
-    //------------------------------------------------------------------
-    clang::NamedDecl *AddVarDecl(const CompilerType &type);
-    
-    //------------------------------------------------------------------
-    /// Create a FunDecl with the name being searched for and the provided
-    /// type and register it in the right places.
-    ///
-    /// @param[in] type
-    ///     The opaque QualType for the FunDecl being registered.
-    ///
-    /// @param[in] extern_c
-    ///     If true, build an extern "C" linkage specification for this.
-    //------------------------------------------------------------------
-    clang::NamedDecl *AddFunDecl(const CompilerType &type,
-                                 bool extern_c = false);
-    
-    //------------------------------------------------------------------
-    /// Create a FunDecl with the name being searched for and generic
-    /// type (i.e. intptr_t NAME_GOES_HERE(...)) and register it in the
-    /// right places.
-    //------------------------------------------------------------------
-    clang::NamedDecl *AddGenericFunDecl();
-    
-    //------------------------------------------------------------------
-    /// Create a TypeDecl with the name being searched for and the provided
-    /// type and register it in the right places.
-    ///
-    /// @param[in] compiler_type
-    ///     The opaque QualType for the TypeDecl being registered.
-    //------------------------------------------------------------------
-    clang::NamedDecl *AddTypeDecl(const CompilerType &compiler_type);
-    
-    
-    //------------------------------------------------------------------
-    /// Add Decls from the provided DeclContextLookupResult to the list
-    /// of results.
-    ///
-    /// @param[in] result
-    ///     The DeclContextLookupResult, usually returned as the result
-    ///     of querying a DeclContext.
-    //------------------------------------------------------------------
-    void AddLookupResult (clang::DeclContextLookupResult result);
-    
-    //------------------------------------------------------------------
-    /// Add a NamedDecl to the list of results.
-    ///
-    /// @param[in] decl
-    ///     The NamedDecl, usually returned as the result
-    ///     of querying a DeclContext.
-    //------------------------------------------------------------------
-    void AddNamedDecl (clang::NamedDecl *decl);
+  ClangASTSource &m_ast_source; ///< The AST source making the request
+  llvm::SmallVectorImpl<clang::NamedDecl *>
+      &m_decls; ///< The list of declarations already constructed
+  ClangASTImporter::NamespaceMapSP m_namespace_map; ///< The mapping of all
+                                                    ///namespaces found for this
+                                                    ///request back to their
+                                                    ///modules
+  const clang::DeclarationName &m_decl_name; ///< The name being looked for
+  const clang::DeclContext
+      *m_decl_context; ///< The DeclContext to put declarations into
+  llvm::SmallSet<CompilerType, 5> m_function_types; ///< All the types of
+                                                    ///functions that have been
+                                                    ///reported, so we don't
+                                                    ///report conflicts
+
+  struct {
+    bool variable : 1;
+    bool function_with_type_info : 1;
+    bool function : 1;
+    bool local_vars_nsp : 1;
+    bool type : 1;
+  } m_found;
+
+  //------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// Initializes class variables.
+  ///
+  /// @param[in] astSource
+  ///     A reference to the AST source making a request.
+  ///
+  /// @param[in] decls
+  ///     A reference to a list into which new Decls will be placed.  This
+  ///     list is typically empty when the function is called.
+  ///
+  /// @param[in] name
+  ///     The name being searched for (always an Identifier).
+  ///
+  /// @param[in] dc
+  ///     The DeclContext to register Decls in.
+  //------------------------------------------------------------------
+  NameSearchContext(ClangASTSource &astSource,
+                    llvm::SmallVectorImpl<clang::NamedDecl *> &decls,
+                    clang::DeclarationName &name, const clang::DeclContext *dc)
+      : m_ast_source(astSource), m_decls(decls), m_decl_name(name),
+        m_decl_context(dc) {
+    memset(&m_found, 0, sizeof(m_found));
+  }
+
+  //------------------------------------------------------------------
+  /// Create a VarDecl with the name being searched for and the provided
+  /// type and register it in the right places.
+  ///
+  /// @param[in] type
+  ///     The opaque QualType for the VarDecl being registered.
+  //------------------------------------------------------------------
+  clang::NamedDecl *AddVarDecl(const CompilerType &type);
+
+  //------------------------------------------------------------------
+  /// Create a FunDecl with the name being searched for and the provided
+  /// type and register it in the right places.
+  ///
+  /// @param[in] type
+  ///     The opaque QualType for the FunDecl being registered.
+  ///
+  /// @param[in] extern_c
+  ///     If true, build an extern "C" linkage specification for this.
+  //------------------------------------------------------------------
+  clang::NamedDecl *AddFunDecl(const CompilerType &type, bool extern_c = false);
+
+  //------------------------------------------------------------------
+  /// Create a FunDecl with the name being searched for and generic
+  /// type (i.e. intptr_t NAME_GOES_HERE(...)) and register it in the
+  /// right places.
+  //------------------------------------------------------------------
+  clang::NamedDecl *AddGenericFunDecl();
+
+  //------------------------------------------------------------------
+  /// Create a TypeDecl with the name being searched for and the provided
+  /// type and register it in the right places.
+  ///
+  /// @param[in] compiler_type
+  ///     The opaque QualType for the TypeDecl being registered.
+  //------------------------------------------------------------------
+  clang::NamedDecl *AddTypeDecl(const CompilerType &compiler_type);
+
+  //------------------------------------------------------------------
+  /// Add Decls from the provided DeclContextLookupResult to the list
+  /// of results.
+  ///
+  /// @param[in] result
+  ///     The DeclContextLookupResult, usually returned as the result
+  ///     of querying a DeclContext.
+  //------------------------------------------------------------------
+  void AddLookupResult(clang::DeclContextLookupResult result);
+
+  //------------------------------------------------------------------
+  /// Add a NamedDecl to the list of results.
+  ///
+  /// @param[in] decl
+  ///     The NamedDecl, usually returned as the result
+  ///     of querying a DeclContext.
+  //------------------------------------------------------------------
+  void AddNamedDecl(clang::NamedDecl *decl);
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDiagnostic.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDiagnostic.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangDiagnostic.h Tue Sep  6 15:57:50 2016
@@ -19,42 +19,32 @@
 
 #include "lldb/Expression/DiagnosticManager.h"
 
-namespace lldb_private
-{
+namespace lldb_private {
 
-
-class ClangDiagnostic : public Diagnostic
-{
+class ClangDiagnostic : public Diagnostic {
 public:
-    typedef std::vector<clang::FixItHint> FixItList;
-    
-    static inline bool classof(const ClangDiagnostic *) { return true; }
-    static inline bool classof(const Diagnostic *diag) {
-        return diag->getKind() == eDiagnosticOriginClang;
-    }
-    
-    ClangDiagnostic(const char *message, DiagnosticSeverity severity, uint32_t compiler_id) :
-        Diagnostic(message, severity, eDiagnosticOriginClang, compiler_id)
-    {
-    }
-    
-    virtual ~ClangDiagnostic() = default;
-    
-    bool HasFixIts () const override { return !m_fixit_vec.empty(); }
-    
-    void
-    AddFixitHint (const clang::FixItHint &fixit)
-    {
-        m_fixit_vec.push_back(fixit);
-    }
-    
-    const FixItList &
-    FixIts() const
-    {
-        return m_fixit_vec;
-    }
-    FixItList m_fixit_vec;
+  typedef std::vector<clang::FixItHint> FixItList;
+
+  static inline bool classof(const ClangDiagnostic *) { return true; }
+  static inline bool classof(const Diagnostic *diag) {
+    return diag->getKind() == eDiagnosticOriginClang;
+  }
+
+  ClangDiagnostic(const char *message, DiagnosticSeverity severity,
+                  uint32_t compiler_id)
+      : Diagnostic(message, severity, eDiagnosticOriginClang, compiler_id) {}
+
+  virtual ~ClangDiagnostic() = default;
+
+  bool HasFixIts() const override { return !m_fixit_vec.empty(); }
+
+  void AddFixitHint(const clang::FixItHint &fixit) {
+    m_fixit_vec.push_back(fixit);
+  }
+
+  const FixItList &FixIts() const { return m_fixit_vec; }
+  FixItList m_fixit_vec;
 };
 
-}  // namespace lldb_private
+} // namespace lldb_private
 #endif /* lldb_ClangDiagnostic_h */

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp Tue Sep  6 15:57:50 2016
@@ -14,11 +14,6 @@
 #include "ClangModulesDeclVendor.h"
 #include "ClangPersistentVariables.h"
 
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclarationName.h"
-#include "clang/AST/Decl.h"
-#include "lldb/lldb-private.h"
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Error.h"
 #include "lldb/Core/Log.h"
@@ -30,9 +25,9 @@
 #include "lldb/Expression/Materializer.h"
 #include "lldb/Host/Endian.h"
 #include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/CompilerDecl.h"
 #include "lldb/Symbol/CompilerDeclContext.h"
-#include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolContext.h"
@@ -50,6 +45,11 @@
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
+#include "lldb/lldb-private.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclarationName.h"
 
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
 
@@ -57,1586 +57,1501 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace clang;
 
-namespace
-{
-    const char *g_lldb_local_vars_namespace_cstr = "$__lldb_local_vars";
+namespace {
+const char *g_lldb_local_vars_namespace_cstr = "$__lldb_local_vars";
 } // anonymous namespace
 
-ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory,
-                                                Materializer::PersistentVariableDelegate *result_delegate,
-                                                ExecutionContext &exe_ctx) :
-    ClangASTSource (exe_ctx.GetTargetSP()),
-    m_found_entities (),
-    m_struct_members (),
-    m_keep_result_in_memory (keep_result_in_memory),
-    m_result_delegate (result_delegate),
-    m_parser_vars (),
-    m_struct_vars ()
-{
-    EnableStructVars();
-}
-
-ClangExpressionDeclMap::~ClangExpressionDeclMap()
-{
-    // Note: The model is now that the parser's AST context and all associated
-    //   data does not vanish until the expression has been executed.  This means
-    //   that valuable lookup data (like namespaces) doesn't vanish, but
-
-    DidParse();
-    DisableStructVars();
-}
-
-bool
-ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx,
-                                  Materializer *materializer)
-{
-    ClangASTMetrics::ClearLocalCounters();
-
-    EnableParserVars();
-    m_parser_vars->m_exe_ctx = exe_ctx;
-
-    Target *target = exe_ctx.GetTargetPtr();
-    if (exe_ctx.GetFramePtr())
-        m_parser_vars->m_sym_ctx = exe_ctx.GetFramePtr()->GetSymbolContext(lldb::eSymbolContextEverything);
-    else if (exe_ctx.GetThreadPtr() && exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0))
-        m_parser_vars->m_sym_ctx = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything);
-    else if (exe_ctx.GetProcessPtr())
-    {
-        m_parser_vars->m_sym_ctx.Clear(true);
-        m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
-    }
-    else if (target)
-    {
-        m_parser_vars->m_sym_ctx.Clear(true);
-        m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
-    }
-
-    if (target)
-    {
-        m_parser_vars->m_persistent_vars = llvm::cast<ClangPersistentVariables>(target->GetPersistentExpressionStateForLanguage(eLanguageTypeC));
-
-        if (!target->GetScratchClangASTContext())
-            return false;
+ClangExpressionDeclMap::ClangExpressionDeclMap(
+    bool keep_result_in_memory,
+    Materializer::PersistentVariableDelegate *result_delegate,
+    ExecutionContext &exe_ctx)
+    : ClangASTSource(exe_ctx.GetTargetSP()), m_found_entities(),
+      m_struct_members(), m_keep_result_in_memory(keep_result_in_memory),
+      m_result_delegate(result_delegate), m_parser_vars(), m_struct_vars() {
+  EnableStructVars();
+}
+
+ClangExpressionDeclMap::~ClangExpressionDeclMap() {
+  // Note: The model is now that the parser's AST context and all associated
+  //   data does not vanish until the expression has been executed.  This means
+  //   that valuable lookup data (like namespaces) doesn't vanish, but
+
+  DidParse();
+  DisableStructVars();
+}
+
+bool ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx,
+                                       Materializer *materializer) {
+  ClangASTMetrics::ClearLocalCounters();
+
+  EnableParserVars();
+  m_parser_vars->m_exe_ctx = exe_ctx;
+
+  Target *target = exe_ctx.GetTargetPtr();
+  if (exe_ctx.GetFramePtr())
+    m_parser_vars->m_sym_ctx =
+        exe_ctx.GetFramePtr()->GetSymbolContext(lldb::eSymbolContextEverything);
+  else if (exe_ctx.GetThreadPtr() &&
+           exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0))
+    m_parser_vars->m_sym_ctx =
+        exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0)->GetSymbolContext(
+            lldb::eSymbolContextEverything);
+  else if (exe_ctx.GetProcessPtr()) {
+    m_parser_vars->m_sym_ctx.Clear(true);
+    m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
+  } else if (target) {
+    m_parser_vars->m_sym_ctx.Clear(true);
+    m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
+  }
+
+  if (target) {
+    m_parser_vars->m_persistent_vars = llvm::cast<ClangPersistentVariables>(
+        target->GetPersistentExpressionStateForLanguage(eLanguageTypeC));
+
+    if (!target->GetScratchClangASTContext())
+      return false;
+  }
+
+  m_parser_vars->m_target_info = GetTargetInfo();
+  m_parser_vars->m_materializer = materializer;
+
+  return true;
+}
+
+void ClangExpressionDeclMap::InstallCodeGenerator(
+    clang::ASTConsumer *code_gen) {
+  assert(m_parser_vars);
+  m_parser_vars->m_code_gen = code_gen;
+}
+
+void ClangExpressionDeclMap::DidParse() {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  if (log)
+    ClangASTMetrics::DumpCounters(log);
+
+  if (m_parser_vars.get()) {
+    for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
+         entity_index < num_entities; ++entity_index) {
+      ExpressionVariableSP var_sp(
+          m_found_entities.GetVariableAtIndex(entity_index));
+      if (var_sp)
+        llvm::cast<ClangExpressionVariable>(var_sp.get())
+            ->DisableParserVars(GetParserID());
+    }
+
+    for (size_t pvar_index = 0,
+                num_pvars = m_parser_vars->m_persistent_vars->GetSize();
+         pvar_index < num_pvars; ++pvar_index) {
+      ExpressionVariableSP pvar_sp(
+          m_parser_vars->m_persistent_vars->GetVariableAtIndex(pvar_index));
+      if (ClangExpressionVariable *clang_var =
+              llvm::dyn_cast<ClangExpressionVariable>(pvar_sp.get()))
+        clang_var->DisableParserVars(GetParserID());
     }
 
-    m_parser_vars->m_target_info = GetTargetInfo();
-    m_parser_vars->m_materializer = materializer;
-
-    return true;
-}
-
-void
-ClangExpressionDeclMap::InstallCodeGenerator (clang::ASTConsumer *code_gen)
-{
-    assert(m_parser_vars);
-    m_parser_vars->m_code_gen = code_gen;
+    DisableParserVars();
+  }
 }
 
-void
-ClangExpressionDeclMap::DidParse()
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+// Interface for IRForTarget
 
-    if (log)
-        ClangASTMetrics::DumpCounters(log);
+ClangExpressionDeclMap::TargetInfo ClangExpressionDeclMap::GetTargetInfo() {
+  assert(m_parser_vars.get());
 
-    if (m_parser_vars.get())
-    {
-        for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
-             entity_index < num_entities;
-             ++entity_index)
-        {
-            ExpressionVariableSP var_sp(m_found_entities.GetVariableAtIndex(entity_index));
-            if (var_sp)
-                llvm::cast<ClangExpressionVariable>(var_sp.get())->DisableParserVars(GetParserID());
-        }
+  TargetInfo ret;
 
-        for (size_t pvar_index = 0, num_pvars = m_parser_vars->m_persistent_vars->GetSize();
-             pvar_index < num_pvars;
-             ++pvar_index)
-        {
-            ExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariableAtIndex(pvar_index));
-            if (ClangExpressionVariable *clang_var = llvm::dyn_cast<ClangExpressionVariable>(pvar_sp.get()))
-                clang_var->DisableParserVars(GetParserID());
-        }
+  ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
 
-        DisableParserVars();
+  Process *process = exe_ctx.GetProcessPtr();
+  if (process) {
+    ret.byte_order = process->GetByteOrder();
+    ret.address_byte_size = process->GetAddressByteSize();
+  } else {
+    Target *target = exe_ctx.GetTargetPtr();
+    if (target) {
+      ret.byte_order = target->GetArchitecture().GetByteOrder();
+      ret.address_byte_size = target->GetArchitecture().GetAddressByteSize();
     }
+  }
+
+  return ret;
 }
 
-// Interface for IRForTarget
+bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
+                                                   const ConstString &name,
+                                                   TypeFromParser parser_type,
+                                                   bool is_result,
+                                                   bool is_lvalue) {
+  assert(m_parser_vars.get());
 
-ClangExpressionDeclMap::TargetInfo
-ClangExpressionDeclMap::GetTargetInfo()
-{
-    assert (m_parser_vars.get());
+  ClangASTContext *ast =
+      llvm::dyn_cast_or_null<ClangASTContext>(parser_type.GetTypeSystem());
+  if (ast == nullptr)
+    return false;
 
-    TargetInfo ret;
+  if (m_parser_vars->m_materializer && is_result) {
+    Error err;
 
     ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+    Target *target = exe_ctx.GetTargetPtr();
+    if (target == nullptr)
+      return false;
 
-    Process *process = exe_ctx.GetProcessPtr();
-    if (process)
-    {
-        ret.byte_order = process->GetByteOrder();
-        ret.address_byte_size = process->GetAddressByteSize();
-    }
-    else
-    {
-        Target *target = exe_ctx.GetTargetPtr();
-        if (target)
-        {
-            ret.byte_order = target->GetArchitecture().GetByteOrder();
-            ret.address_byte_size = target->GetArchitecture().GetAddressByteSize();
-        }
-    }
+    ClangASTContext *context(target->GetScratchClangASTContext());
 
-    return ret;
-}
+    TypeFromUser user_type(m_ast_importer_sp->DeportType(
+                               context->getASTContext(), ast->getASTContext(),
+                               parser_type.GetOpaqueQualType()),
+                           context);
 
-bool
-ClangExpressionDeclMap::AddPersistentVariable
-(
-    const NamedDecl *decl,
-    const ConstString &name,
-    TypeFromParser parser_type,
-    bool is_result,
-    bool is_lvalue
-)
-{
-    assert (m_parser_vars.get());
+    uint32_t offset = m_parser_vars->m_materializer->AddResultVariable(
+        user_type, is_lvalue, m_keep_result_in_memory, m_result_delegate, err);
 
-    ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(parser_type.GetTypeSystem());
-    if (ast == nullptr)
-        return false;
+    ClangExpressionVariable *var = new ClangExpressionVariable(
+        exe_ctx.GetBestExecutionContextScope(), name, user_type,
+        m_parser_vars->m_target_info.byte_order,
+        m_parser_vars->m_target_info.address_byte_size);
 
-    if (m_parser_vars->m_materializer && is_result)
-    {
-        Error err;
+    m_found_entities.AddNewlyConstructedVariable(var);
 
-        ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
-        Target *target = exe_ctx.GetTargetPtr();
-        if (target == nullptr)
-            return false;
+    var->EnableParserVars(GetParserID());
 
-        ClangASTContext *context(target->GetScratchClangASTContext());
+    ClangExpressionVariable::ParserVars *parser_vars =
+        var->GetParserVars(GetParserID());
 
-        TypeFromUser user_type(m_ast_importer_sp->DeportType(context->getASTContext(),
-                                                             ast->getASTContext(),
-                                                             parser_type.GetOpaqueQualType()),
-                               context);
-        
-        uint32_t offset = m_parser_vars->m_materializer->AddResultVariable(user_type,
-                                                                           is_lvalue,
-                                                                           m_keep_result_in_memory,
-                                                                           m_result_delegate,
-                                                                           err);
+    parser_vars->m_named_decl = decl;
+    parser_vars->m_parser_type = parser_type;
 
-        ClangExpressionVariable *var = new ClangExpressionVariable(exe_ctx.GetBestExecutionContextScope(),
-                                                                   name,
-                                                                   user_type,
-                                                                   m_parser_vars->m_target_info.byte_order,
-                                                                   m_parser_vars->m_target_info.address_byte_size);
+    var->EnableJITVars(GetParserID());
 
-        m_found_entities.AddNewlyConstructedVariable(var);
-        
-        var->EnableParserVars(GetParserID());
+    ClangExpressionVariable::JITVars *jit_vars = var->GetJITVars(GetParserID());
 
-        ClangExpressionVariable::ParserVars *parser_vars = var->GetParserVars(GetParserID());
+    jit_vars->m_offset = offset;
 
-        parser_vars->m_named_decl = decl;
-        parser_vars->m_parser_type = parser_type;
+    return true;
+  }
 
-        var->EnableJITVars(GetParserID());
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+  ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+  Target *target = exe_ctx.GetTargetPtr();
+  if (target == NULL)
+    return false;
+
+  ClangASTContext *context(target->GetScratchClangASTContext());
+
+  TypeFromUser user_type(m_ast_importer_sp->DeportType(
+                             context->getASTContext(), ast->getASTContext(),
+                             parser_type.GetOpaqueQualType()),
+                         context);
 
-        ClangExpressionVariable::JITVars *jit_vars = var->GetJITVars(GetParserID());
+  if (!user_type.GetOpaqueQualType()) {
+    if (log)
+      log->Printf("Persistent variable's type wasn't copied successfully");
+    return false;
+  }
 
-        jit_vars->m_offset = offset;
+  if (!m_parser_vars->m_target_info.IsValid())
+    return false;
 
-        return true;
-    }
+  ClangExpressionVariable *var = llvm::cast<ClangExpressionVariable>(
+      m_parser_vars->m_persistent_vars
+          ->CreatePersistentVariable(
+              exe_ctx.GetBestExecutionContextScope(), name, user_type,
+              m_parser_vars->m_target_info.byte_order,
+              m_parser_vars->m_target_info.address_byte_size)
+          .get());
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
-    Target *target = exe_ctx.GetTargetPtr();
-    if (target == NULL)
-        return false;
+  if (!var)
+    return false;
 
-    ClangASTContext *context(target->GetScratchClangASTContext());
+  var->m_frozen_sp->SetHasCompleteType();
 
-    TypeFromUser user_type(m_ast_importer_sp->DeportType(context->getASTContext(),
-                                                         ast->getASTContext(),
-                                                         parser_type.GetOpaqueQualType()),
-                           context);
+  if (is_result)
+    var->m_flags |= ClangExpressionVariable::EVNeedsFreezeDry;
+  else
+    var->m_flags |=
+        ClangExpressionVariable::EVKeepInTarget; // explicitly-declared
+                                                 // persistent variables should
+                                                 // persist
 
-    if (!user_type.GetOpaqueQualType())
-    {
-        if (log)
-            log->Printf("Persistent variable's type wasn't copied successfully");
-        return false;
-    }
+  if (is_lvalue) {
+    var->m_flags |= ClangExpressionVariable::EVIsProgramReference;
+  } else {
+    var->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
+    var->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
+  }
 
-    if (!m_parser_vars->m_target_info.IsValid())
-        return false;
+  if (m_keep_result_in_memory) {
+    var->m_flags |= ClangExpressionVariable::EVKeepInTarget;
+  }
 
-    ClangExpressionVariable *var = llvm::cast<ClangExpressionVariable>(m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx.GetBestExecutionContextScope (),
-                                                                                                                                   name,
-                                                                                                                                   user_type,
-                                                                                                                                   m_parser_vars->m_target_info.byte_order,
-                                                                                                                                   m_parser_vars->m_target_info.address_byte_size).get());
+  if (log)
+    log->Printf("Created persistent variable with flags 0x%hx", var->m_flags);
 
-    if (!var)
-        return false;
+  var->EnableParserVars(GetParserID());
 
-    var->m_frozen_sp->SetHasCompleteType();
-
-    if (is_result)
-        var->m_flags |= ClangExpressionVariable::EVNeedsFreezeDry;
-    else
-        var->m_flags |= ClangExpressionVariable::EVKeepInTarget; // explicitly-declared persistent variables should persist
+  ClangExpressionVariable::ParserVars *parser_vars =
+      var->GetParserVars(GetParserID());
 
-    if (is_lvalue)
-    {
-        var->m_flags |= ClangExpressionVariable::EVIsProgramReference;
-    }
-    else
-    {
-        var->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
-        var->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
-    }
+  parser_vars->m_named_decl = decl;
+  parser_vars->m_parser_type = parser_type;
 
-    if (m_keep_result_in_memory)
-    {
-        var->m_flags |= ClangExpressionVariable::EVKeepInTarget;
-    }
+  return true;
+}
 
-    if (log)
-        log->Printf("Created persistent variable with flags 0x%hx", var->m_flags);
+bool ClangExpressionDeclMap::AddValueToStruct(const NamedDecl *decl,
+                                              const ConstString &name,
+                                              llvm::Value *value, size_t size,
+                                              lldb::offset_t alignment) {
+  assert(m_struct_vars.get());
+  assert(m_parser_vars.get());
 
-    var->EnableParserVars(GetParserID());
+  bool is_persistent_variable = false;
 
-    ClangExpressionVariable::ParserVars *parser_vars = var->GetParserVars(GetParserID());
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    parser_vars->m_named_decl = decl;
-    parser_vars->m_parser_type = parser_type;
+  m_struct_vars->m_struct_laid_out = false;
 
+  if (ClangExpressionVariable::FindVariableInList(m_struct_members, decl,
+                                                  GetParserID()))
     return true;
-}
 
-bool
-ClangExpressionDeclMap::AddValueToStruct
-(
-    const NamedDecl *decl,
-    const ConstString &name,
-    llvm::Value *value,
-    size_t size,
-    lldb::offset_t alignment
-)
-{
-    assert (m_struct_vars.get());
-    assert (m_parser_vars.get());
+  ClangExpressionVariable *var(ClangExpressionVariable::FindVariableInList(
+      m_found_entities, decl, GetParserID()));
 
-    bool is_persistent_variable = false;
+  if (!var) {
+    var = ClangExpressionVariable::FindVariableInList(
+        *m_parser_vars->m_persistent_vars, decl, GetParserID());
+    is_persistent_variable = true;
+  }
+
+  if (!var)
+    return false;
+
+  if (log)
+    log->Printf("Adding value for (NamedDecl*)%p [%s - %s] to the structure",
+                static_cast<const void *>(decl), name.GetCString(),
+                var->GetName().GetCString());
+
+  // We know entity->m_parser_vars is valid because we used a parser variable
+  // to find it
+
+  ClangExpressionVariable::ParserVars *parser_vars =
+      llvm::cast<ClangExpressionVariable>(var)->GetParserVars(GetParserID());
+
+  parser_vars->m_llvm_value = value;
+
+  if (ClangExpressionVariable::JITVars *jit_vars =
+          llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID())) {
+    // We already laid this out; do not touch
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+    if (log)
+      log->Printf("Already placed at 0x%llx",
+                  (unsigned long long)jit_vars->m_offset);
+  }
+
+  llvm::cast<ClangExpressionVariable>(var)->EnableJITVars(GetParserID());
+
+  ClangExpressionVariable::JITVars *jit_vars =
+      llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID());
 
-    m_struct_vars->m_struct_laid_out = false;
+  jit_vars->m_alignment = alignment;
+  jit_vars->m_size = size;
 
-    if (ClangExpressionVariable::FindVariableInList(m_struct_members, decl, GetParserID()))
-        return true;
+  m_struct_members.AddVariable(var->shared_from_this());
 
-    ClangExpressionVariable *var(ClangExpressionVariable::FindVariableInList(m_found_entities, decl, GetParserID()));
+  if (m_parser_vars->m_materializer) {
+    uint32_t offset = 0;
 
-    if (!var)
-    {
-        var = ClangExpressionVariable::FindVariableInList(*m_parser_vars->m_persistent_vars, decl, GetParserID());
-        is_persistent_variable = true;
+    Error err;
+
+    if (is_persistent_variable) {
+      ExpressionVariableSP var_sp(var->shared_from_this());
+      offset = m_parser_vars->m_materializer->AddPersistentVariable(
+          var_sp, nullptr, err);
+    } else {
+      if (const lldb_private::Symbol *sym = parser_vars->m_lldb_sym)
+        offset = m_parser_vars->m_materializer->AddSymbol(*sym, err);
+      else if (const RegisterInfo *reg_info = var->GetRegisterInfo())
+        offset = m_parser_vars->m_materializer->AddRegister(*reg_info, err);
+      else if (parser_vars->m_lldb_var)
+        offset = m_parser_vars->m_materializer->AddVariable(
+            parser_vars->m_lldb_var, err);
     }
 
-    if (!var)
-        return false;
+    if (!err.Success())
+      return false;
 
     if (log)
-        log->Printf("Adding value for (NamedDecl*)%p [%s - %s] to the structure",
-                    static_cast<const void*>(decl), name.GetCString(),
-                    var->GetName().GetCString());
+      log->Printf("Placed at 0x%llx", (unsigned long long)offset);
 
-    // We know entity->m_parser_vars is valid because we used a parser variable
-    // to find it
+    jit_vars->m_offset =
+        offset; // TODO DoStructLayout() should not change this.
+  }
 
-    ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(var)->GetParserVars(GetParserID());
-
-    parser_vars->m_llvm_value = value;
+  return true;
+}
 
-    if (ClangExpressionVariable::JITVars *jit_vars = llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID()))
-    {
-        // We already laid this out; do not touch
+bool ClangExpressionDeclMap::DoStructLayout() {
+  assert(m_struct_vars.get());
 
-        if (log)
-            log->Printf("Already placed at 0x%llx", (unsigned long long)jit_vars->m_offset);
-    }
+  if (m_struct_vars->m_struct_laid_out)
+    return true;
 
-    llvm::cast<ClangExpressionVariable>(var)->EnableJITVars(GetParserID());
+  if (!m_parser_vars->m_materializer)
+    return false;
 
-    ClangExpressionVariable::JITVars *jit_vars = llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID());
+  m_struct_vars->m_struct_alignment =
+      m_parser_vars->m_materializer->GetStructAlignment();
+  m_struct_vars->m_struct_size =
+      m_parser_vars->m_materializer->GetStructByteSize();
+  m_struct_vars->m_struct_laid_out = true;
+  return true;
+}
 
-    jit_vars->m_alignment = alignment;
-    jit_vars->m_size = size;
+bool ClangExpressionDeclMap::GetStructInfo(uint32_t &num_elements, size_t &size,
+                                           lldb::offset_t &alignment) {
+  assert(m_struct_vars.get());
 
-    m_struct_members.AddVariable(var->shared_from_this());
+  if (!m_struct_vars->m_struct_laid_out)
+    return false;
 
-    if (m_parser_vars->m_materializer)
-    {
-        uint32_t offset = 0;
+  num_elements = m_struct_members.GetSize();
+  size = m_struct_vars->m_struct_size;
+  alignment = m_struct_vars->m_struct_alignment;
 
-        Error err;
+  return true;
+}
 
-        if (is_persistent_variable)
-        {
-            ExpressionVariableSP var_sp(var->shared_from_this());
-            offset = m_parser_vars->m_materializer->AddPersistentVariable(var_sp, nullptr, err);
-        }
-        else
-        {
-            if (const lldb_private::Symbol *sym = parser_vars->m_lldb_sym)
-                offset = m_parser_vars->m_materializer->AddSymbol(*sym, err);
-            else if (const RegisterInfo *reg_info = var->GetRegisterInfo())
-                offset = m_parser_vars->m_materializer->AddRegister(*reg_info, err);
-            else if (parser_vars->m_lldb_var)
-                offset = m_parser_vars->m_materializer->AddVariable(parser_vars->m_lldb_var, err);
-        }
+bool ClangExpressionDeclMap::GetStructElement(const NamedDecl *&decl,
+                                              llvm::Value *&value,
+                                              lldb::offset_t &offset,
+                                              ConstString &name,
+                                              uint32_t index) {
+  assert(m_struct_vars.get());
 
-        if (!err.Success())
-            return false;
+  if (!m_struct_vars->m_struct_laid_out)
+    return false;
 
-        if (log)
-            log->Printf("Placed at 0x%llx", (unsigned long long)offset);
+  if (index >= m_struct_members.GetSize())
+    return false;
 
-        jit_vars->m_offset = offset; // TODO DoStructLayout() should not change this.
-    }
+  ExpressionVariableSP member_sp(m_struct_members.GetVariableAtIndex(index));
 
-    return true;
-}
+  if (!member_sp)
+    return false;
 
-bool
-ClangExpressionDeclMap::DoStructLayout ()
-{
-    assert (m_struct_vars.get());
+  ClangExpressionVariable::ParserVars *parser_vars =
+      llvm::cast<ClangExpressionVariable>(member_sp.get())
+          ->GetParserVars(GetParserID());
+  ClangExpressionVariable::JITVars *jit_vars =
+      llvm::cast<ClangExpressionVariable>(member_sp.get())
+          ->GetJITVars(GetParserID());
 
-    if (m_struct_vars->m_struct_laid_out)
-        return true;
+  if (!parser_vars || !jit_vars || !member_sp->GetValueObject())
+    return false;
 
-    if (!m_parser_vars->m_materializer)
-        return false;
+  decl = parser_vars->m_named_decl;
+  value = parser_vars->m_llvm_value;
+  offset = jit_vars->m_offset;
+  name = member_sp->GetName();
 
-    m_struct_vars->m_struct_alignment = m_parser_vars->m_materializer->GetStructAlignment();
-    m_struct_vars->m_struct_size = m_parser_vars->m_materializer->GetStructByteSize();
-    m_struct_vars->m_struct_laid_out = true;
-    return true;
+  return true;
 }
 
-bool ClangExpressionDeclMap::GetStructInfo
-(
-    uint32_t &num_elements,
-    size_t &size,
-    lldb::offset_t &alignment
-)
-{
-    assert (m_struct_vars.get());
+bool ClangExpressionDeclMap::GetFunctionInfo(const NamedDecl *decl,
+                                             uint64_t &ptr) {
+  ClangExpressionVariable *entity(ClangExpressionVariable::FindVariableInList(
+      m_found_entities, decl, GetParserID()));
 
-    if (!m_struct_vars->m_struct_laid_out)
-        return false;
+  if (!entity)
+    return false;
 
-    num_elements = m_struct_members.GetSize();
-    size = m_struct_vars->m_struct_size;
-    alignment = m_struct_vars->m_struct_alignment;
+  // We know m_parser_vars is valid since we searched for the variable by
+  // its NamedDecl
 
-    return true;
+  ClangExpressionVariable::ParserVars *parser_vars =
+      entity->GetParserVars(GetParserID());
+
+  ptr = parser_vars->m_lldb_value.GetScalar().ULongLong();
+
+  return true;
 }
 
-bool
-ClangExpressionDeclMap::GetStructElement
-(
-    const NamedDecl *&decl,
-    llvm::Value *&value,
-    lldb::offset_t &offset,
-    ConstString &name,
-    uint32_t index
-)
-{
-    assert (m_struct_vars.get());
+addr_t ClangExpressionDeclMap::GetSymbolAddress(Target &target,
+                                                Process *process,
+                                                const ConstString &name,
+                                                lldb::SymbolType symbol_type,
+                                                lldb_private::Module *module) {
+  SymbolContextList sc_list;
 
-    if (!m_struct_vars->m_struct_laid_out)
-        return false;
+  if (module)
+    module->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
+  else
+    target.GetImages().FindSymbolsWithNameAndType(name, symbol_type, sc_list);
 
-    if (index >= m_struct_members.GetSize())
-        return false;
+  const uint32_t num_matches = sc_list.GetSize();
+  addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
 
-    ExpressionVariableSP member_sp(m_struct_members.GetVariableAtIndex(index));
+  for (uint32_t i = 0;
+       i < num_matches &&
+       (symbol_load_addr == 0 || symbol_load_addr == LLDB_INVALID_ADDRESS);
+       i++) {
+    SymbolContext sym_ctx;
+    sc_list.GetContextAtIndex(i, sym_ctx);
 
-    if (!member_sp)
-        return false;
+    const Address sym_address = sym_ctx.symbol->GetAddress();
 
-    ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(member_sp.get())->GetParserVars(GetParserID());
-    ClangExpressionVariable::JITVars *jit_vars = llvm::cast<ClangExpressionVariable>(member_sp.get())->GetJITVars(GetParserID());
+    if (!sym_address.IsValid())
+      continue;
 
-    if (!parser_vars ||
-        !jit_vars ||
-        !member_sp->GetValueObject())
-        return false;
+    switch (sym_ctx.symbol->GetType()) {
+    case eSymbolTypeCode:
+    case eSymbolTypeTrampoline:
+      symbol_load_addr = sym_address.GetCallableLoadAddress(&target);
+      break;
+
+    case eSymbolTypeResolver:
+      symbol_load_addr = sym_address.GetCallableLoadAddress(&target, true);
+      break;
+
+    case eSymbolTypeReExported: {
+      ConstString reexport_name = sym_ctx.symbol->GetReExportedSymbolName();
+      if (reexport_name) {
+        ModuleSP reexport_module_sp;
+        ModuleSpec reexport_module_spec;
+        reexport_module_spec.GetPlatformFileSpec() =
+            sym_ctx.symbol->GetReExportedSymbolSharedLibrary();
+        if (reexport_module_spec.GetPlatformFileSpec()) {
+          reexport_module_sp =
+              target.GetImages().FindFirstModule(reexport_module_spec);
+          if (!reexport_module_sp) {
+            reexport_module_spec.GetPlatformFileSpec().GetDirectory().Clear();
+            reexport_module_sp =
+                target.GetImages().FindFirstModule(reexport_module_spec);
+          }
+        }
+        symbol_load_addr = GetSymbolAddress(
+            target, process, sym_ctx.symbol->GetReExportedSymbolName(),
+            symbol_type, reexport_module_sp.get());
+      }
+    } break;
+
+    case eSymbolTypeData:
+    case eSymbolTypeRuntime:
+    case eSymbolTypeVariable:
+    case eSymbolTypeLocal:
+    case eSymbolTypeParam:
+    case eSymbolTypeInvalid:
+    case eSymbolTypeAbsolute:
+    case eSymbolTypeException:
+    case eSymbolTypeSourceFile:
+    case eSymbolTypeHeaderFile:
+    case eSymbolTypeObjectFile:
+    case eSymbolTypeCommonBlock:
+    case eSymbolTypeBlock:
+    case eSymbolTypeVariableType:
+    case eSymbolTypeLineEntry:
+    case eSymbolTypeLineHeader:
+    case eSymbolTypeScopeBegin:
+    case eSymbolTypeScopeEnd:
+    case eSymbolTypeAdditional:
+    case eSymbolTypeCompiler:
+    case eSymbolTypeInstrumentation:
+    case eSymbolTypeUndefined:
+    case eSymbolTypeObjCClass:
+    case eSymbolTypeObjCMetaClass:
+    case eSymbolTypeObjCIVar:
+      symbol_load_addr = sym_address.GetLoadAddress(&target);
+      break;
+    }
+  }
+
+  if (symbol_load_addr == LLDB_INVALID_ADDRESS && process) {
+    ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
+
+    if (runtime) {
+      symbol_load_addr = runtime->LookupRuntimeSymbol(name);
+    }
+  }
+
+  return symbol_load_addr;
+}
+
+addr_t ClangExpressionDeclMap::GetSymbolAddress(const ConstString &name,
+                                                lldb::SymbolType symbol_type) {
+  assert(m_parser_vars.get());
+
+  if (!m_parser_vars->m_exe_ctx.GetTargetPtr())
+    return false;
+
+  return GetSymbolAddress(m_parser_vars->m_exe_ctx.GetTargetRef(),
+                          m_parser_vars->m_exe_ctx.GetProcessPtr(), name,
+                          symbol_type);
+}
+
+const Symbol *ClangExpressionDeclMap::FindGlobalDataSymbol(
+    Target &target, const ConstString &name, lldb_private::Module *module) {
+  SymbolContextList sc_list;
+
+  if (module)
+    module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
+  else
+    target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny,
+                                                  sc_list);
 
-    decl = parser_vars->m_named_decl;
-    value = parser_vars->m_llvm_value;
-    offset = jit_vars->m_offset;
-    name = member_sp->GetName();
+  const uint32_t matches = sc_list.GetSize();
+  for (uint32_t i = 0; i < matches; ++i) {
+    SymbolContext sym_ctx;
+    sc_list.GetContextAtIndex(i, sym_ctx);
+    if (sym_ctx.symbol) {
+      const Symbol *symbol = sym_ctx.symbol;
+      const Address sym_address = symbol->GetAddress();
+
+      if (sym_address.IsValid()) {
+        switch (symbol->GetType()) {
+        case eSymbolTypeData:
+        case eSymbolTypeRuntime:
+        case eSymbolTypeAbsolute:
+        case eSymbolTypeObjCClass:
+        case eSymbolTypeObjCMetaClass:
+        case eSymbolTypeObjCIVar:
+          if (symbol->GetDemangledNameIsSynthesized()) {
+            // If the demangled name was synthesized, then don't use it
+            // for expressions. Only let the symbol match if the mangled
+            // named matches for these symbols.
+            if (symbol->GetMangled().GetMangledName() != name)
+              break;
+          }
+          return symbol;
+
+        case eSymbolTypeReExported: {
+          ConstString reexport_name = symbol->GetReExportedSymbolName();
+          if (reexport_name) {
+            ModuleSP reexport_module_sp;
+            ModuleSpec reexport_module_spec;
+            reexport_module_spec.GetPlatformFileSpec() =
+                symbol->GetReExportedSymbolSharedLibrary();
+            if (reexport_module_spec.GetPlatformFileSpec()) {
+              reexport_module_sp =
+                  target.GetImages().FindFirstModule(reexport_module_spec);
+              if (!reexport_module_sp) {
+                reexport_module_spec.GetPlatformFileSpec()
+                    .GetDirectory()
+                    .Clear();
+                reexport_module_sp =
+                    target.GetImages().FindFirstModule(reexport_module_spec);
+              }
+            }
+            // Don't allow us to try and resolve a re-exported symbol if it is
+            // the same
+            // as the current symbol
+            if (name == symbol->GetReExportedSymbolName() &&
+                module == reexport_module_sp.get())
+              return NULL;
+
+            return FindGlobalDataSymbol(target,
+                                        symbol->GetReExportedSymbolName(),
+                                        reexport_module_sp.get());
+          }
+        } break;
+
+        case eSymbolTypeCode: // We already lookup functions elsewhere
+        case eSymbolTypeVariable:
+        case eSymbolTypeLocal:
+        case eSymbolTypeParam:
+        case eSymbolTypeTrampoline:
+        case eSymbolTypeInvalid:
+        case eSymbolTypeException:
+        case eSymbolTypeSourceFile:
+        case eSymbolTypeHeaderFile:
+        case eSymbolTypeObjectFile:
+        case eSymbolTypeCommonBlock:
+        case eSymbolTypeBlock:
+        case eSymbolTypeVariableType:
+        case eSymbolTypeLineEntry:
+        case eSymbolTypeLineHeader:
+        case eSymbolTypeScopeBegin:
+        case eSymbolTypeScopeEnd:
+        case eSymbolTypeAdditional:
+        case eSymbolTypeCompiler:
+        case eSymbolTypeInstrumentation:
+        case eSymbolTypeUndefined:
+        case eSymbolTypeResolver:
+          break;
+        }
+      }
+    }
+  }
+
+  return NULL;
+}
+
+lldb::VariableSP ClangExpressionDeclMap::FindGlobalVariable(
+    Target &target, ModuleSP &module, const ConstString &name,
+    CompilerDeclContext *namespace_decl, TypeFromUser *type) {
+  VariableList vars;
+
+  if (module && namespace_decl)
+    module->FindGlobalVariables(name, namespace_decl, true, -1, vars);
+  else
+    target.GetImages().FindGlobalVariables(name, true, -1, vars);
+
+  if (vars.GetSize()) {
+    if (type) {
+      for (size_t i = 0; i < vars.GetSize(); ++i) {
+        VariableSP var_sp = vars.GetVariableAtIndex(i);
+
+        if (ClangASTContext::AreTypesSame(
+                *type, var_sp->GetType()->GetFullCompilerType()))
+          return var_sp;
+      }
+    } else {
+      return vars.GetVariableAtIndex(0);
+    }
+  }
+
+  return VariableSP();
+}
+
+ClangASTContext *ClangExpressionDeclMap::GetClangASTContext() {
+  StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
+  if (frame == nullptr)
+    return nullptr;
+
+  SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
+                                                  lldb::eSymbolContextBlock);
+  if (sym_ctx.block == nullptr)
+    return nullptr;
+
+  CompilerDeclContext frame_decl_context = sym_ctx.block->GetDeclContext();
+  if (!frame_decl_context)
+    return nullptr;
 
-    return true;
+  return llvm::dyn_cast_or_null<ClangASTContext>(
+      frame_decl_context.GetTypeSystem());
 }
 
-bool
-ClangExpressionDeclMap::GetFunctionInfo
-(
-    const NamedDecl *decl,
-    uint64_t &ptr
-)
-{
-    ClangExpressionVariable *entity(ClangExpressionVariable::FindVariableInList(m_found_entities, decl, GetParserID()));
+// Interface for ClangASTSource
 
-    if (!entity)
-        return false;
+void ClangExpressionDeclMap::FindExternalVisibleDecls(
+    NameSearchContext &context) {
+  assert(m_ast_context);
 
-    // We know m_parser_vars is valid since we searched for the variable by
-    // its NamedDecl
+  ClangASTMetrics::RegisterVisibleQuery();
 
-    ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
+  const ConstString name(context.m_decl_name.getAsString().c_str());
 
-    ptr = parser_vars->m_lldb_value.GetScalar().ULongLong();
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    return true;
-}
+  if (GetImportInProgress()) {
+    if (log && log->GetVerbose())
+      log->Printf("Ignoring a query during an import");
+    return;
+  }
 
-addr_t
-ClangExpressionDeclMap::GetSymbolAddress (Target &target,
-                                          Process *process,
-                                          const ConstString &name,
-                                          lldb::SymbolType symbol_type,
-                                          lldb_private::Module *module)
-{
-    SymbolContextList sc_list;
+  static unsigned int invocation_id = 0;
+  unsigned int current_id = invocation_id++;
 
-    if (module)
-        module->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
+  if (log) {
+    if (!context.m_decl_context)
+      log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for "
+                  "'%s' in a NULL DeclContext",
+                  current_id, name.GetCString());
+    else if (const NamedDecl *context_named_decl =
+                 dyn_cast<NamedDecl>(context.m_decl_context))
+      log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for "
+                  "'%s' in '%s'",
+                  current_id, name.GetCString(),
+                  context_named_decl->getNameAsString().c_str());
     else
-        target.GetImages().FindSymbolsWithNameAndType(name, symbol_type, sc_list);
+      log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for "
+                  "'%s' in a '%s'",
+                  current_id, name.GetCString(),
+                  context.m_decl_context->getDeclKindName());
+  }
+
+  if (const NamespaceDecl *namespace_context =
+          dyn_cast<NamespaceDecl>(context.m_decl_context)) {
+    if (namespace_context->getName().str() ==
+        std::string(g_lldb_local_vars_namespace_cstr)) {
+      CompilerDeclContext compiler_decl_ctx(
+          GetClangASTContext(), const_cast<void *>(static_cast<const void *>(
+                                    context.m_decl_context)));
+      FindExternalVisibleDecls(context, lldb::ModuleSP(), compiler_decl_ctx,
+                               current_id);
+      return;
+    }
+
+    ClangASTImporter::NamespaceMapSP namespace_map =
+        m_ast_importer_sp->GetNamespaceMap(namespace_context);
+
+    if (log && log->GetVerbose())
+      log->Printf("  CEDM::FEVD[%u] Inspecting (NamespaceMap*)%p (%d entries)",
+                  current_id, static_cast<void *>(namespace_map.get()),
+                  (int)namespace_map->size());
+
+    if (!namespace_map)
+      return;
+
+    for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
+                                                  e = namespace_map->end();
+         i != e; ++i) {
+      if (log)
+        log->Printf("  CEDM::FEVD[%u] Searching namespace %s in module %s",
+                    current_id, i->second.GetName().AsCString(),
+                    i->first->GetFileSpec().GetFilename().GetCString());
 
-    const uint32_t num_matches = sc_list.GetSize();
-    addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
+      FindExternalVisibleDecls(context, i->first, i->second, current_id);
+    }
+  } else if (isa<TranslationUnitDecl>(context.m_decl_context)) {
+    CompilerDeclContext namespace_decl;
 
-    for (uint32_t i=0; i<num_matches && (symbol_load_addr == 0 || symbol_load_addr == LLDB_INVALID_ADDRESS); i++)
-    {
-        SymbolContext sym_ctx;
-        sc_list.GetContextAtIndex(i, sym_ctx);
-
-        const Address sym_address = sym_ctx.symbol->GetAddress();
-
-        if (!sym_address.IsValid())
-            continue;
-
-        switch (sym_ctx.symbol->GetType())
-        {
-            case eSymbolTypeCode:
-            case eSymbolTypeTrampoline:
-                symbol_load_addr = sym_address.GetCallableLoadAddress (&target);
-                break;
+    if (log)
+      log->Printf("  CEDM::FEVD[%u] Searching the root namespace", current_id);
 
-            case eSymbolTypeResolver:
-                symbol_load_addr = sym_address.GetCallableLoadAddress (&target, true);
-                break;
+    FindExternalVisibleDecls(context, lldb::ModuleSP(), namespace_decl,
+                             current_id);
+  }
 
-            case eSymbolTypeReExported:
-                {
-                    ConstString reexport_name = sym_ctx.symbol->GetReExportedSymbolName();
-                    if (reexport_name)
-                    {
-                        ModuleSP reexport_module_sp;
-                        ModuleSpec reexport_module_spec;
-                        reexport_module_spec.GetPlatformFileSpec() = sym_ctx.symbol->GetReExportedSymbolSharedLibrary();
-                        if (reexport_module_spec.GetPlatformFileSpec())
-                        {
-                            reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
-                            if (!reexport_module_sp)
-                            {
-                                reexport_module_spec.GetPlatformFileSpec().GetDirectory().Clear();
-                                reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
-                            }
-                        }
-                        symbol_load_addr = GetSymbolAddress(target, process, sym_ctx.symbol->GetReExportedSymbolName(), symbol_type, reexport_module_sp.get());
-                    }
-                }
-                break;
+  if (!context.m_found.variable && !context.m_found.local_vars_nsp)
+    ClangASTSource::FindExternalVisibleDecls(context);
+}
 
-            case eSymbolTypeData:
-            case eSymbolTypeRuntime:
-            case eSymbolTypeVariable:
-            case eSymbolTypeLocal:
-            case eSymbolTypeParam:
-            case eSymbolTypeInvalid:
-            case eSymbolTypeAbsolute:
-            case eSymbolTypeException:
-            case eSymbolTypeSourceFile:
-            case eSymbolTypeHeaderFile:
-            case eSymbolTypeObjectFile:
-            case eSymbolTypeCommonBlock:
-            case eSymbolTypeBlock:
-            case eSymbolTypeVariableType:
-            case eSymbolTypeLineEntry:
-            case eSymbolTypeLineHeader:
-            case eSymbolTypeScopeBegin:
-            case eSymbolTypeScopeEnd:
-            case eSymbolTypeAdditional:
-            case eSymbolTypeCompiler:
-            case eSymbolTypeInstrumentation:
-            case eSymbolTypeUndefined:
-            case eSymbolTypeObjCClass:
-            case eSymbolTypeObjCMetaClass:
-            case eSymbolTypeObjCIVar:
-                symbol_load_addr = sym_address.GetLoadAddress (&target);
-                break;
-        }
-    }
+void ClangExpressionDeclMap::FindExternalVisibleDecls(
+    NameSearchContext &context, lldb::ModuleSP module_sp,
+    CompilerDeclContext &namespace_decl, unsigned int current_id) {
+  assert(m_ast_context);
 
-    if (symbol_load_addr == LLDB_INVALID_ADDRESS && process)
-    {
-        ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
-
-        if (runtime)
-        {
-            symbol_load_addr = runtime->LookupRuntimeSymbol(name);
+  std::function<void(clang::FunctionDecl *)> MaybeRegisterFunctionBody =
+      [this](clang::FunctionDecl *copied_function_decl) {
+        if (copied_function_decl->getBody() && m_parser_vars->m_code_gen) {
+          DeclGroupRef decl_group_ref(copied_function_decl);
+          m_parser_vars->m_code_gen->HandleTopLevelDecl(decl_group_ref);
         }
-    }
+      };
 
-    return symbol_load_addr;
-}
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-addr_t
-ClangExpressionDeclMap::GetSymbolAddress (const ConstString &name, lldb::SymbolType symbol_type)
-{
-    assert (m_parser_vars.get());
+  SymbolContextList sc_list;
 
-    if (!m_parser_vars->m_exe_ctx.GetTargetPtr())
-        return false;
+  const ConstString name(context.m_decl_name.getAsString().c_str());
 
-    return GetSymbolAddress(m_parser_vars->m_exe_ctx.GetTargetRef(), m_parser_vars->m_exe_ctx.GetProcessPtr(), name, symbol_type);
-}
+  const char *name_unique_cstr = name.GetCString();
 
-const Symbol *
-ClangExpressionDeclMap::FindGlobalDataSymbol (Target &target,
-                                              const ConstString &name,
-                                              lldb_private::Module *module)
-{
-    SymbolContextList sc_list;
+  if (name_unique_cstr == NULL)
+    return;
 
-    if (module)
-        module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
-    else
-        target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
+  static ConstString id_name("id");
+  static ConstString Class_name("Class");
 
-    const uint32_t matches = sc_list.GetSize();
-    for (uint32_t i=0; i<matches; ++i)
-    {
-        SymbolContext sym_ctx;
-        sc_list.GetContextAtIndex(i, sym_ctx);
-        if (sym_ctx.symbol)
-        {
-            const Symbol *symbol = sym_ctx.symbol;
-            const Address sym_address = symbol->GetAddress();
-
-            if (sym_address.IsValid())
-            {
-                switch (symbol->GetType())
-                {
-                    case eSymbolTypeData:
-                    case eSymbolTypeRuntime:
-                    case eSymbolTypeAbsolute:
-                    case eSymbolTypeObjCClass:
-                    case eSymbolTypeObjCMetaClass:
-                    case eSymbolTypeObjCIVar:
-                        if (symbol->GetDemangledNameIsSynthesized())
-                        {
-                            // If the demangled name was synthesized, then don't use it
-                            // for expressions. Only let the symbol match if the mangled
-                            // named matches for these symbols.
-                            if (symbol->GetMangled().GetMangledName() != name)
-                                break;
-                        }
-                        return symbol;
-
-                    case eSymbolTypeReExported:
-                        {
-                            ConstString reexport_name = symbol->GetReExportedSymbolName();
-                            if (reexport_name)
-                            {
-                                ModuleSP reexport_module_sp;
-                                ModuleSpec reexport_module_spec;
-                                reexport_module_spec.GetPlatformFileSpec() = symbol->GetReExportedSymbolSharedLibrary();
-                                if (reexport_module_spec.GetPlatformFileSpec())
-                                {
-                                    reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
-                                    if (!reexport_module_sp)
-                                    {
-                                        reexport_module_spec.GetPlatformFileSpec().GetDirectory().Clear();
-                                        reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
-                                    }
-                                }
-                                // Don't allow us to try and resolve a re-exported symbol if it is the same
-                                // as the current symbol
-                                if (name == symbol->GetReExportedSymbolName() && module == reexport_module_sp.get())
-                                    return NULL;
-
-                                return FindGlobalDataSymbol(target, symbol->GetReExportedSymbolName(), reexport_module_sp.get());
-                            }
-                        }
-                        break;
-
-                    case eSymbolTypeCode: // We already lookup functions elsewhere
-                    case eSymbolTypeVariable:
-                    case eSymbolTypeLocal:
-                    case eSymbolTypeParam:
-                    case eSymbolTypeTrampoline:
-                    case eSymbolTypeInvalid:
-                    case eSymbolTypeException:
-                    case eSymbolTypeSourceFile:
-                    case eSymbolTypeHeaderFile:
-                    case eSymbolTypeObjectFile:
-                    case eSymbolTypeCommonBlock:
-                    case eSymbolTypeBlock:
-                    case eSymbolTypeVariableType:
-                    case eSymbolTypeLineEntry:
-                    case eSymbolTypeLineHeader:
-                    case eSymbolTypeScopeBegin:
-                    case eSymbolTypeScopeEnd:
-                    case eSymbolTypeAdditional:
-                    case eSymbolTypeCompiler:
-                    case eSymbolTypeInstrumentation:
-                    case eSymbolTypeUndefined:
-                    case eSymbolTypeResolver:
-                        break;
-                }
-            }
-        }
-    }
+  if (name == id_name || name == Class_name)
+    return;
 
-    return NULL;
-}
+  // Only look for functions by name out in our symbols if the function
+  // doesn't start with our phony prefix of '$'
+  Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+  StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
+  SymbolContext sym_ctx;
+  if (frame != nullptr)
+    sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
+                                      lldb::eSymbolContextBlock);
 
-lldb::VariableSP
-ClangExpressionDeclMap::FindGlobalVariable
-(
-    Target &target,
-    ModuleSP &module,
-    const ConstString &name,
-    CompilerDeclContext *namespace_decl,
-    TypeFromUser *type
-)
-{
-    VariableList vars;
+  // Try the persistent decls, which take precedence over all else.
+  if (!namespace_decl) {
+    do {
+      if (!target)
+        break;
 
-    if (module && namespace_decl)
-        module->FindGlobalVariables (name, namespace_decl, true, -1, vars);
-    else
-        target.GetImages().FindGlobalVariables(name, true, -1, vars);
+      ClangASTContext *scratch_clang_ast_context =
+          target->GetScratchClangASTContext();
 
-    if (vars.GetSize())
-    {
-        if (type)
-        {
-            for (size_t i = 0; i < vars.GetSize(); ++i)
-            {
-                VariableSP var_sp = vars.GetVariableAtIndex(i);
+      if (!scratch_clang_ast_context)
+        break;
 
-                if (ClangASTContext::AreTypesSame(*type, var_sp->GetType()->GetFullCompilerType ()))
-                    return var_sp;
-            }
-        }
-        else
-        {
-            return vars.GetVariableAtIndex(0);
-        }
-    }
+      ASTContext *scratch_ast_context =
+          scratch_clang_ast_context->getASTContext();
 
-    return VariableSP();
-}
+      if (!scratch_ast_context)
+        break;
 
-ClangASTContext *
-ClangExpressionDeclMap::GetClangASTContext ()
-{
-    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
-    if (frame == nullptr)
-        return nullptr;
+      NamedDecl *persistent_decl =
+          m_parser_vars->m_persistent_vars->GetPersistentDecl(name);
 
-    SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction|lldb::eSymbolContextBlock);
-    if (sym_ctx.block == nullptr)
-        return nullptr;
+      if (!persistent_decl)
+        break;
 
-    CompilerDeclContext frame_decl_context = sym_ctx.block->GetDeclContext();
-    if (!frame_decl_context)
-        return nullptr;
+      Decl *parser_persistent_decl = m_ast_importer_sp->CopyDecl(
+          m_ast_context, scratch_ast_context, persistent_decl);
 
-    return llvm::dyn_cast_or_null<ClangASTContext>(frame_decl_context.GetTypeSystem());
-}
+      if (!parser_persistent_decl)
+        break;
 
-// Interface for ClangASTSource
+      NamedDecl *parser_named_decl =
+          dyn_cast<NamedDecl>(parser_persistent_decl);
+
+      if (!parser_named_decl)
+        break;
 
-void
-ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context)
-{
-    assert (m_ast_context);
+      if (clang::FunctionDecl *parser_function_decl =
+              llvm::dyn_cast<clang::FunctionDecl>(parser_named_decl)) {
+        MaybeRegisterFunctionBody(parser_function_decl);
+      }
 
-    ClangASTMetrics::RegisterVisibleQuery();
+      if (log)
+        log->Printf("  CEDM::FEVD[%u] Found persistent decl %s", current_id,
+                    name.GetCString());
 
-    const ConstString name(context.m_decl_name.getAsString().c_str());
+      context.AddNamedDecl(parser_named_decl);
+    } while (0);
+  }
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  if (name_unique_cstr[0] == '$' && !namespace_decl) {
+    static ConstString g_lldb_class_name("$__lldb_class");
 
-    if (GetImportInProgress())
-    {
-        if (log && log->GetVerbose())
-            log->Printf("Ignoring a query during an import");
+    if (name == g_lldb_class_name) {
+      // Clang is looking for the type of "this"
+
+      if (frame == NULL)
         return;
-    }
 
-    static unsigned int invocation_id = 0;
-    unsigned int current_id = invocation_id++;
+      // Find the block that defines the function represented by "sym_ctx"
+      Block *function_block = sym_ctx.GetFunctionBlock();
 
-    if (log)
-    {
-        if (!context.m_decl_context)
-            log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for '%s' in a NULL DeclContext", current_id, name.GetCString());
-        else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
-            log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for '%s' in '%s'", current_id, name.GetCString(), context_named_decl->getNameAsString().c_str());
-        else
-            log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for '%s' in a '%s'", current_id, name.GetCString(), context.m_decl_context->getDeclKindName());
-    }
+      if (!function_block)
+        return;
 
-    if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
-    {
-        if (namespace_context->getName().str() == std::string(g_lldb_local_vars_namespace_cstr))
-        {
-            CompilerDeclContext compiler_decl_ctx(GetClangASTContext(), const_cast<void *>(static_cast<const void *>(context.m_decl_context)));
-            FindExternalVisibleDecls(context, lldb::ModuleSP(), compiler_decl_ctx, current_id);
-            return;
-        }
+      CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
 
-        ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer_sp->GetNamespaceMap(namespace_context);
+      if (!function_decl_ctx)
+        return;
 
-        if (log && log->GetVerbose())
-            log->Printf("  CEDM::FEVD[%u] Inspecting (NamespaceMap*)%p (%d entries)",
-                        current_id, static_cast<void*>(namespace_map.get()),
-                        (int)namespace_map->size());
+      clang::CXXMethodDecl *method_decl =
+          ClangASTContext::DeclContextGetAsCXXMethodDecl(function_decl_ctx);
 
-        if (!namespace_map)
-            return;
+      if (method_decl) {
+        clang::CXXRecordDecl *class_decl = method_decl->getParent();
 
-        for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
-             i != e;
-             ++i)
-        {
-            if (log)
-                log->Printf("  CEDM::FEVD[%u] Searching namespace %s in module %s",
-                            current_id,
-                            i->second.GetName().AsCString(),
-                            i->first->GetFileSpec().GetFilename().GetCString());
-
-            FindExternalVisibleDecls(context,
-                                     i->first,
-                                     i->second,
-                                     current_id);
-        }
-    }
-    else if (isa<TranslationUnitDecl>(context.m_decl_context))
-    {
-        CompilerDeclContext namespace_decl;
+        QualType class_qual_type(class_decl->getTypeForDecl(), 0);
 
-        if (log)
-            log->Printf("  CEDM::FEVD[%u] Searching the root namespace", current_id);
+        TypeFromUser class_user_type(
+            class_qual_type.getAsOpaquePtr(),
+            ClangASTContext::GetASTContext(&class_decl->getASTContext()));
 
-        FindExternalVisibleDecls(context,
-                                 lldb::ModuleSP(),
-                                 namespace_decl,
-                                 current_id);
-    }
-
-    if (!context.m_found.variable && !context.m_found.local_vars_nsp)
-        ClangASTSource::FindExternalVisibleDecls(context);
-}
-
-void
-ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
-                                                  lldb::ModuleSP module_sp,
-                                                  CompilerDeclContext &namespace_decl,
-                                                  unsigned int current_id)
-{
-    assert (m_ast_context);
-    
-    std::function<void (clang::FunctionDecl *)> MaybeRegisterFunctionBody =
-    [this](clang::FunctionDecl *copied_function_decl)
-    {
-        if (copied_function_decl->getBody() && m_parser_vars->m_code_gen)
-        {
-            DeclGroupRef decl_group_ref(copied_function_decl);
-            m_parser_vars->m_code_gen->HandleTopLevelDecl(decl_group_ref);
+        if (log) {
+          ASTDumper ast_dumper(class_qual_type);
+          log->Printf("  CEDM::FEVD[%u] Adding type for $__lldb_class: %s",
+                      current_id, ast_dumper.GetCString());
         }
-    };
 
+        AddThisType(context, class_user_type, current_id);
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+        if (method_decl->isInstance()) {
+          // self is a pointer to the object
 
-    SymbolContextList sc_list;
+          QualType class_pointer_type =
+              method_decl->getASTContext().getPointerType(class_qual_type);
 
-    const ConstString name(context.m_decl_name.getAsString().c_str());
+          TypeFromUser self_user_type(
+              class_pointer_type.getAsOpaquePtr(),
+              ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
-    const char *name_unique_cstr = name.GetCString();
+          m_struct_vars->m_object_pointer_type = self_user_type;
+        }
+      } else {
+        // This branch will get hit if we are executing code in the context of a
+        // function that
+        // claims to have an object pointer (through DW_AT_object_pointer?) but
+        // is not formally a
+        // method of the class.  In that case, just look up the "this" variable
+        // in the current
+        // scope and use its type.
+        // FIXME: This code is formally correct, but clang doesn't currently
+        // emit DW_AT_object_pointer
+        // for C++ so it hasn't actually been tested.
 
-    if (name_unique_cstr == NULL)
-        return;
+        VariableList *vars = frame->GetVariableList(false);
 
-    static ConstString id_name("id");
-    static ConstString Class_name("Class");
+        lldb::VariableSP this_var = vars->FindVariable(ConstString("this"));
 
-    if (name == id_name || name == Class_name)
-        return;
+        if (this_var && this_var->IsInScope(frame) &&
+            this_var->LocationIsValidForFrame(frame)) {
+          Type *this_type = this_var->GetType();
 
-    // Only look for functions by name out in our symbols if the function
-    // doesn't start with our phony prefix of '$'
-    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
-    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
-    SymbolContext sym_ctx;
-    if (frame != nullptr)
-        sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction|lldb::eSymbolContextBlock);
-    
-    // Try the persistent decls, which take precedence over all else.
-    if (!namespace_decl)
-    {
-        do
-        {
-            if (!target)
-                break;
-            
-            ClangASTContext *scratch_clang_ast_context = target->GetScratchClangASTContext();
-            
-            if (!scratch_clang_ast_context)
-                break;
-            
-            ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext();
-            
-            if (!scratch_ast_context)
-                break;
-            
-            NamedDecl *persistent_decl = m_parser_vars->m_persistent_vars->GetPersistentDecl(name);
-            
-            if (!persistent_decl)
-                break;
-            
-            Decl *parser_persistent_decl = m_ast_importer_sp->CopyDecl(m_ast_context, scratch_ast_context, persistent_decl);
-            
-            if (!parser_persistent_decl)
-                break;
-            
-            NamedDecl *parser_named_decl = dyn_cast<NamedDecl>(parser_persistent_decl);
-            
-            if (!parser_named_decl)
-                break;
-            
-            if (clang::FunctionDecl *parser_function_decl = llvm::dyn_cast<clang::FunctionDecl>(parser_named_decl))
-            {
-                MaybeRegisterFunctionBody(parser_function_decl);
+          if (!this_type)
+            return;
+
+          TypeFromUser pointee_type =
+              this_type->GetForwardCompilerType().GetPointeeType();
+
+          if (pointee_type.IsValid()) {
+            if (log) {
+              ASTDumper ast_dumper(pointee_type);
+              log->Printf("  FEVD[%u] Adding type for $__lldb_class: %s",
+                          current_id, ast_dumper.GetCString());
             }
-            
-            if (log)
-                log->Printf("  CEDM::FEVD[%u] Found persistent decl %s", current_id, name.GetCString());
-            
-            context.AddNamedDecl(parser_named_decl);
-        } while (0);
+
+            AddThisType(context, pointee_type, current_id);
+            TypeFromUser this_user_type(this_type->GetFullCompilerType());
+            m_struct_vars->m_object_pointer_type = this_user_type;
+            return;
+          }
+        }
+      }
+
+      return;
     }
-    
-    if (name_unique_cstr[0] == '$' && !namespace_decl)
-    {
-        static ConstString g_lldb_class_name ("$__lldb_class");
 
-        if (name == g_lldb_class_name)
-        {
-            // Clang is looking for the type of "this"
+    static ConstString g_lldb_objc_class_name("$__lldb_objc_class");
+    if (name == g_lldb_objc_class_name) {
+      // Clang is looking for the type of "*self"
 
-            if (frame == NULL)
-                return;
+      if (!frame)
+        return;
 
+      SymbolContext sym_ctx = frame->GetSymbolContext(
+          lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
 
-            // Find the block that defines the function represented by "sym_ctx"
-            Block *function_block = sym_ctx.GetFunctionBlock();
+      // Find the block that defines the function represented by "sym_ctx"
+      Block *function_block = sym_ctx.GetFunctionBlock();
 
-            if (!function_block)
-                return;
+      if (!function_block)
+        return;
 
-            CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
+      CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
 
-            if (!function_decl_ctx)
-                return;
+      if (!function_decl_ctx)
+        return;
 
-            clang::CXXMethodDecl *method_decl = ClangASTContext::DeclContextGetAsCXXMethodDecl(function_decl_ctx);
+      clang::ObjCMethodDecl *method_decl =
+          ClangASTContext::DeclContextGetAsObjCMethodDecl(function_decl_ctx);
 
-            if (method_decl)
-            {
-                clang::CXXRecordDecl *class_decl = method_decl->getParent();
+      if (method_decl) {
+        ObjCInterfaceDecl *self_interface = method_decl->getClassInterface();
 
-                QualType class_qual_type(class_decl->getTypeForDecl(), 0);
+        if (!self_interface)
+          return;
 
-                TypeFromUser class_user_type (class_qual_type.getAsOpaquePtr(),
-                                              ClangASTContext::GetASTContext(&class_decl->getASTContext()));
+        const clang::Type *interface_type = self_interface->getTypeForDecl();
 
-                if (log)
-                {
-                    ASTDumper ast_dumper(class_qual_type);
-                    log->Printf("  CEDM::FEVD[%u] Adding type for $__lldb_class: %s", current_id, ast_dumper.GetCString());
-                }
+        if (!interface_type)
+          return; // This is unlikely, but we have seen crashes where this
+                  // occurred
+
+        TypeFromUser class_user_type(
+            QualType(interface_type, 0).getAsOpaquePtr(),
+            ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
-                AddThisType(context, class_user_type, current_id);
+        if (log) {
+          ASTDumper ast_dumper(interface_type);
+          log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s",
+                      current_id, ast_dumper.GetCString());
+        }
 
-                if (method_decl->isInstance())
-                {
-                    // self is a pointer to the object
+        AddOneType(context, class_user_type, current_id);
 
-                    QualType class_pointer_type = method_decl->getASTContext().getPointerType(class_qual_type);
+        if (method_decl->isInstanceMethod()) {
+          // self is a pointer to the object
 
-                    TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-                                                ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+          QualType class_pointer_type =
+              method_decl->getASTContext().getObjCObjectPointerType(
+                  QualType(interface_type, 0));
 
-                    m_struct_vars->m_object_pointer_type = self_user_type;
-                }
-            }
-            else
-            {
-                // This branch will get hit if we are executing code in the context of a function that
-                // claims to have an object pointer (through DW_AT_object_pointer?) but is not formally a
-                // method of the class.  In that case, just look up the "this" variable in the current
-                // scope and use its type.
-                // FIXME: This code is formally correct, but clang doesn't currently emit DW_AT_object_pointer
-                // for C++ so it hasn't actually been tested.
-
-                VariableList *vars = frame->GetVariableList(false);
-
-                lldb::VariableSP this_var = vars->FindVariable(ConstString("this"));
-
-                if (this_var &&
-                    this_var->IsInScope(frame) &&
-                    this_var->LocationIsValidForFrame (frame))
-                {
-                    Type *this_type = this_var->GetType();
-
-                    if (!this_type)
-                        return;
-
-                    TypeFromUser pointee_type = this_type->GetForwardCompilerType ().GetPointeeType();
-
-                    if (pointee_type.IsValid())
-                    {
-                        if (log)
-                        {
-                            ASTDumper ast_dumper(pointee_type);
-                            log->Printf("  FEVD[%u] Adding type for $__lldb_class: %s", current_id, ast_dumper.GetCString());
-                        }
-                        
-                        AddThisType(context, pointee_type, current_id);
-                        TypeFromUser this_user_type(this_type->GetFullCompilerType ());
-                        m_struct_vars->m_object_pointer_type = this_user_type;
-                        return;
-                    }
-                }
-            }
+          TypeFromUser self_user_type(
+              class_pointer_type.getAsOpaquePtr(),
+              ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
-            return;
+          m_struct_vars->m_object_pointer_type = self_user_type;
+        } else {
+          // self is a Class pointer
+          QualType class_type = method_decl->getASTContext().getObjCClassType();
+
+          TypeFromUser self_user_type(
+              class_type.getAsOpaquePtr(),
+              ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+
+          m_struct_vars->m_object_pointer_type = self_user_type;
         }
 
-        static ConstString g_lldb_objc_class_name ("$__lldb_objc_class");
-        if (name == g_lldb_objc_class_name)
-        {
-            // Clang is looking for the type of "*self"
+        return;
+      } else {
+        // This branch will get hit if we are executing code in the context of a
+        // function that
+        // claims to have an object pointer (through DW_AT_object_pointer?) but
+        // is not formally a
+        // method of the class.  In that case, just look up the "self" variable
+        // in the current
+        // scope and use its type.
+
+        VariableList *vars = frame->GetVariableList(false);
+
+        lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
+
+        if (self_var && self_var->IsInScope(frame) &&
+            self_var->LocationIsValidForFrame(frame)) {
+          Type *self_type = self_var->GetType();
 
-            if (!frame)
-                return;
+          if (!self_type)
+            return;
 
-            SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction|lldb::eSymbolContextBlock);
+          CompilerType self_clang_type = self_type->GetFullCompilerType();
 
-            // Find the block that defines the function represented by "sym_ctx"
-            Block *function_block = sym_ctx.GetFunctionBlock();
+          if (ClangASTContext::IsObjCClassType(self_clang_type)) {
+            return;
+          } else if (ClangASTContext::IsObjCObjectPointerType(
+                         self_clang_type)) {
+            self_clang_type = self_clang_type.GetPointeeType();
 
-            if (!function_block)
-                return;
+            if (!self_clang_type)
+              return;
 
-            CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
+            if (log) {
+              ASTDumper ast_dumper(self_type->GetFullCompilerType());
+              log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s",
+                          current_id, ast_dumper.GetCString());
+            }
 
-            if (!function_decl_ctx)
-                return;
+            TypeFromUser class_user_type(self_clang_type);
 
-            clang::ObjCMethodDecl *method_decl = ClangASTContext::DeclContextGetAsObjCMethodDecl(function_decl_ctx);
+            AddOneType(context, class_user_type, current_id);
 
-            if (method_decl)
-            {
-                ObjCInterfaceDecl* self_interface = method_decl->getClassInterface();
+            TypeFromUser self_user_type(self_type->GetFullCompilerType());
 
-                if (!self_interface)
-                    return;
+            m_struct_vars->m_object_pointer_type = self_user_type;
+            return;
+          }
+        }
+      }
 
-                const clang::Type *interface_type = self_interface->getTypeForDecl();
+      return;
+    }
 
-                if (!interface_type)
-                    return; // This is unlikely, but we have seen crashes where this occurred
+    if (name == ConstString(g_lldb_local_vars_namespace_cstr)) {
+      CompilerDeclContext frame_decl_context =
+          sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext()
+                                   : CompilerDeclContext();
 
-                TypeFromUser class_user_type(QualType(interface_type, 0).getAsOpaquePtr(),
-                                             ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+      if (frame_decl_context) {
+        ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(
+            frame_decl_context.GetTypeSystem());
 
-                if (log)
-                {
-                    ASTDumper ast_dumper(interface_type);
-                    log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s", current_id, ast_dumper.GetCString());
-                }
+        if (ast) {
+          clang::NamespaceDecl *namespace_decl =
+              ClangASTContext::GetUniqueNamespaceDeclaration(
+                  m_ast_context, name_unique_cstr, nullptr);
+          if (namespace_decl) {
+            context.AddNamedDecl(namespace_decl);
+            clang::DeclContext *clang_decl_ctx =
+                clang::Decl::castToDeclContext(namespace_decl);
+            clang_decl_ctx->setHasExternalVisibleStorage(true);
+            context.m_found.local_vars_nsp = true;
+          }
+        }
+      }
 
-                AddOneType(context, class_user_type, current_id);
+      return;
+    }
 
-                if (method_decl->isInstanceMethod())
-                {
-                    // self is a pointer to the object
+    // any other $__lldb names should be weeded out now
+    if (!::strncmp(name_unique_cstr, "$__lldb", sizeof("$__lldb") - 1))
+      return;
 
-                    QualType class_pointer_type = method_decl->getASTContext().getObjCObjectPointerType(QualType(interface_type, 0));
+    ExpressionVariableSP pvar_sp(
+        m_parser_vars->m_persistent_vars->GetVariable(name));
 
-                    TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-                                                ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+    if (pvar_sp) {
+      AddOneVariable(context, pvar_sp, current_id);
+      return;
+    }
 
-                    m_struct_vars->m_object_pointer_type = self_user_type;
-                }
-                else
-                {
-                    // self is a Class pointer
-                    QualType class_type = method_decl->getASTContext().getObjCClassType();
+    const char *reg_name(&name.GetCString()[1]);
 
-                    TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
-                                                ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+    if (m_parser_vars->m_exe_ctx.GetRegisterContext()) {
+      const RegisterInfo *reg_info(
+          m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(
+              reg_name));
 
-                    m_struct_vars->m_object_pointer_type = self_user_type;
-                }
+      if (reg_info) {
+        if (log)
+          log->Printf("  CEDM::FEVD[%u] Found register %s", current_id,
+                      reg_info->name);
 
-                return;
-            }
-            else
-            {
-                // This branch will get hit if we are executing code in the context of a function that
-                // claims to have an object pointer (through DW_AT_object_pointer?) but is not formally a
-                // method of the class.  In that case, just look up the "self" variable in the current
-                // scope and use its type.
-
-                VariableList *vars = frame->GetVariableList(false);
-
-                lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
-
-                if (self_var &&
-                    self_var->IsInScope(frame) &&
-                    self_var->LocationIsValidForFrame (frame))
-                {
-                    Type *self_type = self_var->GetType();
-
-                    if (!self_type)
-                        return;
-
-                    CompilerType self_clang_type = self_type->GetFullCompilerType ();
-
-                    if (ClangASTContext::IsObjCClassType(self_clang_type))
-                    {
-                        return;
-                    }
-                    else if (ClangASTContext::IsObjCObjectPointerType(self_clang_type))
-                    {
-                        self_clang_type = self_clang_type.GetPointeeType();
-
-                        if (!self_clang_type)
-                            return;
-
-                        if (log)
-                        {
-                            ASTDumper ast_dumper(self_type->GetFullCompilerType ());
-                            log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s", current_id, ast_dumper.GetCString());
-                        }
-
-                        TypeFromUser class_user_type (self_clang_type);
-
-                        AddOneType(context, class_user_type, current_id);
-
-                        TypeFromUser self_user_type(self_type->GetFullCompilerType ());
-
-                        m_struct_vars->m_object_pointer_type = self_user_type;
-                        return;
-                    }
-                }
-            }
+        AddOneRegister(context, reg_info, current_id);
+      }
+    }
+  } else {
+    ValueObjectSP valobj;
+    VariableSP var;
+
+    bool local_var_lookup =
+        !namespace_decl || (namespace_decl.GetName() ==
+                            ConstString(g_lldb_local_vars_namespace_cstr));
+    if (frame && local_var_lookup) {
+      CompilerDeclContext compiler_decl_context =
+          sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext()
+                                   : CompilerDeclContext();
+
+      if (compiler_decl_context) {
+        // Make sure that the variables are parsed so that we have the
+        // declarations.
+        VariableListSP vars = frame->GetInScopeVariableList(true);
+        for (size_t i = 0; i < vars->GetSize(); i++)
+          vars->GetVariableAtIndex(i)->GetDecl();
+
+        // Search for declarations matching the name. Do not include imported
+        // decls
+        // in the search if we are looking for decls in the artificial namespace
+        // $__lldb_local_vars.
+        std::vector<CompilerDecl> found_decls =
+            compiler_decl_context.FindDeclByName(name,
+                                                 namespace_decl.IsValid());
+
+        bool variable_found = false;
+        for (CompilerDecl decl : found_decls) {
+          for (size_t vi = 0, ve = vars->GetSize(); vi != ve; ++vi) {
+            VariableSP candidate_var = vars->GetVariableAtIndex(vi);
+            if (candidate_var->GetDecl() == decl) {
+              var = candidate_var;
+              break;
+            }
+          }
+
+          if (var) {
+            variable_found = true;
+            valobj = ValueObjectVariable::Create(frame, var);
+            AddOneVariable(context, var, valobj, current_id);
+            context.m_found.variable = true;
+          }
+        }
+        if (variable_found)
+          return;
+      }
+    }
+    if (target) {
+      var = FindGlobalVariable(*target, module_sp, name, &namespace_decl, NULL);
+
+      if (var) {
+        valobj = ValueObjectVariable::Create(target, var);
+        AddOneVariable(context, var, valobj, current_id);
+        context.m_found.variable = true;
+        return;
+      }
+    }
 
-            return;
-        }
+    std::vector<clang::NamedDecl *> decls_from_modules;
 
-        if (name == ConstString(g_lldb_local_vars_namespace_cstr))
-        {
-            CompilerDeclContext frame_decl_context = sym_ctx.block != nullptr ?
-                                                     sym_ctx.block->GetDeclContext() :
-                                                     CompilerDeclContext();
-
-            if (frame_decl_context)
-            {
-                ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(frame_decl_context.GetTypeSystem());
-
-                if (ast)
-                {
-                    clang::NamespaceDecl *namespace_decl = ClangASTContext::GetUniqueNamespaceDeclaration(
-                        m_ast_context, name_unique_cstr, nullptr);
-                    if (namespace_decl)
-                    {
-                        context.AddNamedDecl(namespace_decl);
-                        clang::DeclContext *clang_decl_ctx = clang::Decl::castToDeclContext(namespace_decl);
-                        clang_decl_ctx->setHasExternalVisibleStorage(true);
-                        context.m_found.local_vars_nsp = true;
-                    }
-                }
+    if (target) {
+      if (ClangModulesDeclVendor *decl_vendor =
+              target->GetClangModulesDeclVendor()) {
+        decl_vendor->FindDecls(name, false, UINT32_MAX, decls_from_modules);
+      }
+    }
+
+    if (!context.m_found.variable) {
+      const bool include_inlines = false;
+      const bool append = false;
+
+      if (namespace_decl && module_sp) {
+        const bool include_symbols = false;
+
+        module_sp->FindFunctions(name, &namespace_decl, eFunctionNameTypeBase,
+                                 include_symbols, include_inlines, append,
+                                 sc_list);
+      } else if (target && !namespace_decl) {
+        const bool include_symbols = true;
+
+        // TODO Fix FindFunctions so that it doesn't return
+        //   instance methods for eFunctionNameTypeBase.
+
+        target->GetImages().FindFunctions(name, eFunctionNameTypeFull,
+                                          include_symbols, include_inlines,
+                                          append, sc_list);
+      }
+
+      // If we found more than one function, see if we can use the
+      // frame's decl context to remove functions that are shadowed
+      // by other functions which match in type but are nearer in scope.
+      //
+      // AddOneFunction will not add a function whose type has already been
+      // added, so if there's another function in the list with a matching
+      // type, check to see if their decl context is a parent of the current
+      // frame's or was imported via a and using statement, and pick the
+      // best match according to lookup rules.
+      if (sc_list.GetSize() > 1) {
+        // Collect some info about our frame's context.
+        StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
+        SymbolContext frame_sym_ctx;
+        if (frame != nullptr)
+          frame_sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
+                                                  lldb::eSymbolContextBlock);
+        CompilerDeclContext frame_decl_context =
+            frame_sym_ctx.block != nullptr
+                ? frame_sym_ctx.block->GetDeclContext()
+                : CompilerDeclContext();
+
+        // We can't do this without a compiler decl context for our frame.
+        if (frame_decl_context) {
+          clang::DeclContext *frame_decl_ctx =
+              (clang::DeclContext *)frame_decl_context.GetOpaqueDeclContext();
+          ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(
+              frame_decl_context.GetTypeSystem());
+
+          // Structure to hold the info needed when comparing function
+          // declarations.
+          struct FuncDeclInfo {
+            ConstString m_name;
+            CompilerType m_copied_type;
+            uint32_t m_decl_lvl;
+            SymbolContext m_sym_ctx;
+          };
+
+          // First, symplify things by looping through the symbol contexts
+          // to remove unwanted functions and separate out the functions we
+          // want to compare and prune into a separate list.
+          // Cache the info needed about the function declarations in a
+          // vector for efficiency.
+          SymbolContextList sc_sym_list;
+          uint32_t num_indices = sc_list.GetSize();
+          std::vector<FuncDeclInfo> fdi_cache;
+          fdi_cache.reserve(num_indices);
+          for (uint32_t index = 0; index < num_indices; ++index) {
+            FuncDeclInfo fdi;
+            SymbolContext sym_ctx;
+            sc_list.GetContextAtIndex(index, sym_ctx);
+
+            // We don't know enough about symbols to compare them,
+            // but we should keep them in the list.
+            Function *function = sym_ctx.function;
+            if (!function) {
+              sc_sym_list.Append(sym_ctx);
+              continue;
+            }
+            // Filter out functions without declaration contexts, as well as
+            // class/instance methods, since they'll be skipped in the
+            // code that follows anyway.
+            CompilerDeclContext func_decl_context = function->GetDeclContext();
+            if (!func_decl_context ||
+                func_decl_context.IsClassMethod(nullptr, nullptr, nullptr))
+              continue;
+            // We can only prune functions for which we can copy the type.
+            CompilerType func_clang_type =
+                function->GetType()->GetFullCompilerType();
+            CompilerType copied_func_type = GuardedCopyType(func_clang_type);
+            if (!copied_func_type) {
+              sc_sym_list.Append(sym_ctx);
+              continue;
+            }
+
+            fdi.m_sym_ctx = sym_ctx;
+            fdi.m_name = function->GetName();
+            fdi.m_copied_type = copied_func_type;
+            fdi.m_decl_lvl = LLDB_INVALID_DECL_LEVEL;
+            if (fdi.m_copied_type && func_decl_context) {
+              // Call CountDeclLevels to get the number of parent scopes we
+              // have to look through before we find the function declaration.
+              // When comparing functions of the same type, the one with a
+              // lower count will be closer to us in the lookup scope and
+              // shadows the other.
+              clang::DeclContext *func_decl_ctx =
+                  (clang::DeclContext *)
+                      func_decl_context.GetOpaqueDeclContext();
+              fdi.m_decl_lvl =
+                  ast->CountDeclLevels(frame_decl_ctx, func_decl_ctx,
+                                       &fdi.m_name, &fdi.m_copied_type);
+            }
+            fdi_cache.emplace_back(fdi);
+          }
+
+          // Loop through the functions in our cache looking for matching types,
+          // then compare their scope levels to see which is closer.
+          std::multimap<CompilerType, const FuncDeclInfo *> matches;
+          for (const FuncDeclInfo &fdi : fdi_cache) {
+            const CompilerType t = fdi.m_copied_type;
+            auto q = matches.find(t);
+            if (q != matches.end()) {
+              if (q->second->m_decl_lvl > fdi.m_decl_lvl)
+                // This function is closer; remove the old set.
+                matches.erase(t);
+              else if (q->second->m_decl_lvl < fdi.m_decl_lvl)
+                // The functions in our set are closer - skip this one.
+                continue;
+            }
+            matches.insert(std::make_pair(t, &fdi));
+          }
+
+          // Loop through our matches and add their symbol contexts to our list.
+          SymbolContextList sc_func_list;
+          for (const auto &q : matches)
+            sc_func_list.Append(q.second->m_sym_ctx);
+
+          // Rejoin the lists with the functions in front.
+          sc_list = sc_func_list;
+          sc_list.Append(sc_sym_list);
+        }
+      }
+
+      if (sc_list.GetSize()) {
+        Symbol *extern_symbol = NULL;
+        Symbol *non_extern_symbol = NULL;
+
+        for (uint32_t index = 0, num_indices = sc_list.GetSize();
+             index < num_indices; ++index) {
+          SymbolContext sym_ctx;
+          sc_list.GetContextAtIndex(index, sym_ctx);
+
+          if (sym_ctx.function) {
+            CompilerDeclContext decl_ctx = sym_ctx.function->GetDeclContext();
+
+            if (!decl_ctx)
+              continue;
+
+            // Filter out class/instance methods.
+            if (decl_ctx.IsClassMethod(nullptr, nullptr, nullptr))
+              continue;
+
+            AddOneFunction(context, sym_ctx.function, NULL, current_id);
+            context.m_found.function_with_type_info = true;
+            context.m_found.function = true;
+          } else if (sym_ctx.symbol) {
+            if (sym_ctx.symbol->GetType() == eSymbolTypeReExported && target) {
+              sym_ctx.symbol = sym_ctx.symbol->ResolveReExportedSymbol(*target);
+              if (sym_ctx.symbol == NULL)
+                continue;
             }
 
-            return;
+            if (sym_ctx.symbol->IsExternal())
+              extern_symbol = sym_ctx.symbol;
+            else
+              non_extern_symbol = sym_ctx.symbol;
+          }
         }
 
-        // any other $__lldb names should be weeded out now
-        if (!::strncmp(name_unique_cstr, "$__lldb", sizeof("$__lldb") - 1))
-            return;
+        if (!context.m_found.function_with_type_info) {
+          for (clang::NamedDecl *decl : decls_from_modules) {
+            if (llvm::isa<clang::FunctionDecl>(decl)) {
+              clang::NamedDecl *copied_decl =
+                  llvm::cast_or_null<FunctionDecl>(m_ast_importer_sp->CopyDecl(
+                      m_ast_context, &decl->getASTContext(), decl));
+              if (copied_decl) {
+                context.AddNamedDecl(copied_decl);
+                context.m_found.function_with_type_info = true;
+              }
+            }
+          }
+        }
+
+        if (!context.m_found.function_with_type_info) {
+          if (extern_symbol) {
+            AddOneFunction(context, NULL, extern_symbol, current_id);
+            context.m_found.function = true;
+          } else if (non_extern_symbol) {
+            AddOneFunction(context, NULL, non_extern_symbol, current_id);
+            context.m_found.function = true;
+          }
+        }
+      }
+
+      if (!context.m_found.function_with_type_info) {
+        // Try the modules next.
+
+        do {
+          if (ClangModulesDeclVendor *modules_decl_vendor =
+                  m_target->GetClangModulesDeclVendor()) {
+            bool append = false;
+            uint32_t max_matches = 1;
+            std::vector<clang::NamedDecl *> decls;
+
+            if (!modules_decl_vendor->FindDecls(name, append, max_matches,
+                                                decls))
+              break;
+
+            clang::NamedDecl *const decl_from_modules = decls[0];
+
+            if (llvm::isa<clang::FunctionDecl>(decl_from_modules)) {
+              if (log) {
+                log->Printf("  CAS::FEVD[%u] Matching function found for "
+                            "\"%s\" in the modules",
+                            current_id, name.GetCString());
+              }
+
+              clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(
+                  m_ast_context, &decl_from_modules->getASTContext(),
+                  decl_from_modules);
+              clang::FunctionDecl *copied_function_decl =
+                  copied_decl ? dyn_cast<clang::FunctionDecl>(copied_decl)
+                              : nullptr;
 
-        ExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariable(name));
+              if (!copied_function_decl) {
+                if (log)
+                  log->Printf("  CAS::FEVD[%u] - Couldn't export a function "
+                              "declaration from the modules",
+                              current_id);
 
-        if (pvar_sp)
-        {
-            AddOneVariable(context, pvar_sp, current_id);
-            return;
-        }
+                break;
+              }
+
+              MaybeRegisterFunctionBody(copied_function_decl);
 
-        const char *reg_name(&name.GetCString()[1]);
+              context.AddNamedDecl(copied_function_decl);
 
-        if (m_parser_vars->m_exe_ctx.GetRegisterContext())
-        {
-            const RegisterInfo *reg_info(m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(reg_name));
+              context.m_found.function_with_type_info = true;
+              context.m_found.function = true;
+            } else if (llvm::isa<clang::VarDecl>(decl_from_modules)) {
+              if (log) {
+                log->Printf("  CAS::FEVD[%u] Matching variable found for "
+                            "\"%s\" in the modules",
+                            current_id, name.GetCString());
+              }
+
+              clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(
+                  m_ast_context, &decl_from_modules->getASTContext(),
+                  decl_from_modules);
+              clang::VarDecl *copied_var_decl =
+                  copied_decl ? dyn_cast_or_null<clang::VarDecl>(copied_decl)
+                              : nullptr;
 
-            if (reg_info)
-            {
+              if (!copied_var_decl) {
                 if (log)
-                    log->Printf("  CEDM::FEVD[%u] Found register %s", current_id, reg_info->name);
+                  log->Printf("  CAS::FEVD[%u] - Couldn't export a variable "
+                              "declaration from the modules",
+                              current_id);
 
-                AddOneRegister(context, reg_info, current_id);
-            }
-        }
-    }
-    else
-    {
-        ValueObjectSP valobj;
-        VariableSP var;
-
-        bool local_var_lookup = !namespace_decl ||
-                                (namespace_decl.GetName() == ConstString(g_lldb_local_vars_namespace_cstr));
-        if (frame && local_var_lookup)
-        {
-            CompilerDeclContext compiler_decl_context = sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext() : CompilerDeclContext();
-
-            if (compiler_decl_context)
-            {
-                // Make sure that the variables are parsed so that we have the declarations.
-                VariableListSP vars = frame->GetInScopeVariableList(true);
-                for (size_t i = 0; i < vars->GetSize(); i++)
-                    vars->GetVariableAtIndex(i)->GetDecl();
-
-                // Search for declarations matching the name. Do not include imported decls
-                // in the search if we are looking for decls in the artificial namespace
-                // $__lldb_local_vars.
-                std::vector<CompilerDecl> found_decls = compiler_decl_context.FindDeclByName(name, namespace_decl.IsValid());
-                
-                bool variable_found = false;
-                for (CompilerDecl decl : found_decls)
-                {
-                    for (size_t vi = 0, ve = vars->GetSize(); vi != ve; ++vi)
-                    {
-                        VariableSP candidate_var = vars->GetVariableAtIndex(vi);
-                        if (candidate_var->GetDecl() == decl)
-                        {
-                            var = candidate_var;
-                            break;
-                        }
-                    }
-
-                    if (var)
-                    {
-                        variable_found = true;
-                        valobj = ValueObjectVariable::Create(frame, var);
-                        AddOneVariable(context, var, valobj, current_id);
-                        context.m_found.variable = true;
-                    }
-                }
-                if (variable_found)
-                    return;
-            }
-        }
-        if (target)
-        {
-            var = FindGlobalVariable (*target,
-                                      module_sp,
-                                      name,
-                                      &namespace_decl,
-                                      NULL);
-
-            if (var)
-            {
-                valobj = ValueObjectVariable::Create(target, var);
-                AddOneVariable(context, var, valobj, current_id);
-                context.m_found.variable = true;
-                return;
-            }
-        }
-        
-        std::vector<clang::NamedDecl *> decls_from_modules;
-        
-        if (target)
-        {
-            if (ClangModulesDeclVendor *decl_vendor = target->GetClangModulesDeclVendor())
-            {
-                decl_vendor->FindDecls(name, false, UINT32_MAX, decls_from_modules);
-            }
-        }
+                break;
+              }
 
-        if (!context.m_found.variable)
-        {
-            const bool include_inlines = false;
-            const bool append = false;
-
-            if (namespace_decl && module_sp)
-            {
-                const bool include_symbols = false;
-
-                module_sp->FindFunctions(name,
-                                         &namespace_decl,
-                                         eFunctionNameTypeBase,
-                                         include_symbols,
-                                         include_inlines,
-                                         append,
-                                         sc_list);
-            }
-            else if (target && !namespace_decl)
-            {
-                const bool include_symbols = true;
-
-                // TODO Fix FindFunctions so that it doesn't return
-                //   instance methods for eFunctionNameTypeBase.
-
-                target->GetImages().FindFunctions(name,
-                                                  eFunctionNameTypeFull,
-                                                  include_symbols,
-                                                  include_inlines,
-                                                  append,
-                                                  sc_list);
-            }
+              context.AddNamedDecl(copied_var_decl);
 
-            // If we found more than one function, see if we can use the
-            // frame's decl context to remove functions that are shadowed
-            // by other functions which match in type but are nearer in scope.
-            //
-            // AddOneFunction will not add a function whose type has already been
-            // added, so if there's another function in the list with a matching
-            // type, check to see if their decl context is a parent of the current
-            // frame's or was imported via a and using statement, and pick the
-            // best match according to lookup rules.
-            if (sc_list.GetSize() > 1)
-            {
-                // Collect some info about our frame's context.
-                StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
-                SymbolContext frame_sym_ctx;
-                if (frame != nullptr)
-                    frame_sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction|lldb::eSymbolContextBlock);
-                CompilerDeclContext frame_decl_context = frame_sym_ctx.block != nullptr ? frame_sym_ctx.block->GetDeclContext() : CompilerDeclContext();
-
-                // We can't do this without a compiler decl context for our frame.
-                if (frame_decl_context)
-                {
-                    clang::DeclContext *frame_decl_ctx = (clang::DeclContext *)frame_decl_context.GetOpaqueDeclContext();
-                    ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(frame_decl_context.GetTypeSystem());
-
-                    // Structure to hold the info needed when comparing function
-                    // declarations.
-                    struct FuncDeclInfo
-                    {
-                        ConstString m_name;
-                        CompilerType m_copied_type;
-                        uint32_t m_decl_lvl;
-                        SymbolContext m_sym_ctx;
-                    };
-
-                    // First, symplify things by looping through the symbol contexts
-                    // to remove unwanted functions and separate out the functions we
-                    // want to compare and prune into a separate list.
-                    // Cache the info needed about the function declarations in a
-                    // vector for efficiency.
-                    SymbolContextList sc_sym_list;
-                    uint32_t num_indices = sc_list.GetSize();
-                    std::vector<FuncDeclInfo> fdi_cache;
-                    fdi_cache.reserve(num_indices);
-                    for (uint32_t index = 0; index < num_indices; ++index)
-                    {
-                        FuncDeclInfo fdi;
-                        SymbolContext sym_ctx;
-                        sc_list.GetContextAtIndex(index, sym_ctx);
-
-                        // We don't know enough about symbols to compare them,
-                        // but we should keep them in the list.
-                        Function *function = sym_ctx.function;
-                        if (!function)
-                        {
-                            sc_sym_list.Append(sym_ctx);
-                            continue;
-                        }
-                        // Filter out functions without declaration contexts, as well as
-                        // class/instance methods, since they'll be skipped in the
-                        // code that follows anyway.
-                        CompilerDeclContext func_decl_context = function->GetDeclContext();
-                        if (!func_decl_context || func_decl_context.IsClassMethod(nullptr, nullptr, nullptr))
-                            continue;
-                        // We can only prune functions for which we can copy the type.
-                        CompilerType func_clang_type = function->GetType()->GetFullCompilerType();
-                        CompilerType copied_func_type = GuardedCopyType(func_clang_type);
-                        if (!copied_func_type)
-                        {
-                            sc_sym_list.Append(sym_ctx);
-                            continue;
-                        }
-
-                        fdi.m_sym_ctx = sym_ctx;
-                        fdi.m_name = function->GetName();
-                        fdi.m_copied_type = copied_func_type;
-                        fdi.m_decl_lvl = LLDB_INVALID_DECL_LEVEL;
-                        if (fdi.m_copied_type && func_decl_context)
-                        {
-                            // Call CountDeclLevels to get the number of parent scopes we
-                            // have to look through before we find the function declaration.
-                            // When comparing functions of the same type, the one with a
-                            // lower count will be closer to us in the lookup scope and
-                            // shadows the other.
-                            clang::DeclContext *func_decl_ctx = (clang::DeclContext *)func_decl_context.GetOpaqueDeclContext();
-                            fdi.m_decl_lvl = ast->CountDeclLevels(frame_decl_ctx,
-                                                                  func_decl_ctx,
-                                                                  &fdi.m_name,
-                                                                  &fdi.m_copied_type);
-                        }
-                        fdi_cache.emplace_back(fdi);
-                    }
-
-                    // Loop through the functions in our cache looking for matching types,
-                    // then compare their scope levels to see which is closer.
-                    std::multimap<CompilerType, const FuncDeclInfo*> matches;
-                    for (const FuncDeclInfo &fdi : fdi_cache)
-                    {
-                        const CompilerType t = fdi.m_copied_type;
-                        auto q = matches.find(t);
-                        if (q != matches.end())
-                        {
-                            if (q->second->m_decl_lvl > fdi.m_decl_lvl)
-                                // This function is closer; remove the old set.
-                                matches.erase(t);
-                            else if (q->second->m_decl_lvl < fdi.m_decl_lvl)
-                                // The functions in our set are closer - skip this one.
-                                continue;
-                        }
-                        matches.insert(std::make_pair(t, &fdi));
-                    }
-
-                    // Loop through our matches and add their symbol contexts to our list.
-                    SymbolContextList sc_func_list;
-                    for (const auto &q : matches)
-                        sc_func_list.Append(q.second->m_sym_ctx);
-
-                    // Rejoin the lists with the functions in front.
-                    sc_list = sc_func_list;
-                    sc_list.Append(sc_sym_list);
-                }
+              context.m_found.variable = true;
             }
+          }
+        } while (0);
+      }
 
-            if (sc_list.GetSize())
-            {
-                Symbol *extern_symbol = NULL;
-                Symbol *non_extern_symbol = NULL;
-
-                for (uint32_t index = 0, num_indices = sc_list.GetSize();
-                     index < num_indices;
-                     ++index)
-                {
-                    SymbolContext sym_ctx;
-                    sc_list.GetContextAtIndex(index, sym_ctx);
-
-                    if (sym_ctx.function)
-                    {
-                        CompilerDeclContext decl_ctx = sym_ctx.function->GetDeclContext();
-
-                        if (!decl_ctx)
-                            continue;
-
-                        // Filter out class/instance methods.
-                        if (decl_ctx.IsClassMethod(nullptr, nullptr, nullptr))
-                            continue;
-
-                        AddOneFunction(context, sym_ctx.function, NULL, current_id);
-                        context.m_found.function_with_type_info = true;
-                        context.m_found.function = true;
-                    }
-                    else if (sym_ctx.symbol)
-                    {
-                        if (sym_ctx.symbol->GetType() == eSymbolTypeReExported && target)
-                        {
-                            sym_ctx.symbol = sym_ctx.symbol->ResolveReExportedSymbol(*target);
-                            if (sym_ctx.symbol == NULL)
-                                continue;
-                        }
-
-                        if (sym_ctx.symbol->IsExternal())
-                            extern_symbol = sym_ctx.symbol;
-                        else
-                            non_extern_symbol = sym_ctx.symbol;
-                    }
-                }
-                
-                if (!context.m_found.function_with_type_info)
-                {
-                    for (clang::NamedDecl *decl : decls_from_modules)
-                    {
-                        if (llvm::isa<clang::FunctionDecl>(decl))
-                        {
-                            clang::NamedDecl *copied_decl = llvm::cast_or_null<FunctionDecl>(m_ast_importer_sp->CopyDecl(m_ast_context, &decl->getASTContext(), decl));
-                            if (copied_decl)
-                            {
-                                context.AddNamedDecl(copied_decl);
-                                context.m_found.function_with_type_info = true;
-                            }
-                        }
-                    }
-                }
-
-                if (!context.m_found.function_with_type_info)
-                {
-                    if (extern_symbol)
-                    {
-                        AddOneFunction (context, NULL, extern_symbol, current_id);
-                        context.m_found.function = true;
-                    }
-                    else if (non_extern_symbol)
-                    {
-                        AddOneFunction (context, NULL, non_extern_symbol, current_id);
-                        context.m_found.function = true;
-                    }
-                }
-            }
-            
-            if (!context.m_found.function_with_type_info)
-            {
-                // Try the modules next.
-                
-                do
-                {
-                    if (ClangModulesDeclVendor *modules_decl_vendor = m_target->GetClangModulesDeclVendor())
-                    {
-                        bool append = false;
-                        uint32_t max_matches = 1;
-                        std::vector <clang::NamedDecl *> decls;
-                        
-                        if (!modules_decl_vendor->FindDecls(name,
-                                                            append,
-                                                            max_matches,
-                                                            decls))
-                            break;
-                        
-                        clang::NamedDecl *const decl_from_modules = decls[0];
-                        
-                        if (llvm::isa<clang::FunctionDecl>(decl_from_modules))
-                        {
-                            if (log)
-                            {
-                                log->Printf("  CAS::FEVD[%u] Matching function found for \"%s\" in the modules",
-                                            current_id,
-                                            name.GetCString());
-                            }
-                            
-                            clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, &decl_from_modules->getASTContext(), decl_from_modules);
-                            clang::FunctionDecl *copied_function_decl = copied_decl ? dyn_cast<clang::FunctionDecl>(copied_decl) : nullptr;
-                            
-                            if (!copied_function_decl)
-                            {
-                                if (log)
-                                    log->Printf("  CAS::FEVD[%u] - Couldn't export a function declaration from the modules",
-                                                current_id);
-                                
-                                break;
-                            }
-                            
-                            MaybeRegisterFunctionBody(copied_function_decl);
-                            
-                            context.AddNamedDecl(copied_function_decl);
-                            
-                            context.m_found.function_with_type_info = true;
-                            context.m_found.function = true;
-                        }
-                        else if (llvm::isa<clang::VarDecl>(decl_from_modules))
-                        {
-                            if (log)
-                            {
-                                log->Printf("  CAS::FEVD[%u] Matching variable found for \"%s\" in the modules",
-                                            current_id,
-                                            name.GetCString());
-                            }
-                            
-                            clang::Decl *copied_decl = m_ast_importer_sp->CopyDecl(m_ast_context, &decl_from_modules->getASTContext(), decl_from_modules);
-                            clang::VarDecl *copied_var_decl = copied_decl ? dyn_cast_or_null<clang::VarDecl>(copied_decl) : nullptr;
-                            
-                            if (!copied_var_decl)
-                            {
-                                if (log)
-                                    log->Printf("  CAS::FEVD[%u] - Couldn't export a variable declaration from the modules",
-                                                current_id);
-                                
-                                break;
-                            }
-                            
-                            context.AddNamedDecl(copied_var_decl);
-                            
-                            context.m_found.variable = true;
-                        }
-                    }
-                } while (0);
-            }
+      if (target && !context.m_found.variable && !namespace_decl) {
+        // We couldn't find a non-symbol variable for this.  Now we'll hunt for
+        // a generic
+        // data symbol, and -- if it is found -- treat it as a variable.
 
-            if (target && !context.m_found.variable && !namespace_decl)
-            {
-                // We couldn't find a non-symbol variable for this.  Now we'll hunt for a generic
-                // data symbol, and -- if it is found -- treat it as a variable.
-
-                const Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
-
-                if (data_symbol)
-                {
-                    std::string warning("got name from symbols: ");
-                    warning.append(name.AsCString());
-                    const unsigned diag_id = m_ast_context->getDiagnostics().getCustomDiagID(clang::DiagnosticsEngine::Level::Warning, "%0");
-                    m_ast_context->getDiagnostics().Report(diag_id) << warning.c_str();
-                    AddOneGenericVariable(context, *data_symbol, current_id);
-                    context.m_found.variable = true;
-                }
-            }
+        const Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
+
+        if (data_symbol) {
+          std::string warning("got name from symbols: ");
+          warning.append(name.AsCString());
+          const unsigned diag_id =
+              m_ast_context->getDiagnostics().getCustomDiagID(
+                  clang::DiagnosticsEngine::Level::Warning, "%0");
+          m_ast_context->getDiagnostics().Report(diag_id) << warning.c_str();
+          AddOneGenericVariable(context, *data_symbol, current_id);
+          context.m_found.variable = true;
         }
+      }
     }
+  }
 }
 
-//static opaque_compiler_type_t
-//MaybePromoteToBlockPointerType
+// static opaque_compiler_type_t
+// MaybePromoteToBlockPointerType
 //(
 //    ASTContext *ast_context,
 //    opaque_compiler_type_t candidate_type
@@ -1647,14 +1562,16 @@ ClangExpressionDeclMap::FindExternalVisi
 //
 //    QualType candidate_qual_type = QualType::getFromOpaquePtr(candidate_type);
 //
-//    const PointerType *candidate_pointer_type = dyn_cast<PointerType>(candidate_qual_type);
+//    const PointerType *candidate_pointer_type =
+//    dyn_cast<PointerType>(candidate_qual_type);
 //
 //    if (!candidate_pointer_type)
 //        return candidate_type;
 //
 //    QualType pointee_qual_type = candidate_pointer_type->getPointeeType();
 //
-//    const RecordType *pointee_record_type = dyn_cast<RecordType>(pointee_qual_type);
+//    const RecordType *pointee_record_type =
+//    dyn_cast<RecordType>(pointee_qual_type);
 //
 //    if (!pointee_record_type)
 //        return candidate_type;
@@ -1664,659 +1581,639 @@ ClangExpressionDeclMap::FindExternalVisi
 //    if (!pointee_record_decl->isRecord())
 //        return candidate_type;
 //
-//    if (!pointee_record_decl->getName().startswith(llvm::StringRef("__block_literal_")))
+//    if
+//    (!pointee_record_decl->getName().startswith(llvm::StringRef("__block_literal_")))
 //        return candidate_type;
 //
-//    QualType generic_function_type = ast_context->getFunctionNoProtoType(ast_context->UnknownAnyTy);
-//    QualType block_pointer_type = ast_context->getBlockPointerType(generic_function_type);
+//    QualType generic_function_type =
+//    ast_context->getFunctionNoProtoType(ast_context->UnknownAnyTy);
+//    QualType block_pointer_type =
+//    ast_context->getBlockPointerType(generic_function_type);
 //
 //    return block_pointer_type.getAsOpaquePtr();
 //}
 
-bool
-ClangExpressionDeclMap::GetVariableValue (VariableSP &var,
-                                          lldb_private::Value &var_location,
-                                          TypeFromUser *user_type,
-                                          TypeFromParser *parser_type)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    Type *var_type = var->GetType();
-
-    if (!var_type)
-    {
-        if (log)
-            log->PutCString("Skipped a definition because it has no type");
-        return false;
-    }
-
-    CompilerType var_clang_type = var_type->GetFullCompilerType ();
+bool ClangExpressionDeclMap::GetVariableValue(VariableSP &var,
+                                              lldb_private::Value &var_location,
+                                              TypeFromUser *user_type,
+                                              TypeFromParser *parser_type) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (!var_clang_type)
-    {
-        if (log)
-            log->PutCString("Skipped a definition because it has no Clang type");
-        return false;
-    }
+  Type *var_type = var->GetType();
 
-    ClangASTContext *clang_ast = llvm::dyn_cast_or_null<ClangASTContext>(var_type->GetForwardCompilerType().GetTypeSystem());
+  if (!var_type) {
+    if (log)
+      log->PutCString("Skipped a definition because it has no type");
+    return false;
+  }
 
-    if (!clang_ast)
-    {
-        if (log)
-            log->PutCString("Skipped a definition because it has no Clang AST");
-        return false;
-    }
+  CompilerType var_clang_type = var_type->GetFullCompilerType();
 
+  if (!var_clang_type) {
+    if (log)
+      log->PutCString("Skipped a definition because it has no Clang type");
+    return false;
+  }
 
-    ASTContext *ast = clang_ast->getASTContext();
+  ClangASTContext *clang_ast = llvm::dyn_cast_or_null<ClangASTContext>(
+      var_type->GetForwardCompilerType().GetTypeSystem());
 
-    if (!ast)
-    {
-        if (log)
-            log->PutCString("There is no AST context for the current execution context");
-        return false;
-    }
-    //var_clang_type = MaybePromoteToBlockPointerType (ast, var_clang_type);
-
-    DWARFExpression &var_location_expr = var->LocationExpression();
+  if (!clang_ast) {
+    if (log)
+      log->PutCString("Skipped a definition because it has no Clang AST");
+    return false;
+  }
 
-    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
-    Error err;
+  ASTContext *ast = clang_ast->getASTContext();
 
-    if (var->GetLocationIsConstantValueData())
-    {
-        DataExtractor const_value_extractor;
-
-        if (var_location_expr.GetExpressionData(const_value_extractor))
-        {
-            var_location = Value(const_value_extractor.GetDataStart(), const_value_extractor.GetByteSize());
-            var_location.SetValueType(Value::eValueTypeHostAddress);
-        }
-        else
-        {
-            if (log)
-                log->Printf("Error evaluating constant variable: %s", err.AsCString());
-            return false;
-        }
+  if (!ast) {
+    if (log)
+      log->PutCString(
+          "There is no AST context for the current execution context");
+    return false;
+  }
+  // var_clang_type = MaybePromoteToBlockPointerType (ast, var_clang_type);
+
+  DWARFExpression &var_location_expr = var->LocationExpression();
+
+  Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+  Error err;
+
+  if (var->GetLocationIsConstantValueData()) {
+    DataExtractor const_value_extractor;
+
+    if (var_location_expr.GetExpressionData(const_value_extractor)) {
+      var_location = Value(const_value_extractor.GetDataStart(),
+                           const_value_extractor.GetByteSize());
+      var_location.SetValueType(Value::eValueTypeHostAddress);
+    } else {
+      if (log)
+        log->Printf("Error evaluating constant variable: %s", err.AsCString());
+      return false;
     }
+  }
 
-    CompilerType type_to_use = GuardedCopyType(var_clang_type);
+  CompilerType type_to_use = GuardedCopyType(var_clang_type);
 
-    if (!type_to_use)
-    {
-        if (log)
-            log->Printf("Couldn't copy a variable's type into the parser's AST context");
+  if (!type_to_use) {
+    if (log)
+      log->Printf(
+          "Couldn't copy a variable's type into the parser's AST context");
 
-        return false;
-    }
+    return false;
+  }
 
-    if (parser_type)
-        *parser_type = TypeFromParser(type_to_use);
+  if (parser_type)
+    *parser_type = TypeFromParser(type_to_use);
 
-    if (var_location.GetContextType() == Value::eContextTypeInvalid)
-        var_location.SetCompilerType(type_to_use);
+  if (var_location.GetContextType() == Value::eContextTypeInvalid)
+    var_location.SetCompilerType(type_to_use);
 
-    if (var_location.GetValueType() == Value::eValueTypeFileAddress)
-    {
-        SymbolContext var_sc;
-        var->CalculateSymbolContext(&var_sc);
+  if (var_location.GetValueType() == Value::eValueTypeFileAddress) {
+    SymbolContext var_sc;
+    var->CalculateSymbolContext(&var_sc);
 
-        if (!var_sc.module_sp)
-            return false;
+    if (!var_sc.module_sp)
+      return false;
 
-        Address so_addr(var_location.GetScalar().ULongLong(), var_sc.module_sp->GetSectionList());
+    Address so_addr(var_location.GetScalar().ULongLong(),
+                    var_sc.module_sp->GetSectionList());
 
-        lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
+    lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
 
-        if (load_addr != LLDB_INVALID_ADDRESS)
-        {
-            var_location.GetScalar() = load_addr;
-            var_location.SetValueType(Value::eValueTypeLoadAddress);
-        }
+    if (load_addr != LLDB_INVALID_ADDRESS) {
+      var_location.GetScalar() = load_addr;
+      var_location.SetValueType(Value::eValueTypeLoadAddress);
     }
+  }
 
-    if (user_type)
-        *user_type = TypeFromUser(var_clang_type);
+  if (user_type)
+    *user_type = TypeFromUser(var_clang_type);
 
-    return true;
+  return true;
 }
 
-void
-ClangExpressionDeclMap::AddOneVariable (NameSearchContext &context, VariableSP var, ValueObjectSP valobj, unsigned int current_id)
-{
-    assert (m_parser_vars.get());
-
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    TypeFromUser ut;
-    TypeFromParser pt;
-    Value var_location;
+void ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
+                                            VariableSP var,
+                                            ValueObjectSP valobj,
+                                            unsigned int current_id) {
+  assert(m_parser_vars.get());
 
-    if (!GetVariableValue (var, var_location, &ut, &pt))
-        return;
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    clang::QualType parser_opaque_type = QualType::getFromOpaquePtr(pt.GetOpaqueQualType());
+  TypeFromUser ut;
+  TypeFromParser pt;
+  Value var_location;
 
-    if (parser_opaque_type.isNull())
-        return;
-
-    if (const clang::Type *parser_type = parser_opaque_type.getTypePtr())
-    {
-        if (const TagType *tag_type = dyn_cast<TagType>(parser_type))
-            CompleteType(tag_type->getDecl());
-        if (const ObjCObjectPointerType *objc_object_ptr_type = dyn_cast<ObjCObjectPointerType>(parser_type))
-            CompleteType(objc_object_ptr_type->getInterfaceDecl());
-    }
+  if (!GetVariableValue(var, var_location, &ut, &pt))
+    return;
 
+  clang::QualType parser_opaque_type =
+      QualType::getFromOpaquePtr(pt.GetOpaqueQualType());
 
-    bool is_reference = pt.IsReferenceType();
+  if (parser_opaque_type.isNull())
+    return;
 
-    NamedDecl *var_decl = NULL;
-    if (is_reference)
-        var_decl = context.AddVarDecl(pt);
-    else
-        var_decl = context.AddVarDecl(pt.GetLValueReferenceType());
+  if (const clang::Type *parser_type = parser_opaque_type.getTypePtr()) {
+    if (const TagType *tag_type = dyn_cast<TagType>(parser_type))
+      CompleteType(tag_type->getDecl());
+    if (const ObjCObjectPointerType *objc_object_ptr_type =
+            dyn_cast<ObjCObjectPointerType>(parser_type))
+      CompleteType(objc_object_ptr_type->getInterfaceDecl());
+  }
+
+  bool is_reference = pt.IsReferenceType();
+
+  NamedDecl *var_decl = NULL;
+  if (is_reference)
+    var_decl = context.AddVarDecl(pt);
+  else
+    var_decl = context.AddVarDecl(pt.GetLValueReferenceType());
+
+  std::string decl_name(context.m_decl_name.getAsString());
+  ConstString entity_name(decl_name.c_str());
+  ClangExpressionVariable *entity(new ClangExpressionVariable(valobj));
+  m_found_entities.AddNewlyConstructedVariable(entity);
+
+  assert(entity);
+  entity->EnableParserVars(GetParserID());
+  ClangExpressionVariable::ParserVars *parser_vars =
+      entity->GetParserVars(GetParserID());
+  parser_vars->m_parser_type = pt;
+  parser_vars->m_named_decl = var_decl;
+  parser_vars->m_llvm_value = NULL;
+  parser_vars->m_lldb_value = var_location;
+  parser_vars->m_lldb_var = var;
+
+  if (is_reference)
+    entity->m_flags |= ClangExpressionVariable::EVTypeIsReference;
+
+  if (log) {
+    ASTDumper orig_dumper(ut.GetOpaqueQualType());
+    ASTDumper ast_dumper(var_decl);
+    log->Printf("  CEDM::FEVD[%u] Found variable %s, returned %s (original %s)",
+                current_id, decl_name.c_str(), ast_dumper.GetCString(),
+                orig_dumper.GetCString());
+  }
+}
+
+void ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
+                                            ExpressionVariableSP &pvar_sp,
+                                            unsigned int current_id) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    std::string decl_name(context.m_decl_name.getAsString());
-    ConstString entity_name(decl_name.c_str());
-    ClangExpressionVariable *entity(new ClangExpressionVariable(valobj));
-    m_found_entities.AddNewlyConstructedVariable(entity);
-
-    assert (entity);
-    entity->EnableParserVars(GetParserID());
-    ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
-    parser_vars->m_parser_type = pt;
-    parser_vars->m_named_decl  = var_decl;
-    parser_vars->m_llvm_value  = NULL;
-    parser_vars->m_lldb_value  = var_location;
-    parser_vars->m_lldb_var    = var;
+  TypeFromUser user_type(
+      llvm::cast<ClangExpressionVariable>(pvar_sp.get())->GetTypeFromUser());
 
-    if (is_reference)
-        entity->m_flags |= ClangExpressionVariable::EVTypeIsReference;
+  TypeFromParser parser_type(GuardedCopyType(user_type));
 
+  if (!parser_type.GetOpaqueQualType()) {
     if (log)
-    {
-        ASTDumper orig_dumper(ut.GetOpaqueQualType());
-        ASTDumper ast_dumper(var_decl);
-        log->Printf("  CEDM::FEVD[%u] Found variable %s, returned %s (original %s)", current_id, decl_name.c_str(), ast_dumper.GetCString(), orig_dumper.GetCString());
-    }
-}
+      log->Printf("  CEDM::FEVD[%u] Couldn't import type for pvar %s",
+                  current_id, pvar_sp->GetName().GetCString());
+    return;
+  }
 
-void
-ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
-                                       ExpressionVariableSP &pvar_sp,
-                                       unsigned int current_id)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  NamedDecl *var_decl =
+      context.AddVarDecl(parser_type.GetLValueReferenceType());
 
-    TypeFromUser user_type (llvm::cast<ClangExpressionVariable>(pvar_sp.get())->GetTypeFromUser());
+  llvm::cast<ClangExpressionVariable>(pvar_sp.get())
+      ->EnableParserVars(GetParserID());
+  ClangExpressionVariable::ParserVars *parser_vars =
+      llvm::cast<ClangExpressionVariable>(pvar_sp.get())
+          ->GetParserVars(GetParserID());
+  parser_vars->m_parser_type = parser_type;
+  parser_vars->m_named_decl = var_decl;
+  parser_vars->m_llvm_value = NULL;
+  parser_vars->m_lldb_value.Clear();
+
+  if (log) {
+    ASTDumper ast_dumper(var_decl);
+    log->Printf("  CEDM::FEVD[%u] Added pvar %s, returned %s", current_id,
+                pvar_sp->GetName().GetCString(), ast_dumper.GetCString());
+  }
+}
+
+void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
+                                                   const Symbol &symbol,
+                                                   unsigned int current_id) {
+  assert(m_parser_vars.get());
 
-    TypeFromParser parser_type (GuardedCopyType(user_type));
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    if (!parser_type.GetOpaqueQualType())
-    {
-        if (log)
-            log->Printf("  CEDM::FEVD[%u] Couldn't import type for pvar %s", current_id, pvar_sp->GetName().GetCString());
-        return;
-    }
+  Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
-    NamedDecl *var_decl = context.AddVarDecl(parser_type.GetLValueReferenceType());
+  if (target == NULL)
+    return;
 
-    llvm::cast<ClangExpressionVariable>(pvar_sp.get())->EnableParserVars(GetParserID());
-    ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(pvar_sp.get())->GetParserVars(GetParserID());
-    parser_vars->m_parser_type = parser_type;
-    parser_vars->m_named_decl = var_decl;
-    parser_vars->m_llvm_value = NULL;
-    parser_vars->m_lldb_value.Clear();
+  ASTContext *scratch_ast_context =
+      target->GetScratchClangASTContext()->getASTContext();
 
-    if (log)
-    {
-        ASTDumper ast_dumper(var_decl);
-        log->Printf("  CEDM::FEVD[%u] Added pvar %s, returned %s", current_id, pvar_sp->GetName().GetCString(), ast_dumper.GetCString());
-    }
-}
+  TypeFromUser user_type(
+      ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid)
+          .GetPointerType()
+          .GetLValueReferenceType());
+  TypeFromParser parser_type(
+      ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid)
+          .GetPointerType()
+          .GetLValueReferenceType());
+  NamedDecl *var_decl = context.AddVarDecl(parser_type);
+
+  std::string decl_name(context.m_decl_name.getAsString());
+  ConstString entity_name(decl_name.c_str());
+  ClangExpressionVariable *entity(new ClangExpressionVariable(
+      m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(), entity_name,
+      user_type, m_parser_vars->m_target_info.byte_order,
+      m_parser_vars->m_target_info.address_byte_size));
+  m_found_entities.AddNewlyConstructedVariable(entity);
+
+  entity->EnableParserVars(GetParserID());
+  ClangExpressionVariable::ParserVars *parser_vars =
+      entity->GetParserVars(GetParserID());
+
+  const Address symbol_address = symbol.GetAddress();
+  lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(target);
+
+  // parser_vars->m_lldb_value.SetContext(Value::eContextTypeClangType,
+  // user_type.GetOpaqueQualType());
+  parser_vars->m_lldb_value.SetCompilerType(user_type);
+  parser_vars->m_lldb_value.GetScalar() = symbol_load_addr;
+  parser_vars->m_lldb_value.SetValueType(Value::eValueTypeLoadAddress);
+
+  parser_vars->m_parser_type = parser_type;
+  parser_vars->m_named_decl = var_decl;
+  parser_vars->m_llvm_value = NULL;
+  parser_vars->m_lldb_sym = &symbol;
+
+  if (log) {
+    ASTDumper ast_dumper(var_decl);
+
+    log->Printf("  CEDM::FEVD[%u] Found variable %s, returned %s", current_id,
+                decl_name.c_str(), ast_dumper.GetCString());
+  }
+}
+
+bool ClangExpressionDeclMap::ResolveUnknownTypes() {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+  Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+
+  ClangASTContext *scratch_ast_context = target->GetScratchClangASTContext();
+
+  for (size_t index = 0, num_entities = m_found_entities.GetSize();
+       index < num_entities; ++index) {
+    ExpressionVariableSP entity = m_found_entities.GetVariableAtIndex(index);
+
+    ClangExpressionVariable::ParserVars *parser_vars =
+        llvm::cast<ClangExpressionVariable>(entity.get())
+            ->GetParserVars(GetParserID());
+
+    if (entity->m_flags & ClangExpressionVariable::EVUnknownType) {
+      const NamedDecl *named_decl = parser_vars->m_named_decl;
+      const VarDecl *var_decl = dyn_cast<VarDecl>(named_decl);
 
-void
-ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
-                                              const Symbol &symbol,
-                                              unsigned int current_id)
-{
-    assert(m_parser_vars.get());
+      if (!var_decl) {
+        if (log)
+          log->Printf("Entity of unknown type does not have a VarDecl");
+        return false;
+      }
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+      if (log) {
+        ASTDumper ast_dumper(const_cast<VarDecl *>(var_decl));
+        log->Printf("Variable of unknown type now has Decl %s",
+                    ast_dumper.GetCString());
+      }
 
-    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+      QualType var_type = var_decl->getType();
+      TypeFromParser parser_type(
+          var_type.getAsOpaquePtr(),
+          ClangASTContext::GetASTContext(&var_decl->getASTContext()));
+
+      lldb::opaque_compiler_type_t copied_type = m_ast_importer_sp->CopyType(
+          scratch_ast_context->getASTContext(), &var_decl->getASTContext(),
+          var_type.getAsOpaquePtr());
 
-    if (target == NULL)
-        return;
+      if (!copied_type) {
+        if (log)
+          log->Printf("ClangExpressionDeclMap::ResolveUnknownType - Couldn't "
+                      "import the type for a variable");
 
-    ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
+        return (bool)lldb::ExpressionVariableSP();
+      }
 
-    TypeFromUser user_type (ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid).GetPointerType().GetLValueReferenceType());
-    TypeFromParser parser_type (ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid).GetPointerType().GetLValueReferenceType());
-    NamedDecl *var_decl = context.AddVarDecl(parser_type);
-
-    std::string decl_name(context.m_decl_name.getAsString());
-    ConstString entity_name(decl_name.c_str());
-    ClangExpressionVariable *entity(new ClangExpressionVariable(m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
-                                                                entity_name,
-                                                                user_type,
-                                                                m_parser_vars->m_target_info.byte_order,
-                                                                m_parser_vars->m_target_info.address_byte_size));
-    m_found_entities.AddNewlyConstructedVariable(entity);
-    
-    entity->EnableParserVars(GetParserID());
-    ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
-
-    const Address symbol_address = symbol.GetAddress();
-    lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(target);
-
-    //parser_vars->m_lldb_value.SetContext(Value::eContextTypeClangType, user_type.GetOpaqueQualType());
-    parser_vars->m_lldb_value.SetCompilerType(user_type);
-    parser_vars->m_lldb_value.GetScalar() = symbol_load_addr;
-    parser_vars->m_lldb_value.SetValueType(Value::eValueTypeLoadAddress);
+      TypeFromUser user_type(copied_type, scratch_ast_context);
 
-    parser_vars->m_parser_type = parser_type;
-    parser_vars->m_named_decl  = var_decl;
-    parser_vars->m_llvm_value  = NULL;
-    parser_vars->m_lldb_sym    = &symbol;
+      //            parser_vars->m_lldb_value.SetContext(Value::eContextTypeClangType,
+      //            user_type.GetOpaqueQualType());
+      parser_vars->m_lldb_value.SetCompilerType(user_type);
+      parser_vars->m_parser_type = parser_type;
 
-    if (log)
-    {
-        ASTDumper ast_dumper(var_decl);
+      entity->SetCompilerType(user_type);
 
-        log->Printf("  CEDM::FEVD[%u] Found variable %s, returned %s", current_id, decl_name.c_str(), ast_dumper.GetCString());
+      entity->m_flags &= ~(ClangExpressionVariable::EVUnknownType);
     }
+  }
+
+  return true;
 }
 
-bool
-ClangExpressionDeclMap::ResolveUnknownTypes()
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+void ClangExpressionDeclMap::AddOneRegister(NameSearchContext &context,
+                                            const RegisterInfo *reg_info,
+                                            unsigned int current_id) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    ClangASTContext *scratch_ast_context = target->GetScratchClangASTContext();
+  CompilerType clang_type =
+      ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(
+          m_ast_context, reg_info->encoding, reg_info->byte_size * 8);
 
-    for (size_t index = 0, num_entities = m_found_entities.GetSize();
-         index < num_entities;
-         ++index)
-    {
-        ExpressionVariableSP entity = m_found_entities.GetVariableAtIndex(index);
+  if (!clang_type) {
+    if (log)
+      log->Printf("  Tried to add a type for %s, but couldn't get one",
+                  context.m_decl_name.getAsString().c_str());
+    return;
+  }
 
-        ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(entity.get())->GetParserVars(GetParserID());
+  TypeFromParser parser_clang_type(clang_type);
 
-        if (entity->m_flags & ClangExpressionVariable::EVUnknownType)
-        {
-            const NamedDecl *named_decl = parser_vars->m_named_decl;
-            const VarDecl *var_decl = dyn_cast<VarDecl>(named_decl);
+  NamedDecl *var_decl = context.AddVarDecl(parser_clang_type);
 
-            if (!var_decl)
-            {
-                if (log)
-                    log->Printf("Entity of unknown type does not have a VarDecl");
-                return false;
+  ClangExpressionVariable *entity(new ClangExpressionVariable(
+      m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
+      m_parser_vars->m_target_info.byte_order,
+      m_parser_vars->m_target_info.address_byte_size));
+  m_found_entities.AddNewlyConstructedVariable(entity);
+
+  std::string decl_name(context.m_decl_name.getAsString());
+  entity->SetName(ConstString(decl_name.c_str()));
+  entity->SetRegisterInfo(reg_info);
+  entity->EnableParserVars(GetParserID());
+  ClangExpressionVariable::ParserVars *parser_vars =
+      entity->GetParserVars(GetParserID());
+  parser_vars->m_parser_type = parser_clang_type;
+  parser_vars->m_named_decl = var_decl;
+  parser_vars->m_llvm_value = NULL;
+  parser_vars->m_lldb_value.Clear();
+  entity->m_flags |= ClangExpressionVariable::EVBareRegister;
+
+  if (log) {
+    ASTDumper ast_dumper(var_decl);
+    log->Printf("  CEDM::FEVD[%d] Added register %s, returned %s", current_id,
+                context.m_decl_name.getAsString().c_str(),
+                ast_dumper.GetCString());
+  }
+}
+
+void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
+                                            Function *function, Symbol *symbol,
+                                            unsigned int current_id) {
+  assert(m_parser_vars.get());
+
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  NamedDecl *function_decl = NULL;
+  Address fun_address;
+  CompilerType function_clang_type;
+
+  bool is_indirect_function = false;
+
+  if (function) {
+    Type *function_type = function->GetType();
+
+    const lldb::LanguageType comp_unit_language =
+        function->GetCompileUnit()->GetLanguage();
+    const bool extern_c = Language::LanguageIsC(comp_unit_language) ||
+                          (Language::LanguageIsObjC(comp_unit_language) &&
+                           !Language::LanguageIsCPlusPlus(comp_unit_language));
+
+    if (!extern_c) {
+      TypeSystem *type_system = function->GetDeclContext().GetTypeSystem();
+      if (ClangASTContext *src_ast =
+              llvm::dyn_cast<ClangASTContext>(type_system)) {
+        clang::DeclContext *src_decl_context =
+            (clang::DeclContext *)function->GetDeclContext()
+                .GetOpaqueDeclContext();
+        clang::FunctionDecl *src_function_decl =
+            llvm::dyn_cast_or_null<clang::FunctionDecl>(src_decl_context);
+
+        if (src_function_decl) {
+          if (clang::FunctionDecl *copied_function_decl =
+                  llvm::dyn_cast_or_null<clang::FunctionDecl>(
+                      m_ast_importer_sp->CopyDecl(m_ast_context,
+                                                  src_ast->getASTContext(),
+                                                  src_function_decl))) {
+            if (log) {
+              ASTDumper ast_dumper((clang::Decl *)copied_function_decl);
+
+              StreamString ss;
+
+              function->DumpSymbolContext(&ss);
+
+              log->Printf("  CEDM::FEVD[%u] Imported decl for function %s "
+                          "(description %s), returned %s",
+                          current_id,
+                          copied_function_decl->getNameAsString().c_str(),
+                          ss.GetData(), ast_dumper.GetCString());
             }
 
-            if (log)
-            {
-                ASTDumper ast_dumper(const_cast<VarDecl*>(var_decl));
-                log->Printf("Variable of unknown type now has Decl %s", ast_dumper.GetCString());
-            }
-
-            QualType var_type = var_decl->getType();
-            TypeFromParser parser_type(var_type.getAsOpaquePtr(), ClangASTContext::GetASTContext(&var_decl->getASTContext()));
-
-            lldb::opaque_compiler_type_t copied_type = m_ast_importer_sp->CopyType(scratch_ast_context->getASTContext(), &var_decl->getASTContext(), var_type.getAsOpaquePtr());
-
-            if (!copied_type)
-            {
-                if (log)
-                    log->Printf("ClangExpressionDeclMap::ResolveUnknownType - Couldn't import the type for a variable");
-
-                return (bool) lldb::ExpressionVariableSP();
+            context.AddNamedDecl(copied_function_decl);
+            return;
+          } else {
+            if (log) {
+              log->Printf("  Failed to import the function decl for '%s'",
+                          src_function_decl->getName().str().c_str());
             }
-
-            TypeFromUser user_type(copied_type, scratch_ast_context);
-
-//            parser_vars->m_lldb_value.SetContext(Value::eContextTypeClangType, user_type.GetOpaqueQualType());
-            parser_vars->m_lldb_value.SetCompilerType(user_type);
-            parser_vars->m_parser_type = parser_type;
-
-            entity->SetCompilerType(user_type);
-
-            entity->m_flags &= ~(ClangExpressionVariable::EVUnknownType);
+          }
         }
+      }
     }
 
-    return true;
-}
+    if (!function_type) {
+      if (log)
+        log->PutCString("  Skipped a function because it has no type");
+      return;
+    }
 
-void
-ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context,
-                                        const RegisterInfo *reg_info,
-                                        unsigned int current_id)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    CompilerType clang_type = ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (m_ast_context,
-                                                                                    reg_info->encoding,
-                                                                                    reg_info->byte_size * 8);
+    function_clang_type = function_type->GetFullCompilerType();
 
-    if (!clang_type)
-    {
-        if (log)
-            log->Printf("  Tried to add a type for %s, but couldn't get one", context.m_decl_name.getAsString().c_str());
-        return;
+    if (!function_clang_type) {
+      if (log)
+        log->PutCString("  Skipped a function because it has no Clang type");
+      return;
     }
 
-    TypeFromParser parser_clang_type (clang_type);
+    fun_address = function->GetAddressRange().GetBaseAddress();
 
-    NamedDecl *var_decl = context.AddVarDecl(parser_clang_type);
+    CompilerType copied_function_type = GuardedCopyType(function_clang_type);
+    if (copied_function_type) {
+      function_decl = context.AddFunDecl(copied_function_type, extern_c);
 
-    ClangExpressionVariable *entity(new ClangExpressionVariable(m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
-                                                                m_parser_vars->m_target_info.byte_order,
-                                                                m_parser_vars->m_target_info.address_byte_size));
-    m_found_entities.AddNewlyConstructedVariable(entity);
-
-    std::string decl_name(context.m_decl_name.getAsString());
-    entity->SetName (ConstString (decl_name.c_str()));
-    entity->SetRegisterInfo (reg_info);
-    entity->EnableParserVars(GetParserID());
-    ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
-    parser_vars->m_parser_type = parser_clang_type;
-    parser_vars->m_named_decl = var_decl;
-    parser_vars->m_llvm_value = NULL;
-    parser_vars->m_lldb_value.Clear();
-    entity->m_flags |= ClangExpressionVariable::EVBareRegister;
+      if (!function_decl) {
+        if (log) {
+          log->Printf(
+              "  Failed to create a function decl for '%s' {0x%8.8" PRIx64 "}",
+              function_type->GetName().GetCString(), function_type->GetID());
+        }
 
+        return;
+      }
+    } else {
+      // We failed to copy the type we found
+      if (log) {
+        log->Printf("  Failed to import the function type '%s' {0x%8.8" PRIx64
+                    "} into the expression parser AST contenxt",
+                    function_type->GetName().GetCString(),
+                    function_type->GetID());
+      }
+
+      return;
+    }
+  } else if (symbol) {
+    fun_address = symbol->GetAddress();
+    function_decl = context.AddGenericFunDecl();
+    is_indirect_function = symbol->IsIndirect();
+  } else {
     if (log)
-    {
-        ASTDumper ast_dumper(var_decl);
-        log->Printf("  CEDM::FEVD[%d] Added register %s, returned %s", current_id, context.m_decl_name.getAsString().c_str(), ast_dumper.GetCString());
-    }
-}
-
-void
-ClangExpressionDeclMap::AddOneFunction (NameSearchContext &context,
-                                        Function* function,
-                                        Symbol* symbol,
-                                        unsigned int current_id)
-{
-    assert (m_parser_vars.get());
-
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    NamedDecl *function_decl = NULL;
-    Address fun_address;
-    CompilerType function_clang_type;
-
-    bool is_indirect_function = false;
-
-    if (function)
-    {
-        Type *function_type = function->GetType();
-        
-        const lldb::LanguageType comp_unit_language = function->GetCompileUnit()->GetLanguage();
-        const bool extern_c = Language::LanguageIsC(comp_unit_language) ||
-                              (Language::LanguageIsObjC(comp_unit_language) &&
-                               !Language::LanguageIsCPlusPlus(comp_unit_language));
-        
-        if (!extern_c)
-        {
-            TypeSystem *type_system = function->GetDeclContext().GetTypeSystem();
-            if (ClangASTContext *src_ast = llvm::dyn_cast<ClangASTContext>(type_system))
-            {
-                clang::DeclContext *src_decl_context = (clang::DeclContext*)function->GetDeclContext().GetOpaqueDeclContext();
-                clang::FunctionDecl *src_function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(src_decl_context);
-                
-                if (src_function_decl)
-                {
-                    if (clang::FunctionDecl *copied_function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(m_ast_importer_sp->CopyDecl(m_ast_context, src_ast->getASTContext(), src_function_decl)))
-                    {
-                        if (log)
-                        {
-                            ASTDumper ast_dumper((clang::Decl*)copied_function_decl);
-                            
-                            StreamString ss;
-                            
-                            function->DumpSymbolContext(&ss);
-
-                            log->Printf("  CEDM::FEVD[%u] Imported decl for function %s (description %s), returned %s",
-                                        current_id, copied_function_decl->getNameAsString().c_str(), ss.GetData(),
-                                        ast_dumper.GetCString());
-                        }
-                        
-                        context.AddNamedDecl(copied_function_decl);
-                        return;
-                    }
-                    else
-                    {
-                        if (log)
-                        {
-                            log->Printf ("  Failed to import the function decl for '%s'",
-                                         src_function_decl->getName().str().c_str());
-                        }
-                    }
-                }
-            }
-        }
+      log->PutCString("  AddOneFunction called with no function and no symbol");
+    return;
+  }
 
-        if (!function_type)
-        {
-            if (log)
-                log->PutCString("  Skipped a function because it has no type");
-            return;
-        }
+  Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
-        function_clang_type = function_type->GetFullCompilerType ();
+  lldb::addr_t load_addr =
+      fun_address.GetCallableLoadAddress(target, is_indirect_function);
 
-        if (!function_clang_type)
-        {
-            if (log)
-                log->PutCString("  Skipped a function because it has no Clang type");
-            return;
-        }
+  ClangExpressionVariable *entity(new ClangExpressionVariable(
+      m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
+      m_parser_vars->m_target_info.byte_order,
+      m_parser_vars->m_target_info.address_byte_size));
+  m_found_entities.AddNewlyConstructedVariable(entity);
 
-        fun_address = function->GetAddressRange().GetBaseAddress();
+  std::string decl_name(context.m_decl_name.getAsString());
+  entity->SetName(ConstString(decl_name.c_str()));
+  entity->SetCompilerType(function_clang_type);
+  entity->EnableParserVars(GetParserID());
 
-        CompilerType copied_function_type = GuardedCopyType(function_clang_type);
-        if (copied_function_type)
-        {
-            function_decl = context.AddFunDecl(copied_function_type, extern_c);
+  ClangExpressionVariable::ParserVars *parser_vars =
+      entity->GetParserVars(GetParserID());
 
-            if (!function_decl)
-            {
-                if (log)
-                {
-                    log->Printf ("  Failed to create a function decl for '%s' {0x%8.8" PRIx64 "}",
-                                 function_type->GetName().GetCString(),
-                                 function_type->GetID());
-                }
+  if (load_addr != LLDB_INVALID_ADDRESS) {
+    parser_vars->m_lldb_value.SetValueType(Value::eValueTypeLoadAddress);
+    parser_vars->m_lldb_value.GetScalar() = load_addr;
+  } else {
+    // We have to try finding a file address.
 
-                return;
-            }
-        }
-        else
-        {
-            // We failed to copy the type we found
-            if (log)
-            {
-                log->Printf ("  Failed to import the function type '%s' {0x%8.8" PRIx64 "} into the expression parser AST contenxt",
-                             function_type->GetName().GetCString(),
-                             function_type->GetID());
-            }
+    lldb::addr_t file_addr = fun_address.GetFileAddress();
 
-            return;
-        }
-    }
-    else if (symbol)
-    {
-        fun_address = symbol->GetAddress();
-        function_decl = context.AddGenericFunDecl();
-        is_indirect_function = symbol->IsIndirect();
-    }
-    else
-    {
-        if (log)
-            log->PutCString("  AddOneFunction called with no function and no symbol");
-        return;
-    }
+    parser_vars->m_lldb_value.SetValueType(Value::eValueTypeFileAddress);
+    parser_vars->m_lldb_value.GetScalar() = file_addr;
+  }
 
-    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+  parser_vars->m_named_decl = function_decl;
+  parser_vars->m_llvm_value = NULL;
 
-    lldb::addr_t load_addr = fun_address.GetCallableLoadAddress(target, is_indirect_function);
+  if (log) {
+    ASTDumper ast_dumper(function_decl);
 
-    ClangExpressionVariable *entity(new ClangExpressionVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
-                                                                 m_parser_vars->m_target_info.byte_order,
-                                                                 m_parser_vars->m_target_info.address_byte_size));
-    m_found_entities.AddNewlyConstructedVariable(entity);
-
-    std::string decl_name(context.m_decl_name.getAsString());
-    entity->SetName(ConstString(decl_name.c_str()));
-    entity->SetCompilerType (function_clang_type);
-    entity->EnableParserVars(GetParserID());
-
-    ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
-
-    if (load_addr != LLDB_INVALID_ADDRESS)
-    {
-        parser_vars->m_lldb_value.SetValueType(Value::eValueTypeLoadAddress);
-        parser_vars->m_lldb_value.GetScalar() = load_addr;
-    }
-    else
-    {
-        // We have to try finding a file address.
+    StreamString ss;
 
-        lldb::addr_t file_addr = fun_address.GetFileAddress();
+    fun_address.Dump(&ss,
+                     m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
+                     Address::DumpStyleResolvedDescription);
 
-        parser_vars->m_lldb_value.SetValueType(Value::eValueTypeFileAddress);
-        parser_vars->m_lldb_value.GetScalar() = file_addr;
-    }
+    log->Printf(
+        "  CEDM::FEVD[%u] Found %s function %s (description %s), returned %s",
+        current_id, (function ? "specific" : "generic"), decl_name.c_str(),
+        ss.GetData(), ast_dumper.GetCString());
+  }
+}
 
+void ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
+                                         TypeFromUser &ut,
+                                         unsigned int current_id) {
+  CompilerType copied_clang_type = GuardedCopyType(ut);
 
-    parser_vars->m_named_decl  = function_decl;
-    parser_vars->m_llvm_value  = NULL;
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
+  if (!copied_clang_type) {
     if (log)
-    {
-        ASTDumper ast_dumper(function_decl);
+      log->Printf(
+          "ClangExpressionDeclMap::AddThisType - Couldn't import the type");
 
-        StreamString ss;
-
-        fun_address.Dump(&ss, m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(), Address::DumpStyleResolvedDescription);
+    return;
+  }
 
-        log->Printf("  CEDM::FEVD[%u] Found %s function %s (description %s), returned %s",
-                    current_id,
-                    (function ? "specific" : "generic"),
-                    decl_name.c_str(),
-                    ss.GetData(),
-                    ast_dumper.GetCString());
+  if (copied_clang_type.IsAggregateType() &&
+      copied_clang_type.GetCompleteType()) {
+    CompilerType void_clang_type =
+        ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid);
+    CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
+
+    CompilerType method_type = ClangASTContext::CreateFunctionType(
+        m_ast_context, void_clang_type, &void_ptr_clang_type, 1, false, 0);
+
+    const bool is_virtual = false;
+    const bool is_static = false;
+    const bool is_inline = false;
+    const bool is_explicit = false;
+    const bool is_attr_used = true;
+    const bool is_artificial = false;
+
+    CXXMethodDecl *method_decl =
+        ClangASTContext::GetASTContext(m_ast_context)
+            ->AddMethodToCXXRecordType(
+                copied_clang_type.GetOpaqueQualType(), "$__lldb_expr",
+                method_type, lldb::eAccessPublic, is_virtual, is_static,
+                is_inline, is_explicit, is_attr_used, is_artificial);
+
+    if (log) {
+      ASTDumper method_ast_dumper((clang::Decl *)method_decl);
+      ASTDumper type_ast_dumper(copied_clang_type);
+
+      log->Printf("  CEDM::AddThisType Added function $__lldb_expr "
+                  "(description %s) for this type %s",
+                  method_ast_dumper.GetCString(), type_ast_dumper.GetCString());
     }
-}
+  }
 
-void
-ClangExpressionDeclMap::AddThisType(NameSearchContext &context,
-                                    TypeFromUser &ut,
-                                    unsigned int current_id)
-{
-    CompilerType copied_clang_type = GuardedCopyType(ut);
+  if (!copied_clang_type.IsValid())
+    return;
 
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+  TypeSourceInfo *type_source_info = m_ast_context->getTrivialTypeSourceInfo(
+      QualType::getFromOpaquePtr(copied_clang_type.GetOpaqueQualType()));
 
-    if (!copied_clang_type)
-    {
-        if (log)
-            log->Printf("ClangExpressionDeclMap::AddThisType - Couldn't import the type");
+  if (!type_source_info)
+    return;
 
-        return;
-    }
+  // Construct a typedef type because if "*this" is a templated type we can't
+  // just return ClassTemplateSpecializationDecls in response to name queries.
+  // Using a typedef makes this much more robust.
+
+  TypedefDecl *typedef_decl = TypedefDecl::Create(
+      *m_ast_context, m_ast_context->getTranslationUnitDecl(), SourceLocation(),
+      SourceLocation(), context.m_decl_name.getAsIdentifierInfo(),
+      type_source_info);
 
-    if (copied_clang_type.IsAggregateType() && copied_clang_type.GetCompleteType ())
-    {
-        CompilerType void_clang_type = ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid);
-        CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
-
-        CompilerType method_type = ClangASTContext::CreateFunctionType (m_ast_context,
-                                                                        void_clang_type,
-                                                                        &void_ptr_clang_type,
-                                                                        1,
-                                                                        false,
-                                                                        0);
-
-        const bool is_virtual = false;
-        const bool is_static = false;
-        const bool is_inline = false;
-        const bool is_explicit = false;
-        const bool is_attr_used = true;
-        const bool is_artificial = false;
-
-        CXXMethodDecl *method_decl = ClangASTContext::GetASTContext(m_ast_context)->
-            AddMethodToCXXRecordType (copied_clang_type.GetOpaqueQualType(),
-                                      "$__lldb_expr",
-                                      method_type,
-                                      lldb::eAccessPublic,
-                                      is_virtual,
-                                      is_static,
-                                      is_inline,
-                                      is_explicit,
-                                      is_attr_used,
-                                      is_artificial);
-        
-        if (log)
-        {
-            ASTDumper method_ast_dumper((clang::Decl*)method_decl);
-            ASTDumper type_ast_dumper(copied_clang_type);
-        
-            log->Printf("  CEDM::AddThisType Added function $__lldb_expr (description %s) for this type %s",
-                        method_ast_dumper.GetCString(),
-                        type_ast_dumper.GetCString());
-        }
-    }
+  if (!typedef_decl)
+    return;
 
-    if (!copied_clang_type.IsValid())
-        return;
-    
-    TypeSourceInfo *type_source_info = m_ast_context->getTrivialTypeSourceInfo(QualType::getFromOpaquePtr(copied_clang_type.GetOpaqueQualType()));
-    
-    if (!type_source_info)
-        return;
-    
-    // Construct a typedef type because if "*this" is a templated type we can't just return ClassTemplateSpecializationDecls in response to name queries.
-    // Using a typedef makes this much more robust.
-    
-    TypedefDecl *typedef_decl = TypedefDecl::Create(*m_ast_context,
-                                                    m_ast_context->getTranslationUnitDecl(),
-                                                    SourceLocation(),
-                                                    SourceLocation(),
-                                                    context.m_decl_name.getAsIdentifierInfo(),
-                                                    type_source_info);
-    
-    
-    if (!typedef_decl)
-        return;
-    
-    context.AddNamedDecl(typedef_decl);
+  context.AddNamedDecl(typedef_decl);
 
-    return;
+  return;
 }
 
-void
-ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
-                                   TypeFromUser &ut,
-                                   unsigned int current_id)
-{
-    CompilerType copied_clang_type = GuardedCopyType(ut);
-
-    if (!copied_clang_type)
-    {
-        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+void ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
+                                        TypeFromUser &ut,
+                                        unsigned int current_id) {
+  CompilerType copied_clang_type = GuardedCopyType(ut);
 
-        if (log)
-            log->Printf("ClangExpressionDeclMap::AddOneType - Couldn't import the type");
+  if (!copied_clang_type) {
+    Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-        return;
-    }
+    if (log)
+      log->Printf(
+          "ClangExpressionDeclMap::AddOneType - Couldn't import the type");
+
+    return;
+  }
 
-    context.AddTypeDecl(copied_clang_type);
+  context.AddTypeDecl(copied_clang_type);
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h Tue Sep  6 15:57:50 2016
@@ -17,37 +17,40 @@
 // C++ Includes
 #include <vector>
 
-#include "ClangExpressionVariable.h"
 #include "ClangASTSource.h"
+#include "ClangExpressionVariable.h"
 
 // Other libraries and framework includes
 // Project includes
-#include "llvm/ADT/DenseMap.h"
-#include "clang/AST/Decl.h"
-#include "lldb/lldb-public.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Expression/Materializer.h"
-#include "lldb/Symbol/TaggedASTType.h"
 #include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Symbol/TaggedASTType.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-public.h"
+#include "clang/AST/Decl.h"
+#include "llvm/ADT/DenseMap.h"
 
 namespace lldb_private {
 
 //----------------------------------------------------------------------
-/// @class ClangExpressionDeclMap ClangExpressionDeclMap.h "lldb/Expression/ClangExpressionDeclMap.h"
+/// @class ClangExpressionDeclMap ClangExpressionDeclMap.h
+/// "lldb/Expression/ClangExpressionDeclMap.h"
 /// @brief Manages named entities that are defined in LLDB's debug information.
 ///
 /// The Clang parser uses the ClangASTSource as an interface to request named
-/// entities from outside an expression.  The ClangASTSource reports back, listing
+/// entities from outside an expression.  The ClangASTSource reports back,
+/// listing
 /// all possible objects corresponding to a particular name.  But it in turn
-/// relies on ClangExpressionDeclMap, which performs several important functions.
+/// relies on ClangExpressionDeclMap, which performs several important
+/// functions.
 ///
 /// First, it records what variables and functions were looked up and what Decls
 /// were returned for them.
 ///
-/// Second, it constructs a struct on behalf of IRForTarget, recording which 
-/// variables should be placed where and relaying this information back so that 
+/// Second, it constructs a struct on behalf of IRForTarget, recording which
+/// variables should be placed where and relaying this information back so that
 /// IRForTarget can generate context-independent code.
 ///
 /// Third, it "materializes" this struct on behalf of the expression command,
@@ -57,642 +60,581 @@ namespace lldb_private {
 /// Fourth and finally, it "dematerializes" the struct after the JITted code has
 /// has executed, placing the new values back where it found the old ones.
 //----------------------------------------------------------------------
-class ClangExpressionDeclMap : 
-    public ClangASTSource
-{
+class ClangExpressionDeclMap : public ClangASTSource {
 public:
-    //------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// Initializes class variables.
-    ///
-    /// @param[in] keep_result_in_memory
-    ///     If true, inhibits the normal deallocation of the memory for
-    ///     the result persistent variable, and instead marks the variable
-    ///     as persisting.
-    ///
-    /// @param[in] delegate
-    ///     If non-NULL, use this delegate to report result values.  This
-    ///     allows the client ClangUserExpression to report a result.
-    ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use when parsing.
-    //------------------------------------------------------------------
-    ClangExpressionDeclMap (bool keep_result_in_memory,
-                            Materializer::PersistentVariableDelegate *result_delegate,
-                            ExecutionContext &exe_ctx);
-    
-    //------------------------------------------------------------------
-    /// Destructor
-    //------------------------------------------------------------------
-    ~ClangExpressionDeclMap() override;
-    
-    //------------------------------------------------------------------
-    /// Enable the state needed for parsing and IR transformation.
-    ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use when finding types for variables.
-    ///     Also used to find a "scratch" AST context to store result types.
-    ///
-    /// @param[in] materializer
-    ///     If non-NULL, the materializer to populate with information about
-    ///     the variables to use
-    ///
-    /// @return
-    ///     True if parsing is possible; false if it is unsafe to continue.
-    //------------------------------------------------------------------
-    bool
-    WillParse (ExecutionContext &exe_ctx,
-               Materializer *materializer);
-    
-    void
-    InstallCodeGenerator (clang::ASTConsumer *code_gen);
-    
-    //------------------------------------------------------------------
-    /// [Used by ClangExpressionParser] For each variable that had an unknown
-    ///     type at the beginning of parsing, determine its final type now.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    ResolveUnknownTypes();
-    
-    //------------------------------------------------------------------
-    /// Disable the state needed for parsing and IR transformation.
-    //------------------------------------------------------------------
-    void 
-    DidParse ();
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Add a variable to the list of persistent
-    ///     variables for the process.
-    ///
-    /// @param[in] decl
-    ///     The Clang declaration for the persistent variable, used for
-    ///     lookup during parsing.
-    ///
-    /// @param[in] name
-    ///     The name of the persistent variable, usually $something.
-    ///
-    /// @param[in] type
-    ///     The type of the variable, in the Clang parser's context.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    AddPersistentVariable (const clang::NamedDecl *decl,
-                           const ConstString &name, 
-                           TypeFromParser type,
-                           bool is_result,
-                           bool is_lvalue);
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Add a variable to the struct that needs to
-    ///     be materialized each time the expression runs.
-    ///
-    /// @param[in] decl
-    ///     The Clang declaration for the variable.
-    ///
-    /// @param[in] name
-    ///     The name of the variable.
-    ///
-    /// @param[in] value
-    ///     The LLVM IR value for this variable.
-    ///
-    /// @param[in] size
-    ///     The size of the variable in bytes.
-    ///
-    /// @param[in] alignment
-    ///     The required alignment of the variable in bytes.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    AddValueToStruct (const clang::NamedDecl *decl,
-                      const ConstString &name,
-                      llvm::Value *value,
-                      size_t size,
-                      lldb::offset_t alignment);
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Finalize the struct, laying out the position 
-    /// of each object in it.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    DoStructLayout ();
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Get general information about the laid-out
-    /// struct after DoStructLayout() has been called.
-    ///
-    /// @param[out] num_elements
-    ///     The number of elements in the struct.
-    ///
-    /// @param[out] size
-    ///     The size of the struct, in bytes.
-    ///
-    /// @param[out] alignment
-    ///     The alignment of the struct, in bytes.
-    ///
-    /// @return
-    ///     True if the information could be retrieved; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    GetStructInfo (uint32_t &num_elements,
-                   size_t &size,
-                   lldb::offset_t &alignment);
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Get specific information about one field
-    /// of the laid-out struct after DoStructLayout() has been called.
-    ///
-    /// @param[out] decl
-    ///     The parsed Decl for the field, as generated by ClangASTSource
-    ///     on ClangExpressionDeclMap's behalf.  In the case of the result
-    ///     value, this will have the name $__lldb_result even if the
-    ///     result value ends up having the name $1.  This is an
-    ///     implementation detail of IRForTarget.
-    ///
-    /// @param[out] value
-    ///     The IR value for the field (usually a GlobalVariable).  In
-    ///     the case of the result value, this will have the correct
-    ///     name ($1, for instance).  This is an implementation detail
-    ///     of IRForTarget.
-    ///
-    /// @param[out] offset
-    ///     The offset of the field from the beginning of the struct.
-    ///     As long as the struct is aligned according to its required
-    ///     alignment, this offset will align the field correctly.
-    ///
-    /// @param[out] name
-    ///     The name of the field as used in materialization.
-    ///
-    /// @param[in] index
-    ///     The index of the field about which information is requested.
-    ///
-    /// @return
-    ///     True if the information could be retrieved; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    GetStructElement (const clang::NamedDecl *&decl,
-                      llvm::Value *&value,
-                      lldb::offset_t &offset,
-                      ConstString &name,
-                      uint32_t index);
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Get information about a function given its
-    /// Decl.
-    ///
-    /// @param[in] decl
-    ///     The parsed Decl for the Function, as generated by ClangASTSource
-    ///     on ClangExpressionDeclMap's behalf.
-    ///
-    /// @param[out] ptr
-    ///     The absolute address of the function in the target.
-    ///
-    /// @return
-    ///     True if the information could be retrieved; false otherwise.
-    //------------------------------------------------------------------
-    bool 
-    GetFunctionInfo (const clang::NamedDecl *decl, 
-                     uint64_t &ptr);
-    
-    //------------------------------------------------------------------
-    /// [Used by IRForTarget] Get the address of a symbol given nothing
-    /// but its name.
-    ///
-    /// @param[in] target
-    ///     The target to find the symbol in.  If not provided,
-    ///     then the current parsing context's Target.
-    ///
-    /// @param[in] process
-    ///     The process to use.  For Objective-C symbols, the process's
-    ///     Objective-C language runtime may be queried if the process
-    ///     is non-NULL.
-    ///
-    /// @param[in] name
-    ///     The name of the symbol.  
-    ///
-    /// @param[in] module
-    ///     The module to limit the search to. This can be NULL
-    ///
-    /// @return
-    ///     Valid load address for the symbol
-    //------------------------------------------------------------------
-    lldb::addr_t 
-    GetSymbolAddress (Target &target,
-                      Process *process,
-                      const ConstString &name,
-                      lldb::SymbolType symbol_type,
-                      Module *module = NULL);
-    
-    lldb::addr_t
-    GetSymbolAddress (const ConstString &name,
-                      lldb::SymbolType symbol_type);
-    
-    //------------------------------------------------------------------
-    /// [Used by IRInterpreter] Get basic target information.
-    ///
-    /// @param[out] byte_order
-    ///     The byte order of the target.
-    ///
-    /// @param[out] address_byte_size
-    ///     The size of a pointer in bytes.
-    ///
-    /// @return
-    ///     True if the information could be determined; false 
-    ///     otherwise.
-    //------------------------------------------------------------------
-    struct TargetInfo
-    {
-        lldb::ByteOrder byte_order;
-        size_t address_byte_size;
-        
-        TargetInfo() :
-            byte_order(lldb::eByteOrderInvalid),
-            address_byte_size(0)
-        {
-        }
-        
-        bool IsValid()
-        {
-            return (byte_order != lldb::eByteOrderInvalid &&
-                    address_byte_size != 0);
-        }
-    };
-    TargetInfo GetTargetInfo();
-    
-    //------------------------------------------------------------------
-    /// [Used by ClangASTSource] Find all entities matching a given name,
-    /// using a NameSearchContext to make Decls for them.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext that can construct Decls for this name.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    void 
-    FindExternalVisibleDecls(NameSearchContext &context) override;
-    
-    //------------------------------------------------------------------
-    /// Find all entities matching a given name in a given module/namespace,
-    /// using a NameSearchContext to make Decls for them.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext that can construct Decls for this name.
-    ///
-    /// @param[in] module
-    ///     If non-NULL, the module to query.
-    ///
-    /// @param[in] namespace_decl
-    ///     If valid and module is non-NULL, the parent namespace.
-    ///
-    /// @param[in] name
-    ///     The name as a plain C string.  The NameSearchContext contains 
-    ///     a DeclarationName for the name so at first the name may seem
-    ///     redundant, but ClangExpressionDeclMap operates in RTTI land so 
-    ///     it can't access DeclarationName.
-    ///
-    /// @param[in] current_id
-    ///     The ID for the current FindExternalVisibleDecls invocation,
-    ///     for logging purposes.
-    ///
-    /// @return
-    ///     True on success; false otherwise.
-    //------------------------------------------------------------------
-    void 
-    FindExternalVisibleDecls (NameSearchContext &context, 
-                              lldb::ModuleSP module,
-                              CompilerDeclContext &namespace_decl,
-                              unsigned int current_id);
-private:
-    ExpressionVariableList      m_found_entities;           ///< All entities that were looked up for the parser.
-    ExpressionVariableList      m_struct_members;           ///< All entities that need to be placed in the struct.
-    bool                        m_keep_result_in_memory;    ///< True if result persistent variables generated by this expression should stay in memory.
-    Materializer::PersistentVariableDelegate *m_result_delegate;  ///< If non-NULL, used to report expression results to ClangUserExpression.
-    
-    //----------------------------------------------------------------------
-    /// The following values should not live beyond parsing
-    //----------------------------------------------------------------------
-    class ParserVars 
-    {
-    public:
-        ParserVars(ClangExpressionDeclMap &decl_map) :
-            m_decl_map(decl_map)
-        {
-        }
-        
-        Target *
-        GetTarget()
-        {
-            if (m_exe_ctx.GetTargetPtr())
-                return m_exe_ctx.GetTargetPtr();
-            else if (m_sym_ctx.target_sp)
-                m_sym_ctx.target_sp.get();
-            return NULL;
-        }
-        
-        ExecutionContext            m_exe_ctx;                      ///< The execution context to use when parsing.
-        SymbolContext               m_sym_ctx;                      ///< The symbol context to use in finding variables and types.
-        ClangPersistentVariables   *m_persistent_vars = nullptr;    ///< The persistent variables for the process.
-        bool                        m_enable_lookups = false;       ///< Set to true during parsing if we have found the first "$__lldb" name.
-        TargetInfo                  m_target_info;                  ///< Basic information about the target.
-        Materializer               *m_materializer = nullptr;       ///< If non-NULL, the materializer to use when reporting used variables.
-        clang::ASTConsumer         *m_code_gen = nullptr;           ///< If non-NULL, a code generator that receives new top-level functions.
-    private:
-        ClangExpressionDeclMap     &m_decl_map;
-        DISALLOW_COPY_AND_ASSIGN (ParserVars);
-    };
-    
-    std::unique_ptr<ParserVars> m_parser_vars;
-    
-    //----------------------------------------------------------------------
-    /// Activate parser-specific variables
-    //----------------------------------------------------------------------
-    void 
-    EnableParserVars()
-    {
-        if (!m_parser_vars.get())
-            m_parser_vars.reset(new ParserVars(*this));
-    }
-    
-    //----------------------------------------------------------------------
-    /// Deallocate parser-specific variables
-    //----------------------------------------------------------------------
-    void 
-    DisableParserVars()
-    {
-        m_parser_vars.reset();
-    }
-    
-    //----------------------------------------------------------------------
-    /// The following values contain layout information for the materialized
-    /// struct, but are not specific to a single materialization
-    //----------------------------------------------------------------------
-    struct StructVars {
-        StructVars() :
-            m_struct_alignment(0),
-            m_struct_size(0),
-            m_struct_laid_out(false),
-            m_result_name(),
-            m_object_pointer_type(NULL, NULL)
-        {
-        }
-        
-        lldb::offset_t              m_struct_alignment;         ///< The alignment of the struct in bytes.
-        size_t                      m_struct_size;              ///< The size of the struct in bytes.
-        bool                        m_struct_laid_out;          ///< True if the struct has been laid out and the layout is valid (that is, no new fields have been added since).
-        ConstString                 m_result_name;              ///< The name of the result variable ($1, for example)
-        TypeFromUser                m_object_pointer_type;      ///< The type of the "this" variable, if one exists
-    };
-    
-    std::unique_ptr<StructVars> m_struct_vars;
-    
-    //----------------------------------------------------------------------
-    /// Activate struct variables
-    //----------------------------------------------------------------------
-    void 
-    EnableStructVars()
-    {
-        if (!m_struct_vars.get())
-            m_struct_vars.reset(new struct StructVars);
-    }
-    
-    //----------------------------------------------------------------------
-    /// Deallocate struct variables
-    //----------------------------------------------------------------------
-    void
-    DisableStructVars()
-    {
-        m_struct_vars.reset();
+  //------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// Initializes class variables.
+  ///
+  /// @param[in] keep_result_in_memory
+  ///     If true, inhibits the normal deallocation of the memory for
+  ///     the result persistent variable, and instead marks the variable
+  ///     as persisting.
+  ///
+  /// @param[in] delegate
+  ///     If non-NULL, use this delegate to report result values.  This
+  ///     allows the client ClangUserExpression to report a result.
+  ///
+  /// @param[in] exe_ctx
+  ///     The execution context to use when parsing.
+  //------------------------------------------------------------------
+  ClangExpressionDeclMap(
+      bool keep_result_in_memory,
+      Materializer::PersistentVariableDelegate *result_delegate,
+      ExecutionContext &exe_ctx);
+
+  //------------------------------------------------------------------
+  /// Destructor
+  //------------------------------------------------------------------
+  ~ClangExpressionDeclMap() override;
+
+  //------------------------------------------------------------------
+  /// Enable the state needed for parsing and IR transformation.
+  ///
+  /// @param[in] exe_ctx
+  ///     The execution context to use when finding types for variables.
+  ///     Also used to find a "scratch" AST context to store result types.
+  ///
+  /// @param[in] materializer
+  ///     If non-NULL, the materializer to populate with information about
+  ///     the variables to use
+  ///
+  /// @return
+  ///     True if parsing is possible; false if it is unsafe to continue.
+  //------------------------------------------------------------------
+  bool WillParse(ExecutionContext &exe_ctx, Materializer *materializer);
+
+  void InstallCodeGenerator(clang::ASTConsumer *code_gen);
+
+  //------------------------------------------------------------------
+  /// [Used by ClangExpressionParser] For each variable that had an unknown
+  ///     type at the beginning of parsing, determine its final type now.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  bool ResolveUnknownTypes();
+
+  //------------------------------------------------------------------
+  /// Disable the state needed for parsing and IR transformation.
+  //------------------------------------------------------------------
+  void DidParse();
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Add a variable to the list of persistent
+  ///     variables for the process.
+  ///
+  /// @param[in] decl
+  ///     The Clang declaration for the persistent variable, used for
+  ///     lookup during parsing.
+  ///
+  /// @param[in] name
+  ///     The name of the persistent variable, usually $something.
+  ///
+  /// @param[in] type
+  ///     The type of the variable, in the Clang parser's context.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  bool AddPersistentVariable(const clang::NamedDecl *decl,
+                             const ConstString &name, TypeFromParser type,
+                             bool is_result, bool is_lvalue);
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Add a variable to the struct that needs to
+  ///     be materialized each time the expression runs.
+  ///
+  /// @param[in] decl
+  ///     The Clang declaration for the variable.
+  ///
+  /// @param[in] name
+  ///     The name of the variable.
+  ///
+  /// @param[in] value
+  ///     The LLVM IR value for this variable.
+  ///
+  /// @param[in] size
+  ///     The size of the variable in bytes.
+  ///
+  /// @param[in] alignment
+  ///     The required alignment of the variable in bytes.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  bool AddValueToStruct(const clang::NamedDecl *decl, const ConstString &name,
+                        llvm::Value *value, size_t size,
+                        lldb::offset_t alignment);
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Finalize the struct, laying out the position
+  /// of each object in it.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  bool DoStructLayout();
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Get general information about the laid-out
+  /// struct after DoStructLayout() has been called.
+  ///
+  /// @param[out] num_elements
+  ///     The number of elements in the struct.
+  ///
+  /// @param[out] size
+  ///     The size of the struct, in bytes.
+  ///
+  /// @param[out] alignment
+  ///     The alignment of the struct, in bytes.
+  ///
+  /// @return
+  ///     True if the information could be retrieved; false otherwise.
+  //------------------------------------------------------------------
+  bool GetStructInfo(uint32_t &num_elements, size_t &size,
+                     lldb::offset_t &alignment);
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Get specific information about one field
+  /// of the laid-out struct after DoStructLayout() has been called.
+  ///
+  /// @param[out] decl
+  ///     The parsed Decl for the field, as generated by ClangASTSource
+  ///     on ClangExpressionDeclMap's behalf.  In the case of the result
+  ///     value, this will have the name $__lldb_result even if the
+  ///     result value ends up having the name $1.  This is an
+  ///     implementation detail of IRForTarget.
+  ///
+  /// @param[out] value
+  ///     The IR value for the field (usually a GlobalVariable).  In
+  ///     the case of the result value, this will have the correct
+  ///     name ($1, for instance).  This is an implementation detail
+  ///     of IRForTarget.
+  ///
+  /// @param[out] offset
+  ///     The offset of the field from the beginning of the struct.
+  ///     As long as the struct is aligned according to its required
+  ///     alignment, this offset will align the field correctly.
+  ///
+  /// @param[out] name
+  ///     The name of the field as used in materialization.
+  ///
+  /// @param[in] index
+  ///     The index of the field about which information is requested.
+  ///
+  /// @return
+  ///     True if the information could be retrieved; false otherwise.
+  //------------------------------------------------------------------
+  bool GetStructElement(const clang::NamedDecl *&decl, llvm::Value *&value,
+                        lldb::offset_t &offset, ConstString &name,
+                        uint32_t index);
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Get information about a function given its
+  /// Decl.
+  ///
+  /// @param[in] decl
+  ///     The parsed Decl for the Function, as generated by ClangASTSource
+  ///     on ClangExpressionDeclMap's behalf.
+  ///
+  /// @param[out] ptr
+  ///     The absolute address of the function in the target.
+  ///
+  /// @return
+  ///     True if the information could be retrieved; false otherwise.
+  //------------------------------------------------------------------
+  bool GetFunctionInfo(const clang::NamedDecl *decl, uint64_t &ptr);
+
+  //------------------------------------------------------------------
+  /// [Used by IRForTarget] Get the address of a symbol given nothing
+  /// but its name.
+  ///
+  /// @param[in] target
+  ///     The target to find the symbol in.  If not provided,
+  ///     then the current parsing context's Target.
+  ///
+  /// @param[in] process
+  ///     The process to use.  For Objective-C symbols, the process's
+  ///     Objective-C language runtime may be queried if the process
+  ///     is non-NULL.
+  ///
+  /// @param[in] name
+  ///     The name of the symbol.
+  ///
+  /// @param[in] module
+  ///     The module to limit the search to. This can be NULL
+  ///
+  /// @return
+  ///     Valid load address for the symbol
+  //------------------------------------------------------------------
+  lldb::addr_t GetSymbolAddress(Target &target, Process *process,
+                                const ConstString &name,
+                                lldb::SymbolType symbol_type,
+                                Module *module = NULL);
+
+  lldb::addr_t GetSymbolAddress(const ConstString &name,
+                                lldb::SymbolType symbol_type);
+
+  //------------------------------------------------------------------
+  /// [Used by IRInterpreter] Get basic target information.
+  ///
+  /// @param[out] byte_order
+  ///     The byte order of the target.
+  ///
+  /// @param[out] address_byte_size
+  ///     The size of a pointer in bytes.
+  ///
+  /// @return
+  ///     True if the information could be determined; false
+  ///     otherwise.
+  //------------------------------------------------------------------
+  struct TargetInfo {
+    lldb::ByteOrder byte_order;
+    size_t address_byte_size;
+
+    TargetInfo() : byte_order(lldb::eByteOrderInvalid), address_byte_size(0) {}
+
+    bool IsValid() {
+      return (byte_order != lldb::eByteOrderInvalid && address_byte_size != 0);
     }
-    
-    //----------------------------------------------------------------------
-    /// Get this parser's ID for use in extracting parser- and JIT-specific
-    /// data from persistent variables.
-    //----------------------------------------------------------------------
-    uint64_t
-    GetParserID()
-    {
-        return (uint64_t)this;
+  };
+  TargetInfo GetTargetInfo();
+
+  //------------------------------------------------------------------
+  /// [Used by ClangASTSource] Find all entities matching a given name,
+  /// using a NameSearchContext to make Decls for them.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext that can construct Decls for this name.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  void FindExternalVisibleDecls(NameSearchContext &context) override;
+
+  //------------------------------------------------------------------
+  /// Find all entities matching a given name in a given module/namespace,
+  /// using a NameSearchContext to make Decls for them.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext that can construct Decls for this name.
+  ///
+  /// @param[in] module
+  ///     If non-NULL, the module to query.
+  ///
+  /// @param[in] namespace_decl
+  ///     If valid and module is non-NULL, the parent namespace.
+  ///
+  /// @param[in] name
+  ///     The name as a plain C string.  The NameSearchContext contains
+  ///     a DeclarationName for the name so at first the name may seem
+  ///     redundant, but ClangExpressionDeclMap operates in RTTI land so
+  ///     it can't access DeclarationName.
+  ///
+  /// @param[in] current_id
+  ///     The ID for the current FindExternalVisibleDecls invocation,
+  ///     for logging purposes.
+  ///
+  /// @return
+  ///     True on success; false otherwise.
+  //------------------------------------------------------------------
+  void FindExternalVisibleDecls(NameSearchContext &context,
+                                lldb::ModuleSP module,
+                                CompilerDeclContext &namespace_decl,
+                                unsigned int current_id);
+
+private:
+  ExpressionVariableList
+      m_found_entities; ///< All entities that were looked up for the parser.
+  ExpressionVariableList
+      m_struct_members; ///< All entities that need to be placed in the struct.
+  bool m_keep_result_in_memory; ///< True if result persistent variables
+                                ///generated by this expression should stay in
+                                ///memory.
+  Materializer::PersistentVariableDelegate
+      *m_result_delegate; ///< If non-NULL, used to report expression results to
+                          ///ClangUserExpression.
+
+  //----------------------------------------------------------------------
+  /// The following values should not live beyond parsing
+  //----------------------------------------------------------------------
+  class ParserVars {
+  public:
+    ParserVars(ClangExpressionDeclMap &decl_map) : m_decl_map(decl_map) {}
+
+    Target *GetTarget() {
+      if (m_exe_ctx.GetTargetPtr())
+        return m_exe_ctx.GetTargetPtr();
+      else if (m_sym_ctx.target_sp)
+        m_sym_ctx.target_sp.get();
+      return NULL;
     }
-    
-    //------------------------------------------------------------------
-    /// Given a target, find a data symbol that has the given name.
-    ///
-    /// @param[in] target
-    ///     The target to use as the basis for the search.
-    ///
-    /// @param[in] name
-    ///     The name as a plain C string.
-    ///
-    /// @param[in] module
-    ///     The module to limit the search to. This can be NULL
-    ///
-    /// @return
-    ///     The LLDB Symbol found, or NULL if none was found.
-    //------------------------------------------------------------------
-    const Symbol *
-    FindGlobalDataSymbol (Target &target,
-                          const ConstString &name,
-                          Module *module = NULL);
-    
-    //------------------------------------------------------------------
-    /// Given a target, find a variable that matches the given name and 
-    /// type.
-    ///
-    /// @param[in] target
-    ///     The target to use as a basis for finding the variable.
-    ///
-    /// @param[in] module
-    ///     If non-NULL, the module to search.
-    ///
-    /// @param[in] name
-    ///     The name as a plain C string.
-    ///
-    /// @param[in] namespace_decl
-    ///     If non-NULL and module is non-NULL, the parent namespace.
-    ///
-    /// @param[in] type
-    ///     The required type for the variable.  This function may be called
-    ///     during parsing, in which case we don't know its type; hence the
-    ///     default.
-    ///
-    /// @return
-    ///     The LLDB Variable found, or NULL if none was found.
-    //------------------------------------------------------------------
-    lldb::VariableSP
-    FindGlobalVariable (Target &target,
-                        lldb::ModuleSP &module,
-                        const ConstString &name,
-                        CompilerDeclContext *namespace_decl,
-                        TypeFromUser *type = NULL);
-    
-    //------------------------------------------------------------------
-    /// Get the value of a variable in a given execution context and return
-    /// the associated Types if needed.
-    ///
-    /// @param[in] var
-    ///     The variable to evaluate.
-    ///
-    /// @param[out] var_location
-    ///     The variable location value to fill in
-    ///
-    /// @param[out] found_type
-    ///     The type of the found value, as it was found in the user process.
-    ///     This is only useful when the variable is being inspected on behalf
-    ///     of the parser, hence the default.
-    ///
-    /// @param[out] parser_type
-    ///     The type of the found value, as it was copied into the parser's
-    ///     AST context.  This is only useful when the variable is being
-    ///     inspected on behalf of the parser, hence the default.
-    ///
-    /// @param[in] decl
-    ///     The Decl to be looked up.
-    ///
-    /// @return
-    ///     Return true if the value was successfully filled in.
-    //------------------------------------------------------------------
-    bool
-    GetVariableValue (lldb::VariableSP &var,
-                      lldb_private::Value &var_location,
-                      TypeFromUser *found_type = NULL,
-                      TypeFromParser *parser_type = NULL);
-    
-    //------------------------------------------------------------------
-    /// Use the NameSearchContext to generate a Decl for the given LLDB
-    /// Variable, and put it in the Tuple list.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] var
-    ///     The LLDB Variable that needs a Decl.
-    ///
-    /// @param[in] valobj
-    ///     The LLDB ValueObject for that variable.
-    //------------------------------------------------------------------
-    void 
-    AddOneVariable (NameSearchContext &context, 
-                    lldb::VariableSP var,
-                    lldb::ValueObjectSP valobj,
-                    unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Use the NameSearchContext to generate a Decl for the given
-    /// persistent variable, and put it in the list of found entities.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] pvar
-    ///     The persistent variable that needs a Decl.
-    ///
-    /// @param[in] current_id
-    ///     The ID of the current invocation of FindExternalVisibleDecls
-    ///     for logging purposes.
-    //------------------------------------------------------------------
-    void 
-    AddOneVariable (NameSearchContext &context, 
-                    lldb::ExpressionVariableSP &pvar_sp,
-                    unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Use the NameSearchContext to generate a Decl for the given LLDB
-    /// symbol (treated as a variable), and put it in the list of found
-    /// entities.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] var
-    ///     The LLDB Variable that needs a Decl.
-    //------------------------------------------------------------------
-    void
-    AddOneGenericVariable (NameSearchContext &context,
-                           const Symbol &symbol,
-                           unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Use the NameSearchContext to generate a Decl for the given
-    /// function.  (Functions are not placed in the Tuple list.)  Can
-    /// handle both fully typed functions and generic functions.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] fun
-    ///     The Function that needs to be created.  If non-NULL, this is
-    ///     a fully-typed function.
-    ///
-    /// @param[in] sym
-    ///     The Symbol that corresponds to a function that needs to be 
-    ///     created with generic type (unitptr_t foo(...)).
-    //------------------------------------------------------------------
-    void
-    AddOneFunction (NameSearchContext &context, 
-                    Function *fun, 
-                    Symbol *sym,
-                    unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Use the NameSearchContext to generate a Decl for the given
-    /// register.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] reg_info
-    ///     The information corresponding to that register.
-    //------------------------------------------------------------------
-    void 
-    AddOneRegister (NameSearchContext &context, 
-                    const RegisterInfo *reg_info,
-                    unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Use the NameSearchContext to generate a Decl for the given
-    /// type.  (Types are not placed in the Tuple list.)
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] type
-    ///     The type that needs to be created.
-    //------------------------------------------------------------------
-    void 
-    AddOneType (NameSearchContext &context, 
-                TypeFromUser &type,
-                unsigned int current_id);
-    
-    //------------------------------------------------------------------
-    /// Generate a Decl for "*this" and add a member function declaration
-    /// to it for the expression, then report it.
-    ///
-    /// @param[in] context
-    ///     The NameSearchContext to use when constructing the Decl.
-    ///
-    /// @param[in] type
-    ///     The type for *this.
-    //------------------------------------------------------------------
-    void
-    AddThisType(NameSearchContext &context,
-                TypeFromUser &type,
-                unsigned int current_id);
 
-    ClangASTContext *
-    GetClangASTContext();
+    ExecutionContext m_exe_ctx; ///< The execution context to use when parsing.
+    SymbolContext m_sym_ctx; ///< The symbol context to use in finding variables
+                             ///and types.
+    ClangPersistentVariables *m_persistent_vars =
+        nullptr; ///< The persistent variables for the process.
+    bool m_enable_lookups = false; ///< Set to true during parsing if we have
+                                   ///found the first "$__lldb" name.
+    TargetInfo m_target_info;      ///< Basic information about the target.
+    Materializer *m_materializer = nullptr;   ///< If non-NULL, the materializer
+                                              ///to use when reporting used
+                                              ///variables.
+    clang::ASTConsumer *m_code_gen = nullptr; ///< If non-NULL, a code generator
+                                              ///that receives new top-level
+                                              ///functions.
+  private:
+    ClangExpressionDeclMap &m_decl_map;
+    DISALLOW_COPY_AND_ASSIGN(ParserVars);
+  };
+
+  std::unique_ptr<ParserVars> m_parser_vars;
+
+  //----------------------------------------------------------------------
+  /// Activate parser-specific variables
+  //----------------------------------------------------------------------
+  void EnableParserVars() {
+    if (!m_parser_vars.get())
+      m_parser_vars.reset(new ParserVars(*this));
+  }
+
+  //----------------------------------------------------------------------
+  /// Deallocate parser-specific variables
+  //----------------------------------------------------------------------
+  void DisableParserVars() { m_parser_vars.reset(); }
+
+  //----------------------------------------------------------------------
+  /// The following values contain layout information for the materialized
+  /// struct, but are not specific to a single materialization
+  //----------------------------------------------------------------------
+  struct StructVars {
+    StructVars()
+        : m_struct_alignment(0), m_struct_size(0), m_struct_laid_out(false),
+          m_result_name(), m_object_pointer_type(NULL, NULL) {}
+
+    lldb::offset_t
+        m_struct_alignment; ///< The alignment of the struct in bytes.
+    size_t m_struct_size;   ///< The size of the struct in bytes.
+    bool m_struct_laid_out; ///< True if the struct has been laid out and the
+                            ///layout is valid (that is, no new fields have been
+                            ///added since).
+    ConstString
+        m_result_name; ///< The name of the result variable ($1, for example)
+    TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if
+                                        ///one exists
+  };
+
+  std::unique_ptr<StructVars> m_struct_vars;
+
+  //----------------------------------------------------------------------
+  /// Activate struct variables
+  //----------------------------------------------------------------------
+  void EnableStructVars() {
+    if (!m_struct_vars.get())
+      m_struct_vars.reset(new struct StructVars);
+  }
+
+  //----------------------------------------------------------------------
+  /// Deallocate struct variables
+  //----------------------------------------------------------------------
+  void DisableStructVars() { m_struct_vars.reset(); }
+
+  //----------------------------------------------------------------------
+  /// Get this parser's ID for use in extracting parser- and JIT-specific
+  /// data from persistent variables.
+  //----------------------------------------------------------------------
+  uint64_t GetParserID() { return (uint64_t) this; }
+
+  //------------------------------------------------------------------
+  /// Given a target, find a data symbol that has the given name.
+  ///
+  /// @param[in] target
+  ///     The target to use as the basis for the search.
+  ///
+  /// @param[in] name
+  ///     The name as a plain C string.
+  ///
+  /// @param[in] module
+  ///     The module to limit the search to. This can be NULL
+  ///
+  /// @return
+  ///     The LLDB Symbol found, or NULL if none was found.
+  //------------------------------------------------------------------
+  const Symbol *FindGlobalDataSymbol(Target &target, const ConstString &name,
+                                     Module *module = NULL);
+
+  //------------------------------------------------------------------
+  /// Given a target, find a variable that matches the given name and
+  /// type.
+  ///
+  /// @param[in] target
+  ///     The target to use as a basis for finding the variable.
+  ///
+  /// @param[in] module
+  ///     If non-NULL, the module to search.
+  ///
+  /// @param[in] name
+  ///     The name as a plain C string.
+  ///
+  /// @param[in] namespace_decl
+  ///     If non-NULL and module is non-NULL, the parent namespace.
+  ///
+  /// @param[in] type
+  ///     The required type for the variable.  This function may be called
+  ///     during parsing, in which case we don't know its type; hence the
+  ///     default.
+  ///
+  /// @return
+  ///     The LLDB Variable found, or NULL if none was found.
+  //------------------------------------------------------------------
+  lldb::VariableSP FindGlobalVariable(Target &target, lldb::ModuleSP &module,
+                                      const ConstString &name,
+                                      CompilerDeclContext *namespace_decl,
+                                      TypeFromUser *type = NULL);
+
+  //------------------------------------------------------------------
+  /// Get the value of a variable in a given execution context and return
+  /// the associated Types if needed.
+  ///
+  /// @param[in] var
+  ///     The variable to evaluate.
+  ///
+  /// @param[out] var_location
+  ///     The variable location value to fill in
+  ///
+  /// @param[out] found_type
+  ///     The type of the found value, as it was found in the user process.
+  ///     This is only useful when the variable is being inspected on behalf
+  ///     of the parser, hence the default.
+  ///
+  /// @param[out] parser_type
+  ///     The type of the found value, as it was copied into the parser's
+  ///     AST context.  This is only useful when the variable is being
+  ///     inspected on behalf of the parser, hence the default.
+  ///
+  /// @param[in] decl
+  ///     The Decl to be looked up.
+  ///
+  /// @return
+  ///     Return true if the value was successfully filled in.
+  //------------------------------------------------------------------
+  bool GetVariableValue(lldb::VariableSP &var,
+                        lldb_private::Value &var_location,
+                        TypeFromUser *found_type = NULL,
+                        TypeFromParser *parser_type = NULL);
+
+  //------------------------------------------------------------------
+  /// Use the NameSearchContext to generate a Decl for the given LLDB
+  /// Variable, and put it in the Tuple list.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] var
+  ///     The LLDB Variable that needs a Decl.
+  ///
+  /// @param[in] valobj
+  ///     The LLDB ValueObject for that variable.
+  //------------------------------------------------------------------
+  void AddOneVariable(NameSearchContext &context, lldb::VariableSP var,
+                      lldb::ValueObjectSP valobj, unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Use the NameSearchContext to generate a Decl for the given
+  /// persistent variable, and put it in the list of found entities.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] pvar
+  ///     The persistent variable that needs a Decl.
+  ///
+  /// @param[in] current_id
+  ///     The ID of the current invocation of FindExternalVisibleDecls
+  ///     for logging purposes.
+  //------------------------------------------------------------------
+  void AddOneVariable(NameSearchContext &context,
+                      lldb::ExpressionVariableSP &pvar_sp,
+                      unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Use the NameSearchContext to generate a Decl for the given LLDB
+  /// symbol (treated as a variable), and put it in the list of found
+  /// entities.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] var
+  ///     The LLDB Variable that needs a Decl.
+  //------------------------------------------------------------------
+  void AddOneGenericVariable(NameSearchContext &context, const Symbol &symbol,
+                             unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Use the NameSearchContext to generate a Decl for the given
+  /// function.  (Functions are not placed in the Tuple list.)  Can
+  /// handle both fully typed functions and generic functions.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] fun
+  ///     The Function that needs to be created.  If non-NULL, this is
+  ///     a fully-typed function.
+  ///
+  /// @param[in] sym
+  ///     The Symbol that corresponds to a function that needs to be
+  ///     created with generic type (unitptr_t foo(...)).
+  //------------------------------------------------------------------
+  void AddOneFunction(NameSearchContext &context, Function *fun, Symbol *sym,
+                      unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Use the NameSearchContext to generate a Decl for the given
+  /// register.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] reg_info
+  ///     The information corresponding to that register.
+  //------------------------------------------------------------------
+  void AddOneRegister(NameSearchContext &context, const RegisterInfo *reg_info,
+                      unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Use the NameSearchContext to generate a Decl for the given
+  /// type.  (Types are not placed in the Tuple list.)
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] type
+  ///     The type that needs to be created.
+  //------------------------------------------------------------------
+  void AddOneType(NameSearchContext &context, TypeFromUser &type,
+                  unsigned int current_id);
+
+  //------------------------------------------------------------------
+  /// Generate a Decl for "*this" and add a member function declaration
+  /// to it for the expression, then report it.
+  ///
+  /// @param[in] context
+  ///     The NameSearchContext to use when constructing the Decl.
+  ///
+  /// @param[in] type
+  ///     The type for *this.
+  //------------------------------------------------------------------
+  void AddThisType(NameSearchContext &context, TypeFromUser &type,
+                   unsigned int current_id);
+
+  ClangASTContext *GetClangASTContext();
 };
-    
+
 } // namespace lldb_private
 
 #endif // liblldb_ClangExpressionDeclMap_h_

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h Tue Sep  6 15:57:50 2016
@@ -12,17 +12,17 @@
 
 // C Includes
 // C++ Includes
-#include <string>
 #include <map>
+#include <string>
 #include <vector>
 
 // Other libraries and framework includes
 // Project includes
 
-#include "lldb/lldb-forward.h"
-#include "lldb/lldb-private.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Expression/ExpressionTypeSystemHelper.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private.h"
 
 namespace lldb_private {
 
@@ -31,52 +31,43 @@ class RecordingMemoryManager;
 //----------------------------------------------------------------------
 // ClangExpressionHelper
 //----------------------------------------------------------------------
-class ClangExpressionHelper : public ExpressionTypeSystemHelper
-{
+class ClangExpressionHelper : public ExpressionTypeSystemHelper {
 public:
-    static bool classof(const ExpressionTypeSystemHelper *ts)
-    {
-        return ts->getKind() == eKindClangHelper;
-    }
-
-    ClangExpressionHelper () :
-        ExpressionTypeSystemHelper(ExpressionTypeSystemHelper::LLVMCastKind::eKindClangHelper)
-    {
-    }
-
-    //------------------------------------------------------------------
-    /// Destructor
-    //------------------------------------------------------------------
-    virtual ~ClangExpressionHelper ()
-    {
-    }
-    
-    //------------------------------------------------------------------
-    /// Return the object that the parser should use when resolving external
-    /// values.  May be NULL if everything should be self-contained.
-    //------------------------------------------------------------------
-    virtual ClangExpressionDeclMap *
-    DeclMap () = 0;
-    
-    //------------------------------------------------------------------
-    /// Return the object that the parser should allow to access ASTs.
-    /// May be NULL if the ASTs do not need to be transformed.
-    ///
-    /// @param[in] passthrough
-    ///     The ASTConsumer that the returned transformer should send
-    ///     the ASTs to after transformation.
-    //------------------------------------------------------------------
-    virtual clang::ASTConsumer *
-    ASTTransformer(clang::ASTConsumer *passthrough) = 0;
-
-    virtual void
-    CommitPersistentDecls()
-    {
-    }
+  static bool classof(const ExpressionTypeSystemHelper *ts) {
+    return ts->getKind() == eKindClangHelper;
+  }
+
+  ClangExpressionHelper()
+      : ExpressionTypeSystemHelper(
+            ExpressionTypeSystemHelper::LLVMCastKind::eKindClangHelper) {}
+
+  //------------------------------------------------------------------
+  /// Destructor
+  //------------------------------------------------------------------
+  virtual ~ClangExpressionHelper() {}
+
+  //------------------------------------------------------------------
+  /// Return the object that the parser should use when resolving external
+  /// values.  May be NULL if everything should be self-contained.
+  //------------------------------------------------------------------
+  virtual ClangExpressionDeclMap *DeclMap() = 0;
+
+  //------------------------------------------------------------------
+  /// Return the object that the parser should allow to access ASTs.
+  /// May be NULL if the ASTs do not need to be transformed.
+  ///
+  /// @param[in] passthrough
+  ///     The ASTConsumer that the returned transformer should send
+  ///     the ASTs to after transformation.
+  //------------------------------------------------------------------
+  virtual clang::ASTConsumer *
+  ASTTransformer(clang::ASTConsumer *passthrough) = 0;
+
+  virtual void CommitPersistentDecls() {}
 
 protected:
 };
 
 } // namespace lldb_private
 
-#endif  // liblldb_ClangExpression_h_
+#endif // liblldb_ClangExpression_h_

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Tue Sep  6 15:57:50 2016
@@ -17,12 +17,12 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
-#include "clang/Basic/Version.h" 
+#include "clang/Basic/Version.h"
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/CodeGen/ModuleBuilder.h"
 #include "clang/Edit/Commit.h"
-#include "clang/Edit/EditsReceiver.h"
 #include "clang/Edit/EditedSource.h"
+#include "clang/Edit/EditsReceiver.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -32,8 +32,8 @@
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Parse/ParseAST.h"
-#include "clang/Rewrite/Frontend/FrontendActions.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Rewrite/Frontend/FrontendActions.h"
 #include "clang/Sema/SemaConsumer.h"
 #include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
 
@@ -50,19 +50,19 @@
 
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Signals.h"
 
 // Project includes
-#include "ClangExpressionParser.h"
 #include "ClangDiagnostic.h"
+#include "ClangExpressionParser.h"
 
 #include "ClangASTSource.h"
-#include "ClangExpressionHelper.h"
 #include "ClangExpressionDeclMap.h"
+#include "ClangExpressionHelper.h"
 #include "ClangModulesDeclVendor.h"
 #include "ClangPersistentVariables.h"
 #include "IRForTarget.h"
@@ -100,931 +100,888 @@ using namespace lldb_private;
 // Utility Methods for Clang
 //===----------------------------------------------------------------------===//
 
-
-class ClangExpressionParser::LLDBPreprocessorCallbacks : public PPCallbacks
-{
-    ClangModulesDeclVendor     &m_decl_vendor;
-    ClangPersistentVariables   &m_persistent_vars;
-    StreamString                m_error_stream;
-    bool                        m_has_errors = false;
+class ClangExpressionParser::LLDBPreprocessorCallbacks : public PPCallbacks {
+  ClangModulesDeclVendor &m_decl_vendor;
+  ClangPersistentVariables &m_persistent_vars;
+  StreamString m_error_stream;
+  bool m_has_errors = false;
 
 public:
-    LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor,
-                              ClangPersistentVariables &persistent_vars) :
-        m_decl_vendor(decl_vendor),
-        m_persistent_vars(persistent_vars)
-    {
-    }
-    
-    void
-    moduleImport(SourceLocation import_location,
-                 clang::ModuleIdPath path,
-                 const clang::Module * /*null*/) override
-    {
-        std::vector<ConstString> string_path;
-        
-        for (const std::pair<IdentifierInfo *, SourceLocation> &component : path)
-        {
-            string_path.push_back(ConstString(component.first->getName()));
-        }
-     
-        StreamString error_stream;
-        
-        ClangModulesDeclVendor::ModuleVector exported_modules;
-        
-        if (!m_decl_vendor.AddModule(string_path, &exported_modules, m_error_stream))
-        {
-            m_has_errors = true;
-        }
-        
-        for (ClangModulesDeclVendor::ModuleID module : exported_modules)
-        {
-            m_persistent_vars.AddHandLoadedClangModule(module);
-        }
+  LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor,
+                            ClangPersistentVariables &persistent_vars)
+      : m_decl_vendor(decl_vendor), m_persistent_vars(persistent_vars) {}
+
+  void moduleImport(SourceLocation import_location, clang::ModuleIdPath path,
+                    const clang::Module * /*null*/) override {
+    std::vector<ConstString> string_path;
+
+    for (const std::pair<IdentifierInfo *, SourceLocation> &component : path) {
+      string_path.push_back(ConstString(component.first->getName()));
+    }
+
+    StreamString error_stream;
+
+    ClangModulesDeclVendor::ModuleVector exported_modules;
+
+    if (!m_decl_vendor.AddModule(string_path, &exported_modules,
+                                 m_error_stream)) {
+      m_has_errors = true;
     }
-    
-    bool hasErrors()
-    {
-        return m_has_errors;
-    }
-    
-    const std::string &getErrorString()
-    {
-        return m_error_stream.GetString();
+
+    for (ClangModulesDeclVendor::ModuleID module : exported_modules) {
+      m_persistent_vars.AddHandLoadedClangModule(module);
     }
+  }
+
+  bool hasErrors() { return m_has_errors; }
+
+  const std::string &getErrorString() { return m_error_stream.GetString(); }
 };
 
-class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer
-{
+class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer {
 public:
-    ClangDiagnosticManagerAdapter() : m_passthrough(new clang::TextDiagnosticBuffer) {}
+  ClangDiagnosticManagerAdapter()
+      : m_passthrough(new clang::TextDiagnosticBuffer) {}
 
-    ClangDiagnosticManagerAdapter(const std::shared_ptr<clang::TextDiagnosticBuffer> &passthrough)
-        : m_passthrough(passthrough)
-    {
-    }
-
-    void
-    ResetManager(DiagnosticManager *manager = nullptr)
-    {
-        m_manager = manager;
-    }
-
-    void
-    HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info)
-    {
-        if (m_manager)
-        {
-            llvm::SmallVector<char, 32> diag_str;
-            Info.FormatDiagnostic(diag_str);
-            diag_str.push_back('\0');
-            const char *data = diag_str.data();
-
-            lldb_private::DiagnosticSeverity severity;
-            bool make_new_diagnostic = true;
-            
-            switch (DiagLevel)
-            {
-                case DiagnosticsEngine::Level::Fatal:
-                case DiagnosticsEngine::Level::Error:
-                    severity = eDiagnosticSeverityError;
-                    break;
-                case DiagnosticsEngine::Level::Warning:
-                    severity = eDiagnosticSeverityWarning;
-                    break;
-                case DiagnosticsEngine::Level::Remark:
-                case DiagnosticsEngine::Level::Ignored:
-                    severity = eDiagnosticSeverityRemark;
-                    break;
-                case DiagnosticsEngine::Level::Note:
-                    m_manager->AppendMessageToDiagnostic(data);
-                    make_new_diagnostic = false;
-            }
-            if (make_new_diagnostic)
-            {
-                ClangDiagnostic *new_diagnostic = new ClangDiagnostic(data, severity, Info.getID());
-                m_manager->AddDiagnostic(new_diagnostic);
-                
-                // Don't store away warning fixits, since the compiler doesn't have enough
-                // context in an expression for the warning to be useful.
-                // FIXME: Should we try to filter out FixIts that apply to our generated
-                // code, and not the user's expression?
-                if (severity == eDiagnosticSeverityError)
-                {
-                    size_t num_fixit_hints = Info.getNumFixItHints();
-                    for (size_t i = 0; i < num_fixit_hints; i++)
-                    {
-                        const clang::FixItHint &fixit = Info.getFixItHint(i);
-                        if (!fixit.isNull())
-                            new_diagnostic->AddFixitHint(fixit);
-                    }
-                }
-            }
+  ClangDiagnosticManagerAdapter(
+      const std::shared_ptr<clang::TextDiagnosticBuffer> &passthrough)
+      : m_passthrough(passthrough) {}
+
+  void ResetManager(DiagnosticManager *manager = nullptr) {
+    m_manager = manager;
+  }
+
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+                        const clang::Diagnostic &Info) {
+    if (m_manager) {
+      llvm::SmallVector<char, 32> diag_str;
+      Info.FormatDiagnostic(diag_str);
+      diag_str.push_back('\0');
+      const char *data = diag_str.data();
+
+      lldb_private::DiagnosticSeverity severity;
+      bool make_new_diagnostic = true;
+
+      switch (DiagLevel) {
+      case DiagnosticsEngine::Level::Fatal:
+      case DiagnosticsEngine::Level::Error:
+        severity = eDiagnosticSeverityError;
+        break;
+      case DiagnosticsEngine::Level::Warning:
+        severity = eDiagnosticSeverityWarning;
+        break;
+      case DiagnosticsEngine::Level::Remark:
+      case DiagnosticsEngine::Level::Ignored:
+        severity = eDiagnosticSeverityRemark;
+        break;
+      case DiagnosticsEngine::Level::Note:
+        m_manager->AppendMessageToDiagnostic(data);
+        make_new_diagnostic = false;
+      }
+      if (make_new_diagnostic) {
+        ClangDiagnostic *new_diagnostic =
+            new ClangDiagnostic(data, severity, Info.getID());
+        m_manager->AddDiagnostic(new_diagnostic);
+
+        // Don't store away warning fixits, since the compiler doesn't have
+        // enough
+        // context in an expression for the warning to be useful.
+        // FIXME: Should we try to filter out FixIts that apply to our generated
+        // code, and not the user's expression?
+        if (severity == eDiagnosticSeverityError) {
+          size_t num_fixit_hints = Info.getNumFixItHints();
+          for (size_t i = 0; i < num_fixit_hints; i++) {
+            const clang::FixItHint &fixit = Info.getFixItHint(i);
+            if (!fixit.isNull())
+              new_diagnostic->AddFixitHint(fixit);
+          }
         }
-        
-        m_passthrough->HandleDiagnostic(DiagLevel, Info);
+      }
     }
 
-    void
-    FlushDiagnostics(DiagnosticsEngine &Diags)
-    {
-        m_passthrough->FlushDiagnostics(Diags);
-    }
+    m_passthrough->HandleDiagnostic(DiagLevel, Info);
+  }
 
-    DiagnosticConsumer *
-    clone(DiagnosticsEngine &Diags) const
-    {
-        return new ClangDiagnosticManagerAdapter(m_passthrough);
-    }
+  void FlushDiagnostics(DiagnosticsEngine &Diags) {
+    m_passthrough->FlushDiagnostics(Diags);
+  }
+
+  DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
+    return new ClangDiagnosticManagerAdapter(m_passthrough);
+  }
 
-    clang::TextDiagnosticBuffer *
-    GetPassthrough()
-    {
-        return m_passthrough.get();
-    }
+  clang::TextDiagnosticBuffer *GetPassthrough() { return m_passthrough.get(); }
 
 private:
-    DiagnosticManager *m_manager = nullptr;
-    std::shared_ptr<clang::TextDiagnosticBuffer> m_passthrough;
+  DiagnosticManager *m_manager = nullptr;
+  std::shared_ptr<clang::TextDiagnosticBuffer> m_passthrough;
 };
 
 //===----------------------------------------------------------------------===//
 // Implementation of ClangExpressionParser
 //===----------------------------------------------------------------------===//
 
-ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
-                                              Expression &expr,
-                                              bool generate_debug_info) :
-    ExpressionParser (exe_scope, expr, generate_debug_info),
-    m_compiler (),
-    m_code_generator (),
-    m_pp_callbacks(nullptr)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    // We can't compile expressions without a target.  So if the exe_scope is null or doesn't have a target,
-    // then we just need to get out of here.  I'll lldb_assert and not make any of the compiler objects since
-    // I can't return errors directly from the constructor.  Further calls will check if the compiler was made and
-    // bag out if it wasn't.
-    
-    if (!exe_scope)
-    {
-        lldb_assert(exe_scope, "Can't make an expression parser with a null scope.", __FUNCTION__, __FILE__, __LINE__);
-        return;
-    }
-    
-    lldb::TargetSP target_sp;
-    target_sp = exe_scope->CalculateTarget();
-    if (!target_sp)
-    {
-        lldb_assert(target_sp.get(), "Can't make an expression parser with a null target.", __FUNCTION__, __FILE__, __LINE__);
-        return;
-    }
-    
-    // 1. Create a new compiler instance.
-    m_compiler.reset(new CompilerInstance());
-    lldb::LanguageType frame_lang = expr.Language(); // defaults to lldb::eLanguageTypeUnknown
-    bool overridden_target_opts = false;
-    lldb_private::LanguageRuntime *lang_rt = nullptr;
-
-    std::string abi;
-    ArchSpec target_arch;
-    target_arch = target_sp->GetArchitecture();
-
-    const auto target_machine = target_arch.GetMachine();
-
-    // If the expression is being evaluated in the context of an existing
-    // stack frame, we introspect to see if the language runtime is available.
-    
-    lldb::StackFrameSP frame_sp = exe_scope->CalculateStackFrame();
-    lldb::ProcessSP process_sp = exe_scope->CalculateProcess();
-    
-    // Make sure the user hasn't provided a preferred execution language
-    // with `expression --language X -- ...`
-    if (frame_sp && frame_lang == lldb::eLanguageTypeUnknown)
-        frame_lang = frame_sp->GetLanguage();
-
-    if (process_sp && frame_lang != lldb::eLanguageTypeUnknown)
-    {
-        lang_rt = process_sp->GetLanguageRuntime(frame_lang);
-        if (log)
-            log->Printf("Frame has language of type %s", Language::GetNameForLanguageType(frame_lang));
-    }
-
-    // 2. Configure the compiler with a set of default options that are appropriate
-    // for most situations.
-    if (target_arch.IsValid())
-    {
-        std::string triple = target_arch.GetTriple().str();
-        m_compiler->getTargetOpts().Triple = triple;
-        if (log)
-            log->Printf("Using %s as the target triple", m_compiler->getTargetOpts().Triple.c_str());
-    }
-    else
-    {
-        // If we get here we don't have a valid target and just have to guess.
-        // Sometimes this will be ok to just use the host target triple (when we evaluate say "2+3", but other
-        // expressions like breakpoint conditions and other things that _are_ target specific really shouldn't just be
-        // using the host triple. In such a case the language runtime should expose an overridden options set (3),
-        // below.
-        m_compiler->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
-        if (log)
-            log->Printf("Using default target triple of %s", m_compiler->getTargetOpts().Triple.c_str());
-    }
-    // Now add some special fixes for known architectures:
-    // Any arm32 iOS environment, but not on arm64
-    if (m_compiler->getTargetOpts().Triple.find("arm64") == std::string::npos &&
-        m_compiler->getTargetOpts().Triple.find("arm") != std::string::npos &&
-        m_compiler->getTargetOpts().Triple.find("ios") != std::string::npos)
-    {
-        m_compiler->getTargetOpts().ABI = "apcs-gnu";
-    }
-    // Supported subsets of x86
-    if (target_machine == llvm::Triple::x86 ||
-        target_machine == llvm::Triple::x86_64)
-    {
-        m_compiler->getTargetOpts().Features.push_back("+sse");
-        m_compiler->getTargetOpts().Features.push_back("+sse2");
-    }
-
-    // Set the target CPU to generate code for.
-    // This will be empty for any CPU that doesn't really need to make a special CPU string.
-    m_compiler->getTargetOpts().CPU = target_arch.GetClangTargetCPU();
-
-    // Set the target ABI
-    abi = GetClangTargetABI(target_arch);
-    if (!abi.empty())
-        m_compiler->getTargetOpts().ABI = abi;
-
-    // 3. Now allow the runtime to provide custom configuration options for the target.
-    // In this case, a specialized language runtime is available and we can query it for extra options.
-    // For 99% of use cases, this will not be needed and should be provided when basic platform detection is not enough.
-    if (lang_rt)
-        overridden_target_opts = lang_rt->GetOverrideExprOptions(m_compiler->getTargetOpts());
-
-    if (overridden_target_opts)
-        if (log)
-        {
-            log->Debug("Using overridden target options for the expression evaluation");
-
-            auto opts = m_compiler->getTargetOpts();
-            log->Debug("Triple: '%s'", opts.Triple.c_str());
-            log->Debug("CPU: '%s'", opts.CPU.c_str());
-            log->Debug("FPMath: '%s'", opts.FPMath.c_str());
-            log->Debug("ABI: '%s'", opts.ABI.c_str());
-            log->Debug("LinkerVersion: '%s'", opts.LinkerVersion.c_str());
-            StringList::LogDump(log, opts.FeaturesAsWritten, "FeaturesAsWritten");
-            StringList::LogDump(log, opts.Features, "Features");
-            StringList::LogDump(log, opts.Reciprocals, "Reciprocals");
-        }
+ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope,
+                                             Expression &expr,
+                                             bool generate_debug_info)
+    : ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
+      m_code_generator(), m_pp_callbacks(nullptr) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  // We can't compile expressions without a target.  So if the exe_scope is null
+  // or doesn't have a target,
+  // then we just need to get out of here.  I'll lldb_assert and not make any of
+  // the compiler objects since
+  // I can't return errors directly from the constructor.  Further calls will
+  // check if the compiler was made and
+  // bag out if it wasn't.
+
+  if (!exe_scope) {
+    lldb_assert(exe_scope, "Can't make an expression parser with a null scope.",
+                __FUNCTION__, __FILE__, __LINE__);
+    return;
+  }
+
+  lldb::TargetSP target_sp;
+  target_sp = exe_scope->CalculateTarget();
+  if (!target_sp) {
+    lldb_assert(target_sp.get(),
+                "Can't make an expression parser with a null target.",
+                __FUNCTION__, __FILE__, __LINE__);
+    return;
+  }
+
+  // 1. Create a new compiler instance.
+  m_compiler.reset(new CompilerInstance());
+  lldb::LanguageType frame_lang =
+      expr.Language(); // defaults to lldb::eLanguageTypeUnknown
+  bool overridden_target_opts = false;
+  lldb_private::LanguageRuntime *lang_rt = nullptr;
+
+  std::string abi;
+  ArchSpec target_arch;
+  target_arch = target_sp->GetArchitecture();
+
+  const auto target_machine = target_arch.GetMachine();
+
+  // If the expression is being evaluated in the context of an existing
+  // stack frame, we introspect to see if the language runtime is available.
+
+  lldb::StackFrameSP frame_sp = exe_scope->CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope->CalculateProcess();
+
+  // Make sure the user hasn't provided a preferred execution language
+  // with `expression --language X -- ...`
+  if (frame_sp && frame_lang == lldb::eLanguageTypeUnknown)
+    frame_lang = frame_sp->GetLanguage();
 
-    // 4. Create and install the target on the compiler.
-    m_compiler->createDiagnostics();
-    auto target_info = TargetInfo::CreateTargetInfo(m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
+  if (process_sp && frame_lang != lldb::eLanguageTypeUnknown) {
+    lang_rt = process_sp->GetLanguageRuntime(frame_lang);
     if (log)
-    {
-        log->Printf("Using SIMD alignment: %d", target_info->getSimdDefaultAlign());
-        log->Printf("Target datalayout string: '%s'", target_info->getDataLayout().getStringRepresentation().c_str());
-        log->Printf("Target ABI: '%s'", target_info->getABI().str().c_str());
-        log->Printf("Target vector alignment: %d", target_info->getMaxVectorAlign());
-    }
-    m_compiler->setTarget(target_info);
-
-    assert (m_compiler->hasTarget());
-
-    // 5. Set language options.
-    lldb::LanguageType language = expr.Language();
-
-    switch (language)
-    {
-    case lldb::eLanguageTypeC:
-    case lldb::eLanguageTypeC89:
-    case lldb::eLanguageTypeC99:
-    case lldb::eLanguageTypeC11:
-        // FIXME: the following language option is a temporary workaround,
-        // to "ask for C, get C++."
-        // For now, the expression parser must use C++ anytime the
-        // language is a C family language, because the expression parser
-        // uses features of C++ to capture values.
-        m_compiler->getLangOpts().CPlusPlus = true;
-        break;
-    case lldb::eLanguageTypeObjC:
-        m_compiler->getLangOpts().ObjC1 = true;
-        m_compiler->getLangOpts().ObjC2 = true;
-        // FIXME: the following language option is a temporary workaround,
-        // to "ask for ObjC, get ObjC++" (see comment above).
-        m_compiler->getLangOpts().CPlusPlus = true;
-        break;
-    case lldb::eLanguageTypeC_plus_plus:
-    case lldb::eLanguageTypeC_plus_plus_11:
-    case lldb::eLanguageTypeC_plus_plus_14:
-        m_compiler->getLangOpts().CPlusPlus11 = true;
-        m_compiler->getHeaderSearchOpts().UseLibcxx = true;
-        LLVM_FALLTHROUGH;
-    case lldb::eLanguageTypeC_plus_plus_03:
-        m_compiler->getLangOpts().CPlusPlus = true;
-        // FIXME: the following language option is a temporary workaround,
-        // to "ask for C++, get ObjC++".  Apple hopes to remove this requirement
-        // on non-Apple platforms, but for now it is needed.
-        m_compiler->getLangOpts().ObjC1 = true;
-        break;
-    case lldb::eLanguageTypeObjC_plus_plus:
-    case lldb::eLanguageTypeUnknown:
-    default:
-        m_compiler->getLangOpts().ObjC1 = true;
-        m_compiler->getLangOpts().ObjC2 = true;
-        m_compiler->getLangOpts().CPlusPlus = true;
-        m_compiler->getLangOpts().CPlusPlus11 = true;
-        m_compiler->getHeaderSearchOpts().UseLibcxx = true;
-        break;
-    }
+      log->Printf("Frame has language of type %s",
+                  Language::GetNameForLanguageType(frame_lang));
+  }
+
+  // 2. Configure the compiler with a set of default options that are
+  // appropriate
+  // for most situations.
+  if (target_arch.IsValid()) {
+    std::string triple = target_arch.GetTriple().str();
+    m_compiler->getTargetOpts().Triple = triple;
+    if (log)
+      log->Printf("Using %s as the target triple",
+                  m_compiler->getTargetOpts().Triple.c_str());
+  } else {
+    // If we get here we don't have a valid target and just have to guess.
+    // Sometimes this will be ok to just use the host target triple (when we
+    // evaluate say "2+3", but other
+    // expressions like breakpoint conditions and other things that _are_ target
+    // specific really shouldn't just be
+    // using the host triple. In such a case the language runtime should expose
+    // an overridden options set (3),
+    // below.
+    m_compiler->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
+    if (log)
+      log->Printf("Using default target triple of %s",
+                  m_compiler->getTargetOpts().Triple.c_str());
+  }
+  // Now add some special fixes for known architectures:
+  // Any arm32 iOS environment, but not on arm64
+  if (m_compiler->getTargetOpts().Triple.find("arm64") == std::string::npos &&
+      m_compiler->getTargetOpts().Triple.find("arm") != std::string::npos &&
+      m_compiler->getTargetOpts().Triple.find("ios") != std::string::npos) {
+    m_compiler->getTargetOpts().ABI = "apcs-gnu";
+  }
+  // Supported subsets of x86
+  if (target_machine == llvm::Triple::x86 ||
+      target_machine == llvm::Triple::x86_64) {
+    m_compiler->getTargetOpts().Features.push_back("+sse");
+    m_compiler->getTargetOpts().Features.push_back("+sse2");
+  }
+
+  // Set the target CPU to generate code for.
+  // This will be empty for any CPU that doesn't really need to make a special
+  // CPU string.
+  m_compiler->getTargetOpts().CPU = target_arch.GetClangTargetCPU();
+
+  // Set the target ABI
+  abi = GetClangTargetABI(target_arch);
+  if (!abi.empty())
+    m_compiler->getTargetOpts().ABI = abi;
+
+  // 3. Now allow the runtime to provide custom configuration options for the
+  // target.
+  // In this case, a specialized language runtime is available and we can query
+  // it for extra options.
+  // For 99% of use cases, this will not be needed and should be provided when
+  // basic platform detection is not enough.
+  if (lang_rt)
+    overridden_target_opts =
+        lang_rt->GetOverrideExprOptions(m_compiler->getTargetOpts());
+
+  if (overridden_target_opts)
+    if (log) {
+      log->Debug(
+          "Using overridden target options for the expression evaluation");
+
+      auto opts = m_compiler->getTargetOpts();
+      log->Debug("Triple: '%s'", opts.Triple.c_str());
+      log->Debug("CPU: '%s'", opts.CPU.c_str());
+      log->Debug("FPMath: '%s'", opts.FPMath.c_str());
+      log->Debug("ABI: '%s'", opts.ABI.c_str());
+      log->Debug("LinkerVersion: '%s'", opts.LinkerVersion.c_str());
+      StringList::LogDump(log, opts.FeaturesAsWritten, "FeaturesAsWritten");
+      StringList::LogDump(log, opts.Features, "Features");
+      StringList::LogDump(log, opts.Reciprocals, "Reciprocals");
+    }
+
+  // 4. Create and install the target on the compiler.
+  m_compiler->createDiagnostics();
+  auto target_info = TargetInfo::CreateTargetInfo(
+      m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
+  if (log) {
+    log->Printf("Using SIMD alignment: %d", target_info->getSimdDefaultAlign());
+    log->Printf("Target datalayout string: '%s'",
+                target_info->getDataLayout().getStringRepresentation().c_str());
+    log->Printf("Target ABI: '%s'", target_info->getABI().str().c_str());
+    log->Printf("Target vector alignment: %d",
+                target_info->getMaxVectorAlign());
+  }
+  m_compiler->setTarget(target_info);
+
+  assert(m_compiler->hasTarget());
+
+  // 5. Set language options.
+  lldb::LanguageType language = expr.Language();
+
+  switch (language) {
+  case lldb::eLanguageTypeC:
+  case lldb::eLanguageTypeC89:
+  case lldb::eLanguageTypeC99:
+  case lldb::eLanguageTypeC11:
+    // FIXME: the following language option is a temporary workaround,
+    // to "ask for C, get C++."
+    // For now, the expression parser must use C++ anytime the
+    // language is a C family language, because the expression parser
+    // uses features of C++ to capture values.
+    m_compiler->getLangOpts().CPlusPlus = true;
+    break;
+  case lldb::eLanguageTypeObjC:
+    m_compiler->getLangOpts().ObjC1 = true;
+    m_compiler->getLangOpts().ObjC2 = true;
+    // FIXME: the following language option is a temporary workaround,
+    // to "ask for ObjC, get ObjC++" (see comment above).
+    m_compiler->getLangOpts().CPlusPlus = true;
+    break;
+  case lldb::eLanguageTypeC_plus_plus:
+  case lldb::eLanguageTypeC_plus_plus_11:
+  case lldb::eLanguageTypeC_plus_plus_14:
+    m_compiler->getLangOpts().CPlusPlus11 = true;
+    m_compiler->getHeaderSearchOpts().UseLibcxx = true;
+    LLVM_FALLTHROUGH;
+  case lldb::eLanguageTypeC_plus_plus_03:
+    m_compiler->getLangOpts().CPlusPlus = true;
+    // FIXME: the following language option is a temporary workaround,
+    // to "ask for C++, get ObjC++".  Apple hopes to remove this requirement
+    // on non-Apple platforms, but for now it is needed.
+    m_compiler->getLangOpts().ObjC1 = true;
+    break;
+  case lldb::eLanguageTypeObjC_plus_plus:
+  case lldb::eLanguageTypeUnknown:
+  default:
+    m_compiler->getLangOpts().ObjC1 = true;
+    m_compiler->getLangOpts().ObjC2 = true;
+    m_compiler->getLangOpts().CPlusPlus = true;
+    m_compiler->getLangOpts().CPlusPlus11 = true;
+    m_compiler->getHeaderSearchOpts().UseLibcxx = true;
+    break;
+  }
+
+  m_compiler->getLangOpts().Bool = true;
+  m_compiler->getLangOpts().WChar = true;
+  m_compiler->getLangOpts().Blocks = true;
+  m_compiler->getLangOpts().DebuggerSupport =
+      true; // Features specifically for debugger clients
+  if (expr.DesiredResultType() == Expression::eResultTypeId)
+    m_compiler->getLangOpts().DebuggerCastResultToId = true;
+
+  m_compiler->getLangOpts().CharIsSigned =
+      ArchSpec(m_compiler->getTargetOpts().Triple.c_str())
+          .CharIsSignedByDefault();
+
+  // Spell checking is a nice feature, but it ends up completing a
+  // lot of types that we didn't strictly speaking need to complete.
+  // As a result, we spend a long time parsing and importing debug
+  // information.
+  m_compiler->getLangOpts().SpellChecking = false;
+
+  if (process_sp && m_compiler->getLangOpts().ObjC1) {
+    if (process_sp->GetObjCLanguageRuntime()) {
+      if (process_sp->GetObjCLanguageRuntime()->GetRuntimeVersion() ==
+          ObjCLanguageRuntime::ObjCRuntimeVersions::eAppleObjC_V2)
+        m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::MacOSX,
+                                                  VersionTuple(10, 7));
+      else
+        m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::FragileMacOSX,
+                                                  VersionTuple(10, 7));
+
+      if (process_sp->GetObjCLanguageRuntime()->HasNewLiteralsAndIndexing())
+        m_compiler->getLangOpts().DebuggerObjCLiteral = true;
+    }
+  }
+
+  m_compiler->getLangOpts().ThreadsafeStatics = false;
+  m_compiler->getLangOpts().AccessControl =
+      false; // Debuggers get universal access
+  m_compiler->getLangOpts().DollarIdents =
+      true; // $ indicates a persistent variable name
+
+  // Set CodeGen options
+  m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
+  m_compiler->getCodeGenOpts().InstrumentFunctions = false;
+  m_compiler->getCodeGenOpts().DisableFPElim = true;
+  m_compiler->getCodeGenOpts().OmitLeafFramePointer = false;
+  if (generate_debug_info)
+    m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
+  else
+    m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::NoDebugInfo);
+
+  // Disable some warnings.
+  m_compiler->getDiagnostics().setSeverityForGroup(
+      clang::diag::Flavor::WarningOrError, "unused-value",
+      clang::diag::Severity::Ignored, SourceLocation());
+  m_compiler->getDiagnostics().setSeverityForGroup(
+      clang::diag::Flavor::WarningOrError, "odr",
+      clang::diag::Severity::Ignored, SourceLocation());
+
+  // Inform the target of the language options
+  //
+  // FIXME: We shouldn't need to do this, the target should be immutable once
+  // created. This complexity should be lifted elsewhere.
+  m_compiler->getTarget().adjust(m_compiler->getLangOpts());
+
+  // 6. Set up the diagnostic buffer for reporting errors
+
+  m_compiler->getDiagnostics().setClient(new ClangDiagnosticManagerAdapter);
+
+  // 7. Set up the source management objects inside the compiler
+
+  clang::FileSystemOptions file_system_options;
+  m_file_manager.reset(new clang::FileManager(file_system_options));
+
+  if (!m_compiler->hasSourceManager())
+    m_compiler->createSourceManager(*m_file_manager.get());
+
+  m_compiler->createFileManager();
+  m_compiler->createPreprocessor(TU_Complete);
+
+  if (ClangModulesDeclVendor *decl_vendor =
+          target_sp->GetClangModulesDeclVendor()) {
+    ClangPersistentVariables *clang_persistent_vars =
+        llvm::cast<ClangPersistentVariables>(
+            target_sp->GetPersistentExpressionStateForLanguage(
+                lldb::eLanguageTypeC));
+    std::unique_ptr<PPCallbacks> pp_callbacks(
+        new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars));
+    m_pp_callbacks =
+        static_cast<LLDBPreprocessorCallbacks *>(pp_callbacks.get());
+    m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks));
+  }
+
+  // 8. Most of this we get from the CompilerInstance, but we
+  // also want to give the context an ExternalASTSource.
+  m_selector_table.reset(new SelectorTable());
+  m_builtin_context.reset(new Builtin::Context());
+
+  std::unique_ptr<clang::ASTContext> ast_context(
+      new ASTContext(m_compiler->getLangOpts(), m_compiler->getSourceManager(),
+                     m_compiler->getPreprocessor().getIdentifierTable(),
+                     *m_selector_table.get(), *m_builtin_context.get()));
+
+  ast_context->InitBuiltinTypes(m_compiler->getTarget());
+
+  ClangExpressionHelper *type_system_helper =
+      dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
+  ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap();
+
+  if (decl_map) {
+    llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source(
+        decl_map->CreateProxy());
+    decl_map->InstallASTContext(ast_context.get());
+    ast_context->setExternalSource(ast_source);
+  }
+
+  m_ast_context.reset(
+      new ClangASTContext(m_compiler->getTargetOpts().Triple.c_str()));
+  m_ast_context->setASTContext(ast_context.get());
+  m_compiler->setASTContext(ast_context.release());
+
+  std::string module_name("$__lldb_module");
+
+  m_llvm_context.reset(new LLVMContext());
+  m_code_generator.reset(CreateLLVMCodeGen(
+      m_compiler->getDiagnostics(), module_name,
+      m_compiler->getHeaderSearchOpts(), m_compiler->getPreprocessorOpts(),
+      m_compiler->getCodeGenOpts(), *m_llvm_context));
+}
 
-    m_compiler->getLangOpts().Bool = true;
-    m_compiler->getLangOpts().WChar = true;
-    m_compiler->getLangOpts().Blocks = true;
-    m_compiler->getLangOpts().DebuggerSupport = true; // Features specifically for debugger clients
-    if (expr.DesiredResultType() == Expression::eResultTypeId)
-        m_compiler->getLangOpts().DebuggerCastResultToId = true;
-
-    m_compiler->getLangOpts().CharIsSigned =
-            ArchSpec(m_compiler->getTargetOpts().Triple.c_str()).CharIsSignedByDefault();
-
-    // Spell checking is a nice feature, but it ends up completing a
-    // lot of types that we didn't strictly speaking need to complete.
-    // As a result, we spend a long time parsing and importing debug
-    // information.
-    m_compiler->getLangOpts().SpellChecking = false;
-
-    if (process_sp && m_compiler->getLangOpts().ObjC1)
-    {
-        if (process_sp->GetObjCLanguageRuntime())
-        {
-            if (process_sp->GetObjCLanguageRuntime()->GetRuntimeVersion() == ObjCLanguageRuntime::ObjCRuntimeVersions::eAppleObjC_V2)
-                m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::MacOSX, VersionTuple(10, 7));
-            else
-                m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::FragileMacOSX, VersionTuple(10, 7));
+ClangExpressionParser::~ClangExpressionParser() {}
 
-            if (process_sp->GetObjCLanguageRuntime()->HasNewLiteralsAndIndexing())
-                m_compiler->getLangOpts().DebuggerObjCLiteral = true;
+unsigned ClangExpressionParser::Parse(DiagnosticManager &diagnostic_manager) {
+  ClangDiagnosticManagerAdapter *adapter =
+      static_cast<ClangDiagnosticManagerAdapter *>(
+          m_compiler->getDiagnostics().getClient());
+  clang::TextDiagnosticBuffer *diag_buf = adapter->GetPassthrough();
+  diag_buf->FlushDiagnostics(m_compiler->getDiagnostics());
+
+  adapter->ResetManager(&diagnostic_manager);
+
+  const char *expr_text = m_expr.Text();
+
+  clang::SourceManager &source_mgr = m_compiler->getSourceManager();
+  bool created_main_file = false;
+  if (m_compiler->getCodeGenOpts().getDebugInfo() ==
+      codegenoptions::FullDebugInfo) {
+    int temp_fd = -1;
+    llvm::SmallString<PATH_MAX> result_path;
+    FileSpec tmpdir_file_spec;
+    if (HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir,
+                              tmpdir_file_spec)) {
+      tmpdir_file_spec.AppendPathComponent("lldb-%%%%%%.expr");
+      std::string temp_source_path = tmpdir_file_spec.GetPath();
+      llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path);
+    } else {
+      llvm::sys::fs::createTemporaryFile("lldb", "expr", temp_fd, result_path);
+    }
+
+    if (temp_fd != -1) {
+      lldb_private::File file(temp_fd, true);
+      const size_t expr_text_len = strlen(expr_text);
+      size_t bytes_written = expr_text_len;
+      if (file.Write(expr_text, bytes_written).Success()) {
+        if (bytes_written == expr_text_len) {
+          file.Close();
+          source_mgr.setMainFileID(
+              source_mgr.createFileID(m_file_manager->getFile(result_path),
+                                      SourceLocation(), SrcMgr::C_User));
+          created_main_file = true;
         }
+      }
     }
+  }
 
-    m_compiler->getLangOpts().ThreadsafeStatics = false;
-    m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access
-    m_compiler->getLangOpts().DollarIdents = true; // $ indicates a persistent variable name
-
-    // Set CodeGen options
-    m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
-    m_compiler->getCodeGenOpts().InstrumentFunctions = false;
-    m_compiler->getCodeGenOpts().DisableFPElim = true;
-    m_compiler->getCodeGenOpts().OmitLeafFramePointer = false;
-    if (generate_debug_info)
-        m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
-    else
-        m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::NoDebugInfo);
-
-    // Disable some warnings.
-    m_compiler->getDiagnostics().setSeverityForGroup(clang::diag::Flavor::WarningOrError,
-        "unused-value", clang::diag::Severity::Ignored, SourceLocation());
-    m_compiler->getDiagnostics().setSeverityForGroup(clang::diag::Flavor::WarningOrError,
-        "odr", clang::diag::Severity::Ignored, SourceLocation());
-
-    // Inform the target of the language options
-    //
-    // FIXME: We shouldn't need to do this, the target should be immutable once
-    // created. This complexity should be lifted elsewhere.
-    m_compiler->getTarget().adjust(m_compiler->getLangOpts());
-
-    // 6. Set up the diagnostic buffer for reporting errors
-
-    m_compiler->getDiagnostics().setClient(new ClangDiagnosticManagerAdapter);
-
-    // 7. Set up the source management objects inside the compiler
-
-    clang::FileSystemOptions file_system_options;
-    m_file_manager.reset(new clang::FileManager(file_system_options));
-
-    if (!m_compiler->hasSourceManager())
-        m_compiler->createSourceManager(*m_file_manager.get());
-
-    m_compiler->createFileManager();
-    m_compiler->createPreprocessor(TU_Complete);
-    
-    if (ClangModulesDeclVendor *decl_vendor = target_sp->GetClangModulesDeclVendor())
-    {
-        ClangPersistentVariables *clang_persistent_vars = llvm::cast<ClangPersistentVariables>(target_sp->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC));
-        std::unique_ptr<PPCallbacks> pp_callbacks(new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars));
-        m_pp_callbacks = static_cast<LLDBPreprocessorCallbacks*>(pp_callbacks.get());
-        m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks));
-    }
-        
-    // 8. Most of this we get from the CompilerInstance, but we
-    // also want to give the context an ExternalASTSource.
-    m_selector_table.reset(new SelectorTable());
-    m_builtin_context.reset(new Builtin::Context());
-
-    std::unique_ptr<clang::ASTContext> ast_context(new ASTContext(m_compiler->getLangOpts(),
-                                                                  m_compiler->getSourceManager(),
-                                                                  m_compiler->getPreprocessor().getIdentifierTable(),
-                                                                  *m_selector_table.get(),
-                                                                  *m_builtin_context.get()));
-    
-    ast_context->InitBuiltinTypes(m_compiler->getTarget());
-
-    ClangExpressionHelper *type_system_helper = dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
-    ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap();
-
-    if (decl_map)
-    {
-        llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source(decl_map->CreateProxy());
-        decl_map->InstallASTContext(ast_context.get());
-        ast_context->setExternalSource(ast_source);
-    }
-
-    m_ast_context.reset(new ClangASTContext(m_compiler->getTargetOpts().Triple.c_str()));
-    m_ast_context->setASTContext(ast_context.get());
-    m_compiler->setASTContext(ast_context.release());
-
-    std::string module_name("$__lldb_module");
-
-    m_llvm_context.reset(new LLVMContext());
-    m_code_generator.reset(CreateLLVMCodeGen(m_compiler->getDiagnostics(),
-                                             module_name,
-                                             m_compiler->getHeaderSearchOpts(),
-                                             m_compiler->getPreprocessorOpts(),
-                                             m_compiler->getCodeGenOpts(),
-                                             *m_llvm_context));
-}
+  if (!created_main_file) {
+    std::unique_ptr<MemoryBuffer> memory_buffer =
+        MemoryBuffer::getMemBufferCopy(expr_text, __FUNCTION__);
+    source_mgr.setMainFileID(source_mgr.createFileID(std::move(memory_buffer)));
+  }
+
+  diag_buf->BeginSourceFile(m_compiler->getLangOpts(),
+                            &m_compiler->getPreprocessor());
+
+  ClangExpressionHelper *type_system_helper =
+      dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
+
+  ASTConsumer *ast_transformer =
+      type_system_helper->ASTTransformer(m_code_generator.get());
+
+  if (ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap())
+    decl_map->InstallCodeGenerator(m_code_generator.get());
+
+  if (ast_transformer) {
+    ast_transformer->Initialize(m_compiler->getASTContext());
+    ParseAST(m_compiler->getPreprocessor(), ast_transformer,
+             m_compiler->getASTContext());
+  } else {
+    m_code_generator->Initialize(m_compiler->getASTContext());
+    ParseAST(m_compiler->getPreprocessor(), m_code_generator.get(),
+             m_compiler->getASTContext());
+  }
+
+  diag_buf->EndSourceFile();
+
+  unsigned num_errors = diag_buf->getNumErrors();
+
+  if (m_pp_callbacks && m_pp_callbacks->hasErrors()) {
+    num_errors++;
+    diagnostic_manager.PutCString(eDiagnosticSeverityError,
+                                  "while importing modules:");
+    diagnostic_manager.AppendMessageToDiagnostic(
+        m_pp_callbacks->getErrorString().c_str());
+  }
+
+  if (!num_errors) {
+    if (type_system_helper->DeclMap() &&
+        !type_system_helper->DeclMap()->ResolveUnknownTypes()) {
+      diagnostic_manager.Printf(eDiagnosticSeverityError,
+                                "Couldn't infer the type of a variable");
+      num_errors++;
+    }
+  }
+
+  if (!num_errors) {
+    type_system_helper->CommitPersistentDecls();
+  }
 
-ClangExpressionParser::~ClangExpressionParser()
-{
-}
+  adapter->ResetManager();
 
-unsigned
-ClangExpressionParser::Parse(DiagnosticManager &diagnostic_manager)
-{
-    ClangDiagnosticManagerAdapter *adapter =
-        static_cast<ClangDiagnosticManagerAdapter *>(m_compiler->getDiagnostics().getClient());
-    clang::TextDiagnosticBuffer *diag_buf = adapter->GetPassthrough();
-    diag_buf->FlushDiagnostics(m_compiler->getDiagnostics());
-
-    adapter->ResetManager(&diagnostic_manager);
-
-    const char *expr_text = m_expr.Text();
-
-    clang::SourceManager &source_mgr = m_compiler->getSourceManager();
-    bool created_main_file = false;
-    if (m_compiler->getCodeGenOpts().getDebugInfo() == codegenoptions::FullDebugInfo)
-    {
-        int temp_fd = -1;
-        llvm::SmallString<PATH_MAX> result_path;
-        FileSpec tmpdir_file_spec;
-        if (HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
-        {
-            tmpdir_file_spec.AppendPathComponent("lldb-%%%%%%.expr");
-            std::string temp_source_path = tmpdir_file_spec.GetPath();
-            llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path);
-        }
-        else
-        {
-            llvm::sys::fs::createTemporaryFile("lldb", "expr", temp_fd, result_path);
-        }
+  return num_errors;
+}
 
-        if (temp_fd != -1)
-        {
-            lldb_private::File file(temp_fd, true);
-            const size_t expr_text_len = strlen(expr_text);
-            size_t bytes_written = expr_text_len;
-            if (file.Write(expr_text, bytes_written).Success())
-            {
-                if (bytes_written == expr_text_len)
-                {
-                    file.Close();
-                    source_mgr.setMainFileID(source_mgr.createFileID(m_file_manager->getFile(result_path),
-                                                                     SourceLocation(), SrcMgr::C_User));
-                    created_main_file = true;
-                }
-            }
-        }
-    }
+std::string
+ClangExpressionParser::GetClangTargetABI(const ArchSpec &target_arch) {
+  std::string abi;
 
-    if (!created_main_file)
-    {
-        std::unique_ptr<MemoryBuffer> memory_buffer = MemoryBuffer::getMemBufferCopy(expr_text, __FUNCTION__);
-        source_mgr.setMainFileID(source_mgr.createFileID(std::move(memory_buffer)));
+  if (target_arch.IsMIPS()) {
+    switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) {
+    case ArchSpec::eMIPSABI_N64:
+      abi = "n64";
+      break;
+    case ArchSpec::eMIPSABI_N32:
+      abi = "n32";
+      break;
+    case ArchSpec::eMIPSABI_O32:
+      abi = "o32";
+      break;
+    default:
+      break;
     }
+  }
+  return abi;
+}
 
-    diag_buf->BeginSourceFile(m_compiler->getLangOpts(), &m_compiler->getPreprocessor());
-
-    ClangExpressionHelper *type_system_helper = dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
+bool ClangExpressionParser::RewriteExpression(
+    DiagnosticManager &diagnostic_manager) {
+  clang::SourceManager &source_manager = m_compiler->getSourceManager();
+  clang::edit::EditedSource editor(source_manager, m_compiler->getLangOpts(),
+                                   nullptr);
+  clang::edit::Commit commit(editor);
+  clang::Rewriter rewriter(source_manager, m_compiler->getLangOpts());
 
-    ASTConsumer *ast_transformer = type_system_helper->ASTTransformer(m_code_generator.get());
+  class RewritesReceiver : public edit::EditsReceiver {
+    Rewriter &rewrite;
 
-    if (ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap())
-        decl_map->InstallCodeGenerator(m_code_generator.get());
+  public:
+    RewritesReceiver(Rewriter &in_rewrite) : rewrite(in_rewrite) {}
 
-    if (ast_transformer)
-    {
-        ast_transformer->Initialize(m_compiler->getASTContext());
-        ParseAST(m_compiler->getPreprocessor(), ast_transformer, m_compiler->getASTContext());
+    void insert(SourceLocation loc, StringRef text) override {
+      rewrite.InsertText(loc, text);
     }
-    else
-    {
-        m_code_generator->Initialize(m_compiler->getASTContext());
-        ParseAST(m_compiler->getPreprocessor(), m_code_generator.get(), m_compiler->getASTContext());
+    void replace(CharSourceRange range, StringRef text) override {
+      rewrite.ReplaceText(range.getBegin(), rewrite.getRangeSize(range), text);
     }
+  };
 
-    diag_buf->EndSourceFile();
+  RewritesReceiver rewrites_receiver(rewriter);
 
-    unsigned num_errors = diag_buf->getNumErrors();
-
-    if (m_pp_callbacks && m_pp_callbacks->hasErrors())
-    {
-        num_errors++;
-        diagnostic_manager.PutCString(eDiagnosticSeverityError, "while importing modules:");
-        diagnostic_manager.AppendMessageToDiagnostic(m_pp_callbacks->getErrorString().c_str());
-    }
+  const DiagnosticList &diagnostics = diagnostic_manager.Diagnostics();
+  size_t num_diags = diagnostics.size();
+  if (num_diags == 0)
+    return false;
 
-    if (!num_errors)
-    {
-        if (type_system_helper->DeclMap() && !type_system_helper->DeclMap()->ResolveUnknownTypes())
-        {
-            diagnostic_manager.Printf(eDiagnosticSeverityError, "Couldn't infer the type of a variable");
-            num_errors++;
+  for (const Diagnostic *diag : diagnostic_manager.Diagnostics()) {
+    const ClangDiagnostic *diagnostic = llvm::dyn_cast<ClangDiagnostic>(diag);
+    if (diagnostic && diagnostic->HasFixIts()) {
+      for (const FixItHint &fixit : diagnostic->FixIts()) {
+        // This is cobbed from clang::Rewrite::FixItRewriter.
+        if (fixit.CodeToInsert.empty()) {
+          if (fixit.InsertFromRange.isValid()) {
+            commit.insertFromRange(fixit.RemoveRange.getBegin(),
+                                   fixit.InsertFromRange, /*afterToken=*/false,
+                                   fixit.BeforePreviousInsertions);
+          } else
+            commit.remove(fixit.RemoveRange);
+        } else {
+          if (fixit.RemoveRange.isTokenRange() ||
+              fixit.RemoveRange.getBegin() != fixit.RemoveRange.getEnd())
+            commit.replace(fixit.RemoveRange, fixit.CodeToInsert);
+          else
+            commit.insert(fixit.RemoveRange.getBegin(), fixit.CodeToInsert,
+                          /*afterToken=*/false, fixit.BeforePreviousInsertions);
         }
+      }
     }
+  }
 
-    if (!num_errors)
-    {
-        type_system_helper->CommitPersistentDecls();
-    }
+  // FIXME - do we want to try to propagate specific errors here?
+  if (!commit.isCommitable())
+    return false;
+  else if (!editor.commit(commit))
+    return false;
 
-    adapter->ResetManager();
+  // Now play all the edits, and stash the result in the diagnostic manager.
+  editor.applyRewrites(rewrites_receiver);
+  RewriteBuffer &main_file_buffer =
+      rewriter.getEditBuffer(source_manager.getMainFileID());
+
+  std::string fixed_expression;
+  llvm::raw_string_ostream out_stream(fixed_expression);
+
+  main_file_buffer.write(out_stream);
+  out_stream.flush();
+  diagnostic_manager.SetFixedExpression(fixed_expression);
 
-    return num_errors;
+  return true;
 }
 
-std::string
-ClangExpressionParser::GetClangTargetABI (const ArchSpec &target_arch)
-{
-    std::string abi;
- 
-    if(target_arch.IsMIPS())
-    {
-       switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask)
-       {
-       case ArchSpec::eMIPSABI_N64:
-            abi = "n64"; break;
-       case ArchSpec::eMIPSABI_N32:
-            abi = "n32"; break;
-       case ArchSpec::eMIPSABI_O32:
-            abi = "o32"; break;
-       default:
-              break;
-       }
+static bool FindFunctionInModule(ConstString &mangled_name,
+                                 llvm::Module *module, const char *orig_name) {
+  for (const auto &func : module->getFunctionList()) {
+    const StringRef &name = func.getName();
+    if (name.find(orig_name) != StringRef::npos) {
+      mangled_name.SetString(name);
+      return true;
     }
-    return abi;
+  }
+
+  return false;
 }
 
-bool
-ClangExpressionParser::RewriteExpression(DiagnosticManager &diagnostic_manager)
-{
-    clang::SourceManager &source_manager = m_compiler->getSourceManager();
-    clang::edit::EditedSource editor(source_manager, m_compiler->getLangOpts(), nullptr);
-    clang::edit::Commit commit(editor);
-    clang::Rewriter rewriter(source_manager, m_compiler->getLangOpts());
-    
-    class RewritesReceiver : public edit::EditsReceiver {
-      Rewriter &rewrite;
+lldb_private::Error ClangExpressionParser::PrepareForExecution(
+    lldb::addr_t &func_addr, lldb::addr_t &func_end,
+    lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,
+    bool &can_interpret, ExecutionPolicy execution_policy) {
+  func_addr = LLDB_INVALID_ADDRESS;
+  func_end = LLDB_INVALID_ADDRESS;
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  lldb_private::Error err;
+
+  std::unique_ptr<llvm::Module> llvm_module_ap(
+      m_code_generator->ReleaseModule());
+
+  if (!llvm_module_ap.get()) {
+    err.SetErrorToGenericError();
+    err.SetErrorString("IR doesn't contain a module");
+    return err;
+  }
 
-    public:
-      RewritesReceiver(Rewriter &in_rewrite) : rewrite(in_rewrite) { }
+  ConstString function_name;
 
-      void insert(SourceLocation loc, StringRef text) override {
-        rewrite.InsertText(loc, text);
-      }
-      void replace(CharSourceRange range, StringRef text) override {
-        rewrite.ReplaceText(range.getBegin(), rewrite.getRangeSize(range), text);
-      }
-    };
-    
-    RewritesReceiver rewrites_receiver(rewriter);
-    
-    const DiagnosticList &diagnostics = diagnostic_manager.Diagnostics();
-    size_t num_diags = diagnostics.size();
-    if (num_diags == 0)
-        return false;
-    
-    for (const Diagnostic *diag : diagnostic_manager.Diagnostics())
-    {
-        const ClangDiagnostic *diagnostic = llvm::dyn_cast<ClangDiagnostic>(diag);
-        if (diagnostic && diagnostic->HasFixIts())
-        {
-             for (const FixItHint &fixit : diagnostic->FixIts())
-             {
-                // This is cobbed from clang::Rewrite::FixItRewriter.
-                if (fixit.CodeToInsert.empty())
-                {
-                  if (fixit.InsertFromRange.isValid())
-                  {
-                      commit.insertFromRange(fixit.RemoveRange.getBegin(),
-                                             fixit.InsertFromRange, /*afterToken=*/false,
-                                             fixit.BeforePreviousInsertions);
-                  }
-                  else
-                    commit.remove(fixit.RemoveRange);
-                }
-                else
-                {
-                  if (fixit.RemoveRange.isTokenRange() ||
-                      fixit.RemoveRange.getBegin() != fixit.RemoveRange.getEnd())
-                    commit.replace(fixit.RemoveRange, fixit.CodeToInsert);
-                  else
-                    commit.insert(fixit.RemoveRange.getBegin(), fixit.CodeToInsert,
-                                /*afterToken=*/false, fixit.BeforePreviousInsertions);
-                }
-            }
-        }
-    }
-    
-    // FIXME - do we want to try to propagate specific errors here?
-    if (!commit.isCommitable())
-        return false;
-    else if (!editor.commit(commit))
-        return false;
-    
-    // Now play all the edits, and stash the result in the diagnostic manager.
-    editor.applyRewrites(rewrites_receiver);
-    RewriteBuffer &main_file_buffer = rewriter.getEditBuffer(source_manager.getMainFileID());
-
-    std::string fixed_expression;
-    llvm::raw_string_ostream out_stream(fixed_expression);
-    
-    main_file_buffer.write(out_stream);
-    out_stream.flush();
-    diagnostic_manager.SetFixedExpression(fixed_expression);
-    
-    return true;
-}
+  if (execution_policy != eExecutionPolicyTopLevel) {
+    // Find the actual name of the function (it's often mangled somehow)
 
-static bool FindFunctionInModule (ConstString &mangled_name,
-                                  llvm::Module *module,
-                                  const char *orig_name)
-{
-    for (const auto &func : module->getFunctionList())
-    {
-        const StringRef &name = func.getName();
-        if (name.find(orig_name) != StringRef::npos)
-        {
-            mangled_name.SetString(name);
-            return true;
-        }
-    }
+    if (!FindFunctionInModule(function_name, llvm_module_ap.get(),
+                              m_expr.FunctionName())) {
+      err.SetErrorToGenericError();
+      err.SetErrorStringWithFormat("Couldn't find %s() in the module",
+                                   m_expr.FunctionName());
+      return err;
+    } else {
+      if (log)
+        log->Printf("Found function %s for %s", function_name.AsCString(),
+                    m_expr.FunctionName());
+    }
+  }
+
+  SymbolContext sc;
+
+  if (lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP()) {
+    sc = frame_sp->GetSymbolContext(lldb::eSymbolContextEverything);
+  } else if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP()) {
+    sc.target_sp = target_sp;
+  }
+
+  LLVMUserExpression::IRPasses custom_passes;
+  {
+    auto lang = m_expr.Language();
+    if (log)
+      log->Printf("%s - Currrent expression language is %s\n", __FUNCTION__,
+                  Language::GetNameForLanguageType(lang));
 
-    return false;
-}
+    if (lang != lldb::eLanguageTypeUnknown) {
+      auto runtime = exe_ctx.GetProcessSP()->GetLanguageRuntime(lang);
+      if (runtime)
+        runtime->GetIRPasses(custom_passes);
+    }
+  }
 
-lldb_private::Error
-ClangExpressionParser::PrepareForExecution (lldb::addr_t &func_addr,
-                                            lldb::addr_t &func_end,
-                                            lldb::IRExecutionUnitSP &execution_unit_sp,
-                                            ExecutionContext &exe_ctx,
-                                            bool &can_interpret,
-                                            ExecutionPolicy execution_policy)
-{
-	func_addr = LLDB_INVALID_ADDRESS;
-	func_end = LLDB_INVALID_ADDRESS;
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    lldb_private::Error err;
-
-    std::unique_ptr<llvm::Module> llvm_module_ap (m_code_generator->ReleaseModule());
-
-    if (!llvm_module_ap.get())
-    {
-        err.SetErrorToGenericError();
-        err.SetErrorString("IR doesn't contain a module");
+  if (custom_passes.EarlyPasses) {
+    if (log)
+      log->Printf("%s - Running Early IR Passes from LanguageRuntime on "
+                  "expression module '%s'",
+                  __FUNCTION__, m_expr.FunctionName());
+
+    custom_passes.EarlyPasses->run(*llvm_module_ap);
+  }
+
+  execution_unit_sp.reset(
+      new IRExecutionUnit(m_llvm_context, // handed off here
+                          llvm_module_ap, // handed off here
+                          function_name, exe_ctx.GetTargetSP(), sc,
+                          m_compiler->getTargetOpts().Features));
+
+  ClangExpressionHelper *type_system_helper =
+      dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
+  ClangExpressionDeclMap *decl_map =
+      type_system_helper->DeclMap(); // result can be NULL
+
+  if (decl_map) {
+    Stream *error_stream = NULL;
+    Target *target = exe_ctx.GetTargetPtr();
+    error_stream = target->GetDebugger().GetErrorFile().get();
+
+    IRForTarget ir_for_target(decl_map, m_expr.NeedsVariableResolution(),
+                              *execution_unit_sp, *error_stream,
+                              function_name.AsCString());
+
+    bool ir_can_run =
+        ir_for_target.runOnModule(*execution_unit_sp->GetModule());
+
+    if (!ir_can_run) {
+      err.SetErrorString(
+          "The expression could not be prepared to run in the target");
+      return err;
+    }
+
+    Process *process = exe_ctx.GetProcessPtr();
+
+    if (execution_policy != eExecutionPolicyAlways &&
+        execution_policy != eExecutionPolicyTopLevel) {
+      lldb_private::Error interpret_error;
+
+      bool interpret_function_calls =
+          !process ? false : process->CanInterpretFunctionCalls();
+      can_interpret = IRInterpreter::CanInterpret(
+          *execution_unit_sp->GetModule(), *execution_unit_sp->GetFunction(),
+          interpret_error, interpret_function_calls);
+
+      if (!can_interpret && execution_policy == eExecutionPolicyNever) {
+        err.SetErrorStringWithFormat("Can't run the expression locally: %s",
+                                     interpret_error.AsCString());
         return err;
+      }
     }
 
-    ConstString function_name;
+    if (!process && execution_policy == eExecutionPolicyAlways) {
+      err.SetErrorString("Expression needed to run in the target, but the "
+                         "target can't be run");
+      return err;
+    }
+
+    if (!process && execution_policy == eExecutionPolicyTopLevel) {
+      err.SetErrorString("Top-level code needs to be inserted into a runnable "
+                         "target, but the target can't be run");
+      return err;
+    }
+
+    if (execution_policy == eExecutionPolicyAlways ||
+        (execution_policy != eExecutionPolicyTopLevel && !can_interpret)) {
+      if (m_expr.NeedsValidation() && process) {
+        if (!process->GetDynamicCheckers()) {
+          DynamicCheckerFunctions *dynamic_checkers =
+              new DynamicCheckerFunctions();
+
+          DiagnosticManager install_diagnostics;
+
+          if (!dynamic_checkers->Install(install_diagnostics, exe_ctx)) {
+            if (install_diagnostics.Diagnostics().size())
+              err.SetErrorString("couldn't install checkers, unknown error");
+            else
+              err.SetErrorString(install_diagnostics.GetString().c_str());
 
-    if (execution_policy != eExecutionPolicyTopLevel)
-    {
-        // Find the actual name of the function (it's often mangled somehow)
-
-        if (!FindFunctionInModule(function_name, llvm_module_ap.get(), m_expr.FunctionName()))
-        {
-            err.SetErrorToGenericError();
-            err.SetErrorStringWithFormat("Couldn't find %s() in the module", m_expr.FunctionName());
             return err;
+          }
+
+          process->SetDynamicCheckers(dynamic_checkers);
+
+          if (log)
+            log->Printf("== [ClangUserExpression::Evaluate] Finished "
+                        "installing dynamic checkers ==");
         }
-        else
-        {
-            if (log)
-                log->Printf("Found function %s for %s", function_name.AsCString(), m_expr.FunctionName());
+
+        IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(),
+                                          function_name.AsCString());
+
+        llvm::Module *module = execution_unit_sp->GetModule();
+        if (!module || !ir_dynamic_checks.runOnModule(*module)) {
+          err.SetErrorToGenericError();
+          err.SetErrorString("Couldn't add dynamic checks to the expression");
+          return err;
         }
-    }
 
-    SymbolContext sc;
+        if (custom_passes.LatePasses) {
+          if (log)
+            log->Printf("%s - Running Late IR Passes from LanguageRuntime on "
+                        "expression module '%s'",
+                        __FUNCTION__, m_expr.FunctionName());
 
-    if (lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP())
-    {
-        sc = frame_sp->GetSymbolContext(lldb::eSymbolContextEverything);
-    }
-    else if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP())
-    {
-        sc.target_sp = target_sp;
-    }
-
-    LLVMUserExpression::IRPasses custom_passes;
-    {
-        auto lang = m_expr.Language();
-        if (log)
-            log->Printf("%s - Currrent expression language is %s\n", __FUNCTION__,
-                        Language::GetNameForLanguageType(lang));
-
-        if (lang != lldb::eLanguageTypeUnknown)
-        {
-            auto runtime = exe_ctx.GetProcessSP()->GetLanguageRuntime(lang);
-            if (runtime)
-                runtime->GetIRPasses(custom_passes);
+          custom_passes.LatePasses->run(*module);
         }
+      }
     }
 
-    if (custom_passes.EarlyPasses)
-    {
-        if (log)
-            log->Printf("%s - Running Early IR Passes from LanguageRuntime on expression module '%s'", __FUNCTION__,
-                        m_expr.FunctionName());
-
-        custom_passes.EarlyPasses->run(*llvm_module_ap);
-    }
-
-    execution_unit_sp.reset(new IRExecutionUnit (m_llvm_context, // handed off here
-                                                 llvm_module_ap, // handed off here
-                                                 function_name,
-                                                 exe_ctx.GetTargetSP(),
-                                                 sc,
-                                                 m_compiler->getTargetOpts().Features));
-
-    ClangExpressionHelper *type_system_helper = dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
-    ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap(); // result can be NULL
-
-    if (decl_map)
-    {
-        Stream *error_stream = NULL;
-        Target *target = exe_ctx.GetTargetPtr();
-        error_stream = target->GetDebugger().GetErrorFile().get();
-
-        IRForTarget ir_for_target(decl_map, m_expr.NeedsVariableResolution(), *execution_unit_sp, *error_stream,
-                                  function_name.AsCString());
-
-        bool ir_can_run = ir_for_target.runOnModule(*execution_unit_sp->GetModule());
-
-        if (!ir_can_run)
-        {
-            err.SetErrorString("The expression could not be prepared to run in the target");
-            return err;
-        }
+    if (execution_policy == eExecutionPolicyAlways ||
+        execution_policy == eExecutionPolicyTopLevel || !can_interpret) {
+      execution_unit_sp->GetRunnableInfo(err, func_addr, func_end);
+    }
+  } else {
+    execution_unit_sp->GetRunnableInfo(err, func_addr, func_end);
+  }
 
-        Process *process = exe_ctx.GetProcessPtr();
+  return err;
+}
 
-        if (execution_policy != eExecutionPolicyAlways && execution_policy != eExecutionPolicyTopLevel)
-        {
-            lldb_private::Error interpret_error;
-
-            bool interpret_function_calls = !process ? false : process->CanInterpretFunctionCalls();
-            can_interpret =
-                IRInterpreter::CanInterpret(*execution_unit_sp->GetModule(), *execution_unit_sp->GetFunction(),
-                                            interpret_error, interpret_function_calls);
-
-            if (!can_interpret && execution_policy == eExecutionPolicyNever)
-            {
-                err.SetErrorStringWithFormat("Can't run the expression locally: %s", interpret_error.AsCString());
-                return err;
-            }
-        }
+lldb_private::Error ClangExpressionParser::RunStaticInitializers(
+    lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx) {
+  lldb_private::Error err;
+
+  lldbassert(execution_unit_sp.get());
+  lldbassert(exe_ctx.HasThreadScope());
+
+  if (!execution_unit_sp.get()) {
+    err.SetErrorString(
+        "can't run static initializers for a NULL execution unit");
+    return err;
+  }
 
-        if (!process && execution_policy == eExecutionPolicyAlways)
-        {
-            err.SetErrorString("Expression needed to run in the target, but the target can't be run");
-            return err;
-        }
+  if (!exe_ctx.HasThreadScope()) {
+    err.SetErrorString("can't run static initializers without a thread");
+    return err;
+  }
 
-        if (!process && execution_policy == eExecutionPolicyTopLevel)
-        {
-            err.SetErrorString(
-                "Top-level code needs to be inserted into a runnable target, but the target can't be run");
-            return err;
-        }
+  std::vector<lldb::addr_t> static_initializers;
 
-        if (execution_policy == eExecutionPolicyAlways ||
-            (execution_policy != eExecutionPolicyTopLevel && !can_interpret))
-        {
-            if (m_expr.NeedsValidation() && process)
-            {
-                if (!process->GetDynamicCheckers())
-                {
-                    DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
-
-                    DiagnosticManager install_diagnostics;
-
-                    if (!dynamic_checkers->Install(install_diagnostics, exe_ctx))
-                    {
-                        if (install_diagnostics.Diagnostics().size())
-                            err.SetErrorString("couldn't install checkers, unknown error");
-                        else
-                            err.SetErrorString(install_diagnostics.GetString().c_str());
-
-                        return err;
-                    }
-
-                    process->SetDynamicCheckers(dynamic_checkers);
-
-                    if (log)
-                        log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
-                }
-
-                IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(), function_name.AsCString());
-
-                llvm::Module *module = execution_unit_sp->GetModule();
-                if (!module || !ir_dynamic_checks.runOnModule(*module))
-                {
-                    err.SetErrorToGenericError();
-                    err.SetErrorString("Couldn't add dynamic checks to the expression");
-                    return err;
-                }
-
-                if (custom_passes.LatePasses)
-                {
-                    if (log)
-                        log->Printf("%s - Running Late IR Passes from LanguageRuntime on expression module '%s'",
-                                    __FUNCTION__, m_expr.FunctionName());
-
-                    custom_passes.LatePasses->run(*module);
-                }
-            }
-        }
+  execution_unit_sp->GetStaticInitializers(static_initializers);
 
-        if (execution_policy == eExecutionPolicyAlways || execution_policy == eExecutionPolicyTopLevel ||
-            !can_interpret)
-        {
-            execution_unit_sp->GetRunnableInfo(err, func_addr, func_end);
-        }
-    }
-    else
-    {
-        execution_unit_sp->GetRunnableInfo(err, func_addr, func_end);
-    }
+  for (lldb::addr_t static_initializer : static_initializers) {
+    EvaluateExpressionOptions options;
 
-    return err;
-}
+    lldb::ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(
+        exe_ctx.GetThreadRef(), Address(static_initializer), CompilerType(),
+        llvm::ArrayRef<lldb::addr_t>(), options));
 
-lldb_private::Error
-ClangExpressionParser::RunStaticInitializers (lldb::IRExecutionUnitSP &execution_unit_sp,
-                                              ExecutionContext &exe_ctx)
-{
-    lldb_private::Error err;
-    
-    lldbassert(execution_unit_sp.get());
-    lldbassert(exe_ctx.HasThreadScope());
-    
-    if (!execution_unit_sp.get())
-    {
-        err.SetErrorString ("can't run static initializers for a NULL execution unit");
-        return err;
-    }
-    
-    if (!exe_ctx.HasThreadScope())
-    {
-        err.SetErrorString ("can't run static initializers without a thread");
-        return err;
-    }
-    
-    std::vector<lldb::addr_t> static_initializers;
-    
-    execution_unit_sp->GetStaticInitializers(static_initializers);
-    
-    for (lldb::addr_t static_initializer : static_initializers)
-    {
-        EvaluateExpressionOptions options;
-                
-        lldb::ThreadPlanSP call_static_initializer(new ThreadPlanCallFunction(exe_ctx.GetThreadRef(),
-                                                                              Address(static_initializer),
-                                                                              CompilerType(),
-                                                                              llvm::ArrayRef<lldb::addr_t>(),
-                                                                              options));
-        
-        DiagnosticManager execution_errors;
-        lldb::ExpressionResults results = exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(exe_ctx, call_static_initializer, options, execution_errors);
-        
-        if (results != lldb::eExpressionCompleted)
-        {
-            err.SetErrorStringWithFormat ("couldn't run static initializer: %s", execution_errors.GetString().c_str());
-            return err;
-        }
+    DiagnosticManager execution_errors;
+    lldb::ExpressionResults results =
+        exe_ctx.GetThreadRef().GetProcess()->RunThreadPlan(
+            exe_ctx, call_static_initializer, options, execution_errors);
+
+    if (results != lldb::eExpressionCompleted) {
+      err.SetErrorStringWithFormat("couldn't run static initializer: %s",
+                                   execution_errors.GetString().c_str());
+      return err;
     }
-    
-    return err;
+  }
+
+  return err;
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h Tue Sep  6 15:57:50 2016
@@ -20,13 +20,13 @@
 #include <string>
 #include <vector>
 
-namespace lldb_private
-{
+namespace lldb_private {
 
 class IRExecutionUnit;
-    
+
 //----------------------------------------------------------------------
-/// @class ClangExpressionParser ClangExpressionParser.h "lldb/Expression/ClangExpressionParser.h"
+/// @class ClangExpressionParser ClangExpressionParser.h
+/// "lldb/Expression/ClangExpressionParser.h"
 /// @brief Encapsulates an instance of Clang that can parse expressions.
 ///
 /// ClangExpressionParser is responsible for preparing an instance of
@@ -35,134 +35,132 @@ class IRExecutionUnit;
 /// conversion to formats (DWARF bytecode, or JIT compiled machine code)
 /// that can be executed.
 //----------------------------------------------------------------------
-class ClangExpressionParser : public ExpressionParser
-{
+class ClangExpressionParser : public ExpressionParser {
 public:
-    //------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// Initializes class variables.
-    ///
-    /// @param[in] exe_scope,
-    ///     If non-NULL, an execution context scope that can help to 
-    ///     correctly create an expression with a valid process for 
-    ///     optional tuning Objective-C runtime support. Can be NULL.
-    ///
-    /// @param[in] expr
-    ///     The expression to be parsed.
-    //------------------------------------------------------------------
-    ClangExpressionParser (ExecutionContextScope *exe_scope,
-                           Expression &expr,
-                           bool generate_debug_info);
-    
-    //------------------------------------------------------------------
-    /// Destructor
-    //------------------------------------------------------------------
-    ~ClangExpressionParser () override;
-    
-    //------------------------------------------------------------------
-    /// Parse a single expression and convert it to IR using Clang.  Don't
-    /// wrap the expression in anything at all.
-    ///
-    /// @param[in] diagnostic_manager
-    ///     The diagnostic manager to report errors to.
-    ///
-    /// @return
-    ///     The number of errors encountered during parsing.  0 means
-    ///     success.
-    //------------------------------------------------------------------
-    unsigned
-    Parse(DiagnosticManager &diagnostic_manager) override;
-    
-    bool
-    RewriteExpression(DiagnosticManager &diagnostic_manager) override;
-
-    //------------------------------------------------------------------
-    /// Ready an already-parsed expression for execution, possibly
-    /// evaluating it statically.
-    ///
-    /// @param[out] func_addr
-    ///     The address to which the function has been written.
-    ///
-    /// @param[out] func_end
-    ///     The end of the function's allocated memory region.  (func_addr
-    ///     and func_end do not delimit an allocated region; the allocated
-    ///     region may begin before func_addr.)
-    ///
-    /// @param[in] execution_unit_sp
-    ///     After parsing, ownership of the execution unit for
-    ///     for the expression is handed to this shared pointer.
-    ///
-    /// @param[in] exe_ctx
-    ///     The execution context to write the function into.
-    ///
-    /// @param[out] evaluated_statically
-    ///     Set to true if the expression could be interpreted statically;
-    ///     untouched otherwise.
-    ///
-    /// @param[out] const_result
-    ///     If the result of the expression is constant, and the
-    ///     expression has no side effects, this is set to the result of the
-    ///     expression.
-    ///
-    /// @param[in] execution_policy
-    ///     Determines whether the expression must be JIT-compiled, must be
-    ///     evaluated statically, or whether this decision may be made
-    ///     opportunistically.
-    ///
-    /// @return
-    ///     An error code indicating the success or failure of the operation.
-    ///     Test with Success().
-    //------------------------------------------------------------------
-    Error
-    PrepareForExecution (lldb::addr_t &func_addr,
-                         lldb::addr_t &func_end,
-                         lldb::IRExecutionUnitSP &execution_unit_sp,
-                         ExecutionContext &exe_ctx,
-                         bool &can_interpret,
-                         lldb_private::ExecutionPolicy execution_policy) override;
-    
-    //------------------------------------------------------------------
-    /// Run all static initializers for an execution unit.
-    ///
-    /// @param[in] execution_unit_sp
-    ///     The execution unit.
-    ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use when running them.  Thread can't be null.
-    ///
-    /// @return
-    ///     The error code indicating the 
-    //------------------------------------------------------------------
-    Error
-    RunStaticInitializers (lldb::IRExecutionUnitSP &execution_unit_sp,
-                           ExecutionContext &exe_ctx);
-
-    //------------------------------------------------------------------
-    /// Returns a string representing current ABI.
-    ///
-    /// @param[in] target_arch
-    ///     The target architecture.
-    ///
-    /// @return
-    ///     A string representing target ABI for the current architecture.
-    //-------------------------------------------------------------------
-    std::string
-    GetClangTargetABI (const ArchSpec &target_arch);
- 
+  //------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// Initializes class variables.
+  ///
+  /// @param[in] exe_scope,
+  ///     If non-NULL, an execution context scope that can help to
+  ///     correctly create an expression with a valid process for
+  ///     optional tuning Objective-C runtime support. Can be NULL.
+  ///
+  /// @param[in] expr
+  ///     The expression to be parsed.
+  //------------------------------------------------------------------
+  ClangExpressionParser(ExecutionContextScope *exe_scope, Expression &expr,
+                        bool generate_debug_info);
+
+  //------------------------------------------------------------------
+  /// Destructor
+  //------------------------------------------------------------------
+  ~ClangExpressionParser() override;
+
+  //------------------------------------------------------------------
+  /// Parse a single expression and convert it to IR using Clang.  Don't
+  /// wrap the expression in anything at all.
+  ///
+  /// @param[in] diagnostic_manager
+  ///     The diagnostic manager to report errors to.
+  ///
+  /// @return
+  ///     The number of errors encountered during parsing.  0 means
+  ///     success.
+  //------------------------------------------------------------------
+  unsigned Parse(DiagnosticManager &diagnostic_manager) override;
+
+  bool RewriteExpression(DiagnosticManager &diagnostic_manager) override;
+
+  //------------------------------------------------------------------
+  /// Ready an already-parsed expression for execution, possibly
+  /// evaluating it statically.
+  ///
+  /// @param[out] func_addr
+  ///     The address to which the function has been written.
+  ///
+  /// @param[out] func_end
+  ///     The end of the function's allocated memory region.  (func_addr
+  ///     and func_end do not delimit an allocated region; the allocated
+  ///     region may begin before func_addr.)
+  ///
+  /// @param[in] execution_unit_sp
+  ///     After parsing, ownership of the execution unit for
+  ///     for the expression is handed to this shared pointer.
+  ///
+  /// @param[in] exe_ctx
+  ///     The execution context to write the function into.
+  ///
+  /// @param[out] evaluated_statically
+  ///     Set to true if the expression could be interpreted statically;
+  ///     untouched otherwise.
+  ///
+  /// @param[out] const_result
+  ///     If the result of the expression is constant, and the
+  ///     expression has no side effects, this is set to the result of the
+  ///     expression.
+  ///
+  /// @param[in] execution_policy
+  ///     Determines whether the expression must be JIT-compiled, must be
+  ///     evaluated statically, or whether this decision may be made
+  ///     opportunistically.
+  ///
+  /// @return
+  ///     An error code indicating the success or failure of the operation.
+  ///     Test with Success().
+  //------------------------------------------------------------------
+  Error
+  PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
+                      lldb::IRExecutionUnitSP &execution_unit_sp,
+                      ExecutionContext &exe_ctx, bool &can_interpret,
+                      lldb_private::ExecutionPolicy execution_policy) override;
+
+  //------------------------------------------------------------------
+  /// Run all static initializers for an execution unit.
+  ///
+  /// @param[in] execution_unit_sp
+  ///     The execution unit.
+  ///
+  /// @param[in] exe_ctx
+  ///     The execution context to use when running them.  Thread can't be null.
+  ///
+  /// @return
+  ///     The error code indicating the
+  //------------------------------------------------------------------
+  Error RunStaticInitializers(lldb::IRExecutionUnitSP &execution_unit_sp,
+                              ExecutionContext &exe_ctx);
+
+  //------------------------------------------------------------------
+  /// Returns a string representing current ABI.
+  ///
+  /// @param[in] target_arch
+  ///     The target architecture.
+  ///
+  /// @return
+  ///     A string representing target ABI for the current architecture.
+  //-------------------------------------------------------------------
+  std::string GetClangTargetABI(const ArchSpec &target_arch);
+
 private:
-    std::unique_ptr<llvm::LLVMContext>       m_llvm_context;         ///< The LLVM context to generate IR into
-    std::unique_ptr<clang::FileManager>      m_file_manager;         ///< The Clang file manager object used by the compiler
-    std::unique_ptr<clang::CompilerInstance> m_compiler;             ///< The Clang compiler used to parse expressions into IR
-    std::unique_ptr<clang::Builtin::Context> m_builtin_context;      ///< Context for Clang built-ins
-    std::unique_ptr<clang::SelectorTable>    m_selector_table;       ///< Selector table for Objective-C methods
-    std::unique_ptr<clang::CodeGenerator>    m_code_generator;       ///< The Clang object that generates IR
-    
-    class LLDBPreprocessorCallbacks;
-    LLDBPreprocessorCallbacks               *m_pp_callbacks;         ///< Called when the preprocessor encounters module imports
-    std::unique_ptr<ClangASTContext>         m_ast_context;
+  std::unique_ptr<llvm::LLVMContext>
+      m_llvm_context; ///< The LLVM context to generate IR into
+  std::unique_ptr<clang::FileManager>
+      m_file_manager; ///< The Clang file manager object used by the compiler
+  std::unique_ptr<clang::CompilerInstance>
+      m_compiler; ///< The Clang compiler used to parse expressions into IR
+  std::unique_ptr<clang::Builtin::Context>
+      m_builtin_context; ///< Context for Clang built-ins
+  std::unique_ptr<clang::SelectorTable>
+      m_selector_table; ///< Selector table for Objective-C methods
+  std::unique_ptr<clang::CodeGenerator>
+      m_code_generator; ///< The Clang object that generates IR
+
+  class LLDBPreprocessorCallbacks;
+  LLDBPreprocessorCallbacks *m_pp_callbacks; ///< Called when the preprocessor
+                                             ///encounters module imports
+  std::unique_ptr<ClangASTContext> m_ast_context;
 };
-    
 }
 
-#endif  // liblldb_ClangExpressionParser_h_
+#endif // liblldb_ClangExpressionParser_h_

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp Tue Sep  6 15:57:50 2016
@@ -9,7 +9,6 @@
 
 #include "ClangExpressionVariable.h"
 
-#include "clang/AST/ASTContext.h"
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/DataExtractor.h"
 #include "lldb/Core/Stream.h"
@@ -17,60 +16,54 @@
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
+#include "clang/AST/ASTContext.h"
 
 using namespace lldb_private;
 using namespace clang;
 
 const char *g_clang_expression_variable_kind_name = "ClangExpressionVariable";
 
-ClangExpressionVariable::ClangExpressionVariable(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size) :
-    ExpressionVariable(LLVMCastKind::eKindClang),
-    m_parser_vars(),
-    m_jit_vars ()
-{
-    m_flags = EVNone;
-    m_frozen_sp = ValueObjectConstResult::Create (exe_scope, byte_order, addr_byte_size);
+ClangExpressionVariable::ClangExpressionVariable(
+    ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order,
+    uint32_t addr_byte_size)
+    : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(),
+      m_jit_vars() {
+  m_flags = EVNone;
+  m_frozen_sp =
+      ValueObjectConstResult::Create(exe_scope, byte_order, addr_byte_size);
 }
 
-ClangExpressionVariable::ClangExpressionVariable (ExecutionContextScope *exe_scope,
-                                                  Value &value,
-                                                  const ConstString &name,
-                                                  uint16_t flags) :
-    ExpressionVariable(LLVMCastKind::eKindClang),
-    m_parser_vars(),
-    m_jit_vars ()
-{
-    m_flags = flags;
-    m_frozen_sp = ValueObjectConstResult::Create (exe_scope, value, name);
+ClangExpressionVariable::ClangExpressionVariable(
+    ExecutionContextScope *exe_scope, Value &value, const ConstString &name,
+    uint16_t flags)
+    : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(),
+      m_jit_vars() {
+  m_flags = flags;
+  m_frozen_sp = ValueObjectConstResult::Create(exe_scope, value, name);
 }
 
-ClangExpressionVariable::ClangExpressionVariable (const lldb::ValueObjectSP &valobj_sp) :
-    ExpressionVariable(LLVMCastKind::eKindClang),
-    m_parser_vars(),
-    m_jit_vars ()
-{
-    m_flags = EVNone;
-    m_frozen_sp = valobj_sp;
+ClangExpressionVariable::ClangExpressionVariable(
+    const lldb::ValueObjectSP &valobj_sp)
+    : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(),
+      m_jit_vars() {
+  m_flags = EVNone;
+  m_frozen_sp = valobj_sp;
 }
 
-ClangExpressionVariable::ClangExpressionVariable(ExecutionContextScope *exe_scope,
-                                                 const ConstString &name,
-                                                 const TypeFromUser& user_type,
-                                                 lldb::ByteOrder byte_order,
-                                                 uint32_t addr_byte_size) :
-    ExpressionVariable(LLVMCastKind::eKindClang),
-    m_parser_vars(),
-    m_jit_vars()
-{
-    m_flags = EVNone;
-    m_frozen_sp = ValueObjectConstResult::Create (exe_scope, byte_order, addr_byte_size);
-    SetName (name);
-    SetCompilerType (user_type);
+ClangExpressionVariable::ClangExpressionVariable(
+    ExecutionContextScope *exe_scope, const ConstString &name,
+    const TypeFromUser &user_type, lldb::ByteOrder byte_order,
+    uint32_t addr_byte_size)
+    : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(),
+      m_jit_vars() {
+  m_flags = EVNone;
+  m_frozen_sp =
+      ValueObjectConstResult::Create(exe_scope, byte_order, addr_byte_size);
+  SetName(name);
+  SetCompilerType(user_type);
 }
 
-TypeFromUser
-ClangExpressionVariable::GetTypeFromUser()
-{
-    TypeFromUser tfu (m_frozen_sp->GetCompilerType());
-    return tfu;
+TypeFromUser ClangExpressionVariable::GetTypeFromUser() {
+  TypeFromUser tfu(m_frozen_sp->GetCompilerType());
+  return tfu;
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h Tue Sep  6 15:57:50 2016
@@ -24,15 +24,15 @@
 #include "llvm/Support/Casting.h"
 
 // Project includes
-#include "lldb/lldb-public.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Expression/ExpressionVariable.h"
 #include "lldb/Symbol/TaggedASTType.h"
+#include "lldb/lldb-public.h"
 
 namespace llvm {
-    class Value;
+class Value;
 }
 
 namespace lldb_private {
@@ -40,7 +40,8 @@ namespace lldb_private {
 class ValueObjectConstResult;
 
 //----------------------------------------------------------------------
-/// @class ClangExpressionVariable ClangExpressionVariable.h "lldb/Expression/ClangExpressionVariable.h"
+/// @class ClangExpressionVariable ClangExpressionVariable.h
+/// "lldb/Expression/ClangExpressionVariable.h"
 /// @brief Encapsulates one variable for the expression parser.
 ///
 /// The expression parser uses variables in three different contexts:
@@ -62,204 +63,178 @@ class ValueObjectConstResult;
 /// polymorphism, and provides necessary support methods.  Its interface
 /// is RTTI-neutral.
 //----------------------------------------------------------------------
-class ClangExpressionVariable : public ExpressionVariable
-{
+class ClangExpressionVariable : public ExpressionVariable {
 public:
-    ClangExpressionVariable(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size);
+  ClangExpressionVariable(ExecutionContextScope *exe_scope,
+                          lldb::ByteOrder byte_order, uint32_t addr_byte_size);
 
-    ClangExpressionVariable (ExecutionContextScope *exe_scope,
-                             Value &value,
-                             const ConstString &name,
-                             uint16_t flags = EVNone);
-    
-    ClangExpressionVariable(const lldb::ValueObjectSP &valobj_sp);
-    
-    ClangExpressionVariable(ExecutionContextScope *exe_scope,
-                            const ConstString &name,
-                            const TypeFromUser& user_type,
-                            lldb::ByteOrder byte_order,
-                            uint32_t addr_byte_size);
-        
-    //----------------------------------------------------------------------
-    /// Utility functions for dealing with ExpressionVariableLists in Clang-specific ways
-    //----------------------------------------------------------------------
-    
-    //----------------------------------------------------------------------
-    /// Finds a variable by NamedDecl in the list.
-    ///
-    /// @param[in] name
-    ///     The name of the requested variable.
-    ///
-    /// @return
-    ///     The variable requested, or NULL if that variable is not in the list.
-    //----------------------------------------------------------------------
-    static ClangExpressionVariable *
-    FindVariableInList (ExpressionVariableList &list, const clang::NamedDecl *decl, uint64_t parser_id)
-    {
-        lldb::ExpressionVariableSP var_sp;
-        for (size_t index = 0, size = list.GetSize(); index < size; ++index)
-        {
-            var_sp = list.GetVariableAtIndex(index);
-            
-            if (ClangExpressionVariable *clang_var = llvm::dyn_cast<ClangExpressionVariable>(var_sp.get()))
-            {
-                ClangExpressionVariable::ParserVars *parser_vars = clang_var->GetParserVars(parser_id);
-                
-                if (parser_vars && parser_vars->m_named_decl == decl)
-                    return clang_var;
-            }
-        }
-        return nullptr;
-    }
+  ClangExpressionVariable(ExecutionContextScope *exe_scope, Value &value,
+                          const ConstString &name, uint16_t flags = EVNone);
+
+  ClangExpressionVariable(const lldb::ValueObjectSP &valobj_sp);
+
+  ClangExpressionVariable(ExecutionContextScope *exe_scope,
+                          const ConstString &name,
+                          const TypeFromUser &user_type,
+                          lldb::ByteOrder byte_order, uint32_t addr_byte_size);
+
+  //----------------------------------------------------------------------
+  /// Utility functions for dealing with ExpressionVariableLists in
+  /// Clang-specific ways
+  //----------------------------------------------------------------------
+
+  //----------------------------------------------------------------------
+  /// Finds a variable by NamedDecl in the list.
+  ///
+  /// @param[in] name
+  ///     The name of the requested variable.
+  ///
+  /// @return
+  ///     The variable requested, or NULL if that variable is not in the list.
+  //----------------------------------------------------------------------
+  static ClangExpressionVariable *
+  FindVariableInList(ExpressionVariableList &list, const clang::NamedDecl *decl,
+                     uint64_t parser_id) {
+    lldb::ExpressionVariableSP var_sp;
+    for (size_t index = 0, size = list.GetSize(); index < size; ++index) {
+      var_sp = list.GetVariableAtIndex(index);
+
+      if (ClangExpressionVariable *clang_var =
+              llvm::dyn_cast<ClangExpressionVariable>(var_sp.get())) {
+        ClangExpressionVariable::ParserVars *parser_vars =
+            clang_var->GetParserVars(parser_id);
+
+        if (parser_vars && parser_vars->m_named_decl == decl)
+          return clang_var;
+      }
+    }
+    return nullptr;
+  }
+
+  //----------------------------------------------------------------------
+  /// If the variable contains its own data, make a Value point at it.
+  /// If \a exe_ctx in not NULL, the value will be resolved in with
+  /// that execution context.
+  ///
+  /// @param[in] value
+  ///     The value to point at the data.
+  ///
+  /// @param[in] exe_ctx
+  ///     The execution context to use to resolve \a value.
+  ///
+  /// @return
+  ///     True on success; false otherwise (in particular, if this variable
+  ///     does not contain its own data).
+  //----------------------------------------------------------------------
+  bool PointValueAtData(Value &value, ExecutionContext *exe_ctx);
+
+  //----------------------------------------------------------------------
+  /// The following values should not live beyond parsing
+  //----------------------------------------------------------------------
+  class ParserVars {
+  public:
+    ParserVars()
+        : m_parser_type(), m_named_decl(NULL), m_llvm_value(NULL),
+          m_lldb_value(), m_lldb_var(), m_lldb_sym(NULL) {}
+
+    TypeFromParser
+        m_parser_type; ///< The type of the variable according to the parser
+    const clang::NamedDecl
+        *m_named_decl;         ///< The Decl corresponding to this variable
+    llvm::Value *m_llvm_value; ///< The IR value corresponding to this variable;
+                               ///usually a GlobalValue
+    lldb_private::Value
+        m_lldb_value;            ///< The value found in LLDB for this variable
+    lldb::VariableSP m_lldb_var; ///< The original variable for this variable
+    const lldb_private::Symbol *m_lldb_sym; ///< The original symbol for this
+                                            ///variable, if it was a symbol
+  };
 
-    //----------------------------------------------------------------------
-    /// If the variable contains its own data, make a Value point at it.
-    /// If \a exe_ctx in not NULL, the value will be resolved in with
-    /// that execution context.
-    ///
-    /// @param[in] value
-    ///     The value to point at the data.
-    ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use to resolve \a value.
-    ///
-    /// @return
-    ///     True on success; false otherwise (in particular, if this variable
-    ///     does not contain its own data).
-    //----------------------------------------------------------------------
-    bool
-    PointValueAtData(Value &value, ExecutionContext *exe_ctx);
-    
-    //----------------------------------------------------------------------
-    /// The following values should not live beyond parsing
-    //----------------------------------------------------------------------
-    class ParserVars 
-    {
-    public:
-
-        ParserVars() :
-            m_parser_type(),
-            m_named_decl (NULL),
-            m_llvm_value (NULL),
-            m_lldb_value (),
-            m_lldb_var   (),
-            m_lldb_sym   (NULL)
-        {
-        }
-
-        TypeFromParser          m_parser_type;  ///< The type of the variable according to the parser
-        const clang::NamedDecl *m_named_decl;   ///< The Decl corresponding to this variable
-        llvm::Value            *m_llvm_value;   ///< The IR value corresponding to this variable; usually a GlobalValue
-        lldb_private::Value     m_lldb_value;   ///< The value found in LLDB for this variable
-        lldb::VariableSP        m_lldb_var;     ///< The original variable for this variable
-        const lldb_private::Symbol *m_lldb_sym; ///< The original symbol for this variable, if it was a symbol
-    };
-    
 private:
-    typedef std::map <uint64_t, ParserVars> ParserVarMap;
-    ParserVarMap m_parser_vars;
+  typedef std::map<uint64_t, ParserVars> ParserVarMap;
+  ParserVarMap m_parser_vars;
 
 public:
-    //----------------------------------------------------------------------
-    /// Make this variable usable by the parser by allocating space for
-    /// parser-specific variables
-    //----------------------------------------------------------------------
-    void 
-    EnableParserVars(uint64_t parser_id)
-    {
-        m_parser_vars.insert(std::make_pair(parser_id, ParserVars()));
-    }
-    
-    //----------------------------------------------------------------------
-    /// Deallocate parser-specific variables
-    //----------------------------------------------------------------------
-    void
-    DisableParserVars(uint64_t parser_id)
-    {
-        m_parser_vars.erase(parser_id);
-    }
-    
-    //----------------------------------------------------------------------
-    /// Access parser-specific variables
-    //----------------------------------------------------------------------
-    ParserVars *
-    GetParserVars(uint64_t parser_id)
-    {
-        ParserVarMap::iterator i = m_parser_vars.find(parser_id);
-        
-        if (i == m_parser_vars.end())
-            return NULL;
-        else
-            return &i->second;
-    }
-    
-    //----------------------------------------------------------------------
-    /// The following values are valid if the variable is used by JIT code
-    //----------------------------------------------------------------------
-    struct JITVars {
-        JITVars () :
-            m_alignment (0),
-            m_size (0),
-            m_offset (0)
-        {
-        }
-
-        lldb::offset_t   m_alignment; ///< The required alignment of the variable, in bytes
-        size_t  m_size;               ///< The space required for the variable, in bytes
-        lldb::offset_t   m_offset;    ///< The offset of the variable in the struct, in bytes
-    };
-    
+  //----------------------------------------------------------------------
+  /// Make this variable usable by the parser by allocating space for
+  /// parser-specific variables
+  //----------------------------------------------------------------------
+  void EnableParserVars(uint64_t parser_id) {
+    m_parser_vars.insert(std::make_pair(parser_id, ParserVars()));
+  }
+
+  //----------------------------------------------------------------------
+  /// Deallocate parser-specific variables
+  //----------------------------------------------------------------------
+  void DisableParserVars(uint64_t parser_id) { m_parser_vars.erase(parser_id); }
+
+  //----------------------------------------------------------------------
+  /// Access parser-specific variables
+  //----------------------------------------------------------------------
+  ParserVars *GetParserVars(uint64_t parser_id) {
+    ParserVarMap::iterator i = m_parser_vars.find(parser_id);
+
+    if (i == m_parser_vars.end())
+      return NULL;
+    else
+      return &i->second;
+  }
+
+  //----------------------------------------------------------------------
+  /// The following values are valid if the variable is used by JIT code
+  //----------------------------------------------------------------------
+  struct JITVars {
+    JITVars() : m_alignment(0), m_size(0), m_offset(0) {}
+
+    lldb::offset_t
+        m_alignment; ///< The required alignment of the variable, in bytes
+    size_t m_size;   ///< The space required for the variable, in bytes
+    lldb::offset_t
+        m_offset; ///< The offset of the variable in the struct, in bytes
+  };
+
 private:
-    typedef std::map <uint64_t, JITVars> JITVarMap;
-    JITVarMap m_jit_vars;
-    
+  typedef std::map<uint64_t, JITVars> JITVarMap;
+  JITVarMap m_jit_vars;
+
 public:
-    //----------------------------------------------------------------------
-    /// Make this variable usable for materializing for the JIT by allocating 
-    /// space for JIT-specific variables
-    //----------------------------------------------------------------------
-    void 
-    EnableJITVars(uint64_t parser_id)
-    {
-        m_jit_vars.insert(std::make_pair(parser_id, JITVars()));
-    }
-    
-    //----------------------------------------------------------------------
-    /// Deallocate JIT-specific variables
-    //----------------------------------------------------------------------
-    void 
-    DisableJITVars(uint64_t parser_id)
-    {
-        m_jit_vars.erase(parser_id);
-    }
-    
-    JITVars *GetJITVars(uint64_t parser_id)
-    {
-        JITVarMap::iterator i = m_jit_vars.find(parser_id);
-        
-        if (i == m_jit_vars.end())
-            return NULL;
-        else
-            return &i->second;
-    }
-    
-    TypeFromUser
-    GetTypeFromUser ();
-    
-    //------------------------------------------------------------------
-    // llvm casting support
-    //------------------------------------------------------------------
-    static bool classof(const ExpressionVariable *ev)
-    {
-        return ev->getKind() == ExpressionVariable::eKindClang;
-    }
-    
-    //----------------------------------------------------------------------
-    /// Members
-    //----------------------------------------------------------------------        
-    DISALLOW_COPY_AND_ASSIGN (ClangExpressionVariable);
+  //----------------------------------------------------------------------
+  /// Make this variable usable for materializing for the JIT by allocating
+  /// space for JIT-specific variables
+  //----------------------------------------------------------------------
+  void EnableJITVars(uint64_t parser_id) {
+    m_jit_vars.insert(std::make_pair(parser_id, JITVars()));
+  }
+
+  //----------------------------------------------------------------------
+  /// Deallocate JIT-specific variables
+  //----------------------------------------------------------------------
+  void DisableJITVars(uint64_t parser_id) { m_jit_vars.erase(parser_id); }
+
+  JITVars *GetJITVars(uint64_t parser_id) {
+    JITVarMap::iterator i = m_jit_vars.find(parser_id);
+
+    if (i == m_jit_vars.end())
+      return NULL;
+    else
+      return &i->second;
+  }
+
+  TypeFromUser GetTypeFromUser();
+
+  //------------------------------------------------------------------
+  // llvm casting support
+  //------------------------------------------------------------------
+  static bool classof(const ExpressionVariable *ev) {
+    return ev->getKind() == ExpressionVariable::eKindClang;
+  }
+
+  //----------------------------------------------------------------------
+  /// Members
+  //----------------------------------------------------------------------
+  DISALLOW_COPY_AND_ASSIGN(ClangExpressionVariable);
 };
 
 } // namespace lldb_private
 
-#endif  // liblldb_ClangExpressionVariable_h_
+#endif // liblldb_ClangExpressionVariable_h_

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp Tue Sep  6 15:57:50 2016
@@ -50,178 +50,177 @@ using namespace lldb_private;
 //----------------------------------------------------------------------
 // ClangFunctionCaller constructor
 //----------------------------------------------------------------------
-ClangFunctionCaller::ClangFunctionCaller 
-(
-    ExecutionContextScope &exe_scope,
-    const CompilerType &return_type, 
-    const Address& functionAddress, 
-    const ValueList &arg_value_list,
-    const char *name
-) :
-    FunctionCaller(exe_scope, return_type, functionAddress, arg_value_list, name),
-    m_type_system_helper (*this)
-{
-    m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
-    // Can't make a ClangFunctionCaller without a process.
-    assert (m_jit_process_wp.lock());
+ClangFunctionCaller::ClangFunctionCaller(ExecutionContextScope &exe_scope,
+                                         const CompilerType &return_type,
+                                         const Address &functionAddress,
+                                         const ValueList &arg_value_list,
+                                         const char *name)
+    : FunctionCaller(exe_scope, return_type, functionAddress, arg_value_list,
+                     name),
+      m_type_system_helper(*this) {
+  m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
+  // Can't make a ClangFunctionCaller without a process.
+  assert(m_jit_process_wp.lock());
 }
 
 //----------------------------------------------------------------------
 // Destructor
 //----------------------------------------------------------------------
-ClangFunctionCaller::~ClangFunctionCaller()
-{
-}
+ClangFunctionCaller::~ClangFunctionCaller() {}
 
 unsigned
 
-ClangFunctionCaller::CompileFunction (lldb::ThreadSP thread_to_use_sp, 
-                                      DiagnosticManager &diagnostic_manager)
-{
-    if (m_compiled)
-        return 0;
-
-    // Compilation might call code, make sure to keep on the thread the caller indicated.
-    ThreadList::ExpressionExecutionThreadPusher execution_thread_pusher(thread_to_use_sp);
-    
-    // FIXME: How does clang tell us there's no return value?  We need to handle that case.
-    unsigned num_errors = 0;
-    
-    std::string return_type_str (m_function_return_type.GetTypeName().AsCString(""));
-    
-    // Cons up the function we're going to wrap our call in, then compile it...
-    // We declare the function "extern "C"" because the compiler might be in C++
-    // mode which would mangle the name and then we couldn't find it again...
-    m_wrapper_function_text.clear();
-    m_wrapper_function_text.append ("extern \"C\" void ");
-    m_wrapper_function_text.append (m_wrapper_function_name);
-    m_wrapper_function_text.append (" (void *input)\n{\n    struct ");
-    m_wrapper_function_text.append (m_wrapper_struct_name);
-    m_wrapper_function_text.append (" \n  {\n");
-    m_wrapper_function_text.append ("    ");
-    m_wrapper_function_text.append (return_type_str);
-    m_wrapper_function_text.append (" (*fn_ptr) (");
-
-    // Get the number of arguments.  If we have a function type and it is prototyped,
-    // trust that, otherwise use the values we were given.
-
-    // FIXME: This will need to be extended to handle Variadic functions.  We'll need
-    // to pull the defined arguments out of the function, then add the types from the
-    // arguments list for the variable arguments.
-
-    uint32_t num_args = UINT32_MAX;
-    bool trust_function = false;
-    // GetArgumentCount returns -1 for an unprototyped function.
-    CompilerType function_clang_type;
-    if (m_function_ptr)
-    {
-        function_clang_type = m_function_ptr->GetCompilerType();
-        if (function_clang_type)
-        {
-            int num_func_args = function_clang_type.GetFunctionArgumentCount();
-            if (num_func_args >= 0)
-            {
-                trust_function = true;
-                num_args = num_func_args;
-            }
-        }
+ClangFunctionCaller::CompileFunction(lldb::ThreadSP thread_to_use_sp,
+                                     DiagnosticManager &diagnostic_manager) {
+  if (m_compiled)
+    return 0;
+
+  // Compilation might call code, make sure to keep on the thread the caller
+  // indicated.
+  ThreadList::ExpressionExecutionThreadPusher execution_thread_pusher(
+      thread_to_use_sp);
+
+  // FIXME: How does clang tell us there's no return value?  We need to handle
+  // that case.
+  unsigned num_errors = 0;
+
+  std::string return_type_str(
+      m_function_return_type.GetTypeName().AsCString(""));
+
+  // Cons up the function we're going to wrap our call in, then compile it...
+  // We declare the function "extern "C"" because the compiler might be in C++
+  // mode which would mangle the name and then we couldn't find it again...
+  m_wrapper_function_text.clear();
+  m_wrapper_function_text.append("extern \"C\" void ");
+  m_wrapper_function_text.append(m_wrapper_function_name);
+  m_wrapper_function_text.append(" (void *input)\n{\n    struct ");
+  m_wrapper_function_text.append(m_wrapper_struct_name);
+  m_wrapper_function_text.append(" \n  {\n");
+  m_wrapper_function_text.append("    ");
+  m_wrapper_function_text.append(return_type_str);
+  m_wrapper_function_text.append(" (*fn_ptr) (");
+
+  // Get the number of arguments.  If we have a function type and it is
+  // prototyped,
+  // trust that, otherwise use the values we were given.
+
+  // FIXME: This will need to be extended to handle Variadic functions.  We'll
+  // need
+  // to pull the defined arguments out of the function, then add the types from
+  // the
+  // arguments list for the variable arguments.
+
+  uint32_t num_args = UINT32_MAX;
+  bool trust_function = false;
+  // GetArgumentCount returns -1 for an unprototyped function.
+  CompilerType function_clang_type;
+  if (m_function_ptr) {
+    function_clang_type = m_function_ptr->GetCompilerType();
+    if (function_clang_type) {
+      int num_func_args = function_clang_type.GetFunctionArgumentCount();
+      if (num_func_args >= 0) {
+        trust_function = true;
+        num_args = num_func_args;
+      }
     }
+  }
 
-    if (num_args == UINT32_MAX)
-        num_args = m_arg_values.GetSize();
-
-    std::string args_buffer;  // This one stores the definition of all the args in "struct caller".
-    std::string args_list_buffer;  // This one stores the argument list called from the structure.
-    for (size_t i = 0; i < num_args; i++)
-    {
-        std::string type_name;
-
-        if (trust_function)
-        {
-            type_name = function_clang_type.GetFunctionArgumentTypeAtIndex(i).GetTypeName().AsCString("");
-        }
-        else
-        {
-            CompilerType clang_qual_type = m_arg_values.GetValueAtIndex(i)->GetCompilerType ();
-            if (clang_qual_type)
-            {
-                type_name = clang_qual_type.GetTypeName().AsCString("");
-            }
-            else
-            {
-                diagnostic_manager.Printf(eDiagnosticSeverityError,
-                                          "Could not determine type of input value %" PRIu64 ".", (uint64_t)i);
-                return 1;
-            }
-        }
-
-        m_wrapper_function_text.append (type_name);
-        if (i < num_args - 1)
-            m_wrapper_function_text.append (", ");
-
-        char arg_buf[32];
-        args_buffer.append ("    ");
-        args_buffer.append (type_name);
-        snprintf(arg_buf, 31, "arg_%" PRIu64, (uint64_t)i);
-        args_buffer.push_back (' ');
-        args_buffer.append (arg_buf);
-        args_buffer.append (";\n");
-
-        args_list_buffer.append ("__lldb_fn_data->");
-        args_list_buffer.append (arg_buf);
-        if (i < num_args - 1)
-            args_list_buffer.append (", ");
+  if (num_args == UINT32_MAX)
+    num_args = m_arg_values.GetSize();
 
+  std::string args_buffer; // This one stores the definition of all the args in
+                           // "struct caller".
+  std::string args_list_buffer; // This one stores the argument list called from
+                                // the structure.
+  for (size_t i = 0; i < num_args; i++) {
+    std::string type_name;
+
+    if (trust_function) {
+      type_name = function_clang_type.GetFunctionArgumentTypeAtIndex(i)
+                      .GetTypeName()
+                      .AsCString("");
+    } else {
+      CompilerType clang_qual_type =
+          m_arg_values.GetValueAtIndex(i)->GetCompilerType();
+      if (clang_qual_type) {
+        type_name = clang_qual_type.GetTypeName().AsCString("");
+      } else {
+        diagnostic_manager.Printf(
+            eDiagnosticSeverityError,
+            "Could not determine type of input value %" PRIu64 ".",
+            (uint64_t)i);
+        return 1;
+      }
     }
-    m_wrapper_function_text.append (");\n"); // Close off the function calling prototype.
-
-    m_wrapper_function_text.append (args_buffer);
-
-    m_wrapper_function_text.append ("    ");
-    m_wrapper_function_text.append (return_type_str);
-    m_wrapper_function_text.append (" return_value;");
-    m_wrapper_function_text.append ("\n  };\n  struct ");
-    m_wrapper_function_text.append (m_wrapper_struct_name);
-    m_wrapper_function_text.append ("* __lldb_fn_data = (struct ");
-    m_wrapper_function_text.append (m_wrapper_struct_name);
-    m_wrapper_function_text.append (" *) input;\n");
-
-    m_wrapper_function_text.append ("  __lldb_fn_data->return_value = __lldb_fn_data->fn_ptr (");
-    m_wrapper_function_text.append (args_list_buffer);
-    m_wrapper_function_text.append (");\n}\n");
-
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    if (log)
-        log->Printf ("Expression: \n\n%s\n\n", m_wrapper_function_text.c_str());
-        
-    // Okay, now compile this expression
-    
-    lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
-    if (jit_process_sp)
-    {
-        const bool generate_debug_info = true;
-        m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, generate_debug_info));
 
-        num_errors = m_parser->Parse(diagnostic_manager);
-    }
-    else
-    {
-        diagnostic_manager.PutCString(eDiagnosticSeverityError, "no process - unable to inject function");
-        num_errors = 1;
-    }
+    m_wrapper_function_text.append(type_name);
+    if (i < num_args - 1)
+      m_wrapper_function_text.append(", ");
+
+    char arg_buf[32];
+    args_buffer.append("    ");
+    args_buffer.append(type_name);
+    snprintf(arg_buf, 31, "arg_%" PRIu64, (uint64_t)i);
+    args_buffer.push_back(' ');
+    args_buffer.append(arg_buf);
+    args_buffer.append(";\n");
+
+    args_list_buffer.append("__lldb_fn_data->");
+    args_list_buffer.append(arg_buf);
+    if (i < num_args - 1)
+      args_list_buffer.append(", ");
+  }
+  m_wrapper_function_text.append(
+      ");\n"); // Close off the function calling prototype.
+
+  m_wrapper_function_text.append(args_buffer);
+
+  m_wrapper_function_text.append("    ");
+  m_wrapper_function_text.append(return_type_str);
+  m_wrapper_function_text.append(" return_value;");
+  m_wrapper_function_text.append("\n  };\n  struct ");
+  m_wrapper_function_text.append(m_wrapper_struct_name);
+  m_wrapper_function_text.append("* __lldb_fn_data = (struct ");
+  m_wrapper_function_text.append(m_wrapper_struct_name);
+  m_wrapper_function_text.append(" *) input;\n");
+
+  m_wrapper_function_text.append(
+      "  __lldb_fn_data->return_value = __lldb_fn_data->fn_ptr (");
+  m_wrapper_function_text.append(args_list_buffer);
+  m_wrapper_function_text.append(");\n}\n");
+
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+  if (log)
+    log->Printf("Expression: \n\n%s\n\n", m_wrapper_function_text.c_str());
+
+  // Okay, now compile this expression
+
+  lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
+  if (jit_process_sp) {
+    const bool generate_debug_info = true;
+    m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this,
+                                             generate_debug_info));
+
+    num_errors = m_parser->Parse(diagnostic_manager);
+  } else {
+    diagnostic_manager.PutCString(eDiagnosticSeverityError,
+                                  "no process - unable to inject function");
+    num_errors = 1;
+  }
 
-    m_compiled = (num_errors == 0);
-    
-    if (!m_compiled)
-        return num_errors;
+  m_compiled = (num_errors == 0);
 
+  if (!m_compiled)
     return num_errors;
+
+  return num_errors;
 }
 
 clang::ASTConsumer *
-ClangFunctionCaller::ClangFunctionCallerHelper::ASTTransformer (clang::ASTConsumer *passthrough)
-{
-    m_struct_extractor.reset(new ASTStructExtractor(passthrough, m_owner.GetWrapperStructName(), m_owner));
-    
-    return m_struct_extractor.get();
+ClangFunctionCaller::ClangFunctionCallerHelper::ASTTransformer(
+    clang::ASTConsumer *passthrough) {
+  m_struct_extractor.reset(new ASTStructExtractor(
+      passthrough, m_owner.GetWrapperStructName(), m_owner));
+
+  return m_struct_extractor.get();
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h Tue Sep  6 15:57:50 2016
@@ -16,23 +16,23 @@
 // Project includes
 #include "ClangExpressionHelper.h"
 
-#include "lldb/Core/ClangForward.h"
 #include "lldb/Core/Address.h"
 #include "lldb/Core/ArchSpec.h"
+#include "lldb/Core/ClangForward.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/ValueObjectList.h"
 #include "lldb/Expression/FunctionCaller.h"
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Target/Process.h"
 
-namespace lldb_private
-{
-    
+namespace lldb_private {
+
 class ASTStructExtractor;
 class ClangExpressionParser;
 
 //----------------------------------------------------------------------
-/// @class ClangFunctionCaller ClangFunctionCaller.h "lldb/Expression/ClangFunctionCaller.h"
+/// @class ClangFunctionCaller ClangFunctionCaller.h
+/// "lldb/Expression/ClangFunctionCaller.h"
 /// @brief Encapsulates a function that can be called.
 ///
 /// A given ClangFunctionCaller object can handle a single function signature.
@@ -42,7 +42,7 @@ class ClangExpressionParser;
 /// It performs the call by synthesizing a structure that contains the pointer
 /// to the function and the arguments that should be passed to that function,
 /// and producing a special-purpose JIT-compiled function that accepts a void*
-/// pointing to this struct as its only argument and calls the function in the 
+/// pointing to this struct as its only argument and calls the function in the
 /// struct with the written arguments.  This method lets Clang handle the
 /// vagaries of function calling conventions.
 ///
@@ -54,124 +54,111 @@ class ClangExpressionParser;
 /// InsertFunction() followed by WriteFunctionArguments(), which will return
 /// the location of the args struct for the wrapper function in args_addr_ref.
 ///
-/// If you need to call the function on the thread plan stack, you can also 
+/// If you need to call the function on the thread plan stack, you can also
 /// call InsertFunction() followed by GetThreadPlanToCallFunction().
 ///
 /// Any of the methods that take arg_addr_ptr or arg_addr_ref can be passed
 /// a pointer set to LLDB_INVALID_ADDRESS and new structure will be allocated
 /// and its address returned in that variable.
-/// 
+///
 /// Any of the methods that take arg_addr_ptr can be passed NULL, and the
 /// argument space will be managed for you.
-//----------------------------------------------------------------------    
-class ClangFunctionCaller : public FunctionCaller
-{
-    friend class ASTStructExtractor;
-    
-    class ClangFunctionCallerHelper : public ClangExpressionHelper
-    {
-    public:
-        ClangFunctionCallerHelper (ClangFunctionCaller &owner) :
-            m_owner(owner)
-        {
-        }
-        
-        ~ClangFunctionCallerHelper() override = default;
-        
-        //------------------------------------------------------------------
-        /// Return the object that the parser should use when resolving external
-        /// values.  May be NULL if everything should be self-contained.
-        //------------------------------------------------------------------
-        ClangExpressionDeclMap *
-        DeclMap() override
-        {
-            return NULL;
-        }
-        
-        //------------------------------------------------------------------
-        /// Return the object that the parser should allow to access ASTs.
-        /// May be NULL if the ASTs do not need to be transformed.
-        ///
-        /// @param[in] passthrough
-        ///     The ASTConsumer that the returned transformer should send
-        ///     the ASTs to after transformation.
-        //------------------------------------------------------------------
-        clang::ASTConsumer *
-        ASTTransformer(clang::ASTConsumer *passthrough) override;
-
-    private:
-        ClangFunctionCaller                      &m_owner;
-        std::unique_ptr<ASTStructExtractor> m_struct_extractor;         ///< The class that generates the argument struct layout.
-    };
+//----------------------------------------------------------------------
+class ClangFunctionCaller : public FunctionCaller {
+  friend class ASTStructExtractor;
+
+  class ClangFunctionCallerHelper : public ClangExpressionHelper {
+  public:
+    ClangFunctionCallerHelper(ClangFunctionCaller &owner) : m_owner(owner) {}
+
+    ~ClangFunctionCallerHelper() override = default;
 
-public:
     //------------------------------------------------------------------
-    /// Constructor
-    ///
-    /// @param[in] exe_scope
-    ///     An execution context scope that gets us at least a target and 
-    ///     process.
-    ///
-    /// @param[in] ast_context
-    ///     The AST context to evaluate argument types in.
-    ///
-    /// @param[in] return_qualtype
-    ///     An opaque Clang QualType for the function result.  Should be
-    ///     defined in ast_context.
-    ///
-    /// @param[in] function_address
-    ///     The address of the function to call.
-    ///
-    /// @param[in] arg_value_list
-    ///     The default values to use when calling this function.  Can
-    ///     be overridden using WriteFunctionArguments().
+    /// Return the object that the parser should use when resolving external
+    /// values.  May be NULL if everything should be self-contained.
     //------------------------------------------------------------------
-    ClangFunctionCaller (ExecutionContextScope &exe_scope,
-                         const CompilerType &return_type,
-                         const Address& function_address,
-                         const ValueList &arg_value_list,
-                         const char *name);
-    
-    ~ClangFunctionCaller() override;
+    ClangExpressionDeclMap *DeclMap() override { return NULL; }
 
     //------------------------------------------------------------------
-    /// Compile the wrapper function
-    ///
-    /// @param[in] thread_to_use_sp
-    ///     Compilation might end up calling functions.  Pass in the thread you
-    ///     want the compilation to use.  If you pass in an empty ThreadSP it will
-    ///     use the currently selected thread.
+    /// Return the object that the parser should allow to access ASTs.
+    /// May be NULL if the ASTs do not need to be transformed.
     ///
-    /// @param[in] diagnostic_manager
-    ///     The diagnostic manager to report parser errors to.
-    ///
-    /// @return
-    ///     The number of errors.
+    /// @param[in] passthrough
+    ///     The ASTConsumer that the returned transformer should send
+    ///     the ASTs to after transformation.
     //------------------------------------------------------------------
-    unsigned
-    CompileFunction (lldb::ThreadSP thread_to_use_sp,
-                     DiagnosticManager &diagnostic_manager) override;
-
-    ExpressionTypeSystemHelper *
-    GetTypeSystemHelper() override
-    {
-        return &m_type_system_helper;
-    }
+    clang::ASTConsumer *
+    ASTTransformer(clang::ASTConsumer *passthrough) override;
+
+  private:
+    ClangFunctionCaller &m_owner;
+    std::unique_ptr<ASTStructExtractor> m_struct_extractor; ///< The class that
+                                                            ///generates the
+                                                            ///argument struct
+                                                            ///layout.
+  };
+
+public:
+  //------------------------------------------------------------------
+  /// Constructor
+  ///
+  /// @param[in] exe_scope
+  ///     An execution context scope that gets us at least a target and
+  ///     process.
+  ///
+  /// @param[in] ast_context
+  ///     The AST context to evaluate argument types in.
+  ///
+  /// @param[in] return_qualtype
+  ///     An opaque Clang QualType for the function result.  Should be
+  ///     defined in ast_context.
+  ///
+  /// @param[in] function_address
+  ///     The address of the function to call.
+  ///
+  /// @param[in] arg_value_list
+  ///     The default values to use when calling this function.  Can
+  ///     be overridden using WriteFunctionArguments().
+  //------------------------------------------------------------------
+  ClangFunctionCaller(ExecutionContextScope &exe_scope,
+                      const CompilerType &return_type,
+                      const Address &function_address,
+                      const ValueList &arg_value_list, const char *name);
+
+  ~ClangFunctionCaller() override;
+
+  //------------------------------------------------------------------
+  /// Compile the wrapper function
+  ///
+  /// @param[in] thread_to_use_sp
+  ///     Compilation might end up calling functions.  Pass in the thread you
+  ///     want the compilation to use.  If you pass in an empty ThreadSP it will
+  ///     use the currently selected thread.
+  ///
+  /// @param[in] diagnostic_manager
+  ///     The diagnostic manager to report parser errors to.
+  ///
+  /// @return
+  ///     The number of errors.
+  //------------------------------------------------------------------
+  unsigned CompileFunction(lldb::ThreadSP thread_to_use_sp,
+                           DiagnosticManager &diagnostic_manager) override;
+
+  ExpressionTypeSystemHelper *GetTypeSystemHelper() override {
+    return &m_type_system_helper;
+  }
 
 protected:
-    const char *GetWrapperStructName()
-    {
-        return m_wrapper_struct_name.c_str();
-    }
+  const char *GetWrapperStructName() { return m_wrapper_struct_name.c_str(); }
 
 private:
-    //------------------------------------------------------------------
-    // For ClangFunctionCaller only
-    //------------------------------------------------------------------
-
-    // Note: the parser needs to be destructed before the execution unit, so
-    // declare the execution unit first.
-    ClangFunctionCallerHelper   m_type_system_helper;
+  //------------------------------------------------------------------
+  // For ClangFunctionCaller only
+  //------------------------------------------------------------------
+
+  // Note: the parser needs to be destructed before the execution unit, so
+  // declare the execution unit first.
+  ClangFunctionCallerHelper m_type_system_helper;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Tue Sep  6 15:57:50 2016
@@ -37,700 +37,643 @@
 using namespace lldb_private;
 
 namespace {
-    // Any Clang compiler requires a consumer for diagnostics.  This one stores them as strings
-    // so we can provide them to the user in case a module failed to load.
-    class StoringDiagnosticConsumer : public clang::DiagnosticConsumer
-    {
-    public:
-        StoringDiagnosticConsumer ();
-
-        void
-        HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
-                         const clang::Diagnostic &info) override;
-        
-        void
-        ClearDiagnostics ();
-        
-        void
-        DumpDiagnostics (Stream &error_stream);
-
-    private:
-        typedef std::pair<clang::DiagnosticsEngine::Level, std::string> IDAndDiagnostic;
-        std::vector<IDAndDiagnostic> m_diagnostics;
-        Log * m_log;
-    };
-    
-    // The private implementation of our ClangModulesDeclVendor.  Contains all the Clang state required
-    // to load modules.
-    class ClangModulesDeclVendorImpl : public ClangModulesDeclVendor
-    {
-    public:
-        ClangModulesDeclVendorImpl(llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> &diagnostics_engine,
-                                   llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> &compiler_invocation,
-                                   std::unique_ptr<clang::CompilerInstance> &&compiler_instance,
-                                   std::unique_ptr<clang::Parser> &&parser);
-
-        ~ClangModulesDeclVendorImpl() override = default;
-
-        bool
-        AddModule(ModulePath &path,
-                  ModuleVector *exported_modules,
-                  Stream &error_stream) override;
-
-        bool
-        AddModulesForCompileUnit(CompileUnit &cu,
-                                 ModuleVector &exported_modules,
-                                 Stream &error_stream) override;
-
-        uint32_t
-        FindDecls(const ConstString &name,
-                  bool append,
-                  uint32_t max_matches,
-                  std::vector <clang::NamedDecl*> &decls) override;
-        
-        void
-        ForEachMacro(const ModuleVector &modules,
-                     std::function<bool (const std::string &)> handler) override;
-        
-    private:
-        void
-        ReportModuleExportsHelper (std::set<ClangModulesDeclVendor::ModuleID> &exports,
-                                   clang::Module *module);
-
-        void
-        ReportModuleExports (ModuleVector &exports,
-                             clang::Module *module);
-
-        clang::ModuleLoadResult
-        DoGetModule(clang::ModuleIdPath path, bool make_visible);
-        
-        bool                                                m_enabled = false;
-        
-        llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>  m_diagnostics_engine;
-        llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> m_compiler_invocation;
-        std::unique_ptr<clang::CompilerInstance>            m_compiler_instance;
-        std::unique_ptr<clang::Parser>                      m_parser;
-        size_t                                              m_source_location_index = 0; // used to give name components fake SourceLocations
-
-        typedef std::vector<ConstString>                    ImportedModule;
-        typedef std::map<ImportedModule, clang::Module *>   ImportedModuleMap;
-        typedef std::set<ModuleID>                          ImportedModuleSet;
-        ImportedModuleMap                                   m_imported_modules;
-        ImportedModuleSet                                   m_user_imported_modules;
-    };
+// Any Clang compiler requires a consumer for diagnostics.  This one stores them
+// as strings
+// so we can provide them to the user in case a module failed to load.
+class StoringDiagnosticConsumer : public clang::DiagnosticConsumer {
+public:
+  StoringDiagnosticConsumer();
+
+  void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
+                        const clang::Diagnostic &info) override;
+
+  void ClearDiagnostics();
+
+  void DumpDiagnostics(Stream &error_stream);
+
+private:
+  typedef std::pair<clang::DiagnosticsEngine::Level, std::string>
+      IDAndDiagnostic;
+  std::vector<IDAndDiagnostic> m_diagnostics;
+  Log *m_log;
+};
+
+// The private implementation of our ClangModulesDeclVendor.  Contains all the
+// Clang state required
+// to load modules.
+class ClangModulesDeclVendorImpl : public ClangModulesDeclVendor {
+public:
+  ClangModulesDeclVendorImpl(
+      llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> &diagnostics_engine,
+      llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> &compiler_invocation,
+      std::unique_ptr<clang::CompilerInstance> &&compiler_instance,
+      std::unique_ptr<clang::Parser> &&parser);
+
+  ~ClangModulesDeclVendorImpl() override = default;
+
+  bool AddModule(ModulePath &path, ModuleVector *exported_modules,
+                 Stream &error_stream) override;
+
+  bool AddModulesForCompileUnit(CompileUnit &cu, ModuleVector &exported_modules,
+                                Stream &error_stream) override;
+
+  uint32_t FindDecls(const ConstString &name, bool append, uint32_t max_matches,
+                     std::vector<clang::NamedDecl *> &decls) override;
+
+  void ForEachMacro(const ModuleVector &modules,
+                    std::function<bool(const std::string &)> handler) override;
+
+private:
+  void
+  ReportModuleExportsHelper(std::set<ClangModulesDeclVendor::ModuleID> &exports,
+                            clang::Module *module);
+
+  void ReportModuleExports(ModuleVector &exports, clang::Module *module);
+
+  clang::ModuleLoadResult DoGetModule(clang::ModuleIdPath path,
+                                      bool make_visible);
+
+  bool m_enabled = false;
+
+  llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> m_diagnostics_engine;
+  llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> m_compiler_invocation;
+  std::unique_ptr<clang::CompilerInstance> m_compiler_instance;
+  std::unique_ptr<clang::Parser> m_parser;
+  size_t m_source_location_index =
+      0; // used to give name components fake SourceLocations
+
+  typedef std::vector<ConstString> ImportedModule;
+  typedef std::map<ImportedModule, clang::Module *> ImportedModuleMap;
+  typedef std::set<ModuleID> ImportedModuleSet;
+  ImportedModuleMap m_imported_modules;
+  ImportedModuleSet m_user_imported_modules;
+};
 } // anonymous namespace
 
-StoringDiagnosticConsumer::StoringDiagnosticConsumer ()
-{
-    m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
-}
-
-void
-StoringDiagnosticConsumer::HandleDiagnostic (clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info)
-{
-    llvm::SmallVector<char, 256> diagnostic_string;
-    
-    info.FormatDiagnostic(diagnostic_string);
-    
-    m_diagnostics.push_back(IDAndDiagnostic(DiagLevel, std::string(diagnostic_string.data(), diagnostic_string.size())));
-}
-
-void
-StoringDiagnosticConsumer::ClearDiagnostics ()
-{
-    m_diagnostics.clear();
-}
-
-void
-StoringDiagnosticConsumer::DumpDiagnostics (Stream &error_stream)
-{
-    for (IDAndDiagnostic &diag : m_diagnostics)
-    {
-        switch (diag.first)
-        {
-            default:
-                error_stream.PutCString(diag.second.c_str());
-                error_stream.PutChar('\n');
-                break;
-            case clang::DiagnosticsEngine::Level::Ignored:
-                break;
-        }
-    }
+StoringDiagnosticConsumer::StoringDiagnosticConsumer() {
+  m_log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
 }
 
-static FileSpec
-GetResourceDir ()
-{
-    static FileSpec g_cached_resource_dir;
-    
-    static std::once_flag g_once_flag;
-    
-    std::call_once(g_once_flag, [](){
-        HostInfo::GetLLDBPath (lldb::ePathTypeClangDir, g_cached_resource_dir);
-    });
-    
-    return g_cached_resource_dir;
-}
-
-ClangModulesDeclVendor::ClangModulesDeclVendor()
-{
-}
-
-ClangModulesDeclVendor::~ClangModulesDeclVendor()
-{
-}
-
-ClangModulesDeclVendorImpl::ClangModulesDeclVendorImpl(llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> &diagnostics_engine,
-                                                       llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> &compiler_invocation,
-                                                       std::unique_ptr<clang::CompilerInstance> &&compiler_instance,
-                                                       std::unique_ptr<clang::Parser> &&parser) :
-    ClangModulesDeclVendor(),
-    m_diagnostics_engine(diagnostics_engine),
-    m_compiler_invocation(compiler_invocation),
-    m_compiler_instance(std::move(compiler_instance)),
-    m_parser(std::move(parser)),
-    m_imported_modules()
-{
-}
-
-void
-ClangModulesDeclVendorImpl::ReportModuleExportsHelper (std::set<ClangModulesDeclVendor::ModuleID> &exports,
-                                                       clang::Module *module)
-{
-    if (exports.count(reinterpret_cast<ClangModulesDeclVendor::ModuleID>(module)))
-        return;
-    
-    exports.insert(reinterpret_cast<ClangModulesDeclVendor::ModuleID>(module));
-    
-    llvm::SmallVector<clang::Module*, 2> sub_exports;
-    
-    module->getExportedModules(sub_exports);
+void StoringDiagnosticConsumer::HandleDiagnostic(
+    clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info) {
+  llvm::SmallVector<char, 256> diagnostic_string;
 
-    for (clang::Module *module : sub_exports)
-    {
-        ReportModuleExportsHelper(exports, module);
-    }
+  info.FormatDiagnostic(diagnostic_string);
+
+  m_diagnostics.push_back(
+      IDAndDiagnostic(DiagLevel, std::string(diagnostic_string.data(),
+                                             diagnostic_string.size())));
 }
 
-void
-ClangModulesDeclVendorImpl::ReportModuleExports (ClangModulesDeclVendor::ModuleVector &exports,
-                                                 clang::Module *module)
-{
-    std::set<ClangModulesDeclVendor::ModuleID> exports_set;
-    
-    ReportModuleExportsHelper(exports_set, module);
-    
-    for (ModuleID module : exports_set)
-    {
-        exports.push_back(module);
+void StoringDiagnosticConsumer::ClearDiagnostics() { m_diagnostics.clear(); }
+
+void StoringDiagnosticConsumer::DumpDiagnostics(Stream &error_stream) {
+  for (IDAndDiagnostic &diag : m_diagnostics) {
+    switch (diag.first) {
+    default:
+      error_stream.PutCString(diag.second.c_str());
+      error_stream.PutChar('\n');
+      break;
+    case clang::DiagnosticsEngine::Level::Ignored:
+      break;
     }
+  }
 }
 
-bool
-ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
-                                      ModuleVector *exported_modules,
-                                      Stream &error_stream)
-{
-    // Fail early.
-    
-    if (m_compiler_instance->hadModuleLoaderFatalFailure())
-    {
-        error_stream.PutCString("error: Couldn't load a module because the module loader is in a fatal state.\n");
-        return false;
-    }
-    
-    // Check if we've already imported this module.
-    
-    std::vector<ConstString> imported_module;
-    
-    for (ConstString path_component : path)
-    {
-        imported_module.push_back(path_component);
-    }
-    
-    {
-        ImportedModuleMap::iterator mi = m_imported_modules.find(imported_module);
-        
-        if (mi != m_imported_modules.end())
-        {
-            if (exported_modules)
-            {
-                ReportModuleExports(*exported_modules, mi->second);
-            }
-            return true;
-        }
-    }
-    
-    if (!m_compiler_instance->getPreprocessor().getHeaderSearchInfo().lookupModule(path[0].GetStringRef()))
-    {
-        error_stream.Printf("error: Header search couldn't locate module %s\n", path[0].AsCString());
-        return false;
-    }
-    
-    llvm::SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4> clang_path;
-    
-    {
-        clang::SourceManager &source_manager = m_compiler_instance->getASTContext().getSourceManager();
-        
-        for (ConstString path_component : path)
-        {
-            clang_path.push_back(std::make_pair(&m_compiler_instance->getASTContext().Idents.get(path_component.GetStringRef()),
-                                                source_manager.getLocForStartOfFile(source_manager.getMainFileID()).getLocWithOffset(m_source_location_index++)));
-        }
+static FileSpec GetResourceDir() {
+  static FileSpec g_cached_resource_dir;
+
+  static std::once_flag g_once_flag;
+
+  std::call_once(g_once_flag, []() {
+    HostInfo::GetLLDBPath(lldb::ePathTypeClangDir, g_cached_resource_dir);
+  });
+
+  return g_cached_resource_dir;
+}
+
+ClangModulesDeclVendor::ClangModulesDeclVendor() {}
+
+ClangModulesDeclVendor::~ClangModulesDeclVendor() {}
+
+ClangModulesDeclVendorImpl::ClangModulesDeclVendorImpl(
+    llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> &diagnostics_engine,
+    llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> &compiler_invocation,
+    std::unique_ptr<clang::CompilerInstance> &&compiler_instance,
+    std::unique_ptr<clang::Parser> &&parser)
+    : ClangModulesDeclVendor(), m_diagnostics_engine(diagnostics_engine),
+      m_compiler_invocation(compiler_invocation),
+      m_compiler_instance(std::move(compiler_instance)),
+      m_parser(std::move(parser)), m_imported_modules() {}
+
+void ClangModulesDeclVendorImpl::ReportModuleExportsHelper(
+    std::set<ClangModulesDeclVendor::ModuleID> &exports,
+    clang::Module *module) {
+  if (exports.count(reinterpret_cast<ClangModulesDeclVendor::ModuleID>(module)))
+    return;
+
+  exports.insert(reinterpret_cast<ClangModulesDeclVendor::ModuleID>(module));
+
+  llvm::SmallVector<clang::Module *, 2> sub_exports;
+
+  module->getExportedModules(sub_exports);
+
+  for (clang::Module *module : sub_exports) {
+    ReportModuleExportsHelper(exports, module);
+  }
+}
+
+void ClangModulesDeclVendorImpl::ReportModuleExports(
+    ClangModulesDeclVendor::ModuleVector &exports, clang::Module *module) {
+  std::set<ClangModulesDeclVendor::ModuleID> exports_set;
+
+  ReportModuleExportsHelper(exports_set, module);
+
+  for (ModuleID module : exports_set) {
+    exports.push_back(module);
+  }
+}
+
+bool ClangModulesDeclVendorImpl::AddModule(ModulePath &path,
+                                           ModuleVector *exported_modules,
+                                           Stream &error_stream) {
+  // Fail early.
+
+  if (m_compiler_instance->hadModuleLoaderFatalFailure()) {
+    error_stream.PutCString("error: Couldn't load a module because the module "
+                            "loader is in a fatal state.\n");
+    return false;
+  }
+
+  // Check if we've already imported this module.
+
+  std::vector<ConstString> imported_module;
+
+  for (ConstString path_component : path) {
+    imported_module.push_back(path_component);
+  }
+
+  {
+    ImportedModuleMap::iterator mi = m_imported_modules.find(imported_module);
+
+    if (mi != m_imported_modules.end()) {
+      if (exported_modules) {
+        ReportModuleExports(*exported_modules, mi->second);
+      }
+      return true;
     }
-    
-    StoringDiagnosticConsumer *diagnostic_consumer = static_cast<StoringDiagnosticConsumer *>(m_compiler_instance->getDiagnostics().getClient());
-    
-    diagnostic_consumer->ClearDiagnostics();
-    
-    clang::Module *top_level_module = DoGetModule(clang_path.front(), false);
-    
-    if (!top_level_module)
-    {
-        diagnostic_consumer->DumpDiagnostics(error_stream);
-        error_stream.Printf("error: Couldn't load top-level module %s\n", path[0].AsCString());
-        return false;
+  }
+
+  if (!m_compiler_instance->getPreprocessor()
+           .getHeaderSearchInfo()
+           .lookupModule(path[0].GetStringRef())) {
+    error_stream.Printf("error: Header search couldn't locate module %s\n",
+                        path[0].AsCString());
+    return false;
+  }
+
+  llvm::SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>,
+                    4>
+      clang_path;
+
+  {
+    clang::SourceManager &source_manager =
+        m_compiler_instance->getASTContext().getSourceManager();
+
+    for (ConstString path_component : path) {
+      clang_path.push_back(std::make_pair(
+          &m_compiler_instance->getASTContext().Idents.get(
+              path_component.GetStringRef()),
+          source_manager.getLocForStartOfFile(source_manager.getMainFileID())
+              .getLocWithOffset(m_source_location_index++)));
     }
-    
-    clang::Module *submodule = top_level_module;
-    
-    for (size_t ci = 1; ci < path.size(); ++ci)
-    {
-        llvm::StringRef component = path[ci].GetStringRef();
-        submodule = submodule->findSubmodule(component.str());
-        if (!submodule)
-        {
-            diagnostic_consumer->DumpDiagnostics(error_stream);
-            error_stream.Printf("error: Couldn't load submodule %s\n", component.str().c_str());
-            return false;
-        }
+  }
+
+  StoringDiagnosticConsumer *diagnostic_consumer =
+      static_cast<StoringDiagnosticConsumer *>(
+          m_compiler_instance->getDiagnostics().getClient());
+
+  diagnostic_consumer->ClearDiagnostics();
+
+  clang::Module *top_level_module = DoGetModule(clang_path.front(), false);
+
+  if (!top_level_module) {
+    diagnostic_consumer->DumpDiagnostics(error_stream);
+    error_stream.Printf("error: Couldn't load top-level module %s\n",
+                        path[0].AsCString());
+    return false;
+  }
+
+  clang::Module *submodule = top_level_module;
+
+  for (size_t ci = 1; ci < path.size(); ++ci) {
+    llvm::StringRef component = path[ci].GetStringRef();
+    submodule = submodule->findSubmodule(component.str());
+    if (!submodule) {
+      diagnostic_consumer->DumpDiagnostics(error_stream);
+      error_stream.Printf("error: Couldn't load submodule %s\n",
+                          component.str().c_str());
+      return false;
     }
-    
-    clang::Module *requested_module = DoGetModule(clang_path, true);
-    
-    if (requested_module != nullptr)
-    {
-        if (exported_modules)
-        {
-            ReportModuleExports(*exported_modules, requested_module);
-        }
+  }
 
-        m_imported_modules[imported_module] = requested_module;
-        
-        m_enabled = true;
-        
-        return true;
+  clang::Module *requested_module = DoGetModule(clang_path, true);
+
+  if (requested_module != nullptr) {
+    if (exported_modules) {
+      ReportModuleExports(*exported_modules, requested_module);
     }
-    
-    return false;
+
+    m_imported_modules[imported_module] = requested_module;
+
+    m_enabled = true;
+
+    return true;
+  }
+
+  return false;
 }
 
-bool
-ClangModulesDeclVendor::LanguageSupportsClangModules (lldb::LanguageType language)
-{
-    switch (language)
-    {
-    default:
-        return false;
-    // C++ and friends to be added
-    case lldb::LanguageType::eLanguageTypeC:
-    case lldb::LanguageType::eLanguageTypeC11:
-    case lldb::LanguageType::eLanguageTypeC89:
-    case lldb::LanguageType::eLanguageTypeC99:
-    case lldb::LanguageType::eLanguageTypeObjC:
-        return true;
-    }
+bool ClangModulesDeclVendor::LanguageSupportsClangModules(
+    lldb::LanguageType language) {
+  switch (language) {
+  default:
+    return false;
+  // C++ and friends to be added
+  case lldb::LanguageType::eLanguageTypeC:
+  case lldb::LanguageType::eLanguageTypeC11:
+  case lldb::LanguageType::eLanguageTypeC89:
+  case lldb::LanguageType::eLanguageTypeC99:
+  case lldb::LanguageType::eLanguageTypeObjC:
+    return true;
+  }
 }
 
-bool
-ClangModulesDeclVendorImpl::AddModulesForCompileUnit(CompileUnit &cu,
-                                                     ClangModulesDeclVendor::ModuleVector &exported_modules,
-                                                     Stream &error_stream)
-{
-    if (LanguageSupportsClangModules(cu.GetLanguage()))
-    {
-        std::vector<ConstString> imported_modules = cu.GetImportedModules();
-        
-        for (ConstString imported_module : imported_modules)
-        {
-            std::vector<ConstString> path;
-            
-            path.push_back(imported_module);
-            
-            if (!AddModule(path, &exported_modules, error_stream))
-            {
-                return false;
-            }
-        }
-        
-        return true;
+bool ClangModulesDeclVendorImpl::AddModulesForCompileUnit(
+    CompileUnit &cu, ClangModulesDeclVendor::ModuleVector &exported_modules,
+    Stream &error_stream) {
+  if (LanguageSupportsClangModules(cu.GetLanguage())) {
+    std::vector<ConstString> imported_modules = cu.GetImportedModules();
+
+    for (ConstString imported_module : imported_modules) {
+      std::vector<ConstString> path;
+
+      path.push_back(imported_module);
+
+      if (!AddModule(path, &exported_modules, error_stream)) {
+        return false;
+      }
     }
 
     return true;
+  }
+
+  return true;
 }
 
 // ClangImporter::lookupValue
 
 uint32_t
-ClangModulesDeclVendorImpl::FindDecls (const ConstString &name,
-                                       bool append,
-                                       uint32_t max_matches,
-                                       std::vector <clang::NamedDecl*> &decls)
-{
-    if (!m_enabled)
-    {
-        return 0;
-    }
+ClangModulesDeclVendorImpl::FindDecls(const ConstString &name, bool append,
+                                      uint32_t max_matches,
+                                      std::vector<clang::NamedDecl *> &decls) {
+  if (!m_enabled) {
+    return 0;
+  }
+
+  if (!append)
+    decls.clear();
+
+  clang::IdentifierInfo &ident =
+      m_compiler_instance->getASTContext().Idents.get(name.GetStringRef());
+
+  clang::LookupResult lookup_result(
+      m_compiler_instance->getSema(), clang::DeclarationName(&ident),
+      clang::SourceLocation(), clang::Sema::LookupOrdinaryName);
+
+  m_compiler_instance->getSema().LookupName(
+      lookup_result,
+      m_compiler_instance->getSema().getScopeForContext(
+          m_compiler_instance->getASTContext().getTranslationUnitDecl()));
+
+  uint32_t num_matches = 0;
+
+  for (clang::NamedDecl *named_decl : lookup_result) {
+    if (num_matches >= max_matches)
+      return num_matches;
+
+    decls.push_back(named_decl);
+    ++num_matches;
+  }
+
+  return num_matches;
+}
+
+void ClangModulesDeclVendorImpl::ForEachMacro(
+    const ClangModulesDeclVendor::ModuleVector &modules,
+    std::function<bool(const std::string &)> handler) {
+  if (!m_enabled) {
+    return;
+  }
+
+  typedef std::map<ModuleID, ssize_t> ModulePriorityMap;
+  ModulePriorityMap module_priorities;
+
+  ssize_t priority = 0;
+
+  for (ModuleID module : modules) {
+    module_priorities[module] = priority++;
+  }
+
+  if (m_compiler_instance->getPreprocessor().getExternalSource()) {
+    m_compiler_instance->getPreprocessor()
+        .getExternalSource()
+        ->ReadDefinedMacros();
+  }
+
+  for (clang::Preprocessor::macro_iterator
+           mi = m_compiler_instance->getPreprocessor().macro_begin(),
+           me = m_compiler_instance->getPreprocessor().macro_end();
+       mi != me; ++mi) {
+    const clang::IdentifierInfo *ii = nullptr;
+
+    {
+      if (clang::IdentifierInfoLookup *lookup =
+              m_compiler_instance->getPreprocessor()
+                  .getIdentifierTable()
+                  .getExternalIdentifierLookup()) {
+        lookup->get(mi->first->getName());
+      }
+      if (!ii) {
+        ii = mi->first;
+      }
+    }
+
+    ssize_t found_priority = -1;
+    clang::MacroInfo *macro_info = nullptr;
+
+    for (clang::ModuleMacro *module_macro :
+         m_compiler_instance->getPreprocessor().getLeafModuleMacros(ii)) {
+      clang::Module *module = module_macro->getOwningModule();
+
+      {
+        ModulePriorityMap::iterator pi =
+            module_priorities.find(reinterpret_cast<ModuleID>(module));
+
+        if (pi != module_priorities.end() && pi->second > found_priority) {
+          macro_info = module_macro->getMacroInfo();
+          found_priority = pi->second;
+        }
+      }
 
-    if (!append)
-        decls.clear();
-    
-    clang::IdentifierInfo &ident = m_compiler_instance->getASTContext().Idents.get(name.GetStringRef());
-    
-    clang::LookupResult lookup_result(m_compiler_instance->getSema(),
-                                      clang::DeclarationName(&ident),
-                                      clang::SourceLocation(),
-                                      clang::Sema::LookupOrdinaryName);
-    
-    m_compiler_instance->getSema().LookupName(lookup_result, m_compiler_instance->getSema().getScopeForContext(m_compiler_instance->getASTContext().getTranslationUnitDecl()));
-    
-    uint32_t num_matches = 0;
-    
-    for (clang::NamedDecl *named_decl : lookup_result)
-    {
-        if (num_matches >= max_matches)
-            return num_matches;
-        
-        decls.push_back(named_decl);
-        ++num_matches;
-    }
-    
-    return num_matches;
-}
+      clang::Module *top_level_module = module->getTopLevelModule();
 
-void
-ClangModulesDeclVendorImpl::ForEachMacro(const ClangModulesDeclVendor::ModuleVector &modules,
-                                         std::function<bool (const std::string &)> handler)
-{
-    if (!m_enabled)
-    {
-        return;
-    }
-    
-    typedef std::map<ModuleID, ssize_t> ModulePriorityMap;
-    ModulePriorityMap module_priorities;
-    
-    ssize_t priority = 0;
-    
-    for (ModuleID module : modules)
-    {
-        module_priorities[module] = priority++;
-    }
-    
-    if (m_compiler_instance->getPreprocessor().getExternalSource())
-    {
-        m_compiler_instance->getPreprocessor().getExternalSource()->ReadDefinedMacros();
+      if (top_level_module != module) {
+        ModulePriorityMap::iterator pi = module_priorities.find(
+            reinterpret_cast<ModuleID>(top_level_module));
+
+        if ((pi != module_priorities.end()) && pi->second > found_priority) {
+          macro_info = module_macro->getMacroInfo();
+          found_priority = pi->second;
+        }
+      }
     }
-    
-    for (clang::Preprocessor::macro_iterator mi = m_compiler_instance->getPreprocessor().macro_begin(),
-                                             me = m_compiler_instance->getPreprocessor().macro_end();
-         mi != me;
-         ++mi)
-    {
-        const clang::IdentifierInfo *ii = nullptr;
-        
-        {
-            if (clang::IdentifierInfoLookup *lookup = m_compiler_instance->getPreprocessor().getIdentifierTable().getExternalIdentifierLookup())
-            {
-                lookup->get(mi->first->getName());
+
+    if (macro_info) {
+      std::string macro_expansion = "#define ";
+      macro_expansion.append(mi->first->getName().str().c_str());
+
+      {
+        if (macro_info->isFunctionLike()) {
+          macro_expansion.append("(");
+
+          bool first_arg = true;
+
+          for (clang::MacroInfo::arg_iterator ai = macro_info->arg_begin(),
+                                              ae = macro_info->arg_end();
+               ai != ae; ++ai) {
+            if (!first_arg) {
+              macro_expansion.append(", ");
+            } else {
+              first_arg = false;
             }
-            if (!ii)
-            {
-                ii = mi->first;
+
+            macro_expansion.append((*ai)->getName().str());
+          }
+
+          if (macro_info->isC99Varargs()) {
+            if (first_arg) {
+              macro_expansion.append("...");
+            } else {
+              macro_expansion.append(", ...");
             }
+          } else if (macro_info->isGNUVarargs()) {
+            macro_expansion.append("...");
+          }
+
+          macro_expansion.append(")");
         }
-        
-        ssize_t found_priority = -1;
-        clang::MacroInfo *macro_info = nullptr;
-        
-        for (clang::ModuleMacro *module_macro : m_compiler_instance->getPreprocessor().getLeafModuleMacros(ii))
-        {
-            clang::Module *module = module_macro->getOwningModule();
-            
-            {
-                ModulePriorityMap::iterator pi = module_priorities.find(reinterpret_cast<ModuleID>(module));
-                
-                if (pi != module_priorities.end() && pi->second > found_priority)
-                {
-                    macro_info = module_macro->getMacroInfo();
-                    found_priority = pi->second;
-                }
+
+        macro_expansion.append(" ");
+
+        bool first_token = true;
+
+        for (clang::MacroInfo::tokens_iterator ti = macro_info->tokens_begin(),
+                                               te = macro_info->tokens_end();
+             ti != te; ++ti) {
+          if (!first_token) {
+            macro_expansion.append(" ");
+          } else {
+            first_token = false;
+          }
+
+          if (ti->isLiteral()) {
+            if (const char *literal_data = ti->getLiteralData()) {
+              std::string token_str(literal_data, ti->getLength());
+              macro_expansion.append(token_str);
+            } else {
+              bool invalid = false;
+              const char *literal_source =
+                  m_compiler_instance->getSourceManager().getCharacterData(
+                      ti->getLocation(), &invalid);
+
+              if (invalid) {
+                lldbassert(!"Unhandled token kind");
+                macro_expansion.append("<unknown literal value>");
+              } else {
+                macro_expansion.append(
+                    std::string(literal_source, ti->getLength()));
+              }
             }
-            
-            clang::Module *top_level_module = module->getTopLevelModule();
-            
-            if (top_level_module != module)
-            {
-                ModulePriorityMap::iterator pi = module_priorities.find(reinterpret_cast<ModuleID>(top_level_module));
-                
-                if ((pi != module_priorities.end()) && pi->second > found_priority)
-                {
-                    macro_info = module_macro->getMacroInfo();
-                    found_priority = pi->second;
-                }
+          } else if (const char *punctuator_spelling =
+                         clang::tok::getPunctuatorSpelling(ti->getKind())) {
+            macro_expansion.append(punctuator_spelling);
+          } else if (const char *keyword_spelling =
+                         clang::tok::getKeywordSpelling(ti->getKind())) {
+            macro_expansion.append(keyword_spelling);
+          } else {
+            switch (ti->getKind()) {
+            case clang::tok::TokenKind::identifier:
+              macro_expansion.append(ti->getIdentifierInfo()->getName().str());
+              break;
+            case clang::tok::TokenKind::raw_identifier:
+              macro_expansion.append(ti->getRawIdentifier().str());
+              break;
+            default:
+              macro_expansion.append(ti->getName());
+              break;
             }
+          }
         }
-        
-        if (macro_info)
-        {
-            std::string macro_expansion = "#define ";
-            macro_expansion.append(mi->first->getName().str().c_str());
-            
-            {
-                if (macro_info->isFunctionLike())
-                {
-                    macro_expansion.append("(");
-                    
-                    bool first_arg = true;
-                    
-                    for (clang::MacroInfo::arg_iterator ai = macro_info->arg_begin(),
-                                                        ae = macro_info->arg_end();
-                         ai != ae;
-                         ++ai)
-                    {
-                        if (!first_arg)
-                        {
-                            macro_expansion.append(", ");
-                        }
-                        else
-                        {
-                            first_arg = false;
-                        }
-                        
-                        macro_expansion.append((*ai)->getName().str());
-                    }
-                    
-                    if (macro_info->isC99Varargs())
-                    {
-                        if (first_arg)
-                        {
-                            macro_expansion.append("...");
-                        }
-                        else
-                        {
-                            macro_expansion.append(", ...");
-                        }
-                    }
-                    else if (macro_info->isGNUVarargs())
-                    {
-                        macro_expansion.append("...");
-                    }
-                    
-                    macro_expansion.append(")");
-                }
-                
-                macro_expansion.append(" ");
-
-                bool first_token = true;
-                
-                for (clang::MacroInfo::tokens_iterator ti = macro_info->tokens_begin(),
-                     te = macro_info->tokens_end();
-                     ti != te;
-                     ++ti)
-                {
-                    if (!first_token)
-                    {
-                        macro_expansion.append(" ");
-                    }
-                    else
-                    {
-                        first_token = false;
-                    }
-                    
-                    if (ti->isLiteral())
-                    {
-                        if (const char *literal_data = ti->getLiteralData())
-                        {
-                            std::string token_str(literal_data, ti->getLength());
-                            macro_expansion.append(token_str);
-                        }
-                        else
-                        {
-                            bool invalid = false;
-                            const char *literal_source = m_compiler_instance->getSourceManager().getCharacterData(ti->getLocation(), &invalid);
-                            
-                            if (invalid)
-                            {
-                                lldbassert(!"Unhandled token kind");
-                                macro_expansion.append("<unknown literal value>");
-                            }
-                            else
-                            {
-                                macro_expansion.append(std::string(literal_source, ti->getLength()));
-                            }
-                        }
-                    }
-                    else if (const char *punctuator_spelling = clang::tok::getPunctuatorSpelling(ti->getKind()))
-                    {
-                        macro_expansion.append(punctuator_spelling);
-                    }
-                    else if (const char *keyword_spelling = clang::tok::getKeywordSpelling(ti->getKind()))
-                    {
-                        macro_expansion.append(keyword_spelling);
-                    }
-                    else
-                    {
-                        switch (ti->getKind())
-                        {
-                            case clang::tok::TokenKind::identifier:
-                                macro_expansion.append(ti->getIdentifierInfo()->getName().str());
-                                break;
-                            case clang::tok::TokenKind::raw_identifier:
-                                macro_expansion.append(ti->getRawIdentifier().str());
-                                break;
-                            default:
-                                macro_expansion.append(ti->getName());
-                                break;
-                        }
-                    }
-                }
-                
-                if (handler(macro_expansion))
-                {
-                    return;
-                }
-            }
+
+        if (handler(macro_expansion)) {
+          return;
         }
+      }
     }
+  }
 }
 
 clang::ModuleLoadResult
 ClangModulesDeclVendorImpl::DoGetModule(clang::ModuleIdPath path,
-                                        bool make_visible)
-{
-    clang::Module::NameVisibilityKind visibility = make_visible ? clang::Module::AllVisible : clang::Module::Hidden;
-    
-    const bool is_inclusion_directive = false;
-    
-    return m_compiler_instance->loadModule(path.front().second, path, visibility, is_inclusion_directive);
+                                        bool make_visible) {
+  clang::Module::NameVisibilityKind visibility =
+      make_visible ? clang::Module::AllVisible : clang::Module::Hidden;
+
+  const bool is_inclusion_directive = false;
+
+  return m_compiler_instance->loadModule(path.front().second, path, visibility,
+                                         is_inclusion_directive);
 }
 
 static const char *ModuleImportBufferName = "LLDBModulesMemoryBuffer";
 
 lldb_private::ClangModulesDeclVendor *
-ClangModulesDeclVendor::Create(Target &target)
-{
-    // FIXME we should insure programmatically that the expression parser's compiler and the modules runtime's
-    // compiler are both initialized in the same way – preferably by the same code.
-    
-    if (!target.GetPlatform()->SupportsModules())
-        return nullptr;
-    
-    const ArchSpec &arch = target.GetArchitecture();
-    
-    std::vector<std::string> compiler_invocation_arguments =
-    {
-        "clang",
-        "-fmodules",
-        "-fimplicit-module-maps",
-        "-fcxx-modules",
-        "-fsyntax-only",
-        "-femit-all-decls",
-        "-target", arch.GetTriple().str(),
-        "-fmodules-validate-system-headers",
-        "-Werror=non-modular-include-in-framework-module"
-    };
-    
-    target.GetPlatform()->AddClangModuleCompilationOptions(&target, compiler_invocation_arguments);
+ClangModulesDeclVendor::Create(Target &target) {
+  // FIXME we should insure programmatically that the expression parser's
+  // compiler and the modules runtime's
+  // compiler are both initialized in the same way – preferably by the same
+  // code.
 
-    compiler_invocation_arguments.push_back(ModuleImportBufferName);
+  if (!target.GetPlatform()->SupportsModules())
+    return nullptr;
 
-    // Add additional search paths with { "-I", path } or { "-F", path } here.
-   
-    {
-        llvm::SmallString<128> DefaultModuleCache;
-        const bool erased_on_reboot = false;
-        llvm::sys::path::system_temp_directory(erased_on_reboot, DefaultModuleCache);
-        llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");
-        llvm::sys::path::append(DefaultModuleCache, "ModuleCache");
-        std::string module_cache_argument("-fmodules-cache-path=");
-        module_cache_argument.append(DefaultModuleCache.str().str());
-        compiler_invocation_arguments.push_back(module_cache_argument);
-    }
-    
-    FileSpecList &module_search_paths = target.GetClangModuleSearchPaths();
-    
-    for (size_t spi = 0, spe = module_search_paths.GetSize(); spi < spe; ++spi)
-    {
-        const FileSpec &search_path = module_search_paths.GetFileSpecAtIndex(spi);
-        
-        std::string search_path_argument = "-I";
-        search_path_argument.append(search_path.GetPath());
-        
-        compiler_invocation_arguments.push_back(search_path_argument);
-    }
-    
-    {
-        FileSpec clang_resource_dir = GetResourceDir();
-        
-        if (clang_resource_dir.IsDirectory())
-        {
-            compiler_invocation_arguments.push_back("-resource-dir");
-            compiler_invocation_arguments.push_back(clang_resource_dir.GetPath());
-        }
-    }
-    
-    llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diagnostics_engine = clang::CompilerInstance::createDiagnostics(new clang::DiagnosticOptions,
-                                                                                                                       new StoringDiagnosticConsumer);
-    
-    std::vector<const char *> compiler_invocation_argument_cstrs;
-    
-    for (const std::string &arg : compiler_invocation_arguments) {
-        compiler_invocation_argument_cstrs.push_back(arg.c_str());
+  const ArchSpec &arch = target.GetArchitecture();
+
+  std::vector<std::string> compiler_invocation_arguments = {
+      "clang",
+      "-fmodules",
+      "-fimplicit-module-maps",
+      "-fcxx-modules",
+      "-fsyntax-only",
+      "-femit-all-decls",
+      "-target",
+      arch.GetTriple().str(),
+      "-fmodules-validate-system-headers",
+      "-Werror=non-modular-include-in-framework-module"};
+
+  target.GetPlatform()->AddClangModuleCompilationOptions(
+      &target, compiler_invocation_arguments);
+
+  compiler_invocation_arguments.push_back(ModuleImportBufferName);
+
+  // Add additional search paths with { "-I", path } or { "-F", path } here.
+
+  {
+    llvm::SmallString<128> DefaultModuleCache;
+    const bool erased_on_reboot = false;
+    llvm::sys::path::system_temp_directory(erased_on_reboot,
+                                           DefaultModuleCache);
+    llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");
+    llvm::sys::path::append(DefaultModuleCache, "ModuleCache");
+    std::string module_cache_argument("-fmodules-cache-path=");
+    module_cache_argument.append(DefaultModuleCache.str().str());
+    compiler_invocation_arguments.push_back(module_cache_argument);
+  }
+
+  FileSpecList &module_search_paths = target.GetClangModuleSearchPaths();
+
+  for (size_t spi = 0, spe = module_search_paths.GetSize(); spi < spe; ++spi) {
+    const FileSpec &search_path = module_search_paths.GetFileSpecAtIndex(spi);
+
+    std::string search_path_argument = "-I";
+    search_path_argument.append(search_path.GetPath());
+
+    compiler_invocation_arguments.push_back(search_path_argument);
+  }
+
+  {
+    FileSpec clang_resource_dir = GetResourceDir();
+
+    if (clang_resource_dir.IsDirectory()) {
+      compiler_invocation_arguments.push_back("-resource-dir");
+      compiler_invocation_arguments.push_back(clang_resource_dir.GetPath());
     }
-    
-    llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> invocation(clang::createInvocationFromCommandLine(compiler_invocation_argument_cstrs, diagnostics_engine));
-    
-    if (!invocation)
-        return nullptr;
-    
-    std::unique_ptr<llvm::MemoryBuffer> source_buffer = llvm::MemoryBuffer::getMemBuffer("extern int __lldb __attribute__((unavailable));",
-                                                                                         ModuleImportBufferName);
-    
-    invocation->getPreprocessorOpts().addRemappedFile(ModuleImportBufferName, source_buffer.release());
-    
-    std::unique_ptr<clang::CompilerInstance> instance(new clang::CompilerInstance);
-    
-    instance->setDiagnostics(diagnostics_engine.get());
-    instance->setInvocation(invocation.get());
-    
-    std::unique_ptr<clang::FrontendAction> action(new clang::SyntaxOnlyAction);
-    
-    instance->setTarget(clang::TargetInfo::CreateTargetInfo(*diagnostics_engine, instance->getInvocation().TargetOpts));
-    
-    if (!instance->hasTarget())
-        return nullptr;
-    
-    instance->getTarget().adjust(instance->getLangOpts());
-    
-    if (!action->BeginSourceFile(*instance, instance->getFrontendOpts().Inputs[0]))
-        return nullptr;
-    
-    instance->getPreprocessor().enableIncrementalProcessing();
-    
-    instance->createModuleManager();
-    
-    instance->createSema(action->getTranslationUnitKind(), nullptr);
-    
-    const bool skipFunctionBodies = false;
-    std::unique_ptr<clang::Parser> parser(new clang::Parser(instance->getPreprocessor(), instance->getSema(), skipFunctionBodies));
-    
-    instance->getPreprocessor().EnterMainSourceFile();
-    parser->Initialize();
-    
-    clang::Parser::DeclGroupPtrTy parsed;
-    
-    while (!parser->ParseTopLevelDecl(parsed));
-    
-    return new ClangModulesDeclVendorImpl (diagnostics_engine, invocation, std::move(instance), std::move(parser));
+  }
+
+  llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diagnostics_engine =
+      clang::CompilerInstance::createDiagnostics(new clang::DiagnosticOptions,
+                                                 new StoringDiagnosticConsumer);
+
+  std::vector<const char *> compiler_invocation_argument_cstrs;
+
+  for (const std::string &arg : compiler_invocation_arguments) {
+    compiler_invocation_argument_cstrs.push_back(arg.c_str());
+  }
+
+  llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> invocation(
+      clang::createInvocationFromCommandLine(compiler_invocation_argument_cstrs,
+                                             diagnostics_engine));
+
+  if (!invocation)
+    return nullptr;
+
+  std::unique_ptr<llvm::MemoryBuffer> source_buffer =
+      llvm::MemoryBuffer::getMemBuffer(
+          "extern int __lldb __attribute__((unavailable));",
+          ModuleImportBufferName);
+
+  invocation->getPreprocessorOpts().addRemappedFile(ModuleImportBufferName,
+                                                    source_buffer.release());
+
+  std::unique_ptr<clang::CompilerInstance> instance(
+      new clang::CompilerInstance);
+
+  instance->setDiagnostics(diagnostics_engine.get());
+  instance->setInvocation(invocation.get());
+
+  std::unique_ptr<clang::FrontendAction> action(new clang::SyntaxOnlyAction);
+
+  instance->setTarget(clang::TargetInfo::CreateTargetInfo(
+      *diagnostics_engine, instance->getInvocation().TargetOpts));
+
+  if (!instance->hasTarget())
+    return nullptr;
+
+  instance->getTarget().adjust(instance->getLangOpts());
+
+  if (!action->BeginSourceFile(*instance,
+                               instance->getFrontendOpts().Inputs[0]))
+    return nullptr;
+
+  instance->getPreprocessor().enableIncrementalProcessing();
+
+  instance->createModuleManager();
+
+  instance->createSema(action->getTranslationUnitKind(), nullptr);
+
+  const bool skipFunctionBodies = false;
+  std::unique_ptr<clang::Parser> parser(new clang::Parser(
+      instance->getPreprocessor(), instance->getSema(), skipFunctionBodies));
+
+  instance->getPreprocessor().EnterMainSourceFile();
+  parser->Initialize();
+
+  clang::Parser::DeclGroupPtrTy parsed;
+
+  while (!parser->ParseTopLevelDecl(parsed))
+    ;
+
+  return new ClangModulesDeclVendorImpl(diagnostics_engine, invocation,
+                                        std::move(instance), std::move(parser));
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h Tue Sep  6 15:57:50 2016
@@ -18,111 +18,104 @@
 #include <set>
 #include <vector>
 
-namespace lldb_private
-{
-    
-class ClangModulesDeclVendor : public DeclVendor
-{
+namespace lldb_private {
+
+class ClangModulesDeclVendor : public DeclVendor {
 public:
-    //------------------------------------------------------------------
-    // Constructors and Destructors
-    //------------------------------------------------------------------
-    ClangModulesDeclVendor();
-    
-    ~ClangModulesDeclVendor() override;
-    
-    static ClangModulesDeclVendor *
-    Create(Target &target);
-    
-    typedef std::vector<ConstString> ModulePath;
-    typedef uintptr_t                ModuleID;
-    typedef std::vector<ModuleID>    ModuleVector;
-    
-    //------------------------------------------------------------------
-    /// Add a module to the list of modules to search.
-    ///
-    /// @param[in] path
-    ///     The path to the exact module to be loaded.  E.g., if the desired
-    ///     module is std.io, then this should be { "std", "io" }.
-    ///
-    /// @param[in] exported_modules
-    ///     If non-NULL, a pointer to a vector to populate with the ID of every
-    ///     module that is re-exported by the specified module.
-    ///
-    /// @param[in] error_stream
-    ///     A stream to populate with the output of the Clang parser when
-    ///     it tries to load the module.
-    ///
-    /// @return
-    ///     True if the module could be loaded; false if not.  If the
-    ///     compiler encountered a fatal error during a previous module
-    ///     load, then this will always return false for this ModuleImporter.
-    //------------------------------------------------------------------
-    virtual bool
-    AddModule(ModulePath &path,
-              ModuleVector *exported_modules,
-              Stream &error_stream) = 0;
-    
-    //------------------------------------------------------------------
-    /// Add all modules referred to in a given compilation unit to the list
-    /// of modules to search.
-    ///
-    /// @param[in] cu
-    ///     The compilation unit to scan for imported modules.
-    ///
-    /// @param[in] exported_modules
-    ///     A vector to populate with the ID of each module loaded (directly
-    ///     and via re-exports) in this way.
-    ///
-    /// @param[in] error_stream
-    ///     A stream to populate with the output of the Clang parser when
-    ///     it tries to load the modules.
-    ///
-    /// @return
-    ///     True if all modules referred to by the compilation unit could be
-    ///     loaded; false if one could not be loaded.  If the compiler
-    ///     encountered a fatal error during a previous module
-    ///     load, then this will always return false for this ModuleImporter.
-    //------------------------------------------------------------------
-    virtual bool
-    AddModulesForCompileUnit(CompileUnit &cu,
-                             ModuleVector &exported_modules,
-                             Stream &error_stream) = 0;
-
-    //------------------------------------------------------------------
-    /// Enumerate all the macros that are defined by a given set of modules
-    /// that are already imported.
-    ///
-    /// @param[in] modules
-    ///     The unique IDs for all modules to query.  Later modules have higher
-    ///     priority, just as if you @imported them in that order.  This matters
-    ///     if module A #defines a macro and module B #undefs it.
-    ///
-    /// @param[in] handler
-    ///     A function to call with the text of each #define (including the
-    ///     #define directive).  #undef directives are not included; we simply
-    ///     elide any corresponding #define.  If this function returns true,
-    ///     we stop the iteration immediately.
-    //------------------------------------------------------------------
-    virtual void
-    ForEachMacro(const ModuleVector &modules,
-                 std::function<bool (const std::string &)> handler) = 0;
-    
-    //------------------------------------------------------------------
-    /// Query whether Clang supports modules for a particular language.
-    /// LLDB uses this to decide whether to try to find the modules loaded
-    /// by a gaiven compile unit.
-    ///
-    /// @param[in] language
-    ///     The language to query for.
-    ///
-    /// @return
-    ///     True if Clang has modules for the given language.
-    //------------------------------------------------------------------
-    static bool
-    LanguageSupportsClangModules (lldb::LanguageType language);
+  //------------------------------------------------------------------
+  // Constructors and Destructors
+  //------------------------------------------------------------------
+  ClangModulesDeclVendor();
+
+  ~ClangModulesDeclVendor() override;
+
+  static ClangModulesDeclVendor *Create(Target &target);
+
+  typedef std::vector<ConstString> ModulePath;
+  typedef uintptr_t ModuleID;
+  typedef std::vector<ModuleID> ModuleVector;
+
+  //------------------------------------------------------------------
+  /// Add a module to the list of modules to search.
+  ///
+  /// @param[in] path
+  ///     The path to the exact module to be loaded.  E.g., if the desired
+  ///     module is std.io, then this should be { "std", "io" }.
+  ///
+  /// @param[in] exported_modules
+  ///     If non-NULL, a pointer to a vector to populate with the ID of every
+  ///     module that is re-exported by the specified module.
+  ///
+  /// @param[in] error_stream
+  ///     A stream to populate with the output of the Clang parser when
+  ///     it tries to load the module.
+  ///
+  /// @return
+  ///     True if the module could be loaded; false if not.  If the
+  ///     compiler encountered a fatal error during a previous module
+  ///     load, then this will always return false for this ModuleImporter.
+  //------------------------------------------------------------------
+  virtual bool AddModule(ModulePath &path, ModuleVector *exported_modules,
+                         Stream &error_stream) = 0;
+
+  //------------------------------------------------------------------
+  /// Add all modules referred to in a given compilation unit to the list
+  /// of modules to search.
+  ///
+  /// @param[in] cu
+  ///     The compilation unit to scan for imported modules.
+  ///
+  /// @param[in] exported_modules
+  ///     A vector to populate with the ID of each module loaded (directly
+  ///     and via re-exports) in this way.
+  ///
+  /// @param[in] error_stream
+  ///     A stream to populate with the output of the Clang parser when
+  ///     it tries to load the modules.
+  ///
+  /// @return
+  ///     True if all modules referred to by the compilation unit could be
+  ///     loaded; false if one could not be loaded.  If the compiler
+  ///     encountered a fatal error during a previous module
+  ///     load, then this will always return false for this ModuleImporter.
+  //------------------------------------------------------------------
+  virtual bool AddModulesForCompileUnit(CompileUnit &cu,
+                                        ModuleVector &exported_modules,
+                                        Stream &error_stream) = 0;
+
+  //------------------------------------------------------------------
+  /// Enumerate all the macros that are defined by a given set of modules
+  /// that are already imported.
+  ///
+  /// @param[in] modules
+  ///     The unique IDs for all modules to query.  Later modules have higher
+  ///     priority, just as if you @imported them in that order.  This matters
+  ///     if module A #defines a macro and module B #undefs it.
+  ///
+  /// @param[in] handler
+  ///     A function to call with the text of each #define (including the
+  ///     #define directive).  #undef directives are not included; we simply
+  ///     elide any corresponding #define.  If this function returns true,
+  ///     we stop the iteration immediately.
+  //------------------------------------------------------------------
+  virtual void
+  ForEachMacro(const ModuleVector &modules,
+               std::function<bool(const std::string &)> handler) = 0;
+
+  //------------------------------------------------------------------
+  /// Query whether Clang supports modules for a particular language.
+  /// LLDB uses this to decide whether to try to find the modules loaded
+  /// by a gaiven compile unit.
+  ///
+  /// @param[in] language
+  ///     The language to query for.
+  ///
+  /// @return
+  ///     True if Clang has modules for the given language.
+  //------------------------------------------------------------------
+  static bool LanguageSupportsClangModules(lldb::LanguageType language);
 };
-    
+
 } // namespace lldb_private
 
 #endif // liblldb_ClangModulesDeclVendor_h

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp Tue Sep  6 15:57:50 2016
@@ -21,74 +21,66 @@
 using namespace lldb;
 using namespace lldb_private;
 
-ClangPersistentVariables::ClangPersistentVariables () :
-    lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang),
-    m_next_persistent_variable_id (0)
-{
-}
-
-ExpressionVariableSP
-ClangPersistentVariables::CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp)
-{
-    return AddNewlyConstructedVariable(new ClangExpressionVariable(valobj_sp));
-}
-
-ExpressionVariableSP
-ClangPersistentVariables::CreatePersistentVariable (ExecutionContextScope *exe_scope, 
-                                                    const ConstString &name, 
-                                                    const CompilerType& compiler_type,
-                                                    lldb::ByteOrder byte_order, 
-                                                    uint32_t addr_byte_size)
-{
-    return AddNewlyConstructedVariable(new ClangExpressionVariable(exe_scope, name, compiler_type, byte_order, addr_byte_size));
-}
-
-void
-ClangPersistentVariables::RemovePersistentVariable (lldb::ExpressionVariableSP variable)
-{
-    RemoveVariable(variable);
-    
-    const char *name = variable->GetName().AsCString();
-    
-    if (*name != '$')
-        return;
-    name++;
-    
-    if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1)
-        m_next_persistent_variable_id--;
-}
-
-ConstString
-ClangPersistentVariables::GetNextPersistentVariableName ()
-{
-    char name_cstr[256];
-    ::snprintf (name_cstr, sizeof(name_cstr), "$%u", m_next_persistent_variable_id++);
-    ConstString name(name_cstr);
-    return name;
-}
-
-void
-ClangPersistentVariables::RegisterPersistentDecl (const ConstString &name,
-                                                  clang::NamedDecl *decl)
-{
-    m_persistent_decls.insert(std::pair<const char*, clang::NamedDecl*>(name.GetCString(), decl));
-    
-    if (clang::EnumDecl *enum_decl = llvm::dyn_cast<clang::EnumDecl>(decl))
-    {
-        for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators())
-        {
-            m_persistent_decls.insert(std::pair<const char*, clang::NamedDecl*>(ConstString(enumerator_decl->getNameAsString()).GetCString(), enumerator_decl));
-        }
+ClangPersistentVariables::ClangPersistentVariables()
+    : lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang),
+      m_next_persistent_variable_id(0) {}
+
+ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable(
+    const lldb::ValueObjectSP &valobj_sp) {
+  return AddNewlyConstructedVariable(new ClangExpressionVariable(valobj_sp));
+}
+
+ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable(
+    ExecutionContextScope *exe_scope, const ConstString &name,
+    const CompilerType &compiler_type, lldb::ByteOrder byte_order,
+    uint32_t addr_byte_size) {
+  return AddNewlyConstructedVariable(new ClangExpressionVariable(
+      exe_scope, name, compiler_type, byte_order, addr_byte_size));
+}
+
+void ClangPersistentVariables::RemovePersistentVariable(
+    lldb::ExpressionVariableSP variable) {
+  RemoveVariable(variable);
+
+  const char *name = variable->GetName().AsCString();
+
+  if (*name != '$')
+    return;
+  name++;
+
+  if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1)
+    m_next_persistent_variable_id--;
+}
+
+ConstString ClangPersistentVariables::GetNextPersistentVariableName() {
+  char name_cstr[256];
+  ::snprintf(name_cstr, sizeof(name_cstr), "$%u",
+             m_next_persistent_variable_id++);
+  ConstString name(name_cstr);
+  return name;
+}
+
+void ClangPersistentVariables::RegisterPersistentDecl(const ConstString &name,
+                                                      clang::NamedDecl *decl) {
+  m_persistent_decls.insert(
+      std::pair<const char *, clang::NamedDecl *>(name.GetCString(), decl));
+
+  if (clang::EnumDecl *enum_decl = llvm::dyn_cast<clang::EnumDecl>(decl)) {
+    for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators()) {
+      m_persistent_decls.insert(std::pair<const char *, clang::NamedDecl *>(
+          ConstString(enumerator_decl->getNameAsString()).GetCString(),
+          enumerator_decl));
     }
+  }
 }
 
 clang::NamedDecl *
-ClangPersistentVariables::GetPersistentDecl (const ConstString &name)
-{
-    PersistentDeclMap::const_iterator i = m_persistent_decls.find(name.GetCString());
-    
-    if (i == m_persistent_decls.end())
-        return NULL;
-    else
-        return i->second;
+ClangPersistentVariables::GetPersistentDecl(const ConstString &name) {
+  PersistentDeclMap::const_iterator i =
+      m_persistent_decls.find(name.GetCString());
+
+  if (i == m_persistent_decls.end())
+    return NULL;
+  else
+    return i->second;
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h Tue Sep  6 15:57:50 2016
@@ -21,81 +21,74 @@
 
 #include "lldb/Expression/ExpressionVariable.h"
 
-namespace lldb_private
-{
-    
+namespace lldb_private {
+
 //----------------------------------------------------------------------
-/// @class ClangPersistentVariables ClangPersistentVariables.h "lldb/Expression/ClangPersistentVariables.h"
-/// @brief Manages persistent values that need to be preserved between expression invocations.
+/// @class ClangPersistentVariables ClangPersistentVariables.h
+/// "lldb/Expression/ClangPersistentVariables.h"
+/// @brief Manages persistent values that need to be preserved between
+/// expression invocations.
 ///
 /// A list of variables that can be accessed and updated by any expression.  See
 /// ClangPersistentVariable for more discussion.  Also provides an increasing,
 /// 0-based counter for naming result variables.
 //----------------------------------------------------------------------
-class ClangPersistentVariables : public PersistentExpressionState
-{
+class ClangPersistentVariables : public PersistentExpressionState {
 public:
-    ClangPersistentVariables();
+  ClangPersistentVariables();
+
+  ~ClangPersistentVariables() override = default;
 
-    ~ClangPersistentVariables() override = default;
+  //------------------------------------------------------------------
+  // llvm casting support
+  //------------------------------------------------------------------
+  static bool classof(const PersistentExpressionState *pv) {
+    return pv->getKind() == PersistentExpressionState::eKindClang;
+  }
+
+  lldb::ExpressionVariableSP
+  CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
+
+  lldb::ExpressionVariableSP CreatePersistentVariable(
+      ExecutionContextScope *exe_scope, const ConstString &name,
+      const CompilerType &compiler_type, lldb::ByteOrder byte_order,
+      uint32_t addr_byte_size) override;
+
+  //----------------------------------------------------------------------
+  /// Return the next entry in the sequence of strings "$0", "$1", ... for
+  /// use naming persistent expression convenience variables.
+  ///
+  /// @return
+  ///     A string that contains the next persistent variable name.
+  //----------------------------------------------------------------------
+  ConstString GetNextPersistentVariableName() override;
+
+  void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
+
+  void RegisterPersistentDecl(const ConstString &name, clang::NamedDecl *decl);
+
+  clang::NamedDecl *GetPersistentDecl(const ConstString &name);
+
+  void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {
+    m_hand_loaded_clang_modules.push_back(module);
+  }
+
+  const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {
+    return m_hand_loaded_clang_modules;
+  }
 
-    //------------------------------------------------------------------
-    // llvm casting support
-    //------------------------------------------------------------------
-    static bool classof(const PersistentExpressionState *pv)
-    {
-        return pv->getKind() == PersistentExpressionState::eKindClang;
-    }
-
-    lldb::ExpressionVariableSP
-    CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp) override;
-
-    lldb::ExpressionVariableSP
-    CreatePersistentVariable (ExecutionContextScope *exe_scope,
-                              const ConstString &name, 
-                              const CompilerType& compiler_type, 
-                              lldb::ByteOrder byte_order, 
-                              uint32_t addr_byte_size) override;
-
-    //----------------------------------------------------------------------
-    /// Return the next entry in the sequence of strings "$0", "$1", ... for
-    /// use naming persistent expression convenience variables.
-    ///
-    /// @return
-    ///     A string that contains the next persistent variable name.
-    //----------------------------------------------------------------------
-    ConstString
-    GetNextPersistentVariableName () override;
-    
-    void
-    RemovePersistentVariable (lldb::ExpressionVariableSP variable) override;
-    
-    void
-    RegisterPersistentDecl (const ConstString &name,
-                            clang::NamedDecl *decl);
-    
-    clang::NamedDecl *
-    GetPersistentDecl (const ConstString &name);
-    
-    void
-    AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module)
-    {
-        m_hand_loaded_clang_modules.push_back(module);
-    }
-    
-    const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules()
-    {
-        return m_hand_loaded_clang_modules;
-    }
-    
 private:
-    uint32_t                                                m_next_persistent_variable_id;  ///< The counter used by GetNextResultName().
-    
-    typedef llvm::DenseMap<const char *, clang::NamedDecl *>    PersistentDeclMap;
-    PersistentDeclMap                                           m_persistent_decls;         ///< Persistent entities declared by the user.
-    
-    ClangModulesDeclVendor::ModuleVector                    m_hand_loaded_clang_modules;    ///< These are Clang modules we hand-loaded; these are the highest-
-                                                                                            ///< priority source for macros.
+  uint32_t m_next_persistent_variable_id; ///< The counter used by
+                                          ///GetNextResultName().
+
+  typedef llvm::DenseMap<const char *, clang::NamedDecl *> PersistentDeclMap;
+  PersistentDeclMap
+      m_persistent_decls; ///< Persistent entities declared by the user.
+
+  ClangModulesDeclVendor::ModuleVector
+      m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
+                                   ///these are the highest-
+                                   ///< priority source for macros.
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Tue Sep  6 15:57:50 2016
@@ -9,21 +9,21 @@
 
 #include <stdio.h>
 #if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
+#include <sys/types.h>
 #endif
 
 #include <cstdlib>
-#include <string>
 #include <map>
+#include <string>
 
 #include "ClangUserExpression.h"
 
 #include "ASTResultSynthesizer.h"
+#include "ClangDiagnostic.h"
 #include "ClangExpressionDeclMap.h"
 #include "ClangExpressionParser.h"
 #include "ClangModulesDeclVendor.h"
 #include "ClangPersistentVariables.h"
-#include "ClangDiagnostic.h"
 
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/Debugger.h"
@@ -39,11 +39,11 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Symbol/Type.h"
-#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/VariableList.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
@@ -57,676 +57,633 @@
 
 using namespace lldb_private;
 
-ClangUserExpression::ClangUserExpression(ExecutionContextScope &exe_scope, const char *expr, const char *expr_prefix,
-                                         lldb::LanguageType language, ResultType desired_type,
-                                         const EvaluateExpressionOptions &options)
-    : LLVMUserExpression(exe_scope, expr, expr_prefix, language, desired_type, options),
-      m_type_system_helper(*m_target_wp.lock().get(), options.GetExecutionPolicy() == eExecutionPolicyTopLevel)
-{
-    switch (m_language)
-    {
-        case lldb::eLanguageTypeC_plus_plus:
-            m_allow_cxx = true;
-            break;
-        case lldb::eLanguageTypeObjC:
-            m_allow_objc = true;
-            break;
-        case lldb::eLanguageTypeObjC_plus_plus:
-        default:
-            m_allow_cxx = true;
-            m_allow_objc = true;
-            break;
-    }
-}
-
-ClangUserExpression::~ClangUserExpression ()
-{
-}
-
-void
-ClangUserExpression::ScanContext(ExecutionContext &exe_ctx, Error &err)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    if (log)
-        log->Printf("ClangUserExpression::ScanContext()");
+ClangUserExpression::ClangUserExpression(
+    ExecutionContextScope &exe_scope, const char *expr, const char *expr_prefix,
+    lldb::LanguageType language, ResultType desired_type,
+    const EvaluateExpressionOptions &options)
+    : LLVMUserExpression(exe_scope, expr, expr_prefix, language, desired_type,
+                         options),
+      m_type_system_helper(*m_target_wp.lock().get(),
+                           options.GetExecutionPolicy() ==
+                               eExecutionPolicyTopLevel) {
+  switch (m_language) {
+  case lldb::eLanguageTypeC_plus_plus:
+    m_allow_cxx = true;
+    break;
+  case lldb::eLanguageTypeObjC:
+    m_allow_objc = true;
+    break;
+  case lldb::eLanguageTypeObjC_plus_plus:
+  default:
+    m_allow_cxx = true;
+    m_allow_objc = true;
+    break;
+  }
+}
+
+ClangUserExpression::~ClangUserExpression() {}
+
+void ClangUserExpression::ScanContext(ExecutionContext &exe_ctx, Error &err) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-    m_target = exe_ctx.GetTargetPtr();
-
-    if (!(m_allow_cxx || m_allow_objc))
-    {
-        if (log)
-            log->Printf("  [CUE::SC] Settings inhibit C++ and Objective-C");
-        return;
-    }
-
-    StackFrame *frame = exe_ctx.GetFramePtr();
-    if (frame == NULL)
-    {
-        if (log)
-            log->Printf("  [CUE::SC] Null stack frame");
-        return;
-    }
-
-    SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
-
-    if (!sym_ctx.function)
-    {
-        if (log)
-            log->Printf("  [CUE::SC] Null function");
-        return;
-    }
-
-    // Find the block that defines the function represented by "sym_ctx"
-    Block *function_block = sym_ctx.GetFunctionBlock();
-
-    if (!function_block)
-    {
-        if (log)
-            log->Printf("  [CUE::SC] Null function block");
-        return;
-    }
+  if (log)
+    log->Printf("ClangUserExpression::ScanContext()");
 
-    CompilerDeclContext decl_context = function_block->GetDeclContext();
+  m_target = exe_ctx.GetTargetPtr();
 
-    if (!decl_context)
-    {
-        if (log)
-            log->Printf("  [CUE::SC] Null decl context");
-        return;
-    }
+  if (!(m_allow_cxx || m_allow_objc)) {
+    if (log)
+      log->Printf("  [CUE::SC] Settings inhibit C++ and Objective-C");
+    return;
+  }
 
-    if (clang::CXXMethodDecl *method_decl = ClangASTContext::DeclContextGetAsCXXMethodDecl(decl_context))
-    {
-        if (m_allow_cxx && method_decl->isInstance())
-        {
-            if (m_enforce_valid_object)
-            {
-                lldb::VariableListSP variable_list_sp (function_block->GetBlockVariableList (true));
+  StackFrame *frame = exe_ctx.GetFramePtr();
+  if (frame == NULL) {
+    if (log)
+      log->Printf("  [CUE::SC] Null stack frame");
+    return;
+  }
 
-                const char *thisErrorString = "Stopped in a C++ method, but 'this' isn't available; pretending we are in a generic context";
+  SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
+                                                  lldb::eSymbolContextBlock);
 
-                if (!variable_list_sp)
-                {
-                    err.SetErrorString(thisErrorString);
-                    return;
-                }
+  if (!sym_ctx.function) {
+    if (log)
+      log->Printf("  [CUE::SC] Null function");
+    return;
+  }
 
-                lldb::VariableSP this_var_sp (variable_list_sp->FindVariable(ConstString("this")));
+  // Find the block that defines the function represented by "sym_ctx"
+  Block *function_block = sym_ctx.GetFunctionBlock();
 
-                if (!this_var_sp ||
-                    !this_var_sp->IsInScope(frame) ||
-                    !this_var_sp->LocationIsValidForFrame (frame))
-                {
-                    err.SetErrorString(thisErrorString);
-                    return;
-                }
-            }
+  if (!function_block) {
+    if (log)
+      log->Printf("  [CUE::SC] Null function block");
+    return;
+  }
 
-            m_in_cplusplus_method = true;
-            m_needs_object_ptr = true;
-        }
-    }
-    else if (clang::ObjCMethodDecl *method_decl = ClangASTContext::DeclContextGetAsObjCMethodDecl(decl_context))
-    {
-        if (m_allow_objc)
-        {
-            if (m_enforce_valid_object)
-            {
-                lldb::VariableListSP variable_list_sp (function_block->GetBlockVariableList (true));
-
-                const char *selfErrorString = "Stopped in an Objective-C method, but 'self' isn't available; pretending we are in a generic context";
-
-                if (!variable_list_sp)
-                {
-                    err.SetErrorString(selfErrorString);
-                    return;
-                }
-
-                lldb::VariableSP self_variable_sp = variable_list_sp->FindVariable(ConstString("self"));
-
-                if (!self_variable_sp ||
-                    !self_variable_sp->IsInScope(frame) ||
-                    !self_variable_sp->LocationIsValidForFrame (frame))
-                {
-                    err.SetErrorString(selfErrorString);
-                    return;
-                }
-            }
+  CompilerDeclContext decl_context = function_block->GetDeclContext();
 
+  if (!decl_context) {
+    if (log)
+      log->Printf("  [CUE::SC] Null decl context");
+    return;
+  }
+
+  if (clang::CXXMethodDecl *method_decl =
+          ClangASTContext::DeclContextGetAsCXXMethodDecl(decl_context)) {
+    if (m_allow_cxx && method_decl->isInstance()) {
+      if (m_enforce_valid_object) {
+        lldb::VariableListSP variable_list_sp(
+            function_block->GetBlockVariableList(true));
+
+        const char *thisErrorString = "Stopped in a C++ method, but 'this' "
+                                      "isn't available; pretending we are in a "
+                                      "generic context";
+
+        if (!variable_list_sp) {
+          err.SetErrorString(thisErrorString);
+          return;
+        }
+
+        lldb::VariableSP this_var_sp(
+            variable_list_sp->FindVariable(ConstString("this")));
+
+        if (!this_var_sp || !this_var_sp->IsInScope(frame) ||
+            !this_var_sp->LocationIsValidForFrame(frame)) {
+          err.SetErrorString(thisErrorString);
+          return;
+        }
+      }
+
+      m_in_cplusplus_method = true;
+      m_needs_object_ptr = true;
+    }
+  } else if (clang::ObjCMethodDecl *method_decl =
+                 ClangASTContext::DeclContextGetAsObjCMethodDecl(
+                     decl_context)) {
+    if (m_allow_objc) {
+      if (m_enforce_valid_object) {
+        lldb::VariableListSP variable_list_sp(
+            function_block->GetBlockVariableList(true));
+
+        const char *selfErrorString = "Stopped in an Objective-C method, but "
+                                      "'self' isn't available; pretending we "
+                                      "are in a generic context";
+
+        if (!variable_list_sp) {
+          err.SetErrorString(selfErrorString);
+          return;
+        }
+
+        lldb::VariableSP self_variable_sp =
+            variable_list_sp->FindVariable(ConstString("self"));
+
+        if (!self_variable_sp || !self_variable_sp->IsInScope(frame) ||
+            !self_variable_sp->LocationIsValidForFrame(frame)) {
+          err.SetErrorString(selfErrorString);
+          return;
+        }
+      }
+
+      m_in_objectivec_method = true;
+      m_needs_object_ptr = true;
+
+      if (!method_decl->isInstanceMethod())
+        m_in_static_method = true;
+    }
+  } else if (clang::FunctionDecl *function_decl =
+                 ClangASTContext::DeclContextGetAsFunctionDecl(decl_context)) {
+    // We might also have a function that said in the debug information that it
+    // captured an
+    // object pointer.  The best way to deal with getting to the ivars at
+    // present is by pretending
+    // that this is a method of a class in whatever runtime the debug info says
+    // the object pointer
+    // belongs to.  Do that here.
+
+    ClangASTMetadata *metadata =
+        ClangASTContext::DeclContextGetMetaData(decl_context, function_decl);
+    if (metadata && metadata->HasObjectPtr()) {
+      lldb::LanguageType language = metadata->GetObjectPtrLanguage();
+      if (language == lldb::eLanguageTypeC_plus_plus) {
+        if (m_enforce_valid_object) {
+          lldb::VariableListSP variable_list_sp(
+              function_block->GetBlockVariableList(true));
+
+          const char *thisErrorString = "Stopped in a context claiming to "
+                                        "capture a C++ object pointer, but "
+                                        "'this' isn't available; pretending we "
+                                        "are in a generic context";
+
+          if (!variable_list_sp) {
+            err.SetErrorString(thisErrorString);
+            return;
+          }
+
+          lldb::VariableSP this_var_sp(
+              variable_list_sp->FindVariable(ConstString("this")));
+
+          if (!this_var_sp || !this_var_sp->IsInScope(frame) ||
+              !this_var_sp->LocationIsValidForFrame(frame)) {
+            err.SetErrorString(thisErrorString);
+            return;
+          }
+        }
+
+        m_in_cplusplus_method = true;
+        m_needs_object_ptr = true;
+      } else if (language == lldb::eLanguageTypeObjC) {
+        if (m_enforce_valid_object) {
+          lldb::VariableListSP variable_list_sp(
+              function_block->GetBlockVariableList(true));
+
+          const char *selfErrorString =
+              "Stopped in a context claiming to capture an Objective-C object "
+              "pointer, but 'self' isn't available; pretending we are in a "
+              "generic context";
+
+          if (!variable_list_sp) {
+            err.SetErrorString(selfErrorString);
+            return;
+          }
+
+          lldb::VariableSP self_variable_sp =
+              variable_list_sp->FindVariable(ConstString("self"));
+
+          if (!self_variable_sp || !self_variable_sp->IsInScope(frame) ||
+              !self_variable_sp->LocationIsValidForFrame(frame)) {
+            err.SetErrorString(selfErrorString);
+            return;
+          }
+
+          Type *self_type = self_variable_sp->GetType();
+
+          if (!self_type) {
+            err.SetErrorString(selfErrorString);
+            return;
+          }
+
+          CompilerType self_clang_type = self_type->GetForwardCompilerType();
+
+          if (!self_clang_type) {
+            err.SetErrorString(selfErrorString);
+            return;
+          }
+
+          if (ClangASTContext::IsObjCClassType(self_clang_type)) {
+            return;
+          } else if (ClangASTContext::IsObjCObjectPointerType(
+                         self_clang_type)) {
             m_in_objectivec_method = true;
             m_needs_object_ptr = true;
-
-            if (!method_decl->isInstanceMethod())
-                m_in_static_method = true;
-        }
-    }
-    else if (clang::FunctionDecl *function_decl = ClangASTContext::DeclContextGetAsFunctionDecl(decl_context))
-    {
-        // We might also have a function that said in the debug information that it captured an
-        // object pointer.  The best way to deal with getting to the ivars at present is by pretending
-        // that this is a method of a class in whatever runtime the debug info says the object pointer
-        // belongs to.  Do that here.
-
-        ClangASTMetadata *metadata = ClangASTContext::DeclContextGetMetaData (decl_context, function_decl);
-        if (metadata && metadata->HasObjectPtr())
-        {
-            lldb::LanguageType language = metadata->GetObjectPtrLanguage();
-            if (language == lldb::eLanguageTypeC_plus_plus)
-            {
-                if (m_enforce_valid_object)
-                {
-                    lldb::VariableListSP variable_list_sp (function_block->GetBlockVariableList (true));
-
-                    const char *thisErrorString = "Stopped in a context claiming to capture a C++ object pointer, but 'this' isn't available; pretending we are in a generic context";
-
-                    if (!variable_list_sp)
-                    {
-                        err.SetErrorString(thisErrorString);
-                        return;
-                    }
-
-                    lldb::VariableSP this_var_sp (variable_list_sp->FindVariable(ConstString("this")));
-
-                    if (!this_var_sp ||
-                        !this_var_sp->IsInScope(frame) ||
-                        !this_var_sp->LocationIsValidForFrame (frame))
-                    {
-                        err.SetErrorString(thisErrorString);
-                        return;
-                    }
-                }
-
-                m_in_cplusplus_method = true;
-                m_needs_object_ptr = true;
-            }
-            else if (language == lldb::eLanguageTypeObjC)
-            {
-                if (m_enforce_valid_object)
-                {
-                    lldb::VariableListSP variable_list_sp (function_block->GetBlockVariableList (true));
-
-                    const char *selfErrorString = "Stopped in a context claiming to capture an Objective-C object pointer, but 'self' isn't available; pretending we are in a generic context";
-
-                    if (!variable_list_sp)
-                    {
-                        err.SetErrorString(selfErrorString);
-                        return;
-                    }
-
-                    lldb::VariableSP self_variable_sp = variable_list_sp->FindVariable(ConstString("self"));
-
-                    if (!self_variable_sp ||
-                        !self_variable_sp->IsInScope(frame) ||
-                        !self_variable_sp->LocationIsValidForFrame (frame))
-                    {
-                        err.SetErrorString(selfErrorString);
-                        return;
-                    }
-
-                    Type *self_type = self_variable_sp->GetType();
-
-                    if (!self_type)
-                    {
-                        err.SetErrorString(selfErrorString);
-                        return;
-                    }
-
-                    CompilerType self_clang_type = self_type->GetForwardCompilerType ();
-
-                    if (!self_clang_type)
-                    {
-                        err.SetErrorString(selfErrorString);
-                        return;
-                    }
-
-                    if (ClangASTContext::IsObjCClassType(self_clang_type))
-                    {
-                        return;
-                    }
-                    else if (ClangASTContext::IsObjCObjectPointerType(self_clang_type))
-                    {
-                        m_in_objectivec_method = true;
-                        m_needs_object_ptr = true;
-                    }
-                    else
-                    {
-                        err.SetErrorString(selfErrorString);
-                        return;
-                    }
-                }
-                else
-                {
-                    m_in_objectivec_method = true;
-                    m_needs_object_ptr = true;
-                }
-            }
+          } else {
+            err.SetErrorString(selfErrorString);
+            return;
+          }
+        } else {
+          m_in_objectivec_method = true;
+          m_needs_object_ptr = true;
         }
+      }
     }
+  }
 }
 
 // This is a really nasty hack, meant to fix Objective-C expressions of the form
 // (int)[myArray count].  Right now, because the type information for count is
 // not available, [myArray count] returns id, which can't be directly cast to
 // int without causing a clang error.
-static void
-ApplyObjcCastHack(std::string &expr)
-{
+static void ApplyObjcCastHack(std::string &expr) {
 #define OBJC_CAST_HACK_FROM "(int)["
-#define OBJC_CAST_HACK_TO   "(int)(long long)["
+#define OBJC_CAST_HACK_TO "(int)(long long)["
 
-    size_t from_offset;
+  size_t from_offset;
 
-    while ((from_offset = expr.find(OBJC_CAST_HACK_FROM)) != expr.npos)
-        expr.replace(from_offset, sizeof(OBJC_CAST_HACK_FROM) - 1, OBJC_CAST_HACK_TO);
+  while ((from_offset = expr.find(OBJC_CAST_HACK_FROM)) != expr.npos)
+    expr.replace(from_offset, sizeof(OBJC_CAST_HACK_FROM) - 1,
+                 OBJC_CAST_HACK_TO);
 
 #undef OBJC_CAST_HACK_TO
 #undef OBJC_CAST_HACK_FROM
 }
 
-bool
-ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
-                           lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory,
-                           bool generate_debug_info)
-{
-    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
-    Error err;
-
-    InstallContext(exe_ctx);
-    
-    if (Target *target = exe_ctx.GetTargetPtr())
-    {
-        if (PersistentExpressionState *persistent_state = target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))
-        {
-            m_result_delegate.RegisterPersistentState(persistent_state);
-        }
-        else
-        {
-            diagnostic_manager.PutCString(eDiagnosticSeverityError, "couldn't start parsing (no persistent data)");
-            return false;
-        }
-    }
+bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
+                                ExecutionContext &exe_ctx,
+                                lldb_private::ExecutionPolicy execution_policy,
+                                bool keep_result_in_memory,
+                                bool generate_debug_info) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  Error err;
+
+  InstallContext(exe_ctx);
+
+  if (Target *target = exe_ctx.GetTargetPtr()) {
+    if (PersistentExpressionState *persistent_state =
+            target->GetPersistentExpressionStateForLanguage(
+                lldb::eLanguageTypeC)) {
+      m_result_delegate.RegisterPersistentState(persistent_state);
+    } else {
+      diagnostic_manager.PutCString(
+          eDiagnosticSeverityError,
+          "couldn't start parsing (no persistent data)");
+      return false;
+    }
+  } else {
+    diagnostic_manager.PutCString(eDiagnosticSeverityError,
+                                  "error: couldn't start parsing (no target)");
+    return false;
+  }
+
+  ScanContext(exe_ctx, err);
+
+  if (!err.Success()) {
+    diagnostic_manager.PutCString(eDiagnosticSeverityWarning, err.AsCString());
+  }
+
+  ////////////////////////////////////
+  // Generate the expression
+  //
+
+  ApplyObjcCastHack(m_expr_text);
+  // ApplyUnicharHack(m_expr_text);
+
+  std::string prefix = m_expr_prefix;
+
+  if (ClangModulesDeclVendor *decl_vendor =
+          m_target->GetClangModulesDeclVendor()) {
+    const ClangModulesDeclVendor::ModuleVector &hand_imported_modules =
+        llvm::cast<ClangPersistentVariables>(
+            m_target->GetPersistentExpressionStateForLanguage(
+                lldb::eLanguageTypeC))
+            ->GetHandLoadedClangModules();
+    ClangModulesDeclVendor::ModuleVector modules_for_macros;
+
+    for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) {
+      modules_for_macros.push_back(module);
+    }
+
+    if (m_target->GetEnableAutoImportClangModules()) {
+      if (StackFrame *frame = exe_ctx.GetFramePtr()) {
+        if (Block *block = frame->GetFrameBlock()) {
+          SymbolContext sc;
+
+          block->CalculateSymbolContext(&sc);
+
+          if (sc.comp_unit) {
+            StreamString error_stream;
+
+            decl_vendor->AddModulesForCompileUnit(
+                *sc.comp_unit, modules_for_macros, error_stream);
+          }
+        }
+      }
+    }
+  }
+
+  lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown;
+
+  if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) {
+    m_transformed_text = m_expr_text;
+  } else {
+    std::unique_ptr<ExpressionSourceCode> source_code(
+        ExpressionSourceCode::CreateWrapped(prefix.c_str(),
+                                            m_expr_text.c_str()));
+
+    if (m_in_cplusplus_method)
+      lang_type = lldb::eLanguageTypeC_plus_plus;
+    else if (m_in_objectivec_method)
+      lang_type = lldb::eLanguageTypeObjC;
     else
-    {
-        diagnostic_manager.PutCString(eDiagnosticSeverityError, "error: couldn't start parsing (no target)");
-        return false;
-    }
-
-    ScanContext(exe_ctx, err);
-
-    if (!err.Success())
-    {
-        diagnostic_manager.PutCString(eDiagnosticSeverityWarning, err.AsCString());
-    }
-
-    ////////////////////////////////////
-    // Generate the expression
-    //
-
-    ApplyObjcCastHack(m_expr_text);
-    //ApplyUnicharHack(m_expr_text);
-
-    std::string prefix = m_expr_prefix;
-    
-    if (ClangModulesDeclVendor *decl_vendor = m_target->GetClangModulesDeclVendor())
-    {
-        const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = llvm::cast<ClangPersistentVariables>(m_target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))->GetHandLoadedClangModules();
-        ClangModulesDeclVendor::ModuleVector modules_for_macros;
-        
-        for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules)
-        {
-            modules_for_macros.push_back(module);
-        }
+      lang_type = lldb::eLanguageTypeC;
 
-        if (m_target->GetEnableAutoImportClangModules())
-        {
-            if (StackFrame *frame = exe_ctx.GetFramePtr())
-            {
-                if (Block *block = frame->GetFrameBlock())
-                {
-                    SymbolContext sc;
-                    
-                    block->CalculateSymbolContext(&sc);
-                    
-                    if (sc.comp_unit)
-                    {
-                        StreamString error_stream;
-                        
-                        decl_vendor->AddModulesForCompileUnit(*sc.comp_unit, modules_for_macros, error_stream);
-                    }
-                }
-            }
-        }
+    if (!source_code->GetText(m_transformed_text, lang_type, m_in_static_method,
+                              exe_ctx)) {
+      diagnostic_manager.PutCString(eDiagnosticSeverityError,
+                                    "couldn't construct expression body");
+      return false;
     }
+  }
 
-    lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown;
+  if (log)
+    log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
 
-    if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel)
-    {
-        m_transformed_text = m_expr_text;
-    }
-    else
-    {
-        std::unique_ptr<ExpressionSourceCode> source_code(
-            ExpressionSourceCode::CreateWrapped(prefix.c_str(), m_expr_text.c_str()));
-
-        if (m_in_cplusplus_method)
-            lang_type = lldb::eLanguageTypeC_plus_plus;
-        else if (m_in_objectivec_method)
-            lang_type = lldb::eLanguageTypeObjC;
-        else
-            lang_type = lldb::eLanguageTypeC;
-
-        if (!source_code->GetText(m_transformed_text, lang_type, m_in_static_method, exe_ctx))
-        {
-            diagnostic_manager.PutCString(eDiagnosticSeverityError, "couldn't construct expression body");
-            return false;
-        }
-    }
+  ////////////////////////////////////
+  // Set up the target and compiler
+  //
 
-    if (log)
-        log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
+  Target *target = exe_ctx.GetTargetPtr();
 
-    ////////////////////////////////////
-    // Set up the target and compiler
-    //
+  if (!target) {
+    diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target");
+    return false;
+  }
 
-    Target *target = exe_ctx.GetTargetPtr();
+  //////////////////////////
+  // Parse the expression
+  //
 
-    if (!target)
-    {
-        diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target");
-        return false;
-    }
+  m_materializer_ap.reset(new Materializer());
 
-    //////////////////////////
-    // Parse the expression
-    //
+  ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
 
-    m_materializer_ap.reset(new Materializer());
+  class OnExit {
+  public:
+    typedef std::function<void(void)> Callback;
 
-    ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
+    OnExit(Callback const &callback) : m_callback(callback) {}
 
-    class OnExit
-    {
-    public:
-        typedef std::function <void (void)> Callback;
+    ~OnExit() { m_callback(); }
 
-        OnExit (Callback const &callback) :
-            m_callback(callback)
-        {
-        }
+  private:
+    Callback m_callback;
+  };
 
-        ~OnExit ()
-        {
-            m_callback();
-        }
-    private:
-        Callback m_callback;
-    };
+  OnExit on_exit([this]() { ResetDeclMap(); });
 
-    OnExit on_exit([this]() { ResetDeclMap(); });
+  if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
+    diagnostic_manager.PutCString(
+        eDiagnosticSeverityError,
+        "current process state is unsuitable for expression parsing");
 
-    if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get()))
-    {
-        diagnostic_manager.PutCString(eDiagnosticSeverityError,
-                                      "current process state is unsuitable for expression parsing");
+    ResetDeclMap(); // We are being careful here in the case of breakpoint
+                    // conditions.
 
-        ResetDeclMap(); // We are being careful here in the case of breakpoint conditions.
+    return false;
+  }
 
-        return false;
-    }
+  if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) {
+    DeclMap()->SetLookupsEnabled(true);
+  }
 
-    if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel)
-    {
-        DeclMap()->SetLookupsEnabled(true);
-    }
+  Process *process = exe_ctx.GetProcessPtr();
+  ExecutionContextScope *exe_scope = process;
 
-    Process *process = exe_ctx.GetProcessPtr();
-    ExecutionContextScope *exe_scope = process;
+  if (!exe_scope)
+    exe_scope = exe_ctx.GetTargetPtr();
 
-    if (!exe_scope)
-        exe_scope = exe_ctx.GetTargetPtr();
+  // We use a shared pointer here so we can use the original parser - if it
+  // succeeds
+  // or the rewrite parser we might make if it fails.  But the parser_sp will
+  // never be empty.
 
-    // We use a shared pointer here so we can use the original parser - if it succeeds
-    // or the rewrite parser we might make if it fails.  But the parser_sp will never be empty.
-    
-    ClangExpressionParser parser(exe_scope, *this, generate_debug_info);
+  ClangExpressionParser parser(exe_scope, *this, generate_debug_info);
 
-    unsigned num_errors = parser.Parse(diagnostic_manager);
+  unsigned num_errors = parser.Parse(diagnostic_manager);
 
-    // Check here for FixItHints.  If there are any try to apply the fixits and set the fixed text in m_fixed_text
-    // before returning an error.
-    if (num_errors)
-    {
-        if (diagnostic_manager.HasFixIts())
-        {
-            if (parser.RewriteExpression(diagnostic_manager))
-            {
-                size_t fixed_start;
-                size_t fixed_end;
-                const std::string &fixed_expression = diagnostic_manager.GetFixedExpression();
-                if (ExpressionSourceCode::GetOriginalBodyBounds(fixed_expression, lang_type, fixed_start, fixed_end))
-                    m_fixed_text = fixed_expression.substr(fixed_start, fixed_end - fixed_start);
-            }
-        }
+  // Check here for FixItHints.  If there are any try to apply the fixits and
+  // set the fixed text in m_fixed_text
+  // before returning an error.
+  if (num_errors) {
+    if (diagnostic_manager.HasFixIts()) {
+      if (parser.RewriteExpression(diagnostic_manager)) {
+        size_t fixed_start;
+        size_t fixed_end;
+        const std::string &fixed_expression =
+            diagnostic_manager.GetFixedExpression();
+        if (ExpressionSourceCode::GetOriginalBodyBounds(
+                fixed_expression, lang_type, fixed_start, fixed_end))
+          m_fixed_text =
+              fixed_expression.substr(fixed_start, fixed_end - fixed_start);
+      }
+    }
+
+    ResetDeclMap(); // We are being careful here in the case of breakpoint
+                    // conditions.
+
+    return false;
+  }
 
-        ResetDeclMap(); // We are being careful here in the case of breakpoint conditions.
+  //////////////////////////////////////////////////////////////////////////////////////////
+  // Prepare the output of the parser for execution, evaluating it statically if
+  // possible
+  //
 
-        return false;
+  {
+    Error jit_error = parser.PrepareForExecution(
+        m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx,
+        m_can_interpret, execution_policy);
+
+    if (!jit_error.Success()) {
+      const char *error_cstr = jit_error.AsCString();
+      if (error_cstr && error_cstr[0])
+        diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr);
+      else
+        diagnostic_manager.PutCString(eDiagnosticSeverityError,
+                                      "expression can't be interpreted or run");
+      return false;
     }
+  }
 
-    //////////////////////////////////////////////////////////////////////////////////////////
-    // Prepare the output of the parser for execution, evaluating it statically if possible
-    //
-
-    {
-        Error jit_error = parser.PrepareForExecution(m_jit_start_addr,
-                                                     m_jit_end_addr,
-                                                     m_execution_unit_sp,
-                                                     exe_ctx,
-                                                     m_can_interpret,
-                                                     execution_policy);
-
-        if (!jit_error.Success())
-        {
-            const char *error_cstr = jit_error.AsCString();
-            if (error_cstr && error_cstr[0])
-                diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr);
-            else
-                diagnostic_manager.PutCString(eDiagnosticSeverityError, "expression can't be interpreted or run");
-            return false;
-        }
+  if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel) {
+    Error static_init_error =
+        parser.RunStaticInitializers(m_execution_unit_sp, exe_ctx);
+
+    if (!static_init_error.Success()) {
+      const char *error_cstr = static_init_error.AsCString();
+      if (error_cstr && error_cstr[0])
+        diagnostic_manager.Printf(eDiagnosticSeverityError,
+                                  "couldn't run static initializers: %s\n",
+                                  error_cstr);
+      else
+        diagnostic_manager.PutCString(eDiagnosticSeverityError,
+                                      "couldn't run static initializers\n");
+      return false;
     }
+  }
 
-    if (exe_ctx.GetProcessPtr() && execution_policy == eExecutionPolicyTopLevel)
-    {
-        Error static_init_error = parser.RunStaticInitializers(m_execution_unit_sp, exe_ctx);
-
-        if (!static_init_error.Success())
-        {
-            const char *error_cstr = static_init_error.AsCString();
-            if (error_cstr && error_cstr[0])
-                diagnostic_manager.Printf(eDiagnosticSeverityError, "couldn't run static initializers: %s\n",
-                                          error_cstr);
-            else
-                diagnostic_manager.PutCString(eDiagnosticSeverityError, "couldn't run static initializers\n");
-            return false;
-        }
+  if (m_execution_unit_sp) {
+    bool register_execution_unit = false;
+
+    if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) {
+      register_execution_unit = true;
     }
 
-    if (m_execution_unit_sp)
-    {
-        bool register_execution_unit = false;
-
-        if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel)
-        {
-            register_execution_unit = true;
-        }
-        
-        // If there is more than one external function in the execution
-        // unit, it needs to keep living even if it's not top level, because
-        // the result could refer to that function.
-        
-        if (m_execution_unit_sp->GetJittedFunctions().size() > 1)
-        {
-            register_execution_unit = true;
-        }
+    // If there is more than one external function in the execution
+    // unit, it needs to keep living even if it's not top level, because
+    // the result could refer to that function.
 
-        if (register_execution_unit)
-        {
-            llvm::cast<PersistentExpressionState>(
-                exe_ctx.GetTargetPtr()->GetPersistentExpressionStateForLanguage(m_language))
-                ->RegisterExecutionUnit(m_execution_unit_sp);
-        }
+    if (m_execution_unit_sp->GetJittedFunctions().size() > 1) {
+      register_execution_unit = true;
     }
 
-    if (generate_debug_info)
-    {
-        lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
-
-        if (jit_module_sp)
-        {
-            ConstString const_func_name(FunctionName());
-            FileSpec jit_file;
-            jit_file.GetFilename() = const_func_name;
-            jit_module_sp->SetFileSpecAndObjectName (jit_file, ConstString());
-            m_jit_module_wp = jit_module_sp;
-            target->GetImages().Append(jit_module_sp);
-        }
+    if (register_execution_unit) {
+      llvm::cast<PersistentExpressionState>(
+          exe_ctx.GetTargetPtr()->GetPersistentExpressionStateForLanguage(
+              m_language))
+          ->RegisterExecutionUnit(m_execution_unit_sp);
     }
+  }
 
-    ResetDeclMap(); // Make this go away since we don't need any of its state after parsing.  This also gets rid of any
-                    // ClangASTImporter::Minions.
+  if (generate_debug_info) {
+    lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
 
-    if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
-        m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
-    return true;
-}
-
-bool
-ClangUserExpression::AddArguments(ExecutionContext &exe_ctx, std::vector<lldb::addr_t> &args,
-                                  lldb::addr_t struct_address, DiagnosticManager &diagnostic_manager)
-{
-    lldb::addr_t object_ptr = LLDB_INVALID_ADDRESS;
-    lldb::addr_t cmd_ptr = LLDB_INVALID_ADDRESS;
-
-    if (m_needs_object_ptr)
-    {
-        lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP();
-        if (!frame_sp)
-            return true;
-        
-        ConstString object_name;
-
-        if (m_in_cplusplus_method)
-        {
-            object_name.SetCString("this");
-        }
-        else if (m_in_objectivec_method)
-        {
-            object_name.SetCString("self");
-        }
-        else
-        {
-            diagnostic_manager.PutCString(eDiagnosticSeverityError, "need object pointer but don't know the language");
-            return false;
-        }
+    if (jit_module_sp) {
+      ConstString const_func_name(FunctionName());
+      FileSpec jit_file;
+      jit_file.GetFilename() = const_func_name;
+      jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
+      m_jit_module_wp = jit_module_sp;
+      target->GetImages().Append(jit_module_sp);
+    }
+  }
 
-        Error object_ptr_error;
+  ResetDeclMap(); // Make this go away since we don't need any of its state
+                  // after parsing.  This also gets rid of any
+                  // ClangASTImporter::Minions.
 
-        object_ptr = GetObjectPointer(frame_sp, object_name, object_ptr_error);
+  if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
+    m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
+  return true;
+}
 
-        if (!object_ptr_error.Success())
-        {
-            exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf("warning: `%s' is not accessible (subsituting 0)\n", object_name.AsCString());
-            object_ptr = 0;
-        }
+bool ClangUserExpression::AddArguments(ExecutionContext &exe_ctx,
+                                       std::vector<lldb::addr_t> &args,
+                                       lldb::addr_t struct_address,
+                                       DiagnosticManager &diagnostic_manager) {
+  lldb::addr_t object_ptr = LLDB_INVALID_ADDRESS;
+  lldb::addr_t cmd_ptr = LLDB_INVALID_ADDRESS;
 
-        if (m_in_objectivec_method)
-        {
-            ConstString cmd_name("_cmd");
-
-            cmd_ptr = GetObjectPointer(frame_sp, cmd_name, object_ptr_error);
-
-            if (!object_ptr_error.Success())
-            {
-                diagnostic_manager.Printf(eDiagnosticSeverityWarning,
-                                          "couldn't get cmd pointer (substituting NULL): %s",
-                                          object_ptr_error.AsCString());
-                cmd_ptr = 0;
-            }
-        }
-        
-        args.push_back(object_ptr);
+  if (m_needs_object_ptr) {
+    lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP();
+    if (!frame_sp)
+      return true;
 
-        if (m_in_objectivec_method)
-            args.push_back(cmd_ptr);
+    ConstString object_name;
 
-        args.push_back(struct_address);
+    if (m_in_cplusplus_method) {
+      object_name.SetCString("this");
+    } else if (m_in_objectivec_method) {
+      object_name.SetCString("self");
+    } else {
+      diagnostic_manager.PutCString(
+          eDiagnosticSeverityError,
+          "need object pointer but don't know the language");
+      return false;
     }
-    else
-    {
-        args.push_back(struct_address);
+
+    Error object_ptr_error;
+
+    object_ptr = GetObjectPointer(frame_sp, object_name, object_ptr_error);
+
+    if (!object_ptr_error.Success()) {
+      exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf(
+          "warning: `%s' is not accessible (subsituting 0)\n",
+          object_name.AsCString());
+      object_ptr = 0;
     }
-    return true;
+
+    if (m_in_objectivec_method) {
+      ConstString cmd_name("_cmd");
+
+      cmd_ptr = GetObjectPointer(frame_sp, cmd_name, object_ptr_error);
+
+      if (!object_ptr_error.Success()) {
+        diagnostic_manager.Printf(
+            eDiagnosticSeverityWarning,
+            "couldn't get cmd pointer (substituting NULL): %s",
+            object_ptr_error.AsCString());
+        cmd_ptr = 0;
+      }
+    }
+
+    args.push_back(object_ptr);
+
+    if (m_in_objectivec_method)
+      args.push_back(cmd_ptr);
+
+    args.push_back(struct_address);
+  } else {
+    args.push_back(struct_address);
+  }
+  return true;
 }
 
-lldb::ExpressionVariableSP
-ClangUserExpression::GetResultAfterDematerialization(ExecutionContextScope *exe_scope)
-{
-    return m_result_delegate.GetVariable();
+lldb::ExpressionVariableSP ClangUserExpression::GetResultAfterDematerialization(
+    ExecutionContextScope *exe_scope) {
+  return m_result_delegate.GetVariable();
 }
 
-void
-ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap(ExecutionContext &exe_ctx, Materializer::PersistentVariableDelegate &delegate, bool keep_result_in_memory)
-{
-    m_expr_decl_map_up.reset(new ClangExpressionDeclMap(keep_result_in_memory, &delegate, exe_ctx));
+void ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap(
+    ExecutionContext &exe_ctx,
+    Materializer::PersistentVariableDelegate &delegate,
+    bool keep_result_in_memory) {
+  m_expr_decl_map_up.reset(
+      new ClangExpressionDeclMap(keep_result_in_memory, &delegate, exe_ctx));
 }
 
 clang::ASTConsumer *
-ClangUserExpression::ClangUserExpressionHelper::ASTTransformer(clang::ASTConsumer *passthrough)
-{
-    m_result_synthesizer_up.reset(new ASTResultSynthesizer(passthrough, m_top_level, m_target));
+ClangUserExpression::ClangUserExpressionHelper::ASTTransformer(
+    clang::ASTConsumer *passthrough) {
+  m_result_synthesizer_up.reset(
+      new ASTResultSynthesizer(passthrough, m_top_level, m_target));
 
-    return m_result_synthesizer_up.get();
+  return m_result_synthesizer_up.get();
 }
 
-void
-ClangUserExpression::ClangUserExpressionHelper::CommitPersistentDecls()
-{
-    if (m_result_synthesizer_up.get())
-    {
-        m_result_synthesizer_up->CommitPersistentDecls();
-    }
+void ClangUserExpression::ClangUserExpressionHelper::CommitPersistentDecls() {
+  if (m_result_synthesizer_up.get()) {
+    m_result_synthesizer_up->CommitPersistentDecls();
+  }
 }
 
-ClangUserExpression::ResultDelegate::ResultDelegate()
-{
-}
+ClangUserExpression::ResultDelegate::ResultDelegate() {}
 
-ConstString
-ClangUserExpression::ResultDelegate::GetName()
-{
-    return m_persistent_state->GetNextPersistentVariableName();
+ConstString ClangUserExpression::ResultDelegate::GetName() {
+  return m_persistent_state->GetNextPersistentVariableName();
 }
 
-void
-ClangUserExpression::ResultDelegate::DidDematerialize(lldb::ExpressionVariableSP &variable)
-{
-    m_variable = variable;
+void ClangUserExpression::ResultDelegate::DidDematerialize(
+    lldb::ExpressionVariableSP &variable) {
+  m_variable = variable;
 }
 
-void
-ClangUserExpression::ResultDelegate::RegisterPersistentState(PersistentExpressionState *persistent_state)
-{
-    m_persistent_state = persistent_state;
+void ClangUserExpression::ResultDelegate::RegisterPersistentState(
+    PersistentExpressionState *persistent_state) {
+  m_persistent_state = persistent_state;
 }
 
-lldb::ExpressionVariableSP &
-ClangUserExpression::ResultDelegate::GetVariable()
-{
-    return m_variable;
+lldb::ExpressionVariableSP &ClangUserExpression::ResultDelegate::GetVariable() {
+  return m_variable;
 }
-




More information about the lldb-commits mailing list