Auto merge of #79235 - ortem:fix-btreemap-gdb-pretty-printer, r=Mark-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 https://github.com/intellij-rust/intellij-rust/pull/6356
This commit is contained in:
bors 2020-12-02 04:12:33 +00:00
commit 92e4fb0732

View File

@ -1,7 +1,6 @@
from sys import version_info from sys import version_info
import gdb import gdb
from gdb import lookup_type
if version_info[0] >= 3: if version_info[0] >= 3:
xrange = range xrange = range
@ -213,7 +212,7 @@ def children_of_btree_map(map):
def children_of_node(node_ptr, height): def children_of_node(node_ptr, height):
def cast_to_internal(node): def cast_to_internal(node):
internal_type_name = node.type.target().name.replace("LeafNode", "InternalNode", 1) 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()) return node.cast(internal_type.pointer())
if node_ptr.type.name.startswith("alloc::collections::btree::node::BoxedNode<"): if node_ptr.type.name.startswith("alloc::collections::btree::node::BoxedNode<"):
@ -233,8 +232,10 @@ def children_of_btree_map(map):
yield child yield child
if i < length: if i < length:
# Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays. # Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays.
key = keys[i]["value"]["value"] if keys.type.sizeof > 0 else "()" key_type_size = keys.type.sizeof
val = vals[i]["value"]["value"] if vals.type.sizeof > 0 else "()" 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 yield key, val
if map["length"] > 0: if map["length"] > 0: