From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22745 invoked by alias); 7 Jan 2014 04:23:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 22635 invoked by uid 89); 7 Jan 2014 04:23:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 07 Jan 2014 04:23:08 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 20CB311666D for ; Mon, 6 Jan 2014 23:23:07 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MyGYBPU5sBf0 for ; Mon, 6 Jan 2014 23:23:07 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 6254111666A for ; Mon, 6 Jan 2014 23:23:06 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 89B9CE02E6; Tue, 7 Jan 2014 08:23:03 +0400 (RET) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [commit/Ada 11/11] Ada: Fix missing call to pretty-printer for fields of records. Date: Tue, 07 Jan 2014 04:23:00 -0000 Message-Id: <1389068515-10129-12-git-send-email-brobecker@adacore.com> In-Reply-To: <1389068515-10129-1-git-send-email-brobecker@adacore.com> References: <1389068515-10129-1-git-send-email-brobecker@adacore.com> X-SW-Source: 2014-01/txt/msg00125.txt.bz2 Consider the following types: type Time_T is record Secs : Integer; end record; Before : Time_T := (Secs => 1384395743); In this example, we assume that type Time_T is the number of seconds since Epoch, and so added a Python pretty-printer, to print this type in a more human-friendly way. For instance: (gdb) print before $1 = Thu Nov 14 02:22:23 2013 (1384395743) However, we've noticed that things stop working when this type is embedded inside another record, and we try to print that record. For instance, with the following declarations: type Composite is record Id : Integer; T : Time_T; end record; Afternoon : Composite := (Id => 1, T => (Secs => 1384395865)); (gdb) print afternoon $2 = (id => 1, t => (secs => 1384395865)) We expected instead: (gdb) print afternoon $2 = (id => 1, t => Thu Nov 14 02:24:25 2013 (1384395865)) This patch fixes the problem by making sure that we try to print each field via a call to val_print, rather than calling ada_val_print directly. We need to go through val_print, as the val_print handles all language-independent features such as calling the pretty-printer, knowing that ada_val_print will get called eventually if actual Ada-specific printing is required (which should be the most common scenario). And because val_print takes the language as parameter, we enhanced the print_field_values and print_variant_part to also take a language. As a bonus, this allows us to remove a couple of references to current_language. gdb/ChangeLog: * ada-valprint.c (print_field_values): Add "language" parameter. Update calls to print_field_values and print_variant_part. Pass new parameter "language" in call to val_print instead of "current_language". Replace call to ada_val_print by call to val_print. (print_variant_part): Add "language" parameter. (ada_val_print_struct_union): Update call to print_field_values. gdb/testsuite/ChangeLog: * gdb.ada/pp-rec-component.exp, gdb.ada/pp-rec-component.py, gdb.ada/pp-rec-component/foo.adb, gdb.ada/pp-rec-component/pck.adb, gdb.ada/pp-rec-component/pck.ads: New files. --- gdb/ChangeLog | 10 +++++++ gdb/ada-valprint.c | 27 ++++++++--------- gdb/testsuite/ChangeLog | 6 ++++ gdb/testsuite/gdb.ada/pp-rec-component.exp | 40 ++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/pp-rec-component.py | 35 ++++++++++++++++++++++ gdb/testsuite/gdb.ada/pp-rec-component/foo.adb | 22 ++++++++++++++ gdb/testsuite/gdb.ada/pp-rec-component/pck.adb | 21 ++++++++++++++ gdb/testsuite/gdb.ada/pp-rec-component/pck.ads | 23 +++++++++++++++ 8 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/pp-rec-component.exp create mode 100644 gdb/testsuite/gdb.ada/pp-rec-component.py create mode 100644 gdb/testsuite/gdb.ada/pp-rec-component/foo.adb create mode 100644 gdb/testsuite/gdb.ada/pp-rec-component/pck.adb create mode 100644 gdb/testsuite/gdb.ada/pp-rec-component/pck.ads diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9fc947b..11e5565 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2014-01-07 Joel Brobecker + * ada-valprint.c (print_field_values): Add "language" parameter. + Update calls to print_field_values and print_variant_part. + Pass new parameter "language" in call to val_print instead + of "current_language". Replace call to ada_val_print by call + to val_print. + (print_variant_part): Add "language" parameter. + (ada_val_print_struct_union): Update call to print_field_values. + +2014-01-07 Joel Brobecker + * ada-valprint.c (ui_memcpy): Delete. (ada_print_floating): Update documentation. Add empty line between between function documentation and implementation. diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 1ae2089..8f2219f 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -39,7 +39,8 @@ static int print_field_values (struct type *, const gdb_byte *, struct ui_file *, int, const struct value *, const struct value_print_options *, - int, struct type *, int); + int, struct type *, int, + const struct language_defn *); /* Make TYPE unsigned if its range of values includes no negatives. */ @@ -536,7 +537,8 @@ print_variant_part (struct type *type, int field_num, const struct value *val, const struct value_print_options *options, int comma_needed, - struct type *outer_type, int outer_offset) + struct type *outer_type, int outer_offset, + const struct language_defn *language) { struct type *var_type = TYPE_FIELD_TYPE (type, field_num); int which = ada_which_variant_applies (var_type, outer_type, @@ -551,7 +553,7 @@ print_variant_part (struct type *type, int field_num, offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT, stream, recurse, val, options, - comma_needed, outer_type, outer_offset); + comma_needed, outer_type, outer_offset, language); } /* Print out fields of value at VALADDR + OFFSET having structure type TYPE. @@ -575,7 +577,8 @@ print_field_values (struct type *type, const gdb_byte *valaddr, const struct value *val, const struct value_print_options *options, int comma_needed, - struct type *outer_type, int outer_offset) + struct type *outer_type, int outer_offset, + const struct language_defn *language) { int i, len; @@ -594,7 +597,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), stream, recurse, val, options, - comma_needed, type, offset); + comma_needed, type, offset, language); continue; } else if (ada_is_variant_part (type, i)) @@ -603,7 +606,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, print_variant_part (type, i, valaddr, offset, stream, recurse, val, options, comma_needed, - outer_type, outer_offset); + outer_type, outer_offset, language); continue; } @@ -657,7 +660,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, value_contents_for_printing (v), value_embedded_offset (v), 0, stream, recurse + 1, v, - &opts, current_language); + &opts, language); } } else @@ -665,11 +668,9 @@ print_field_values (struct type *type, const gdb_byte *valaddr, struct value_print_options opts = *options; opts.deref_ref = 0; - ada_val_print (TYPE_FIELD_TYPE (type, i), - valaddr, - (offset - + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), - 0, stream, recurse + 1, val, &opts); + val_print (TYPE_FIELD_TYPE (type, i), valaddr, + (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), + 0, stream, recurse + 1, val, &opts, language); } annotate_field_end (); } @@ -963,7 +964,7 @@ ada_val_print_struct_union if (print_field_values (type, valaddr, offset_aligned, stream, recurse, original_value, options, - 0, type, offset_aligned) != 0 + 0, type, offset_aligned, language) != 0 && options->prettyformat) { fprintf_filtered (stream, "\n"); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 67e5cc1..8b00435 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2014-01-07 Joel Brobecker + * gdb.ada/pp-rec-component.exp, gdb.ada/pp-rec-component.py, + gdb.ada/pp-rec-component/foo.adb, gdb.ada/pp-rec-component/pck.adb, + gdb.ada/pp-rec-component/pck.ads: New files. + +2014-01-07 Joel Brobecker + * gdb.python/py-pp-integral.c: New file. * gdb.python/py-pp-integral.py: New file. * gdb.python/py-pp-integral.exp: New file. diff --git a/gdb/testsuite/gdb.ada/pp-rec-component.exp b/gdb/testsuite/gdb.ada/pp-rec-component.exp new file mode 100644 index 0000000..faa7a0f --- /dev/null +++ b/gdb/testsuite/gdb.ada/pp-rec-component.exp @@ -0,0 +1,40 @@ +# Copyright 2014 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 . + +load_lib "ada.exp" + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } { + return -1 +} + +clean_restart ${testfile} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +set remote_python_file \ + [gdb_remote_download host ${srcdir}/${subdir}/${gdb_test_file_name}.py] +gdb_test_no_output "source ${remote_python_file}" + +set bp_location [gdb_get_line_number "BREAK" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test "print before" \ + " = Thu Nov 14 02:22:23 2013 \\(1384395743\\)" + +gdb_test "print /r before" \ + " = \\(secs => 1384395743\\)" diff --git a/gdb/testsuite/gdb.ada/pp-rec-component.py b/gdb/testsuite/gdb.ada/pp-rec-component.py new file mode 100644 index 0000000..98bfa82 --- /dev/null +++ b/gdb/testsuite/gdb.ada/pp-rec-component.py @@ -0,0 +1,35 @@ +# Copyright (C) 2014 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 . + +from time import asctime, gmtime +import gdb # silence pyflakes + + +class TimeTPrinter: + def __init__(self, val): + self.val = val + + def to_string(self): + secs = int(self.val['secs']) + return "%s (%d)" % (asctime(gmtime(secs)), secs) + + +def time_sniffer(val): + if val.type.tag == "pck__time_t": + return TimeTPrinter(val) + return None + + +gdb.pretty_printers.append(time_sniffer) diff --git a/gdb/testsuite/gdb.ada/pp-rec-component/foo.adb b/gdb/testsuite/gdb.ada/pp-rec-component/foo.adb new file mode 100644 index 0000000..3f8e73b --- /dev/null +++ b/gdb/testsuite/gdb.ada/pp-rec-component/foo.adb @@ -0,0 +1,22 @@ +-- Copyright 2014 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 . + +with Pck; use Pck; + +procedure Foo is + Before : Time_T := (Secs => 1384395743); +begin + Do_Nothing (Before'Address); -- BREAK +end Foo; diff --git a/gdb/testsuite/gdb.ada/pp-rec-component/pck.adb b/gdb/testsuite/gdb.ada/pp-rec-component/pck.adb new file mode 100644 index 0000000..2b31332 --- /dev/null +++ b/gdb/testsuite/gdb.ada/pp-rec-component/pck.adb @@ -0,0 +1,21 @@ +-- Copyright 2014 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 . + +package body Pck is + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; +end Pck; diff --git a/gdb/testsuite/gdb.ada/pp-rec-component/pck.ads b/gdb/testsuite/gdb.ada/pp-rec-component/pck.ads new file mode 100644 index 0000000..b1652aa --- /dev/null +++ b/gdb/testsuite/gdb.ada/pp-rec-component/pck.ads @@ -0,0 +1,23 @@ +-- Copyright 2014 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 . + +with System; + +package Pck is + type Time_T is record + Secs : Integer; + end record; + procedure Do_Nothing (A : System.Address); +end Pck; -- 1.8.3.2