From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34426 invoked by alias); 21 Jun 2016 07:17:50 -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 32832 invoked by uid 89); 21 Jun 2016 07:17:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=HX-Envelope-From:sk:wtedesc, 53,7, H*r:sk:wtedesc, 2196 X-HELO: mga11.intel.com Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jun 2016 07:17:35 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 21 Jun 2016 00:17:33 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 21 Jun 2016 00:17:32 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u5L7HVCE023644; Tue, 21 Jun 2016 08:17:31 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id u5L7HVZr017501; Tue, 21 Jun 2016 09:17:31 +0200 Received: (from wtedesch@localhost) by ulvlx001.iul.intel.com with œ id u5L7HU8s017497; Tue, 21 Jun 2016 09:17:31 +0200 From: Walfred Tedeschi To: palves@redhat.com, qiyaoltc@gmail.com Cc: gdb-patches@sourceware.org, Walfred Tedeschi Subject: [PATCH V3] Improve user experience in printing Fortran derived types. Date: Tue, 21 Jun 2016 07:17:00 -0000 Message-Id: <1466493448-17323-1-git-send-email-walfred.tedeschi@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00346.txt.bz2 Output for Fortran derived classes is like: "( 9, 'abc')" with this changes the output is changed to: "( lucky_number = 9, letters = 'abc')" 2016-03-08 Walfred Tedeschi * f-valprint.c (f_val_print): Add field names for printing derived types fields. gdb/testsuite: * gdb.fortran/derived-type.exp (print q): Add fields to the output. * gdb.fortran/vla-type.exp (print twov): Fix vla tests with structs. * gdb.fortran/derived-type-function.exp: New file. * gdb.fortran/derived-type-function.f90: New file. --- gdb/f-valprint.c | 34 +++++++++--- .../gdb.fortran/derived-type-function.exp | 38 +++++++++++++ .../gdb.fortran/derived-type-function.f90 | 62 ++++++++++++++++++++++ gdb/testsuite/gdb.fortran/derived-type.exp | 6 +-- gdb/testsuite/gdb.fortran/vla-type.exp | 4 +- 5 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 gdb/testsuite/gdb.fortran/derived-type-function.exp create mode 100644 gdb/testsuite/gdb.fortran/derived-type-function.f90 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 1264737..08215e2 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -219,6 +219,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, struct gdbarch *gdbarch = get_type_arch (type); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); unsigned int i = 0; /* Number of characters printed. */ + int printed_field = 0; /* Number of fields printed. */ struct type *elttype; CORE_ADDR addr; int index; @@ -337,15 +338,32 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, struct value *field = value_field ((struct value *)original_value, index); - val_print (value_type (field), - value_contents_for_printing (field), - value_embedded_offset (field), - value_address (field), stream, recurse + 1, - field, options, current_language); + struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, index)); - if (index != TYPE_NFIELDS (type) - 1) - fputs_filtered (", ", stream); - } + + if (TYPE_CODE (field_type) != TYPE_CODE_FUNC) + { + const char *field_name; + + if (printed_field > 0) + fputs_filtered (", ", stream); + + field_name = TYPE_FIELD_NAME (type, index); + if (field_name != NULL) + { + fputs_filtered (field_name, stream); + fputs_filtered (" = ", stream); + } + + val_print (value_type (field), + value_contents_for_printing (field), + value_embedded_offset (field), + value_address (field), stream, recurse + 1, + field, options, current_language); + + ++printed_field; + } + } fprintf_filtered (stream, " )"); break; diff --git a/gdb/testsuite/gdb.fortran/derived-type-function.exp b/gdb/testsuite/gdb.fortran/derived-type-function.exp new file mode 100644 index 0000000..94c609c --- /dev/null +++ b/gdb/testsuite/gdb.fortran/derived-type-function.exp @@ -0,0 +1,38 @@ +# Copyright 2016 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 was contributed by Walfred Tedeschi (walfred.tedeschi@intel.com). + +# This file is part of the gdb testsuite. It contains tests for type-printing +# and value-printing Fortran derived types. + +if { [skip_fortran_tests] } { return -1 } + +standard_testfile .f90 + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}]} { + return -1 +} + +if ![runto MAIN__] then { + perror "couldn't run to breakpoint MAIN__" + continue +} + +gdb_breakpoint [gdb_get_line_number "bp"] +gdb_continue_to_breakpoint "bp" + +gdb_test "print aRec" "= \\( a = 2, b = 3 \\)"\ +"Print rectangle structure with members' name" diff --git a/gdb/testsuite/gdb.fortran/derived-type-function.f90 b/gdb/testsuite/gdb.fortran/derived-type-function.f90 new file mode 100644 index 0000000..5fa3904 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/derived-type-function.f90 @@ -0,0 +1,62 @@ +! Copyright 2016 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 . +! +! Ihis file is the Fortran source file for derived-type.exp. It was +! contributed by Walfred Tedeschi (walfred.tedeschi@intel.com). + +module class_Rectangle + implicit none + private + + type, public :: Rectangle + real :: a + real :: b + contains + procedure :: area => rectangle_area + procedure :: print_area => print_area + end type Rectangle +contains + + function rectangle_area (this) result (area) + class (Rectangle), intent (in) :: this + + real :: area + area = this%a * this%b + end function rectangle_area + + subroutine print_area (this) + class (Rectangle), intent (in) :: this + real :: area + + area = this%area () + print *, ' area = ', area + end subroutine print_area + +end module class_Rectangle + + +program rectangle_Test + use class_Rectangle + implicit none + + type (Rectangle) :: aRec + real areaE + + aRec = Rectangle (2., 3.) + ! bp + call aRec%print_area + +end program rectangle_Test + diff --git a/gdb/testsuite/gdb.fortran/derived-type.exp b/gdb/testsuite/gdb.fortran/derived-type.exp index 73eb1f4..32431bc 100644 --- a/gdb/testsuite/gdb.fortran/derived-type.exp +++ b/gdb/testsuite/gdb.fortran/derived-type.exp @@ -53,7 +53,7 @@ gdb_test_multiple "ptype q" $test { gdb_breakpoint [gdb_get_line_number "print"] gdb_continue_to_breakpoint "print" -gdb_test "print p" "\\$\[0-9\]+ = \\( 1, 2\\.375 \\)" +gdb_test "print p" "\\$\[0-9\]+ = \\( c = 1, d = 2\\.375 \\)" gdb_test "print p%c" "\\$\[0-9\]+ = 1" gdb_test "print p%d" "\\$\[0-9\]+ = 2\\.375" gdb_test "print q%a" "\\$\[0-9\]+ = 3\\.125" @@ -75,10 +75,10 @@ gdb_test "print q%x%d" "\\$\[0-9\]+ = 2\\.375" set test "print q" gdb_test_multiple $test $test { - -re "\\$\[0-9\]+ = \\( 3.125, \\( 1, 2\\.375 \\), 'abcdefg' \\)\r\n$gdb_prompt $" { + -re "\\$\[0-9\]+ = \\( a = 3.125, x = \\( c = 1, d = 2\\.375 \\), b = 'abcdefg' \\)\r\n$gdb_prompt $" { pass $test } - -re "\\$\[0-9\]+ = \\( 3.125, \\( 1, 2\\.375 \\), \\(97 'a', 98 'b', 99 'c', 100 'd', 101 'e', 102 'f', 103 'g'\\) \\)\r\n$gdb_prompt $" { + -re "\\$\[0-9\]+ = \\( a = 3.125, x = \\( 1, 2\\.375 \\), b = \\('abcdefg'\\) \\)\r\n$gdb_prompt $" { # Compiler should produce string, not an array of characters. setup_xfail "*-*-*" fail $test diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp b/gdb/testsuite/gdb.fortran/vla-type.exp index 68884ce..401782b 100755 --- a/gdb/testsuite/gdb.fortran/vla-type.exp +++ b/gdb/testsuite/gdb.fortran/vla-type.exp @@ -33,7 +33,7 @@ set int [fortran_int4] # the debugger when accessing it. gdb_breakpoint [gdb_get_line_number "before-allocated"] gdb_continue_to_breakpoint "before-allocated" -gdb_test "print twov" " = \\\( , \\\)" \ +gdb_test "print twov" " = \\\( ivla1 = , ivla2 = \\\)" \ "print twov before allocated" gdb_test "print twov%ivla1" " = " \ "print twov%ivla1 before allocated" @@ -60,7 +60,7 @@ gdb_test "ptype twov" \ "\\s+$int :: ivla1\\\(5,12,99\\\)" \ "\\s+$int :: ivla2\\\(9,12\\\)" \ "End Type two" ] -gdb_test "print twov" " = \\\( \\\(\\\( \\\( 1, 1, 1, 1, 1\\\)\ +gdb_test "print twov" " = \\\( ivla1 = \\\(\\\( \\\( 1, 1, 1, 1, 1\\\)\ \\\( 1, 1, 321, 1, 1\\\)\ \\\( 1, 1, 1, 1, 1\\\) .*" -- 2.7.4