binutils-gdb/gdb/testsuite/gdb.threads/execl.exp
Tom de Vries 14e9c72c33 [gdb/testsuite] Avoid breakpoint in GLIBC in gdb.threads/execl.exp
When running the gdb.threads/execl.exp test-case, we run into this FAIL:
...
(gdb) continue^M
Continuing.^M
^M
Thread 1 "execl" hit Breakpoint 2, __GI_execl (path=0x6024a0 \
  "build/gdb/testsuite/outputs/gdb.threads/execl/execl1", \
  arg=<optimized out>) at execl.c:51^M
51        if (execl (new_image, new_image, NULL) == -1) \
  /* set breakpoint here */^M
(gdb) FAIL: gdb.threads/execl.exp: continue across exec
...
The fail is due to the continue command hitting a breakpoint in __GI_execl
rather than main.

This problem originates from where we execute the "b 51" command, and get two
breakpoint locations:
...
(gdb) run ^M
Starting program: build/gdb/testsuite/outputs/gdb.threads/execl/execl ^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
^M
Breakpoint 1, main (argc=1, argv=0x7fffffffd3f8) at gdb.threads/execl.c:44^M
44        pthread_create (&thread1, NULL, thread_function, NULL);^M
(gdb) b 51^M
Breakpoint 2 at 0x400787: gdb.threads/execl.c:51. (2 locations)^M
(gdb) PASS: gdb.threads/execl.exp: set breakpoint at execl
...

Adding a "info breakpoints" command, we can see the locations:
...
(gdb) info breakpoints^M
Num     Type           Disp Enb Address            What^M
1       breakpoint     keep y   0x00000000004006ee in main at \
  gdb.threads/execl.c:44^M
        breakpoint already hit 1 time^M
2       breakpoint     keep y   <MULTIPLE>         ^M
2.1                         y   0x0000000000400787 in main at \
  gdb.threads/execl.c:51^M
2.2                         y   0x00007ffff758d925 in __GI_execl at \
  execl.c:51^M
(gdb) PASS: gdb.threads/execl.exp: info breakpoints
...

The fact that the __GI_execl breakpoint location is there, is a bug, filed as
PR25656.  Without debug info for GLIBC though, the bug is not triggered.

Fix the FAIL by working around the bug, and deleting the breakpoint after
hitting the first breakpoint location.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-03-12  Tom de Vries  <tdevries@suse.de>

	* gdb.threads/execl.exp: Delete breakpoint after hitting it.
2020-03-12 14:37:15 +01:00

76 lines
2.3 KiB
Plaintext

# Copyright (C) 2008-2020 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test handling of threads across an execl.
# Original image, loads a thread library.
standard_testfile
if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
return -1
}
# New image, that does not load a thread library.
set testfile1 "execl1"
set srcfile1 ${testfile1}.c
set binfile1 [standard_output_file ${testfile1}]
if {[gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable {debug}] != "" } {
return -1
}
clean_restart ${binfile}
runto_main
gdb_test "b [gdb_get_line_number "breakpoint here"]" \
".*Breakpoint .*execl.*" "set breakpoint at execl"
gdb_test "continue" ".*breakpoint here.*" "continue to exec"
gdb_test "info threads" "1 *Thread.*2 *Thread.*3 *Thread.*" "info threads before exec"
# Work around PR25656, where the breakpoint above sets 2 breakpoint locations:
# - one on gdb.threads/execl.c:$linenumber, and
# - one in GLIBC's execl.c:$linenumber, in __GI_execl
# Delete the breakpoint to make sure we hit main upon continue, rather than
# __GI_execl.
gdb_test_no_output "delete 2"
# When continuing from this point we'll hit the breakpoint in main()
# again, this time in the exec'd process.
gdb_test "continue" ".*Breakpoint 1, main.*" \
"continue across exec"
gdb_test "info threads" ".*" "info threads after exec"
set test "info threads after exec"
gdb_test_multiple "info threads" "$test" {
-re "2 *Thread .*$gdb_prompt $" {
# Old threads left behind.
fail "$test"
}
-re "4 *Thread .*$gdb_prompt $" {
# New threads registered.
fail "$test"
}
-re "$gdb_prompt $" {
# Target doesn't register the main thread, pass for now.
pass "$test"
}
}
gdb_continue_to_end