如何记录 iOS 应用中使用的所有方法 [英] How to log all methods used in iOS app

查看:19
本文介绍了如何记录 iOS 应用中使用的所有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我负责为客户开发 iPad 应用.已经完成了大量工作,我正在努力拼凑整个设计的运行方式.

I'm taking over the development of an iPad app for a client. There's a substantial amount of work that's already been done and I'm trying to piece together how the whole thing is designed to run.

我想做的一件事是记录应用程序运行时调用的方法.我见过一个自定义 DTrace 脚本,它旨在从启动时记录所有方法,但是当我在 Instruments 中运行它时,我没有得到任何结果.

One of the things I'd like to do is log which methods get called when the app runs. I've seen a custom DTrace script that's meant to log all methods from startup, but when I run it in Instruments I get no results.

记录方法的最佳方式是什么?

What's the best way of logging the methods?

推荐答案

灵感来自 tc 对类似问题的回答 这里,我整理了一个调试断点操作,该操作将注销类和方法每次在应用程序中触发 objc_msgSend() 时的名称.这与我在 这个答案.

Inspired by tc's answer to a similar question here, I put together a debug breakpoint action that will log out the class and method name for every time objc_msgSend() is triggered in your application. This works similarly to the DTrace script I described in this answer.

要启用此断点操作,请创建一个新的符号断点(在 Xcode 4 中,转到断点导航器并使用窗口左下角的加号创建一个新的符号断点).将符号设为 objc_msgSend,将其设置为在评估操作后自动继续,并使用以下命令将操作设置为调试器命令:

To enable this breakpoint action, create a new symbolic breakpoint (in Xcode 4, go to the breakpoint navigator and create a new symbolic breakpoint using the plus at the bottom left of the window). Have the symbol be objc_msgSend, set it to automatically continue after evaluating actions, and set the action to be a debugger command using the following:

printf "[%s %s]
", (char *)object_getClassName(*(long*)($esp+4)),*(long *)($esp+8)

您的断点应如下所示:

当针对您的应用程序运行时,这应该会注销这样的消息:

This should log out messages like this when run against your application:

[UIApplication sharedApplication]
[UIApplication _isClassic]
[NSCFString getCString:maxLength:encoding:]
[UIApplication class]
[SLSMoleculeAppDelegate isSubclassOfClass:]
[SLSMoleculeAppDelegate initialize]

如果您想知道我从哪里提取内存地址,请阅读这个关于 Objective-C 运行时内部结构的 Phrack 文章.上面的内存地址仅适用于模拟器,因此您可能需要调整它以针对 iOS 设备上的应用程序运行.Collin 建议在他的回答中进行以下修改,以便在设备上运行:

If you're wondering where I pulled the memory addresses, read this Phrack article on the Objective-C runtime internals. The memory addresses above will only work against the Simulator, so you might need to tweak this to run against applications on the iOS devices. Collin suggests the following modification in his answer to run this on a device:

printf "[%s %s]
", (char *)object_getClassName($r0),$r1

此外,我认为您会发现注销应用程序中调用的每个方法都会让您不知所措.您也许可以使用一些条件来过滤它,但我不知道这是否有助于您了解代码的执行方式.

Also, I think you'll see that logging out every method called in your application will overwhelm you with information. You might be able to use some conditions to filter this, but I don't know if this will help you to learn how your code executes.

这篇关于如何记录 iOS 应用中使用的所有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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