66#include " ddprof.hpp"
77
88#include " cap_display.hpp"
9+ #include " crash_tracker.hpp"
910#include " ddprof_cmdline.hpp"
1011#include " ddprof_context.hpp"
1112#include " ddprof_context_lib.hpp"
3334
3435namespace ddprof {
3536namespace {
36- /* **************************** SIGSEGV Handler *******************************/
37- void sigsegv_handler (int sig, siginfo_t *si, void *uc) {
38- // TODO this really shouldn't call printf-family functions...
39- (void )uc;
40- #ifdef __GLIBC__
41- constexpr size_t k_stacktrace_buffer_size = 4096 ;
42- static void *buf[k_stacktrace_buffer_size] = {};
43- size_t const sz = backtrace (buf, std::size (buf));
44- #endif
45- (void )fprintf (
46- stderr, " ddprof[%d]: <%.*s> has encountered an error and will exit\n " ,
47- getpid (), static_cast <int >(str_version ().size ()), str_version ().data ());
48- if (sig == SIGSEGV) {
49- printf (" [DDPROF] Fault address: %p\n " , si->si_addr );
50- }
51- #ifdef __GLIBC__
52- backtrace_symbols_fd (buf, sz, STDERR_FILENO);
53- #endif
54- exit (-1 );
55- }
5637
5738void display_system_info () {
5839
@@ -92,6 +73,25 @@ DDRes get_process_threads(pid_t pid, std::vector<pid_t> &threads) {
9273 return {};
9374}
9475
76+ void configure_crash_tracker (const DDProfContext &ctx) {
77+ std::vector<std::string> args = {" --service" , ctx.exp_input .service };
78+ if (!ctx.exp_input .url .empty ()) {
79+ args.push_back (" --url" );
80+ args.push_back (ctx.exp_input .url );
81+ }
82+ if (!ctx.exp_input .host .empty ()) {
83+ args.push_back (" --host" );
84+ args.push_back (ctx.exp_input .host );
85+ }
86+ if (!ctx.exp_input .port .empty ()) {
87+ args.push_back (" --port" );
88+ args.push_back (ctx.exp_input .port );
89+ }
90+
91+ args.push_back (" --report-crash" );
92+ install_crash_tracker (" /proc/self/exe" , args);
93+ }
94+
9595} // namespace
9696
9797DDRes ddprof_setup (DDProfContext &ctx) {
@@ -115,10 +115,7 @@ DDRes ddprof_setup(DDProfContext &ctx) {
115115
116116 // Setup signal handler if defined
117117 if (ctx.params .fault_info ) {
118- struct sigaction sigaction_handlers = {};
119- sigaction_handlers.sa_sigaction = sigsegv_handler;
120- sigaction_handlers.sa_flags = SA_SIGINFO;
121- sigaction (SIGSEGV, &(sigaction_handlers), nullptr );
118+ configure_crash_tracker (ctx);
122119 }
123120
124121 // Set the nice level, but only if it was overridden because 0 is valid
0 commit comments