]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-dlopen-stap-probe-test.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-dlopen-stap-probe-test.patch
CommitLineData
f412e1b4
PS
1commit 5bfdc32cd3bf373c3b02e1fd864ed8ceab0292b2
2Author: Jan Kratochvil <jan.kratochvil@redhat.com>
3Date: Mon Aug 8 12:08:53 2011 +0200
4
5 +testcase
6
7Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.threads/dlopen-libpthread-lib.c
8===================================================================
9--- /dev/null 1970-01-01 00:00:00.000000000 +0000
10+++ gdb-7.3.50.20110722/gdb/testsuite/gdb.threads/dlopen-libpthread-lib.c 2011-08-10 18:30:56.000000000 +0200
11@@ -0,0 +1,40 @@
12+/* This testcase is part of GDB, the GNU debugger.
13+
14+ Copyright 2011 Free Software Foundation, Inc.
15+
16+ This program is free software; you can redistribute it and/or modify
17+ it under the terms of the GNU General Public License as published by
18+ the Free Software Foundation; either version 3 of the License, or
19+ (at your option) any later version.
20+
21+ This program is distributed in the hope that it will be useful,
22+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+ GNU General Public License for more details.
25+
26+ You should have received a copy of the GNU General Public License
27+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
28+
29+#include <pthread.h>
30+#include <assert.h>
31+
32+static void *
33+tfunc (void *arg)
34+{
35+ void (*notifyp) (void) = arg;
36+
37+ notifyp ();
38+}
39+
40+void
41+f (void (*notifyp) (void))
42+{
43+ pthread_t t;
44+ int i;
45+
46+ i = pthread_create (&t, NULL, tfunc, notifyp);
47+ assert (i == 0);
48+
49+ i = pthread_join (t, NULL);
50+ assert (i == 0);
51+}
52Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.threads/dlopen-libpthread.c
53===================================================================
54--- /dev/null 1970-01-01 00:00:00.000000000 +0000
55+++ gdb-7.3.50.20110722/gdb/testsuite/gdb.threads/dlopen-libpthread.c 2011-08-10 18:30:56.000000000 +0200
56@@ -0,0 +1,46 @@
57+/* This testcase is part of GDB, the GNU debugger.
58+
59+ Copyright 2011 Free Software Foundation, Inc.
60+
61+ This program is free software; you can redistribute it and/or modify
62+ it under the terms of the GNU General Public License as published by
63+ the Free Software Foundation; either version 3 of the License, or
64+ (at your option) any later version.
65+
66+ This program is distributed in the hope that it will be useful,
67+ but WITHOUT ANY WARRANTY; without even the implied warranty of
68+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69+ GNU General Public License for more details.
70+
71+ You should have received a copy of the GNU General Public License
72+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
73+
74+#include <dlfcn.h>
75+#include <stddef.h>
76+#include <assert.h>
77+
78+static const char *volatile filename;
79+
80+static void
81+notify (void)
82+{
83+ filename = NULL; /* notify-here */
84+}
85+
86+int
87+main (void)
88+{
89+ void *h;
90+ void (*fp) (void (*) (void));
91+
92+ assert (filename != NULL);
93+ h = dlopen (filename, RTLD_LAZY);
94+ assert (h != NULL);
95+
96+ fp = dlsym (h, "f");
97+ assert (fp != NULL);
98+
99+ fp (notify);
100+
101+ return 0;
102+}
103Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.threads/dlopen-libpthread.exp
104===================================================================
105--- /dev/null 1970-01-01 00:00:00.000000000 +0000
106+++ gdb-7.3.50.20110722/gdb/testsuite/gdb.threads/dlopen-libpthread.exp 2011-08-10 18:30:56.000000000 +0200
107@@ -0,0 +1,74 @@
108+# Copyright 2011 Free Software Foundation, Inc.
109+#
110+# This program is free software; you can redistribute it and/or modify
111+# it under the terms of the GNU General Public License as published by
112+# the Free Software Foundation; either version 3 of the License, or
113+# (at your option) any later version.
114+#
115+# This program is distributed in the hope that it will be useful,
116+# but WITHOUT ANY WARRANTY; without even the implied warranty of
117+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118+# GNU General Public License for more details.
119+#
120+# You should have received a copy of the GNU General Public License
121+# along with this program. If not, see <http://www.gnu.org/licenses/>.
122+
123+if {![istarget *-linux*] || [skip_shlib_tests]} {
124+ return 0
125+}
126+
127+load_lib prelink-support.exp
128+
129+set testfile "dlopen-libpthread"
130+set srcmainfile ${testfile}.c
131+set srclibfile ${testfile}-lib.c
132+set executable ${testfile}
133+set binfile_lib ${objdir}/${subdir}/${executable}.so
134+set binfile ${objdir}/${subdir}/${executable}
135+set lib_dlopen [shlib_target_file ${executable}.so]
136+
137+# Use build_executable_own_libs as prelinked libpthread.so can produce false
138+# PASS - it is OK if GDB processes it still before relocation.
139+
140+set relink_args [build_executable_own_libs ${testfile}.exp ${executable}.so $srclibfile {debug shlib_pthreads} no]
141+if {$relink_args == "" || ![prelink_no $relink_args]
142+ || [prepare_for_testing ${testfile}.exp ${executable} ${srcmainfile} {debug shlib_load}] } {
143+ return -1
144+}
145+gdb_load_shlibs $binfile_lib
146+
147+if { ![runto_main] } {
148+ return -1
149+}
150+
151+set test "print _dl_debug_notify"
152+gdb_test_multiple $test $test {
153+ -re " 0x\[0-9a-f\]+ <_dl_debug_notify>\r\n$gdb_prompt $" {
154+ pass $test
155+ }
156+ -re "No symbol \"_dl_debug_notify\" in current context\\.\r\n$gdb_prompt $" {
157+ xfail $test
158+ untested ${testfile}.exp
159+ return
160+ }
161+}
162+
163+set test "libpthread.so not found"
164+gdb_test_multiple "info sharedlibrary" $test {
165+ -re "/libpthread\\.so.*\r\n$gdb_prompt $" {
166+ fail $test
167+ }
168+ -re "/libc\\.so.*\r\n$gdb_prompt $" {
169+ pass $test
170+ }
171+}
172+
173+gdb_test "set variable filename=\"$lib_dlopen\""
174+
175+gdb_breakpoint "notify"
176+
177+# The error was:
178+# Cannot find new threads: generic error
179+gdb_continue_to_breakpoint "notify" ".* notify-here .*"
180+
181+gdb_test "info sharedlibrary" {/libpthread\.so.*} "libpthread.so found"
182Index: gdb-7.3.50.20110722/gdb/testsuite/lib/gdb.exp
183===================================================================
184--- gdb-7.3.50.20110722.orig/gdb/testsuite/lib/gdb.exp 2011-08-10 18:30:55.000000000 +0200
185+++ gdb-7.3.50.20110722/gdb/testsuite/lib/gdb.exp 2011-08-10 18:30:56.000000000 +0200
186@@ -3563,30 +3563,49 @@ proc build_executable { testname executa
187 set sources ${executable}.c
188 }
189
190- set binfile ${objdir}/${subdir}/${executable}
191-
192- set objects {}
193- for {set i 0} "\$i<[llength $sources]" {incr i} {
194- set s [lindex $sources $i]
195- if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
196- untested $testname
197- return -1
198- }
199- lappend objects "${binfile}${i}.o"
200+ # get_compiler_info by gdb_compile_shlib and gdb_compile_shlib_pthreads.
201+ set info_options ""
202+ if { [lsearch -exact $options "c++"] >= 0 } {
203+ set info_options "c++"
204 }
205-
206- if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
207- untested $testname
208+ if [get_compiler_info binfile_unused ${info_options}] {
209 return -1
210 }
211
212- set info_options ""
213- if { [lsearch -exact $options "c++"] >= 0 } {
214- set info_options "c++"
215+ set binfile ${objdir}/${subdir}/${executable}
216+
217+ set func gdb_compile
218+ set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
219+ if {$func_index != -1} {
220+ set func "${func}_[lindex $options $func_index]"
221 }
222- if [get_compiler_info ${binfile} ${info_options}] {
223+
224+ # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
225+ # parameter. They also requires $sources while gdb_compile and
226+ # gdb_compile_pthreads require $objects.
227+ if [string match gdb_compile_shlib* $func] {
228+ set sources_path {}
229+ foreach s $sources {
230+ lappend sources_path "${srcdir}/${subdir}/${s}"
231+ }
232+ set ret [$func $sources_path "${binfile}" $options]
233+ } else {
234+ set objects {}
235+ for {set i 0} "\$i<[llength $sources]" {incr i} {
236+ set s [lindex $sources $i]
237+ if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
238+ untested $testname
239+ return -1
240+ }
241+ lappend objects "${binfile}${i}.o"
242+ }
243+ set ret [$func $objects "${binfile}" executable $options]
244+ }
245+ if { $ret != "" } {
246+ untested $testname
247 return -1
248 }
249+
250 return 0
251 }
252
253Index: gdb-7.3.50.20110722/gdb/testsuite/lib/prelink-support.exp
254===================================================================
255--- gdb-7.3.50.20110722.orig/gdb/testsuite/lib/prelink-support.exp 2011-01-01 16:33:52.000000000 +0100
256+++ gdb-7.3.50.20110722/gdb/testsuite/lib/prelink-support.exp 2011-08-10 19:25:41.000000000 +0200
257@@ -95,8 +95,9 @@ proc file_copy {src dest} {
258 # Wrap function build_executable so that the resulting executable is fully
259 # self-sufficient (without dependencies on system libraries). Parameter
260 # INTERP may be used to specify a loader (ld.so) to be used that is
261-# different from the default system one. Libraries on which the executable
262-# depends are copied into directory DIR. Default DIR value to
263+# different from the default system one. INTERP can be set to "no" if no ld.so
264+# copy should be made. Libraries on which the executable depends are copied
265+# into directory DIR. Default DIR value to
266 # `${objdir}/${subdir}/${EXECUTABLE}.d'.
267 #
268 # In case of success, return a string containing the arguments to be used
269@@ -151,8 +152,15 @@ proc build_executable_own_libs {testname
270
271 if {$interp == ""} {
272 set interp_system [section_get $binfile .interp]
273- set interp ${dir}/[file tail $interp_system]
274- file_copy $interp_system $interp
275+ if {$interp_system == ""} {
276+ fail "$test could not find .interp"
277+ } else {
278+ set interp ${dir}/[file tail $interp_system]
279+ file_copy $interp_system $interp
280+ }
281+ }
282+ if {$interp == "no"} {
283+ set interp ""
284 }
285
286 set dests {}
287@@ -164,13 +172,19 @@ proc build_executable_own_libs {testname
288
289 # Do not lappend it so that "-rpath $dir" overrides any possible "-rpath"s
290 # specified by the caller to be able to link it for ldd" above.
291- set options [linsert $options 0 "ldflags=-Wl,--dynamic-linker,$interp,-rpath,$dir"]
292+ set options [linsert $options 0 "ldflags=-Wl,-rpath,$dir"]
293+ if {$interp != ""} {
294+ set options [linsert $options 0 "ldflags=-Wl,--dynamic-linker,$interp"]
295+ }
296
297 if {[build_executable $testname $executable $sources $options] == -1} {
298 return ""
299 }
300
301- set prelink_args "--dynamic-linker=$interp --ld-library-path=$dir $binfile $interp [concat $dests]"
302+ set prelink_args "--ld-library-path=$dir $binfile [concat $dests]"
303+ if {$interp != ""} {
304+ set prelink_args "--dynamic-linker=$interp $prelink_args $interp"
305+ }
306 return $prelink_args
307 }
308
309Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.base/break-interp.exp
310===================================================================
311--- gdb-7.3.50.20110722.orig/gdb/testsuite/gdb.base/break-interp.exp 2011-07-01 21:12:12.000000000 +0200
312+++ gdb-7.3.50.20110722/gdb/testsuite/gdb.base/break-interp.exp 2011-08-10 18:32:21.000000000 +0200
313@@ -108,14 +108,20 @@ proc strip_debug {dest} {
314 }
315 }
316
317+# Former symbol for solib changes notifications was _dl_debug_state, newer one
318+# is _dl_debug_notify, the right one one traps by `set stop-on-solib-events 1'.
319+
320+set solib_bp {(_dl_debug_state|_dl_debug_notify)}
321+
322 # Implementation of reach.
323
324 proc reach_1 {func command displacement} {
325- global gdb_prompt expect_out
326+ global gdb_prompt expect_out solib_bp
327
328- if {$func == "_dl_debug_state"} {
329+ if {$func == $solib_bp} {
330 # Breakpoint on _dl_debug_state can have problems due to its overlap
331 # with the existing internal breakpoint from GDB.
332+ # With also _dl_debug_notify we would need even two breakpoints.
333 gdb_test_no_output "set stop-on-solib-events 1"
334 } elseif {! [gdb_breakpoint $func allow-pending]} {
335 return
336@@ -141,21 +147,21 @@ proc reach_1 {func command displacement}
337 exp_continue
338 }
339 -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
340- if {$func == "_dl_debug_state"} {
341+ if {$func == $solib_bp} {
342 fail $test
343 } else {
344 pass $test
345 }
346 }
347 -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
348- if {$func == "_dl_debug_state"} {
349+ if {$func == $solib_bp} {
350 fail $test
351 } else {
352 pass $test
353 }
354 }
355 -re "Stopped due to shared library event\r\n$gdb_prompt $" {
356- if {$func == "_dl_debug_state"} {
357+ if {$func == $solib_bp} {
358 if {$debug_state_count == 0} {
359 # First stop does not yet relocate the _start function
360 # descriptor on ppc64.
361@@ -174,7 +180,7 @@ proc reach_1 {func command displacement}
362 fail $test_displacement
363 }
364
365- if {$func == "_dl_debug_state"} {
366+ if {$func == $solib_bp} {
367 gdb_test_no_output "set stop-on-solib-events 0"
368 }
369 }
370@@ -373,7 +379,7 @@ proc test_attach {file displacement {rel
371 }
372
373 proc test_ld {file ifmain trynosym displacement} {
374- global srcdir subdir gdb_prompt expect_out inferior_exited_re
375+ global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
376
377 # First test normal `file'-command loaded $FILE with symbols.
378
379@@ -401,9 +407,9 @@ proc test_ld {file ifmain trynosym displ
380 gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
381 }
382
383- reach "_dl_debug_state" "run" $displacement
384+ reach $solib_bp "run" $displacement
385
386- gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
387+ gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
388
389 if $ifmain {
390 reach "main" continue "NONE"
391@@ -415,7 +421,7 @@ proc test_ld {file ifmain trynosym displ
392
393 # Try re-run if the new PIE displacement takes effect.
394 gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
395- reach "_dl_debug_state" "run" $displacement
396+ reach $solib_bp "run" $displacement
397
398 if $ifmain {
399 test_core $file $displacement
400@@ -448,7 +454,7 @@ proc test_ld {file ifmain trynosym displ
401 gdb_test "exec-file $file" "exec-file $escapedfile" "load"
402
403 if $ifmain {
404- reach "_dl_debug_state" run $displacement
405+ reach $solib_bp run $displacement
406
407 # Use two separate gdb_test_multiple statements to avoid timeouts due
408 # to slow processing of wildcard capturing long output
This page took 0.363264 seconds and 4 git commands to generate.