locked
Windows Bash: Can't debug multithreaded applications with gdb RRS feed

  • Question

  • Re-posted from the Microsoft Insiders forum, at the suggestion of members of that forum.  Apologies if that's not the appropriate thing to do; please let me know.

    http://answers.microsoft.com/en-us/insider/forum/insider_apps-insider_other/window-bash-cant-debug-multithreaded-applications/5e1914ad-7ba2-4507-b21e-4a8b990d69b7?tm=1460769755172

    I'm seeing lots of crashes in more complicated Linux applications running on Windows.  (Did I mention that it's really cool that I'm running Linux applications on Windows?)  I'm trying to track down exactly what's going on.  gdb is my first go-to tool for debugging applications under Linux; I think it wouldn't be too much to say that it's the standard Linux tool for lots of types of debugging.  But I'm finding that it can't debug even the simplest of threaded applications on Windows Bash.  (It has no such problem under a real Linux kernel.)

    Here's a minimal reproducer:

    #include <pthread.h>
    
    // Make thread spin indefinitely
    void *spin(void * no_arg)
    {
        while (1) ;
        return NULL;
    }
    
    int main()
    {
        pthread_t spin_thread;
        pthread_create(&spin_thread, NULL, spin, NULL);
        while (1) ;
        return 0;
    }

    To compile, write to a file and run "gcc <filename> -lpthread -g".  Then, to test, do "gdb ./a.out".  Once you get to the gdb prompt, type "run".  What I see is:

    (gdb) run
    Starting program: /mnt/c/Users/[me]/linwrapper/a.out
    warning: Error disabling address space randomization: Success
    warning: linux_ptrace_test_ret_to_nx: PTRACE_KILL waitpid returned -1: Interrupted system call
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    [New Thread 0x7ff5ff600700 (LWP 414)]
    Cannot find user-level thread for LWP 410: generic error
    (gdb)

    On a real Linux kernel, "run" doesn't return until you hit Ctrl-C, because the command spins forever.  It certainly doesn't error out.

    I write and work with a lot of code in C/C++.  And threads are pretty much unavoidable these days.  And I'm not going to pretend that my code never has bugs :-)  Is there a good way to debug multithreaded Linux apps in Windows Bash?


    Saturday, April 16, 2016 1:46 AM

Answers

