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

Manual rewrite of 5102f4b11d
revert-6246b479
AnyOldName3 2 years ago
parent 72d99237e3
commit 48368f79b6

@ -77,6 +77,32 @@ namespace Crash
CloseHandle(mShmHandle);
}
void CrashCatcher::updateDumpPaths(
const std::filesystem::path& crashDumpPath, const std::filesystem::path& freezeDumpPath)
{
shmLock();
memset(mShm->mStartup.mCrashDumpFilePath, 0, sizeof(mShm->mStartup.mCrashDumpFilePath));
const auto str = crashDumpPath.u8string();
size_t length = str.length();
if (length >= MAX_LONG_PATH)
length = MAX_LONG_PATH - 1;
strncpy_s(mShm->mStartup.mCrashDumpFilePath, sizeof mShm->mStartup.mCrashDumpFilePath,
Misc::StringUtils::u8StringToString(str).c_str(), length);
mShm->mStartup.mCrashDumpFilePath[length] = '\0';
memset(mShm->mStartup.mFreezeDumpFilePath, 0, sizeof(mShm->mStartup.mFreezeDumpFilePath));
const auto strFreeze = freezeDumpPath.u8string();
length = strFreeze.length();
if (length >= MAX_LONG_PATH)
length = MAX_LONG_PATH - 1;
strncpy_s(mShm->mStartup.mFreezeDumpFilePath, sizeof mShm->mStartup.mFreezeDumpFilePath,
Misc::StringUtils::u8StringToString(strFreeze).c_str(), length);
mShm->mStartup.mFreezeDumpFilePath[length] = '\0';
shmUnlock();
}
void CrashCatcher::setupIpc()
{
SECURITY_ATTRIBUTES attributes;

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

@ -314,6 +314,16 @@ void setupLogging(const std::filesystem::path& 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";
std::filesystem::path dumpDirectory = logDir;
Crash::CrashCatcher::instance()->updateDumpPaths(dumpDirectory / crashDumpName, dumpDirectory / freezeDumpName);
}
#endif
}
int wrapApplication(int (*innerApplication)(int argc, char* argv[]), int argc, char* argv[], std::string_view appName)

Loading…
Cancel
Save