[llvm-branch-commits] [lldb] 5861234 - [lldb] Track the API boundary using a thread_local variable.
Jonas Devlieghere via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 9 09:02:52 PST 2020
Author: Jonas Devlieghere
Date: 2020-12-09T08:58:40-08:00
New Revision: 5861234e72c035ad39b5fd843eef78ab4039351e
URL: https://github.com/llvm/llvm-project/commit/5861234e72c035ad39b5fd843eef78ab4039351e
DIFF: https://github.com/llvm/llvm-project/commit/5861234e72c035ad39b5fd843eef78ab4039351e.diff
LOG: [lldb] Track the API boundary using a thread_local variable.
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".
Differential revision: https://reviews.llvm.org/D92811
Added:
Modified:
lldb/include/lldb/Utility/ReproducerInstrumentation.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/source/Utility/ReproducerInstrumentation.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Utility/ReproducerInstrumentation.h b/lldb/include/lldb/Utility/ReproducerInstrumentation.h
index 8e319d749231..e4c31522c4fc 100644
--- a/lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ b/lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -841,6 +841,10 @@ class Recorder {
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 @@ class Recorder {
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
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 0d13884e8089..5f950d42cac6 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -33,6 +33,7 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/ReproducerInstrumentation.h"
#include "lldb/Utility/Timer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
@@ -437,6 +438,7 @@ ScriptInterpreterPythonImpl::Locker::Locker(
: 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)) {
diff --git a/lldb/source/Utility/ReproducerInstrumentation.cpp b/lldb/source/Utility/ReproducerInstrumentation.cpp
index 09aea69d8313..626120c9d71a 100644
--- a/lldb/source/Utility/ReproducerInstrumentation.cpp
+++ b/lldb/source/Utility/ReproducerInstrumentation.cpp
@@ -227,4 +227,4 @@ llvm::Optional<InstrumentationData> &InstrumentationData::InstanceImpl() {
return g_instrumentation_data;
}
-bool lldb_private::repro::Recorder::g_global_boundary;
+thread_local bool lldb_private::repro::Recorder::g_global_boundary = false;
More information about the llvm-branch-commits
mailing list