crash_event.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. from typing import Any, Collection, Dict, Mapping, Sequence
  2. IN_APP_FRAME = {
  3. "function": "LoginViewController.viewDidAppear",
  4. "raw_function": "LoginViewController.viewDidAppear(Bool)",
  5. "symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF",
  6. "package": "SentryApp",
  7. "filename": "LoginViewController.swift",
  8. "abs_path": "/Users/sentry/git/iOS/Sentry/LoggedOut/LoginViewController.swift",
  9. "lineno": 196,
  10. "in_app": True,
  11. "image_addr": "0x100260000",
  12. "instruction_addr": "0x102b16630",
  13. "symbol_addr": "0x100260000",
  14. }
  15. def get_sentry_frame(function: str, in_app: bool = False) -> Mapping[str, Any]:
  16. return {
  17. "function": function,
  18. "package": "Sentry",
  19. "in_app": in_app,
  20. "image_addr": "0x100304000",
  21. }
  22. def get_frames(function: str, sentry_frame_in_app: bool = False) -> Sequence[Mapping[str, Any]]:
  23. frames = [
  24. get_sentry_frame(function, sentry_frame_in_app),
  25. {
  26. "function": "LoginViewController.viewDidAppear",
  27. "symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF",
  28. "package": "/private/var/containers/Bundle/Application/D9118D4F-E47F-47D3-96A2-35E854245CB4/iOS-Swift.app/iOS-Swift",
  29. "in_app": True,
  30. "filename": "LoginViewController.swift",
  31. "image_addr": "0x100260000",
  32. },
  33. IN_APP_FRAME,
  34. {
  35. "function": "-[UIViewController _setViewAppearState:isAnimating:]",
  36. "symbol": "-[UIViewController _setViewAppearState:isAnimating:]",
  37. "package": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  38. "in_app": False,
  39. "image_addr": "0x1a4e8f000",
  40. },
  41. {
  42. "function": "-[UIViewController __viewDidAppear:]",
  43. "symbol": "-[UIViewController __viewDidAppear:]",
  44. "package": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  45. "in_app": False,
  46. "image_addr": "0x1a4e8f000",
  47. },
  48. {
  49. "function": "-[UIViewController _endAppearanceTransition:]",
  50. "symbol": "-[UIViewController _endAppearanceTransition:]",
  51. "package": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  52. "in_app": False,
  53. "image_addr": "0x1a4e8f000",
  54. },
  55. {
  56. "function": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
  57. "symbol": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
  58. "package": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  59. "in_app": False,
  60. "image_addr": "0x1a4e8f000",
  61. },
  62. {
  63. "function": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
  64. "symbol": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
  65. "package": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  66. "in_app": False,
  67. "image_addr": "0x1a4e8f000",
  68. },
  69. {
  70. "filename": "EventStripperTestFrame.swift",
  71. "function": "function",
  72. "raw_function": "raw_function",
  73. "module": "module",
  74. "abs_path": "abs_path",
  75. "in_app": False,
  76. "instruction_addr": "0x1a4e8f000",
  77. "addr_mode": "0x1a4e8f000",
  78. "symbol": "symbol",
  79. "symbol_addr": "0x1a4e8f000",
  80. "image_addr": "0x1a4e8f000",
  81. "package": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  82. "platform": "platform",
  83. "post_context": ["should_be_removed"],
  84. },
  85. ]
  86. # The frames have to be ordered from caller to callee, or oldest to youngest.
  87. # The last frame is the one creating the exception.
  88. # As we usually look at stacktraces from youngest to oldest, we reverse the order.
  89. return frames[::-1]
  90. def get_crash_event(handled=False, function="-[Sentry]", **kwargs) -> Dict[str, Collection[str]]:
  91. return get_crash_event_with_frames(get_frames(function), handled=handled, **kwargs)
  92. def get_crash_event_with_frames(
  93. frames: Sequence[Mapping[str, Any]], handled=False, **kwargs
  94. ) -> Dict[str, Collection[str]]:
  95. result = {
  96. "event_id": "80e3496eff734ab0ac993167aaa0d1cd",
  97. "release": "5.222.5",
  98. "type": "error",
  99. "level": "fatal",
  100. "platform": "cocoa",
  101. "tags": {"level": "fatal"},
  102. "exception": {
  103. "values": [
  104. {
  105. "stacktrace": {
  106. "frames": frames,
  107. },
  108. "type": "EXC_BAD_ACCESS",
  109. "value": "crash > crash: > objectAtIndex: >\nAttempted to dereference null pointer.",
  110. "mechanism": {
  111. "handled": handled,
  112. "type": "mach",
  113. "meta": {
  114. "signal": {
  115. "number": 11,
  116. "code": 0,
  117. "name": "SIGSEGV",
  118. "code_name": "SEGV_NOOP",
  119. },
  120. "mach_exception": {
  121. "exception": 1,
  122. "code": 1,
  123. "subcode": 0,
  124. "name": "EXC_BAD_ACCESS",
  125. },
  126. },
  127. },
  128. }
  129. ]
  130. },
  131. "breadcrumbs": {
  132. "values": [
  133. {
  134. "timestamp": 1675900265.0,
  135. "type": "debug",
  136. "category": "started",
  137. "level": "info",
  138. "message": "Breadcrumb Tracking",
  139. },
  140. ]
  141. },
  142. "contexts": {
  143. "app": {
  144. "app_start_time": "2023-02-08T23:51:05Z",
  145. "device_app_hash": "8854fe9e3d4e4a66493baee798bfae0228efabf1",
  146. "build_type": "app store",
  147. "app_identifier": "com.some.company.io",
  148. "app_name": "SomeCompany",
  149. "app_version": "5.222.5",
  150. "app_build": "21036",
  151. "app_id": "397D4F75-6C01-32D1-BF46-62098979E470",
  152. "type": "app",
  153. },
  154. "device": {
  155. "family": "iOS",
  156. "model": "iPhone14,8",
  157. "model_id": "D28AP",
  158. "arch": "arm64e",
  159. "memory_size": 5944508416,
  160. "free_memory": 102154240,
  161. "usable_memory": 4125687808,
  162. "storage_size": 127854202880,
  163. "boot_time": "2023-02-01T05:21:23Z",
  164. "timezone": "PST",
  165. "type": "device",
  166. },
  167. "os": {
  168. "name": "iOS",
  169. "version": "16.3",
  170. "build": "20D47",
  171. "kernel_version": "Darwin Kernel Version 22.3.0: Wed Jan 4 21:25:19 PST 2023; root:xnu-8792.82.2~1/RELEASE_ARM64_T8110",
  172. "rooted": False,
  173. "type": "os",
  174. },
  175. },
  176. "debug_meta": {
  177. "images": [
  178. {
  179. "code_file": "/private/var/containers/Bundle/Application/895DA2DE-5FE3-44A0-8C0F-900519EA5516/iOS-Swift.app/iOS-Swift",
  180. "debug_id": "aa8a3697-c88a-36f9-a687-3d3596568c8d",
  181. "arch": "arm64",
  182. "image_addr": "0x100260000",
  183. "image_size": 180224,
  184. "image_vmaddr": "0x100000000",
  185. "type": "macho",
  186. },
  187. {
  188. "code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/iOS-Swift.app/Frameworks/Sentry.framework/Sentry",
  189. "debug_id": "e2623c4d-79c5-3cdf-90ab-2cf44e026bdd",
  190. "arch": "arm64",
  191. "image_addr": "0x100304000",
  192. "image_size": 802816,
  193. "type": "macho",
  194. },
  195. {
  196. "code_file": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  197. "debug_id": "b0858d8e-7220-37bf-873f-ecc2b0a358c3",
  198. "arch": "arm64e",
  199. "image_addr": "0x1a4e8f000",
  200. "image_size": 25309184,
  201. "image_vmaddr": "0x188ff7000",
  202. "type": "macho",
  203. },
  204. {
  205. "code_file": "/System/Library/Frameworks/CFNetwork.framework/CFNetwork",
  206. "debug_id": "b2273be9-538a-3f56-b9c7-801f39550f58",
  207. "arch": "arm64e",
  208. "image_addr": "0x1a3e32000",
  209. "image_size": 3977216,
  210. "image_vmaddr": "0x187f9a000",
  211. "in_app": False,
  212. "type": "macho",
  213. },
  214. ]
  215. },
  216. "environment": "test-app",
  217. "sdk": {
  218. "name": "sentry.cocoa",
  219. "version": "8.1.0",
  220. "integrations": [
  221. "Crash",
  222. "PerformanceTracking",
  223. "MetricKit",
  224. "WatchdogTerminationTracking",
  225. "ViewHierarchy",
  226. "NetworkTracking",
  227. "ANRTracking",
  228. "AutoBreadcrumbTracking",
  229. "FramesTracking",
  230. "AppStartTracking",
  231. "Screenshot",
  232. "FileIOTracking",
  233. "UIEventTracking",
  234. "AutoSessionTracking",
  235. "CoreDataTracking",
  236. "PreWarmedAppStartTracing",
  237. ],
  238. },
  239. "threads": {
  240. "values": [
  241. {
  242. "id": 0,
  243. "stacktrace": {
  244. "frames": [
  245. {
  246. "function": "<redacted>",
  247. "in_app": False,
  248. "data": {"symbolicator_status": "unknown_image"},
  249. "image_addr": "0x0",
  250. "instruction_addr": "0x1129be52e",
  251. "symbol_addr": "0x0",
  252. },
  253. {
  254. "function": "<redacted>",
  255. "in_app": False,
  256. "data": {"symbolicator_status": "unknown_image"},
  257. "image_addr": "0x0",
  258. "instruction_addr": "0x104405f21",
  259. "symbol_addr": "0x0",
  260. },
  261. ],
  262. },
  263. "raw_stacktrace": {
  264. "frames": [
  265. {
  266. "function": "<redacted>",
  267. "in_app": False,
  268. "image_addr": "0x0",
  269. "instruction_addr": "0x1129be52e",
  270. "symbol_addr": "0x0",
  271. },
  272. {
  273. "function": "<redacted>",
  274. "in_app": False,
  275. "image_addr": "0x0",
  276. "instruction_addr": "0x104405f21",
  277. "symbol_addr": "0x0",
  278. },
  279. ],
  280. },
  281. "crashed": True,
  282. }
  283. ]
  284. },
  285. "user": {
  286. "id": "803F5C87-0F8B-41C7-8499-27BD71A92738",
  287. "ip_address": "192.168.0.1",
  288. "geo": {"country_code": "US", "region": "United States"},
  289. },
  290. "logger": "my.logger.name",
  291. }
  292. result.update(kwargs)
  293. return result