diff options
author | Tad Marshall <tad@10gen.com> | 2012-11-13 14:56:39 -0500 |
---|---|---|
committer | Dan Pasette <dan@10gen.com> | 2013-01-08 03:10:02 -0500 |
commit | f7afbab2c3fcb54475a6d3c12065f7b36a3f5065 (patch) | |
tree | 2c3135287f5962b1d0c79076329c2e02b747cc8e | |
parent | e4d0c8913502bf13c00e1448fc74b38cea8cdfff (diff) | |
download | mongo-f7afbab2c3fcb54475a6d3c12065f7b36a3f5065.tar.gz |
SERVER-7435 Set symbol path in call to SymInitialize()
Set a symbol search path for Windows stack trace, starting with the
directory where the running executable is located. Include Windows
directories as well, using default locations.
-rw-r--r-- | src/mongo/util/stacktrace.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/mongo/util/stacktrace.cpp b/src/mongo/util/stacktrace.cpp index 032b5070b0e..7858eef82e6 100644 --- a/src/mongo/util/stacktrace.cpp +++ b/src/mongo/util/stacktrace.cpp @@ -11,6 +11,7 @@ #ifdef _WIN32 #include <sstream> #include <stdio.h> +#include <boost/filesystem/operations.hpp> #include <boost/smart_ptr/scoped_array.hpp> #include "mongo/platform/windows_basic.h" #include <DbgHelp.h> @@ -54,6 +55,26 @@ namespace mongo { namespace mongo { /** + * Get the path string to be used when searching for PDB files. + * + * @param process Process handle + * @return searchPath Returned search path string + */ + static const char* getSymbolSearchPath(HANDLE process) { + static std::string symbolSearchPath; + + if (symbolSearchPath.empty()) { + static const size_t bufferSize = 1024; + boost::scoped_array<char> pathBuffer(new char[bufferSize]); + GetModuleFileNameA(NULL, pathBuffer.get(), bufferSize); + boost::filesystem::path exePath(pathBuffer.get()); + symbolSearchPath = exePath.parent_path().string(); + symbolSearchPath += ";C:\\Windows\\System32;C:\\Windows"; + } + return symbolSearchPath.c_str(); + } + + /** * Get the display name of the executable module containing the specified address. * * @param process Process handle @@ -172,7 +193,7 @@ namespace mongo { void printWindowsStackTrace( CONTEXT& context, std::ostream& os ) { SimpleMutex::scoped_lock lk(_stackTraceMutex); HANDLE process = GetCurrentProcess(); - BOOL ret = SymInitialize( process, NULL, TRUE ); + BOOL ret = SymInitialize(process, getSymbolSearchPath(process), TRUE); if ( ret == FALSE ) { DWORD dosError = GetLastError(); log() << "Stack trace failed, SymInitialize failed with error " << |