Skip to content

Commit 961fa0d

Browse files
committed
add breakpad crash handler for Windows
Integrate and modify code from this demo: https://github.com/KandaoVR/qt-breakpad Use the latest version of breakpad with the cmake file from the vcpkg port. To enable the crash handler, pass the cmake option to `generate.py`, e.g.: ```bash python ./generate.py -cmake-flags '-DENABLE_CRASH_HANDLER=ON' release ``` It will then be activated for both the terminal and the signer. When `OFF` breakpad will still be in effect to launch the systray cleanup code, but the crash handler will not display. I am working on the report receiver web app here: https://github.com/rkitover/qt-breakpad-web TODO: - see if mac and linux can work Signed-off-by: Rafael Kitover <rkitover@gmail.com>
1 parent fb18e68 commit 961fa0d

20 files changed

+1309
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "AuthAPI"]
88
path = AuthAPI
99
url = https://github.com/autheid/AuthAPI
10+
[submodule "breakpad/breakpad"]
11+
path = breakpad/breakpad
12+
url = https://github.com/google/breakpad.git

BlockSettleApp/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ FILE(GLOB SOURCES *.cpp)
44
FILE(GLOB HEADERS *.h)
55

66
INCLUDE_DIRECTORIES( ${COMMON_UI_LIB_INCLUDE_DIR} )
7+
8+
if(WIN32)
9+
set(SOURCES ${SOURCES} ../breakpad/qtsystemexceptionhandler.cpp)
10+
set(HEADERS ${HEADERS} ../breakpad/qtsystemexceptionhandler.h)
11+
endif()
12+
713
INCLUDE_DIRECTORIES( ${COMMON_LIB_INCLUDE_DIR} )
814
INCLUDE_DIRECTORIES( ${BLOCKSETTLE_UI_INCLUDE_DIR} )
915
INCLUDE_DIRECTORIES( ${BS_NETWORK_INCLUDE_DIR} )
@@ -14,6 +20,7 @@ INCLUDE_DIRECTORIES( ${CRYPTO_LIB_INCLUDE_DIR} )
1420
INCLUDE_DIRECTORIES( ${BOTAN_INCLUDE_DIR} )
1521
INCLUDE_DIRECTORIES( ${Qt5Svg_INCLUDE_DIRS} )
1622

23+
1724
IF ( APPLE )
1825
SET( BUNDLE_NAME "BlockSettle Terminal" )
1926

@@ -58,4 +65,13 @@ TARGET_LINK_LIBRARIES( ${BLOCKSETTLE_APP_NAME}
5865
${QT_LIBS}
5966
${OS_SPECIFIC_LIBS}
6067
${OPENSSL_LIBS}
68+
)
69+
70+
if(WIN32)
71+
target_include_directories(${BLOCKSETTLE_APP_NAME}
72+
PRIVATE ${CMAKE_BINARY_DIR}/common/BlockSettleUILib # for TerminalVersion.h
73+
PRIVATE ../breakpad
6174
)
75+
target_compile_definitions(${BLOCKSETTLE_APP_NAME} PRIVATE -DENABLE_QT_BREAKPAD)
76+
target_link_libraries(${BLOCKSETTLE_APP_NAME} libbreakpad)
77+
endif()

BlockSettleApp/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include "btc/ecc.h"
2323

2424
#include "AppNap.h"
25+
#include "TerminalVersion.h"
26+
27+
#ifdef ENABLE_QT_BREAKPAD
28+
#include "qtsystemexceptionhandler.h"
29+
#endif
2530

2631
#ifdef USE_QWindowsIntegrationPlugin
2732
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
@@ -171,6 +176,16 @@ static int GuiApp(int &argc, char** argv)
171176
QApplication app(argc, argv);
172177
#endif
173178

179+
app.setApplicationVersion(QLatin1String(TERMINAL_VERSION_STRING));
180+
181+
#ifdef ENABLE_QT_BREAKPAD
182+
// uncomment this to test the crash handler
183+
//QTimer::singleShot(13000, []{ QtSystemExceptionHandler::crash(); });
184+
QtSystemExceptionHandler exceptionHandler(app.applicationDirPath());
185+
#endif
186+
187+
QApplication::setOrganizationName(QLatin1String("BlockSettle"));
188+
QApplication::setApplicationName(QLatin1String("Terminal"));
174189

175190
QApplication::setQuitOnLastWindowClosed(false);
176191

@@ -255,6 +270,7 @@ static int GuiApp(int &argc, char** argv)
255270
splashScreen.setGeometry(splashGeometry);
256271

257272
splashScreen.show();
273+
258274
app.processEvents();
259275

260276
#ifdef NDEBUG
@@ -264,6 +280,9 @@ static int GuiApp(int &argc, char** argv)
264280
#endif
265281
}
266282

