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

feat: Add Breakpad support for Windows #278

Merged
merged 17 commits into from
Jun 17, 2020
Merged
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
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ endif()
option(SENTRY_ENABLE_INSTALL "Enable sentry installation" "${SENTRY_MAIN_PROJECT}")

if(MSVC AND CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
message(WARNING "Crashpad is not supported for MSVC with XP toolset. Default backend was switched to 'none'")
set(SENTRY_DEFAULT_BACKEND "none")
message(WARNING "Crashpad is not supported for MSVC with XP toolset. Default backend was switched to 'breakpad'")
set(SENTRY_DEFAULT_BACKEND "breakpad")
elseif(APPLE OR WIN32)
set(SENTRY_DEFAULT_BACKEND "crashpad")
elseif(LINUX)
Expand All @@ -119,8 +119,8 @@ endif()
if(SENTRY_BACKEND_CRASHPAD AND NOT (APPLE OR WIN32))
message(FATAL_ERROR "The Crashpad backend is currently only supported on macOS and Windows")
endif()
if(SENTRY_BACKEND_BREAKPAD AND NOT LINUX)
message(FATAL_ERROR "The Breakpad backend is currently only supported on Linux")
if(SENTRY_BACKEND_BREAKPAD AND NOT (LINUX OR WIN32))
message(FATAL_ERROR "The Breakpad backend is currently only supported on Linux and Windows")
endif()
if(SENTRY_BACKEND_INPROC AND WIN32)
message(FATAL_ERROR "The in-process backend is not supported on Windows")
Expand Down Expand Up @@ -196,6 +196,10 @@ add_subdirectory(src)

set_target_properties(sentry PROPERTIES PUBLIC_HEADER "include/sentry.h")

# check size type
include(CheckTypeSize)
check_type_size("long" CMAKE_SIZEOF_LONG)

# https://gitlab.kitware.com/cmake/cmake/issues/18393
if(BUILD_SHARED_LIBS)
if(APPLE)
Expand All @@ -211,6 +215,7 @@ if(BUILD_SHARED_LIBS)
else()
target_compile_definitions(sentry PUBLIC SENTRY_BUILD_STATIC)
endif()
target_compile_definitions(sentry PRIVATE SIZEOF_LONG=${CMAKE_SIZEOF_LONG})

if(SENTRY_TRANSPORT_CURL)
find_package(CURL REQUIRED)
Expand Down Expand Up @@ -278,7 +283,10 @@ endif()

#respect CMAKE_SYSTEM_VERSION
if(WIN32)
if(${CMAKE_SYSTEM_VERSION} MATCHES "^10")
if(MSVC AND CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
#force WINNT to 5.1 for Windows XP toolchain
target_compile_definitions(sentry PRIVATE "_WIN32_WINNT=0x0501")
elseif(${CMAKE_SYSTEM_VERSION} MATCHES "^10")
target_compile_definitions(sentry PRIVATE "_WIN32_WINNT=0x0A00")
elseif(${CMAKE_SYSTEM_VERSION} MATCHES "^6.3")
target_compile_definitions(sentry PRIVATE "_WIN32_WINNT=0x0603")
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ format: setup-venv

style: setup-venv
@.venv/bin/python ./scripts/check-clang-format.py -r examples include src tests/unit
@.venv/bin/black --check tests
@.venv/bin/black --diff --check tests
.PHONY: style
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The SDK supports different features on the target platform:
have the `curl` library available. On other platforms, library users need to
implement their own transport, based on the `function transport` API.
- **Crashpad Backend** is currently only supported on Windows and macOS.
- **Breakpad Backend** is currently only supported on Linux.
- **Breakpad Backend** is currently only supported on Linux and Windows.

## Building and Installation

Expand Down Expand Up @@ -170,7 +170,6 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.

For Windows versions below than `6.0` it is also necessary to use XP toolchain
in case of MSVC compiler (pass `-T v141_xp` to CMake command line).
Also, you are not able to use Crashpad with XP toolchains, no crashes will be handled at all.

- `SENTRY_TRANSPORT` (Default: depending on platform):
Sentry can use different http libraries to send reports to the server.
Expand All @@ -185,7 +184,7 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
- **crashpad**: This uses the out-of-process crashpad handler. It is currently
only supported on Windows and macOS, and used as the default there.
- **breakpad**: This uses the in-process breakpad handler. It is currently
only supported on Linux, and used as the default there.
only supported on Linux and Windows, and used as the default on Linux.
- **inproc**: A small in-process handler which is supported on all platforms
except Windows, and is used as default on Linux and Android.
- **none**: This builds `sentry-native` without a backend, so it does not handle
Expand All @@ -201,7 +200,7 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
| Backends | | | | |
| - inproc | | ✓ | ✓ | ☑ |
| - crashpad | ☑ | ☑ | | |
| - breakpad | | | ☑ | |
| - breakpad | | | ☑ | |
| - none | ✓ | ✓ | ✓ | ✓ |

Legend:
Expand Down
132 changes: 87 additions & 45 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,93 @@
if (LINUX OR ANDROID)
# The list is copied from: https://github.com/google/breakpad/blob/c7522272ffafa9b162f135aaee5d02a8895fcb0b/Makefile.am#L153-L188
list(APPEND BREAKPAD_SOURCES
breakpad/src/client/linux/crash_generation/crash_generation_client.cc
breakpad/src/client/linux/crash_generation/crash_generation_server.cc
breakpad/src/client/linux/dump_writer_common/thread_info.cc
breakpad/src/client/linux/dump_writer_common/ucontext_reader.cc
breakpad/src/client/linux/handler/exception_handler.cc
breakpad/src/client/linux/handler/exception_handler.h
breakpad/src/client/linux/handler/minidump_descriptor.cc
breakpad/src/client/linux/handler/minidump_descriptor.h
breakpad/src/client/linux/log/log.cc
breakpad/src/client/linux/log/log.h
breakpad/src/client/linux/microdump_writer/microdump_writer.cc
breakpad/src/client/linux/microdump_writer/microdump_writer.h
breakpad/src/client/linux/minidump_writer/linux_core_dumper.cc
breakpad/src/client/linux/minidump_writer/linux_dumper.cc
breakpad/src/client/linux/minidump_writer/linux_ptrace_dumper.cc
breakpad/src/client/linux/minidump_writer/minidump_writer.cc
breakpad/src/client/minidump_file_writer-inl.h
breakpad/src/client/minidump_file_writer.cc
breakpad/src/client/minidump_file_writer.h
breakpad/src/common/convert_UTF.cc
breakpad/src/common/convert_UTF.h
breakpad/src/common/md5.cc
breakpad/src/common/md5.h
breakpad/src/common/string_conversion.cc
breakpad/src/common/string_conversion.h
breakpad/src/common/linux/elf_core_dump.cc
breakpad/src/common/linux/elfutils.cc
breakpad/src/common/linux/elfutils.h
breakpad/src/common/linux/file_id.cc
breakpad/src/common/linux/file_id.h
breakpad/src/common/linux/guid_creator.cc
breakpad/src/common/linux/guid_creator.h
breakpad/src/common/linux/linux_libc_support.cc
breakpad/src/common/linux/memory_mapped_file.cc
breakpad/src/common/linux/safe_readlink.cc
)
# The list of files is drived from: breakpad/Makefile.am

set(BREAKPAD_SOURCES_COMMON
breakpad/src/common/convert_UTF.cc
breakpad/src/common/convert_UTF.h
breakpad/src/common/md5.cc
breakpad/src/common/md5.h
breakpad/src/common/string_conversion.cc
breakpad/src/common/string_conversion.h
)

set(BREAKPAD_SOURCES_COMMON_LINUX
breakpad/src/common/linux/elf_core_dump.cc
breakpad/src/common/linux/elfutils.cc
breakpad/src/common/linux/elfutils.h
breakpad/src/common/linux/file_id.cc
breakpad/src/common/linux/file_id.h
breakpad/src/common/linux/guid_creator.cc
breakpad/src/common/linux/guid_creator.h
breakpad/src/common/linux/linux_libc_support.cc
breakpad/src/common/linux/memory_mapped_file.cc
breakpad/src/common/linux/safe_readlink.cc
)

set(BREAKPAD_SOURCES_COMMON_LINUX_GETCONTEXT
breakpad/src/common/linux/breakpad_getcontext.S
)

set(BREAKPAD_SOURCES_COMMON_WINDOWS
breakpad/src/common/windows/guid_string.cc
breakpad/src/common/windows/guid_string.h
)

set(BREAKPAD_SOURCES_CLIENT_LINUX
breakpad/src/client/minidump_file_writer-inl.h
breakpad/src/client/minidump_file_writer.cc
breakpad/src/client/minidump_file_writer.h
breakpad/src/client/linux/crash_generation/crash_generation_client.cc
breakpad/src/client/linux/crash_generation/crash_generation_server.cc
breakpad/src/client/linux/dump_writer_common/thread_info.cc
breakpad/src/client/linux/dump_writer_common/ucontext_reader.cc
breakpad/src/client/linux/handler/exception_handler.cc
breakpad/src/client/linux/handler/exception_handler.h
breakpad/src/client/linux/handler/minidump_descriptor.cc
breakpad/src/client/linux/handler/minidump_descriptor.h
breakpad/src/client/linux/log/log.cc
breakpad/src/client/linux/log/log.h
breakpad/src/client/linux/microdump_writer/microdump_writer.cc
breakpad/src/client/linux/microdump_writer/microdump_writer.h
breakpad/src/client/linux/minidump_writer/linux_core_dumper.cc
breakpad/src/client/linux/minidump_writer/linux_dumper.cc
breakpad/src/client/linux/minidump_writer/linux_ptrace_dumper.cc
breakpad/src/client/linux/minidump_writer/minidump_writer.cc
)

set(BREAKPAD_SOURCES_CLIENT_WINDOWS
breakpad/src/client/windows/crash_generation/crash_generation_client.cc
breakpad/src/client/windows/crash_generation/crash_generation_client.h
breakpad/src/client/windows/handler/exception_handler.cc
breakpad/src/client/windows/handler/exception_handler.h
)


add_library(breakpad_client STATIC)
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON})

