JustPaste.it

Hi,

I'm trying to use QSharedPointer to define an object that will be created in a thread that will emit a signal to another thread. The application is working as expected (creating and destroying the objects).

However, when I try to debug using GDB, the debugger receives segmentation faults.

Below a simple code that could reproduce the issue:

------------
#ifndef TESTCLASS_H
#define TESTCLASS_H

#include <QSharedPointer>
class TestClass
{
public:
const static int m_nTypeId;
TestClass();
~TestClass();
};
typedef QSharedPointer<TestClass> SharedTestClass;
Q_DECLARE_METATYPE(SharedTestClass)

#endif // TESTCLASS_H
------------

------------
#include "testclass.h"
#include <QMetaType>
#include <qdebug.h>

const int TestClass::m_nTypeId = qRegisterMetaType< QSharedPointer<TestClass> >("QSharedPointer<TestClass>");

TestClass::TestClass()
{
qDebug() << "created";
}

TestClass::~TestClass()
{
qDebug() << "distroyed";
}
------------

------------
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include "testclass.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

{
QSharedPointer<TestClass> test = QSharedPointer<TestClass>(new TestClass());
qDebug() << test->m_nTypeId;
test.reset(new TestClass());
test.reset(new TestClass());
test.reset(new TestClass());
test.reset(new TestClass());
}

return a.exec();
}
------------

Running this code, the result in the console is as expected:

------------
created
1025
created
distroyed
created
distroyed
created
distroyed
created
distroyed
distroyed
------------

However, debugging the application using GDB, the debugger show a SIGABRT as below:


------------
root@emad:~# gdb /usr/sbin/testFunction
GNU gdb (GDB) 7.9.1
This GDB was configured as "arm-poky-linux-gnueabi".
(gdb) run
Starting program: /usr/sbin/testFunction

Program received signal SIGSEGV, Segmentation fault.
_dl_debug_initialize (ldbase=4294967292, ns=1095236752) at dl-debug.c:55
55 if (r->r_map == NULL || ldbase != 0)
(gdb)
------------

If the program not contain any QSharePointer, the issue debugging disappear.

A more complex program sending QSharePointer objects using slots has a similar situation with GDB, that can be reproduced with the previous example.

Thanks for any suggestion and comment,

Julio