Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <windows.h>
  8. #include <dbghelp.h>
  9. #include "tier0/minidump.h"
  10. #include "tools_minidump.h"
  11. static bool g_bToolsWriteFullMinidumps = false;
  12. static ToolsExceptionHandler g_pCustomExceptionHandler = NULL;
  13. // --------------------------------------------------------------------------------- //
  14. // Internal helpers.
  15. // --------------------------------------------------------------------------------- //
  16. static LONG __stdcall ToolsExceptionFilter( struct _EXCEPTION_POINTERS *ExceptionInfo )
  17. {
  18. // Non VMPI workers write a minidump and show a crash dialog like normal.
  19. int iType = MiniDumpNormal;
  20. if ( g_bToolsWriteFullMinidumps )
  21. iType = MiniDumpWithDataSegs | MiniDumpWithIndirectlyReferencedMemory;
  22. WriteMiniDumpUsingExceptionInfo( ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo, (MINIDUMP_TYPE)iType );
  23. return EXCEPTION_CONTINUE_SEARCH;
  24. }
  25. static LONG __stdcall ToolsExceptionFilter_Custom( struct _EXCEPTION_POINTERS *ExceptionInfo )
  26. {
  27. // Run their custom handler.
  28. g_pCustomExceptionHandler( ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo );
  29. return EXCEPTION_EXECUTE_HANDLER; // (never gets here anyway)
  30. }
  31. // --------------------------------------------------------------------------------- //
  32. // Interface functions.
  33. // --------------------------------------------------------------------------------- //
  34. void EnableFullMinidumps( bool bFull )
  35. {
  36. g_bToolsWriteFullMinidumps = bFull;
  37. }
  38. void SetupDefaultToolsMinidumpHandler()
  39. {
  40. SetUnhandledExceptionFilter( ToolsExceptionFilter );
  41. }
  42. void SetupToolsMinidumpHandler( ToolsExceptionHandler fn )
  43. {
  44. g_pCustomExceptionHandler = fn;
  45. SetUnhandledExceptionFilter( ToolsExceptionFilter_Custom );
  46. }