Make it possible to set Exception breakpoints when the target doesn't yet
have a process, then fetch the right runtime resolver when the process is made.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@152015 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
index ebf2a09..8b80c90 100644
--- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
+++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
@@ -258,36 +258,31 @@
 static const char *exception_names[] = {"__cxa_throw", "__cxa_allocate", "__cxa_rethrow", "__cxa_catch"};
 static const int num_throw_names = 3;
 
-BreakpointSP
-ItaniumABILanguageRuntime::CreateExceptionBreakpoint (bool catch_bp, bool throw_bp, bool is_internal)
+BreakpointResolverSP
+ItaniumABILanguageRuntime::CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp)
 {
-    BreakpointSP exc_breakpt_sp;
+    BreakpointResolverSP resolver_sp;
+    
     if (catch_bp && throw_bp)
-        exc_breakpt_sp = m_process->GetTarget().CreateBreakpoint (NULL,
-                                                                  NULL,
-                                                                  exception_names,
-                                                                  sizeof (exception_names)/sizeof (char *),
-                                                                  eFunctionNameTypeBase, 
-                                                                  is_internal, 
-                                                                  eLazyBoolNo);
+        resolver_sp.reset (new BreakpointResolverName (bkpt,
+                                                       exception_names,
+                                                       sizeof (exception_names)/sizeof (char *),
+                                                       eFunctionNameTypeBase,
+                                                       eLazyBoolNo));
     else if (throw_bp)
-        exc_breakpt_sp = m_process->GetTarget().CreateBreakpoint (NULL,
-                                                                  NULL,
-                                                                  exception_names,
-                                                                  num_throw_names,
-                                                                  eFunctionNameTypeBase, 
-                                                                  is_internal, 
-                                                                  eLazyBoolNo);
+        resolver_sp.reset (new BreakpointResolverName (bkpt,
+                                                       exception_names,
+                                                       num_throw_names,
+                                                       eFunctionNameTypeBase,
+                                                       eLazyBoolNo));
     else if (catch_bp)
-        exc_breakpt_sp = m_process->GetTarget().CreateBreakpoint (NULL,
-                                                                  NULL,
-                                                                  exception_names + num_throw_names,
-                                                                  sizeof (exception_names)/sizeof (char *) - num_throw_names,
-                                                                  eFunctionNameTypeBase, 
-                                                                  is_internal, 
-                                                                  eLazyBoolNo);
+        resolver_sp.reset (new BreakpointResolverName (bkpt,
+                                                       exception_names + num_throw_names,
+                                                       sizeof (exception_names)/sizeof (char *) - num_throw_names,
+                                                       eFunctionNameTypeBase,
+                                                       eLazyBoolNo));
 
-    return exc_breakpt_sp;
+    return resolver_sp;
 }
 
 void
@@ -301,7 +296,11 @@
     const bool is_internal = true;
     
     if (!m_cxx_exception_bp_sp)
-        m_cxx_exception_bp_sp = CreateExceptionBreakpoint (catch_bp, throw_bp, is_internal);
+        m_cxx_exception_bp_sp = LanguageRuntime::CreateExceptionBreakpoint (m_process->GetTarget(),
+                                                                            GetLanguageType(),
+                                                                            catch_bp, 
+                                                                            throw_bp, 
+                                                                            is_internal);
     else
         m_cxx_exception_bp_sp->SetEnabled (true);
     
diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
index ae7fa99..5077392 100644
--- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
+++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
@@ -74,8 +74,8 @@
         ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason);
         
     protected:
-        virtual lldb::BreakpointSP
-        CreateExceptionBreakpoint (bool catch_bp, bool throw_bp, bool is_internal = false);
+        virtual lldb::BreakpointResolverSP
+        CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp);
 
     private:
         ItaniumABILanguageRuntime(Process *process) : lldb_private::CPPLanguageRuntime(process) { } // Call CreateInstance instead.
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index 8f955f9..3beab91 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -295,7 +295,11 @@
     const bool is_internal = true;
     
     if (!m_objc_exception_bp_sp)
