[Lldb-commits] [lldb] [lldb] Use Policy for ProcessRunLock re-entrancy (PR #195774)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon May 18 15:53:32 PDT 2026


================
@@ -91,29 +96,65 @@ class PolicyStack {
 
   Policy Current() const;
 
-  void Push(Policy policy) { m_stack.push_back(std::move(policy)); }
-
-  void Pop() {
-    assert(!m_stack.empty() && "can't pop the base policy");
-    m_stack.pop_back();
-  }
-
   void Dump(Stream &s) const;
 
-  /// RAII guard that pushes a policy on construction and pops on destruction.
+  /// RAII guard that pops a policy on destruction.
   class Guard {
+    friend class PolicyStack;
+
   public:
-    explicit Guard(Policy policy) { Get().Push(std::move(policy)); }
-    ~Guard() { Get().Pop(); }
+    ~Guard() {
+      if (m_active)
+        Get().Pop();
----------------
JDevlieghere wrote:

If i move this guard to another thread, this will pop from the new thread, corrupting its policy stack. I think we'll need to at least store the `std::this_thread::get_id()` (in an assert build?) to prevent someone from doing that accidentally because that would be a nightmare to debug. I think that should probably live in the policy as I can't imagine a situation where it's ever safe to push and pop from a different thread with our current design.

https://github.com/llvm/llvm-project/pull/195774


More information about the lldb-commits mailing list