Skip to content

Commit f6a5fb3

Browse files
committed
shorten crashlog paths from the gd folder
1 parent 5b2865a commit f6a5fb3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

loader/src/platform/windows/crashlog.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ static std::string getDateString(bool filesafe) {
3838
return oss.str();
3939
}
4040

41-
static std::string getModuleName(HMODULE module, bool fullPath = true) {
41+
static std::string getModuleName(HMODULE module, bool fullPath = true, bool shortKnown = false) {
4242
char buffer[MAX_PATH];
4343
if (!GetModuleFileNameA(module, buffer, MAX_PATH)) {
4444
return "<Unknown>";
4545
}
4646
if (fullPath) {
47+
if (shortKnown) {
48+
auto gdDir = utils::string::wideToUtf8(dirs::getGameDir().wstring());
49+
if (std::string_view(buffer).starts_with(gdDir)) {
50+
return std::filesystem::path(buffer).filename().string();
51+
}
52+
}
4753
return buffer;
4854
}
4955
return std::filesystem::path(buffer).filename().string();
@@ -129,7 +135,7 @@ static void printAddr(std::ostream& stream, void const* addr, bool fullPath = tr
129135
)) {
130136
// calculate base + [address]
131137
auto const diff = reinterpret_cast<uintptr_t>(addr) - reinterpret_cast<uintptr_t>(module);
132-
stream << getModuleName(module, fullPath) << " + " << std::hex << diff << std::dec;
138+
stream << getModuleName(module, fullPath, true) << " + " << std::hex << diff << std::dec;
133139

134140
// log symbol if possible
135141
if (g_symbolsInitialized) {
@@ -248,7 +254,7 @@ static std::string getStacktrace(PCONTEXT context, Mod*& suspectedFaultyMod) {
248254
return ret;
249255
}
250256
return SymFunctionTableAccess64(hProcess, AddrBase);
251-
},
257+
},
252258
+[](HANDLE hProcess, DWORD64 dwAddr) -> DWORD64 {
253259
auto ret = GeodeFunctionTableAccess64(hProcess, dwAddr);
254260
if (ret) {
@@ -510,14 +516,14 @@ static void handleException(LPEXCEPTION_POINTERS info) {
510516
}
511517
else {
512518
// set the search path to include the mods' temp directories
513-
if (std::array<char, 4096> searchPathBuffer;
519+
if (std::array<char, 4096> searchPathBuffer;
514520
SymGetSearchPath(static_cast<HMODULE>(GetCurrentProcess()), searchPathBuffer.data(), searchPathBuffer.size())) {
515521
std::string searchPath(searchPathBuffer.data());
516522
searchPath += ";" + g_unzippedSearchPaths;
517523
SymSetSearchPath(static_cast<HMODULE>(GetCurrentProcess()), searchPath.c_str());
518524
}
519525
}
520-
526+
521527
// in some cases, we can be pretty certain that the first mod found while unwinding
522528
// is the one that caused the crash, so using `suspectedFaultyMod` is safe and correct.
523529
//

0 commit comments

Comments
 (0)