From 887e71588b295a4d4f4bd7480b1a8c8507dfddb8 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 14 May 2021 19:54:35 -0600 Subject: Fix Python pretty-printing bug in Rust An upstream Rust bug notes notes that the Python pretty-printing feature is broken for values that appear as members of certain types in Rust. The bug here is that some of the Rust value-printing code calls value_print_inner, a method on rust_language. This bypasses the common code that calls into Python. I'm checking this in. gdb/ChangeLog 2021-05-14 Tom Tromey * rust-lang.c (rust_language::val_print_struct) (rust_language::print_enum): Use common_val_print, not value_print_inner. gdb/testsuite/ChangeLog 2021-05-14 Tom Tromey * gdb.rust/pp.exp: New file. * gdb.rust/pp.py: New file. * gdb.rust/pp.rs: New file. --- gdb/testsuite/gdb.rust/pp.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 gdb/testsuite/gdb.rust/pp.py (limited to 'gdb/testsuite/gdb.rust/pp.py') diff --git a/gdb/testsuite/gdb.rust/pp.py b/gdb/testsuite/gdb.rust/pp.py new file mode 100644 index 0000000..57c8cc3 --- /dev/null +++ b/gdb/testsuite/gdb.rust/pp.py @@ -0,0 +1,49 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the GDB testsuite. It tests python pretty +# printers. + +import re +import gdb + + +# Printer for Inner. +class inner_print(object): + def __init__(self, val): + self.val = val + + def to_string(self): + return "x(" + str(self.val["x"]) + ")" + + +def lookup_function(val): + "Look-up and return a pretty-printer that can print val." + + # Get the type. + type = val.type + + # Get the type name. + typename = type.tag + + if typename == None: + return None + + if typename == "pp::Inner": + return inner_print(val) + return None + + +gdb.pretty_printers.append(lookup_function) -- cgit v1.1