mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-11-12 23:07:21 +00:00
[common/client] platform: abstract runtime services
This commit is contained in:
@@ -57,3 +57,13 @@ void platform_debugInit(void)
|
||||
|
||||
debug_lookup = (isatty(STDERR_FILENO) == 1) ? colorLookup : plainLookup;
|
||||
}
|
||||
|
||||
void debug_lock(void)
|
||||
{
|
||||
flockfile(stderr);
|
||||
}
|
||||
|
||||
void debug_unlock(void)
|
||||
{
|
||||
funlockfile(stderr);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
struct CrashHandlerState
|
||||
{
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER previous;
|
||||
bool installed;
|
||||
};
|
||||
|
||||
static struct CrashHandlerState crashHandler;
|
||||
|
||||
static const char * exception_name(DWORD code)
|
||||
{
|
||||
switch (code)
|
||||
@@ -124,8 +132,8 @@ static LONG CALLBACK exception_filter(EXCEPTION_POINTERS * exc)
|
||||
|
||||
if (SymFromAddr(hProcess, frame.AddrPC.Offset, &disp, symbol))
|
||||
{
|
||||
IMAGEHLP_LINE line = { sizeof(IMAGEHLP_LINE), 0 };
|
||||
DWORD lineDisp;
|
||||
IMAGEHLP_LINE line = { .SizeOfStruct = sizeof(line) };
|
||||
DWORD lineDisp;
|
||||
|
||||
if (SymGetLineFromAddr64(hProcess, frame.AddrPC.Offset, &lineDisp, &line))
|
||||
DEBUG_ERROR("[trace]: %2d: %s:%s+0x%" PRIx64 " (%s:%" PRIx64 "+0x%" PRIx64 ")",
|
||||
@@ -152,10 +160,25 @@ bool installCrashHandler(const char * exe, char * argv0)
|
||||
{
|
||||
(void)exe;
|
||||
(void)argv0;
|
||||
SetUnhandledExceptionFilter(exception_filter);
|
||||
|
||||
if (!crashHandler.installed)
|
||||
{
|
||||
crashHandler.previous = SetUnhandledExceptionFilter(exception_filter);
|
||||
crashHandler.installed = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanupCrashHandler(void)
|
||||
{
|
||||
if (!crashHandler.installed)
|
||||
return;
|
||||
|
||||
SetUnhandledExceptionFilter(crashHandler.previous);
|
||||
crashHandler.previous = NULL;
|
||||
crashHandler.installed = false;
|
||||
}
|
||||
|
||||
void printBacktrace(void)
|
||||
{
|
||||
}
|
||||
@@ -172,6 +195,10 @@ bool installCrashHandler(const char * exe, char * argv0)
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanupCrashHandler(void)
|
||||
{
|
||||
}
|
||||
|
||||
void printBacktrace(void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,3 +37,13 @@ void platform_debugInit(void)
|
||||
|
||||
debug_lookup = plainLookup;
|
||||
}
|
||||
|
||||
void debug_lock(void)
|
||||
{
|
||||
_lock_file(stderr);
|
||||
}
|
||||
|
||||
void debug_unlock(void)
|
||||
{
|
||||
_unlock_file(stderr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user