kubamracek created this revision.
kubamracek added a project: Sanitizers.

We can provide this via StopReason->GetValue().  This is important so that 
users of SB API can treat various sanitizers differently (the extended stop 
reason data is also structured differently for different sanitizers).


https://reviews.llvm.org/D30007

Files:
  include/lldb/API/SBThread.h
  include/lldb/API/SBThreadPlan.h
  include/lldb/Target/InstrumentationRuntimeStopInfo.h
  include/lldb/Target/StopInfo.h
  packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py
  packages/Python/lldbsuite/test/functionalities/asan/TestReportData.py
  packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
  scripts/interface/SBThread.i
  scripts/interface/SBThreadPlan.i
  source/API/SBThread.cpp
  
source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
  
source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
  source/Target/InstrumentationRuntimeStopInfo.cpp

Index: source/Target/InstrumentationRuntimeStopInfo.cpp
===================================================================
--- source/Target/InstrumentationRuntimeStopInfo.cpp
+++ source/Target/InstrumentationRuntimeStopInfo.cpp
@@ -17,9 +17,9 @@
 using namespace lldb_private;
 
 InstrumentationRuntimeStopInfo::InstrumentationRuntimeStopInfo(
-    Thread &thread, std::string description,
+    Thread &thread, InstrumentationRuntimeType type, std::string description,
     StructuredData::ObjectSP additional_data)
-    : StopInfo(thread, 0) {
+    : StopInfo(thread, type) {
   m_extended_info = additional_data;
   m_description = description;
 }
@@ -30,8 +30,8 @@
 
 StopInfoSP
 InstrumentationRuntimeStopInfo::CreateStopReasonWithInstrumentationData(
-    Thread &thread, std::string description,
+    Thread &thread, InstrumentationRuntimeType type, std::string description,
     StructuredData::ObjectSP additionalData) {
   return StopInfoSP(
-      new InstrumentationRuntimeStopInfo(thread, description, additionalData));
+      new InstrumentationRuntimeStopInfo(thread, type, description, additionalData));
 }
Index: source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
===================================================================
--- source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
+++ source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
@@ -818,7 +818,8 @@
       thread_sp->SetStopInfo(
           InstrumentationRuntimeStopInfo::
               CreateStopReasonWithInstrumentationData(
-                  *thread_sp, stop_reason_description, report));
+                  *thread_sp, eInstrumentationRuntimeTypeThreadSanitizer,
+                  stop_reason_description, report));
 
     StreamFileSP stream_sp(
         process_sp->GetTarget().GetDebugger().GetOutputFile());
