Commit | Line | Data |
---|---|---|
6b8c53f2 AB |
1 | # Copyright 2020 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 | # 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. | |
20 | # | |
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. | |
25 | ||
26 | if {[skip_fortran_tests]} { return -1 } | |
27 | ||
28 | standard_testfile mixed-lang-stack.c mixed-lang-stack.cpp mixed-lang-stack.f90 | |
29 | ||
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 | |
36 | } | |
37 | ||
38 | # Runs the test program and examins the stack. LANG is a string, the | |
39 | # value to pass to GDB's 'set language ...' command. | |
40 | proc run_tests { lang } { | |
41 | with_test_prefix "lang=${lang}" { | |
42 | global binfile hex | |
43 | ||
44 | clean_restart ${binfile} | |
45 | ||
46 | if ![runto_main] { | |
47 | untested "could not run to main" | |
48 | return -1 | |
49 | } | |
50 | ||
51 | gdb_breakpoint "breakpt" | |
52 | gdb_continue_to_breakpoint "breakpt" | |
53 | ||
54 | if { $lang == "c" || $lang == "c++" } { | |
55 | gdb_test "set language c" \ | |
56 | "Warning: the current language does not match this frame." | |
57 | } else { | |
58 | gdb_test_no_output "set language $lang" | |
59 | } | |
60 | ||
61 | # Check the backtrace. | |
547ce8f0 TV |
62 | set e_arg "\['\"\]abcdef\['\"\]" |
63 | set 1b_args "\[^\r\n\]+$e_arg\[^\r\n\]+" | |
64 | set 1g_args "obj=\[^\r\n\]+" | |
65 | set bt_stack \ | |
66 | [multi_line \ | |
67 | "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \ | |
68 | "#1\\s+$hex in mixed_func_1h \\(\\) at \[^\r\n\]+" \ | |
69 | "#2\\s+$hex in mixed_func_1g \\($1g_args\\) at \[^\r\n\]+" \ | |
70 | "#3\\s+$hex in mixed_func_1f \\(\\) at \[^\r\n\]+" \ | |
71 | "#4\\s+$hex in mixed_func_1e \\(\\) at \[^\r\n\]+" \ | |
72 | "#5\\s+$hex in mixed_func_1d \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ | |
73 | "#6\\s+$hex in mixed_func_1c \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ | |
74 | "#7\\s+$hex in mixed_func_1b \\($1b_args\\) at \[^\r\n\]+" \ | |
75 | "#8\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \ | |
9370fd51 | 76 | "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" ] |
547ce8f0 | 77 | gdb_test "bt -frame-arguments all" $bt_stack |
6b8c53f2 AB |
78 | |
79 | # Check the language for frame #0. | |
80 | gdb_test "info frame" "source language fortran\..*" \ | |
81 | "info frame in frame #0" | |
82 | ||
83 | # Move up to the C++ frames and check the frame state, print a | |
84 | # C++ object. | |
85 | gdb_test "frame 2" "#2\\s+$hex in mixed_func_1g .*" \ | |
86 | "select frame #2" | |
87 | gdb_test "info frame" "source language c\\+\\+\..*" \ | |
88 | "info frame in frame #2" | |
89 | if { $lang == "fortran" } { | |
5935fd15 | 90 | 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 \\)" |
6b8c53f2 | 91 | } else { |
5935fd15 | 92 | 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\\}" |
6b8c53f2 AB |
93 | } |
94 | gdb_test "print obj" "${obj_pattern}" | |
95 | ||
96 | # Move up the stack a way, and check frame and the frame | |
97 | # arguments. | |
98 | gdb_test "frame 5" "#5\\s+$hex in mixed_func_1d .*" \ | |
99 | "select frame #5" | |
100 | gdb_test "info frame" "source language fortran\..*" \ | |
101 | "info frame in frame #5" | |
102 | ||
103 | gdb_test "up" "#6\\s+$hex in mixed_func_1c .*" \ | |
104 | "up to frame #6" | |
105 | gdb_test "info frame" "source language c\..*" \ | |
106 | "info frame in frame #6" | |
107 | ||
108 | if { $lang == "fortran" } { | |
109 | set d_pattern "\\(4,5\\)" | |
110 | set f_pattern "$hex 'abcdef\\\\000'" | |
111 | } else { | |
cc77ed24 | 112 | set d_pattern "4 \\+ 5i" |
6b8c53f2 AB |
113 | set f_pattern "$hex \"abcdef\"" |
114 | } | |
115 | ||
116 | set args_pattern [multi_line \ | |
117 | "a = 1" \ | |
118 | "b = 2" \ | |
119 | "c = 3" \ | |
120 | "d = ${d_pattern}" \ | |
121 | "f = ${f_pattern}" \ | |
122 | "g = $hex" ] | |
123 | ||
124 | gdb_test "info args" $args_pattern \ | |
125 | "info args in frame #6" | |
126 | if { $lang == "fortran" } { | |
127 | set g_pattern " = \\( a = 1\\.5, b = 2\\.5 \\)" | |
128 | } else { | |
129 | set g_pattern " = \\{a = 1\\.5, b = 2\\.5\\}" | |
130 | } | |
131 | gdb_test "print *g" "${g_pattern}" \ | |
132 | "print object pointed to by g" | |
133 | ||
134 | gdb_test "up" "#7\\s+$hex in mixed_func_1b .*" \ | |
135 | "up to frame #7" | |
136 | gdb_test "info frame" "source language fortran\..*" \ | |
137 | "info frame in frame #7" | |
138 | ||
139 | if { $lang == "c" || $lang == "c++" } { | |
cc77ed24 | 140 | set d_pattern "4 \\+ 5i" |
6b8c53f2 AB |
141 | set e_pattern "\"abcdef\"" |
142 | set g_pattern "\{a = 1.5, b = 2.5\}" | |
143 | } else { | |
144 | set d_pattern "\\(4,5\\)" | |
145 | set e_pattern "'abcdef'" | |
146 | set g_pattern "\\( a = 1.5, b = 2.5 \\)" | |
147 | } | |
148 | ||
149 | set args_pattern [multi_line \ | |
150 | "a = 1" \ | |
151 | "b = 2" \ | |
152 | "c = 3" \ | |
153 | "d = ${d_pattern}" \ | |
154 | "e = ${e_pattern}" \ | |
155 | "g = ${g_pattern}" \ | |
156 | "_e = 6" ] | |
157 | ||
158 | gdb_test "info args" $args_pattern \ | |
159 | "info args in frame #7" | |
160 | } | |
161 | } | |
162 | ||
163 | run_tests "auto" | |
164 | run_tests "fortran" | |
165 | run_tests "c" | |
166 | run_tests "c++" |