Author: Nerixyz
Date: 2026-07-31T15:08:03+02:00
New Revision: f5ffd86a9bd6dd9327669448c3b604ce9b658941

URL: 
https://github.com/llvm/llvm-project/commit/f5ffd86a9bd6dd9327669448c3b604ce9b658941
DIFF: 
https://github.com/llvm/llvm-project/commit/f5ffd86a9bd6dd9327669448c3b604ce9b658941.diff

LOG: [lldb] Treat synthetic variables as always in scope (#204177)

When the variables in scope are requested, synthetic variables wouldn't
be returned, because `Variable::IsInScope` would return false. With this
PR, we return true for synthetic variables.

There's still one inconsistency between `frame var` and
`SBFrame::GetVariables` where `frame var` shows "re-exported" variables
from real frames (here: `variable_in_main`). Note that
`IsSyntheticValueType` returns false for `variable_in_main`.

Added: 
    

Modified: 
    lldb/source/Symbol/Variable.cpp
    
lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 70a61fc7789c9..1d623da23c3c9 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -31,6 +31,7 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
+#include "lldb/Utility/ValueType.h"
 #include "lldb/ValueObject/ValueObject.h"
 #include "lldb/ValueObject/ValueObjectVariable.h"
 
@@ -279,6 +280,10 @@ bool Variable::LocationIsValidForAddress(const Address 
&address) {
 }
 
 bool Variable::IsInScope(StackFrame *frame) {
+  // Synthetic values are always in scope.
+  if (IsSyntheticValueType(m_scope))
+    return true;
+
   switch (m_scope) {
   case eValueTypeRegister:
   case eValueTypeRegisterSet:

diff  --git 
a/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py
 
b/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py
index ddd9b68a632bb..58eae50a4d76f 100644
--- 
a/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py
+++ 
b/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py
@@ -855,13 +855,15 @@ def test_get_values(self):
         self.assertEqual(variables.GetValueAtIndex(0).name, "variable_in_main")
         self.assertEqual(variables.GetValueAtIndex(1).name, "_handler_one")
 
-        # FIXME: Synthetic variables are never in scope.
+        # Synthetic variables are always in scope.
         variables = frame0.GetVariables(False, False, False, True)
         self.assertFalse(variables.IsValid())
         self.assertEqual(variables.GetSize(), 0)
         variables = frame0.GetVariables(False, True, False, True)
-        self.assertFalse(variables.IsValid())
-        self.assertEqual(variables.GetSize(), 0)
+        self.assertTrue(variables.IsValid())
+        # We don't see `variable_in_main` here, because it doesn't have the 
synthetic flag.
+        self.assertEqual(variables.GetSize(), 1)
+        self.assertEqual(variables.GetValueAtIndex(0).name, "_handler_one")
 
         # Check the `frame variable` command(s) handle synthetic variables the
         # way we expect by printing them.


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

Reply via email to