44#include " xrDebug.h"
55#include " os_clipboard.h"
66#include " Debug/dxerr.h"
7- #include " Threading/ScopeLock.h "
7+ #include " Threading/ScopeLock.hpp "
88
99#pragma warning(push)
1010#pragma warning(disable : 4091) // 'typedef ': ignored on left of '' when no variable is declared
@@ -47,7 +47,7 @@ static BOOL bException = FALSE;
4747
4848#if defined XR_X64
4949# define MACHINE_TYPE IMAGE_FILE_MACHINE_AMD64
50- #elif defined XR_X86
50+ #elif defined XR_X86
5151# define MACHINE_TYPE IMAGE_FILE_MACHINE_I386
5252#else
5353# error CPU architecture is not supported.
@@ -81,12 +81,12 @@ bool xrDebug::ErrorAfterDialog = false;
8181bool xrDebug::symEngineInitialized = false ;
8282Lock xrDebug::dbgHelpLock;
8383
84- void xrDebug::SetBugReportFile (const char * fileName) { strcpy_s (BugReportFile, fileName); }
84+ void xrDebug::SetBugReportFile (const char * fileName) { strcpy_s (BugReportFile, fileName); }
8585
86- bool xrDebug::GetNextStackFrameString (LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string & frameStr)
86+ bool xrDebug::GetNextStackFrameString (LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string& frameStr)
8787{
8888 BOOL result = StackWalk (MACHINE_TYPE, GetCurrentProcess (), GetCurrentThread (), stackFrame, threadCtx, nullptr ,
89- SymFunctionTableAccess, SymGetModuleBase, nullptr );
89+ SymFunctionTableAccess, SymGetModuleBase, nullptr );
9090
9191 if (result == FALSE || stackFrame->AddrPC .Offset == 0 )
9292 {
@@ -149,8 +149,8 @@ bool xrDebug::GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCt
149149 {
150150 if (dwLineOffset)
151151 {
152- xr_sprintf (formatBuff, _countof (formatBuff), " in %s line %u + %u byte(s)" , sourceInfo.FileName ,
153- sourceInfo.LineNumber , dwLineOffset);
152+ xr_sprintf (formatBuff, _countof (formatBuff), " in %s line %u + %u byte(s)" , sourceInfo.FileName ,
153+ sourceInfo.LineNumber , dwLineOffset);
154154 }
155155 else
156156 {
@@ -211,7 +211,7 @@ xr_vector<xr_string> xrDebug::BuildStackTrace(PCONTEXT threadCtx, u16 maxFramesC
211211 stackFrame.AddrStack .Offset = threadCtx->Rsp ;
212212 stackFrame.AddrFrame .Mode = AddrModeFlat;
213213 stackFrame.AddrFrame .Offset = threadCtx->Rbp ;
214- #elif defined XR_X86
214+ #elif defined XR_X86
215215 stackFrame.AddrPC .Mode = AddrModeFlat;
216216 stackFrame.AddrPC .Offset = threadCtx->Eip ;
217217 stackFrame.AddrStack .Mode = AddrModeFlat;
@@ -236,26 +236,26 @@ SStringVec xrDebug::BuildStackTrace(u16 maxFramesCount)
236236{
237237 CONTEXT currentThreadCtx = {};
238238
239- RtlCaptureContext (¤tThreadCtx); // / GetThreadContext cann 't be used on the current thread
239+ RtlCaptureContext (¤tThreadCtx); // / GetThreadContext can 't be used on the current thread
240240 currentThreadCtx.ContextFlags = CONTEXT_FULL;
241241
242242 return BuildStackTrace (¤tThreadCtx, maxFramesCount);
243243}
244244
245- void xrDebug::LogStackTrace (const char * header)
245+ void xrDebug::LogStackTrace (const char * header)
246246{
247247 SStringVec stackTrace = BuildStackTrace ();
248248 Msg (" %s" , header);
249- for (const auto & frame : stackTrace)
249+ for (const auto & frame : stackTrace)
250250 {
251251 Msg (" %s" , frame.c_str ());
252252 }
253253}
254254
255- void xrDebug::GatherInfo (char * assertionInfo, const ErrorLocation & loc, const char * expr, const char * desc,
256- const char * arg1, const char * arg2)
255+ void xrDebug::GatherInfo (char * assertionInfo, const ErrorLocation& loc, const char * expr, const char * desc,
256+ const char * arg1, const char * arg2)
257257{
258- char * buffer = assertionInfo;
258+ char * buffer = assertionInfo;
259259 if (!expr)
260260 expr = " <no expression>" ;
261261 bool extendedDesc = desc && strchr (desc, ' \n ' );
@@ -317,7 +317,7 @@ void xrDebug::GatherInfo(char *assertionInfo, const ErrorLocation &loc, const ch
317317 os_clipboard::copy_to_clipboard (assertionInfo);
318318}
319319
320- void xrDebug::Fatal (const ErrorLocation & loc, const char * format, ...)
320+ void xrDebug::Fatal (const ErrorLocation& loc, const char * format, ...)
321321{
322322 string1024 desc;
323323 va_list args;
@@ -328,14 +328,14 @@ void xrDebug::Fatal(const ErrorLocation &loc, const char *format, ...)
328328 Fail (ignoreAlways, loc, nullptr , " fatal error" , desc);
329329}
330330
331- void xrDebug::Fail (bool & ignoreAlways, const ErrorLocation & loc, const char * expr, long hresult, const char * arg1,
332- const char * arg2)
331+ void xrDebug::Fail (bool & ignoreAlways, const ErrorLocation& loc, const char * expr, long hresult, const char * arg1,
332+ const char * arg2)
333333{
334334 Fail (ignoreAlways, loc, expr, xrDebug::ErrorToString (hresult), arg1, arg2);
335335}
336336
337- void xrDebug::Fail (bool & ignoreAlways, const ErrorLocation & loc, const char * expr, const char * desc, const char * arg1,
338- const char * arg2)
337+ void xrDebug::Fail (bool & ignoreAlways, const ErrorLocation& loc, const char * expr, const char * desc, const char * arg1,
338+ const char * arg2)
339339{
340340#ifdef PROFILE_CRITICAL_SECTIONS
341341 static Lock lock (MUTEX_PROFILE_ID (xrDebug::Backend));
@@ -348,11 +348,11 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
348348 GatherInfo (assertionInfo, loc, expr, desc, arg1, arg2);
349349#ifdef USE_OWN_ERROR_MESSAGE_WINDOW
350350 strcat (assertionInfo,
351- " \r\n "
352- " Press CANCEL to abort execution\r\n "
353- " Press TRY AGAIN to continue execution\r\n "
354- " Press CONTINUE to continue execution and ignore all the errors of this type\r\n "
355- " \r\n " );
351+ " \r\n "
352+ " Press CANCEL to abort execution\r\n "
353+ " Press TRY AGAIN to continue execution\r\n "
354+ " Press CONTINUE to continue execution and ignore all the errors of this type\r\n "
355+ " \r\n " );
356356#endif
357357 if (OnCrash)
358358 OnCrash ();
@@ -364,7 +364,8 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
364364 else
365365 {
366366#ifdef USE_OWN_ERROR_MESSAGE_WINDOW
367- int result = MessageBox (NULL , assertionInfo, " Fatal error" , MB_CANCELTRYCONTINUE | MB_ICONERROR | MB_SYSTEMMODAL);
367+ int result = MessageBox (NULL , assertionInfo, " Fatal error" ,
368+ MB_CANCELTRYCONTINUE | MB_ICONERROR | MB_SYSTEMMODAL);
368369 switch (result)
369370 {
370371 case IDCANCEL:
@@ -373,7 +374,8 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
373374#endif
374375 DEBUG_BREAK;
375376 break ;
376- case IDTRYAGAIN: ErrorAfterDialog = false ; break ;
377+ case IDTRYAGAIN: ErrorAfterDialog = false ;
378+ break ;
377379 case IDCONTINUE:
378380 ErrorAfterDialog = false ;
379381 ignoreAlways = true ;
@@ -392,13 +394,13 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
392394 lock.Leave ();
393395}
394396
395- void xrDebug::Fail (bool & ignoreAlways, const ErrorLocation & loc, const char * expr, const std::string & desc,
396- const char * arg1, const char * arg2)
397+ void xrDebug::Fail (bool & ignoreAlways, const ErrorLocation& loc, const char * expr, const std::string& desc,
398+ const char * arg1, const char * arg2)
397399{
398400 Fail (ignoreAlways, loc, expr, desc.c_str (), arg1, arg2);
399401}
400402
401- void xrDebug::DoExit (const std::string & message)
403+ void xrDebug::DoExit (const std::string& message)
402404{
403405 FlushLog ();
404406 MessageBox (NULL , message.c_str (), " Error" , MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
@@ -407,7 +409,7 @@ void xrDebug::DoExit(const std::string &message)
407409
408410LPCSTR xrDebug::ErrorToString (long code)
409411{
410- const char * result = nullptr ;
412+ const char * result = nullptr ;
411413 static string1024 descStorage;
412414 DXGetErrorDescription (code, descStorage, sizeof (descStorage));
413415 if (!result)
@@ -475,7 +477,7 @@ void WINAPI xrDebug::PreErrorHandler(INT_PTR)
475477 BT_SaveSnapshot (nullptr );
476478}
477479
478- void xrDebug::SetupExceptionHandler (const bool & dedicated)
480+ void xrDebug::SetupExceptionHandler (const bool & dedicated)
479481{
480482 // disable 'appname has stopped working' popup dialog
481483 UINT prevMode = SetErrorMode (SEM_NOGPFAULTERRORBOX);
@@ -486,11 +488,11 @@ void xrDebug::SetupExceptionHandler(const bool &dedicated)
486488 else
487489 BT_SetActivityType (BTA_SAVEREPORT);
488490 BT_SetDialogMessage (BTDM_INTRO2,
489- " This is X-Ray Engine v1.6 crash reporting client. "
490- " To help the development process, "
491- " please Submit Bug or save report and email it manually (button More...)."
492- " \r\n "
493- " Many thanks in advance and sorry for the inconvenience." );
491+ " This is X-Ray Engine v1.6 crash reporting client. "
492+ " To help the development process, "
493+ " please Submit Bug or save report and email it manually (button More...)."
494+ " \r\n "
495+ " Many thanks in advance and sorry for the inconvenience." );
494496 BT_SetPreErrHandler (PreErrorHandler, 0 );
495497 BT_SetAppName (" X-Ray Engine" );
496498 BT_SetReportFormat (BTRF_TEXT);
@@ -536,23 +538,23 @@ void xrDebug::SaveMiniDump(EXCEPTION_POINTERS *exPtrs)
536538}
537539#endif
538540
539- void xrDebug::FormatLastError (char * buffer, const size_t & bufferSize)
541+ void xrDebug::FormatLastError (char * buffer, const size_t & bufferSize)
540542{
541543 int lastErr = GetLastError ();
542544 if (lastErr == ERROR_SUCCESS)
543545 {
544546 *buffer = 0 ;
545547 return ;
546548 }
547- void * msg = nullptr ;
549+ void * msg = nullptr ;
548550 FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr , lastErr,
549- MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0 , nullptr );
551+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0 , nullptr );
550552 // XXX nitrocaster: check buffer overflow
551553 sprintf (buffer, " [error][%8d]: %s" , lastErr, (char *)msg);
552554 LocalFree (msg);
553555}
554556
555- LONG WINAPI xrDebug::UnhandledFilter (EXCEPTION_POINTERS * exPtrs)
557+ LONG WINAPI xrDebug::UnhandledFilter (EXCEPTION_POINTERS* exPtrs)
556558{
557559 string256 errMsg;
558560 FormatLastError (errMsg, sizeof (errMsg));
@@ -599,9 +601,9 @@ LONG WINAPI xrDebug::UnhandledFilter(EXCEPTION_POINTERS *exPtrs)
599601 if (OnDialog)
600602 OnDialog (true );
601603 MessageBox (NULL ,
602- " Fatal error occurred\n\n "
603- " Press OK to abort program execution" ,
604- " Fatal error" , MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
604+ " Fatal error occurred\n\n "
605+ " Press OK to abort program execution" ,
606+ " Fatal error" , MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
605607 }
606608#endif
607609 ReportFault (exPtrs, 0 );
@@ -627,14 +629,14 @@ void _terminate()
627629}
628630#endif // USE_BUG_TRAP
629631
630- static void handler_base (const char * reason)
632+ static void handler_base (const char * reason)
631633{
632634 bool ignoreAlways = false ;
633635 xrDebug::Fail (ignoreAlways, DEBUG_INFO, nullptr , reason, nullptr , nullptr );
634636}
635637
636- static void invalid_parameter_handler (const wchar_t * expression, const wchar_t * function, const wchar_t * file,
637- unsigned int line, uintptr_t reserved)
638+ static void invalid_parameter_handler (const wchar_t * expression, const wchar_t * function, const wchar_t * file,
639+ unsigned int line, uintptr_t reserved)
638640{
639641 bool ignoreAlways = false ;
640642 string4096 mbExpression;
@@ -668,6 +670,7 @@ static void abort_handler(int signal) { handler_base("application is aborting");
668670static void floating_point_handler (int signal) { handler_base (" floating point error" ); }
669671static void illegal_instruction_handler (int signal) { handler_base (" illegal instruction" ); }
670672static void termination_handler (int signal) { handler_base (" termination with exit code 3" ); }
673+
671674void xrDebug::OnThreadSpawn ()
672675{
673676#ifdef USE_BUG_TRAP
@@ -691,7 +694,7 @@ void xrDebug::OnThreadSpawn()
691694#endif
692695}
693696
694- void xrDebug::Initialize (const bool & dedicated)
697+ void xrDebug::Initialize (const bool & dedicated)
695698{
696699 *BugReportFile = 0 ;
697700 OnThreadSpawn ();
0 commit comments