diff options
author | Tad Marshall <tad@10gen.com> | 2012-11-13 14:56:39 -0500 |
---|---|---|
committer | Tad Marshall <tad@10gen.com> | 2012-11-19 21:02:22 -0500 |
commit | a273613e5b95ab666f770d07f77df1b5d2abd888 (patch) | |
tree | 14dc124a14230ccf30881c34a62d950b1cba5bd2 | |
parent | e12ae88b13032796fda557e8c1fa070f6935b322 (diff) | |
download | mongo-a273613e5b95ab666f770d07f77df1b5d2abd888.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 " << |