Index: source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
===================================================================
--- source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
+++ source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
@@ -257,9 +257,11 @@
   if (process_sp && process_sp == context->exe_ctx_ref.GetProcessSP()) {
     ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP();
     if (thread_sp)
-      thread_sp->SetStopInfo(InstrumentationRuntimeStopInfo::
-                                 CreateStopReasonWithInstrumentationData(
-                                     *thread_sp, description, report));
+      thread_sp->SetStopInfo(
+          InstrumentationRuntimeStopInfo::
+              CreateStopReasonWithInstrumentationData(
+                  *thread_sp, eInstrumentationRuntimeTypeAddressSanitizer,
+                  description, report));
 
     StreamFileSP stream_sp(
         process_sp->GetTarget().GetDebugger().GetOutputFile());
Index: source/API/SBThread.cpp
===================================================================
--- source/API/SBThread.cpp
+++ source/API/SBThread.cpp
@@ -167,7 +167,6 @@
         case eStopReasonExec:
         case eStopReasonPlanComplete:
         case eStopReasonThreadExiting:
-        case eStopReasonInstrumentation:
           // There is no data for these stop reasons.
           return 0;
 
@@ -190,6 +189,9 @@
 
         case eStopReasonException:
           return 1;
+
+        case eStopReasonInstrumentation:
+          return 1;
         }
       }
     } else {
@@ -221,7 +223,6 @@
         case eStopReasonExec:
         case eStopReasonPlanComplete:
         case eStopReasonThreadExiting:
-        case eStopReasonInstrumentation:
           // There is no data for these stop reasons.
           return 0;
 
@@ -255,6 +256,9 @@
 
         case eStopReasonException:
           return stop_info_sp->GetValue();
+
+        case eStopReasonInstrumentation:
+          return stop_info_sp->GetValue();
         }
       }
     } else {
Index: scripts/interface/SBThreadPlan.i
===================================================================
--- scripts/interface/SBThreadPlan.i
+++ scripts/interface/SBThreadPlan.i
@@ -59,16 +59,17 @@
     /// breakpoint IDs followed by the breakpoint location IDs (they always come
     /// in pairs).
     ///
-    /// Stop Reason              Count Data Type
-    /// ======================== ===== =========================================
-    /// eStopReasonNone          0
-    /// eStopReasonTrace         0
-    /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
-    /// eStopReasonWatchpoint    1     watchpoint id
-    /// eStopReasonSignal        1     unix signal number
-    /// eStopReasonException     N     exception data
-    /// eStopReasonExec          0
-    /// eStopReasonPlanComplete  0
+    /// Stop Reason                Count Data Type
+    /// ========================== ===== =======================================
+    /// eStopReasonNone            0
+    /// eStopReasonTrace           0
+    /// eStopReasonBreakpoint      N     duple: {breakpoint id, location id}
+    /// eStopReasonWatchpoint      1     watchpoint id
+    /// eStopReasonSignal          1     unix signal number
+    /// eStopReasonException       N     exception data
+    /// eStopReasonExec            0
+    /// eStopReasonPlanComplete    0
+    /// eStopReasonInstrumentation 1     InstrumentationRuntimeType value
     //--------------------------------------------------------------------------
     uint64_t
     GetStopReasonDataAtIndex(uint32_t idx);
Index: scripts/interface/SBThread.i
===================================================================
--- scripts/interface/SBThread.i
+++ scripts/interface/SBThread.i
@@ -96,16 +96,17 @@
     /// breakpoint IDs followed by the breakpoint location IDs (they always come
     /// in pairs).
     ///
-    /// Stop Reason              Count Data Type
-    /// ======================== ===== =========================================
-    /// eStopReasonNone          0
-    /// eStopReasonTrace         0
-    /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
-    /// eStopReasonWatchpoint    1     watchpoint id
-    /// eStopReasonSignal        1     unix signal number
-    /// eStopReasonException     N     exception data
-    /// eStopReasonExec          0
-    /// eStopReasonPlanComplete  0
+    /// Stop Reason                Count Data Type
+    /// ========================== ===== =======================================
+    /// eStopReasonNone            0
+    /// eStopReasonTrace           0
+    /// eStopReasonBreakpoint      N     duple: {breakpoint id, location id}
+    /// eStopReasonWatchpoint      1     watchpoint id
+    /// eStopReasonSignal          1     unix signal number
+    /// eStopReasonException       N     exception data
+    /// eStopReasonExec            0
+    /// eStopReasonPlanComplete    0
+    /// eStopReasonInstrumentation 1     InstrumentationRuntimeType value
     //--------------------------------------------------------------------------
     ") GetStopReasonDataAtIndex;
     uint64_t
Index: packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
+++ packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
@@ -50,18 +50,21 @@
         self.expect("thread list", "A data race should be detected",
                     substrs=['stopped', 'stop reason = Data race detected'])
 
+        process = self.dbg.GetSelectedTarget().process
         self.assertEqual(
-            self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason(),
+            process.GetSelectedThread().GetStopReason(),
             lldb.eStopReasonInstrumentation)
+        self.assertEqual(
+            process.GetSelectedThread().GetStopReasonDataAtIndex(0),
+            lldb.eInstrumentationRuntimeTypeThreadSanitizer)
 
         # test that the TSan dylib is present
         self.expect(
             "image lookup -n __tsan_get_current_report",
             "__tsan_get_current_report should be present",
             substrs=['1 match found'])
 
         # We should be stopped in __tsan_on_report
-        process = self.dbg.GetSelectedTarget().process
         thread = process.GetSelectedThread()
         frame = thread.GetSelectedFrame()
         self.assertTrue("__tsan_on_report" in frame.GetFunctionName())
Index: packages/Python/lldbsuite/test/functionalities/asan/TestReportData.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/asan/TestReportData.py
+++ packages/Python/lldbsuite/test/functionalities/asan/TestReportData.py
@@ -58,9 +58,13 @@
                 'stopped',
                 'stop reason = Use of deallocated memory'])
 
+        process = self.dbg.GetSelectedTarget().process
         self.assertEqual(
-            self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason(),
+            process.GetSelectedThread().GetStopReason(),
             lldb.eStopReasonInstrumentation)
+        self.assertEqual(process.
+            GetSelectedThread().GetStopReasonDataAtIndex(0),
+            lldb.eInstrumentationRuntimeTypeAddressSanitizer)
 
         self.expect("bt", "The backtrace should show the crashing line",
                     substrs=['main.c:%d' % self.line_crash])
Index: packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py
+++ packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py
@@ -123,6 +123,13 @@
                 'stopped',
                 'stop reason = Use of deallocated memory'])
 
