iOS-底層原理3:objc4-781調(diào)試

1、準備工作

  • objc4-781 源碼
  • 依賴的文件


    源碼編譯需要依賴的文件

說明:其中除了其中 launchd-106.10 需要在Mac OS X 10.4.4下載,其他的均可以在最新的的版本macOS 10.15中檢索到

2、編譯調(diào)試

下載完源碼解壓直接運行,會出現(xiàn)以下問題:

問題1:unable to find sdk 'macosx.internal'

報錯1

解決:選擇 target -> objc -> Build Settings -> Base SDK -> 選擇 macOS
注意:【target中的 objc 和 obc-trampolines都需要更改】

解決方法

每解決一個問題,繼續(xù)編譯
問題2:'sys/reason.h' file not found

解決:
step1:Apple sourcemacOS10.15 --> xnu-6153.11.26/bsd/sys/reason.h 路徑自行下載
step2:objc4-781的根目錄下新建Common文件夾, 并在Common文件夾中創(chuàng)建sys文件夾
step3:將 reason.h文件拷貝到sys文件中

創(chuàng)建文件夾拷貝文件

step4:設(shè)置文件檢索路徑:選擇 target -> objc -> Build Settings,在工程的 Header Search Paths 中添加搜索路徑 $(SRCROOT)/Common

截屏2020-09-08 下午4.53.53.png

問題3:'mach-o/dyld_priv.h' file not found

解決:
step1:在Common文件中 創(chuàng)建 mach-o 文件夾
step2:找到文件:dyld-733.6 -- include -- mach-o -- dyld_priv.h
step3:dyld_priv.h拷貝到 mach-o文件夾中

拷貝dyld_priv.h文件到mach-o文件夾

step4:拷貝到文件夾后,還需要修改 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

問題4:'os/lock_private.h' file not found
解決:
step1:在Common中創(chuàng)建 os文件夾
step2:找到文件libplatform-220 --> private --> os --> lock_private.h 、base_private.h,
step3:將文件拷貝至 os 文件夾中

拷貝文件到os

問題5:'pthread/tsd_private.h' file not found
解決:
step1:在Common文件夾中創(chuàng)建 pthread 文件夾
step2:找到libpthread-416.11.1 --> private --> tsd_private.h、spinlock_private.h文件,
step3:拷貝到 pthread文件夾

拷貝文件到pthread

問題6:'System/machine/cpu_capabilities.h' file not found
解決:
step1:在Common文件夾中創(chuàng)建System文件夾,并在System文件夾下創(chuàng)建machine文件夾
step2:找到xnu6153.11.26 --> osfmk --> machine --> cpu_capabilities.h文件,
step3:將文件拷貝到machine文件夾下

拷貝文件到machine

問題7:'os/tsd.h' file not found
解決:
step1:找到xnu6153.11.26 --> libsyscall --> os --> tsd.h文件,
step2:將文件拷貝到Common-->os文件夾下

拷貝文件到os

問題8:'System/pthread_machdep.h' file not found
解決:
step1:Libc-583版本中找到Libc-583/pthreads/pthread_machdep.h
step2:將文件拷貝到Common--> System

拷貝文件到System

說明:在最新版的macOS 10.15中最新版下載的libc中沒有這個h文件,需要下載Libc-583版本

問題9:'CrashReporterClient.h' file not found
解決:
step1:* 在 Libc-825.24中找到Libc-825.24/include/CrashReporterClient.h
step2:將文件拷貝到Common文件夾下

拷貝文件到Common

如果編譯還是報錯,則
需要在 Build Settings -> Preprocessor Macros 中加入:LIBC_NO_LIBCRASHREPORTERCLIENT

問題10:'objc-shared-cache.h' file not found
解決:
step1:找到dyld-733.6 --> include --> objc-shared-cache.h
step2:將文件拷貝到Common文件夾下

問題11:'Block_private.h' file not found
解決:
step1:找到libclosure-74 --> Block_private.h
step2:將文件拷貝到Common文件夾下

問題12:'_simple.h' file not found
解決:
step1:找到libplatform-220 --> private --> _simple.h
step2:將文件拷貝到Common文件夾下

問題13:'kern/restartable.h' file not found
解決:
step1:在Common文件夾下創(chuàng)建kern文件夾
step2:找到xnu-6153.11.26 --> osfmk --> kern -->restartable.h
step3:將文件拷貝到kern文件夾下

問題14:Mismatch in debug-ness macros
解決:
step1:注釋掉objc-runtime.mm中的#error mismatch in debug-ness macros

問題15:ld: can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order
解決:
step1:targets-->objc-->Build Settings
step2:在工程的 Order File 中添加搜索路徑 $(SRCROOT)/libobjc.order

2251862-83633168dcdbb018.png

問題16:Library not found for -lCrashReporterClient
解決:
step1: target -> objc -> Build Settings
step2:Other Linker Flags 中刪除 -lCrashReporterClient ( DebugRelease 都刪了)

問題17:SDK "macosx.internal" cannot be located.
解決:
step1: target -> objc -> Build Phases -> Run Script(markgc)
step2: 把腳本文本 macosx.internal 改成 macosx

繼續(xù)編譯,編譯成功

運行

step1: 新建一個target :LBHTest

step2: Targets-->LBHTest-->Build Phases

截屏2020-09-08 下午11.12.21.png

step3:新建一個LBHPerson類

step4:在main.m中 創(chuàng)建 LBHPerson的對象,進行源碼調(diào)試

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容