-        m_objc_exception_bp_sp = CreateExceptionBreakpoint (catch_bp, throw_bp, is_internal);
+        m_objc_exception_bp_sp = LanguageRuntime::CreateExceptionBreakpoint (m_process->GetTarget(),
+                                                                            GetLanguageType(),
+                                                                            catch_bp, 
+                                                                            throw_bp, 
+                                                                            is_internal);
     else
         m_objc_exception_bp_sp->SetEnabled(true);
 }
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
index 7f3e8df..09dc6d1 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
@@ -104,22 +104,18 @@
     return 1;
 }
 
-BreakpointSP
-AppleObjCRuntimeV1::CreateExceptionBreakpoint (bool catch_bp, bool throw_bp, bool is_internal)
+BreakpointResolverSP
+AppleObjCRuntimeV1::CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp)
 {
-    BreakpointSP exc_breakpt_sp;
-    if (!m_process)
-        return exc_breakpt_sp;
+    BreakpointResolverSP resolver_sp;
     
-    
-    // FIXME: Only do throw for now...
-    if (throw_bp)
-        exc_breakpt_sp = m_process->GetTarget().CreateBreakpoint (NULL,
-                                                                  NULL,
-                                                                  "objc_exception_throw",
-                                                                  eFunctionNameTypeBase, 
-                                                                  is_internal);
-    return exc_breakpt_sp;
+    if (catch_bp && throw_bp)
+        resolver_sp.reset (new BreakpointResolverName (bkpt,
+                                                       "objc_exception_throw",
+                                                       eFunctionNameTypeBase,
+                                                       Breakpoint::Exact,
+                                                       eLazyBoolNo));
+    return resolver_sp;
 }
 
 struct BufStruct {
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
index 38a36f1..df8b6b4 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
@@ -91,8 +91,8 @@
     }
 
 protected:
-    virtual lldb::BreakpointSP
-    CreateExceptionBreakpoint (bool catch_bp, bool throw_bp, bool is_internal = false);
+    virtual lldb::BreakpointResolverSP
+    CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp);
             
 private:
     AppleObjCRuntimeV1(Process *process) : 
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index ff62414..2134f3b 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -444,22 +444,18 @@
     return 1;
 }
 
-BreakpointSP
-AppleObjCRuntimeV2::CreateExceptionBreakpoint (bool catch_bp, bool throw_bp, bool is_internal)
+BreakpointResolverSP
+AppleObjCRuntimeV2::CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp)
 {
-    BreakpointSP exc_breakpt_sp;
-    if (!m_process)
-        return exc_breakpt_sp;
+    BreakpointResolverSP resolver_sp;
     
-    
-    // FIXME: Only do throw for now...
-    if (throw_bp)
-        exc_breakpt_sp = m_process->GetTarget().CreateBreakpoint (NULL,
-                                                                  NULL,
-                                                                  "objc_exception_throw",
-                                                                  eFunctionNameTypeBase, 
-                                                                  is_internal);
-    return exc_breakpt_sp;
+    if (catch_bp && throw_bp)
+        resolver_sp.reset (new BreakpointResolverName (bkpt,
+                                                       "objc_exception_throw",
+                                                       eFunctionNameTypeBase,
+                                                       Breakpoint::Exact,
+                                                       eLazyBoolNo));
+    return resolver_sp;
 }
 
 ClangUtilityFunction *
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
index 47a1f40..057fa62 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -97,8 +97,8 @@
     GetSymbolVendor();
     
 protected:
-    virtual lldb::BreakpointSP
-    CreateExceptionBreakpoint (bool catch_bp, bool throw_bp, bool is_internal = false);
+    virtual lldb::BreakpointResolverSP
+    CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp);
 
 private:
     
diff --git a/source/Target/LanguageRuntime.cpp b/source/Target/LanguageRuntime.cpp
index 3b5b329..b6a9a57 100644
--- a/source/Target/LanguageRuntime.cpp
+++ b/source/Target/LanguageRuntime.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Core/PluginManager.h"
 
 using namespace lldb;
