summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.fortran/print_type.exp
blob: 7d5915390d57eb2e9e5b00a768e860484984a9a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright 2019-2020 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 <http://www.gnu.org/licenses/>.

# Check how GDB handles printing pointers, both when associated, and
# when not associated.

standard_testfile "pointers.f90"
load_lib fortran.exp

if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
    {debug f90 quiet}] } {
    return -1
}

if ![runto_main] {
    untested "could not run to main"
    return -1
}

# Depending on the compiler being used, the type names can be printed
# differently.
set logical [fortran_logical4]
set real [fortran_real4]
set int [fortran_int4]
set complex [fortran_complex4]

# Print the inferior variable VAR_NAME, and check that the result
# matches the string TYPE.
proc check_pointer_type { var_name type } {
    gdb_test "ptype ${var_name}" \
	"type = PTR TO -> \\( ${type} \\)"
}

gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
gdb_continue_to_breakpoint "Before pointer assignment"

with_test_prefix "pointers not associated" {
    check_pointer_type "logp" "$logical"
    check_pointer_type "comp" "$complex"
    check_pointer_type "charp" "character\\*1"
    check_pointer_type "charap" "character\\*3"
    check_pointer_type "intp" "$int"

    # Current gfortran seems to not mark 'intap' as a pointer.  Intels
    # Fortran compiler does though.
    set test "ptype intap"
    gdb_test_multiple "ptype intap" $test {
	-re "type = PTR TO -> \\( $int \\(:,:\\) \\)\r\n$gdb_prompt $" {
	    pass $test
	}
	-re "type = $int \\(:,:\\)\r\n$gdb_prompt $" {
	    pass $test
	}
    }

    check_pointer_type "realp" "$real"
    check_pointer_type "twop" \
	[multi_line "Type two" \
	     "    $int, allocatable :: ivla1\\(:\\)" \
	     "    $int, allocatable :: ivla2\\(:,:\\)" \
	     "End Type two"]
}

gdb_test "ptype two" \
    [multi_line "type = Type two" \
	 "    $int, allocatable :: ivla1\\(:\\)" \
	 "    $int, allocatable :: ivla2\\(:,:\\)" \
	 "End Type two"]

gdb_breakpoint [gdb_get_line_number "Before value assignment"]
gdb_continue_to_breakpoint "Before value assignment"
gdb_test "ptype twop" \
    [multi_line "type = PTR TO -> \\( Type two" \
                "    $int, allocatable :: ivla1\\(:\\)" \
                "    $int, allocatable :: ivla2\\(:,:\\)" \
                "End Type two \\)"]

gdb_breakpoint [gdb_get_line_number "After value assignment"]
gdb_continue_to_breakpoint "After value assignment"
gdb_test "ptype logv" "type = $logical"
gdb_test "ptype comv" "type = $complex"
gdb_test "ptype charv" "type = character\\*1"
gdb_test "ptype chara" "type = character\\*3"
gdb_test "ptype intv" "type = $int"
gdb_test "ptype inta" "type = $int \\(10,2\\)"
gdb_test "ptype realv" "type = $real"

gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
set test "ptype intap"
gdb_test_multiple $test $test {
    -re "type = $int \\(10,2\\)\r\n$gdb_prompt $" {
        pass $test
    }
    -re "type = PTR TO -> \\( $int \\(10,2\\)\\)\r\n$gdb_prompt $" {
        pass $test
    }
}
gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"