Skip to content

Commit 4adb81a

Browse files
committed
[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 (cherry picked from commit 5861234)
1 parent 162fe1d commit 4adb81a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lldb/include/lldb/Utility/ReproducerInstrumentation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ class Recorder {
841841

842842
bool ShouldCapture() { return m_local_boundary; }
843843

844+
/// Mark the current thread as a private thread and pretend that everything
845+
/// on this thread is behind happening behind the API boundary.
846+
static void PrivateThread() { g_global_boundary = true; }
847+
844848
private:
845849
template <typename T> friend struct replay;
846850
void UpdateBoundary() {
@@ -868,7 +872,7 @@ class Recorder {
868872
bool m_result_recorded;
869873

870874
/// Whether we're currently across the API boundary.
871-
static bool g_global_boundary;
875+
static thread_local bool g_global_boundary;
872876
};
873877

874878
/// To be used as the "Runtime ID" of a constructor. It also invokes the

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "lldb/Interpreter/CommandReturnObject.h"
3333
#include "lldb/Target/Thread.h"
3434
#include "lldb/Target/ThreadPlan.h"
35+
#include "lldb/Utility/ReproducerInstrumentation.h"
3536
#include "lldb/Utility/Timer.h"
3637
#include "llvm/ADT/STLExtras.h"
3738
#include "llvm/ADT/StringRef.h"
@@ -430,6 +431,7 @@ ScriptInterpreterPythonImpl::Locker::Locker(
430431
: ScriptInterpreterLocker(),
431432
m_teardown_session((on_leave & TearDownSession) == TearDownSession),
432433
m_python_interpreter(py_interpreter) {
434+
repro::Recorder::PrivateThread();
433435
DoAcquireLock();
434436
if ((on_entry & InitSession) == InitSession) {
435437
if (!DoInitSession(on_entry, in, out, err)) {

lldb/source/Utility/ReproducerInstrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,4 @@ llvm::Optional<InstrumentationData> &InstrumentationData::InstanceImpl() {
227227
return g_instrumentation_data;
228228
}
229229

230-
bool lldb_private::repro::Recorder::g_global_boundary;
230+
thread_local bool lldb_private::repro::Recorder::g_global_boundary = false;

0 commit comments

Comments
 (0)