CrashReporter.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #ifndef __CRASH_REPORTER_H
  11. #define __CRASH_REPORTER_H
  12. // This is a crash reporter that will send a minidump by email on unhandled exceptions
  13. // This normally only runs if you are not currently debugging.
  14. // To send reports while debugging (mostly to test this class), define _DEBUG_CRASH_REPORTER
  15. // and put your code in a try/except block such as
  16. //
  17. // extern void DumpMiniDump(PEXCEPTION_POINTERS excpInfo);
  18. //
  19. // void main(void)
  20. //{
  21. //__try
  22. //{
  23. // RunGame();
  24. //}
  25. //__except(DumpMiniDump(GetExceptionInformation()),EXCEPTION_EXECUTE_HANDLER)
  26. //{
  27. //}
  28. //}
  29. // The minidump can be opened in visual studio and will show you where the crash occurred and give you the local variable values.
  30. //
  31. // How to use the minidump:
  32. //
  33. // Put the minidump on your harddrive and double click it. It will open Visual Studio. It will look for the exe that caused the crash in the directory
  34. // that the program that crashed was running at. If it can't find this exe, or if it is different, it will look in the current
  35. // directory for that exe. If it still can't find it, or if it is different, it will load Visual Studio and indicate that it can't find
  36. // the executable module. No source code will be shown at that point. However, you can specify modpath=<pathToExeDirectory> in the
  37. // project properties window for "Command Arguments".
  38. // The best solution is copy the .dmp to a directory containing a copy of the exe that crashed.
  39. //
  40. // On load, Visual Studio will look for the .pdb, which it uses to find the source code files and other information. This is fine as long as the source
  41. // code files on your harddrive match those that were used to create the exe. If they don't, you will see source code but it will be the wrong code.
  42. // There are three ways to deal with this.
  43. //
  44. // The first way is to change the path to your source code so it won't find the wrong code automatically.
  45. // This will cause the debugger to not find the source code pointed to in the .pdb . You will be prompted for the location of the correct source code.
  46. //
  47. // The second way is to build the exe on a different path than what you normally program with. For example, when you program you use c:/Working/Mygame
  48. // When you release builds, you do at c:/Version2.2/Mygame . After a build, you keep the source files, the exe, and the pdb
  49. // on a harddrive at that location. When you get a crash .dmp, copy it to the same directory as the exe, ( c:/Version2.2/Mygame/bin )
  50. // This way the .pdb will point to the correct sources to begin wtih.
  51. //
  52. // The third way is save build labels or branches in source control and get that version (you only need source code + .exe + .pdb) before debugging.
  53. // After debugging, restore your previous work.
  54. //
  55. // To use:
  56. // #include "DbgHelp.h"
  57. // Link with Dbghelp.lib ws2_32.lib
  58. namespace RakNet {
  59. // Possible actions to take on a crash. If you want to restart the app as well, see the CrashRelauncher sample.
  60. enum CrashReportAction
  61. {
  62. // Send an email (mutually exclusive with AOC_EMAIL_WITH_ATTACHMENT)
  63. AOC_EMAIL_NO_ATTACHMENT=1,
  64. // Send an email and attach the minidump (mutually exclusive with AOC_EMAIL_NO_ATTACHMENT)
  65. AOC_EMAIL_WITH_ATTACHMENT=2,
  66. // Write the minidump to disk in a specified directory
  67. AOC_WRITE_TO_DISK=4,
  68. // In silent mode there are no prompts. This is useful for an unmonitored application.
  69. AOC_SILENT_MODE=8
  70. };
  71. /// Holds all the parameters to CrashReporter::Start
  72. struct CrashReportControls
  73. {
  74. // Bitwise OR of CrashReportAction values to determine what to do on a crash.
  75. int actionToTake;
  76. // Used to generate the dump filename. Required with AOC_EMAIL_WITH_ATTACHMENT or AOC_WRITE_TO_DISK
  77. char appName[128];
  78. char appVersion[128];
  79. // Used with AOC_WRITE_TO_DISK . Path to write to. Not the filename, just the path. Empty string means the current directory.
  80. char pathToMinidump[260];
  81. // Required with AOC_EMAIL_* & AOC_SILENT_MODE . The SMTP server to send emails from.
  82. char SMTPServer[128];
  83. // Required with AOC_EMAIL_* & AOC_SILENT_MODE . The account name to send emails with (probably your email address).
  84. char SMTPAccountName[64];
  85. // Required with AOC_EMAIL_* & AOC_SILENT_MODE . What to put in the sender field of the email.
  86. char emailSender[64];
  87. // Required with AOC_EMAIL_* . What to put in the subject of the email.
  88. char emailSubjectPrefix[128];
  89. // Required with AOC_EMAIL_* as long as you are NOT in AOC_SILENT_MODE . What to put in the body of the email.
  90. char emailBody[1024];
  91. // Required with AOC_EMAIL_* . Who to send the email to.
  92. char emailRecipient[64];
  93. // Required with AOC_EMAIL_* . What password to use to send the email under TLS, if required
  94. char emailPassword[64];
  95. // How much memory to write. MiniDumpNormal is the least but doesn't seem to give correct globals. MiniDumpWithDataSegs gives more.
  96. // Include "DbgHelp.h" for these enumerations.
  97. int minidumpType;
  98. };
  99. /// \brief On an unhandled exception, will save a minidump and email it.
  100. /// A minidump can be opened in visual studio to give the callstack and local variables at the time of the crash.
  101. /// It has the same amount of information as if you crashed while debugging in the relevant mode. So Debug tends to give
  102. /// accurate stacks and info while Release does not.
  103. ///
  104. /// Minidumps are only accurate for the code as it was compiled at the date of the release. So you should label releases in source control
  105. /// and put that label number in the 'appVersion' field.
  106. class CrashReporter
  107. {
  108. public:
  109. static void Start(CrashReportControls *input);
  110. static CrashReportControls controls;
  111. };
  112. } // namespace RakNet
  113. #endif
粤ICP备19079148号