Skip to content

Commit

Permalink
xrCore/xrDebug.cpp: GetInstructionPtr() refactor
Browse files Browse the repository at this point in the history
Fixed BugTrap reports path
  • Loading branch information
Xottab-DUTY committed Feb 5, 2018
1 parent 516d22c commit 77d94c7
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/xrCore/xrDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ static BOOL bException = FALSE;

namespace
{
#ifdef XR_X64
extern "C" void * _ReturnAddress(void);
DWORD_PTR GetInstructionPtr()
{
return (DWORD_PTR)_ReturnAddress();
}
#else
void __declspec(naked, noinline) * __cdecl GetInstructionPtr()

ICN void* GetInstructionPtr()
{
_asm mov eax, [esp] _asm retn
}
#ifdef _MSC_VER
return _ReturnAddress();
#else
#ifdef _WIN64
_asm mov rax, [rsp]
_asm retn
#else
_asm mov eax, [esp]
_asm retn
#endif
#endif
}
}

xrDebug::UnhandledExceptionFilter xrDebug::PrevFilter = nullptr;
Expand Down Expand Up @@ -90,7 +93,7 @@ size_t xrDebug::BuildStackTrace(char* buffer, size_t capacity, size_t lineCapaci
if (GetThreadContext(GetCurrentThread(), &context))
{
#if defined(XR_X64)
context.Rip = GetInstructionPtr();
context.Rip = (DWORD64)GetInstructionPtr();
context.Rbp = (DWORD64)&ebp;
context.Rsp = (DWORD64)&context;
#elif defined(XR_X86)
Expand Down Expand Up @@ -337,7 +340,7 @@ void WINAPI xrDebug::PreErrorHandler(INT_PTR)

string_path dumpPath;
if (FS.path_exist("$app_data_root$"))
FS.update_path(dumpPath, "$app_data_root$", dumpPath);
FS.update_path(dumpPath, "$app_data_root$", "");
xr_strcat(dumpPath, "reports");

BT_SetReportFilePath(dumpPath);
Expand Down Expand Up @@ -468,7 +471,7 @@ LONG WINAPI xrDebug::UnhandledFilter(EXCEPTION_POINTERS* exPtrs)
if (OnDialog)
OnDialog(true);
MessageBox(NULL,
"Fatal error occured\n\n"
"Fatal error occurred\n\n"
"Press OK to abort program execution",
"Fatal error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
}
Expand Down

0 comments on commit 77d94c7

Please sign in to comment.