Skip to content
Permalink
Browse files

Crashhandler allthreads (#6013)

* [CrashHandler] Suspend all threads on crash
  • Loading branch information
NathanW2 committed Jan 8, 2018
1 parent 25770c4 commit 39d4d9abacf3dbc19b6cd4a5698461af0d67d21e
Showing with 34 additions and 3 deletions.
  1. +6 −2 src/crashhandler/main.cpp
  2. +27 −1 src/crashhandler/qgsstacktrace.cpp
  3. +1 −0 src/crashhandler/qgsstacktrace.h
@@ -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.

0 comments on commit 39d4d9a

Please sign in to comment.
You can’t perform that action at this time.