Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program runs normally but gets Segmentation Fault in debugger
Forum Updated to NodeBB v4.3 + New Features

Program runs normally but gets Segmentation Fault in debugger

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 663 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.
  • M Offline
    M Offline
    Mike_W
    wrote on last edited by aha_1980
    #1

    I have a simple console app that looks for ports and checks their status for writing.

    #include <QCoreApplication>
    #include <QSerialPort>
    #include <QSerialPortInfo>
    #include <QIODevice>
    #include <iostream>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QSerialPort port;
        QList<QSerialPortInfo> qports = QSerialPortInfo::availablePorts();
    
        std::cout << qports.length() << " serial ports found\n" << std::endl;
    
        for(const QSerialPortInfo &portinfo : qports) {
            std::cout << "Checking port " << portinfo.portName().toStdString() << std::endl;
    
            port.setPortName(portinfo.portName());
    
    
            port.setBaudRate(QSerialPort::Baud9600);
            port.setDataBits(QSerialPort::Data8);
            port.setParity(QSerialPort::NoParity);
            port.setStopBits(QSerialPort::OneStop);
            port.setFlowControl(QSerialPort::HardwareControl);
            bool isOpen = port.open(QIODevice::WriteOnly);
            std::cout << "Port opened: " << ((isOpen) ? "TRUE" : "FALSE") << std::endl;
            std::cout << "Port writable: " << ((port.isWritable()) ? "TRUE" : "FALSE") << std::endl;
    
            std::cout << "Port is " << ((isOpen && port.isWritable()) ? "" : "not ") << "ready\n" << std::endl;
    
            port.close();
        }
        return a.exec();
    }
    

    The program runs successfully on Windows 10 and my output screen looks like this:

    3 serial ports found
    
    Checking port COM2
    Port opened: FALSE
    Port writable: FALSE
    Port is not ready
    
    Checking port COM3
    Port opened: TRUE
    Port writable: TRUE
    Port is ready
    
    Checking port COM4
    Port opened: FALSE
    Port writable: FALSE
    Port is not ready
    

    I set a breakpoint and start debugger I enter the debugger and expand the port variable to see its members. Then expanding some of those variables (d and properties) causes a Segmentation Fault dialog window to pop up. After I cancel the dialog I see that the issue occured in qserialport_p.h at the start ofthe QSerialPortPrivate class definition.

    class QSerialPortPrivate : public QIODevicePrivate
    {
        Q_DECLARE_PUBLIC(QSerialPort)
    

    I realize that these members have bad addresses. But is this normal or a problem? After I dispose of the dialog the app can continue fine. I want to know if this is a budding problem or if it is just a quirk of the Debug system. I declare my QSerialPort as a variable rather than construct it since I don't have a parent QObject for it. I want to know if I can ignore this and simply not debug into these QSerialPort members or if this is a future issue.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      but gets Segmentation Fault

      So where does it crash?

      I realize that these members have bad addresses.

      Qt is compiled in release mode - the debug information can not be accurate then.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        but gets Segmentation Fault

        So where does it crash?

        I realize that these members have bad addresses.

        Qt is compiled in release mode - the debug information can not be accurate then.

        M Offline
        M Offline
        Mike_W
        wrote on last edited by
        #3

        @Christian-Ehrlicher The program is compiled in Debug mode and runs fine if I don't try to debug it. However when I set a breakpoint (before executing port.close) and go into the debugger. I cannot expand some of the memebers of the port variable without getting a segmentation fault dialog.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mike_W said in Program runs normally but gets Segmentation Fault in debugger:

          I cannot expand some of the memebers of the port variable without getting a segmentation fault dialog.

          So not your program crashes but the debugger? What compiler and debugger do you use?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @Mike_W said in Program runs normally but gets Segmentation Fault in debugger:

            I cannot expand some of the memebers of the port variable without getting a segmentation fault dialog.

            So not your program crashes but the debugger? What compiler and debugger do you use?

            M Offline
            M Offline
            Mike_W
            wrote on last edited by Mike_W
            #5

            @Christian-Ehrlicher I am using MinGW 7.3.0 32-bit for C and C++. They are installed at C:\Qt5.12.6\Tools\mingw730_32\bin on my PC. They were installed with Qt Creator and Qt. The debugger is GNU gdb 8.1 for MinGW 7.3.0 32-bit in the same directory.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What version of QtCreator? Does creator or the debugger crash?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0

              • Login

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