diff options
author | <shinichiro.hamaji@gmail.com> | 2009-03-04 10:16:33 +0000 |
---|---|---|
committer | <shinichiro.hamaji@gmail.com> | 2009-03-04 10:16:33 +0000 |
commit | 4a3f102ce054b8219f32befa9554bf49261f8701 (patch) | |
tree | 45fefa0f2f3d233781db1a5b7117602c7f1109ff /src | |
parent | f365379532ad3c0d86fa1b52434392df256166b4 (diff) | |
download | glog-4a3f102ce054b8219f32befa9554bf49261f8701.tar.gz glog-4a3f102ce054b8219f32befa9554bf49261f8701.tar.bz2 glog-4a3f102ce054b8219f32befa9554bf49261f8701.zip |
Introduce RecordCrashReason().
git-svn-id: https://google-glog.googlecode.com/svn/trunk@40 eb4d4688-79bd-11dd-afb4-1d65580434c0
Diffstat (limited to 'src')
-rw-r--r-- | src/glog/logging.h.in | 4 | ||||
-rw-r--r-- | src/logging.cc | 28 | ||||
-rw-r--r-- | src/utilities.h | 4 | ||||
-rwxr-xr-x | src/windows/glog/logging.h | 4 |
4 files changed, 27 insertions, 13 deletions
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 84f1448..463dc37 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -840,6 +840,7 @@ namespace glog_internal_namespace_ { template <bool> struct CompileAssert { }; +class CrashReason; } // namespace glog_internal_namespace_ #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \ @@ -1106,6 +1107,9 @@ private: void Init(const char* file, int line, LogSeverity severity, 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: static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex diff --git a/src/logging.cc b/src/logging.cc index e930e4a..25e9a86 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -1182,17 +1182,9 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) { // someone else can use them (as long as they flush afterwards) if (data_->severity_ == FATAL && exit_on_dfatal) { if (data_->first_fatal_) { - crash_reason.filename = fatal_msg_data_exclusive_.fullname_; - crash_reason.line_number = fatal_msg_data_exclusive_.line_; - crash_reason.message = fatal_msg_buf_exclusive + - 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 + // Store crash information so that it is accessible from within signal + // handlers that may be invoked later. + RecordCrashReason(&crash_reason); SetCrashReason(&crash_reason); // Store shortened fatal message for other logs and GWQ status @@ -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() { #if defined(_DEBUG) && defined(_MSC_VER) // When debugging on windows, avoid the obnoxious dialog and make diff --git a/src/utilities.h b/src/utilities.h index 2c955d8..dc4c6d1 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -201,8 +201,8 @@ struct CrashReason { int line_number; const char* message; - // We'll also store a bit of context at the time of crash as it may not be - // available later on. + // We'll also store a bit of stack trace context at the time of crash as + // it may not be available later on. void* stack[32]; int depth; }; diff --git a/src/windows/glog/logging.h b/src/windows/glog/logging.h index 13d69a3..26ed501 100755 --- a/src/windows/glog/logging.h +++ b/src/windows/glog/logging.h @@ -844,6 +844,7 @@ namespace glog_internal_namespace_ { template <bool> struct CompileAssert { }; +class CrashReason; } // namespace glog_internal_namespace_ #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \ @@ -1110,6 +1111,9 @@ private: void Init(const char* file, int line, LogSeverity severity, 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: static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex |