https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/195771

>From 53a4804a64912627bb46f9d0cbdce5362100ff11 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <[email protected]>
Date: Tue, 5 May 2026 13:01:03 -0700
Subject: [PATCH 1/2] [lldb] Add Policy infrastructure

Add a generic thread-local policy stack and a Policy
struct that describes what view of the process a thread should see
(private reality vs public illusion) and what operations it is allowed
to perform.

This is the infrastructure for replacing ad-hoc host thread identity
checks (CurrentThreadIsPrivateStateThread, IsOnThread, etc.) with a
unified, composable mechanism. No behavioral changes yet -- adoption
will follow in subsequent patches.

rdar://176223894

Signed-off-by: Med Ismail Bennani <[email protected]>
---
 lldb/include/lldb/Target/Policy.h    | 114 +++++++++++++++++++++++++
 lldb/unittests/Target/CMakeLists.txt |   1 +
 lldb/unittests/Target/PolicyTest.cpp | 122 +++++++++++++++++++++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 lldb/include/lldb/Target/Policy.h
 create mode 100644 lldb/unittests/Target/PolicyTest.cpp

diff --git a/lldb/include/lldb/Target/Policy.h 
b/lldb/include/lldb/Target/Policy.h
new file mode 100644
index 0000000000000..36084a1fc2cb7
--- /dev/null
+++ b/lldb/include/lldb/Target/Policy.h
@@ -0,0 +1,114 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_TARGET_POLICY_H
+#define LLDB_TARGET_POLICY_H
+
+#include "llvm/ADT/SmallVector.h"
+
+#include <cassert>
+
+namespace lldb_private {
+
+/// Describes what view of the process a thread should see and what
+/// operations it is allowed to perform.
+///
+/// Frame providers are a public illusion layered on top of the private
+/// reality (the unwinder stack). The private state thread manages the
+/// stop of that private reality, so the correct view for its logic IS the
+/// private reality. The public illusion is only applied once the process
+/// has settled and clients query the stopped state.
+///
+/// This struct is a pure data store -- no business logic. It is pushed
+/// onto a per-thread stack (PolicyStack) so that code
+/// can consult the current policy instead of comparing host thread
+/// identities.
+struct Policy {
+  /// What view of the process this thread sees.
+  enum class View {
+    Public,  ///< Provider-augmented frames, public state, public run lock.
+    Private, ///< Parent (unwinder) frames, private state, private run lock.
+  };
+
+  /// What operations this thread is allowed to perform.
+  /// Enforced at specific callsites, not by the policy itself.
+  struct Capabilities {
+    bool can_evaluate_expressions = true;
+    /// Whether expression evaluation may resume all threads to avoid
+    /// deadlocks (e.g. when a lock is held by another thread).
+    bool can_run_all_threads = true;
+    /// Whether the expression runner may fall back to running all threads
+    /// after a single-thread attempt times out.
+    bool can_try_all_threads = true;
+    bool can_run_breakpoint_actions = true;
+    bool can_load_frame_providers = true;
+    bool can_run_frame_recognizers = true;
+  };
+
+  View view = View::Public;
+  Capabilities capabilities;
+
+  static Policy PublicState() { return {}; }
+
+  static Policy PrivateState() {
+    Policy p;
+    p.view = View::Private;
+    p.capabilities.can_load_frame_providers = false;
+    p.capabilities.can_run_frame_recognizers = false;
+    return p;
+  }
+
+  static Policy PublicStateRunningExpression() {
+    Policy p;
+    p.capabilities.can_run_breakpoint_actions = false;
+    return p;
+  }
+};
+
+/// Per-thread policy stack.
+///
+/// The stack lives in thread_local storage. Each thread has its own stack,
+/// initialized with a default-constructed base entry that is never popped.
+/// RAII guards (Guard) push and pop policies.
+///
+/// For thread pool workers that don't inherit thread_local storage, the
+/// policy must be passed into the lambda and pushed onto the worker
+/// thread's stack when the task starts.
+class PolicyStack {
+public:
+  static PolicyStack &GetForCurrentThread() {
+    static thread_local PolicyStack s_stack;
+    return s_stack;
+  }
+
+  Policy Current() const { return m_stack.back(); }
+
+  void Push(Policy policy) { m_stack.push_back(std::move(policy)); }
+
+  void Pop() {
+    assert(!m_stack.empty() && "can't pop the last policy");
+    m_stack.pop_back();
+  }
+
+  /// RAII guard that pushes a policy on construction and pops on destruction.
+  class Guard {
+  public:
+    explicit Guard(Policy policy) { GetForCurrentThread().Push(policy); }
+    ~Guard() { GetForCurrentThread().Pop(); }
+
+    Guard(const Guard &) = delete;
+    Guard &operator=(const Guard &) = delete;
+  };
+
+private:
+  llvm::SmallVector<Policy> m_stack = {Policy{}};
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_TARGET_POLICY_H
diff --git a/lldb/unittests/Target/CMakeLists.txt 
b/lldb/unittests/Target/CMakeLists.txt
index bf08a8f015ba0..c4578e2fbfc77 100644
--- a/lldb/unittests/Target/CMakeLists.txt
+++ b/lldb/unittests/Target/CMakeLists.txt
@@ -9,6 +9,7 @@ add_lldb_unittest(TargetTests
   MemoryTagMapTest.cpp
   ModuleCacheTest.cpp
   PathMappingListTest.cpp
+  PolicyTest.cpp
   RegisterFlagsTest.cpp
   RemoteAwarePlatformTest.cpp
   ScratchTypeSystemTest.cpp
diff --git a/lldb/unittests/Target/PolicyTest.cpp 
b/lldb/unittests/Target/PolicyTest.cpp
new file mode 100644
index 0000000000000..e1291d185eb21
--- /dev/null
+++ b/lldb/unittests/Target/PolicyTest.cpp
@@ -0,0 +1,122 @@
+//===-- PolicyTest.cpp 
----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/Policy.h"
+#include "gtest/gtest.h"
+
+#include <thread>
+
+using namespace lldb_private;
+
+TEST(PolicyTest, DefaultIsPublicWithAllCapabilities) {
+  Policy p;
+  EXPECT_EQ(p.view, Policy::View::Public);
+  EXPECT_TRUE(p.capabilities.can_evaluate_expressions);
+  EXPECT_TRUE(p.capabilities.can_run_all_threads);
+  EXPECT_TRUE(p.capabilities.can_try_all_threads);
+  EXPECT_TRUE(p.capabilities.can_run_breakpoint_actions);
+  EXPECT_TRUE(p.capabilities.can_load_frame_providers);
+  EXPECT_TRUE(p.capabilities.can_run_frame_recognizers);
+}
+
+TEST(PolicyTest, PublicState) {
+  Policy p = Policy::PublicState();
+  EXPECT_EQ(p.view, Policy::View::Public);
+  EXPECT_TRUE(p.capabilities.can_evaluate_expressions);
+  EXPECT_TRUE(p.capabilities.can_run_all_threads);
+  EXPECT_TRUE(p.capabilities.can_try_all_threads);
+  EXPECT_TRUE(p.capabilities.can_run_breakpoint_actions);
+  EXPECT_TRUE(p.capabilities.can_load_frame_providers);
+  EXPECT_TRUE(p.capabilities.can_run_frame_recognizers);
+}
+
+TEST(PolicyTest, PrivateState) {
+  Policy p = Policy::PrivateState();
+  EXPECT_EQ(p.view, Policy::View::Private);
+  EXPECT_TRUE(p.capabilities.can_evaluate_expressions);
+  EXPECT_TRUE(p.capabilities.can_run_all_threads);
+  EXPECT_TRUE(p.capabilities.can_try_all_threads);
+  EXPECT_TRUE(p.capabilities.can_run_breakpoint_actions);
+  EXPECT_FALSE(p.capabilities.can_load_frame_providers);
+  EXPECT_FALSE(p.capabilities.can_run_frame_recognizers);
+}
+
+TEST(PolicyTest, PublicStateRunningExpression) {
+  Policy p = Policy::PublicStateRunningExpression();
+  EXPECT_EQ(p.view, Policy::View::Public);
+  EXPECT_TRUE(p.capabilities.can_evaluate_expressions);
+  EXPECT_TRUE(p.capabilities.can_run_all_threads);
+  EXPECT_TRUE(p.capabilities.can_try_all_threads);
+  EXPECT_FALSE(p.capabilities.can_run_breakpoint_actions);
+  EXPECT_TRUE(p.capabilities.can_load_frame_providers);
+  EXPECT_TRUE(p.capabilities.can_run_frame_recognizers);
+}
+
+TEST(PolicyTest, StackDefaultIsPublicState) {
+  PolicyStack &stack = PolicyStack::GetForCurrentThread();
+  Policy current = stack.Current();
+  EXPECT_EQ(current.view, Policy::View::Public);
+  EXPECT_TRUE(current.capabilities.can_evaluate_expressions);
+  EXPECT_TRUE(current.capabilities.can_load_frame_providers);
+}
+
+TEST(PolicyTest, StackPushPop) {
+  PolicyStack &stack = PolicyStack::GetForCurrentThread();
+
+  stack.Push(Policy::PrivateState());
+  EXPECT_EQ(stack.Current().view, Policy::View::Private);
+  EXPECT_FALSE(stack.Current().capabilities.can_load_frame_providers);
+
+  stack.Push(Policy::PublicStateRunningExpression());
+  EXPECT_EQ(stack.Current().view, Policy::View::Public);
+  EXPECT_FALSE(stack.Current().capabilities.can_run_breakpoint_actions);
+
+  stack.Pop();
+  EXPECT_EQ(stack.Current().view, Policy::View::Private);
+
+  stack.Pop();
+  EXPECT_EQ(stack.Current().view, Policy::View::Public);
+}
+
+TEST(PolicyTest, GuardRAII) {
+  PolicyStack &stack = PolicyStack::GetForCurrentThread();
+  EXPECT_EQ(stack.Current().view, Policy::View::Public);
+
+  {
+    PolicyStack::Guard guard(Policy::PrivateState());
+    EXPECT_EQ(stack.Current().view, Policy::View::Private);
+    EXPECT_FALSE(stack.Current().capabilities.can_load_frame_providers);
+
+    {
+      PolicyStack::Guard inner(Policy::PublicStateRunningExpression());
+      EXPECT_EQ(stack.Current().view, Policy::View::Public);
+      EXPECT_FALSE(stack.Current().capabilities.can_run_breakpoint_actions);
+    }
+
+    EXPECT_EQ(stack.Current().view, Policy::View::Private);
+  }
+
+  EXPECT_EQ(stack.Current().view, Policy::View::Public);
+}
+
+TEST(PolicyTest, StackIsPerThread) {
+  PolicyStack &main_stack = PolicyStack::GetForCurrentThread();
+  main_stack.Push(Policy::PrivateState());
+
+  Policy::View other_thread_view;
+  std::thread t([&other_thread_view]() {
+    PolicyStack &stack = PolicyStack::GetForCurrentThread();
+    other_thread_view = stack.Current().view;
+  });
+  t.join();
+
+  EXPECT_EQ(main_stack.Current().view, Policy::View::Private);
+  EXPECT_EQ(other_thread_view, Policy::View::Public);
+
+  main_stack.Pop();
+}

>From 67c6a8e881d0eb98657ba996ad7967e99f7dd53b Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <[email protected]>
Date: Mon, 4 May 2026 18:41:00 -0700
Subject: [PATCH 2/2] [lldb] Adopt Policy for private/public view and
 capability decisions

Push Policy::PrivateState() at all sites where the private state
thread needs to see the private reality instead of the public illusion:

  - StopInfoBreakpoint::ShouldStopSynchronous (sync callbacks, WasHit)
  - StopInfoBreakpoint::PerformAction (async callbacks, conditions)
  - StopInfoWatchpoint::ShouldStopSynchronous
  - StopInfoWatchpoint::PerformAction
  - RunThreadPlan (original PST during expression evaluation)
  - RunPrivateStateThread (override PSTs)

Consult the policy at all view decision points:

  - Process::GetState() -- private vs public state
  - Target::GetAPIMutex() -- private vs public mutex
  - PrivateStateThread::GetRunLock() -- private vs public run lock
  - Thread::GetStackFrameList() -- parent vs provider-augmented frames
  - StackFrameList::SelectMostRelevantFrame() -- skip frame recognizers
  - StopInfoBreakpoint::PerformAction() -- skip breakpoint actions

The existing host thread identity checks remain as fallbacks until
Policy is pushed for all PSTs unconditionally.

rdar://176223894

Signed-off-by: Med Ismail Bennani <[email protected]>
---
 lldb/include/lldb/Target/Process.h    | 29 +++++----------------------
 lldb/source/Target/Process.cpp        | 21 ++++++++++---------
 lldb/source/Target/StackFrameList.cpp |  5 +++++
 lldb/source/Target/StopInfo.cpp       | 21 ++++++++++++++++++-
 lldb/source/Target/Target.cpp         |  9 +++++++--
 lldb/source/Target/Thread.cpp         | 16 ++++++++-------
 6 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 67a9a883cd36c..e6669701971fc 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -41,6 +41,7 @@
 #include "lldb/Target/InstrumentationRuntime.h"
 #include "lldb/Target/Memory.h"
 #include "lldb/Target/MemoryTagManager.h"
+#include "lldb/Target/Policy.h"
 #include "lldb/Target/QueueList.h"
 #include "lldb/Target/ThreadList.h"
 #include "lldb/Target/ThreadPlanStack.h"
@@ -3334,10 +3335,12 @@ void PruneThreadPlans();
     }
 
     ProcessRunLock &GetRunLock() {
+      auto &policy = PolicyStack::GetForCurrentThread().Current();
+      if (policy.view == Policy::View::Private)
+        return m_private_run_lock;
       if (IsOnThread(Host::GetCurrentThread()))
         return m_private_run_lock;
-      else
-        return m_public_run_lock;
+      return m_public_run_lock;
     }
 
     Process &m_process;
@@ -3719,28 +3722,6 @@ class UtilityFunctionScope {
   }
 };
 
-/// RAII guard that marks the current thread as a private state thread.
-///
-/// When RunThreadPlan detects it is running on the private state thread, it
-/// spins up an override thread and reassigns m_current_private_state_thread_sp
-/// to it. The original PST continues processing events via DoOnRemoval
-/// callbacks, but CurrentThreadIsPrivateStateThread() no longer recognizes it.
-/// This guard sets a thread_local flag so that GetStackFrameList can identify
-/// the original PST and return parent frames instead of provider-augmented
-/// frames.
-struct PrivateStateThreadGuard {
-  PrivateStateThreadGuard() { g_is_private_state_thread = true; }
-  ~PrivateStateThreadGuard() { g_is_private_state_thread = false; }
-  static bool IsPrivateStateThread() { return g_is_private_state_thread; }
-
-  // Non-copyable, non-movable.
-  PrivateStateThreadGuard(const PrivateStateThreadGuard &) = delete;
-  PrivateStateThreadGuard &operator=(const PrivateStateThreadGuard &) = delete;
-
-private:
-  static thread_local bool g_is_private_state_thread;
-};
-
 } // namespace lldb_private
 
 #endif // LLDB_TARGET_PROCESS_H
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 9fa6d5b26e9de..5420a3302f87c 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -52,6 +52,7 @@
 #include "lldb/Target/MemoryRegionInfo.h"
 #include "lldb/Target/OperatingSystem.h"
 #include "lldb/Target/Platform.h"
