Commit | Line | Data |
---|---|---|
42a4f53d | 1 | # Copyright 2011-2019 Free Software Foundation, Inc. |
3b2a0cf2 JB |
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 | # The same tests as in jit.exp, but loading JITer itself from a shared | |
17 | # library. | |
18 | ||
3b2a0cf2 | 19 | if {[skip_shlib_tests]} { |
84c93cd5 | 20 | untested "skipping shared library tests" |
3b2a0cf2 JB |
21 | return -1 |
22 | } | |
23 | ||
4c93b1db | 24 | if {[get_compiler_info]} { |
84c93cd5 | 25 | untested "could not get compiler info" |
3b2a0cf2 JB |
26 | return 1 |
27 | } | |
28 | ||
29 | # | |
30 | # test running programs | |
31 | # | |
32 | ||
33 | set testfile jit-dlmain | |
34 | set srcfile ${testfile}.c | |
f8b41b00 | 35 | set binfile [standard_output_file ${testfile}] |
3b2a0cf2 | 36 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } { |
84c93cd5 | 37 | untested "failed to compile" |
3b2a0cf2 JB |
38 | return -1 |
39 | } | |
40 | ||
41 | set testfile2 jit-main | |
42 | set srcfile2 ${testfile2}.c | |
f8b41b00 | 43 | set binfile2 [standard_output_file ${testfile2}.so] |
724f4f80 | 44 | set binfile2_dlopen [shlib_target_file ${testfile2}.so] |
3b2a0cf2 | 45 | if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug additional_flags="-DMAIN=jit_dl_main"}] != "" } { |
84c93cd5 | 46 | untested "failed to compile main shared library" |
3b2a0cf2 JB |
47 | return -1 |
48 | } | |
49 | ||
50 | set solib_testfile "jit-solib" | |
51 | set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c" | |
f8b41b00 | 52 | set solib_binfile [standard_output_file ${solib_testfile}.so] |
724f4f80 | 53 | set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.so" |
3b2a0cf2 JB |
54 | |
55 | # Note: compiling without debug info: the library goes through symbol | |
56 | # renaming by munging on its symbol table, and that wouldn't work for .debug | |
57 | # sections. Also, output for "info function" changes when debug info is resent. | |
58 | if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } { | |
84c93cd5 | 59 | untested "failed to compile jit shared library" |
3b2a0cf2 JB |
60 | return -1 |
61 | } | |
62 | ||
7817ea46 | 63 | set solib_binfile_target [gdb_remote_download target ${solib_binfile}] |
724f4f80 | 64 | |
0a251e08 YQ |
65 | proc one_jit_test {count match_str} { |
66 | with_test_prefix "one_jit_test-$count" { | |
67 | global verbose testfile srcfile2 binfile2 binfile2_dlopen solib_binfile_target solib_binfile_test_msg | |
68 | ||
69 | clean_restart $testfile | |
d9019901 | 70 | gdb_load_shlib $binfile2 |
0a251e08 YQ |
71 | |
72 | # This is just to help debugging when things fail | |
73 | if {$verbose > 0} { | |
74 | gdb_test "set debug jit 1" | |
75 | } | |
76 | ||
77 | if { ![runto_main] } { | |
bc6c7af4 | 78 | fail "can't run to main" |
0a251e08 YQ |
79 | return |
80 | } | |
81 | ||
82 | gdb_breakpoint [gdb_get_line_number "break here before-dlopen" ] | |
83 | gdb_continue_to_breakpoint "break here before-dlopen" | |
84 | # Poke desired values directly into inferior instead of using "set args" | |
85 | # because "set args" does not work under gdbserver. | |
86 | gdb_test_no_output "set var jit_libname = \"$binfile2_dlopen\"" | |
87 | ||
88 | gdb_breakpoint [gdb_get_line_number "break here after-dlopen" ] | |
89 | gdb_continue_to_breakpoint "break here after-dlopen" | |
90 | ||
91 | gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 0} $srcfile2]" | |
92 | gdb_continue_to_breakpoint "break here 0" | |
93 | ||
94 | gdb_test_no_output "set var argc = 2" | |
95 | gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\"" | |
96 | gdb_test_no_output "set var count = $count" | |
97 | ||
98 | gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 1} $srcfile2]" | |
99 | gdb_continue_to_breakpoint "break here 1" | |
100 | ||
101 | gdb_test "info function jit_function" "$match_str" | |
102 | ||
103 | # This is just to help debugging when things fail | |
104 | if {$verbose > 0} { | |
105 | gdb_test "maintenance print objfiles" | |
106 | gdb_test "maintenance info break" | |
107 | } | |
108 | ||
109 | gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 2} $srcfile2]" | |
110 | gdb_continue_to_breakpoint "break here 2" | |
111 | # All jit librares must have been unregistered | |
112 | gdb_test "info function jit_function" \ | |
113 | "All functions matching regular expression \"jit_function\":" | |
3b2a0cf2 | 114 | } |
0a251e08 | 115 | } |
3b2a0cf2 JB |
116 | |
117 | one_jit_test 1 "${hex} jit_function_0000" | |
118 | one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" | |
6571a381 TT |
119 | |
120 | # We don't intend to load the .so as a JIT debuginfo reader, but we | |
121 | # need some handy file name for a completion test. | |
122 | gdb_test \ | |
123 | "complete jit-reader-load [standard_output_file ${solib_testfile}.s]" \ | |
124 | "jit-reader-load $solib_binfile" \ | |
125 | "test jit-reader-load filename completion" |