iOSiOS

iOS-底层原理3:objc4-781调试

2020-09-08  本文已影响0人  AcmenL

1、准备工作

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

2、编译调试

下载完源码解压直接运行,会出现以下问题:

问题1:unable to find sdk 'macosx.internal'

报错1

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

解决方法
每解决一个问题,继续编译
问题2:'sys/reason.h' file not found

解决:
step1:Apple sourcemacOS10.15 --> xnu-6153.11.26/bsd/sys/reason.h 路径自行下载
step2:objc4-781的根目录下新建Common文件夹, 并在Common文件夹中创建sys文件夹
step3:将 reason.h文件拷贝到sys文件中

创建文件夹拷贝文件

step4:设置文件检索路径:选择 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文件中 创建 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中创建 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文件夹中创建 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文件夹中创建System文件夹,并在System文件夹下创建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文件夹下创建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

继续编译,编译成功

运行

step1: 新建一个target :LBHTest

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

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

step3:新建一个LBHPerson类

step4:在main.m中 创建 LBHPerson的对象,进行源码调试

上一篇下一篇

猜你喜欢

热点阅读