Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Debugging a QProcess on Linux/GDB hangs
Forum Updated to NodeBB v4.3 + New Features

Debugging a QProcess on Linux/GDB hangs

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
6 Posts 4 Posters 619 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    __mk__
    wrote on 15 Feb 2023, 07:56 last edited by __mk__
    #1

    I have a program where I create a child process using QProcess which I want to debug with the Qt Creator Debugger. I'm on Ubuntu 20.04.5 LTS and I'm using gdb version 9.2.

    The project is compiled in Debug mode. When I start the debugger, the program runs normally, but then hangs where I would expect the child process to finish.

    The program works fine when I run it without the debugger. (both in debug mode and release mode)

    Here's my program:

    #include <QCoreApplication>
    #include <QDebug>
    #include <QProcess>
    
    QString getUname(void) {
        QProcess* myProcess = new QProcess();
        QString uname;
        myProcess->start("uname", QStringList()<<"-a");
        myProcess->waitForFinished(100);
        uname = myProcess->readAllStandardOutput().replace("\n", "");
        delete myProcess;
        return uname;
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        qDebug() << "uname:";
        qDebug() << getUname();
        return a.exec();
    }
    

    When I run it in debugger, it prints "uname:" and then hangs. It does not print the output of the uname command, but the debugger does not finish either.

    Here's the debugger log (I've read that this is important for troubleshooting) https://pastebin.com/QMWRfrdH

    J J 2 Replies Last reply 15 Feb 2023, 07:59
    0
    • _ __mk__
      15 Feb 2023, 07:56

      I have a program where I create a child process using QProcess which I want to debug with the Qt Creator Debugger. I'm on Ubuntu 20.04.5 LTS and I'm using gdb version 9.2.

      The project is compiled in Debug mode. When I start the debugger, the program runs normally, but then hangs where I would expect the child process to finish.

      The program works fine when I run it without the debugger. (both in debug mode and release mode)

      Here's my program:

      #include <QCoreApplication>
      #include <QDebug>
      #include <QProcess>
      
      QString getUname(void) {
          QProcess* myProcess = new QProcess();
          QString uname;
          myProcess->start("uname", QStringList()<<"-a");
          myProcess->waitForFinished(100);
          uname = myProcess->readAllStandardOutput().replace("\n", "");
          delete myProcess;
          return uname;
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          qDebug() << "uname:";
          qDebug() << getUname();
          return a.exec();
      }
      

      When I run it in debugger, it prints "uname:" and then hangs. It does not print the output of the uname command, but the debugger does not finish either.

      Here's the debugger log (I've read that this is important for troubleshooting) https://pastebin.com/QMWRfrdH

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 15 Feb 2023, 07:59 last edited by
      #2

      @__mk__ said in Debugging a QProcess on Linux/GDB hangs:

      and then hangs

      Where exactly does it hang?

      Note: there is no need to allocate QProcess on the heap in this case as you anyway wait for it to finish.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • _ __mk__
        15 Feb 2023, 07:56

        I have a program where I create a child process using QProcess which I want to debug with the Qt Creator Debugger. I'm on Ubuntu 20.04.5 LTS and I'm using gdb version 9.2.

        The project is compiled in Debug mode. When I start the debugger, the program runs normally, but then hangs where I would expect the child process to finish.

        The program works fine when I run it without the debugger. (both in debug mode and release mode)

        Here's my program:

        #include <QCoreApplication>
        #include <QDebug>
        #include <QProcess>
        
        QString getUname(void) {
            QProcess* myProcess = new QProcess();
            QString uname;
            myProcess->start("uname", QStringList()<<"-a");
            myProcess->waitForFinished(100);
            uname = myProcess->readAllStandardOutput().replace("\n", "");
            delete myProcess;
            return uname;
        }
        
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
            qDebug() << "uname:";
            qDebug() << getUname();
            return a.exec();
        }
        

        When I run it in debugger, it prints "uname:" and then hangs. It does not print the output of the uname command, but the debugger does not finish either.

        Here's the debugger log (I've read that this is important for troubleshooting) https://pastebin.com/QMWRfrdH

        J Online
        J Online
        JonB
        wrote on 15 Feb 2023, 08:13 last edited by
        #3

        @__mk__
        gdb behaviour can be controlled when the process spawns a sub-process ("forking"). Although the default behaviour is to allow the child to run unimpeded I suppose you might have changed that, you could read https://sourceware.org/gdb/onlinedocs/gdb/Forks.html for information.

        What happens if you debug your program by running gdb directly in a terminal/shell instead of from Qt Creator --- any different behaviour?

        _ 1 Reply Last reply 15 Feb 2023, 09:24
        0
        • J JonB
          15 Feb 2023, 08:13

          @__mk__
          gdb behaviour can be controlled when the process spawns a sub-process ("forking"). Although the default behaviour is to allow the child to run unimpeded I suppose you might have changed that, you could read https://sourceware.org/gdb/onlinedocs/gdb/Forks.html for information.

          What happens if you debug your program by running gdb directly in a terminal/shell instead of from Qt Creator --- any different behaviour?

          _ Offline
          _ Offline
          __mk__
          wrote on 15 Feb 2023, 09:24 last edited by
          #4

          @JonB @jsulm

          Manually debugging the program via command-line gdb works fine.

          Starting program: /home/user/build-TestProject-Desktop_Qt_5_15_2_GCC_64bit-Debug/TestProject 
          [Thread debugging using libthread_db enabled]
          Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
          uname:
          [Attaching after Thread 0x7ffff4e49780 (LWP 12448) fork to child process 12452]
          [New inferior 2 (process 12452)]
          [Detaching after fork from parent process 12448]
          [Inferior 1 (process 12448) detached]
          [Thread debugging using libthread_db enabled]
          Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
          process 12452 is executing new program: /usr/bin/uname
          [Inferior 2 (process 12452) exited normally]
          "Linux u 5.15.0-60-generic #66~20.04.1-Ubuntu SMP Wed Jan 25 09:41:30 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux"
          
          

          The Qt creator debugger seems to hang where I call myProcess->start. I set a breakpoint for that line and the lines afterwards. The debugger waits on the line where I call start and then I click continue. This is the point where it hangs. The line after start never gets reached.

          J 1 Reply Last reply 15 Feb 2023, 09:30
          0
          • _ __mk__
            15 Feb 2023, 09:24

            @JonB @jsulm

            Manually debugging the program via command-line gdb works fine.

            Starting program: /home/user/build-TestProject-Desktop_Qt_5_15_2_GCC_64bit-Debug/TestProject 
            [Thread debugging using libthread_db enabled]
            Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
            uname:
            [Attaching after Thread 0x7ffff4e49780 (LWP 12448) fork to child process 12452]
            [New inferior 2 (process 12452)]
            [Detaching after fork from parent process 12448]
            [Inferior 1 (process 12448) detached]
            [Thread debugging using libthread_db enabled]
            Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
            process 12452 is executing new program: /usr/bin/uname
            [Inferior 2 (process 12452) exited normally]
            "Linux u 5.15.0-60-generic #66~20.04.1-Ubuntu SMP Wed Jan 25 09:41:30 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux"
            
            

            The Qt creator debugger seems to hang where I call myProcess->start. I set a breakpoint for that line and the lines afterwards. The debugger waits on the line where I call start and then I click continue. This is the point where it hangs. The line after start never gets reached.

            J Online
            J Online
            JonB
            wrote on 15 Feb 2023, 09:30 last edited by JonB
            #5

            @__mk__
            Well this output from standalone gdb seems to indicate that it actually attaches to the forked child process and detaches from the parent process, which I was not expecting. If it does the same from Qt Creator (doesn't that have some window pane to show the sort of output you are getting from gdb?) I imagine that could be problematic.

            Did you read the link I referenced? I think you should make sure just what your gdb "fork" settings are, you can print them out from standalone gdb I think.

            1 Reply Last reply
            0
            • andrA Offline
              andrA Offline
              andr
              wrote on 16 Feb 2023, 11:09 last edited by
              #6

              The log is indeed helpful: You have non-default settings that are apparently not helpful in your case:

              d/MultiInferior: true (default: false) ***
              [...]
              set detach-on-fork off

              1 Reply Last reply
              1

              1/6

              15 Feb 2023, 07:56

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved