Skip to content

Commit

Permalink
[Testbed] Print callstack in Testbed exception handler.
Browse files Browse the repository at this point in the history
This uses a function in Testbed that is not directly exposed in the public interface of LLGL.
  • Loading branch information
LukasBanana committed Jun 9, 2024
1 parent 8043bbd commit 783ba29
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/Testbed/TestbedMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,33 @@ static int GuardedMain(int argc, char* argv[])
}

#ifdef _WIN32

// Declare function that is not directly exposed in LLGL
namespace LLGL
{
LLGL_EXPORT UTF8String DebugStackTrace(unsigned firstStackFrame = 0, unsigned maxNumStackFrames = 64);
};

static LONG TestbedVectoredExceptionHandler(EXCEPTION_POINTERS* e)
{
LLGL::UTF8String stackTrace = DebugStackTrace();
::fprintf(
stderr,
"Exception during test run: Address=%p, Code=0x%08X",
e->ExceptionRecord->ExceptionAddress, e->ExceptionRecord->ExceptionCode
"Exception during test run: Address=%p, Code=0x%08X\n"
"Callstack:\n"
"----------\n"
"%s\n",
e->ExceptionRecord->ExceptionAddress, e->ExceptionRecord->ExceptionCode, stackTrace.c_str()
);
return EXCEPTION_CONTINUE_SEARCH;
}
#endif

#endif // /_WIN32

int main(int argc, char* argv[])
{
#ifdef _WIN32

AddVectoredExceptionHandler(1, TestbedVectoredExceptionHandler);
__try
{
Expand All @@ -200,7 +213,9 @@ int main(int argc, char* argv[])
::fflush(stderr);
return 1;
}

#else

try
{
return GuardedMain(argc, argv);
Expand All @@ -211,6 +226,7 @@ int main(int argc, char* argv[])
::fflush(stderr);
return 1;
}

#endif
}

Expand Down

0 comments on commit 783ba29

Please sign in to comment.