[Lldb-commits] [PATCH] D92811: [lldb] Track the API boundary using a thread_local variable.

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 7 20:45:53 PST 2020


JDevlieghere created this revision.
JDevlieghere added reviewers: friss, labath.
JDevlieghere requested review of this revision.

The reproducers currently use a static variable to track the API boundary. This is obviously incorrect when the SB API is used concurrently. While I do not plan to support that use-case (right now), I do want to avoid us crashing. As a first step, correctly track API boundaries across multiple threads.

Before this patch SB API calls made by the embedded script interpreter would be considered "behind the API boundary" and correctly ignored. After this patch, we need to tell the reproducers to ignore the scripting thread as a "private thread".


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D92811

Files:
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Utility/ReproducerInstrumentation.cpp


Index: lldb/source/Utility/ReproducerInstrumentation.cpp
===================================================================
--- lldb/source/Utility/ReproducerInstrumentation.cpp
+++ lldb/source/Utility/ReproducerInstrumentation.cpp
@@ -227,4 +227,4 @@
   return g_instrumentation_data;
 }
 
-bool lldb_private::repro::Recorder::g_global_boundary;
+thread_local bool lldb_private::repro::Recorder::g_global_boundary = false;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -437,6 +437,7 @@
     : ScriptInterpreterLocker(),
       m_teardown_session((on_leave & TearDownSession) == TearDownSession),
       m_python_interpreter(py_interpreter) {
+  repro::Recorder::PrivateThread();
   DoAcquireLock();
   if ((on_entry & InitSession) == InitSession) {
     if (!DoInitSession(on_entry, in, out, err)) {
Index: lldb/include/lldb/Utility/ReproducerInstrumentation.h
===================================================================
--- lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -841,6 +841,10 @@
 
   bool ShouldCapture() { return m_local_boundary; }
 
+  /// Mark the current thread as a private thread and pretend that everything
+  /// on this thread is behind happening behind the API boundary.
+  static void PrivateThread() { g_global_boundary = true; }
+
 private:
   template <typename T> friend struct replay;
   void UpdateBoundary() {
@@ -868,7 +872,7 @@
   bool m_result_recorded;
 
   /// Whether we're currently across the API boundary.
-  static bool g_global_boundary;
+  static thread_local bool g_global_boundary;
 };
 
 /// To be used as the "Runtime ID" of a constructor. It also invokes the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92811.310082.patch
Type: text/x-patch
Size: 1943 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201208/7dba03af/attachment.bin>


More information about the lldb-commits mailing list