Skip to content

Commit

Permalink
Codechange: [Win32] unify AppendDecodedStacktrace and LogStacktrace (O…
Browse files Browse the repository at this point in the history
…penTTD#11220)

AppendDecodedStacktrace was already doing the same as LogStacktrace,
just with a different name.
  • Loading branch information
TrueBrain committed Aug 20, 2023
1 parent bc2dfc4 commit 45cc3ac
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/os/windows/crashlog_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ class CrashLogWindows : public CrashLog {
}
#endif

#if defined(_MSC_VER)
void AppendDecodedStacktrace(std::back_insert_iterator<std::string> &output_iterator) const;
#else
void AppendDecodedStacktrace(std::back_insert_iterator<std::string> &output_iterator) const {}
#endif /* _MSC_VER */

/**
* A crash log is always generated when it's generated.
* @param ep the data related to the exception.
Expand Down Expand Up @@ -111,17 +105,11 @@ class CrashLogWindows : public CrashLog {
);
}

/* virtual */ void CrashLogWindows::LogStacktrace(std::back_insert_iterator<std::string> &output_iterator) const
{
fmt::format_to(output_iterator, "Stack trace:\n");
fmt::format_to(output_iterator, " Not supported.\n");
}

#if defined(_MSC_VER)
static const uint MAX_SYMBOL_LEN = 512;
static const uint MAX_FRAMES = 64;

void CrashLogWindows::AppendDecodedStacktrace(std::back_insert_iterator<std::string> &output_iterator) const
/* virtual */ void CrashLogWindows::LogStacktrace(std::back_insert_iterator<std::string> &output_iterator) const
{
DllLoader dbghelp(L"dbghelp.dll");
struct ProcPtrs {
Expand All @@ -146,7 +134,7 @@ void CrashLogWindows::AppendDecodedStacktrace(std::back_insert_iterator<std::str
dbghelp.GetProcAddress("SymGetLineFromAddr64"),
};

fmt::format_to(output_iterator, "\nDecoded stack trace:\n");
fmt::format_to(output_iterator, "Stack trace:\n");

/* Try to load the functions from the DLL, if that fails because of a too old dbghelp.dll, just skip it. */
if (dbghelp.Success()) {
Expand Down Expand Up @@ -231,7 +219,13 @@ void CrashLogWindows::AppendDecodedStacktrace(std::back_insert_iterator<std::str
proc.pSymCleanup(hCur);
}

fmt::format_to(output_iterator, "\n*** End of additional info ***\n");
fmt::format_to(output_iterator, "\n");
}
#else
/* virtual */ void CrashLogWindows::LogStacktrace(std::back_insert_iterator<std::string> &output_iterator) const
{
fmt::format_to(output_iterator, "Stack trace:\n");
fmt::format_to(output_iterator, " Not supported.\n");
}
#endif /* _MSC_VER */

Expand Down Expand Up @@ -279,7 +273,6 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
auto output_iterator = std::back_inserter(log->crashlog);
log->FillCrashLog(output_iterator);
log->WriteCrashDump();
log->AppendDecodedStacktrace(output_iterator);
log->WriteCrashLog();
log->WriteScreenshot();
log->SendSurvey();
Expand Down

0 comments on commit 45cc3ac

Please sign in to comment.