Merge "Turn on crash reporter for debug standalone heapprofd."
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
index 7fc0cdd..15fa31b 100644
--- a/gn/BUILD.gn
+++ b/gn/BUILD.gn
@@ -81,6 +81,7 @@
"PERFETTO_ZLIB=$enable_perfetto_zlib",
"PERFETTO_TRACED_PERF=$enable_perfetto_traced_perf",
"PERFETTO_HEAPPROFD=$enable_perfetto_heapprofd",
+ "PERFETTO_STDERR_CRASH_DUMP=$enable_perfetto_stderr_crash_dump",
]
rel_out_path = rebase_path(gen_header_path, "$root_build_dir")
diff --git a/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h b/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h
index d68f557..649d9ed 100644
--- a/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h
+++ b/include/perfetto/base/build_configs/android_tree/perfetto_build_flags.h
@@ -40,6 +40,7 @@
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_ZLIB() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_TRACED_PERF() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_HEAPPROFD() (1)
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_STDERR_CRASH_DUMP() (0)
// clang-format on
#endif // GEN_BUILD_CONFIG_PERFETTO_BUILD_FLAGS_H_
diff --git a/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h b/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
index dad653c..393c2b2 100644
--- a/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
+++ b/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
@@ -40,6 +40,7 @@
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_ZLIB() (1)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_TRACED_PERF() (0)
#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_HEAPPROFD() (0)
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_STDERR_CRASH_DUMP() (0)
// clang-format on
#endif // GEN_BUILD_CONFIG_PERFETTO_BUILD_FLAGS_H_
diff --git a/src/base/debug_crash_stack_trace.cc b/src/base/debug_crash_stack_trace.cc
index 4da0fba..2a55d2b 100644
--- a/src/base/debug_crash_stack_trace.cc
+++ b/src/base/debug_crash_stack_trace.cc
@@ -107,6 +107,7 @@
}
void RestoreSignalHandlers() {
+ g_sighandler_registered = false;
for (size_t i = 0; i < sizeof(g_signals) / sizeof(g_signals[0]); i++)
sigaction(g_signals[i].sig_num, &g_signals[i].old_handler, nullptr);
}
@@ -233,9 +234,13 @@
}
}
+} // namespace
+
+namespace perfetto {
// __attribute__((constructor)) causes a static initializer that automagically
// early runs this function before the main().
-void __attribute__((constructor)) EnableStacktraceOnCrashForDebug();
+void PERFETTO_EXPORT __attribute__((constructor))
+EnableStacktraceOnCrashForDebug();
void EnableStacktraceOnCrashForDebug() {
if (g_sighandler_registered)
@@ -259,7 +264,6 @@
// (ii) the output of death test is not visible.
pthread_atfork(nullptr, nullptr, &RestoreSignalHandlers);
}
-
-} // namespace
+} // namespace perfetto
#pragma GCC diagnostic pop
diff --git a/src/profiling/memory/client_api_factory_standalone.cc b/src/profiling/memory/client_api_factory_standalone.cc
index b49da1f..da2a083 100644
--- a/src/profiling/memory/client_api_factory_standalone.cc
+++ b/src/profiling/memory/client_api_factory_standalone.cc
@@ -45,6 +45,8 @@
// service. This happens in CreateClient.
namespace perfetto {
+void EnableStacktraceOnCrashForDebug();
+
namespace profiling {
namespace {
@@ -107,6 +109,11 @@
daemon(/* nochdir= */ 0, /* noclose= */ 1);
+ // On debug builds, we want to turn on crash reporting for heapprofd.
+#if PERFETTO_BUILDFLAG(PERFETTO_STDERR_CRASH_DUMP)
+ EnableStacktraceOnCrashForDebug();
+#endif
+
cli_sock.ReleaseFd();
// Leave stderr open for logging.