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

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

问题描述

我正在为客户开发一款iPad应用程序。有大量的工作已经完成,我正在努力拼凑整个设计的运行方式。



我喜欢的其中一件事要做的是记录应用程序运行时调用哪些方法。我已经看到了一个自定义DTrace脚本,它意味着记录启动时的所有方法,但是当我在Instruments中运行它时,我没有得到任何结果。



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

解决方案

受到tc对类似问题的回答的启发。上面的内存地址只能用于模拟器,因此您可能需要调整它以针对iOS设备上的应用程序运行。 Collin建议在他的答案中进行以下修改,以便在设备上运行:

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

此外,我认为您会看到注销应用程序中调用的每个方法都会让您感到不堪重负。您可能可以使用某些条件来过滤它,但我不知道这是否有助于您了解代码的执行方式。


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.

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?

解决方案

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.

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]\n", (char *)object_getClassName(*(long*)($esp+4)),*(long *)($esp+8)

Your breakpoint should look something like the following:

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]

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]\n", (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天全站免登陆