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