KSCrashMonitorContext.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // KSCrashMonitorContext.h
  3. //
  4. // Created by Karl Stenerud on 2012-02-12.
  5. //
  6. // Copyright (c) 2012 Karl Stenerud. All rights reserved.
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall remain in place
  16. // in this source code.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. //
  26. #ifndef HDR_KSCrashMonitorContext_h
  27. #define HDR_KSCrashMonitorContext_h
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "KSCrashMonitorType.h"
  32. #include "KSMachineContext.h"
  33. #include <stdbool.h>
  34. #include <stdint.h>
  35. typedef struct KSCrash_MonitorContext
  36. {
  37. /** Unique identifier for this event. */
  38. const char* eventID;
  39. /**
  40. If true, so reported user exception will have the current snapshot.
  41. */
  42. bool currentSnapshotUserReported;
  43. /** If true, the environment has crashed hard, and only async-safe
  44. * functions should be used.
  45. */
  46. bool requiresAsyncSafety;
  47. /** If true, the crash handling system is currently handling a crash.
  48. * When false, all values below this field are considered invalid.
  49. */
  50. bool handlingCrash;
  51. /** If true, a second crash occurred while handling a crash. */
  52. bool crashedDuringCrashHandling;
  53. /** If true, the registers contain valid information about the crash. */
  54. bool registersAreValid;
  55. /** True if the crash system has detected a stack overflow. */
  56. bool isStackOverflow;
  57. /** The machine context that generated the event. */
  58. struct KSMachineContext* offendingMachineContext;
  59. /** Address that caused the fault. */
  60. uintptr_t faultAddress;
  61. /** The type of crash that occurred.
  62. * This determines which other fields are valid. */
  63. KSCrashMonitorType crashType;
  64. /** The name of the exception that caused the crash, if any. */
  65. const char* exceptionName;
  66. /** Short description of why the crash occurred. */
  67. const char* crashReason;
  68. /** The stack cursor for the trace leading up to the crash.
  69. * Note: Actual type is KSStackCursor*
  70. */
  71. void* stackCursor;
  72. struct
  73. {
  74. /** The mach exception type. */
  75. int type;
  76. /** The mach exception code. */
  77. int64_t code;
  78. /** The mach exception subcode. */
  79. int64_t subcode;
  80. } mach;
  81. struct
  82. {
  83. /** The exception name. */
  84. const char* name;
  85. /** The exception userInfo. */
  86. const char* userInfo;
  87. } NSException;
  88. struct
  89. {
  90. /** The exception name. */
  91. const char* name;
  92. } CPPException;
  93. struct
  94. {
  95. /** User context information. */
  96. const void* userContext;
  97. int signum;
  98. int sigcode;
  99. } signal;
  100. struct
  101. {
  102. /** The exception name. */
  103. const char* name;
  104. /** The language the exception occured in. */
  105. const char* language;
  106. /** The line of code where the exception occurred. Can be NULL. */
  107. const char* lineOfCode;
  108. /** The user-supplied JSON encoded stack trace. */
  109. const char* customStackTrace;
  110. } userException;
  111. struct
  112. {
  113. /** Total active time elapsed since the last crash. */
  114. double activeDurationSinceLastCrash;
  115. /** Total time backgrounded elapsed since the last crash. */
  116. double backgroundDurationSinceLastCrash;
  117. /** Number of app launches since the last crash. */
  118. int launchesSinceLastCrash;
  119. /** Number of sessions (launch, resume from suspend) since last crash. */
  120. int sessionsSinceLastCrash;
  121. /** Total active time elapsed since launch. */
  122. double activeDurationSinceLaunch;
  123. /** Total time backgrounded elapsed since launch. */
  124. double backgroundDurationSinceLaunch;
  125. /** Number of sessions (launch, resume from suspend) since app launch. */
  126. int sessionsSinceLaunch;
  127. /** If true, the application crashed on the previous launch. */
  128. bool crashedLastLaunch;
  129. /** If true, the application crashed on this launch. */
  130. bool crashedThisLaunch;
  131. /** Timestamp for when the app state was last changed (active<->inactive,
  132. * background<->foreground) */
  133. double appStateTransitionTime;
  134. /** If true, the application is currently active. */
  135. bool applicationIsActive;
  136. /** If true, the application is currently in the foreground. */
  137. bool applicationIsInForeground;
  138. } AppState;
  139. /* Misc system information */
  140. struct
  141. {
  142. const char* systemName;
  143. const char* systemVersion;
  144. const char* machine;
  145. const char* model;
  146. const char* kernelVersion;
  147. const char* osVersion;
  148. bool isJailbroken;
  149. const char* bootTime;
  150. const char* appStartTime;
  151. const char* executablePath;
  152. const char* executableName;
  153. const char* bundleID;
  154. const char* bundleName;
  155. const char* bundleVersion;
  156. const char* bundleShortVersion;
  157. const char* appID;
  158. const char* cpuArchitecture;
  159. int cpuType;
  160. int cpuSubType;
  161. int binaryCPUType;
  162. int binaryCPUSubType;
  163. const char* timezone;
  164. const char* processName;
  165. int processID;
  166. int parentProcessID;
  167. const char* deviceAppHash;
  168. const char* buildType;
  169. uint64_t storageSize;
  170. uint64_t memorySize;
  171. uint64_t freeMemory;
  172. uint64_t usableMemory;
  173. } System;
  174. struct
  175. {
  176. /** Address of the last deallocated exception. */
  177. uintptr_t address;
  178. /** Name of the last deallocated exception. */
  179. const char* name;
  180. /** Reason field from the last deallocated exception. */
  181. const char* reason;
  182. } ZombieException;
  183. /** Full path to the console log, if any. */
  184. const char* consoleLogPath;
  185. } KSCrash_MonitorContext;
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif // HDR_KSCrashMonitorContext_h