本文主要是經過將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