Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2019-2020 Free Software Foundation, Inc. |
2ff0a947 TT |
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 | if {[skip_shlib_tests]} { | |
17 | return 0 | |
18 | } | |
19 | ||
20 | load_lib "ada.exp" | |
21 | ||
7a82e903 PA |
22 | if { [skip_ada_tests] } { return -1 } |
23 | ||
2ff0a947 TT |
24 | standard_ada_testfile foo |
25 | ||
2ff0a947 TT |
26 | set srcfile2 [file join [file dirname $srcfile] some_package.adb] |
27 | set ofile2 [standard_output_file some_package.o] | |
28 | set sofile [standard_output_file libsome_package.so] | |
29 | ||
30 | set outdir [file dirname $binfile] | |
31 | ||
32 | # To make an Ada shared library we have to jump through a number of | |
33 | # hoops. | |
34 | ||
35 | # First compile to a .o. We can't compile directly to a .so because | |
36 | # GCC rejects that: | |
37 | # $ gcc -g -shared -fPIC -o qqz.o some_package.adb | |
38 | # gcc: error: -c or -S required for Ada | |
39 | # And, we can't compile in "ada" mode because dejagnu will try to | |
40 | # invoke gnatmake, which we don't want. | |
41 | if {[target_compile_ada_from_dir $outdir $srcfile2 $ofile2 \ | |
42 | object {debug additional_flags=-fPIC}] != ""} { | |
43 | return -1 | |
44 | } | |
45 | ||
46 | # Now turn the .o into a shared library. | |
47 | if {[gdb_compile_shlib $ofile2 $sofile \ | |
48 | {debug additional_flags=-fPIC}] != ""} { | |
49 | return -1 | |
50 | } | |
51 | ||
5d7e6ed0 TV |
52 | # Set linkarg such that the executable can find the shared library. |
53 | if {[istarget "*-*-mingw*"] | |
54 | || [istarget *-*-cygwin*] | |
55 | || [istarget *-*-pe*] | |
56 | || [istarget arm*-*-symbianelf*]} { | |
57 | # Do not need anything. | |
58 | set linkarg "" | |
59 | } elseif {[istarget *-*-freebsd*] || [istarget *-*-openbsd*]} { | |
60 | set linkarg "-Wl,-rpath,$outdir" | |
61 | } else { | |
62 | set linkarg "-Wl,-rpath,\\\$ORIGIN" | |
2ff0a947 TT |
63 | } |
64 | ||
5d7e6ed0 TV |
65 | # Make sure we link against the shared GNAT run time. |
66 | set gnatbind_options [list -bargs -shared -margs] | |
2ff0a947 | 67 | |
5d7e6ed0 TV |
68 | # Link against the shared library. |
69 | set gnatlink_options [list -largs $linkarg -Wl,-lsome_package -margs] | |
2ff0a947 | 70 | |
5d7e6ed0 TV |
71 | set options [list debug] |
72 | foreach option [concat $gnatbind_options $gnatlink_options] { | |
73 | lappend options [concat "additional_flags=" $option] | |
74 | } | |
75 | ||
76 | # Create executable. | |
77 | if {[gdb_compile_ada $srcfile $binfile executable $options] != ""} { | |
78 | return -1 | |
2ff0a947 TT |
79 | } |
80 | ||
81 | clean_restart ${testfile} | |
82 | ||
83 | if {![runto_main]} then { | |
84 | return 0 | |
85 | } | |
86 | ||
60ff3cd7 AB |
87 | set can_catch_exceptions 0 |
88 | gdb_test_multiple "catch exception some_kind_of_error" "" { | |
89 | -re "Catchpoint \[0-9\]+: `some_kind_of_error' Ada exception\r\n$gdb_prompt $" { | |
90 | pass $gdb_test_name | |
91 | set can_catch_exceptions 1 | |
92 | } | |
2ff0a947 | 93 | |
60ff3cd7 AB |
94 | -re "Your Ada runtime appears to be missing some debugging information.\r\nCannot insert Ada exception catchpoint in this configuration.\r\n$gdb_prompt $" { |
95 | unsupported $gdb_test_name | |
96 | } | |
97 | } | |
37f6a7f4 | 98 | |
60ff3cd7 AB |
99 | if { $can_catch_exceptions } { |
100 | gdb_test "cont" \ | |
101 | "Catchpoint \[0-9\]+, .* at .*foo\.adb:\[0-9\]+.*" \ | |
102 | "caught the exception" | |
103 | ||
104 | gdb_test "print \$_ada_exception = some_package.some_kind_of_error'Address" \ | |
105 | " = true" | |
106 | } |