gdb, testsuite, fortran: adapt info symbol expected output for intel compilers
[binutils-gdb.git] / gdb / testsuite / gdb.fortran / nested-funcs-2.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 # Further testing of placing breakpoints in nested subroutines.
17
18 if {[skip_fortran_tests]} { return -1 }
19 load_lib "fortran.exp"
20
21 standard_testfile ".f90"
22
23 if {[build_executable ${testfile}.exp ${testfile} \
24 ${srcfile} {debug f90}]} {
25 return -1
26 }
27
28 set int4 [fortran_int4]
29
30 # When WITH_SRC_PREFIX_P is true then some symbol references will be
31 # prefixed with the filename. When WITH_NEST_PREFIX_P is true then
32 # nested subroutine symbols will be prefixed with their parent
33 # subroutine scope.
34 proc do_bp_tests {with_src_prefix_p with_nest_prefix_p} {
35 global testfile srcfile
36 global int4
37 global hex
38
39 clean_restart ${testfile}
40
41 if { $with_src_prefix_p } {
42 set src_prefix "${srcfile}:"
43 } else {
44 set src_prefix ""
45 }
46
47 if { $with_nest_prefix_p } {
48 set nest_prefix "contains_keyword::"
49 } else {
50 set nest_prefix ""
51 }
52
53 # Normally, info symbol prints the symbol table name for any fortran
54 # symbols (since symbol lookup happens via the minimal symbol
55 # table). This would correspond to the linkage name in the full symbol
56 # table.
57 # For gfortran (and maybe others) these names currently have the form
58 # XXXX.NUMBER where XXXX is the symbol name and NUMBER a compiler generated
59 # appendix for mangling. This mangled name gets recognized by the Ada
60 # demangler/decoder and decoded as Ada (setting the symbol language to Ada)
61 # to XXXX. This leads to the somewhat unexpected output of XXXX over
62 # XXXX.NUMBER for info symbol.
63 # For ifort and ifx the generated linkage names have the form
64 # SCOPEA_SCOPEB_XXXX_ which is not recognized by the Ada demangler and thus
65 # printed as is.
66 # Note that there is no Fortran mangling standard. We keep the
67 # gfortran behavior as is and extend the test to reflect ifx and ifort
68 # mangling.
69 proc get_linkage_name_pattern {symbol_name} {
70
71 if { [test_compiler_info icc*] || [test_compiler_info intel*]} {
72 return "\(?:.*_\)?${symbol_name}_?"
73 } else {
74 return ${symbol_name}
75 }
76 }
77
78 # Test setting up breakpoints and otherwise examining nested
79 # functions before the program starts.
80 with_test_prefix "before start" {
81 foreach entry \
82 [list \
83 [list "increment" "${int4} \\\(${int4}\\\)"] \
84 [list "increment_program_global" "${int4} \\\(void\\\)"] \
85 [list "hidden_variable" "void \\\(void\\\)"]] {
86 set function [lindex $entry 0]
87 set type [lindex $entry 1]
88
89 # Currently referencing symbols using 'info',
90 # 'whatis' and 'ptype' before the program is
91 # started doesn't work. This is the same
92 # behaviour we see in C++ so I don't think this
93 # is a failure, just a limitation in current GDB.
94 if { ${with_nest_prefix_p} } {
95 gdb_test "info symbol ${nest_prefix}${function}" \
96 "[get_linkage_name_pattern ${function}] in section .*"
97 gdb_test "whatis ${nest_prefix}${function}" \
98 "type = ${type}"
99 gdb_test "ptype ${nest_prefix}${function}" \
100 "type = ${type}"
101 gdb_test "print ${nest_prefix}${function}" \
102 "{${type}} $hex <contains_keyword::${function}>"
103 }
104
105 gdb_breakpoint "${src_prefix}${nest_prefix}${function}"
106 }
107 }
108
109 # Break on a contained function and run to it.
110 if {![runto ${src_prefix}[gdb_get_line_number "pre_init"]]} then {
111 perror "couldn't run to breakpoint pre_init"
112 continue
113 }
114
115 # Call a contained function.
116 if { ${with_nest_prefix_p} } {
117 gdb_test_stdio "call ${nest_prefix}subroutine_to_call()" " called" ""
118 }
119
120 # Break on another contained function and run to it.
121 gdb_breakpoint "${src_prefix}${nest_prefix}increment"
122 gdb_continue_to_breakpoint "increment" ".*increment = i \\\+ 1"
123 gdb_breakpoint ${src_prefix}[gdb_get_line_number "post_increment"]
124 gdb_continue_to_breakpoint "post_increment"
125
126 # Check arguments and locals report the correct values. 12 is
127 # passed in and 13 is the result after adding 1.
128 gdb_test "info args" "i = 12"
129 gdb_test "info locals" " = 13"
130
131 # Check we can see variables from an outer program scope.
132 gdb_breakpoint ${src_prefix}[gdb_get_line_number "post_increment_global"]
133 gdb_continue_to_breakpoint "post_increment_global" \
134 ".*print \\\*, program_i ! post_increment_global"
135 gdb_test "info args" "No arguments." \
136 "no argument subroutine has no arguments"
137 gdb_test "p program_i" " = 7" "printing outer scoped variable"
138
139 # Stepping into a contained subroutine.
140 gdb_breakpoint ${src_prefix}[gdb_get_line_number "pre_step"]
141 gdb_continue_to_breakpoint "pre_step" ".*call step\\\(\\\) ! pre_step"
142 gdb_test "step" \
143 ".*print '\\\(A\\\)', \\\"step\\\" ! post_step" \
144 "step into the correct place"
145
146 # Local hides program global.
147 gdb_breakpoint ${src_prefix}[gdb_get_line_number "post_hidden"]
148 gdb_continue_to_breakpoint "post_hidden" \
149 ".*print \\\*, program_i ! post_hidden"
150 gdb_test "p program_i" " = 30" "printing hidden global"
151
152 # Check info symbol, whatis and ptype can find information on
153 # these nested functions.
154 foreach entry \
155 [list \
156 [list "increment" "${int4} \\\(${int4}\\\)"] \
157 [list "increment_program_global" "${int4} \\\(void\\\)"]] {
158 set function [lindex $entry 0]
159 set type [lindex $entry 1]
160 with_test_prefix $function {
161 gdb_test "info symbol ${nest_prefix}$function" \
162 "[get_linkage_name_pattern $function] in section .*"
163 gdb_test "whatis ${nest_prefix}$function" \
164 "type = ${type}"
165 gdb_test "ptype ${nest_prefix}$function" \
166 "type = ${type}"
167 }
168 }
169 }
170
171 foreach_with_prefix src_prefix { 0 1 } {
172 foreach_with_prefix nest_prefix { 0 1 } {
173 do_bp_tests ${src_prefix} ${nest_prefix}
174 }
175 }