-
Notifications
You must be signed in to change notification settings - Fork 2
/
breakpad.cc
129 lines (114 loc) · 3.99 KB
/
breakpad.cc
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "breakpad.hpp"
#include <utils/utils.h>
#include <QDebug>
#include <QDesktopServices>
#if defined(Q_OS_WIN)
#include <client/windows/handler/exception_handler.h>
#elif defined(Q_OS_MAC)
#include <client/mac/handler/exception_handler.h>
#elif defined(Q_OS_LINUX)
#include <client/linux/handler/exception_handler.h>
#endif
#ifdef Q_OS_WIN
#define CrashReportName "CrashReport.exe"
#else
#define CrashReportName "CrashReport"
#endif
namespace Dump {
// 程序崩溃回调函数;
#if defined(Q_OS_WIN)
auto callback(const wchar_t *dump_path,
const wchar_t *id,
void * /*unused*/,
EXCEPTION_POINTERS * /*unused*/,
MDRawAssertionInfo * /*unused*/,
bool succeeded) -> bool
{
if (succeeded) {
qInfo() << "Create dump file success:" << QString::fromWCharArray(dump_path)
<< QString::fromWCharArray(id);
emit BreakPad::instance()->crash();
} else {
qWarning() << "Create dump file failed";
}
return succeeded;
}
#elif defined(Q_OS_MAC)
bool callback(const char *dump_dir, const char *minidump_id, void *, bool succeeded)
{
if (succeeded) {
qInfo() << "Create dump file success:" << dump_dir << minidump_id;
emit BreakPad::instance()->crash();
} else {
qWarning() << "Create dump file failed";
}
return succeeded;
}
#elif defined(Q_OS_LINUX)
bool callback(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded)
{
Q_UNUSED(context)
if (succeeded) {
qInfo() << "Create dump file success:" << QString::fromLocal8Bit(descriptor.path());
emit BreakPad::instance()->crash();
} else {
qWarning() << "Create dump file failed";
}
return succeeded;
}
#endif
class BreakPad::BreakPadPrivate
{
public:
explicit BreakPadPrivate(BreakPad *q)
: q_ptr(q)
{}
void setDumpPath(const QString &path)
{
#if defined(Q_OS_WIN)
exceptionHandlerPtr.reset(
new google_breakpad::ExceptionHandler(path.toStdWString(),
nullptr,
callback,
nullptr,
google_breakpad::ExceptionHandler::HANDLER_ALL));
#elif defined(Q_OS_MAC)
exceptionHandlerPtr.reset(new google_breakpad::ExceptionHandler(path.toStdString(),
nullptr,
callback,
nullptr,
true,
nullptr));
#elif defined(Q_OS_LINUX)
exceptionHandlerPtr.reset(
new google_breakpad::ExceptionHandler(google_breakpad::MinidumpDescriptor(
path.toStdString()),
nullptr,
callback,
nullptr,
true,
-1));
#endif
}
~BreakPadPrivate() = default;
BreakPad *q_ptr;
QScopedPointer<google_breakpad::ExceptionHandler> exceptionHandlerPtr;
};
void BreakPad::setDumpPath(const QString &path)
{
d_ptr->setDumpPath(path);
}
BreakPad::BreakPad(QObject *parent)
: QObject{parent}
, d_ptr(new BreakPadPrivate(this))
{}
BreakPad::~BreakPad() = default;
void openCrashReporter()
{
const auto reporterPath = qApp->applicationDirPath() + "/" + CrashReportName;
QStringList args{Utils::crashPath(), Utils::logPath(), qApp->applicationFilePath()};
args.append(qApp->arguments());
QProcess process;
process.startDetached(reporterPath, args);
}
} // namespace Dump