本文主要是经过将objc4-781的源码编译成功,而后在源码中进行调试,便于跟踪方法的底层实现流程html
须要下载如下依赖文件 macos
其中除了其中
launchd-106.10
须要在Mac OS X 10.4.4下载,其余的都可以在最新的的版本macOS 10.15中检索到xcode
源码编译就是不断的调试修改源码的问题,主要有如下问题markdown
target -> objc -> Build Settings -> Base SDK ->
选择 macOS 【target中的 objc 和 obc-trampolines
都须要更改】在Apple source的 macOS10.15 --> xnu-6153.11.26/bsd/sys/reason.h
路径自行下载app
在objc4-781
的根目录下新建CJLCommon
文件, 同时在CJLCommon
文件中建立sys
文件oop
最后将 reason.h
文件拷贝到sys
文件中ui
target -> objc -> Build Settings
,在工程的 Header Serach Paths
中添加搜索路径 $(SRCROOT)/CJLCommon
CJLCommon
文件中 建立 mach-o
文件dyld-733.6 -- include -- mach-o -- dyld_priv.h
mach-o
文件中dyld_priv.h
文件,即在 dyld_priv.h
文件顶部加入一下宏:#define DYLD_MACOSX_VERSION_10_11 0x000A0B00
#define DYLD_MACOSX_VERSION_10_12 0x000A0C00
#define DYLD_MACOSX_VERSION_10_13 0x000A0D00
#define DYLD_MACOSX_VERSION_10_14 0x000A0E00
复制代码
CJLCommon
中建立 os
文件lock_private.h、base_private.h
文件:libplatform-220 --> private --> os --> lock_private.h 、base_private.h
,并将文件拷贝至 os 文件中lock_private.h dyld_priv.h
中若是报错,去掉 bridgeos(3.0)
CJLCommon
中建立 pthread
文件tsd_private.h、spinlock_private.h
文件,h文件路径为:libpthread-416.11.1 --> private --> tsd_private.h、spinlock_private.h
,并拷贝到 pthread
文件System -- machine
文件cpu_capabilities.h
文件拷贝到 machine
文件,h文件路径为:xnu6153.11.26 --> osfmk --> machine --> cpu_capabilities.h
tsd.h
文件,拷贝到os文件, h文件路径为:xnu6153.11.26 --> libsyscall --> os --> tsd.h
pthread_machdep.h
文件,h文件路径为:Libc-583/pthreads/pthread_machdep.h
system
文件中在最新版的macOS 10.15中最新版下载的
libc
中没有这个h文件,须要下载Libc-583版本spa
Libc-825.24
中找到该文件,路径为Libc-825.24/include/CrashReporterClient.h
,直接存放在CJLCommon
文件中Build Settings -> Preprocessor Macros
中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
CrashReporterClient
,这里面咱们直接更改了里面的宏信息 #define LIBC_NO_LIBCRASHREPORTERCLIENT
CrashReporterClient
的问题,解决方法是 在BuildSetting --> Other Linker Flags
中去掉CrashReporterClient
.文件路径为:dyld-733.6 --> include --> objc-shared-cache.h
debug
CJLCommon
objc-runtime.mm
中的#error mismatch in debug-ness macros
libplatform-220 --> private --> _simple.h
CJLCommon
中CJLCommon
中建立kern
文件xnu-6153.11.26 --> osfmk --> kern -->restartable.h
libclosure-74 --> Block_private.h
CJLCommon
目录问题描述为:can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order
调试
target -> objc -> Build Settings
Order File
中添加搜索路径 $(SRCROOT)/libobjc.order
问题描述为:/xcodebuild:1:1: SDK "macosx.internal" cannot be located.
target -> objc -> Build Phases -> Run Script(markgc)
macosx.internal
改为 macosx
target
:CJLTest
CJLPerson
类main.m
中 建立 CJLPerson
的对象,进行源码调试若是有如下调试问题,能够根据提供的方案进行尝试
Build Phases --> Compile Source
中,将main文件移至第一位Build Setting
中将Enable Hardened Runtime
置为NO