Commit 4a3f102c authored by 's avatar

Introduce RecordCrashReason().


git-svn-id: https://google-glog.googlecode.com/svn/trunk@40 eb4d4688-79bd-11dd-afb4-1d65580434c0
parent f3653795
...@@ -840,6 +840,7 @@ namespace glog_internal_namespace_ { ...@@ -840,6 +840,7 @@ namespace glog_internal_namespace_ {
template <bool> template <bool>
struct CompileAssert { struct CompileAssert {
}; };
class CrashReason;
} // namespace glog_internal_namespace_ } // namespace glog_internal_namespace_
#define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \ #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
...@@ -1106,6 +1107,9 @@ private: ...@@ -1106,6 +1107,9 @@ private:
void Init(const char* file, int line, LogSeverity severity, void Init(const char* file, int line, LogSeverity severity,
void (LogMessage::*send_method)()); void (LogMessage::*send_method)());
// Used to fill in crash information during LOG(FATAL) failures.
void RecordCrashReason(glog_internal_namespace_::CrashReason* reason);
// Counts of messages sent at each priority: // Counts of messages sent at each priority:
static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex
......
...@@ -1182,17 +1182,9 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { ...@@ -1182,17 +1182,9 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) {
// someone else can use them (as long as they flush afterwards) // someone else can use them (as long as they flush afterwards)
if (data_->severity_ == FATAL && exit_on_dfatal) { if (data_->severity_ == FATAL && exit_on_dfatal) {
if (data_->first_fatal_) { if (data_->first_fatal_) {
crash_reason.filename = fatal_msg_data_exclusive_.fullname_; // Store crash information so that it is accessible from within signal
crash_reason.line_number = fatal_msg_data_exclusive_.line_; // handlers that may be invoked later.
crash_reason.message = fatal_msg_buf_exclusive + RecordCrashReason(&crash_reason);
fatal_msg_data_exclusive_.num_prefix_chars_;
#ifdef HAVE_STACKTRACE
crash_reason.depth = GetStackTrace(crash_reason.stack,
ARRAYSIZE(crash_reason.stack),
3);
#else
crash_reason.depth = 0;
#endif
SetCrashReason(&crash_reason); SetCrashReason(&crash_reason);
// Store shortened fatal message for other logs and GWQ status // Store shortened fatal message for other logs and GWQ status
...@@ -1224,6 +1216,20 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { ...@@ -1224,6 +1216,20 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) {
} }
} }
void LogMessage::RecordCrashReason(
glog_internal_namespace_::CrashReason* reason) {
reason->filename = fatal_msg_data_exclusive_.fullname_;
reason->line_number = fatal_msg_data_exclusive_.line_;
reason->message = fatal_msg_buf_exclusive +
fatal_msg_data_exclusive_.num_prefix_chars_;
#ifdef HAVE_STACKTRACE
// Retrieve the stack trace, omitting the logging frames that got us here.
reason->depth = GetStackTrace(reason->stack, ARRAYSIZE(reason->stack), 4);
#else
reason->depth = 0;
#endif
}
static void logging_fail() { static void logging_fail() {
#if defined(_DEBUG) && defined(_MSC_VER) #if defined(_DEBUG) && defined(_MSC_VER)
// When debugging on windows, avoid the obnoxious dialog and make // When debugging on windows, avoid the obnoxious dialog and make
......
...@@ -201,8 +201,8 @@ struct CrashReason { ...@@ -201,8 +201,8 @@ struct CrashReason {
int line_number; int line_number;
const char* message; const char* message;
// We'll also store a bit of context at the time of crash as it may not be // We'll also store a bit of stack trace context at the time of crash as
// available later on. // it may not be available later on.
void* stack[32]; void* stack[32];
int depth; int depth;
}; };
......
...@@ -844,6 +844,7 @@ namespace glog_internal_namespace_ { ...@@ -844,6 +844,7 @@ namespace glog_internal_namespace_ {
template <bool> template <bool>
struct CompileAssert { struct CompileAssert {
}; };
class CrashReason;
} // namespace glog_internal_namespace_ } // namespace glog_internal_namespace_
#define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \ #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
...@@ -1110,6 +1111,9 @@ private: ...@@ -1110,6 +1111,9 @@ private:
void Init(const char* file, int line, LogSeverity severity, void Init(const char* file, int line, LogSeverity severity,
void (LogMessage::*send_method)()); void (LogMessage::*send_method)());
// Used to fill in crash information during LOG(FATAL) failures.
void RecordCrashReason(glog_internal_namespace_::CrashReason* reason);
// Counts of messages sent at each priority: // Counts of messages sent at each priority:
static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment