Crashhandler allthreads (#6013)

* [CrashHandler] Suspend all threads on crash
This commit is contained in:
Nathan Woodrow 2018-01-09 09:23:17 +10:00 committed by GitHub
parent 25770c445c
commit 39d4d9abac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View File

@ -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;

View File

@ -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 );

View File

@ -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.