Skip to content

Commit 5611721

Browse files
authored
Merge pull request ceph#61264 from irq0/wip/breakpad
Breakpad Crash Handler
2 parents 24bc646 + d2467ba commit 5611721

File tree

13 files changed

+257
-0
lines changed

13 files changed

+257
-0
lines changed

.gitmodules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@
7979
path = src/nvmeof/gateway
8080
url = https://github.com/ceph/ceph-nvmeof.git
8181
fetchRecurseSubmodules = false
82+
shallow = true
83+
[submodule "src/breakpad"]
84+
path = src/breakpad
85+
url = https://chromium.googlesource.com/breakpad/breakpad
86+
[submodule "src/lss"]
87+
path = src/lss
88+
url = https://chromium.googlesource.com/linux-syscall-support

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,18 @@ if(WITH_CATCH2)
542542
message("-- Enabled Catch2 support")
543543
endif()
544544

545+
if(WIN32)
546+
set(WITH_BREAKPAD_DEFAULT OFF)
547+
else()
548+
set(WITH_BREAKPAD_DEFAULT ON)
549+
endif()
550+
551+
option(WITH_BREAKPAD "Build with Google Breakpad crash reporter" ${WITH_BREAKPAD_DEFAULT})
552+
if(WITH_BREAKPAD)
553+
set(HAVE_BREAKPAD ON)
554+
message("-- Enabled Google Breakpad crash reporter")
555+
endif()
556+
545557
#option for RGW
546558
option(WITH_RADOSGW "RADOS Gateway is enabled" ON)
547559
option(WITH_RADOSGW_BEAST_OPENSSL "RADOS Gateway's Beast frontend uses OpenSSL" ON)

src/CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,47 @@ if (WITH_BLKIN)
325325
add_subdirectory(blkin/blkin-lib)
326326
endif(WITH_BLKIN)
327327

328+
## breakpad
329+
if(WITH_BREAKPAD)
330+
set(breakpad_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/breakpad)
331+
set(lss_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/lss)
332+
333+
add_custom_target(breakpad_lss_symlink)
334+
add_custom_command(
335+
TARGET breakpad_lss_symlink
336+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${lss_SOURCE_DIR} ${breakpad_SOURCE_DIR}/src/third_party/lss
337+
COMMENT "Creating symbolic link lss -> breakpad third party"
338+
)
339+
ExternalProject_Add(
340+
breakpad_project
341+
SOURCE_DIR "${breakpad_SOURCE_DIR}"
342+
CONFIGURE_COMMAND cd "${breakpad_SOURCE_DIR}"
343+
COMMAND "${breakpad_SOURCE_DIR}/configure"
344+
"CFLAGS=${CMAKE_C_FLAGS} -Wno-array-bounds -Wno-maybe-uninitialized"
345+
"CXXFLAGS=${CMAKE_CXX_FLAGS} -Wno-array-bounds -Wno-maybe-uninitialized"
346+
"LDFLAGS=${CMAKE_EXE_LINKER_FLAGS} -Wno-array-bounds -Wno-maybe-uninitialized"
347+
BUILD_COMMAND
348+
/bin/sh -cx "cd ${breakpad_SOURCE_DIR} && make"
349+
INSTALL_COMMAND ""
350+
UPDATE_DISCONNECTED ON
351+
BUILD_IN_SOURCE ON
352+
DEPENDS breakpad_lss_symlink
353+
BUILD_BYPRODUCTS "${breakpad_SOURCE_DIR}/src/libbreakpad.a;${breakpad_SOURCE_DIR}/src/client/linux/libbreakpad_client.a"
354+
)
355+
356+
add_library(libbreakpad STATIC IMPORTED GLOBAL)
357+
set_property(TARGET libbreakpad PROPERTY IMPORTED_LOCATION ${breakpad_SOURCE_DIR}/src/libbreakpad.a)
358+
add_library(libbreakpad_client STATIC IMPORTED GLOBAL)
359+
set_property(TARGET libbreakpad_client PROPERTY IMPORTED_LOCATION ${breakpad_SOURCE_DIR}/src/client/linux/libbreakpad_client.a)
360+
361+
include_directories(SYSTEM "${breakpad_SOURCE_DIR}/src")
362+
add_dependencies(libbreakpad breakpad_project)
363+
add_dependencies(libbreakpad_client breakpad_project)
364+
365+
add_library(breakpad INTERFACE)
366+
target_link_libraries(breakpad INTERFACE libbreakpad libbreakpad_client)
367+
endif(WITH_BREAKPAD)
368+
328369
if(WITH_JAEGER)
329370
find_package(thrift 0.13.0 REQUIRED)
330371
include(BuildOpentelemetry)
@@ -481,6 +522,11 @@ if(WITH_JAEGER)
481522
target_link_libraries(common-objs jaeger_base)
482523
endif()
483524

525+
if(WITH_BREAKPAD)
526+
add_dependencies(common-objs breakpad_project)
527+
target_link_libraries(common-objs breakpad)
528+
endif()
529+
484530
CHECK_C_COMPILER_FLAG("-fvar-tracking-assignments" HAS_VTA)
485531
add_subdirectory(auth)
486532
add_subdirectory(common)
@@ -542,6 +588,10 @@ if(WITH_JAEGER)
542588
list(APPEND ceph_common_deps jaeger_base)
543589
endif()
544590

