Skip to content

Commit

Permalink
[gdb/testsuite] Fix race in gdb.base/add-symbol-file-attach.exp
Browse files Browse the repository at this point in the history
When running test-case gdb.base/add-symbol-file-attach.exp with target board
unix/-m32, we run into:
...
(gdb) attach 3955^M
Attaching to process 3955^M
Load new symbol table from "add-symbol-file-attach"? (y or n) y^M
Reading symbols from add-symbol-file-attach/add-symbol-file-attach...^M
Reading symbols from /lib/libm.so.6...^M
Reading symbols from /usr/lib/debug/lib/libm-2.31.so-i386.debug...^M
Reading symbols from /lib/libc.so.6...^M
Reading symbols from /usr/lib/debug/lib/libc-2.31.so-i386.debug...^M
Reading symbols from /lib/ld-linux.so.2...^M
Reading symbols from /usr/lib/debug/lib/ld-2.31.so-i386.debug...^M
0xf7f53549 in __kernel_vsyscall ()^M
(gdb) FAIL: gdb.base/add-symbol-file-attach.exp: attach
...

The test fails because this regexp is used:
...
    -re ".*in \[_A-Za-z0-9\]*pause.*$gdb_prompt $" {
...

The regexp attempts to detect that the exec is somewhere in pause ():
...
int
main (int argc, char **argv)
{
  pause ();
  return 0;
}
...
but when the exec is blocked in pause, the backtrace is:
...
 (gdb) bt
 #0  0xf7fd2549 in __kernel_vsyscall ()
 #1  0xf7d84966 in __libc_pause () at ../sysdeps/unix/sysv/linux/pause.c:29
 #2  0x0804844c in main (argc=1, argv=0xffffce84)
     at /data/vries/gdb/src/gdb/testsuite/gdb.base/add-symbol-file-attach.c:26
...

We could simply extend the regexp to also match __kernel_vsyscall, but the
more fundamental problem is that the test is racy.

The attach can happen before the exec is blocked in pause (), somewhere in the
dynamic linker resolving the call to pause, in main or even earlier.

Note that for the test-case to be effective, the exec is not required to be in
pause ().  I added a "while (1);" loop at the start of main, reverted the
patch fixing the corresponding PR and reproduced the problem it's supposed to
detect.

Fix this by simply matching the "Reading symbols from" line, similar to what
an earlier test is doing.

While we're at it, rewrite the earlier test to also use the -wrap idiom.

Tested on x86_64-linux.
  • Loading branch information
vries committed Sep 4, 2023
1 parent 0f020d9 commit 1b9a9c3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gdb/testsuite/gdb.base/add-symbol-file-attach.exp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gdb_test_multiple "add-symbol-file $binfile" $test {
send_gdb "y\n"
exp_continue
}
-re "Reading symbols from.*$gdb_prompt $" {
-re -wrap "Reading symbols from .*" {
pass $test
}
}
Expand All @@ -71,7 +71,7 @@ gdb_test_multiple "attach $testpid" $test {
send_gdb "y\n"
exp_continue
}
-re ".*in \[_A-Za-z0-9\]*pause.*$gdb_prompt $" {
-re -wrap "Reading symbols from .*" {
pass $test
}
}
Expand Down

0 comments on commit 1b9a9c3

Please sign in to comment.