Tests for validate symbol file using build-id
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / solib-mismatch.exp
1 # Copyright 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 standard_testfile
17 set executable $testfile
18
19 if ![is_remote target] {
20 untested "only gdbserver supports build-id reporting"
21 return -1
22 }
23 if [is_remote host] {
24 untested "only local host is currently supported"
25 return -1
26 }
27
28 # Test overview:
29 # generate two shared objects. One that will be used by the process
30 # and another, modified, that will be found by gdb. Gdb should
31 # detect the mismatch and refuse to use mismatched shared object.
32
33 if { [get_compiler_info] } {
34 untested "get_compiler_info failed."
35 return -1
36 }
37
38 # First version of the object, to be loaded by ld.
39 set srclibfilerun ${testfile}-lib.c
40
41 # Modified version of the object to be loaded by gdb
42 # Code in -libmod.c is tuned so it gives a mismatch but
43 # leaves .dynamic at the same point.
44 set srclibfilegdb ${testfile}-libmod.c
45
46 # So file name:
47 set binlibfilebase lib${testfile}.so
48
49 # Setup run directory (where program is run from)
50 # It contains executable and '-lib' version of the library.
51 set binlibfiledirrun [standard_output_file ${testfile}_wd]
52 set binlibfilerun ${binlibfiledirrun}/${binlibfilebase}
53
54 # Second solib version is in current directory, '-libmod' version.
55 set binlibfiledirgdb [standard_output_file ""]
56 set binlibfilegdb ${binlibfiledirgdb}/${binlibfilebase}
57
58 # Executable
59 set srcfile ${testfile}.c
60 set executable ${testfile}
61
62 file delete -force -- "${binlibfiledirrun}"
63 file mkdir "${binlibfiledirrun}"
64
65 set exec_opts {}
66
67 if { ![istarget "*-*-nto-*"] } {
68 lappend exec_opts "shlib_load"
69 }
70
71 lappend exec_opts "additional_flags=-DDIRNAME\=\"${binlibfiledirrun}\" -DLIB\=\"./${binlibfilebase}\""
72 lappend exec_opts "debug"
73
74 if { [build_executable $testfile.exp $executable $srcfile $exec_opts] != 0 } {
75 return -1
76 }
77
78 if { [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfilerun}" "${binlibfilerun}" [list debug ldflags=-Wl,--build-id]] != ""
79 || [gdb_gnu_strip_debug "${binlibfilerun}"]
80 || [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfilegdb}" "${binlibfilegdb}" [list debug ldflags=-Wl,--build-id]] != "" } {
81 untested "compilation failed."
82 return -1
83 }
84
85 proc solib_matching_test { solibfile symsloaded } {
86 global gdb_prompt
87 global testfile
88 global executable
89 global srcdir
90 global subdir
91 global binlibfiledirrun
92 global binlibfiledirgdb
93 global srcfile
94
95 clean_restart ${binlibfiledirrun}/${executable}
96
97 gdb_test_no_output "set solib-search-path \"${binlibfiledirgdb}\"" ""
98 if { [gdb_test "cd ${binlibfiledirgdb}" "" ""] != 0 } {
99 untested "cd ${binlibfiledirgdb}"
100 return -1
101 }
102
103 # Do not auto load shared libraries, the test needs to have control
104 # over when the relevant output gets printed.
105 gdb_test_no_output "set auto-solib-add off" ""
106
107 if ![runto "${srcfile}:[gdb_get_line_number "set breakpoint 1 here"]"] {
108 return -1
109 }
110
111 gdb_test "sharedlibrary" "" ""
112
113 set nocrlf "\[^\r\n\]*"
114 set expected_header "From${nocrlf}To${nocrlf}Syms${nocrlf}Read${nocrlf}Shared${nocrlf}"
115 set expected_line "${symsloaded}${nocrlf}${solibfile}"
116
117 gdb_test "info sharedlibrary ${solibfile}" \
118 "${expected_header}\r\n.*${expected_line}.*" \
119 "Symbols for ${solibfile} loaded: expected '${symsloaded}'"
120
121 return 0
122 }
123
124 # Copy binary to working dir so it pulls in the library from that dir
125 # (by the virtue of $ORIGIN).
126 file copy -force "${binlibfiledirgdb}/${executable}" \
127 "${binlibfiledirrun}/${executable}"
128
129 # Test unstripped, .dynamic matching
130 with_test_prefix "test unstripped, .dynamic matching" {
131 solib_matching_test "${binlibfilebase}" "No"
132 }
133
134 # Keep original so for debugging purposes
135 file copy -force "${binlibfilegdb}" "${binlibfilegdb}-orig"
136 set objcopy_program [transform objcopy]
137 set result [catch "exec $objcopy_program --only-keep-debug ${binlibfilegdb}"]
138 if {$result != 0} {
139 untested "test --only-keep-debug (objcopy)"
140 }
141
142 # Test --only-keep-debug, .dynamic matching so
143 with_test_prefix "test --only-keep-debug" {
144 solib_matching_test "${binlibfilebase}" "No"
145 }
146
147 # Keep previous so for debugging puroses
148 file copy -force "${binlibfilegdb}" "${binlibfilegdb}-orig1"
149
150 # Copy loaded so over the one gdb will find
151 file copy -force "${binlibfilerun}" "${binlibfilegdb}"
152
153 # Now test it does not mis-invalidate matching libraries
154 with_test_prefix "test matching libraries" {
155 solib_matching_test "${binlibfilebase}" "Yes"
156 }
This page took 0.033114 seconds and 4 git commands to generate.