summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2012-07-30 18:33:08 -0400
committerTad Marshall <tad@10gen.com>2012-07-31 14:13:20 -0400
commit5300139ceb188361f773c7a6f3c24f9fe9affd6a (patch)
treed826820a7e823ea213659d7dce960d6761e4f2e1
parentbb2b218b02b60e03ddd3487f7bf159497645f7e9 (diff)
downloadmongo-5300139ceb188361f773c7a6f3c24f9fe9affd6a.tar.gz
SERVER-6554 Windows unhandled exception filter print stack trace
Modify the Windows stack trace printing code to accept a "context", and use the context record passed to the unhandled exception filter to start the stack trace at the faulting instruction. Collect the context used for "normal" stack traces from inside printStackTrace.
-rw-r--r--src/mongo/db/db.cpp2
-rw-r--r--src/mongo/util/stacktrace.cpp19
-rw-r--r--src/mongo/util/stacktrace.h7
3 files changed, 23 insertions, 5 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index b10617f7279..3a7ea2ca3f3 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -1386,6 +1386,8 @@ namespace mongo {
log() << "*** access violation was a " << acTypeString << addressString << endl;
}
+ log() << "*** stack trace for unhandled exception:" << endl;
+ printWindowsStackTrace( *excPointers->ContextRecord );
doMinidump(excPointers);
// In release builds, let dbexit() try to shut down cleanly
diff --git a/src/mongo/util/stacktrace.cpp b/src/mongo/util/stacktrace.cpp
index 9e9e61f138b..1daebe8b23f 100644
--- a/src/mongo/util/stacktrace.cpp
+++ b/src/mongo/util/stacktrace.cpp
@@ -151,6 +151,20 @@ namespace mongo {
* @param os ostream& to receive printed stack backtrace
*/
void printStackTrace( std::ostream& os ) {
+ CONTEXT context;
+ memset( &context, 0, sizeof(context) );
+ context.ContextFlags = CONTEXT_CONTROL;
+ RtlCaptureContext( &context );
+ printWindowsStackTrace( context, os );
+ }
+
+ /**
+ * Print stack trace (using a specified stack context) to "os"
+ *
+ * @param context CONTEXT record for stack trace
+ * @param os ostream& to receive printed stack backtrace
+ */
+ void printWindowsStackTrace( CONTEXT& context, std::ostream& os ) {
HANDLE process = GetCurrentProcess();
BOOL ret = SymInitialize( process, NULL, TRUE );
if ( ret == FALSE ) {
@@ -163,11 +177,6 @@ namespace mongo {
options |= SYMOPT_LOAD_LINES | SYMOPT_FAIL_CRITICAL_ERRORS;
SymSetOptions( options );
- CONTEXT context;
- memset( &context, 0, sizeof(context) );
- context.ContextFlags = CONTEXT_CONTROL;
- RtlCaptureContext( &context );
-
STACKFRAME64 frame64;
memset( &frame64, 0, sizeof(frame64) );
diff --git a/src/mongo/util/stacktrace.h b/src/mongo/util/stacktrace.h
index d4c9f014959..fab1d8b2a2e 100644
--- a/src/mongo/util/stacktrace.h
+++ b/src/mongo/util/stacktrace.h
@@ -8,9 +8,16 @@
#include <iostream>
+#include "mongo/platform/basic.h"
+
namespace mongo {
// Print stack trace information to "os", default to std::cout.
void printStackTrace(std::ostream &os=std::cout);
+#if defined(_WIN32)
+ // Print stack trace (using a specified stack context) to "os", default to std::cout.
+ void printWindowsStackTrace(CONTEXT &context, std::ostream &os=std::cout);
+#endif
+
} // namespace mongo