Print backtrace for RAY_LOG(FATAL) and also add file and line number … (#1805)

* Print backtrace for RAY_LOG(FATAL) and also add file and line number in common case.

* Fix linting.
This commit is contained in:
Robert Nishihara
2018-04-03 10:12:46 -07:00
committed by Philipp Moritz
parent fbfbb1c079
commit e0193a5501
+11 -3
View File
@@ -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();
}
}