@@ -282,62 +282,8 @@ static bool InvokeClientHandleExceptionSafe(CClientBase* pClient, CExceptionInfo
282282
283283namespace
284284{
285- void ConfigureDbgHelpOptions ()
286- {
287- static std::atomic_flag configured = ATOMIC_FLAG_INIT;
288- if (!configured.test_and_set (std::memory_order_acq_rel))
289- {
290- SymSetOptions (SYMOPT_LOAD_LINES | SYMOPT_UNDNAME | SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_DEFERRED_LOADS);
291- }
292- }
293-
294- std::mutex& GetSymInitMutex ()
295- {
296- static std::mutex symMutex;
297- return symMutex;
298- }
299285} // namespace
300286
301- class SymbolHandlerGuard
302- {
303- public:
304- explicit SymbolHandlerGuard (HANDLE process, bool enableSymbols) : m_process(process), m_initialized(false )
305- {
306- if (!enableSymbols)
307- return ;
308-
309- if (m_process != nullptr )
310- {
311- std::lock_guard<std::mutex> lock{GetSymInitMutex ()};
312-
313- ConfigureDbgHelpOptions ();
314-
315- const SString& processDir = SharedUtil::GetMTAProcessBaseDir ();
316- const char * searchPath = processDir.empty () ? nullptr : processDir.c_str ();
317-
318- if (SymInitialize (m_process, searchPath, TRUE ) != FALSE )
319- m_initialized = true ;
320- }
321- }
322-
323- ~SymbolHandlerGuard ()
324- {
325- if (m_initialized)
326- SymCleanup (m_process);
327- }
328-
329- SymbolHandlerGuard (const SymbolHandlerGuard&) = delete ;
330- SymbolHandlerGuard& operator =(const SymbolHandlerGuard&) = delete ;
331- SymbolHandlerGuard (SymbolHandlerGuard&&) = delete ;
332- SymbolHandlerGuard& operator =(SymbolHandlerGuard&&) = delete ;
333-
334- bool IsInitialized () const { return m_initialized; }
335-
336- private:
337- HANDLE m_process;
338- bool m_initialized;
339- };
340-
341287[[nodiscard]] static bool NormalizePathForValidation (const SString& inputPath, SString& outputPath)
342288{
343289 if (inputPath.empty ())
@@ -767,9 +713,11 @@ static void AppendCrashDiagnostics(const SString& text)
767713 frame.AddrFrame .Mode = AddrModeFlat;
768714 frame.AddrStack .Mode = AddrModeFlat;
769715
770- SymbolHandlerGuard symbolGuard (hProcess, hasSymbols);
771-
772- const bool useDbgHelp = symbolGuard.IsInitialized ();
716+ bool useDbgHelp = false ;
717+ if (hasSymbols)
718+ {
719+ useDbgHelp = CrashHandler::InitializeSymbolHandler ();
720+ }
773721 const auto routines = useDbgHelp ? StackTraceHelpers::MakeStackWalkRoutines (true ) : StackTraceHelpers::MakeStackWalkRoutines (false );
774722
775723 static_assert (MAX_SYM_NAME > 1 , " MAX_SYM_NAME must include room for a terminator" );
@@ -1475,19 +1423,6 @@ long WINAPI CCrashDumpWriter::HandleExceptionGlobal(_EXCEPTION_POINTERS* pExcept
14751423 return EXCEPTION_EXECUTE_HANDLER;
14761424 }
14771425
1478- if (IsFatalException (exceptionCode) == FALSE )
1479- {
1480- std::array<char , DEBUG_BUFFER_SIZE> szDebug;
1481- SAFE_DEBUG_PRINT_C (szDebug.data (), szDebug.size (), " CCrashDumpWriter: Non-fatal exception 0x%08X - ignoring\n " , exceptionCode);
1482- return EXCEPTION_CONTINUE_SEARCH;
1483- }
1484-
1485- const BOOL exceptionLogged = LogExceptionDetails (pException);
1486- if (exceptionLogged == FALSE )
1487- {
1488- SAFE_DEBUG_OUTPUT (" CCrashDumpWriter: WARNING - LogExceptionDetails failed\n " );
1489- }
1490-
14911426 SAFE_DEBUG_OUTPUT (" CCrashDumpWriter: ======================================\n " );
14921427 SAFE_DEBUG_OUTPUT (" CCrashDumpWriter: FATAL EXCEPTION - Begin crash processing\n " );
14931428 SAFE_DEBUG_OUTPUT (" CCrashDumpWriter: ======================================\n " );
@@ -1557,6 +1492,7 @@ long WINAPI CCrashDumpWriter::HandleExceptionGlobal(_EXCEPTION_POINTERS* pExcept
15571492 {
15581493 SAFE_DEBUG_OUTPUT (" CCrashDumpWriter: Client handled exception - continuing execution\n " );
15591494 delete pExceptionInformation;
1495+ ms_bInCrashHandler.store (false , std::memory_order_release);
15601496 return EXCEPTION_CONTINUE_SEARCH;
15611497 }
15621498
0 commit comments