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.

104 lines
4.5 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. // Replaces the current function pointer with the one passed in.
  42. // Returns the previously-set function.
  43. // The function is called internally by WriteMiniDump() and CatchAndWriteMiniDump()
  44. // The default is the built-in function that uses DbgHlp.dll's MiniDumpWriteDump function
  45. typedef void (*FnMiniDump)( unsigned int uStructuredExceptionCode, _EXCEPTION_POINTERS * pExceptionInfo, const char *pszFilenameSuffix );
  46. PLATFORM_INTERFACE FnMiniDump SetMiniDumpFunction( FnMiniDump pfn );
  47. // Use this to write a minidump explicitly.
  48. // Some of the tools choose to catch the minidump themselves instead of using CatchAndWriteMinidump
  49. // so they can show their own dialog.
  50. //
  51. // ptchMinidumpFileNameBuffer if not-NULL should be a writable tchar buffer of length at
  52. // least _MAX_PATH and on return will contain the name of the minidump file written.
  53. // If ptchMinidumpFileNameBuffer is NULL the name of the minidump file written will not
  54. // be available after the function returns.
  55. //
  56. PLATFORM_INTERFACE bool WriteMiniDumpUsingExceptionInfo(
  57. unsigned int uStructuredExceptionCode,
  58. _EXCEPTION_POINTERS * pExceptionInfo,
  59. int /* MINIDUMP_TYPE */ minidumpType,
  60. const char *pszFilenameSuffix = NULL,
  61. tchar *ptchMinidumpFileNameBuffer = NULL
  62. );
  63. // Call this to enable a handler for unhandled exceptions.
  64. PLATFORM_INTERFACE void MinidumpSetUnhandledExceptionFunction( FnMiniDump pfn );
  65. // Call this to prevent crashes in kernel callbacks such as window procs from
  66. // being silently swallowed. We should always call this at startup.
  67. PLATFORM_INTERFACE void EnableCrashingOnCrashes();
  68. #endif // defined(_WIN32) && !defined(_X360)
  69. //
  70. // Minidump User Stream Info Comments.
  71. //
  72. // There currently is a single header string, and an array of 64 comment strings.
  73. // MinidumpUserStreamInfoSetHeader() will set the single header string.
  74. // MinidumpUserStreamInfoAppend() will round robin through and array and set the comment strings, overwriting old.
  75. PLATFORM_INTERFACE void MinidumpUserStreamInfoSetHeader( const char *pFormat, ... );
  76. PLATFORM_INTERFACE void MinidumpUserStreamInfoAppend( const char *pFormat, ... );
  77. // Retrieve the StreamInfo strings.
  78. // Index 0: header string
  79. // Index 1..: comment string
  80. // Returns NULL when you've reached the end of the comment string array
  81. // Empty strings ("\0") can be returned if comment hasn't been set
  82. PLATFORM_INTERFACE const char *MinidumpUserStreamInfoGet( int Index );
  83. #endif // MINIDUMP_H