All replies

  • You are welcome here.   GCC compiler, pthreads emulation libraries and  GDB for Windows exist for long time, in several versions, so probably this new Ubunty stuff still has some rough corners. Feedback from early adopters like you is very important to get this fixed.

    However, it seems like you are confused a little.  Bash is just a shell (with a set of more or less obscure GNU coreutils). Gdb and the C program do not run inside the shell, they run directly under the OS. Windows is not Linux, has never been, and does not magically turn into Linux after installation of some magic "wrapper". By the way, the decision to use Ubuntu "wrapper" was a surprise for many. For long time, Linux compatibility for Windows was associated with Cygwin (Redhat). 



    • Edited by Pavel A Saturday, April 16, 2016 4:18 PM
    Saturday, April 16, 2016 3:58 PM
  • A

    As per my recent answer

    Since the linux subsystem (and insider builders) is in preview your best bet for support is the Ubuntu forums

    Support for Bash/Ubuntu should be directed to the Ubuntu forums here


    Wanikiya and Dyami--Team Zigzag Windows IT-PRO (MS-MVP)

    Saturday, April 16, 2016 4:32 PM
  • Since the linux subsystem (and insider builders) is in preview your best bet for support is the Ubuntu forums


    Support for Bash/Ubuntu should be directed to the Ubuntu forums here


    Wanikiya and Dyami--Team Zigzag Windows IT-PRO (MS-MVP)

    Thank you, Wanikiya and Dyami--Team Zigzag. This good advice would be even better if you mentioned the tag to use for Ubuntu on Windows questions... Is it "windows-10"? or something else?

    -- pa

    Saturday, April 16, 2016 5:38 PM
  • PA

    Unfortunately there is no "official" support for a beta feature (bash) on an preview build (insider).  I have asked the developers where to point these and as this one is more programing than IT pro related the user picked what he felt was appropriate.

    I pointed him here from Microsoft community (consumers) which is clearly not the best.

    As to tag?


    Wanikiya and Dyami--Team Zigzag Windows IT-PRO (MS-MVP)

    Sunday, April 17, 2016 1:45 AM
  • Thanks all!  And apologies for the lengthy delay in my reply -- I just created an account here and I configured notifications incorrectly.  I'll be checking back more often going forward.

    Regarding "bash" -- yes, I definitely understand that bash is just a shell.  I assume that the underlying compatibility layer is somewhat (perhaps not entirely?) closer in structure to something like WINE for Linux.  Maybe with more kernel support for performance?; I've no idea.  But my understanding is that the official public name for the whole feature is still "Windows Bash"?  I personally find that confusing, and would be grateful fora more-accurate name; but if that's the name, that's the name.

    Regarding using the Ubuntu forums -- this issue does not happen on regular Ubuntu.  It's specific to Windows's Linux compatibility layer.  I will go ahead and ask the question in the Ubuntu forums.  But my expectation would be that they would say "cannot reproduce; go ask Microsoft."  If that's their response, is there a good next step?

    Saturday, April 23, 2016 4:18 AM
  • Cross-posted here:

    http://ubuntuforums.org/showthread.php?t=2321544&p=13475283#post13475283

    Saturday, April 23, 2016 4:32 AM
  • Just saw there is an issue tracker for BashOnWindows on GitHub:

    https://github.com/Microsoft/BashOnWindows/issues

    https://github.com/Microsoft/BashOnWindows/issues/204

    With kind regards

    • Proposed as answer by Pavel A Sunday, April 24, 2016 1:57 PM
    Saturday, April 23, 2016 7:05 AM
  • Just saw there is an issue tracker for BashOnWindows on GitHub

    But the original thread question is not actually about bash. Anyone knows a mail list, forum or bugzilla for gdb on modern Windows?

    I assume that the underlying compatibility layer is somewhat (perhaps not entirely?) closer in structure to something like WINE for Linux. Maybe with more kernel support for performance?; I've no idea. But my understanding is that the official public name for the whole feature is still "Windows Bash"? I personally find that confusing, and would be grateful for a more-accurate name

    The official name seems to be WSL - Windows support (or subsystem?) for Linux.

    The article below gives some details:

    https://insights.ubuntu.com/2016/03/30/ubuntu-on-windows-the-ubuntu-userspace-for-windows-developers/

    So if I understand correctly, you run on Windows a native Ubuntu C compiler to compile a native Ubuntu program, and then use the native Ubuntu gdb to debug it (somehow wired with the VS IDE)?

    About special kernel support for the "Linux wrapper".... this is interesting question. Windows NT  from the beginning has been designed to support several "user OS" subsystems, one of these was Unix or Posix subsystem (a.k.a. Interix). An alternate subsystem consists mainly of a "subsystem server" in usermode, and what cannot be done in that, goes into the kernel. For example, the kernel and NTFS support case-sensitive filenames, but nobody uses that. But this "Posix subsystem" has been phased out from recent Windows, and how they deal with Linux compatibility now, should be entirely within Win32... ?

    -- pa




    • Edited by Pavel A Saturday, April 23, 2016 10:58 AM
    Saturday, April 23, 2016 10:41 AM
  • Hmm, yes the #204 looks like a issue in a "wrapper" pthreads library that affects gdb... and they say it is already fixed in internal build... and  when this will be available is not known yet.

    The brand new WSL blog:

    https://blogs.msdn.microsoft.com/wsl/

    The WSL "technology" home page:

    https://msdn.microsoft.com/commandline/wsl/


    • Edited by Pavel A Sunday, April 24, 2016 12:57 AM
    • Marked as answer by aseering Tuesday, April 26, 2016 4:40 AM
    Saturday, April 23, 2016 11:38 PM
  • Yep, thanks!  I'll follow that bug for further details.
    Tuesday, April 26, 2016 4:41 AM
  • Also, for the record, the regular Ubuntu forums directed me back here; they didn't have an answer.

    The BashOnWindows bug tracker seems to be a much better resource.

    Tuesday, April 26, 2016 4:43 AM