Skip to content

Commit feee796

Browse files
authored
feat: Add Breakpad support for Windows (#278)
1 parent fb33dff commit feee796

File tree

10 files changed

+181
-78
lines changed

10 files changed

+181
-78
lines changed

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ endif()
9191
option(SENTRY_ENABLE_INSTALL "Enable sentry installation" "${SENTRY_MAIN_PROJECT}")
9292

9393
if(MSVC AND CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
94-
message(WARNING "Crashpad is not supported for MSVC with XP toolset. Default backend was switched to 'none'")
95-
set(SENTRY_DEFAULT_BACKEND "none")
94+
message(WARNING "Crashpad is not supported for MSVC with XP toolset. Default backend was switched to 'breakpad'")
95+
set(SENTRY_DEFAULT_BACKEND "breakpad")
9696
elseif(APPLE OR WIN32)
9797
set(SENTRY_DEFAULT_BACKEND "crashpad")
9898
elseif(LINUX)
@@ -119,8 +119,8 @@ endif()
119119
if(SENTRY_BACKEND_CRASHPAD AND NOT (APPLE OR WIN32))
120120
message(FATAL_ERROR "The Crashpad backend is currently only supported on macOS and Windows")
121121
endif()
122-
if(SENTRY_BACKEND_BREAKPAD AND NOT LINUX)
123-
message(FATAL_ERROR "The Breakpad backend is currently only supported on Linux")
122+
if(SENTRY_BACKEND_BREAKPAD AND NOT (LINUX OR WIN32))
123+
message(FATAL_ERROR "The Breakpad backend is currently only supported on Linux and Windows")
124124
endif()
125125
if(SENTRY_BACKEND_INPROC AND WIN32)
126126
message(FATAL_ERROR "The in-process backend is not supported on Windows")
@@ -196,6 +196,10 @@ add_subdirectory(src)
196196

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

199+
# check size type
200+
include(CheckTypeSize)
201+
check_type_size("long" CMAKE_SIZEOF_LONG)
202+
199203
# https://gitlab.kitware.com/cmake/cmake/issues/18393
200204
if(BUILD_SHARED_LIBS)
201205
if(APPLE)
@@ -211,6 +215,7 @@ if(BUILD_SHARED_LIBS)
211215
else()
212216
target_compile_definitions(sentry PUBLIC SENTRY_BUILD_STATIC)
213217
endif()
218+
target_compile_definitions(sentry PRIVATE SIZEOF_LONG=${CMAKE_SIZEOF_LONG})
214219

215220
if(SENTRY_TRANSPORT_CURL)
216221
find_package(CURL REQUIRED)
@@ -278,7 +283,10 @@ endif()
278283

279284
#respect CMAKE_SYSTEM_VERSION
280285
if(WIN32)
281-
if(${CMAKE_SYSTEM_VERSION} MATCHES "^10")
286+
if(MSVC AND CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
287+
#force WINNT to 5.1 for Windows XP toolchain
288+
target_compile_definitions(sentry PRIVATE "_WIN32_WINNT=0x0501")
289+
elseif(${CMAKE_SYSTEM_VERSION} MATCHES "^10")
282290
target_compile_definitions(sentry PRIVATE "_WIN32_WINNT=0x0A00")
283291
elseif(${CMAKE_SYSTEM_VERSION} MATCHES "^6.3")
284292
target_compile_definitions(sentry PRIVATE "_WIN32_WINNT=0x0603")

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ format: setup-venv
7777

7878
style: setup-venv
7979
@.venv/bin/python ./scripts/check-clang-format.py -r examples include src tests/unit
80-
@.venv/bin/black --check tests
80+
@.venv/bin/black --diff --check tests
8181
.PHONY: style

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The SDK supports different features on the target platform:
7171
have the `curl` library available. On other platforms, library users need to
7272
implement their own transport, based on the `function transport` API.
7373
- **Crashpad Backend** is currently only supported on Windows and macOS.
74-
- **Breakpad Backend** is currently only supported on Linux.
74+
- **Breakpad Backend** is currently only supported on Linux and Windows.
7575

7676
## Building and Installation
7777

@@ -173,7 +173,6 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
173173

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

178177
- `SENTRY_TRANSPORT` (Default: depending on platform):
179178
Sentry can use different http libraries to send reports to the server.
@@ -190,7 +189,7 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
190189
- **crashpad**: This uses the out-of-process crashpad handler. It is currently
191190
only supported on Windows and macOS, and used as the default there.
192191
- **breakpad**: This uses the in-process breakpad handler. It is currently
193-
only supported on Linux, and used as the default there.
192+
only supported on Linux and Windows, and used as the default on Linux.
194193
- **inproc**: A small in-process handler which is supported on all platforms
195194
except Windows, and is used as default on Linux and Android.
196195
- **none**: This builds `sentry-native` without a backend, so it does not handle
@@ -206,7 +205,7 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
206205
| Backends | | | | |
207206
| - inproc | ||||
208207
| - crashpad ||| | |
209-
| - breakpad | | || |
208+
| - breakpad | | || |
210209
| - none |||||
211210

212211
Legend:

external/CMakeLists.txt

Lines changed: 87 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,93 @@
1-
if (LINUX OR ANDROID)
2-
# The list is copied from: https://github.com/google/breakpad/blob/c7522272ffafa9b162f135aaee5d02a8895fcb0b/Makefile.am#L153-L188
3-
list(APPEND BREAKPAD_SOURCES
4-
breakpad/src/client/linux/crash_generation/crash_generation_client.cc
5-
breakpad/src/client/linux/crash_generation/crash_generation_server.cc
6-
breakpad/src/client/linux/dump_writer_common/thread_info.cc
7-
breakpad/src/client/linux/dump_writer_common/ucontext_reader.cc
8-
breakpad/src/client/linux/handler/exception_handler.cc
9-
breakpad/src/client/linux/handler/exception_handler.h
10-
breakpad/src/client/linux/handler/minidump_descriptor.cc
11-
breakpad/src/client/linux/handler/minidump_descriptor.h
12-
breakpad/src/client/linux/log/log.cc
13-
breakpad/src/client/linux/log/log.h
14-
breakpad/src/client/linux/microdump_writer/microdump_writer.cc
15-
breakpad/src/client/linux/microdump_writer/microdump_writer.h
16-
breakpad/src/client/linux/minidump_writer/linux_core_dumper.cc
17-
breakpad/src/client/linux/minidump_writer/linux_dumper.cc
18-
breakpad/src/client/linux/minidump_writer/linux_ptrace_dumper.cc
19-
breakpad/src/client/linux/minidump_writer/minidump_writer.cc
20-
breakpad/src/client/minidump_file_writer-inl.h
21-
breakpad/src/client/minidump_file_writer.cc
22-
breakpad/src/client/minidump_file_writer.h
23-
breakpad/src/common/convert_UTF.cc
24-
breakpad/src/common/convert_UTF.h
25-
breakpad/src/common/md5.cc
26-
breakpad/src/common/md5.h
27-
breakpad/src/common/string_conversion.cc
28-
breakpad/src/common/string_conversion.h
29-
breakpad/src/common/linux/elf_core_dump.cc
30-
breakpad/src/common/linux/elfutils.cc
31-
breakpad/src/common/linux/elfutils.h
32-
breakpad/src/common/linux/file_id.cc
33-
breakpad/src/common/linux/file_id.h
34-
breakpad/src/common/linux/guid_creator.cc
35-
breakpad/src/common/linux/guid_creator.h
36-
breakpad/src/common/linux/linux_libc_support.cc
37-
breakpad/src/common/linux/memory_mapped_file.cc
38-
breakpad/src/common/linux/safe_readlink.cc
39-
)
1+
# The list of files is drived from: breakpad/Makefile.am
2+
3+
set(BREAKPAD_SOURCES_COMMON
4+
breakpad/src/common/convert_UTF.cc
5+
breakpad/src/common/convert_UTF.h
6+
breakpad/src/common/md5.cc
7+
breakpad/src/common/md5.h
8+
breakpad/src/common/string_conversion.cc
9+
breakpad/src/common/string_conversion.h
10+
)
11+
12+
set(BREAKPAD_SOURCES_COMMON_LINUX
13+
breakpad/src/common/linux/elf_core_dump.cc
14+
breakpad/src/common/linux/elfutils.cc
15+
breakpad/src/common/linux/elfutils.h
16+
breakpad/src/common/linux/file_id.cc
17+
breakpad/src/common/linux/file_id.h
18+
breakpad/src/common/linux/guid_creator.cc
19+
breakpad/src/common/linux/guid_creator.h
20+
breakpad/src/common/linux/linux_libc_support.cc
21+
breakpad/src/common/linux/memory_mapped_file.cc
22+
breakpad/src/common/linux/safe_readlink.cc
23+
)
24+
25+
set(BREAKPAD_SOURCES_COMMON_LINUX_GETCONTEXT
26+
breakpad/src/common/linux/breakpad_getcontext.S
27+
)
28+
29+
set(BREAKPAD_SOURCES_COMMON_WINDOWS
30+
breakpad/src/common/windows/guid_string.cc
31+
breakpad/src/common/windows/guid_string.h
32+
)
33+
34+
set(BREAKPAD_SOURCES_CLIENT_LINUX
35+
breakpad/src/client/minidump_file_writer-inl.h
36+
breakpad/src/client/minidump_file_writer.cc
37+
breakpad/src/client/minidump_file_writer.h
38+
breakpad/src/client/linux/crash_generation/crash_generation_client.cc
39+
breakpad/src/client/linux/crash_generation/crash_generation_server.cc
40+
breakpad/src/client/linux/dump_writer_common/thread_info.cc
41+
breakpad/src/client/linux/dump_writer_common/ucontext_reader.cc
42+
breakpad/src/client/linux/handler/exception_handler.cc
43+
breakpad/src/client/linux/handler/exception_handler.h
44+
breakpad/src/client/linux/handler/minidump_descriptor.cc
45+
breakpad/src/client/linux/handler/minidump_descriptor.h
46+
breakpad/src/client/linux/log/log.cc
47+
breakpad/src/client/linux/log/log.h
48+
breakpad/src/client/linux/microdump_writer/microdump_writer.cc
49+
breakpad/src/client/linux/microdump_writer/microdump_writer.h
50+
breakpad/src/client/linux/minidump_writer/linux_core_dumper.cc
51+
breakpad/src/client/linux/minidump_writer/linux_dumper.cc
52+
breakpad/src/client/linux/minidump_writer/linux_ptrace_dumper.cc
53+
breakpad/src/client/linux/minidump_writer/minidump_writer.cc
54+
)
55+
56+
set(BREAKPAD_SOURCES_CLIENT_WINDOWS
57+
breakpad/src/client/windows/crash_generation/crash_generation_client.cc
58+
breakpad/src/client/windows/crash_generation/crash_generation_client.h
59+
breakpad/src/client/windows/handler/exception_handler.cc
60+
breakpad/src/client/windows/handler/exception_handler.h
61+
)
62+
63+
64+
add_library(breakpad_client STATIC)
65+
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON})
66+
67+
if(LINUX OR ANDROID)
68+
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON_LINUX} ${BREAKPAD_SOURCES_CLIENT_LINUX})
69+
70+
include(CheckFunctionExists)
71+
check_function_exists(getcontext HAVE_GETCONTEXT)
72+
if(HAVE_GETCONTEXT)
73+
target_compile_definitions(breakpad_client PRIVATE HAVE_GETCONTEXT)
74+
else()
75+
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON_LINUX_GETCONTEXT})
76+
endif()
77+
78+
set_property(TARGET breakpad_client PROPERTY POSITION_INDEPENDENT_CODE ON)
4079
endif()
41-
if (ANDROID)
42-
list(APPEND BREAKPAD_SOURCES
43-
breakpad/src/common/android/breakpad_getcontext.S
44-
)
80+
81+
if(WIN32)
82+
target_sources(breakpad_client PRIVATE ${BREAKPAD_SOURCES_COMMON_WINDOWS} ${BREAKPAD_SOURCES_CLIENT_WINDOWS})
83+
target_compile_definitions(breakpad_client PRIVATE _UNICODE)
84+
85+
# set static runtime if enabled
86+
if(SENTRY_BUILD_RUNTIMESTATIC AND MSVC)
87+
set_property(TARGET breakpad_client PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
88+
endif()
4589
endif()
4690

47-
add_library(breakpad_client STATIC ${BREAKPAD_SOURCES})
48-
set_property(TARGET breakpad_client PROPERTY POSITION_INDEPENDENT_CODE ON)
4991
# breakpad has includes directly to `third_party/lss/...`,
5092
# which are being resolved correctly when we add the current directory to
5193
# the include directories. A giant hack, yes, but it works

external/breakpad

Submodule breakpad updated from c752227 to 2757a2c

0 commit comments

Comments
 (0)