[Lldb-commits] [lldb] r360741 - [Target] Generalize some behavior in Thread

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Tue May 14 18:46:45 PDT 2019


Author: xiaobai
Date: Tue May 14 18:46:45 2019
New Revision: 360741

URL: http://llvm.org/viewvc/llvm-project?rev=360741&view=rev
Log:
[Target] Generalize some behavior in Thread

Summary:
I don't think there's a good reason for this behavior to be considered
ObjC-specific. We can generalize this.

Differential Revision: https://reviews.llvm.org/D61776

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
    lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
    lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py?rev=360741&r1=360740&r2=360741&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py Tue May 14 18:46:45 2019
@@ -196,11 +196,12 @@ class ObjCExceptionsTestCase(TestBase):
         self.expect("thread list",
             substrs=['stopped', 'stop reason = signal SIGABRT'])
 
-        self.expect('thread exception', substrs=[])
+        self.expect('thread exception', substrs=['exception ='])
 
         process = self.dbg.GetSelectedTarget().process
         thread = process.GetSelectedThread()
 
-        # C++ exceptions are not exposed in the API (yet).
-        self.assertFalse(thread.GetCurrentException().IsValid())
+        self.assertTrue(thread.GetCurrentException().IsValid())
+
+        # C++ exception backtraces are not exposed in the API (yet).
         self.assertFalse(thread.GetCurrentExceptionBacktrace().IsValid())

Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=360741&r1=360740&r2=360741&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp Tue May 14 18:46:45 2019
@@ -594,6 +594,10 @@ ValueObjectSP ItaniumABILanguageRuntime:
   addr_t exception_addr =
       m_process->ReadPointerFromMemory(result_ptr - ptr_size, error);
 
+  if (!error.Success()) {
+    return ValueObjectSP();
+  }
+
   lldb_private::formatters::InferiorSizedWord exception_isw(exception_addr,
                                                             *m_process);
   ValueObjectSP exception = ValueObject::CreateValueObjectFromData(

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=360741&r1=360740&r2=360741&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Tue May 14 18:46:45 2019
@@ -2209,25 +2209,31 @@ ValueObjectSP Thread::GetCurrentExceptio
       if (auto e = recognized_frame->GetExceptionObject())
         return e;
 
-  // FIXME: For now, only ObjC exceptions are supported. This should really
-  // iterate over all language runtimes and ask them all to give us the current
-  // exception.
-  if (auto runtime = GetProcess()->GetObjCLanguageRuntime())
-    if (auto e = runtime->GetExceptionObjectForThread(shared_from_this()))
-      return e;
+  // NOTE: Even though this behavior is generalized, only ObjC is actually
+  // supported at the moment.
+  for (unsigned lang = eLanguageTypeUnknown; lang < eNumLanguageTypes; lang++) {
+    if (auto runtime = GetProcess()->GetLanguageRuntime(
+            static_cast<lldb::LanguageType>(lang)))
+      if (auto e = runtime->GetExceptionObjectForThread(shared_from_this()))
+        return e;
+  }
 
   return ValueObjectSP();
 }
 
 ThreadSP Thread::GetCurrentExceptionBacktrace() {
   ValueObjectSP exception = GetCurrentException();
-  if (!exception) return ThreadSP();
+  if (!exception)
+    return ThreadSP();
 
-  // FIXME: For now, only ObjC exceptions are supported. This should really
-  // iterate over all language runtimes and ask them all to give us the current
-  // exception.
-  auto runtime = GetProcess()->GetObjCLanguageRuntime();
-  if (!runtime) return ThreadSP();
+  // NOTE: Even though this behavior is generalized, only ObjC is actually
+  // supported at the moment.
+  for (unsigned lang = eLanguageTypeUnknown; lang < eNumLanguageTypes; lang++) {
+    if (auto runtime = GetProcess()->GetLanguageRuntime(
+            static_cast<lldb::LanguageType>(lang)))
+      if (auto bt = runtime->GetBacktraceThreadFromException(exception))
+        return bt;
+  }
 
-  return runtime->GetBacktraceThreadFromException(exception);
+  return ThreadSP();
 }




More information about the lldb-commits mailing list