[Lldb-commits] [lldb] 0949330 - [lldb] Avoid expression evaluation in the std::deque formatter (#127071)

via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 13 23:51:36 PST 2025


Author: Pavel Labath
Date: 2025-02-14T08:51:32+01:00
New Revision: 0949330669cbd179c3c6e40880b5e1027438648f

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

LOG: [lldb] Avoid expression evaluation in the std::deque formatter (#127071)

It's slower and it can fail in contexts where expression evaluation
doesn't work.

Added: 
    

Modified: 
    lldb/examples/synthetic/libcxx.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/synthetic/libcxx.py b/lldb/examples/synthetic/libcxx.py
index 7a71556e779df..5abeb3061f4f5 100644
--- a/lldb/examples/synthetic/libcxx.py
+++ b/lldb/examples/synthetic/libcxx.py
@@ -694,6 +694,13 @@ def get_child_index(self, name):
         except:
             return -1
 
+    @staticmethod
+    def _subscript(ptr: lldb.SBValue, idx: int, name: str) -> lldb.SBValue:
+        """Access a pointer value as if it was an array. Returns ptr[idx]."""
+        deref_t = ptr.GetType().GetPointeeType()
+        offset = idx * deref_t.GetByteSize()
+        return ptr.CreateChildAtOffset(name, offset, deref_t)
+
     def get_child_at_index(self, index):
         logger = lldb.formatters.Logger.Logger()
         logger.write("Fetching child " + str(index))
@@ -703,11 +710,8 @@ def get_child_at_index(self, index):
             return None
         try:
             i, j = divmod(self.start + index, self.block_size)
-
-            return self.first.CreateValueFromExpression(
-                "[" + str(index) + "]",
-                "*(*(%s + %d) + %d)" % (self.map_begin.get_expr_path(), i, j),
-            )
+            val = stddeque_SynthProvider._subscript(self.map_begin, i, "")
+            return stddeque_SynthProvider._subscript(val, j, f"[{index}]")
         except:
             return None
 


        


More information about the lldb-commits mailing list