crash_event_cocoa.py 12 KB

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