Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Debugger not attaching quickly enough?



  • Greetings.

    I'm writing a console application using QtCreator on Windows 7 (x64). I installed the Qt SDK via the offline installer tool for Windows. After that finishes, I use the Maintenance application to update the SDK. I'm experiencing a weird issue when I try to use the debugger and breakpoints. I've tried re-installing the SDK a few times via various methods and on different computers but the issue seems to persist.

    When I set breakpoints, all of them seem to be completely ignored and they get skipped. The application continues running until it finishes. The application is set to be a Debug build and I've tried launching the debugger in various ways (using F5, going to the menu bar and selecting Debug > Start Debugging > Start Debugging, using the Start Debugging icon on the bottom left) but they have the same effect.

    If I use QtCreator on Linux everything works as it should.

    I examined the Debugger Logs and it looked like to me that the debugger wasn't attaching fast enough.

    To get the debugger and breakpoints to work on my application on Windows, I have to insert some "hackish" code to make my application wait for a small amount of time to give the debugger a chance to attach. Once I do this, it works as it should. (debugging and breakpoints work) If I don't do this, breakpoints won't work no matter where I set them. It's slightly annoying.

    I can use some very simple code to replicate this behavior:

    @
    #include <iostream>

    int main(int argc, char *argv[])
    {

    //Try setting as many breakpoints as you like, none of them will be hit
    int a = 3;
    int b = 6;
    int c = 9;
    
    std::cout << "a is: " << a << std::endl;
    std::cout << "b is: " << b << std::endl;
    std::cout << "c is: " << c << std::endl;
    
    return 0;
    

    }
    @

    But add this to make it wait a small bit, and breakpoints work again...

    @
    #include <iostream>
    #include <QWaitCondition>
    #include <QReadWriteLock>

    int main(int argc, char *argv[])
    {
    //This code is totally unneeded for the application, but
    //it seems to give the debugger more time to attach so I can use
    //breakpoints.
    QReadWriteLock mutex;
    QWaitCondition cond;
    mutex.lockForRead();
    cond.wait(&mutex, 500);
    mutex.unlock();

    int a = 3;
    int b = 6;
    int c = 9;
    
    std::cout << "a is: " << a << std::endl;
    std::cout << "b is: " << b << std::endl;
    std::cout << "c is: " << c << std::endl;
    
    return 0;
    

    }
    @

    Could this be a bug or is there something I should be adjusting on my system to prevent this from happening? Maybe I'm doing something wrong?

    If the debugging logs will help, I can post those as well if needed. Sorry for the wall of text.


  • Moderators

    Please file a "bug report":http://bugreports.qt-project.org/ against Qt Creator. Please attach the debugger log, without it it is really hard to diagnose any debugger related issue. Thanks!


Log in to reply