Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lldb/examples/synthetic/libcxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down