]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common/fatal_signal: rework print_backtrace
authorMatan Breizman <mbreizma@redhat.com>
Wed, 4 Jun 2025 10:56:37 +0000 (10:56 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Sun, 22 Jun 2025 09:08:33 +0000 (09:08 +0000)
* Move to GENERIC_LOG
* Print backtrace in log and in std out
* Switch to fmt::format

Signed-off-by: Matan Breizman <mbreizma@redhat.com>
src/crimson/common/fatal_signal.cc

index f2983769de42d21d60071801a2f7b715008bcf4c..cab96c13891c95a6fa8c4719cc0ca26407437d1a 100644 (file)
@@ -7,13 +7,23 @@
 #include <iostream>
 #include <string_view>
 
+// boost is able to translate addresses
+// to lines with the following definition.
+// Similar to Seastar's seastar-addr2line
 #define BOOST_STACKTRACE_USE_ADDR2LINE
+
+// Consider std once C++23 is available
 #include <boost/stacktrace.hpp>
+
 #include <seastar/core/reactor.hh>
 
+#include "crimson/common/log.h"
+
 #include "common/safe_io.h"
 #include "include/scope_guard.h"
 
+SET_SUBSYS(osd);
+
 FatalSignal::FatalSignal()
 {
   install_oneshot_signals_handler<SIGSEGV,
@@ -78,22 +88,24 @@ void FatalSignal::install_oneshot_signal_handler()
   assert(r == 0);
 }
 
-
 [[gnu::noinline]] static void print_backtrace(std::string_view cause) {
-  std::cerr << cause;
-  if (seastar::engine_is_ready()) {
-    std::cerr << " on shard " << seastar::this_shard_id();
-  }
   // nobody wants to see things like `FatalSignal::signaled()` or
   // `print_backtrace()` in our backtraces. `+ 1` is for the extra
   // frame created by kernel (signal trampoline, it will take care
   // about e.g. sigreturn(2) calling; see the man page).
-  constexpr std::size_t FRAMES_TO_SKIP = 3 + 1;
-  std::cerr << ".\nBacktrace:\n";
-  std::cerr << boost::stacktrace::stacktrace(
+  constexpr std::size_t FRAMES_TO_SKIP = 2 + 1;
+
+  std::string backtrace = fmt::format("{} on shard {}  \nBacktrace:\n {}",
+    cause,
+    seastar::engine_is_ready() ? std::to_string(seastar::this_shard_id()) : "no shard",
+    boost::stacktrace::to_string(boost::stacktrace::stacktrace(
     FRAMES_TO_SKIP,
-    static_cast<std::size_t>(-1)/* max depth same as the default one */);
-  std::cerr << std::flush;
+    static_cast<std::size_t>(-1)/* max depth same as the default one */)));
+
+  // Print backtrace in log and in std out
+  GENERIC_ERROR("{}", backtrace);
+  std::cerr << backtrace << std::flush;
+
   // TODO: dump crash related meta data to $crash_dir
   //       see handle_fatal_signal()
 }