• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision04d59df6f311bcc20d74ada64a5e15a4bbb40026 (tree)
Time2016-06-21 22:15:04
AuthorWalfred Tedeschi <walfred.tedeschi@inte...>
CommiterWalfred Tedeschi

Log Message

Improve user experience in printing Fortran derived types.

Output for Fortran derived classes is like:

"( 9, 'abc')"

with this changes the output is changed to:

"( lucky_number = 9, letters = 'abc')"

2016-06-21 Walfred Tedeschi <walfred.tedeschi@intel.com>

* 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.

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
1+2016-06-21 Walfred Tedeschi <walfred.tedeschi@intel.com>
2+
3+ * f-valprint.c (f_val_print): Add field names for printing
4+ derived types fields.
5+
16 2016-06-21 Andreas Arnez <arnez@linux.vnet.ibm.com>
27
38 * s390-linux-tdep.c (s390_iterate_over_regset_sections): Fix typo
--- 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,
219219 struct gdbarch *gdbarch = get_type_arch (type);
220220 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
221221 unsigned int i = 0; /* Number of characters printed. */
222+ int printed_field = 0; /* Number of fields printed. */
222223 struct type *elttype;
223224 CORE_ADDR addr;
224225 int index;
@@ -337,15 +338,32 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
337338 struct value *field = value_field
338339 ((struct value *)original_value, index);
339340
340- val_print (value_type (field),
341- value_contents_for_printing (field),
342- value_embedded_offset (field),
343- value_address (field), stream, recurse + 1,
344- field, options, current_language);
341+ struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, index));
345342
346- if (index != TYPE_NFIELDS (type) - 1)
347- fputs_filtered (", ", stream);
348- }
343+
344+ if (TYPE_CODE (field_type) != TYPE_CODE_FUNC)
345+ {
346+ const char *field_name;
347+
348+ if (printed_field > 0)
349+ fputs_filtered (", ", stream);
350+
351+ field_name = TYPE_FIELD_NAME (type, index);
352+ if (field_name != NULL)
353+ {
354+ fputs_filtered (field_name, stream);
355+ fputs_filtered (" = ", stream);
356+ }
357+
358+ val_print (value_type (field),
359+ value_contents_for_printing (field),
360+ value_embedded_offset (field),
361+ value_address (field), stream, recurse + 1,
362+ field, options, current_language);
363+
364+ ++printed_field;
365+ }
366+ }
349367 fprintf_filtered (stream, " )");
350368 break;
351369
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,12 @@
1+2016-06-21 Walfred Tedeschi <walfred.tedeschi@intel.com>
2+
3+ * gdb.fortran/derived-type.exp (print q): Add fields to the output.
4+ * gdb.fortran/vla-type.exp (print twov): Fix vla tests with
5+ structs.
6+ * gdb.fortran/derived-type-function.exp: New file.
7+ * gdb.fortran/derived-type-function.f90: New file.
8+
9+
110 2016-06-21 Pedro Alves <palves@redhat.com>
211
312 * gdb.base/new-ui.exp: New file.
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/derived-type-function.exp
@@ -0,0 +1,38 @@
1+# Copyright 2016 Free Software Foundation, Inc.
2+
3+# This program is free software; you can redistribute it and/or modify
4+# it under the terms of the GNU General Public License as published by
5+# the Free Software Foundation; either version 3 of the License, or
6+# (at your option) any later version.
7+#
8+# This program is distributed in the hope that it will be useful,
9+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+# GNU General Public License for more details.
12+#
13+# You should have received a copy of the GNU General Public License
14+# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+# This file was contributed by Walfred Tedeschi (walfred.tedeschi@intel.com).
17+
18+# This file is part of the gdb testsuite. It contains tests for type-printing
19+# and value-printing Fortran derived types having also functions.
20+
21+if { [skip_fortran_tests] } { return -1 }
22+
23+standard_testfile .f90
24+
25+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}]} {
26+ return -1
27+}
28+
29+if ![runto MAIN__] then {
30+ perror "couldn't run to breakpoint MAIN__"
31+ continue
32+}
33+
34+gdb_breakpoint [gdb_get_line_number "bp"]
35+gdb_continue_to_breakpoint "bp"
36+
37+gdb_test "print aRec" "= \\( a = 2, b = 3 \\)"\
38+"Print rectangle structure with members' name"
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/derived-type-function.f90
@@ -0,0 +1,62 @@
1+! Copyright 2016 Free Software Foundation, Inc.
2+!
3+! This program is free software; you can redistribute it and/or modify
4+! it under the terms of the GNU General Public License as published by
5+! the Free Software Foundation; either version 3 of the License, or
6+! (at your option) any later version.
7+!
8+! This program is distributed in the hope that it will be useful,
9+! but WITHOUT ANY WARRANTY; without even the implied warranty of
10+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+! GNU General Public License for more details.
12+!
13+! You should have received a copy of the GNU General Public License
14+! along with this program. If not, see <http://www.gnu.org/licenses/>.
15+!
16+! This file is the Fortran source file for derived-type-function.exp.
17+! It was contributed by Walfred Tedeschi (walfred.tedeschi@intel.com).
18+
19+module class_Rectangle
20+ implicit none
21+ private
22+
23+ type, public :: Rectangle
24+ real :: a
25+ real :: b
26+ contains
27+ procedure :: area => rectangle_area
28+ procedure :: print_area => print_area
29+ end type Rectangle
30+contains
31+
32+ function rectangle_area (this) result (area)
33+ class (Rectangle), intent (in) :: this
34+
35+ real :: area
36+ area = this%a * this%b
37+ end function rectangle_area
38+
39+ subroutine print_area (this)
40+ class (Rectangle), intent (in) :: this
41+ real :: area
42+
43+ area = this%area ()
44+ print *, ' area = ', area
45+ end subroutine print_area
46+
47+end module class_Rectangle
48+
49+
50+program rectangle_Test
51+ use class_Rectangle
52+ implicit none
53+
54+ type (Rectangle) :: aRec
55+ real areaE
56+
57+ aRec = Rectangle (2., 3.)
58+ ! bp
59+ call aRec%print_area
60+
61+end program rectangle_Test
62+
--- 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 {
5353 gdb_breakpoint [gdb_get_line_number "print"]
5454 gdb_continue_to_breakpoint "print"
5555
56-gdb_test "print p" "\\$\[0-9\]+ = \\( 1, 2\\.375 \\)"
56+gdb_test "print p" "\\$\[0-9\]+ = \\( c = 1, d = 2\\.375 \\)"
5757 gdb_test "print p%c" "\\$\[0-9\]+ = 1"
5858 gdb_test "print p%d" "\\$\[0-9\]+ = 2\\.375"
5959 gdb_test "print q%a" "\\$\[0-9\]+ = 3\\.125"
@@ -75,10 +75,10 @@ gdb_test "print q%x%d" "\\$\[0-9\]+ = 2\\.375"
7575
7676 set test "print q"
7777 gdb_test_multiple $test $test {
78- -re "\\$\[0-9\]+ = \\( 3.125, \\( 1, 2\\.375 \\), 'abcdefg' \\)\r\n$gdb_prompt $" {
78+ -re "\\$\[0-9\]+ = \\( a = 3.125, x = \\( c = 1, d = 2\\.375 \\), b = 'abcdefg' \\)\r\n$gdb_prompt $" {
7979 pass $test
8080 }
81- -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 $" {
81+ -re "\\$\[0-9\]+ = \\( a = 3.125, x = \\( 1, 2\\.375 \\), b = \\('abcdefg'\\) \\)\r\n$gdb_prompt $" {
8282 # Compiler should produce string, not an array of characters.
8383 setup_xfail "*-*-*"
8484 fail $test
--- a/gdb/testsuite/gdb.fortran/vla-type.exp
+++ b/gdb/testsuite/gdb.fortran/vla-type.exp
@@ -33,7 +33,7 @@ set int [fortran_int4]
3333 # the debugger when accessing it.
3434 gdb_breakpoint [gdb_get_line_number "before-allocated"]
3535 gdb_continue_to_breakpoint "before-allocated"
36-gdb_test "print twov" " = \\\( <not allocated>, <not allocated> \\\)" \
36+gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
3737 "print twov before allocated"
3838 gdb_test "print twov%ivla1" " = <not allocated>" \
3939 "print twov%ivla1 before allocated"
@@ -60,7 +60,7 @@ gdb_test "ptype twov" \
6060 "\\s+$int :: ivla1\\\(5,12,99\\\)" \
6161 "\\s+$int :: ivla2\\\(9,12\\\)" \
6262 "End Type two" ]
63-gdb_test "print twov" " = \\\( \\\(\\\( \\\( 1, 1, 1, 1, 1\\\)\
63+gdb_test "print twov" " = \\\( ivla1 = \\\(\\\( \\\( 1, 1, 1, 1, 1\\\)\
6464 \\\( 1, 1, 321, 1, 1\\\)\
6565 \\\( 1, 1, 1, 1, 1\\\) .*"
6666