GNU Binutils with patches for OS216
Revision | 04d59df6f311bcc20d74ada64a5e15a4bbb40026 (tree) |
---|---|
Time | 2016-06-21 22:15:04 |
Author | Walfred Tedeschi <walfred.tedeschi@inte...> |
Commiter | Walfred Tedeschi |
Improve user experience in printing Fortran derived types.
Output for Fortran derived classes is like:
with this changes the output is changed to:
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.
@@ -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 | + | |
1 | 6 | 2016-06-21 Andreas Arnez <arnez@linux.vnet.ibm.com> |
2 | 7 | |
3 | 8 | * s390-linux-tdep.c (s390_iterate_over_regset_sections): Fix typo |
@@ -219,6 +219,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, | ||
219 | 219 | struct gdbarch *gdbarch = get_type_arch (type); |
220 | 220 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
221 | 221 | unsigned int i = 0; /* Number of characters printed. */ |
222 | + int printed_field = 0; /* Number of fields printed. */ | |
222 | 223 | struct type *elttype; |
223 | 224 | CORE_ADDR addr; |
224 | 225 | int index; |
@@ -337,15 +338,32 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, | ||
337 | 338 | struct value *field = value_field |
338 | 339 | ((struct value *)original_value, index); |
339 | 340 | |
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)); | |
345 | 342 | |
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 | + } | |
349 | 367 | fprintf_filtered (stream, " )"); |
350 | 368 | break; |
351 | 369 |
@@ -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 | + | |
1 | 10 | 2016-06-21 Pedro Alves <palves@redhat.com> |
2 | 11 | |
3 | 12 | * gdb.base/new-ui.exp: New file. |
@@ -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" |
@@ -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 | + |
@@ -53,7 +53,7 @@ gdb_test_multiple "ptype q" $test { | ||
53 | 53 | gdb_breakpoint [gdb_get_line_number "print"] |
54 | 54 | gdb_continue_to_breakpoint "print" |
55 | 55 | |
56 | -gdb_test "print p" "\\$\[0-9\]+ = \\( 1, 2\\.375 \\)" | |
56 | +gdb_test "print p" "\\$\[0-9\]+ = \\( c = 1, d = 2\\.375 \\)" | |
57 | 57 | gdb_test "print p%c" "\\$\[0-9\]+ = 1" |
58 | 58 | gdb_test "print p%d" "\\$\[0-9\]+ = 2\\.375" |
59 | 59 | gdb_test "print q%a" "\\$\[0-9\]+ = 3\\.125" |
@@ -75,10 +75,10 @@ gdb_test "print q%x%d" "\\$\[0-9\]+ = 2\\.375" | ||
75 | 75 | |
76 | 76 | set test "print q" |
77 | 77 | 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 $" { | |
79 | 79 | pass $test |
80 | 80 | } |
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 $" { | |
82 | 82 | # Compiler should produce string, not an array of characters. |
83 | 83 | setup_xfail "*-*-*" |
84 | 84 | fail $test |
@@ -33,7 +33,7 @@ set int [fortran_int4] | ||
33 | 33 | # the debugger when accessing it. |
34 | 34 | gdb_breakpoint [gdb_get_line_number "before-allocated"] |
35 | 35 | 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> \\\)" \ | |
37 | 37 | "print twov before allocated" |
38 | 38 | gdb_test "print twov%ivla1" " = <not allocated>" \ |
39 | 39 | "print twov%ivla1 before allocated" |
@@ -60,7 +60,7 @@ gdb_test "ptype twov" \ | ||
60 | 60 | "\\s+$int :: ivla1\\\(5,12,99\\\)" \ |
61 | 61 | "\\s+$int :: ivla2\\\(9,12\\\)" \ |
62 | 62 | "End Type two" ] |
63 | -gdb_test "print twov" " = \\\( \\\(\\\( \\\( 1, 1, 1, 1, 1\\\)\ | |
63 | +gdb_test "print twov" " = \\\( ivla1 = \\\(\\\( \\\( 1, 1, 1, 1, 1\\\)\ | |
64 | 64 | \\\( 1, 1, 321, 1, 1\\\)\ |
65 | 65 | \\\( 1, 1, 1, 1, 1\\\) .*" |
66 | 66 |