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