Destroy the dynamic loader plugin in Process::Finalize.  If you wait till the auto_ptr gets deleted in the normal course of things the real process class will have been destroyed already, and it's hard to shut down the dynamic loader without accessing some process pure virtual method.  

git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@125668 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index fb6614d..8968c75 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -279,6 +279,11 @@
 {
     // Do any cleanup needed prior to being destructed... Subclasses
     // that override this method should call this superclass method as well.
+    
+    // We need to destroy the loader before the derived Process class gets destroyed
+    // since it is very likely that undoing the loader will require access to the real process.
+    if (m_dyld_ap.get() != NULL)
+        m_dyld_ap.reset();
 }
 
 void
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index b76f9f6..175aa7d 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -98,8 +98,8 @@
         m_section_load_list.Clear();
         if (m_process_sp->IsAlive())
             m_process_sp->Destroy();
-        else
-            m_process_sp->Finalize();
+        
+        m_process_sp->Finalize();
 
         // Do any cleanup of the target we need to do between process instances.
         // NB It is better to do this before destroying the process in case the