Changeset 28 for trunk/src/shared/WheatyExceptionReport.cpp
- Timestamp:
- 11/19/08 13:24:39 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shared/WheatyExceptionReport.cpp
r2 r28 9 9 #pragma warning(disable:4311) 10 10 #include <windows.h> 11 #include <tlhelp32.h> 11 12 #include <stdio.h> 12 13 #include <tchar.h> … … 328 329 329 330 //=========================================================================== 331 void WheatyExceptionReport::printTracesForAllThreads() 332 { 333 HANDLE hThreadSnap = INVALID_HANDLE_VALUE; 334 THREADENTRY32 te32; 335 336 DWORD dwOwnerPID = GetCurrentProcessId(); 337 m_hProcess = GetCurrentProcess(); 338 // Take a snapshot of all running threads 339 hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); 340 if( hThreadSnap == INVALID_HANDLE_VALUE ) 341 return; 342 343 // Fill in the size of the structure before using it. 344 te32.dwSize = sizeof(THREADENTRY32 ); 345 346 // Retrieve information about the first thread, 347 // and exit if unsuccessful 348 if( !Thread32First( hThreadSnap, &te32 ) ) 349 { 350 CloseHandle( hThreadSnap ); // Must clean up the 351 // snapshot object! 352 return; 353 } 354 355 // Now walk the thread list of the system, 356 // and display information about each thread 357 // associated with the specified process 358 do 359 { 360 if( te32.th32OwnerProcessID == dwOwnerPID ) 361 { 362 CONTEXT context; 363 context.ContextFlags = 0xffffffff; 364 HANDLE threadHandle = OpenThread(THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION,false, te32.th32ThreadID); 365 if(threadHandle && GetThreadContext(threadHandle, &context)) 366 { 367 WriteStackDetails( &context, false, threadHandle ); 368 } 369 CloseHandle(threadHandle); 370 } 371 } while( Thread32Next(hThreadSnap, &te32 ) ); 372 373 // Don't forget to clean up the snapshot object. 374 CloseHandle( hThreadSnap ); 375 } 376 377 378 //=========================================================================== 330 379 // Open the report file, and write the desired information to it. Called by 331 380 // WheatyUnhandledExceptionFilter … … 412 461 CONTEXT trashableContext = *pCtx; 413 462 414 WriteStackDetails( &trashableContext, false ); 463 WriteStackDetails( &trashableContext, false, NULL ); 464 printTracesForAllThreads(); 415 465 416 466 // #ifdef _M_IX86 // X86 Only! … … 420 470 421 471 trashableContext = *pCtx; 422 WriteStackDetails( &trashableContext, true );472 WriteStackDetails( &trashableContext, true, NULL ); 423 473 424 474 _tprintf( _T("========================\r\n") ); … … 552 602 void WheatyExceptionReport::WriteStackDetails( 553 603 PCONTEXT pContext, 554 bool bWriteVariables 604 bool bWriteVariables, HANDLE pThreadHandle) // true if local/params should be output 555 605 { 556 606 _tprintf( _T("\r\nCall stack:\r\n") ); … … 592 642 if ( ! StackWalk64( dwMachineType, 593 643 m_hProcess, 594 GetCurrentThread(),644 pThreadHandle != NULL ? pThreadHandle : GetCurrentThread(), 595 645 &sf, 596 646 pContext,