283+
#include <QTextStream>
284+
#include <QFile>
285+
267286
int main(int argc, char** argv)
268287
{
269288
srand(std::time(nullptr));

BlockSettleSigner/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ LIST(APPEND HEADERS ${HEADERS_QML})
1414

1515
FILE(GLOB RESOURCE_FILES *.qrc)
1616

17+
if(WIN32)
18+
set(SOURCES ${SOURCES} ../breakpad/qtsystemexceptionhandler.cpp)
19+
set(HEADERS ${HEADERS} ../breakpad/qtsystemexceptionhandler.h)
20+
endif()
1721

1822
INCLUDE_DIRECTORIES( interfaces/GUI_QML )
1923
INCLUDE_DIRECTORIES( ${COMMON_LIB_INCLUDE_DIR} )
@@ -81,3 +85,12 @@ TARGET_LINK_LIBRARIES(${SIGNER_APP_NAME}
8185
${OS_SPECIFIC_LIBS}
8286
${OPENSSL_LIBS}
8387
)
88+
89+
if(WIN32)
90+
target_include_directories(${SIGNER_APP_NAME}
91+
PRIVATE ${CMAKE_BINARY_DIR}/common/BlockSettleUILib # for TerminalVersion.h
92+
PRIVATE ../breakpad
93+
)
94+
target_compile_definitions(${SIGNER_APP_NAME} PRIVATE -DENABLE_QT_BREAKPAD)
95+
target_link_libraries(${SIGNER_APP_NAME} libbreakpad)
96+
endif()

BlockSettleSigner/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
#include "QmlBridge.h"
3636

3737
#include "AppNap.h"
38+
#include "TerminalVersion.h"
39+
40+
#ifdef ENABLE_QT_BREAKPAD
41+
#include "qtsystemexceptionhandler.h"
42+
#endif
3843

3944
Q_DECLARE_METATYPE(std::string)
4045
Q_DECLARE_METATYPE(std::vector<BinaryData>)
@@ -181,6 +186,14 @@ static int QMLApp(int argc, char **argv
181186
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
182187
QApplication app(argc, argv);
183188

189+
app.setApplicationVersion(QLatin1String(TERMINAL_VERSION_STRING));
190+
191+
#ifdef ENABLE_QT_BREAKPAD
192+
// uncomment this to test the crash handler
193+
//QTimer::singleShot(20000, []{ QtSystemExceptionHandler::crash(); });
194+
QtSystemExceptionHandler exceptionHandler(app.applicationDirPath());
195+
#endif
196+
184197
QApplication::setOrganizationDomain(QLatin1String("blocksettle.com"));
185198
#ifdef __linux__
186199
// Needed for consistency (headless now uses company name in lowercase on Linux)

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ endif()
1414

1515
option(BSTERMINAL_SHARED_LIBS "Build shared libraries" OFF)
1616

17+
option(ENABLE_CRASH_HANDLER "Enable the crash handler" OFF)
18+
1719
add_definitions(-DSTATIC_BUILD)
1820
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG)
1921

@@ -798,6 +800,11 @@ ADD_SUBDIRECTORY( Celer )
798800
ADD_SUBDIRECTORY( common/Blocksettle_proto )
799801
ADD_SUBDIRECTORY( AuthAPI )
800802

803+
if(WIN32)
804+
add_subdirectory(breakpad)
805+
add_subdirectory(qtcrashhandler)
806+
endif()
807+
801808
ADD_SUBDIRECTORY(BlockSettleApp)
802809
ADD_SUBDIRECTORY(BlockSettleSigner)
803810

breakpad/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.0.2)
2+
project(libbreakpad CXX)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
add_definitions(
8+
-DNOMINMAX
9+
-DUNICODE
10+
-DWIN32_LEAN_AND_MEAN
11+
-D_CRT_SECURE_NO_WARNINGS
12+
-D_CRT_SECURE_NO_DEPRECATE
13+
-D_CRT_NONSTDC_NO_DEPRECATE
14+
-D_LIBCPP_VERSION
15+
)
16+
17+
file(GLOB_RECURSE LIBBREAKPAD_CLIENT_SOURCES breakpad/src/client/windows/*.cc breakpad/src/common/windows/*.cc)
18+
19+
include_directories("$ENV{VSINSTALLDIR}/DIA SDK/include")
20+
21+
file(GLOB LIBBREAKPAD_COMMON_SOURCES breakpad/src/common/*.cc breakpad/src/common/*.c breakpad/src/client/*.cc)
22+
23+
list(APPEND LIBBREAKPAD_CLIENT_SOURCES ${LIBBREAKPAD_COMMON_SOURCES})
24+
25+
list(FILTER LIBBREAKPAD_CLIENT_SOURCES EXCLUDE REGEX "/tests|/unittests|_unittest")
26+
27+
list(FILTER LIBBREAKPAD_CLIENT_SOURCES EXCLUDE REGEX "language.cc|path_helper.cc|stabs_to_module.cc|stabs_reader.cc|minidump_file_writer.cc")
28+
29+
add_library(libbreakpad ${LIBBREAKPAD_CLIENT_SOURCES})
30+
31+
target_link_libraries(libbreakpad PRIVATE wininet.lib)
32+
33+
target_include_directories(libbreakpad
34+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/breakpad/src
35+
)

breakpad/breakpad

Submodule breakpad added at db1cda2

0 commit comments

Comments
 (0)