crash_event_cocoa.py 12 KB

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