mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Crashhandler allthreads (#6013)
* [CrashHandler] Suspend all threads on crash
This commit is contained in:
parent
25770c445c
commit
39d4d9abac
@ -91,8 +91,12 @@ int main( int argc, char *argv[] )
|
||||
dlg.show();
|
||||
app.exec();
|
||||
|
||||
ResumeThread( stackTrace->thread );
|
||||
CloseHandle( stackTrace->thread );
|
||||
|
||||
for ( HANDLE threadHandle : stackTrace->threads )
|
||||
{
|
||||
ResumeThread( threadHandle );
|
||||
CloseHandle( threadHandle );
|
||||
}
|
||||
CloseHandle( stackTrace->process );
|
||||
|
||||
return 0;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
#include <Windows.h>
|
||||
#include <DbgHelp.h>
|
||||
@ -780,10 +781,35 @@ QgsStackTrace *QgsStackTrace::trace( DWORD processId, DWORD threadId, LPEXCEPTIO
|
||||
StackTrace *stackTrace = ( StackTrace * )calloc( sizeof( *stackTrace ), 1 );
|
||||
stackTrace->process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, processId );
|
||||
stackTrace->thread = OpenThread( THREAD_ALL_ACCESS, FALSE, threadId );
|
||||
SuspendThread( stackTrace->thread );
|
||||
trace->process = stackTrace->process;
|
||||
trace->thread = stackTrace->thread;
|
||||
|
||||
HANDLE h = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
|
||||
if ( h != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
THREADENTRY32 te;
|
||||
te.dwSize = sizeof( te );
|
||||
if ( Thread32First( h, &te ) )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( te.dwSize >= FIELD_OFFSET( THREADENTRY32, th32OwnerProcessID ) +
|
||||
sizeof( te.th32OwnerProcessID ) )
|
||||
{
|
||||
if ( te.th32OwnerProcessID == processId )
|
||||
{
|
||||
HANDLE threadHandle = OpenThread( THREAD_ALL_ACCESS, FALSE, te.th32ThreadID );
|
||||
trace->threads.push_back( threadHandle );
|
||||
SuspendThread( threadHandle );
|
||||
}
|
||||
}
|
||||
te.dwSize = sizeof( te );
|
||||
}
|
||||
while ( Thread32Next( h, &te ) );
|
||||
}
|
||||
CloseHandle( h );
|
||||
}
|
||||
|
||||
ReadProcessMemory( stackTrace->process, exception, &remoteException, sizeof( remoteException ), NULL );
|
||||
ReadProcessMemory( stackTrace->process, remoteException.ContextRecord, &remoteContextRecord, sizeof( remoteContextRecord ), NULL );
|
||||
|
||||
|
@ -71,6 +71,7 @@ class QgsStackTrace
|
||||
#ifdef _MSC_VER
|
||||
HANDLE process;
|
||||
HANDLE thread;
|
||||
std::vector<HANDLE> threads;
|
||||
|
||||
/**
|
||||
* Return a demangled stack backtrace of the caller function.
|
||||
|
Loading…
x
Reference in New Issue
Block a user