Skip to content

[llvm][utils] Add synthetic provider for llvm::DenseSet #143631

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
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
29 changes: 28 additions & 1 deletion llvm/utils/lldbDataFormatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
"""

from __future__ import annotations

import collections
Expand Down Expand Up @@ -82,6 +83,11 @@ def __lldb_init_module(debugger, internal_dict):
f"-l {__name__}.DenseMapSynthetic "
'-x "^llvm::DenseMap<.+>$"'
)
debugger.HandleCommand(
"type synthetic add -w llvm "
f"-l {__name__}.DenseSetSynthetic "
'-x "^llvm::DenseSet<.+>$"'
)

debugger.HandleCommand(
"type synthetic add -w llvm "
Expand Down Expand Up @@ -372,7 +378,8 @@ def update(self):
# For each key, collect a list of buckets it appears in.
key_buckets: dict[str, list[int]] = collections.defaultdict(list)
for index in range(num_buckets):
key = buckets.GetValueForExpressionPath(f"[{index}].first")
bucket = buckets.GetValueForExpressionPath(f"[{index}]")
key = bucket.GetChildAtIndex(0)
Comment on lines -375 to +382
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is because the entries of a DenseSet are DenseSetPair, which is not actually a pair. There's only one child, and its name is key. The original code works for DenseMapPair, which has two children, first and second. Using GetChildAtIndex(0) will retrieve first for maps, and key for sets.

key_buckets[str(key.data)].append(index)

# Heuristic: This is not a multi-map, any repeated (non-unique) keys are
Expand All @@ -383,6 +390,26 @@ def update(self):
self.child_buckets.append(indexes[0])


class DenseSetSynthetic:
valobj: lldb.SBValue
map: lldb.SBValue

def __init__(self, valobj: lldb.SBValue, _) -> None:
self.valobj = valobj

def num_children(self) -> int:
return self.map.num_children

def get_child_at_index(self, idx: int) -> lldb.SBValue:
map_entry = self.map.child[idx]
set_entry = map_entry.GetChildAtIndex(0)
return set_entry.Clone(f"[{idx}]")

def update(self):
raw_map = self.valobj.GetChildMemberWithName("TheMap")
self.map = raw_map.GetSyntheticValue()


class ExpectedSynthetic:
# The llvm::Expected<T> value.
expected: lldb.SBValue
Expand Down
Loading