gdb/fortran: Show the type for non allocated / associated types
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.fortran / print_type.exp
1 # Copyright 2019 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 # Check how GDB handles printing pointers, both when associated, and
17 # when not associated.
18
19 standard_testfile "pointers.f90"
20 load_lib fortran.exp
21
22 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
23 {debug f90 quiet}] } {
24 return -1
25 }
26
27 if ![runto_main] {
28 untested "could not run to main"
29 return -1
30 }
31
32 # Depending on the compiler being used, the type names can be printed
33 # differently.
34 set logical [fortran_logical4]
35 set real [fortran_real4]
36 set int [fortran_int4]
37 set complex [fortran_complex4]
38
39 # Print the inferior variable VAR_NAME, and check that the result
40 # matches the string TYPE.
41 proc check_pointer_type { var_name type } {
42 gdb_test "ptype ${var_name}" \
43 "type = PTR TO -> \\( ${type} \\)"
44 }
45
46 gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
47 gdb_continue_to_breakpoint "Before pointer assignment"
48
49 with_test_prefix "pointers not associated" {
50 check_pointer_type "logp" "$logical"
51 check_pointer_type "comp" "$complex"
52 check_pointer_type "charp" "character\\*1"
53 check_pointer_type "charap" "character\\*3"
54 check_pointer_type "intp" "$int"
55
56 # Current gfortran seems to not mark 'intap' as a pointer. Intels
57 # Fortran compiler does though.
58 set test "ptype intap"
59 gdb_test_multiple "ptype intap" $test {
60 -re "type = PTR TO -> \\( $int \\(:,:\\) \\)\r\n$gdb_prompt $" {
61 pass $test
62 }
63 -re "type = $int \\(:,:\\)\r\n$gdb_prompt $" {
64 pass $test
65 }
66 }
67
68 check_pointer_type "realp" "$real"
69 check_pointer_type "twop" \
70 [multi_line "Type two" \
71 " $int, allocatable :: ivla1\\(:\\)" \
72 " $int, allocatable :: ivla2\\(:,:\\)" \
73 "End Type two"]
74 }
75
76 gdb_test "ptype two" \
77 [multi_line "type = Type two" \
78 " $int, allocatable :: ivla1\\(:\\)" \
79 " $int, allocatable :: ivla2\\(:,:\\)" \
80 "End Type two"]
81
82 gdb_breakpoint [gdb_get_line_number "Before value assignment"]
83 gdb_continue_to_breakpoint "Before value assignment"
84 gdb_test "ptype twop" \
85 [multi_line "type = PTR TO -> \\( Type two" \
86 " $int, allocatable :: ivla1\\(:\\)" \
87 " $int, allocatable :: ivla2\\(:,:\\)" \
88 "End Type two \\)"]
89
90 gdb_breakpoint [gdb_get_line_number "After value assignment"]
91 gdb_continue_to_breakpoint "After value assignment"
92 gdb_test "ptype logv" "type = $logical"
93 gdb_test "ptype comv" "type = $complex"
94 gdb_test "ptype charv" "type = character\\*1"
95 gdb_test "ptype chara" "type = character\\*3"
96 gdb_test "ptype intv" "type = $int"
97 gdb_test "ptype inta" "type = $int \\(10,2\\)"
98 gdb_test "ptype realv" "type = $real"
99
100 gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
101 gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
102 gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
103 gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
104 gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
105 set test "ptype intap"
106 gdb_test_multiple $test $test {
107 -re "type = $int \\(10,2\\)\r\n$gdb_prompt $" {
108 pass $test
109 }
110 -re "type = PTR TO -> \\( $int \\(10,2\\)\\)\r\n$gdb_prompt $" {
111 pass $test
112 }
113 }
114 gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"
This page took 0.031434 seconds and 4 git commands to generate.