Skip to content

Commit

Permalink
Merge #7059
Browse files Browse the repository at this point in the history
7059: Update HashMap/HashSet pretty-printers to Rust 1.52 r=Undin a=ortem

The corresponding PRs in rustc:
rust-lang/rust#77566
rust-lang/rust#83920

Fixes #7045

changelog: Update LLDB/GDB pretty-printers to render `HashMap`/`HashSet` on Rust 1.52 or higher

Co-authored-by: ortem <ortem00@gmail.com>
  • Loading branch information
bors[bot] and artemmukhin authored Apr 6, 2021
2 parents 2d80f50 + e78fbe5 commit 949953d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
16 changes: 11 additions & 5 deletions prettyPrinters/gdb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,23 @@ def __init__(self, valobj, show_values=True):
self.show_values = show_values

table = self.table()
capacity = int(table["bucket_mask"]) + 1
ctrl = table["ctrl"]["pointer"]
# BACKCOMPAT: rust 1.51. Just drop `else` branch
if table.type.fields()[0].name == "table":
inner_table = table["table"]
else:
inner_table = table

capacity = int(inner_table["bucket_mask"]) + 1
ctrl = inner_table["ctrl"]["pointer"]

self.size = int(table["items"])
self.size = int(inner_table["items"])
self.pair_type = table.type.template_argument(0).strip_typedefs()

self.new_layout = "data" not in table.type
self.new_layout = "data" not in inner_table.type
if self.new_layout:
self.data_ptr = ctrl.cast(self.pair_type.pointer())
else:
self.data_ptr = table["data"]["pointer"]
self.data_ptr = inner_table["data"]["pointer"]

self.valid_indices = []
for idx in range(capacity):
Expand Down
16 changes: 11 additions & 5 deletions prettyPrinters/lldb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,24 @@ def get_child_at_index(self, index):
def update(self):
# type: () -> None
table = self.table()
capacity = table.GetChildMemberWithName("bucket_mask").GetValueAsUnsigned() + 1
ctrl = table.GetChildMemberWithName("ctrl").GetChildAtIndex(0)
# BACKCOMPAT: rust 1.51. Just drop `else` branch
if table.GetChildMemberWithName("table").IsValid():
inner_table = table.GetChildMemberWithName("table")
else:
inner_table = table

capacity = inner_table.GetChildMemberWithName("bucket_mask").GetValueAsUnsigned() + 1
ctrl = inner_table.GetChildMemberWithName("ctrl").GetChildAtIndex(0)

self.size = table.GetChildMemberWithName("items").GetValueAsUnsigned()
self.size = inner_table.GetChildMemberWithName("items").GetValueAsUnsigned()
self.pair_type = table.type.template_args[0].GetTypedefedType()
self.pair_type_size = self.pair_type.GetByteSize()

self.new_layout = not table.GetChildMemberWithName("data").IsValid()
self.new_layout = not inner_table.GetChildMemberWithName("data").IsValid()
if self.new_layout:
self.data_ptr = ctrl.Cast(self.pair_type.GetPointerType())
else:
self.data_ptr = table.GetChildMemberWithName("data").GetChildAtIndex(0)
self.data_ptr = inner_table.GetChildMemberWithName("data").GetChildAtIndex(0)

u8_type = self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar)
u8_type_size = self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar).GetByteSize()
Expand Down
1 change: 0 additions & 1 deletion pretty_printers_tests/tests/hash_map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// min-version: 1.33.0
// max-version: 1.51.0

// === LLDB TESTS ==================================================================================

Expand Down

0 comments on commit 949953d

Please sign in to comment.