+        self.assertEqual(
+            process.GetSelectedThread().GetStopReason(),
+            lldb.eStopReasonInstrumentation)
+        self.assertEqual(
+            process.GetSelectedThread().GetStopReasonDataAtIndex(0),
+            lldb.eInstrumentationRuntimeTypeAddressSanitizer)
+
         # make sure the 'memory history' command still works even when we're
         # generating a report now
         self.expect(
Index: include/lldb/Target/StopInfo.h
===================================================================
--- include/lldb/Target/StopInfo.h
+++ include/lldb/Target/StopInfo.h
@@ -47,6 +47,7 @@
   // eStopReasonSignal           Signal number
   // eStopReasonWatchpoint       WatchpointLocationID
   // eStopReasonPlanComplete     No significance
+  // eStopReasonInstrumentation  InstrumentationRuntimeType value
 
   uint64_t GetValue() const { return m_value; }
 
Index: include/lldb/Target/InstrumentationRuntimeStopInfo.h
===================================================================
--- include/lldb/Target/InstrumentationRuntimeStopInfo.h
+++ include/lldb/Target/InstrumentationRuntimeStopInfo.h
@@ -34,11 +34,13 @@
   bool DoShouldNotify(Event *event_ptr) override { return true; }
 
   static lldb::StopInfoSP CreateStopReasonWithInstrumentationData(
-      Thread &thread, std::string description,
-      StructuredData::ObjectSP additional_data);
+      Thread &thread, lldb::InstrumentationRuntimeType type,
+      std::string description, StructuredData::ObjectSP additional_data);
 
 private:
-  InstrumentationRuntimeStopInfo(Thread &thread, std::string description,
+  InstrumentationRuntimeStopInfo(Thread &thread,
+                                 lldb::InstrumentationRuntimeType type,
+                                 std::string description,
                                  StructuredData::ObjectSP additional_data);
 };
 
Index: include/lldb/API/SBThreadPlan.h
===================================================================
--- include/lldb/API/SBThreadPlan.h
+++ include/lldb/API/SBThreadPlan.h
@@ -48,16 +48,17 @@
   /// breakpoint IDs followed by the breakpoint location IDs (they always come
   /// in pairs).
   ///
-  /// Stop Reason              Count Data Type
-  /// ======================== ===== =========================================
-  /// eStopReasonNone          0
-  /// eStopReasonTrace         0
-  /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
-  /// eStopReasonWatchpoint    1     watchpoint id
-  /// eStopReasonSignal        1     unix signal number
-  /// eStopReasonException     N     exception data
-  /// eStopReasonExec          0
-  /// eStopReasonPlanComplete  0
+  /// Stop Reason                Count Data Type
+  /// ========================== ===== =======================================
+  /// eStopReasonNone            0
+  /// eStopReasonTrace           0
+  /// eStopReasonBreakpoint      N     duple: {breakpoint id, location id}
+  /// eStopReasonWatchpoint      1     watchpoint id
+  /// eStopReasonSignal          1     unix signal number
+  /// eStopReasonException       N     exception data
+  /// eStopReasonExec            0
+  /// eStopReasonPlanComplete    0
+  /// eStopReasonInstrumentation 1     InstrumentationRuntimeType value
   //--------------------------------------------------------------------------
   uint64_t GetStopReasonDataAtIndex(uint32_t idx);
 
Index: include/lldb/API/SBThread.h
===================================================================
--- include/lldb/API/SBThread.h
+++ include/lldb/API/SBThread.h
@@ -57,16 +57,17 @@
   /// breakpoint IDs followed by the breakpoint location IDs (they always come
   /// in pairs).
   ///
-  /// Stop Reason              Count Data Type
-  /// ======================== ===== =========================================
-  /// eStopReasonNone          0
-  /// eStopReasonTrace         0
-  /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
-  /// eStopReasonWatchpoint    1     watchpoint id
-  /// eStopReasonSignal        1     unix signal number
-  /// eStopReasonException     N     exception data
-  /// eStopReasonExec          0
-  /// eStopReasonPlanComplete  0
+  /// Stop Reason                Count Data Type
+  /// ========================== ===== =======================================
+  /// eStopReasonNone            0
+  /// eStopReasonTrace           0
+  /// eStopReasonBreakpoint      N     duple: {breakpoint id, location id}
+  /// eStopReasonWatchpoint      1     watchpoint id
+  /// eStopReasonSignal          1     unix signal number
+  /// eStopReasonException       N     exception data
+  /// eStopReasonExec            0
+  /// eStopReasonPlanComplete    0
+  /// eStopReasonInstrumentation 1     InstrumentationRuntimeType value
   //--------------------------------------------------------------------------
   uint64_t GetStopReasonDataAtIndex(uint32_t idx);
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to