Skip to content

Commit

Permalink
windows breakpad
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Nov 15, 2024
1 parent 3fbbf80 commit 1cd1390
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
#- uses: ilammy/setup-nasm@v1

- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DSDLIMAGE_VENDORED=ON -DSDLIMAGE_DEPS_SHARED=ON -DSDLIMAGE_JXL=OFF -DSDLIMAGE_AVIF=OFF -DPKG_CONFIG_EXECUTABLE=C:/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe -DTOMATO_TOX_AV=ON
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DSDLIMAGE_VENDORED=ON -DSDLIMAGE_DEPS_SHARED=ON -DSDLIMAGE_JXL=OFF -DSDLIMAGE_AVIF=OFF -DPKG_CONFIG_EXECUTABLE=C:/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe -DTOMATO_BREAKPAD=ON -DTOMATO_TOX_AV=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t tomato
Expand Down
23 changes: 16 additions & 7 deletions external/breakpad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ if (NOT TARGET breakpad_client)
if(NOT breakpad_POPULATED)
FetchContent_Populate(breakpad)

enable_language(ASM)
add_library(breakpad_common STATIC
${breakpad_SOURCE_DIR}/src/common/convert_UTF.h
${breakpad_SOURCE_DIR}/src/common/convert_UTF.cc
Expand All @@ -51,19 +50,27 @@ if (NOT TARGET breakpad_client)
target_include_directories(breakpad_common PUBLIC "${breakpad_SOURCE_DIR}/src")

if (WIN32)
# TODO: common
target_sources(breakpad_common PUBLIC
${breakpad_SOURCE_DIR}/src/common/windows/guid_string.h
${breakpad_SOURCE_DIR}/src/common/windows/guid_string.cc
)

add_library(breakpad_client STATIC)
target_sources(breakpad_client
PUBLIC
${breakpad_SOURCE_DIR}/src/client/windows/handler/exception_handler.h
${breakpad_SOURCE_DIR}/src/client/windows/common/ipc_protocol.h
${breakpad_SOURCE_DIR}/src/client/windows/crash_generation/crash_generation_client.h
${breakpad_SOURCE_DIR}/src/client/windows/crash_generation/minidump_generator.h
PRIVATE
${breakpad_SOURCE_DIR}/src/client/windows/handler/exception_handler.cc
${breakpad_SOURCE_DIR}/src/client/windows/crash_generation/crash_generation_client.cc
${breakpad_SOURCE_DIR}/src/client/windows/crash_generation/minidump_generator.cc
)
target_compile_definitions(breakpad_client PRIVATE UNICODE)
#elseif() # TODO: mac, ios and any other platform
else() # assume linux
enable_language(ASM) # mostly to document, needs to be set in parent
target_sources(breakpad_common PUBLIC
${breakpad_SOURCE_DIR}/src/common/linux/elf_core_dump.cc
${breakpad_SOURCE_DIR}/src/common/linux/elfutils.h
Expand Down Expand Up @@ -115,11 +122,13 @@ if (NOT TARGET breakpad_client)
endif()

if (TARGET breakpad_client)
target_sources(breakpad_client PUBLIC
${breakpad_SOURCE_DIR}/src/client/minidump_file_writer-inl.h
${breakpad_SOURCE_DIR}/src/client/minidump_file_writer.h
${breakpad_SOURCE_DIR}/src/client/minidump_file_writer.cc
)
if (NOT WIN32)
target_sources(breakpad_client PUBLIC
${breakpad_SOURCE_DIR}/src/client/minidump_file_writer-inl.h
${breakpad_SOURCE_DIR}/src/client/minidump_file_writer.h
${breakpad_SOURCE_DIR}/src/client/minidump_file_writer.cc
)
endif()
target_link_libraries(breakpad_client PUBLIC breakpad_common)
target_include_directories(breakpad_client PUBLIC "${breakpad_SOURCE_DIR}/src")
target_compile_features(breakpad_client PUBLIC cxx_std_11)
Expand Down
34 changes: 31 additions & 3 deletions src/breakpad_client.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
#include "./breakpad_client.hpp"

// if linux
#ifdef WIN32

bool dumpCallback(const wchar_t* dump_path, const wchar_t* minidump_id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool succeeded) {
//TCHAR* text = new TCHAR[kMaximumLineLength];
//text[0] = _T('\0');
//int result = swprintf_s(text,
// kMaximumLineLength,
// TEXT("Dump generation request %s\r\n"),
// succeeded ? TEXT("succeeded") : TEXT("failed"));
//if (result == -1) {
// delete [] text;
//}

//QueueUserWorkItem(AppendTextWorker, text, WT_EXECUTEDEFAULT);

if (succeeded) {
fprintf(stderr, "Crash detected, MiniDump written to: %ls\n", dump_path);
} else {
fprintf(stderr, "Crash detected, failed to write MiniDump. (path: %ls)\n", dump_path);
}
return succeeded;
}

#else
// linux

bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void*, bool succeeded) {
fprintf(stderr, "Crash detected, MiniDump written to: %s\n", descriptor.path());
if (succeeded) {
fprintf(stderr, "Crash detected, MiniDump written to: %s\n", descriptor.path());
} else {
fprintf(stderr, "Crash detected, failed to write MiniDump. (path: %s)\n", descriptor.path());
}
return succeeded;
}

// endif linux
#endif
20 changes: 18 additions & 2 deletions src/breakpad_client.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#pragma once

// TODO: if linux/android
// TODO: require msvc
#ifdef WIN32

#include <client/windows/handler/exception_handler.h>

bool dumpCallback(const wchar_t* dump_path, const wchar_t* minidump_id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool succeeded);

#define BREAKPAD_MAIN_INIT \
google_breakpad::ExceptionHandler bp_eh{ \
L".\\", /* path */ \
nullptr, \
dumpCallback, \
nullptr, \
google_breakpad::ExceptionHandler::HANDLER_ALL, \
}

#else

#include <client/linux/handler/exception_handler.h>

Expand All @@ -19,4 +35,4 @@ bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void*,
-1, /* dump in-process (OOP would be better) */ \
}

// endif linux
#endif

0 comments on commit 1cd1390

Please sign in to comment.