1
0
mirror of synced 2024-12-02 19:27:21 +01:00

feat: log stacktrace implementation used (#1769)

This commit is contained in:
iTrooz 2024-06-22 21:33:52 +02:00 committed by GitHub
parent b93fd523aa
commit 65dfd4da0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 11 deletions

View File

@ -15,6 +15,11 @@ namespace hex::stacktrace {
void initialize(); void initialize();
std::vector<StackFrame> getStackTrace(); struct StackTraceResult {
std::vector<StackFrame> stackFrames;
std::string implementationName;
};
StackTraceResult getStackTrace();
} }

View File

@ -63,7 +63,9 @@ namespace hex::crash {
} }
static void printStackTrace() { static void printStackTrace() {
for (const auto &stackFrame : stacktrace::getStackTrace()) { auto stackTraceResult = stacktrace::getStackTrace();
log::fatal("Printing stacktrace using implementation '{}'", stackTraceResult.implementationName);
for (const auto &stackFrame : stackTraceResult.stackFrames) {
if (stackFrame.line == 0) if (stackFrame.line == 0)
log::fatal(" ({}) | {}", stackFrame.file, stackFrame.function); log::fatal(" ({}) | {}", stackFrame.file, stackFrame.function);
else else

View File

@ -29,7 +29,7 @@ namespace {
} }
std::vector<StackFrame> getStackTrace() { StackTraceResult getStackTrace() {
std::vector<StackFrame> stackTrace; std::vector<StackFrame> stackTrace;
HANDLE process = GetCurrentProcess(); HANDLE process = GetCurrentProcess();
@ -100,7 +100,7 @@ namespace {
SymCleanup(process); SymCleanup(process);
return stackTrace; return StackTraceResult{ stackTrace, "StackWalk" };
} }
} }
@ -119,7 +119,7 @@ namespace {
} }
std::vector<StackFrame> getStackTrace() { StackTraceResult getStackTrace() {
static std::vector<StackFrame> result; static std::vector<StackFrame> result;
std::array<void*, 128> addresses = {}; std::array<void*, 128> addresses = {};
@ -135,7 +135,7 @@ namespace {
result.push_back(StackFrame { std::move(fileName), std::move(demangledName), 0 }); result.push_back(StackFrame { std::move(fileName), std::move(demangledName), 0 });
} }
return result; return StackTraceResult{ result, "execinfo" };
} }
} }
@ -162,7 +162,7 @@ namespace {
} }
} }
std::vector<StackFrame> getStackTrace() { StackTraceResult getStackTrace() {
static std::vector<StackFrame> result; static std::vector<StackFrame> result;
result.clear(); result.clear();
@ -180,7 +180,7 @@ namespace {
} }
return result; return StackTraceResult{ result, "backtrace" };
} }
} }
@ -192,8 +192,12 @@ namespace {
namespace hex::stacktrace { namespace hex::stacktrace {
void initialize() { } void initialize() { }
std::vector<StackFrame> getStackTrace() { return { StackFrame { "??", "Stacktrace collecting not available!", 0 } }; } StackTraceResult getStackTrace() {
return StackTraceResult {
{StackFrame { "??", "Stacktrace collecting not available!", 0 }},
"none"
};
}
} }
#endif #endif