From 685e1f3e45ef1ffa881be13b6af1867209c294c7 Mon Sep 17 00:00:00 2001 From: ortem Date: Fri, 20 Nov 2020 18:01:15 +0300 Subject: [PATCH] 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 --- src/etc/gdb_providers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/etc/gdb_providers.py b/src/etc/gdb_providers.py index b5ade324bba..d9e08eb581d 100644 --- a/src/etc/gdb_providers.py +++ b/src/etc/gdb_providers.py @@ -1,7 +1,6 @@ from sys import version_info import gdb -from gdb import lookup_type if version_info[0] >= 3: xrange = range @@ -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()) leaf = node_ptr.dereference() @@ -230,8 +229,10 @@ def children_of_btree_map(map): 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: