可可每次方法调用都打破
问题说明
通常在调试时,重要的是我知道一个类的什么方法被调用以什么顺序。原来的解决方案(我一直使用到目前为止)是在每个方法的顶部弹出一个 NSLog
。但是这是耗时,重复,丑陋,如果我忘记在调试后删除日志,我的代码看起来很少。
Often when debugging, it's important for me to know what methods of a class are being called in what order. The naive solution (that I've been using thus far) is to pop an NSLog
at the top of each method. But this is time consuming, repetitive, ugly, and makes my code look juvenile if I forget to remove the logs after debugging.
一个更清洁的解决方案是在每个的我的方法,配置他们的操作发出调试器命令: po NSStringFromSelector(_cmd)
并将其设置为自动继续。这是更漂亮,并避免不必记住删除所有这些 NSLog
,但不是不重复或耗时。
A cleaner solution is to set breakpoints on each of my methods, configure their actions to issue the debugger command: po NSStringFromSelector(_cmd)
and set them to automatically continue. This is prettier and saves me from having to remember to remove all those NSLog
s, but is no less repetitive or time consuming.
我真正想要的是一种方法来设置一个符号断点,打破每个方法(类的一个模块?)。任何调试/运行时主人都有一个解决方案或提示,从哪里开始寻找?
What I really want is a way to set a symbolic breakpoint that breaks on every method (of a class? Of a module?). Any debugging/runtime masters have a solution or tips on where to start looking?
正确答案
所有Objective-C方法调用通过一个的C运行时调用 objc_msgSend
, objc_msgSend_stret
, objc_msgSendSuper
objc_msgSendSuper_stret /Reference/reference.html\"> Objective-C运行时参考。所以你应该能够捕获它们,并给他们记录前两个参数的相关部分的操作(它是正常发送的目标和选择器,描述包含超级调用的目标和类类型的超类的结构体)。
All Objective-C method calls go through one of the C runtime calls objc_msgSend
, objc_msgSend_stret
, objc_msgSendSuper
and objc_msgSendSuper_stret
per the 'Sending Messages' section of the Objective-C Runtime Reference. So you should be able to trap those, and give them actions to log the relevant parts of the first two parameters (it's target and selector for the normal sends, a struct describing the superclass that contains both the target and the class type for super calls).
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhbieehh
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22