1 year ago

#366227

test-img

LLLDaniel

QT 5.15 raise segmentation fault (core dumped) but the coredump file's useless

for learning how to use coredump file to obtain the error line in the code, I write a example project, but from the coredump file's message I can know nothing. is there anyone know how to create a useful coredump file for qt(c++ && qml)? here is my project, when click the button trigger a seg fault!

testDebugqml.pro

QT += 3dcore 3drender 3dinput 3dlogic 3dextras 3danimation qml quick 3dquick  widgets
CONFIG += c++11

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += main.cpp \
    retest.cpp

RESOURCES += qml.qrc

QML_IMPORT_PATH =

QML_DESIGNER_IMPORT_PATH =

qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

HEADERS += \
    retest.h

QMAKE_CC += -g
QMAKE_CXX += -Wall -Wextra -g
QMAKE_LINK += -g

and this is the main.cpp

#include "retest.h"
#include "trackballcameracontroller.h"

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include <QLine>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    engine.rootContext()->setContextProperty(QLatin1String("reTest"), RETest::getInstance());

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));


    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

and this is reTest.h and reTest.cpp file:

reTest.h

class RETest : public QObject
{
    Q_OBJECT
    SINGLETON(RETest)
    QML_WRITABLE_PROPERTY(int, translation)
public:
    explicit RETest(QObject *parent = nullptr);

    Q_INVOKABLE void func();

signals:

public slots:
};
#include "retest.h"

RETest::RETest(QObject *parent) : QObject(parent)
{

}

void RETest::func()
{
    int *ptemp = new int();

    qDebug() << (ptemp != nullptr);
    if(ptemp){
        delete ptemp;
    }
    *ptemp = 1;

}

and this is the qml file, click the button invoke the seg fault function:

import QtQuick 2.9
import QtQuick.Controls 2.15
import QtQuick.Window 2.2


import Qt3D.Core 2.15
import Qt3D.Render 2.15
import Qt3D.Extras 2.15
import Qt3D.Logic 2.15
import Qt3D.Input 2.15
import Qt3D.Animation 2.15
import QtQuick.Scene3D 2.15
import QtQuick.Controls.Material 2.15
import TrackballCameraController 1.0

ApplicationWindow {
    id:root

    visible: true
    width: 640
    height: 480
    title: qsTr("Scroll")


    Button{
        text:"click"
        anchors.right: parent.right
        onClicked:{
            //trigger a segment fault!
            reTest.func()
        }
    }
}

and this is the core dump message in gdb:

GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./testDebugqml...done.
[New LWP 12981]
[New LWP 12984]
[New LWP 12982]
[New LWP 12989]
[New LWP 12983]
[New LWP 12985]
[New LWP 12987]
[New LWP 12988]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./testDebugqml'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  tcache_get (tc_idx=0) at malloc.c:2952
2952    malloc.c: No such file or directory.
[Current thread is 1 (Thread 0x7f6eb2bb0800 (LWP 12981))]

So, what's wrong with the core dump file refer to QT! the coredump file useless, I can't apply this method of locating segment fault on other more complex project!

c++

qt

coredump

0 Answers

Your Answer

Accepted video resources