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. Having SIGSEGV when setting serial port name
Forum Updated to NodeBB v4.3 + New Features

Having SIGSEGV when setting serial port name

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
qserialportsetportnamesigsegv
4 Posts 3 Posters 1.3k 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.
  • C Offline
    C Offline
    cesar93
    wrote on last edited by
    #1

    First of all, sorry if my English is not very comprehensive, it's a little bit rusty, and if I made some error while describing my problem, it's my first post here.

    I'm having trouble when I try to execute the following method:

    serialPort->setPortName(port);
    

    The debugger returns a SIGSEGV error, and when I enter the function that contains the error I get the following error line:

    0x64781f02  <+0x0004>        8b 59 04                 mov    0x4(%ecx),%ebx
    

    Header file:

    #ifndef SERIAL_H
    #define SERIAL_H
    
    #include <QtCore>
    #include <QString>
    #include <QSerialPort>
    
    class Serial : public QObject
    {
        Q_OBJECT
    public:
        Serial();
        QMutex mutex;
        bool isConnected();
        bool serialConnect();
        bool setup();
        bool send(QString);
        bool connected;
        QString receive();
        void closeConnection();
    
    signals:
        void serialReceived(QString);
    
    private slots:
        void onSerialReceived();
    };
    
    #endif // SERIAL_H
    

    Source file:

    static QSerialPort *serialPort;
    
    Serial::Serial()
    {
        connected = false;
    }
    
    bool Serial::serialConnect()
    {
        foreach (const QSerialPortInfo &devinfo, QSerialPortInfo::availablePorts()) {
            QSerialPort devSerial;
            devSerial.setPort(devinfo);
    
            if(devSerial.open(QIODevice::ReadWrite)) {
                if(devinfo.description() == "Arduino Uno" && devinfo.manufacturer() == "Arduino LLC (www.arduino.cc)") {
                    QString port = devinfo.portName();
                    qDebug() << "Serial found: " << port;
                    serialPort->setPortName(port);         //This is where I get the error
                    devSerial.close();
                    if(setup()) {
                        qDebug() << "Setup completed.";
                        connected = true;
                        connect(serialPort, SIGNAL(readyRead()), this, SLOT(onSerialReceived()));
                        return true;
                    }else {
                        qDebug() << "Setup failed.";
                        return false;
                    }
                }
            }
        }
    }
    
    bool Serial::setup()
    {
        try {
            serialPort->setBaudRate(QSerialPort::Baud115200);
            serialPort->setDataBits(QSerialPort::Data8);
            serialPort->setParity(QSerialPort::NoParity);
            serialPort->setStopBits(QSerialPort::OneStop);
            serialPort->setFlowControl(QSerialPort::NoFlowControl);
            if(!serialPort->open(QIODevice::ReadWrite)){
                qDebug() << "Can't open serialport";
                return false;
            }
            return true;
        } catch (QException e) {
            return false;
        }
    }
    

    QSerialPort source (if needed):

    /        Function: QSerialPort::QSerialPort(QObject*)
    0x64781eee  <+0x0038>        c7 43 08 00 00 00 00     movl   $0x0,0x8(%ebx)
    0x64781ef5  <+0x003f>        83 c4 14                 add    $0x14,%esp
    0x64781ef8  <+0x0042>        5b                       pop    %ebx
    0x64781ef9  <+0x0043>        5e                       pop    %esi
    0x64781efa  <+0x0044>        c2 04 00                 ret    $0x4
            Function: _ZN11QSerialPortC2EP7QObject
    0x64781efd  <+0x0047>        90                       nop
            Function: QSerialPort::setPortName(QString const&)
    0x64781efe                   53                       push   %ebx
    0x64781eff  <+0x0001>        83 ec 28                 sub    $0x28,%esp
    0x64781f02  <+0x0004>        8b 59 04                 mov    0x4(%ecx),%ebx      //Error presents in this line
    0x64781f05  <+0x0007>        8d 44 24 1c              lea    0x1c(%esp),%eax
    0x64781f09  <+0x000b>        8b 54 24 30              mov    0x30(%esp),%edx
    0x64781f0d  <+0x000f>        89 54 24 04              mov    %edx,0x4(%esp)
    0x64781f11  <+0x0013>        89 04 24                 mov    %eax,(%esp)
    0x64781f14  <+0x0016>        e8 57 53 00 00           call   0x64787270 <QSerialPortInfoPrivate::portNameToSystemLocation(QString const&)>
    0x64781f19  <+0x001b>        8b 83 9c 00 00 00        mov    0x9c(%ebx),%eax
    0x64781f1f  <+0x0021>        8b 54 24 1c              mov    0x1c(%esp),%edx
    0x64781f23  <+0x0025>        89 93 9c 00 00 00        mov    %edx,0x9c(%ebx)
    0x64781f29  <+0x002b>        89 44 24 1c              mov    %eax,0x1c(%esp)
    0x64781f2d  <+0x002f>        89 c2                    mov    %eax,%edx
    0x64781f2f  <+0x0031>        8b 00                    mov    (%eax),%eax
    0x64781f31  <+0x0033>        85 c0                    test   %eax,%eax
    0x64781f33  <+0x0035>        74 16                    je     0x64781f4b <QSerialPort::setPortName(QString const&)+77>
    0x64781f35  <+0x0037>        83 f8 ff                 cmp    $0xffffffff,%eax
    0x64781f38  <+0x003a>        74 18                    je     0x64781f52 <QSerialPort::setPortName(QString const&)+84>
    0x64781f3a  <+0x003c>        b8 ff ff ff ff           mov    $0xffffffff,%eax
    0x64781f3f  <+0x0041>        f0 0f c1 02              lock xadd %eax,(%edx)
    0x64781f43  <+0x0045>        83 f8 01                 cmp    $0x1,%eax
    0x64781f46  <+0x0048>        0f 95 c0                 setne  %al
    0x64781f49  <+0x004b>        eb 0c                    jmp    0x64781f57 <QSerialPort::setPortName(QString const&)+89>
    0x64781f4b  <+0x004d>        b8 00 00 00 00           mov    $0x0,%eax
    0x64781f50  <+0x0052>        eb 05                    jmp    0x64781f57 <QSerialPort::setPortName(QString const&)+89>
    0x64781f52  <+0x0054>        b8 01 00 00 00           mov    $0x1,%eax
    0x64781f57  <+0x0059>        84 c0                    test   %al,%al
    0x64781f59  <+0x005b>        75 1d                    jne    0x64781f78 <QSerialPort::setPortName(QString const&)+122>
    0x64781f5b  <+0x005d>        c7 44 24 08 04 00 00 00  movl   $0x4,0x8(%esp)
    0x64781f63  <+0x0065>        c7 44 24 04 02 00 00 00  movl   $0x2,0x4(%esp)
    

    If somebody can give me a help on this I would appreciate, thanks in advance.

    JonBJ 1 Reply Last reply
    0
    • C cesar93

      First of all, sorry if my English is not very comprehensive, it's a little bit rusty, and if I made some error while describing my problem, it's my first post here.

      I'm having trouble when I try to execute the following method:

      serialPort->setPortName(port);
      

      The debugger returns a SIGSEGV error, and when I enter the function that contains the error I get the following error line:

      0x64781f02  <+0x0004>        8b 59 04                 mov    0x4(%ecx),%ebx
      

      Header file:

      #ifndef SERIAL_H
      #define SERIAL_H
      
      #include <QtCore>
      #include <QString>
      #include <QSerialPort>
      
      class Serial : public QObject
      {
          Q_OBJECT
      public:
          Serial();
          QMutex mutex;
          bool isConnected();
          bool serialConnect();
          bool setup();
          bool send(QString);
          bool connected;
          QString receive();
          void closeConnection();
      
      signals:
          void serialReceived(QString);
      
      private slots:
          void onSerialReceived();
      };
      
      #endif // SERIAL_H
      

      Source file:

      static QSerialPort *serialPort;
      
      Serial::Serial()
      {
          connected = false;
      }
      
      bool Serial::serialConnect()
      {
          foreach (const QSerialPortInfo &devinfo, QSerialPortInfo::availablePorts()) {
              QSerialPort devSerial;
              devSerial.setPort(devinfo);
      
              if(devSerial.open(QIODevice::ReadWrite)) {
                  if(devinfo.description() == "Arduino Uno" && devinfo.manufacturer() == "Arduino LLC (www.arduino.cc)") {
                      QString port = devinfo.portName();
                      qDebug() << "Serial found: " << port;
                      serialPort->setPortName(port);         //This is where I get the error
                      devSerial.close();
                      if(setup()) {
                          qDebug() << "Setup completed.";
                          connected = true;
                          connect(serialPort, SIGNAL(readyRead()), this, SLOT(onSerialReceived()));
                          return true;
                      }else {
                          qDebug() << "Setup failed.";
                          return false;
                      }
                  }
              }
          }
      }
      
      bool Serial::setup()
      {
          try {
              serialPort->setBaudRate(QSerialPort::Baud115200);
              serialPort->setDataBits(QSerialPort::Data8);
              serialPort->setParity(QSerialPort::NoParity);
              serialPort->setStopBits(QSerialPort::OneStop);
              serialPort->setFlowControl(QSerialPort::NoFlowControl);
              if(!serialPort->open(QIODevice::ReadWrite)){
                  qDebug() << "Can't open serialport";
                  return false;
              }
              return true;
          } catch (QException e) {
              return false;
          }
      }
      

      QSerialPort source (if needed):

      /        Function: QSerialPort::QSerialPort(QObject*)
      0x64781eee  <+0x0038>        c7 43 08 00 00 00 00     movl   $0x0,0x8(%ebx)
      0x64781ef5  <+0x003f>        83 c4 14                 add    $0x14,%esp
      0x64781ef8  <+0x0042>        5b                       pop    %ebx
      0x64781ef9  <+0x0043>        5e                       pop    %esi
      0x64781efa  <+0x0044>        c2 04 00                 ret    $0x4
              Function: _ZN11QSerialPortC2EP7QObject
      0x64781efd  <+0x0047>        90                       nop
              Function: QSerialPort::setPortName(QString const&)
      0x64781efe                   53                       push   %ebx
      0x64781eff  <+0x0001>        83 ec 28                 sub    $0x28,%esp
      0x64781f02  <+0x0004>        8b 59 04                 mov    0x4(%ecx),%ebx      //Error presents in this line
      0x64781f05  <+0x0007>        8d 44 24 1c              lea    0x1c(%esp),%eax
      0x64781f09  <+0x000b>        8b 54 24 30              mov    0x30(%esp),%edx
      0x64781f0d  <+0x000f>        89 54 24 04              mov    %edx,0x4(%esp)
      0x64781f11  <+0x0013>        89 04 24                 mov    %eax,(%esp)
      0x64781f14  <+0x0016>        e8 57 53 00 00           call   0x64787270 <QSerialPortInfoPrivate::portNameToSystemLocation(QString const&)>
      0x64781f19  <+0x001b>        8b 83 9c 00 00 00        mov    0x9c(%ebx),%eax
      0x64781f1f  <+0x0021>        8b 54 24 1c              mov    0x1c(%esp),%edx
      0x64781f23  <+0x0025>        89 93 9c 00 00 00        mov    %edx,0x9c(%ebx)
      0x64781f29  <+0x002b>        89 44 24 1c              mov    %eax,0x1c(%esp)
      0x64781f2d  <+0x002f>        89 c2                    mov    %eax,%edx
      0x64781f2f  <+0x0031>        8b 00                    mov    (%eax),%eax
      0x64781f31  <+0x0033>        85 c0                    test   %eax,%eax
      0x64781f33  <+0x0035>        74 16                    je     0x64781f4b <QSerialPort::setPortName(QString const&)+77>
      0x64781f35  <+0x0037>        83 f8 ff                 cmp    $0xffffffff,%eax
      0x64781f38  <+0x003a>        74 18                    je     0x64781f52 <QSerialPort::setPortName(QString const&)+84>
      0x64781f3a  <+0x003c>        b8 ff ff ff ff           mov    $0xffffffff,%eax
      0x64781f3f  <+0x0041>        f0 0f c1 02              lock xadd %eax,(%edx)
      0x64781f43  <+0x0045>        83 f8 01                 cmp    $0x1,%eax
      0x64781f46  <+0x0048>        0f 95 c0                 setne  %al
      0x64781f49  <+0x004b>        eb 0c                    jmp    0x64781f57 <QSerialPort::setPortName(QString const&)+89>
      0x64781f4b  <+0x004d>        b8 00 00 00 00           mov    $0x0,%eax
      0x64781f50  <+0x0052>        eb 05                    jmp    0x64781f57 <QSerialPort::setPortName(QString const&)+89>
      0x64781f52  <+0x0054>        b8 01 00 00 00           mov    $0x1,%eax
      0x64781f57  <+0x0059>        84 c0                    test   %al,%al
      0x64781f59  <+0x005b>        75 1d                    jne    0x64781f78 <QSerialPort::setPortName(QString const&)+122>
      0x64781f5b  <+0x005d>        c7 44 24 08 04 00 00 00  movl   $0x4,0x8(%esp)
      0x64781f63  <+0x0065>        c7 44 24 04 02 00 00 00  movl   $0x2,0x4(%esp)
      

      If somebody can give me a help on this I would appreciate, thanks in advance.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @cesar93

      static QSerialPort *serialPort;

      That gives you a NULL serialPort. Where do you actually create/new it, before you get to the line:

      serialPort->setPortName(port);         //This is where I get the error
      

      ?

      1 Reply Last reply
      1
      • C Offline
        C Offline
        cesar93
        wrote on last edited by
        #3

        Thanks for the quickly reply,

        It was working before, I guess that when I added a piece of code to it I must have erased the part where I initialized the serialPort, already get it to work again, thanks.

        aha_1980A 1 Reply Last reply
        1
        • C cesar93

          Thanks for the quickly reply,

          It was working before, I guess that when I added a piece of code to it I must have erased the part where I initialized the serialPort, already get it to work again, thanks.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @cesar93 so if your problem is solved, please mark this topic as SOLVED too. Thanks

          Qt has to stay free or it will die.

          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