Track all ObjC method calls?

后端 未结 5 1412
一整个雨季
一整个雨季 2020-11-28 11:31

Sometimes when looking at someone else\'s large Objective-C program, it is hard to know where to begin.

In such situations, I think it would be helpful to log every

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 12:11

    I don't think logging every single call is practical enough to be useful, but here's a suggestion in that direction.

    On a side note, if it's a large program, it better have some kind of documentation or an intro comment for people to get started with the code.

    In any case, every Cocoa application has an applicationDidFinishLaunching... method. It's a good place to start from. Some apps also have their principal (or 'main window') class defined in the Info.plist file. Both these things might give you a hint as to what classes (specifically, view controllers) are the most prominent ones and what methods are likely to have long stack-traces while the program is running. Like a game-loop in a game engine, or some other frequently called method. By placing a breakpoint inside such a method and looking at the stack-trace in the debugger, you can get a general idea of what's going on.

    If it's a UI-heavy app, looking at its NIB files and classes used in them may also help identify parts of app's functionality you might be looking for.

    Another option is to fire up the Time Profiler instrument and check both Hide missing symbols and Hide system libraries checkboxes. This will give you not only a bird's eye view on the methods being called inside the program, but also will pin-point the most often called ones.

    By interacting with your program with the Time Profiler recording on, you could also identify different parts of the program's functionality and correlate them with your actions pretty easily.

提交回复
热议问题