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