Call SymInitialize only once and SymCleanup at app exit

In order to refresh the modules, call SymRefreshModuleList regularly

refs #845
This commit is contained in:
Roland Winklmeier
2016-12-27 03:09:23 +01:00
committed by Mathew Sutcliffe
parent dcbddf8e5e
commit 09963bf33a

View File

@@ -15,6 +15,8 @@
#include <QStringBuilder>
#include <QMutexLocker>
#include <array>
#include <cstdlib>
#include <mutex>
#if defined(Q_CC_MSVC)
# include <windows.h>
@@ -47,8 +49,15 @@ namespace BlackMisc
static QMutex mutex;
QMutexLocker lock(&mutex);
static std::once_flag flag;
std::call_once(flag, []
{
SymInitialize(GetCurrentProcess(), nullptr, true);
std::atexit([] { SymCleanup(GetCurrentProcess()); });
});
auto process = GetCurrentProcess();
SymInitialize(process, nullptr, true);
SymRefreshModuleList(process);
std::array<void*, 100> stack;
auto frames = CaptureStackBackTrace(1, static_cast<DWORD>(stack.size()), stack.data(), nullptr);