crash_event_cocoa.py 13 KB

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