Skip to content

Commit 5861234

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
1 parent fed7565 commit 5861234

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
@@ -33,6 +33,7 @@
3333
#include "lldb/Interpreter/CommandReturnObject.h"
3434
#include "lldb/Target/Thread.h"
3535
#include "lldb/Target/ThreadPlan.h"
36+
#include "lldb/Utility/ReproducerInstrumentation.h"
3637
#include "lldb/Utility/Timer.h"
3738
#include "llvm/ADT/STLExtras.h"
3839
#include "llvm/ADT/StringRef.h"
@@ -437,6 +438,7 @@ ScriptInterpreterPythonImpl::Locker::Locker(
437438
: ScriptInterpreterLocker(),
438439
m_teardown_session((on_leave & TearDownSession) == TearDownSession),
439440
m_python_interpreter(py_interpreter) {
441+
repro::Recorder::PrivateThread();
440442
DoAcquireLock();
441443
if ((on_entry & InitSession) == InitSession) {
442444
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)