Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.fortran / mixed-lang-stack.exp
blob6538e16e566d04eaabb7a3bc216de5ce54ed2edc
1 # Copyright 2020-2023 Free Software Foundation, Inc.
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.
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.
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/> .
16 # This test covers some basic functionality for debugging mixed
17 # Fortran, C, and C++ applications.  Features tested include examining
18 # the backtrace, and printing frame arguments in frames of different
19 # languages.
21 # One important aspect of this test is that we set the language in
22 # turn to auto, fortran, c, and c++, and carry out the full test in
23 # each case to ensure that trying to print objects or types from one
24 # language, while GDB's language is set to another, doesn't crash GDB.
26 if {[skip_fortran_tests]} { return -1 }
28 standard_testfile mixed-lang-stack.c mixed-lang-stack.cpp mixed-lang-stack.f90
30 if {[prepare_for_testing_full "failed to prepare" \
31          [list ${binfile} {debug f90 additional_flags=-lstdc++} \
32               $srcfile {debug} \
33               $srcfile2 {debug c++} \
34               $srcfile3 {debug f90}]]} {
35     return -1
38 set have_index [exec_has_index_section $binfile]
40 # Runs the test program and examins the stack.  LANG is a string, the
41 # value to pass to GDB's 'set language ...' command.
42 proc run_tests { lang } {
43     with_test_prefix "lang=${lang}" {
44         global binfile hex have_index
46         clean_restart ${binfile}
48         if ![runto_main] {
49             return -1
50         }
52         gdb_breakpoint "breakpt"
53         gdb_continue_to_breakpoint "breakpt"
55         if { $lang == "c" || $lang == "c++" } {
56             gdb_test "set language c" \
57                 "Warning: the current language does not match this frame."
58         } else {
59             gdb_test_no_output "set language $lang"
60         }
62         # Check the backtrace.
63         set e_arg "\['\"\]abcdef\['\"\]"
64         set 1b_args "\[^\r\n\]+$e_arg\[^\r\n\]+"
65         set 1g_args "obj=\[^\r\n\]+"
66         set bt_stack \
67             [multi_line \
68                  "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \
69                  "#1\\s+$hex in mixed_func_1h \\(\\) at \[^\r\n\]+" \
70                  "#2\\s+$hex in mixed_func_1g \\($1g_args\\) at \[^\r\n\]+" \
71                  "#3\\s+$hex in mixed_func_1f \\(\\) at \[^\r\n\]+" \
72                  "#4\\s+$hex in mixed_func_1e \\(\\) at \[^\r\n\]+" \
73                  "#5\\s+$hex in mixed_func_1d \\(\[^\r\n\]+\\) at \[^\r\n\]+" \
74                  "#6\\s+$hex in mixed_func_1c \\(\[^\r\n\]+\\) at \[^\r\n\]+" \
75                  "#7\\s+$hex in mixed_func_1b \\($1b_args\\) at \[^\r\n\]+" \
76                  "#8\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \
77                  "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" ]
78         set main_args "argc=1, argv=${hex}( \[^\r\n\]+)?"
79         set bt_stack_kfail \
80             [multi_line \
81                  $bt_stack \
82                  "#10\\s+$hex in main \\($main_args\\) at \[^\r\n\]+"]
83         gdb_test_multiple "bt -frame-arguments all" "" {
84             -re -wrap $bt_stack {
85                 pass $gdb_test_name
86             }
87             -re -wrap $bt_stack_kfail {
88                 if { $have_index } {
89                     setup_kfail "gdb/24549" *-*-*
90                 }
91                 fail $gdb_test_name
92             }
93         }
95         # Check the language for frame #0.
96         gdb_test "info frame" "source language fortran\..*" \
97             "info frame in frame #0"
99         # Move up to the C++ frames and check the frame state, print a
100         # C++ object.
101         gdb_test "frame 2" "#2\\s+$hex in mixed_func_1g .*" \
102             "select frame #2"
103         gdb_test "info frame" "source language c\\+\\+\..*" \
104             "info frame in frame #2"
105         if { $lang == "fortran" } {
106             set obj_pattern " = \\( base_one = \\( num1 = 1, num2 = 2, num3 = 3 \\), base_two = \\( string = $hex 'Something in C\\+\\+\\\\000', val = 3.5 \\), xxx = 9, yyy = 10.5 \\)"
107         } else {
108             set obj_pattern " = \\{<base_one> = \\{num1 = 1, num2 = 2, num3 = 3\\}, <base_two> = \\{string = $hex \"Something in C\\+\\+\", val = 3.5\\}, xxx = 9, yyy = 10.5\\}"
109         }
110         gdb_test "print obj" "${obj_pattern}"
112         # Move up the stack a way, and check frame and the frame
113         # arguments.
114         gdb_test "frame 5" "#5\\s+$hex in mixed_func_1d .*" \
115             "select frame #5"
116         gdb_test "info frame" "source language fortran\..*" \
117             "info frame in frame #5"
119         gdb_test "up" "#6\\s+$hex in mixed_func_1c .*" \
120             "up to frame #6"
121         gdb_test "info frame" "source language c\..*" \
122             "info frame in frame #6"
124         if { $lang == "fortran" } {
125             set d_pattern "\\(4,5\\)"
126             set f_pattern "$hex 'abcdef\\\\000'"
127         } else {
128             set d_pattern "4 \\+ 5i"
129             set f_pattern "$hex \"abcdef\""
130         }
132         # When value-printing pointers in GDB, GDB will try and look for any
133         # associated symbol and print it after the pointer as "<SYMBOL>". For
134         # this test Intel and LLVM compilers move g to the .bss section, thus
135         # creating a symbol, while the GNU compiler stack keeps g purely on the
136         # stack.
137         set g_pattern "$hex\( <\[^\r\n\]+>\)?"
139         set args_pattern [multi_line \
140                               "a = 1" \
141                               "b = 2" \
142                               "c = 3" \
143                               "d = ${d_pattern}" \
144                               "f = ${f_pattern}" \
145                               "g = ${g_pattern}" ]
147         gdb_test "info args" $args_pattern \
148             "info args in frame #6"
149         if { $lang == "fortran" } {
150             set g_val_pattern " = \\( a = 1\\.5, b = 2\\.5 \\)"
151         } else {
152             set g_val_pattern " = \\{a = 1\\.5, b = 2\\.5\\}"
153         }
154         gdb_test "print *g" "${g_val_pattern}" \
155             "print object pointed to by g"
157         gdb_test "up" "#7\\s+$hex in mixed_func_1b .*" \
158             "up to frame #7"
159         gdb_test "info frame" "source language fortran\..*" \
160             "info frame in frame #7"
162         if { $lang == "c" || $lang == "c++" } {
163             set d_pattern "4 \\+ 5i"
164             set e_pattern "\"abcdef\""
165             set g_val_pattern "\{a = 1.5, b = 2.5\}"
166         } else {
167             set d_pattern "\\(4,5\\)"
168             set e_pattern "'abcdef'"
169             set g_val_pattern "\\( a = 1.5, b = 2.5 \\)"
170         }
172         set args_pattern [multi_line \
173                               "a = 1" \
174                               "b = 2" \
175                               "c = 3" \
176                               "d = ${d_pattern}" \
177                               "e = ${e_pattern}" \
178                               "g = ${g_val_pattern}" \
179                               "_e = 6" ]
181         gdb_test "info args" $args_pattern \
182             "info args in frame #7"
183     }
186 run_tests "auto"
187 run_tests "fortran"
188 run_tests "c"
189 run_tests "c++"