crash_event_cocoa.py 13 KB

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