ca6e6c3430b190d30a53ab0daf56e48707ca134a
[platform/upstream/gdb.git] / gdb / testsuite / gdb.base / jit.exp
1 # Copyright 2011-2014 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 if {[skip_shlib_tests]} {
17     untested jit.exp
18     return -1
19 }
20
21 if {[get_compiler_info]} {
22     warning "Could not get compiler info"
23     untested jit.exp
24     return 1
25 }
26
27 #
28 # test running programs
29 #
30
31 proc compile_jit_test {testname options} {
32     global testfile srcfile binfile srcdir subdir
33     global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
34     global solib_binfile_target
35
36     set testfile jit-main
37     set srcfile ${testfile}.c
38     set binfile [standard_output_file $testfile]
39     if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
40               executable [concat debug $options]] != "" } {
41         untested $testname
42         return -1
43     }
44
45     set solib_testfile "jit-solib"
46     set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
47     set solib_binfile [standard_output_file ${solib_testfile}.so]
48     set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}.so"
49
50     # Note: compiling without debug info: the library goes through
51     # symbol renaming by munging on its symbol table, and that
52     # wouldn't work for .debug sections.  Also, output for "info
53     # function" changes when debug info is present.
54     if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {-fPIC}] != "" } {
55         untested $testname
56         return -1
57     }
58
59     if {[is_remote target]} {
60         set solib_binfile_target [gdb_download ${solib_binfile}]
61     } else {
62         set solib_binfile_target $solib_binfile
63     }
64
65     return 0
66 }
67
68 proc one_jit_test {count match_str} {
69     with_test_prefix "one_jit_test-$count" {
70         global verbose testfile solib_binfile_target solib_binfile_test_msg
71
72         clean_restart $testfile
73
74         # This is just to help debugging when things fail
75         if {$verbose > 0} {
76             gdb_test "set debug jit 1"
77         }
78
79         if { ![runto_main] } {
80             fail "Can't run to main"
81             return
82         }
83
84         gdb_breakpoint [gdb_get_line_number "break here 0"]
85         gdb_continue_to_breakpoint "break here 0"
86
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 argc = 2"
90         gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
91         gdb_test_no_output "set var count = $count"
92
93         gdb_breakpoint [gdb_get_line_number "break here 1"]
94         gdb_continue_to_breakpoint "break here 1"
95
96         gdb_test "info function ^jit_function" "$match_str"
97
98         # This is just to help debugging when things fail
99         if {$verbose > 0} {
100             gdb_test "maintenance print objfiles"
101             gdb_test "maintenance info break"
102         }
103
104         gdb_breakpoint [gdb_get_line_number "break here 2"]
105         gdb_continue_to_breakpoint "break here 2"
106         # All jit librares must have been unregistered
107         gdb_test "info function jit_function" \
108             "All functions matching regular expression \"jit_function\":"
109     }
110 }
111
112 if {[compile_jit_test jit.exp {}] < 0} {
113     return
114 }
115 one_jit_test 1 "${hex}  jit_function_0000"
116 one_jit_test 2 "${hex}  jit_function_0000\[\r\n\]+${hex}  jit_function_0001"
117
118 with_test_prefix PIE {
119     if {[compile_jit_test "jit.exp PIE tests" \
120              {additional_flags=-fPIE ldflags=-pie}] < 0} {
121         return
122     }
123
124     one_jit_test 1 "${hex}  jit_function_0000"
125 }