MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / logWindowsException

Function logWindowsException

source/MRMesh/MRLogWindowsExceptions.cpp:23–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21int numMoreStacktraces = 5;
22
23LONG WINAPI logWindowsException( LPEXCEPTION_POINTERS pExInfo )
24{
25 thread_local bool logging = false;
26 if ( logging )
27 return EXCEPTION_CONTINUE_SEARCH; //avoid recursive logging
28
29 if ( !pExInfo )
30 return EXCEPTION_CONTINUE_SEARCH;
31 PEXCEPTION_RECORD pExceptionRecord = pExInfo->ExceptionRecord;
32
33 if ( pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT ||
34 pExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP ||
35 pExceptionRecord->ExceptionCode == RPC_UNAVAILABLE ||
36 pExceptionRecord->ExceptionCode == EXCEPTION_CXX ||
37 pExceptionRecord->ExceptionCode == MS_VC_EXCEPTION )
38 return EXCEPTION_CONTINUE_SEARCH; //normal situation, handled otherwise
39
40 logging = true;
41 if ( pExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && pExceptionRecord->NumberParameters >= 2 )
42 {
43 // https://stackoverflow.com/a/22850748/7325599
44 auto type = []( ULONG64 v )
45 {
46 if ( v == 0 )
47 return "reading";
48 if ( v == 1 )
49 return "writing";
50 if ( v == 8 )
51 return "DEP";
52 return "???";
53 };
54 spdlog::critical( "Access violation: {} at {:#010x}",
55 type( pExceptionRecord->ExceptionInformation[0] ),
56 pExceptionRecord->ExceptionInformation[1] );
57 }
58 else if ( pExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C && pExceptionRecord->NumberParameters >= 2 )
59 {
60 // https://stackoverflow.com/a/41480827/7325599
61 auto len = pExceptionRecord->ExceptionInformation[0];
62 if ( len )
63 --len;
64 const auto * p = (PCSTR)pExceptionRecord->ExceptionInformation[1];
65 spdlog::info( "Narrow debug information: {}", std::string_view( p, len ) );
66 }
67 else if ( pExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_WIDE_C && pExceptionRecord->NumberParameters >= 2 )
68 {
69 // https://stackoverflow.com/a/41480827/7325599
70 auto len = pExceptionRecord->ExceptionInformation[0];
71 if ( len )
72 --len;
73 const auto * p = (PCWSTR)pExceptionRecord->ExceptionInformation[1];
74 spdlog::info( "Wide debug information: {}", Utf16ToUtf8( std::wstring_view( p, len ) ) );
75 }
76 else
77 spdlog::warn( "Windows exception {:#010x}", pExceptionRecord->ExceptionCode );
78
79 if ( numMoreStacktraces > 0 )
80 {

Callers

nothing calls this directly

Calls 4

typeFunction · 0.85
Utf16ToUtf8Function · 0.85
getCurrentStacktraceFunction · 0.85
printCurrentTimerBranchFunction · 0.85

Tested by

no test coverage detected