Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win veh #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

qBreakpad is Qt library to use google-breakpad crash reporting facilities (and using it conviniently).
Supports
* Windows (but crash dump decoding will not work with MinGW compiler)
* Windows
* Linux
* MacOS X

Expand Down Expand Up @@ -41,4 +41,16 @@ Getting started with Google Breakpad
----------------
https://chromium.googlesource.com/breakpad/breakpad/+/master/docs/getting_started_with_breakpad.md

Tips of building and dump's decoding
----------------
* MinGW:
You can try to use the tool **cv2pdb**(https://github.com/rainers/cv2pdb), to strip the debug information from the binary and generate the pdb file,
then use Visual Studio to decode the dump conveniently.
* Linux:
You can use the tool **minidump-2-core** of Google Breakpad, to convert the dump file to core file, then use QtCreator to decode the dump conveniently.
* Mac:
Refer to qBreakpad's Wiki

Wiki
----------------
Detail description about integration `qBreakpad` into your system and platform you could find in **[Wiki](https://github.com/buzzySmile/qBreakpad/wiki)**.
5 changes: 4 additions & 1 deletion demo/demo.pro
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = program reporter
SUBDIRS = program \
programGui \
reporter

6 changes: 6 additions & 0 deletions demo/program/TestMainThread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "TestMainThread.h"

TestMainThread::TestMainThread(QObject *parent) : QObject(parent)
{

}
21 changes: 21 additions & 0 deletions demo/program/TestMainThread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef TESTMAINTHREAD_H
#define TESTMAINTHREAD_H

#include <QObject>
#include <QBreakpadHandler.h>

class TestMainThread : public QObject
{
Q_OBJECT
public:
explicit TestMainThread(QObject *parent = nullptr);

private slots:
void crash() {
QBreakpadHandler::toCrash();
}
signals:

};

#endif // TESTMAINTHREAD_H
21 changes: 14 additions & 7 deletions demo/program/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2009 Aleksey Palazhchenko
* Copyright (C) 2016 Alexander Makarov
*
Expand All @@ -22,6 +22,7 @@

#include "QBreakpadHandler.h"
#include "TestThread.h"
#include "TestMainThread.h"

int main(int argc, char* argv[])
{
Expand All @@ -34,12 +35,18 @@ int main(int argc, char* argv[])

QBreakpadInstance.setDumpPath("crashes");

qsrand(QDateTime::currentDateTime().toTime_t());
TestThread t1(false, qrand());
TestThread t2(true, qrand());

t1.start();
t2.start();
bool bTestMainThread = false;
if (bTestMainThread) {
TestMainThread mth;
QTimer::singleShot(1, &mth, SLOT(crash()));

} else {
qsrand(QDateTime::currentDateTime().toTime_t());
TestThread t1(false, qrand());
TestThread t2(true, qrand());
t1.start();
t2.start();
}

QTimer::singleShot(3000, qApp, SLOT(quit()));
return app.exec();
Expand Down
6 changes: 4 additions & 2 deletions demo/program/program.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ include($$PWD/../../qBreakpad.pri)
QMAKE_LIBDIR += $$PWD/../../handler
LIBS += -lqBreakpad

HEADERS += $$PWD/TestThread.h
SOURCES += $$PWD/TestThread.cpp
HEADERS += $$PWD/TestThread.h \
TestMainThread.h
SOURCES += $$PWD/TestThread.cpp \
TestMainThread.cpp

SOURCES += $$PWD/main.cpp

Expand Down
19 changes: 19 additions & 0 deletions demo/programGui/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{
QBreakpadHandler::toCrash();
}
27 changes: 27 additions & 0 deletions demo/programGui/MainWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <QBreakpadHandler.h>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();

private slots:
void on_pushButton_clicked();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
36 changes: 36 additions & 0 deletions demo/programGui/MainWindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>To Crash</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
15 changes: 15 additions & 0 deletions demo/programGui/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "MainWindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QBreakpadInstance.setDumpPath("crashes");
WinVeh::AddVeh();

MainWindow w;
w.show();
return a.exec();
}
26 changes: 26 additions & 0 deletions demo/programGui/programGui.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
QT += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

include($$PWD/../../qBreakpad.pri)

SOURCES += \
main.cpp \
MainWindow.cpp

HEADERS += \
MainWindow.h

FORMS += \
MainWindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
37 changes: 36 additions & 1 deletion handler/QBreakpadHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2009 Aleksey Palazhchenko
* Copyright (C) 2014 Sergey Shambir
* Copyright (C) 2016 Alexander Makarov
Expand Down Expand Up @@ -144,6 +144,11 @@ QString QBreakpadHandler::uploadUrl() const
return d->uploadUrl.toString();
}

QString QBreakpadHandler::dumpPath() const
{
return d->dumpPath;
}

QStringList QBreakpadHandler::dumpFileList() const
{
if(!d->dumpPath.isNull() && !d->dumpPath.isEmpty()) {
Expand All @@ -155,6 +160,36 @@ QStringList QBreakpadHandler::dumpFileList() const
return QStringList();
}

void QBreakpadHandler::DelOldDumpFiles(int keepLastestFileNum)
{
QStringList sDmpFileNames = QBreakpadInstance.dumpFileList();
if (sDmpFileNames.size() > keepLastestFileNum) {
QMap<QDateTime, QString> mapMTimeFile;
foreach (const QString &sFileName, sDmpFileNames) {
QString sFilePath = QBreakpadInstance.dumpPath() + "/" + sFileName;
QFileInfo fi(sFilePath);
// insertMulti: OS may not have enough time precision to tell the file's MTime(files created in a mostly same time), or files just are your test copys
mapMTimeFile.insertMulti(fi.lastModified(), sFilePath);
}

auto iter = mapMTimeFile.begin();
for (int i=0; i<mapMTimeFile.size() - keepLastestFileNum; i++, iter++) {
QFile::remove(iter.value());
}
}
}

void QBreakpadHandler::toCrash()
{
double VarWithInitValue = 456.321;
int VarWithDynVal = qrand();
if (VarWithInitValue == 0.0)
VarWithDynVal = 123321;

volatile int* iNotExistVar = (int*)(NULL);
*iNotExistVar = 2;
}

void QBreakpadHandler::setUploadUrl(const QUrl &url)
{
if(!url.isValid() || url.isEmpty())
Expand Down
12 changes: 11 additions & 1 deletion handler/QBreakpadHandler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2009 Aleksey Palazhchenko
* Copyright (C) 2014 Sergey Shambir
* Copyright (C) 2016 Alexander Makarov
Expand All @@ -24,6 +24,10 @@
#include <QUrl>
#include "singletone/singleton.h"

#if defined(Q_OS_WIN32)
#include "WinVeh.h"
#endif

namespace google_breakpad {
class ExceptionHandler;
class MinidumpDescriptor;
Expand All @@ -47,6 +51,12 @@ class QBreakpadHandler: public QObject
void setDumpPath(const QString& path);
void setUploadUrl(const QUrl& url);

/// Delete dump files but keep \a keepLastestFileNum latest file according file's time
static void DelOldDumpFiles(int keepLastestFileNum);

/// To crash. A static test function
static void toCrash();

public slots:
void sendDumps();

Expand Down
Loading