1# Copyright 2011 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# The same tests as in jit.exp, but loading JITer itself from a shared 17# library. 18 19if $tracelevel { 20 strace $tracelevel 21} 22 23if {[skip_shlib_tests]} { 24 untested jit-so.exp 25 return -1 26} 27 28if {[get_compiler_info not-used]} { 29 warning "Could not get compiler info" 30 untested jit-so.exp 31 return 1 32} 33 34# 35# test running programs 36# 37 38set testfile jit-dlmain 39set srcfile ${testfile}.c 40set binfile ${objdir}/${subdir}/${testfile} 41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } { 42 untested jit-so.exp 43 return -1 44} 45 46set testfile2 jit-main 47set srcfile2 ${testfile2}.c 48set binfile2 ${objdir}/${subdir}/${testfile2}.so 49if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug additional_flags="-DMAIN=jit_dl_main"}] != "" } { 50 untested jit.exp 51 return -1 52} 53 54set solib_testfile "jit-solib" 55set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c" 56set solib_binfile "${objdir}/${subdir}/${solib_testfile}.so" 57set solib_binfile_test_msg "OBJDIR/${subdir}/${solib_testfile}.so" 58 59# Note: compiling without debug info: the library goes through symbol 60# renaming by munging on its symbol table, and that wouldn't work for .debug 61# sections. Also, output for "info function" changes when debug info is resent. 62if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } { 63 untested jit-so.exp 64 return -1 65} 66 67proc one_jit_test {count match_str} { 68 global verbose testfile srcfile2 binfile2 solib_binfile solib_binfile_test_msg pf_prefix 69 70 set old_pf_prefix $pf_prefix 71 set pf_prefix "one_jit_test-$count" 72 73 clean_restart $testfile 74 75 # This is just to help debugging when things fail 76 if {$verbose > 0} { 77 gdb_test "set debug jit 1" 78 } 79 80 if { ![runto_main] } { 81 fail "Can't run to main" 82 return 83 } 84 85 gdb_breakpoint [gdb_get_line_number "break here before-dlopen" ] 86 gdb_continue_to_breakpoint "break here before-dlopen" 87 # Poke desired values directly into inferior instead of using "set args" 88 # because "set args" does not work under gdbserver. 89 gdb_test_no_output "set var jit_libname = \"$binfile2\"" 90 91 gdb_breakpoint [gdb_get_line_number "break here after-dlopen" ] 92 gdb_continue_to_breakpoint "break here after-dlopen" 93 94 gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 0} $srcfile2]" 95 gdb_continue_to_breakpoint "break here 0" 96 97 gdb_test_no_output "set var argc = 2" 98 gdb_test_no_output "set var libname = \"$solib_binfile\"" "set var libname = \"$solib_binfile_test_msg\"" 99 gdb_test_no_output "set var count = $count" 100 101 gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 1} $srcfile2]" 102 gdb_continue_to_breakpoint "break here 1" 103 104 gdb_test "info function jit_function" "$match_str" 105 106 # This is just to help debugging when things fail 107 if {$verbose > 0} { 108 gdb_test "maintenance print objfiles" 109 gdb_test "maintenance info break" 110 } 111 112 gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 2} $srcfile2]" 113 gdb_continue_to_breakpoint "break here 2" 114 # All jit librares must have been unregistered 115 gdb_test "info function jit_function" \ 116 "All functions matching regular expression \"jit_function\":" \ 117 set pf_prefix $old_pf_prefix 118} 119 120one_jit_test 1 "${hex} jit_function_0000" 121one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 122