4
4
#include " xrDebug.h"
5
5
#include " os_clipboard.h"
6
6
#include " Debug/dxerr.h"
7
- #include " Threading/ScopeLock.h "
7
+ #include " Threading/ScopeLock.hpp "
8
8
9
9
#pragma warning(push)
10
10
#pragma warning(disable : 4091) // 'typedef ': ignored on left of '' when no variable is declared
@@ -47,7 +47,7 @@ static BOOL bException = FALSE;
47
47
48
48
#if defined XR_X64
49
49
# define MACHINE_TYPE IMAGE_FILE_MACHINE_AMD64
50
- #elif defined XR_X86
50
+ #elif defined XR_X86
51
51
# define MACHINE_TYPE IMAGE_FILE_MACHINE_I386
52
52
#else
53
53
# error CPU architecture is not supported.
@@ -81,12 +81,12 @@ bool xrDebug::ErrorAfterDialog = false;
81
81
bool xrDebug::symEngineInitialized = false ;
82
82
Lock xrDebug::dbgHelpLock;
83
83
84
- void xrDebug::SetBugReportFile (const char * fileName) { strcpy_s (BugReportFile, fileName); }
84
+ void xrDebug::SetBugReportFile (const char * fileName) { strcpy_s (BugReportFile, fileName); }
85
85
86
- bool xrDebug::GetNextStackFrameString (LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string & frameStr)
86
+ bool xrDebug::GetNextStackFrameString (LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string& frameStr)
87
87
{
88
88
BOOL result = StackWalk (MACHINE_TYPE, GetCurrentProcess (), GetCurrentThread (), stackFrame, threadCtx, nullptr ,
89
- SymFunctionTableAccess, SymGetModuleBase, nullptr );
89
+ SymFunctionTableAccess, SymGetModuleBase, nullptr );
90
90
91
91
if (result == FALSE || stackFrame->AddrPC .Offset == 0 )
92
92
{
@@ -149,8 +149,8 @@ bool xrDebug::GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCt
149
149
{
150
150
if (dwLineOffset)
151
151
{
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);
154
154
}
155
155
else
156
156
{
@@ -211,7 +211,7 @@ xr_vector<xr_string> xrDebug::BuildStackTrace(PCONTEXT threadCtx, u16 maxFramesC
211
211
stackFrame.AddrStack .Offset = threadCtx->Rsp ;
212
212
stackFrame.AddrFrame .Mode = AddrModeFlat;
213
213
stackFrame.AddrFrame .Offset = threadCtx->Rbp ;
214
- #elif defined XR_X86
214
+ #elif defined XR_X86
215
215
stackFrame.AddrPC .Mode = AddrModeFlat;
216
216
stackFrame.AddrPC .Offset = threadCtx->Eip ;
217
217
stackFrame.AddrStack .Mode = AddrModeFlat;
@@ -236,26 +236,26 @@ SStringVec xrDebug::BuildStackTrace(u16 maxFramesCount)
236
236
{
237
237
CONTEXT currentThreadCtx = {};
238
238
239
- RtlCaptureContext (¤tThreadCtx); // / GetThreadContext cann 't be used on the current thread
239
+ RtlCaptureContext (¤tThreadCtx); // / GetThreadContext can 't be used on the current thread
240
240
currentThreadCtx.ContextFlags = CONTEXT_FULL;
241
241
242
242
return BuildStackTrace (¤tThreadCtx, maxFramesCount);
243
243
}
244
244
245
- void xrDebug::LogStackTrace (const char * header)
245
+ void xrDebug::LogStackTrace (const char * header)
246
246
{
247
247
SStringVec stackTrace = BuildStackTrace ();
248
248
Msg (" %s" , header);
249
- for (const auto & frame : stackTrace)
249
+ for (const auto & frame : stackTrace)
250
250
{
251
251
Msg (" %s" , frame.c_str ());
252
252
}
253
253
}
254
254
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)
257
257
{
258
- char * buffer = assertionInfo;
258
+ char * buffer = assertionInfo;
259
259
if (!expr)
260
260
expr = " <no expression>" ;
261
261
bool extendedDesc = desc && strchr (desc, ' \n ' );
@@ -317,7 +317,7 @@ void xrDebug::GatherInfo(char *assertionInfo, const ErrorLocation &loc, const ch
317
317
os_clipboard::copy_to_clipboard (assertionInfo);
318
318
}
319
319
320
- void xrDebug::Fatal (const ErrorLocation & loc, const char * format, ...)
320
+ void xrDebug::Fatal (const ErrorLocation& loc, const char * format, ...)
321
321
{
322
322
string1024 desc;
323
323
va_list args;
@@ -328,14 +328,14 @@ void xrDebug::Fatal(const ErrorLocation &loc, const char *format, ...)
328
328
Fail (ignoreAlways, loc, nullptr , " fatal error" , desc);
329
329
}
330
330
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)
333
333
{
334
334
Fail (ignoreAlways, loc, expr, xrDebug::ErrorToString (hresult), arg1, arg2);
335
335
}
336
336
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)
339
339
{
340
340
#ifdef PROFILE_CRITICAL_SECTIONS
341
341
static Lock lock (MUTEX_PROFILE_ID (xrDebug::Backend));
@@ -348,11 +348,11 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
348
348
GatherInfo (assertionInfo, loc, expr, desc, arg1, arg2);
349
349
#ifdef USE_OWN_ERROR_MESSAGE_WINDOW
350
350
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 " );
356
356
#endif
357
357
if (OnCrash)
358
358
OnCrash ();
@@ -364,7 +364,8 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
364
364
else
365
365
{
366
366
#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);
368
369
switch (result)
369
370
{
370
371
case IDCANCEL:
@@ -373,7 +374,8 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
373
374
#endif
374
375
DEBUG_BREAK;
375
376
break ;
376
- case IDTRYAGAIN: ErrorAfterDialog = false ; break ;
377
+ case IDTRYAGAIN: ErrorAfterDialog = false ;
378
+ break ;
377
379
case IDCONTINUE:
378
380
ErrorAfterDialog = false ;
379
381
ignoreAlways = true ;
@@ -392,13 +394,13 @@ void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *exp
392
394
lock.Leave ();
393
395
}
394
396
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)
397
399
{
398
400
Fail (ignoreAlways, loc, expr, desc.c_str (), arg1, arg2);
399
401
}
400
402
401
- void xrDebug::DoExit (const std::string & message)
403
+ void xrDebug::DoExit (const std::string& message)
402
404
{
403
405
FlushLog ();
404
406
MessageBox (NULL , message.c_str (), " Error" , MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
@@ -407,7 +409,7 @@ void xrDebug::DoExit(const std::string &message)
407
409
408
410
LPCSTR xrDebug::ErrorToString (long code)
409
411
{
410
- const char * result = nullptr ;
412
+ const char * result = nullptr ;
411
413
static string1024 descStorage;
412
414
DXGetErrorDescription (code, descStorage, sizeof (descStorage));
413
415
if (!result)
@@ -475,7 +477,7 @@ void WINAPI xrDebug::PreErrorHandler(INT_PTR)
475
477
BT_SaveSnapshot (nullptr );
476
478
}
477
479
478
- void xrDebug::SetupExceptionHandler (const bool & dedicated)
480
+ void xrDebug::SetupExceptionHandler (const bool & dedicated)
479
481
{
480
482
// disable 'appname has stopped working' popup dialog
481
483
UINT prevMode = SetErrorMode (SEM_NOGPFAULTERRORBOX);
@@ -486,11 +488,11 @@ void xrDebug::SetupExceptionHandler(const bool &dedicated)
486
488
else
487
489
BT_SetActivityType (BTA_SAVEREPORT);
488
490
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." );
494
496
BT_SetPreErrHandler (PreErrorHandler, 0 );
495
497
BT_SetAppName (" X-Ray Engine" );
496
498
BT_SetReportFormat (BTRF_TEXT);
@@ -536,23 +538,23 @@ void xrDebug::SaveMiniDump(EXCEPTION_POINTERS *exPtrs)
536
538
}
537
539
#endif
538
540
539
- void xrDebug::FormatLastError (char * buffer, const size_t & bufferSize)
541
+ void xrDebug::FormatLastError (char * buffer, const size_t & bufferSize)
540
542
{
541
543
int lastErr = GetLastError ();
542
544
if (lastErr == ERROR_SUCCESS)
543
545
{
544
546
*buffer = 0 ;
545
547
return ;
546
548
}
547
- void * msg = nullptr ;
549
+ void * msg = nullptr ;
548
550
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 );
550
552
// XXX nitrocaster: check buffer overflow
551
553
sprintf (buffer, " [error][%8d]: %s" , lastErr, (char *)msg);
552
554
LocalFree (msg);
553
555
}
554
556
555
- LONG WINAPI xrDebug::UnhandledFilter (EXCEPTION_POINTERS * exPtrs)
557
+ LONG WINAPI xrDebug::UnhandledFilter (EXCEPTION_POINTERS* exPtrs)
556
558
{
557
559
string256 errMsg;
558
560
FormatLastError (errMsg, sizeof (errMsg));
@@ -599,9 +601,9 @@ LONG WINAPI xrDebug::UnhandledFilter(EXCEPTION_POINTERS *exPtrs)
599
601
if (OnDialog)
600
602
OnDialog (true );
601
603
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);
605
607
}
606
608
#endif
607
609
ReportFault (exPtrs, 0 );
@@ -627,14 +629,14 @@ void _terminate()
627
629
}
628
630
#endif // USE_BUG_TRAP
629
631
630
- static void handler_base (const char * reason)
632
+ static void handler_base (const char * reason)
631
633
{
632
634
bool ignoreAlways = false ;
633
635
xrDebug::Fail (ignoreAlways, DEBUG_INFO, nullptr , reason, nullptr , nullptr );
634
636
}
635
637
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)
638
640
{
639
641
bool ignoreAlways = false ;
640
642
string4096 mbExpression;
@@ -668,6 +670,7 @@ static void abort_handler(int signal) { handler_base("application is aborting");
668
670
static void floating_point_handler (int signal) { handler_base (" floating point error" ); }
669
671
static void illegal_instruction_handler (int signal) { handler_base (" illegal instruction" ); }
670
672
static void termination_handler (int signal) { handler_base (" termination with exit code 3" ); }
673
+
671
674
void xrDebug::OnThreadSpawn ()
672
675
{
673
676
#ifdef USE_BUG_TRAP
@@ -691,7 +694,7 @@ void xrDebug::OnThreadSpawn()
691
694
#endif
692
695
}
693
696
694
- void xrDebug::Initialize (const bool & dedicated)
697
+ void xrDebug::Initialize (const bool & dedicated)
695
698
{
696
699
*BugReportFile = 0 ;
697
700
OnThreadSpawn ();
0 commit comments