我是靠谱客的博主 俊秀乐曲,这篇文章主要介绍4. Linux下通过Core文件查找Qt5程序异常退出的问题,现在分享给大家,希望可以做个参考。

  • 环境和工具: Qt5.6.2 MinGW 、 Red Hat

1. 首先配置Core文件的生成环境

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
步骤一: 首先通过 ulimit –c 查看 若为0,则不会产生对应的coredump,需要进行修改和设置。 ulimit -c unlimited (可以产生coredump且不受大小限制),这种设置仅对当前生效; Tisp:如果想永久生效,在/etc/profile中加入以下一行,这将允许生成coredump文件 ulimit -c unlimited 步骤二: vi /etc/sysctl.conf 添加下面两行; kernel.core_uses_pid = 1 kernel.core_pattern=/tmp/core-%e-%p Tips (kernel.core_pattern 的设置规则如下): { %p -insert pid into filename %u - insertcurrent uid into filename %g - insert current gidinto filename %s - insert signal thatcaused the coredump into the filename %t - insert UNIX time thatthe coredump occurred into filename %h - insert hostname wherethe coredump happened into filename %e -insert coredumping executable name into filename } 最后: sysctl -p /etc/sysctl.conf 将修改的配置生效

2. 打开Qt5.6.2 创建一个工程 TestExceptionDump

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::a() { qDebug()<<"this is c"; } void MainWindow::b() { qDebug()<<"this is b"; } void MainWindow::c() { // 异常位置 int *i = NULL; *i = 100; } void MainWindow::on_pushButton_clicked() { int kkk = 1000; qDebug()<<"this is button " << kkk; a(); b(); c(); }

3. 运行

在这里插入图片描述

4.程序崩溃

在这里插入图片描述
查看core配置路径/tmp文件夹发现生成了一个core文件
在这里插入图片描述
将这个文件copy到工程执行程序的目录下
在这里插入图片描述
执行命令:gdb TestExeceptionDump core-TestExceptionDu-4138
在这里插入图片描述
然后在执行命令:bt (back trace 堆栈查询)

在这里插入图片描述
从上图中可以看出最后一个执行的位置在c()函数中,从而分析错误的位置;

最后

以上就是俊秀乐曲最近收集整理的关于4. Linux下通过Core文件查找Qt5程序异常退出的问题的全部内容,更多相关4.内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部