Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-29100

Line feeds added to console output with write()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • Qt Creator 15.0.0-beta1
    • Qt Creator 10.0.0
    • Debugger
    • None
    • Kubuntu 22.04 and GCC 12
    • Linux/X11

    Description

      I tried using write() to print text to stderr. I'm doing something like this multiple times:

      write(stdErrDescriptor, "H", 1);
      write(stdErrDescriptor, "e", 1);
      write(stdErrDescriptor, "l", 1);
      write(stdErrDescriptor, "l", 1);
      write(stdErrDescriptor, "o", 1);
      write(stdErrDescriptor, "\n", 1);

      I'm calling that from the main thread and a sub thread. The output of those threads is serialized by internal program logic.

      I expected to see something like this when running the debug build in Qt Creator:

      Hello
      Hello
      Hello
      Hello
      Hello
      Hello

      However I get this:

      Hello
      Hello
      H
      e
      l
      l
      o
         
      H
      e
      l
      l
      o
         
      Hello
      Hello

      Please note that lines are not interleaved. Still a line feed is added after each write() call when executing the code snippet from a sub thread.

      The effect is completely reproducible when starting the debug build from Qt Creator under gdb supervision. However when manually stepping through the code or when running the debug build without debugger the output looks just fine.

      Thiago Macieira also run some tests and found that he could reproduce the problem without threads:
      "I can reproduce this with the attached test. The problem appears to be that when Qt Creator reads from the pipe, it assumes that whatever it read is a full line after a time out, when it isn't. It doesn't update the previous line when more characters are received."

      #include <unistd.h>
      int main()
      {
         write(2, "h", 1);
         sleep(1);
         write(2, "h", 1);
         sleep(1);
         write(2, "h", 1);
         sleep(1);
         write(2, "h", 1);
         sleep(1);
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            hjk hjk
            silicomancer Bernhard Lindner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes