add breakpad support on linux

This commit is contained in:
Green Sky
2024-11-12 12:53:39 +01:00
parent 9277ef34f6
commit 281e681bf8
7 changed files with 199 additions and 5 deletions

View File

@ -126,6 +126,16 @@ target_sources(tomato PUBLIC
./debug_video_tap.cpp
)
if (TOMATO_BREAKPAD)
target_sources(tomato PUBLIC
./breakpad_client.hpp
./breakpad_client.cpp
)
target_link_libraries(tomato PUBLIC breakpad_client)
target_compile_definitions(tomato PUBLIC TOMATO_BREAKPAD)
endif()
if (TOMATO_TOX_AV)
target_sources(tomato PUBLIC
./tox_av.hpp
@ -167,9 +177,6 @@ target_link_libraries(tomato PUBLIC
SDL3_image::SDL3_image
)
# probably not enough
#target_compile_definitions(tomato PUBLIC ENTT_API_EXPORT)
set_target_properties(tomato PROPERTIES POSITION_INDEPENDENT_CODE ON)
########################################

10
src/breakpad_client.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "./breakpad_client.hpp"
// if linux
bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void*, bool succeeded) {
fprintf(stderr, "Crash detected, MiniDump written to: %s\n", descriptor.path());
return succeeded;
}
// endif linux

22
src/breakpad_client.hpp Normal file
View File

@ -0,0 +1,22 @@
#pragma once
// TODO: if linux/android
#include <client/linux/handler/exception_handler.h>
bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void*, bool succeeded);
#define BREAKPAD_MAIN_INIT \
google_breakpad::MinidumpDescriptor bp_descriptor{"/tmp"}; \
bp_descriptor.set_sanitize_stacks(true); /* *should* remove most PII from stack mem dump */ \
bp_descriptor.set_size_limit(50*1024*1024); /* limit to 50mb */ \
google_breakpad::ExceptionHandler bp_eh{ \
bp_descriptor, \
nullptr, \
dumpCallback, \
nullptr, \
true, /* install handler */ \
-1, /* dump in-process (OOP would be better) */ \
}
// endif linux

View File

@ -19,14 +19,24 @@
#include <thread>
#include <chrono>
#ifdef TOMATO_BREAKPAD
# include "./breakpad_client.hpp"
#endif
int main(int argc, char** argv) {
runSysCheck();
#ifdef TOMATO_BREAKPAD
// TODO: maybe run before sys check?
BREAKPAD_MAIN_INIT;
#endif
// better args
std::vector<std::string_view> args;
for (int i = 0; i < argc; i++) {
args.push_back(argv[i]);
}
runSysCheck();
SDL_SetAppMetadata("tomato", "0.0.0-wip", nullptr);