gdbserver hangs after breakpoint has been hit in a detached thread
In a detached pthread gdbserver hangs when it hits a breakpoint more than once (in a different or newly created thread).
Code: gdb-thread-problem.zip (contains Visual Studio Solution with main.cpp, .sln and .vcxproj files)
// Ignore the fact that Visual Studio complains about "#include <unistd.h>" and "sleep(2)"
// This is because the "Visual C++ for Linux Development" extension does not contain unistd.h
// This only affects IntelliSense not the real compilation on the host
#include <cstdio>
#include <pthread.h>
#include <unistd.h>
static void *ThreadProc(void* payLoad)
{
printf("BEFORE breakpoint\n");
printf("Set a breakpoint (F9) here!\n");
printf("AFTER breakpoint\n");
}
int main()
{
pthread_t p_thr;
pthread_attr_t attr;
void* payload;
while (!(pthread_attr_init(&attr) ||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) ||
pthread_create(&p_thr, &attr, (void * (*)(void *))ThreadProc, payload)))
{
sleep(2);
}
}
Steps to reprodruce:
You need:
- Visual Studio 2015 with Visual C++ for Linux Development or Visual Studio "15" Preview 5 (select Visual C++ for Linux during install)
- Windows 14942 with WSL and Ubuntu 16.04
- for crosscheck: a real Ubuntu 16.04
Then:
- On the Linux machine and on WSL ensure you have "sudo apt-get install g++ gdb gdbserver openssh-server"
- Start sshd and make sure you can log in.
- Open the Visual Studio solution
- Set a breakpoint in ThreadProc where stated in the source code
- Setup a connection to the real Linux machine (Tools - Options - Cross Platform - Connection Manager) and WSL.
- Select the connection for the real Linux machine (Project Properties - Configuration Properties - Remote settings - Target machine)
- Press F5 (Remote GDB debugger)
- When it hits the breakpoint, press F5 at least twice (everything works as expected)
Now select the connection to WSL:
- Press F5
- It will hit the breakpoint as expected
- Press F5
- ERROR: -> displays "BEFORE breakpoint" and then hangs
I also tested on several WSL machines with 14393.222 and Ubuntu 14.04. They have ecactly the same problem.
As a workaround you can switch from gdbserver to gdb (local gdb output transmitted via ssh) in Project Properties - Configuration Properties - Debugging - Debugging Mode
Thank you for reporting the issue @christoh. Could you please provide an strace of gdbserver when it hangs?
strace.zip Probably not too helpful since it stops suddenly as the process hangs and seems to have unflushed user space buffers
Thank you, I think we understand the issue. Gdbserver is in a rt-sigsuspend call waiting for interesting signals which should include socket IO which relies on the currently unimplemented asynchronous IO infrastructure. We are tracking this now internally.
That corresponds to some extent with my findings I got this morning. I was unhappy with the fact that the strace file ended up in the middle of a line. I was able to kill gdbserver gracefully with SIGTERM which caused strace to flush the file buffers. So I can confirm that rt-sigsuspend is indeed the last syscall and it wakes up correctly when it receives a signal (other than async I/O completion).
However, the question remains why it works once on a new thread and fails when a second thread is started.
Started to track this internally.
@christoh can you please let me know what version of gdbserver and the Ubuntu version you are using on WSL? I wasn't able to repro this with the default version of gdbserver on Ubuntu 16.04. From the strace and stacks, that version is using select instead of signal driven IO.
default gdb version on 16.04 GNU gdbserver (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. gdbserver is free software, covered by the GNU General Public License. This gdbserver was configured as "x86_64-linux-gnu"
This is what I am using now on the WSL side: Windows 15007, Ubuntu 16.04, standard Ubuntu gdb 7.11.1 , g++ 5.4.0 (not my own fancy toolchain)
[root@wsl-insider ~] # uname -a
Linux wsl-insider 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@wsl-insider ~] # cat /proc/version
Linux version 4.4.0-43-Microsoft ([email protected]) (gcc version 5.4.0 (GCC) ) #1-Microsoft Wed Dec 31 14:42:53 PST 2014
[root@wsl-insider ~] # /mnt/c/Windows/System32/cmd.exe /c ver
Unable to translate current working directory. Using C:\WINDOWS\system32
Microsoft Windows [Version 10.0.15007]
[root@wsl-insider ~] # gdb --version
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
[root@wsl-insider ~] # g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@wsl-insider ~] #
My DevEnv setup is Visual Studio 2015 with Visual C++ for Linux Development.
Behavior is still the same when I reported this first: Breakpoint is hit correctly once. Then press F5 to continue. GDB and/or the debugee hang just before the breakpoint should have been hit a second time.
Works perfectly on Ubuntu 16.04 with real Linux kernel (Breakpoint can be hit as often as you like instead of only once).
100 % reproducible.
Thanks for the reply! Locally I did the steps below, which I assume would be equivalent. gdbserver ran fine and the strace showed select being used instead of signal driven IO.
In the straces you provided I noticed it was doing exec on /usr/bin/gdbserver.original instead of /usr/bin/gdbserver. Can you confirm that /usr/bin/gdbserver.original isn't different and if the repro below works for you?
repro Bash window 1 – gdbserver localhost:2000 /bin/ls Bash window 2: gdb /bin/ls target remote localhost:2000 run
Sorry for the double post, but I managed to get a repro of this using the Windows gdb client included with the Visual C++ for Linux Development toolkit. It seems really strange that gdbserver would change it's worker loop based on the client but I guess we've seen stranger things :).
repro Bash window 1 – gdbserver localhost:2000 /bin/ls Console window: x86_64-linux-gnu-gdb.exe ls target remote localhost:2000
Great you were able to repro this. It works with /bin/ls of course. It does not work when you create a new thread (see example at the beginning). And you need to set a breakpoint in the newly created thread.
We managed to get this working after enabling signal driven IO for inet tcp sockets and fixing an issue where thread exit wasn't always being reported through ptrace. The fix should be out in an insider build soon.
Thanks for providing the detailed repro, that really helped to narrow down the issues!
Thanks for addressing that issue. It really helps to use WSL as a development platform. I'll close this issue as soon as I can verify it works with the next insider preview.
Unfortunately still the same erroneous behavior in 15025.
Thanks for the follow-up. I just checked and fix didn't make it in for 15025, but should hopefully be the next one. Keep an eye out for the release notes and we'll update the thread as fixed when it hits.
Works perfectly in 15031
Great, thanks for confirming!