+#include "lldb/Target/Policy.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StopInfo.h"
@@ -1277,10 +1278,14 @@ StateType Process::GetState() {
   if (!m_current_private_state_thread_sp)
     return eStateUnloaded;
 
+  auto &policy = PolicyStack::GetForCurrentThread().Current();
+  if (policy.view == Policy::View::Private)
+    return GetPrivateState();
+
   if (CurrentThreadPosesAsPrivateStateThread())
     return GetPrivateState();
-  else
-    return GetPublicState();
+
+  return GetPublicState();
 }
 
 void Process::SetPublicState(StateType new_state, bool restarted) {
@@ -4328,14 +4333,12 @@ Status Process::HaltPrivate() {
   return error;
 }
 
-thread_local bool PrivateStateThreadGuard::g_is_private_state_thread = false;
-
 thread_result_t Process::RunPrivateStateThread(bool is_override) {
   // Override PSTs exist solely to service RunThreadPlan expression evaluation.
   // They must see parent frames, not provider-augmented frames.
-  std::optional<PrivateStateThreadGuard> pst_guard;
+  std::optional<PolicyStack::Guard> policy_guard;
   if (is_override)
-    pst_guard.emplace();
+    policy_guard.emplace(Policy::PrivateState());
 
   bool control_only = true;
 
@@ -5533,9 +5536,9 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
 
     // If we spawned an override PST, mark the current (original) PST so
     // GetStackFrameList returns parent frames during event processing.
-    std::optional<PrivateStateThreadGuard> private_state_thread_guard;
+    std::optional<PolicyStack::Guard> policy_guard;
     if (backup_private_state_thread)
-      private_state_thread_guard.emplace();
+      policy_guard.emplace(Policy::PrivateState());
 
     while (true) {
       // We usually want to resume the process if we get to the top of the
@@ -5937,7 +5940,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
       }
     } // END WAIT LOOP
 
-    private_state_thread_guard.reset();
+    policy_guard.reset();
 
     // If we had to start up a temporary private state thread to run this
     // thread plan, shut it down now.
diff --git a/lldb/source/Target/StackFrameList.cpp 
b/lldb/source/Target/StackFrameList.cpp
index 5423785c2fd51..d8558c78262d8 100644
--- a/lldb/source/Target/StackFrameList.cpp
+++ b/lldb/source/Target/StackFrameList.cpp
@@ -15,6 +15,7 @@
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/Policy.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StackFrame.h"
@@ -806,6 +807,10 @@ void StackFrameList::SelectMostRelevantFrame() {
   // Don't call into the frame recognizers on the private state thread as
   // they can cause code to run in the target, and that can cause deadlocks
   // when fetching stop events for the expression.
+  auto &policy = PolicyStack::GetForCurrentThread().Current();
+  if (policy.view == Policy::View::Private)
+    return;
+
   if (m_thread.GetProcess()->CurrentThreadPosesAsPrivateStateThread())
     return;
 
diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
index 2a7ea2808d87f..88f81832c18c5 100644
--- a/lldb/source/Target/StopInfo.cpp
+++ b/lldb/source/Target/StopInfo.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Core/Debugger.h"
 #include "lldb/Expression/UserExpression.h"
 #include "lldb/Symbol/Block.h"
+#include "lldb/Target/Policy.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/Target.h"
@@ -153,6 +154,10 @@ class StopInfoBreakpoint : public StopInfo {
   StopReason GetStopReason() const override { return eStopReasonBreakpoint; }
 
   bool ShouldStopSynchronous(Event *event_ptr) override {
+    // Breakpoint callbacks run on the PST during stop processing. Push
+    // private state context so callback code sees the private reality.
+    PolicyStack::Guard policy_guard(Policy::PrivateState());
+
     ThreadSP thread_sp(m_thread_wp.lock());
     if (thread_sp) {
       if (!m_should_stop_is_valid) {
@@ -322,6 +327,10 @@ class StopInfoBreakpoint : public StopInfo {
     m_should_perform_action = false;
     bool all_stopping_locs_internal = true;
 
+    // Breakpoint callbacks run on the PST during stop processing. Push
+    // private state context so callback code sees the private reality.
+    PolicyStack::Guard policy_guard(Policy::PrivateState());
+
     ThreadSP thread_sp(m_thread_wp.lock());
 
     if (thread_sp) {
@@ -393,7 +402,9 @@ class StopInfoBreakpoint : public StopInfo {
 
           ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
           Process *process = exe_ctx.GetProcessPtr();
-          if (process->GetModIDRef().IsRunningExpression()) {
+          auto &policy = PolicyStack::GetForCurrentThread().Current();
+          if (!policy.capabilities.can_run_breakpoint_actions ||
+              process->GetModIDRef().IsRunningExpression()) {
             // If we are in the middle of evaluating an expression, don't run
             // asynchronous breakpoint commands or expressions.  That could
             // lead to infinite recursion if the command or condition re-calls
@@ -857,6 +868,10 @@ class StopInfoWatchpoint : public StopInfo {
   };
 
   bool ShouldStopSynchronous(Event *event_ptr) override {
+    // Watchpoint callbacks run on the PST during stop processing. Push
+    // private state context so callback code sees the private reality.
+    PolicyStack::Guard policy_guard(Policy::PrivateState());
+
     // If we are running our step-over the watchpoint plan, stop if it's done
     // and continue if it's not:
     if (m_should_stop_is_valid)
@@ -964,6 +979,10 @@ class StopInfoWatchpoint : public StopInfo {
   }
 
   void PerformAction(Event *event_ptr) override {
+    // Watchpoint callbacks run on the PST during stop processing. Push
+    // private state context so callback code sees the private reality.
+    PolicyStack::Guard policy_guard(Policy::PrivateState());
+
     Log *log = GetLog(LLDBLog::Watchpoints);
     // We're going to calculate if we should stop or not in some way during the
     // course of this code.  Also by default we're going to stop, so set that
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index d7611f470b9b6..b9441e9e6ed20 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -51,6 +51,7 @@
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/Policy.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterTypeBuilder.h"
 #include "lldb/Target/SectionLoadList.h"
@@ -5889,10 +5890,14 @@ Target::TargetEventData::GetModuleListFromEvent(const 
Event *event_ptr) {
 }
 
 std::recursive_mutex &Target::GetAPIMutex() {
+  auto &policy = PolicyStack::GetForCurrentThread().Current();
+  if (policy.view == Policy::View::Private)
+    return m_private_mutex;
+
   if (GetProcessSP() && GetProcessSP()->CurrentThreadIsPrivateStateThread())
     return m_private_mutex;
-  else
-    return m_mutex;
+
+  return m_mutex;
 }
 
 /// Get metrics associated with this target in JSON format.
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index 70053b8822bdc..b37c5c9313ef2 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -24,6 +24,7 @@
 #include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/Policy.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/ScriptedThreadPlan.h"
@@ -1533,7 +1534,7 @@ StackFrameListSP Thread::GetStackFrameList() {
   //       thread that is already mid-construction.
   //
   //  2. Current thread is a private state thread that should see the
-  //     private reality (PrivateStateThreadGuard::IsPrivateStateThread).
+  //     private reality (Policy::View::Private).
   //
   // For case 1, if a provider is active we return its input (parent)
   // frames. For case (2), we return/create the unwinder frame list
@@ -1559,12 +1560,13 @@ StackFrameListSP Thread::GetStackFrameList() {
     return m_curr_frames_sp;
 
   // For case 2, PST must see the private reality, not the public illusion.
-  // PrivateStateThreadGuard is a thread_local flag set by RunThreadPlan
-  // (for the original PST) and RunPrivateStateThread (for override PSTs).
-  // We cannot use CurrentThreadIsPrivateStateThread() here because
-  // RunThreadPlan reassigns m_current_private_state_thread_sp to the
-  // override, so the original PST is no longer recognized.
-  if (PrivateStateThreadGuard::IsPrivateStateThread()) {
+  // Policy is pushed by RunThreadPlan (for the original PST)
+  // and RunPrivateStateThread (for override PSTs). We cannot use
+  // CurrentThreadIsPrivateStateThread() here because RunThreadPlan reassigns
+  // m_current_private_state_thread_sp to the override, so the original PST
+  // is no longer recognized.
+  auto &policy = PolicyStack::GetForCurrentThread().Current();
+  if (policy.view == Policy::View::Private) {
     if (!m_unwinder_frames_sp)
       m_unwinder_frames_sp = std::make_shared<StackFrameList>(
           *this, m_prev_frames_sp, true, /*provider_id=*/0);

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to