最近很多人发文章写objc runtime,我们知道runtime是开源的,如何从源代码编译并且使用自己编译出来的libobjc.A.dylib呢?自己尝试了一下,很多问题。一直不能成功,于是发帖子问了一下:

还在微博上@了一下大牛,也没有什么回复。

这篇文章持续更新,直到我得到我想要的答案。

查看libobjc.A.dylib的函数

nm -gU /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/libobjc.A.dylib
nm -gU /usr/lib/libobjc.A.dylib

http://stackoverflow.com/questions/25590945/trouble-when-linking-objective-c-program-with-my-own-libobjc-a-dylib 解释了如何替换libobjc.A.dylib

The Objective-C Runtime: Understanding and Abusing

OBJC_HELP=1 ./a.out #显示debug 信息
NSObjCMessageLoggingEnabled=Yes ./a.out #在/tmp/msgSend-xx生成

对于Xcode,我们可以在project->schema中设置(command+<): 设置iOS模拟器

对于不越狱的真机,可以通过设置objc_msgSend断点,来控制:

p (void)printf("[%s, %s]\n", (char*)object_getClassName($arg1), $arg2)

真机调试

但是非常非常地慢,需等待。

https://github.com/RetVal/objc4-532.2 build on OSX Yosemite 10.10.2 (14C109)