@@ -46,3 +47,118 @@
 LanguageRuntime::~LanguageRuntime()
 {
 }
+
+BreakpointSP
+LanguageRuntime::CreateExceptionBreakpoint(
+    Target &target, 
+    lldb::LanguageType language, 
+    bool catch_bp, 
+    bool throw_bp, 
+    bool is_internal)
+{
+    BreakpointSP exc_breakpt_sp;
+    BreakpointResolverSP resolver_sp(new ExceptionBreakpointResolver(NULL, language, catch_bp, throw_bp));
+    SearchFilterSP filter_sp(target.GetSearchFilterForModule(NULL));
+    
+    exc_breakpt_sp = target.CreateBreakpoint (filter_sp, resolver_sp, is_internal);
+    
+    return exc_breakpt_sp;
+}
+
+LanguageRuntime::ExceptionBreakpointResolver::ExceptionBreakpointResolver (Breakpoint *bkpt,
+                        LanguageType language,
+                        bool catch_bp,
+                        bool throw_bp) :
+    BreakpointResolver (bkpt, ExceptionResolver),
+    m_language (language),
+    m_catch_bp (catch_bp),
+    m_throw_bp (throw_bp)
+
+{
+}
+                        
+void
+LanguageRuntime::ExceptionBreakpointResolver::GetDescription (Stream *s)
+{
+    s->Printf ("Exception breakpoint (catch: %s throw: %s) using: ", 
+           m_catch_bp ? "on" : "off",
+           m_throw_bp ? "on" : "off");
+       
+    SetActualResolver();
+    if (m_actual_resolver_sp)
+    {
+        s->Printf (" using: ");
+        m_actual_resolver_sp->GetDescription (s);
+    }
+    else
+        s->Printf (".");
+}
+
+bool
+LanguageRuntime::ExceptionBreakpointResolver::SetActualResolver()
+{
+    ProcessSP process_sp = m_process_wp.lock();
+    
+    // See if our process weak pointer is still good:
+    if (!process_sp)
+    {
+        // If not, our resolver is no good, so chuck that.  Then see if we can get the 
+        // target's new process.
+        m_actual_resolver_sp.reset();
+        if (m_breakpoint)
+        {
+            Target &target = m_breakpoint->GetTarget();
+            process_sp = target.GetProcessSP();
+            if (process_sp)
+            {
+                m_process_wp = process_sp;
+                process_sp = m_process_wp.lock();
+            }
+        }
+    }
+    
+    if (process_sp)
+    {
+        if (m_actual_resolver_sp)
+            return true;
+        else
+        {
+            // If we have a process but not a resolver, set one now.
+            LanguageRuntime *runtime = process_sp->GetLanguageRuntime(m_language);
+            if (runtime)
+            {
+                m_actual_resolver_sp = runtime->CreateExceptionResolver (m_breakpoint, m_catch_bp, m_throw_bp);
+                return m_actual_resolver_sp;
+            }
+            else
+                return false;
+        }
+    }
+    else
+        return false;
+}
+
+Searcher::CallbackReturn
+LanguageRuntime::ExceptionBreakpointResolver::SearchCallback (SearchFilter &filter,
+                SymbolContext &context,
+                Address *addr,
+                bool containing)
+{
+    
+    if (!SetActualResolver())
+    {
+        return eCallbackReturnStop;
+    }
+    else
+        return m_actual_resolver_sp->SearchCallback (filter, context, addr, containing);
+}
+
+Searcher::Depth
+LanguageRuntime::ExceptionBreakpointResolver::GetDepth ()
+{
+    if (!SetActualResolver())
+        return eDepthTarget;
+    else
+        return m_actual_resolver_sp->GetDepth();
+}
+
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index 01fb974..f3b8a78 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -385,6 +385,12 @@
     return CreateBreakpoint (filter_sp, resolver_sp, internal);
 }
 
+lldb::BreakpointSP
+Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
+{
+    return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
+}
+    
 BreakpointSP
 Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
 {