crash_event_cocoa.py 12 KB

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