Update Windows crash dump path once we know where we're logging

openmw-48
AnyOldName3 11 months ago
parent 67d08a5dae
commit 5102f4b11d

@ -75,6 +75,25 @@ namespace Crash
CloseHandle(mShmHandle);
}
void CrashCatcher::updateDumpPaths(const std::string& crashDumpPath, const std::string& freezeDumpPath)
{
shmLock();
memset(mShm->mStartup.mCrashDumpFilePath, 0, sizeof(mShm->mStartup.mCrashDumpFilePath));
size_t length = crashDumpPath.length();
if (length >= MAX_LONG_PATH) length = MAX_LONG_PATH - 1;
strncpy(mShm->mStartup.mCrashDumpFilePath, crashDumpPath.c_str(), length);
mShm->mStartup.mCrashDumpFilePath[length] = '\0';
memset(mShm->mStartup.mFreezeDumpFilePath, 0, sizeof(mShm->mStartup.mFreezeDumpFilePath));
length = freezeDumpPath.length();
if (length >= MAX_LONG_PATH) length = MAX_LONG_PATH - 1;
strncpy(mShm->mStartup.mFreezeDumpFilePath, freezeDumpPath.c_str(), length);
mShm->mStartup.mFreezeDumpFilePath[length] = '\0';
shmUnlock();
}
void CrashCatcher::setupIpc()
{
SECURITY_ATTRIBUTES attributes;

@ -27,10 +27,16 @@ namespace Crash
class CrashCatcher final
{
public:
static CrashCatcher* instance()
{
return sInstance;
}
CrashCatcher(int argc, char** argv, const std::string& crashDumpPath, const std::string& freezeDumpPath);
~CrashCatcher();
void updateDumpPaths(const std::string& crashDumpPath, const std::string& freezeDumpPath);
private:
static CrashCatcher* sInstance;

@ -296,6 +296,16 @@ void setupLogging(const std::string& logDir, std::string_view appName)
std::cout.rdbuf(&coutsb);
std::cerr.rdbuf(&cerrsb);
#endif
#ifdef _WIN32
if (Crash::CrashCatcher::instance())
{
const std::string crashDumpName = Misc::StringUtils::lowerCase(appName) + "-crash.dmp";
const std::string freezeDumpName = Misc::StringUtils::lowerCase(appName) + "-freeze.dmp";
boost::filesystem::path dumpDirectory(logDir);
Crash::CrashCatcher::instance()->updateDumpPaths((dumpDirectory / crashDumpName).make_preferred().string(), (dumpDirectory / freezeDumpName).make_preferred().string());
}
#endif
}
int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, char *argv[],

Loading…
Cancel
Save