From e0193a5501b7a9869a35305dc43ee9363e7a45e0 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Tue, 3 Apr 2018 10:12:46 -0700 Subject: [PATCH] =?UTF-8?q?Print=20backtrace=20for=20RAY=5FLOG(FATAL)=20an?= =?UTF-8?q?d=20also=20add=20file=20and=20line=20number=20=E2=80=A6=20(#180?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Print backtrace for RAY_LOG(FATAL) and also add file and line number in common case. * Fix linting. --- src/ray/util/logging.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ray/util/logging.h b/src/ray/util/logging.h index f63be72eb..d44f785d8 100644 --- a/src/ray/util/logging.h +++ b/src/ray/util/logging.h @@ -25,13 +25,15 @@ namespace ray { #define RAY_ERROR 2 #define RAY_FATAL 3 -#define RAY_LOG_INTERNAL(level) ::ray::internal::CerrLog(level) +#define RAY_LOG_INTERNAL(level) \ + ::ray::internal::CerrLog(level) << __FILE__ << ":" << __LINE__ << ": " + #define RAY_LOG(level) RAY_LOG_INTERNAL(RAY_##level) #define RAY_IGNORE_EXPR(expr) ((void) (expr)); #define RAY_CHECK(condition) \ (condition) ? 0 : ::ray::internal::FatalLog(RAY_FATAL) \ - << __FILE__ << __LINE__ \ + << __FILE__ << ":" << __LINE__ \ << " Check failed: " #condition " " #ifdef NDEBUG @@ -67,8 +69,14 @@ class CerrLog { if (has_logged_) { std::cerr << std::endl; } + // This code is duplicated in the FatalLog class. if (severity_ == RAY_FATAL) { - std::exit(1); +#if defined(_EXECINFO_H) || !defined(_WIN32) + void *buffer[255]; + const int calls = backtrace(buffer, sizeof(buffer) / sizeof(void *)); + backtrace_symbols_fd(buffer, calls, 1); +#endif + std::abort(); } }