Skip to content

Commit

Permalink
Auto merge of #79235 - ortem:fix-btreemap-gdb-pretty-printer, r=Mark-…
Browse files Browse the repository at this point in the history
…Simulacrum

Fix zero-sized BTreeMap gdb pretty-printer

`gdb.parse_and_eval("()")` is needed because GDB treats "()" as a Rust array of two characters, not as a unit

Based on intellij-rust/intellij-rust#6356
  • Loading branch information
bors committed Dec 2, 2020
2 parents eb4860c + 685e1f3 commit 92e4fb0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/etc/gdb_providers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sys import version_info

import gdb
from gdb import lookup_type

if version_info[0] >= 3:
xrange = range
Expand Down Expand Up @@ -213,7 +212,7 @@ def children_of_btree_map(map):
def children_of_node(node_ptr, height):
def cast_to_internal(node):
internal_type_name = node.type.target().name.replace("LeafNode", "InternalNode", 1)
internal_type = lookup_type(internal_type_name)
internal_type = gdb.lookup_type(internal_type_name)
return node.cast(internal_type.pointer())

if node_ptr.type.name.startswith("alloc::collections::btree::node::BoxedNode<"):
Expand All @@ -233,8 +232,10 @@ def cast_to_internal(node):
yield child
if i < length:
# Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays.
key = keys[i]["value"]["value"] if keys.type.sizeof > 0 else "()"
val = vals[i]["value"]["value"] if vals.type.sizeof > 0 else "()"
key_type_size = keys.type.sizeof
val_type_size = vals.type.sizeof
key = keys[i]["value"]["value"] if key_type_size > 0 else gdb.parse_and_eval("()")
val = vals[i]["value"]["value"] if val_type_size > 0 else gdb.parse_and_eval("()")
yield key, val

if map["length"] > 0:
Expand Down

0 comments on commit 92e4fb0

Please sign in to comment.