591+
if(WITH_BREAKPAD)
592+
list(APPEND ceph_common_deps breakpad)
593+
endif()
594+
545595
if(WIN32)
546596
list(APPEND ceph_common_deps ws2_32 mswsock iphlpapi bcrypt)
547597
list(APPEND ceph_common_deps dlfcn_win32)
@@ -578,6 +628,10 @@ if(WITH_JAEGER)
578628
add_dependencies(common jaeger_base)
579629
endif()
580630

631+
if(WITH_BREAKPAD)
632+
add_dependencies(common breakpad_project)
633+
endif()
634+
581635
if (WIN32)
582636
# Statically building ceph-common on Windows fails. We're temporarily
583637
# reverting this: 22fefb2338cfc4fcb03ece3cbf77aa964a7f17f2
@@ -597,6 +651,10 @@ if(WITH_JAEGER)
597651
add_dependencies(ceph-common jaeger_base)
598652
endif()
599653

654+
if(WITH_BREAKPAD)
655+
add_dependencies(ceph-common breakpad_project)
656+
endif()
657+
600658
# appease dpkg-shlibdeps
601659
set_target_properties(ceph-common PROPERTIES
602660
SOVERSION 2

src/breakpad

Submodule breakpad added at 41b6533

src/common/ceph_context.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#include "common/cmdparse.h"
3535
#include "common/code_environment.h"
3636
#include "msg/msg_types.h"
37+
#ifdef HAVE_BREAKPAD
38+
#include "breakpad/src/client/linux/handler/exception_handler.h"
39+
#endif
3740
#ifdef WITH_CRIMSON
3841
#include "crimson/common/config_proxy.h"
3942
#include "crimson/common/perf_counters_collection.h"
@@ -143,6 +146,9 @@ class CephContext {
143146

144147
ConfigProxy _conf;
145148
ceph::logging::Log *_log;
149+
#ifdef HAVE_BREAKPAD
150+
std::unique_ptr<google_breakpad::ExceptionHandler> _ex_handler;
151+
#endif
146152

147153
/* init ceph::crypto */
148154
void init_crypto();

src/common/options/global.yaml.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,14 @@ options:
433433
flags:
434434
- startup
435435
with_legacy: true
436+
- name: breakpad
437+
type: bool
438+
level: advanced
439+
desc: setup breakpad crash handler
440+
default: false
441+
flags:
442+
- startup
443+
with_legacy: true
436444
- name: crash_dir
437445
type: str
438446
level: advanced

src/crimson/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ if(WITH_JAEGER)
137137
list(APPEND crimson_common_public_deps jaeger_base)
138138
endif()
139139

140+
if(WITH_BREAKPAD)
141+
list(APPEND crimson_common_public_deps breakpad)
142+
endif()
143+
140144
if(NOT WITH_SYSTEM_BOOST)
141145
list(APPEND crimson_common_deps ${ZLIB_LIBRARIES})
142146
endif()

src/global/global_init.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "extblkdev/ExtBlkDevPlugin.h"
2727
#include "global/global_context.h"
2828
#include "global/global_init.h"
29+
#ifdef HAVE_BREAKPAD
30+
#include <client/linux/handler/minidump_descriptor.h>
31+
#include <google_breakpad/common/minidump_format.h>
32+
#endif
2933
#include "global/pidfile.h"
3034
#include "global/signal_handler.h"
3135
#include "include/compat.h"
@@ -178,6 +182,17 @@ void global_pre_init(
178182
g_conf().complain_about_parse_error(g_ceph_context);
179183
}
180184

185+
#ifdef HAVE_BREAKPAD
186+
static bool dumpCallback(
187+
const google_breakpad::MinidumpDescriptor& descriptor, void* context,
188+
bool succeeded) {
189+
char buf[1024];
190+
snprintf(buf, sizeof(buf), "minidump created in path %s", descriptor.path());
191+
dout_emergency(buf);
192+
return succeeded;
193+
}
194+
#endif
195+
181196
boost::intrusive_ptr<CephContext>
182197
global_init(const std::map<std::string,std::string> *defaults,
183198
std::vector < const char* >& args,
@@ -215,6 +230,20 @@ global_init(const std::map<std::string,std::string> *defaults,
215230
if (g_conf()->fatal_signal_handlers) {
216231
install_standard_sighandlers();
217232
}
233+
234+
#ifdef HAVE_BREAKPAD
235+
if (g_conf()->breakpad) {
236+
google_breakpad::MinidumpDescriptor descriptor(g_conf()->crash_dir);
237+
g_ceph_context->_ex_handler.reset(
238+
new google_breakpad::ExceptionHandler(descriptor, nullptr, dumpCallback, nullptr, true, -1));
239+
}
240+
#else
241+
if (g_conf()->breakpad) {
242+
cerr << "breakpad crash reporting requested, but disabled at build time"
243+
<< std::endl;
244+
}
245+
#endif
246+
218247
ceph::register_assert_context(g_ceph_context);
219248

220249
if (g_conf()->log_flush_on_exit)

src/include/config-h.in.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,7 @@
405405
/* libexec directory path */
406406
#cmakedefine CMAKE_INSTALL_LIBEXECDIR "@CMAKE_INSTALL_LIBEXECDIR@"
407407

408+
/* Define if breakpad is available */
409+
#cmakedefine HAVE_BREAKPAD
410+
408411
#endif /* CONFIG_H */

src/lss

Submodule lss added at ed31caa

0 commit comments

Comments
 (0)