QT 5.15提高细分故障(核心倾倒),但无用的coredump文件
为了学习如何使用Coredump文件在代码中获取错误行,我编写了一个示例项目,但是从Coredump文件的消息中,我一无所知。是否有人知道如何为QT(C ++&& qml)创建有用的Coredump文件? 这是我的项目,当单击按钮触发SEG故障时!
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
这是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();
}
,这是retest.h and retest.cpp文件:
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;
}
这是QML文件,单击按钮调用SEG故障函数:
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()
}
}
}
这是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))]
那么,有什么问题核心转储文件参考QT! CoreDump文件无用,我无法应用这种在其他更复杂的项目上找到细分故障的方法!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论