Imported Upstream version 7.9
[platform/upstream/gdb.git] / gdb / testsuite / gdb.base / gnu-ifunc.exp
1 # Copyright (C) 2009-2015 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     return 0
18 }
19
20 standard_testfile .c
21 set executable ${testfile}
22 set staticexecutable ${executable}-static
23 set staticbinfile [standard_output_file ${staticexecutable}]
24
25 set libfile "${testfile}-lib"
26 set libsrc ${libfile}.c
27 set lib_so [standard_output_file ${libfile}.so]
28 # $lib_o must not have {debug}, it would override the STT_GNU_IFUNC ELF markers.
29 set lib_o [standard_output_file ${libfile}.o]
30
31 # We need DWARF for the "final" function as we "step" into the function and GDB
32 # would step-over the "final" function if there would be no line number debug
33 # information (DWARF) available.
34 #
35 # We must not have DWARF for the "gnu_ifunc" function as DWARF has no way to
36 # express the STT_GNU_IFUNC type and it would be considered as a regular
37 # function due to DWARF by GDB.  In ELF gnu-ifunc is expressed by the
38 # STT_GNU_IFUNC type.
39 #
40 # Both functions need to be in the same shared library file but
41 # gdb_compile_shlib has no way to specify source-specific compilation options.
42 #
43 # Therefore $libfile contains only the STT_GNU_IFUNC function with no DWARF
44 # referencing all the other parts from the main executable with DWARF.
45
46 set lib_opts {}
47 set exec_opts [list debug shlib=$lib_so]
48
49 if [get_compiler_info] {
50     return -1
51 }
52
53 if { [gdb_compile_shlib ${srcdir}/${subdir}/$libsrc $lib_so $lib_opts] != ""
54      || [gdb_compile ${srcdir}/${subdir}/$srcfile $binfile executable $exec_opts] != ""} {
55     untested "Could not compile dynamic executable $binfile."
56     return -1
57 }
58
59 # Start with a fresh gdb.
60
61 clean_restart $executable
62 gdb_load_shlibs ${lib_so}
63
64 if ![runto_main] then {
65     fail "Can't run to main"
66     return 1
67 }
68
69 # The "if" condition is artifical to test regression of a former patch.
70 gdb_breakpoint "[gdb_get_line_number "break-at-nextcall"] if i && gnu_ifunc (i) != 42"
71
72 gdb_breakpoint [gdb_get_line_number "break-at-call"]
73 gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*"
74
75 # Test GDB will automatically indirect the call.
76
77 gdb_test "p gnu_ifunc (3)" " = 4"
78
79 # Test GDB will skip the gnu_ifunc resolver on first call.
80
81 gdb_test "step" "\r\nfinal .*"
82
83 # Test GDB will not break before the final chosen implementation.
84
85 # Also test a former patch regression:
86 # Continuing.
87 # Error in testing breakpoint condition:
88 # Attempt to take address of value not located in memory.
89
90 # Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33
91
92 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint .* (at|in) .*break-at-nextcall.*" \
93          "continue to break-at-nextcall"
94
95 gdb_breakpoint "gnu_ifunc"
96
97 gdb_continue_to_breakpoint "nextcall gnu_ifunc"
98
99 gdb_test "frame" "#0 +(0x\[0-9a-f\]+ in +)?final \\(.*" "nextcall gnu_ifunc skipped"
100
101
102 # Check any commands not doing an inferior call access the address of the
103 # STT_GNU_IFUNC resolver, not the target function.
104
105 if {[istarget powerpc64-*] && [is_lp64_target]} {
106     # With only minimal symbols GDB provides the function descriptors.  With
107     # full debug info the function code would be displayed.
108     set func_prefix {\.}
109 } else {
110     set func_prefix {}
111 }
112
113 gdb_test "p gnu_ifunc" " = {<text gnu-indirect-function variable, no debug info>} 0x\[0-9a-f\]+ <${func_prefix}gnu_ifunc>" "p gnu_ifunc executing"
114 gdb_test "info sym gnu_ifunc" "gnu_ifunc in section .*" "info sym gnu_ifunc executing"
115
116 set test "info addr gnu_ifunc"
117 gdb_test_multiple $test $test {
118     -re "Symbol \"gnu_ifunc\" is at (0x\[0-9a-f\]+) in .*$gdb_prompt $" {
119         pass $test
120     }
121 }
122 gdb_test "info sym $expect_out(1,string)" "gnu_ifunc in section .*" "info sym <gnu_ifunc-address>"
123
124
125 # Test statically linked ifunc resolving during inferior start.
126 # https://bugzilla.redhat.com/show_bug.cgi?id=624967
127
128 # Compile $staticbinfile separately as it may exit on error (ld/12595).
129
130 if { [gdb_compile ${srcdir}/${subdir}/$libsrc $lib_o object {}] != ""
131      || [gdb_compile "${srcdir}/${subdir}/$srcfile $lib_o" $staticbinfile executable {debug}] != "" } {
132     untested "Could not compile static executable $staticbinfile."
133     return -1
134 }
135
136 clean_restart $staticexecutable
137
138 gdb_breakpoint "gnu_ifunc"
139 gdb_breakpoint "main"
140 gdb_run_cmd
141 gdb_test "" "Breakpoint \[0-9\]*, main .*" "static gnu_ifunc"