• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

可可每次方法调用都打破

用户头像
it1352
帮助4

问题说明

通常在调试时,重要的是我知道一个类的什么方法被调用以什么顺序。原来的解决方案(我一直使用到目前为止)是在每个方法的顶部弹出一个 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 NSLogs, 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?

正确答案

#1

所有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
系列文章
更多 icon
同类精品
更多 icon
继续加载