[Lldb-commits] [lldb] [lldb] Avoid expression evaluation in the std::deque formatter (PR #127071)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 13 07:14:04 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
It's slower and it can fail in contexts where expression evaluation doesn't work.
---
Full diff: https://github.com/llvm/llvm-project/pull/127071.diff
1 Files Affected:
- (modified) lldb/examples/synthetic/libcxx.py (+9-5)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/127071
More information about the lldb-commits
mailing list