Skip to content

Commit 0949330

Browse files
authored
[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.
1 parent 2818df3 commit 0949330

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lldb/examples/synthetic/libcxx.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,13 @@ def get_child_index(self, name):
694694
except:
695695
return -1
696696

697+
@staticmethod
698+
def _subscript(ptr: lldb.SBValue, idx: int, name: str) -> lldb.SBValue:
699+
"""Access a pointer value as if it was an array. Returns ptr[idx]."""
700+
deref_t = ptr.GetType().GetPointeeType()
701+
offset = idx * deref_t.GetByteSize()
702+
return ptr.CreateChildAtOffset(name, offset, deref_t)
703+
697704
def get_child_at_index(self, index):
698705
logger = lldb.formatters.Logger.Logger()
699706
logger.write("Fetching child " + str(index))
@@ -703,11 +710,8 @@ def get_child_at_index(self, index):
703710
return None
704711
try:
705712
i, j = divmod(self.start + index, self.block_size)
706-
707-
return self.first.CreateValueFromExpression(
708-
"[" + str(index) + "]",
709-
"*(*(%s + %d) + %d)" % (self.map_begin.get_expr_path(), i, j),
710-
)
713+
val = stddeque_SynthProvider._subscript(self.map_begin, i, "")
714+
return stddeque_SynthProvider._subscript(val, j, f"[{index}]")
711715
except:
712716
return None
713717

0 commit comments

Comments
 (0)