Counter Strike : Global Offensive Source Code
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.

109 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef MINIDUMP_H
  7. #define MINIDUMP_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/platform.h"
  12. // Set prefix to use for minidump files. If you don't set one, it is defaulted for you,
  13. // using the current module name
  14. PLATFORM_INTERFACE void SetMinidumpFilenamePrefix( const char *pszPrefix );
  15. // Set comment to put into minidump file upon next call of WriteMiniDump. (Most common use is the assert text.)
  16. PLATFORM_INTERFACE void SetMinidumpComment( const char *pszComment );
  17. // writes out a minidump of the current stack trace with a unique filename
  18. PLATFORM_INTERFACE void WriteMiniDump( const char *pszFilenameSuffix = NULL );
  19. typedef void( *FnWMain )(int, tchar *[]);
  20. typedef void( *FnVoidPtrFn )(void *);
  21. #if defined(_WIN32) && !defined(_X360)
  22. // calls the passed in function pointer and catches any exceptions/crashes thrown by it, and writes a minidump
  23. // use from wmain() to protect the whole program
  24. typedef void( *FnWMain )(int, tchar *[]);
  25. typedef int( *FnWMainIntRet )(int, tchar *[]);
  26. typedef void( *FnVoidPtrFn )(void *);
  27. enum ECatchAndWriteMinidumpAction
  28. {
  29. k_ECatchAndWriteMiniDumpAbort = 0,
  30. k_ECatchAndWriteMiniDumpReThrow = 1,
  31. k_ECatchAndWriteMiniDumpIgnore = 2,
  32. };
  33. PLATFORM_INTERFACE void CatchAndWriteMiniDump( FnWMain pfn, int argc, tchar *argv[] ); // action = Abort
  34. PLATFORM_INTERFACE void CatchAndWriteMiniDumpForVoidPtrFn( FnVoidPtrFn pfn, void *pv, bool bExitQuietly ); // action = abort if bExitQuietly, Rethrow otherwise
  35. PLATFORM_INTERFACE void CatchAndWriteMiniDumpEx( FnWMain pfn, int argc, tchar *argv[], ECatchAndWriteMinidumpAction eAction );
  36. PLATFORM_INTERFACE int CatchAndWriteMiniDumpExReturnsInt( FnWMainIntRet pfn, int argc, tchar *argv[], ECatchAndWriteMinidumpAction eAction );
  37. PLATFORM_INTERFACE void CatchAndWriteMiniDumpExForVoidPtrFn( FnVoidPtrFn pfn, void *pv, ECatchAndWriteMinidumpAction eAction );
  38. // Let's not include this. We'll use forwards instead.
  39. //#include <dbghelp.h>
  40. struct _EXCEPTION_POINTERS;
  41. typedef _EXCEPTION_POINTERS ExceptionInfo_t;
  42. // Replaces the current function pointer with the one passed in.
  43. // Returns the previously-set function.
  44. // The function is called internally by WriteMiniDump() and CatchAndWriteMiniDump()
  45. // The default is the built-in function that uses DbgHlp.dll's MiniDumpWriteDump function
  46. typedef void( *FnMiniDump )(unsigned int uStructuredExceptionCode, _EXCEPTION_POINTERS * pExceptionInfo, const char *pszFilenameSuffix);
  47. PLATFORM_INTERFACE FnMiniDump SetMiniDumpFunction( FnMiniDump pfn );
  48. // Use this to write a minidump explicitly.
  49. // Some of the tools choose to catch the minidump themselves instead of using CatchAndWriteMinidump
  50. // so they can show their own dialog.
  51. //
  52. // ptchMinidumpFileNameBuffer if not-NULL should be a writable tchar buffer of length at
  53. // least _MAX_PATH and on return will contain the name of the minidump file written.
  54. // If ptchMinidumpFileNameBuffer is NULL the name of the minidump file written will not
  55. // be available after the function returns.
  56. //
  57. // NOTE: Matches windows.h
  58. enum MinidumpType_t
  59. {
  60. MINIDUMP_Normal = 0x00000000,
  61. MINIDUMP_WithDataSegs = 0x00000001,
  62. MINIDUMP_WithFullMemory = 0x00000002,
  63. MINIDUMP_WithHandleData = 0x00000004,
  64. MINIDUMP_FilterMemory = 0x00000008,
  65. MINIDUMP_ScanMemory = 0x00000010,
  66. MINIDUMP_WithUnloadedModules = 0x00000020,
  67. MINIDUMP_WithIndirectlyReferencedMemory = 0x00000040,
  68. MINIDUMP_FilterModulePaths = 0x00000080,
  69. MINIDUMP_WithProcessThreadData = 0x00000100,
  70. MINIDUMP_WithPrivateReadWriteMemory = 0x00000200,
  71. MINIDUMP_WithoutOptionalData = 0x00000400,
  72. MINIDUMP_WithFullMemoryInfo = 0x00000800,
  73. MINIDUMP_WithThreadInfo = 0x00001000,
  74. MINIDUMP_WithCodeSegs = 0x00002000
  75. };
  76. PLATFORM_INTERFACE bool WriteMiniDumpUsingExceptionInfo(
  77. unsigned int uStructuredExceptionCode,
  78. _EXCEPTION_POINTERS * pExceptionInfo,
  79. int /* MINIDUMP_TYPE */ minidumpType,
  80. const char *pszFilenameSuffix = NULL,
  81. tchar *ptchMinidumpFileNameBuffer = NULL
  82. );
  83. // Call this to enable a handler for unhandled exceptions.
  84. PLATFORM_INTERFACE void MinidumpSetUnhandledExceptionFunction( FnMiniDump pfn );
  85. // Call this to prevent crashes in kernel callbacks such as window procs from
  86. // being silently swallowed. We should always call this at startup.
  87. PLATFORM_INTERFACE void EnableCrashingOnCrashes();
  88. #endif
  89. #endif // MINIDUMP_H