Introduce RecordCrashReason().
author <shinichiro.hamaji@gmail.com> <>
Wed, 4 Mar 2009 10:16:33 +0000 (10:16 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Wed, 4 Mar 2009 10:16:33 +0000 (10:16 +0000)
git-svn-id: https://google-glog.googlecode.com/svn/trunk@40 eb4d4688-79bd-11dd-afb4-1d65580434c0

src/glog/logging.h.in
src/logging.cc
src/utilities.h
src/windows/glog/logging.h

index 84f1448..463dc37 100644 (file)
@@ -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
 
index e930e4a..25e9a86 100644 (file)
@@ -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
index 2c955d8..dc4c6d1 100644 (file)
@@ -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;
 };
index 13d69a3..26ed501 100755 (executable)
@@ -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