[gdb/testsuite] Remove stale exec in gdb_compile_ada
[binutils-gdb.git] / gdb / testsuite / lib / ada.exp
1 # Copyright 2004-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 # Call target_compile with SOURCE DEST TYPE and OPTIONS as argument,
17 # after having temporarily changed the current working directory to
18 # BUILDDIR.
19
20 proc target_compile_ada_from_dir {builddir source dest type options} {
21 set saved_cwd [pwd]
22
23 global board
24 set board [target_info name]
25 set save_multilib_flag [board_info $board multilib_flags]
26 set multilib_flag ""
27 foreach op $save_multilib_flag {
28 if { $op == "-pie" || $op == "-no-pie" } {
29 # Pretend gnatmake supports -pie/-no-pie, route it to
30 # linker.
31 append multilib_flag " -largs $op -margs"
32 } else {
33 append multilib_flag " $op"
34 }
35 }
36 if { $multilib_flag != "" } {
37 unset_board_info "multilib_flags"
38 set_board_info multilib_flags "$multilib_flag"
39 }
40
41 catch {
42 cd $builddir
43 return [target_compile $source $dest $type $options]
44 } result options
45 cd $saved_cwd
46
47 if { $save_multilib_flag != "" } {
48 unset_board_info "multilib_flags"
49 set_board_info multilib_flags $save_multilib_flag
50 }
51
52 return -options $options $result
53 }
54
55 # Compile some Ada code.
56
57 proc gdb_compile_ada {source dest type options} {
58
59 set srcdir [file dirname $source]
60 set gprdir [file dirname $srcdir]
61 set objdir [file dirname $dest]
62
63 file delete $dest
64
65 # Although strictly not necessary, we force the recompilation
66 # of all units (additional_flags=-f). This is what is done
67 # when using GCC to build programs in the other languages,
68 # and it avoids using a stray objfile file from a long-past
69 # run, for instance.
70 append options " ada"
71 append options " additional_flags=-f"
72 append options " additional_flags=-I$srcdir"
73
74 set result [target_compile_ada_from_dir \
75 $objdir [file tail $source] $dest $type $options]
76
77 # The Ada build always produces some output, even when the build
78 # succeeds. Thus, we can not use the output the same way we do in
79 # gdb_compile to determine whether the build has succeeded or not.
80 # We therefore simply check whether the dest file has been created
81 # or not. Unless not present, the build has succeeded.
82 if [file exists $dest] { set result "" }
83 gdb_compile_test $source $result
84 return $result
85 }
86
87 # Like standard_testfile, but for Ada. Historically the Ada tests
88 # used a different naming convention from many of the other gdb tests,
89 # and this difference was preserved during the conversion to
90 # standard_testfile. DIR defaults to the base name of the test case;
91 # but can be overridden to find sources in a different subdirectory of
92 # gdb.ada.
93
94 proc standard_ada_testfile {base_file {dir ""}} {
95 global gdb_test_file_name srcdir subdir
96 global testdir testfile srcfile binfile
97
98 if {$dir == ""} {
99 set testdir $gdb_test_file_name
100 } else {
101 set testdir $dir
102 }
103
104 set testfile $base_file
105 set srcfile $srcdir/$subdir/$testdir/$testfile.adb
106 set binfile [standard_output_file $testfile]
107 }
108
109 # A helper function to find the appropriate version of a tool.
110 # TOOL is the tool's name, e.g., "gnatbind" or "gnatlink".
111
112 proc find_ada_tool {tool} {
113 set upper [string toupper $tool]
114
115 set targname ${upper}_FOR_TARGET
116 global $targname
117 if {[info exists $targname]} {
118 return $targname
119 }
120
121 global tool_root_dir
122 set root "$tool_root_dir/gcc"
123 set result ""
124
125 if {![is_remote host]} {
126 set result [lookfor_file $root $tool]
127 }
128
129 if {$result == ""} {
130 set result [transform $tool]
131 }
132
133 return $result
134 }
135
136 # Return 1 if gnatmake is at least version $MAJOR.x.x
137
138 proc gnatmake_version_at_least { major } {
139 set gnatmake [gdb_find_gnatmake]
140 set gnatmake [lindex [split $gnatmake] 0]
141 if {[catch {exec $gnatmake --version} output]} {
142 return 0
143 }
144 if { [regexp {GNATMAKE ([^ .]+).([^ .]+).([^ .]+)} $output \
145 match gnatmake_major gnatmake_minor gnatmake_micro] } {
146 if { $gnatmake_major >= $major } {
147 return 1
148 } else {
149 return 0
150 }
151 }
152
153 # Unknown, return 1
154 return 1
155 }
156
157 # Return 1 if the GNAT runtime appears to have debug info.
158
159 gdb_caching_proc gnat_runtime_has_debug_info {
160 global srcdir
161
162 set src "$srcdir/lib/gnat_debug_info_test.adb"
163 set dst [standard_output_file "gnat_debug_info_test"]
164
165 if { [gdb_compile_ada $src $dst executable {debug}] != "" } {
166 fail "failed to compile gnat-debug-info test binary"
167 return 0
168 }
169
170 clean_restart $dst
171
172 if { ! [runto "GNAT_Debug_Info_Test"] } {
173 fail "failed to run to GNAT_Debug_Info_Test"
174 return 0
175 }
176
177 set has_debug_info 0
178
179 gdb_test_multiple "whatis __gnat_debug_raise_exception" "" {
180 -re "type = <text variable, no debug info>" { }
181 -re "type = void" {
182 set has_debug_info 1
183 }
184 default {
185 # Some other unexpected output...
186 fail $gdb_test_name
187 }
188 }
189
190 return $has_debug_info
191 }