if(LINUX OR ANDROID)
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON_LINUX} ${BREAKPAD_SOURCES_CLIENT_LINUX})

include(CheckFunctionExists)
check_function_exists(getcontext HAVE_GETCONTEXT)
if(HAVE_GETCONTEXT)
target_compile_definitions(breakpad_client PRIVATE HAVE_GETCONTEXT)
else()
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON_LINUX_GETCONTEXT})
endif()

set_property(TARGET breakpad_client PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
if (ANDROID)
list(APPEND BREAKPAD_SOURCES
breakpad/src/common/android/breakpad_getcontext.S
)

if(WIN32)
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON_WINDOWS} ${BREAKPAD_SOURCES_CLIENT_WINDOWS})
target_compile_definitions(breakpad_client PRIVATE _UNICODE)

# set static runtime if enabled
if(SENTRY_BUILD_RUNTIMESTATIC AND MSVC)
set_property(TARGET breakpad_client PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()

add_library(breakpad_client STATIC ${BREAKPAD_SOURCES})
set_property(TARGET breakpad_client PROPERTY POSITION_INDEPENDENT_CODE ON)
# breakpad has includes directly to `third_party/lss/...`,
# which are being resolved correctly when we add the current directory to
# the include directories. A giant hack, yes, but it works
Expand Down
2 changes: 1 addition & 1 deletion external/breakpad
Submodule breakpad updated from c75222 to 2757a2
Loading