可可:每次方法调用都打破? [英] Cocoa: Break on every method call?

查看:112
本文介绍了可可:每次方法调用都打破?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

所有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).

这篇关于可可:每次方法调用都打破?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