下载objc4787.1源码并调试TestDemo项目
- 找到苹果源码网址:https://opensource.apple.com/

-
找到objc4点击下载
QQ20201202-094343.png
3.下载一些依赖的文件
QQ20201202-104952@2x.png
其中除了launchd-842.92.1
需要在Mac OSX 10.9.5中下载,其它均可在最新的里面下载到 -
下载解压打开objc.xcodeproj,编译一下发现报错
错误一:unable to find sdk 'macosx.internal'
QQ20201202-095408@2x.png


解决:Build Settings中搜索macosx.internal
,选择macOS
错误二:sys/reson.h
file not found

解决:首先在objc4-787.1
根目录下创建ZKCommon文件,同时在ZKCommon文件中创建sys
文件,在事先下载的xnu-6153.141.1/bsd/sys/reason.h
把reason.h拷贝到我们自己创建的ZKCommon/sys/
中

选择
target -> objc -> Build Settings
找到Header Serach Paths
添加路径$(SRCROOT)/ZKCommon

错误三:mach-o/dyld_priv.h
file not found

解决:在ZKCommon文件中创建mach-o
文件 dyld-750.6/include/mach-o/dyld_priv.h
拷贝到自己创建的ZKCommon/mach-o
中

拷贝后还要修改
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
错误四:os/lock_private.h
file not found

解决:在ZKCommon文件中创建os
文件,libplatform-220.100.1/private/os/lock_private.h
, libplatform-220.100.1/private/os/base_private.h
2个都拷贝到os文件中

错误五:bridgeos(3.0), bridgeos(4.0)

解决:在
dyld_priv.h
文件中搜索bridgeson(3.0)
删除(可以用空格全部代替)在
lock_private.h
文件中搜索bridgeos(4.0)
删除
错误六:pthread/tsd_private.h
file not found
pthread/spinlock_private.h
file not found


解决:在ZKCommon
文件中创建pthread
文件,libpthread-416.100.3/private/tsd_private.h
, libpthread-416.100.3/private/spinlock_private,h
2个文件都拷贝到pthread
中

错误七:System/machine/cpu_capabilities.h
file not found

解决:在
ZKCommon
中创建System
文件,再创建machine
文件,xnu-6753.141.1/osfmk/machine/cpu_capabilities.h
拷贝到创建的machine
文件夹中

错误八:os/tsd.h
file not found

解决:
xnu-6153.141.1/libsyscall/os/tsd.h
复制到先前ZKCommon
中创建的os
文件中
错误九:System/pthread_machdep.h
file not found

解决:https://opensource.apple.com/tarballs/Libc/ 下载Libc-583
版本,Libc-583/pthreads/pthread_machdep.h
文件拷贝到ZKCommon/System/
中

错误十:CrashReporterClient.h
file not found


解决:https://opensource.apple.com/tarballs/Libc/ 下载Libc-825,24
版本 Libc-825.24/include/CrashReporterClient.h
拷贝到ZKCommon/
中
如果还是报错需要Build Settings -> Preprocessor Macros
加入:LIBC_NO_LIBCRASHREPORTERCLIENT

错误十一:kern/restartable.h
file not found

解决:在ZKCommon
中创建kern
文件,xnu-6153.141.1/osfmk/kern/restartable.h
拷贝到ZKCommon/kern/
中

错误十二:_simple.h
file not found

解决:libplatform-220.100.1/private/_simple.h
拷贝到ZKCommon/
中

错误十三:typedef int pthread_lock_t
inline static int _pthread_has_direct_tsd(void)
inline static void * _pthread_getspecific_direct(unsigned long slot)

解决:注释掉报错的地方不要有漏掉地方
错误十四:mismatch in debug-ness macros

解决:注释掉objc-runtime.mm
中的#error mismatch in debug-ness macros
即可
错误十五:objc-shared-cache.h
file not found

解决:将dyld-750.6/include/objc-shared-cache,h
拷贝到ZKCommon/
中

错误十六:Block_prrivate.h
file not found

解决:libclosure-74/Block_private.h
拷贝到ZKCommon/
中

错误十七:can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/AppleInternal/OrderFiles/libobjc.order
路径问题

解决:target -> objc -> Build Settings
Order File
添加搜索路径$(SRCROOT)/libobjc.order
错误十八:library not found for -lCrashReporterClient

解决:TARGETS -> objc -> Build Settings
搜索Other Linker Flags
找到lCrashReporterClient
删除掉

错误十九:objc-runtime-new.h
static_assert(bucketsMask >= MACH_VM_MAX_ADDRESS, "Bucket field doesn't have enough bits for arbitrary pointers.")
STATIC_ASSERT((~ISA_MASK & MACH_VM_MAX_ADDRESS) == 0 ||
ISA_MASK + sizeof(void*) == MACH_VM_MAX_ADDRESS);


解决:断言错误,网上找了好久没有找到解决办法,最后只能注释掉了,查看以前老的版本没有发现这个错误,有知道解决办法的可以留言告诉我一下
错误二十:shell脚本问题

解决:targets -> Build Phases -> Run Script
中 macosx.internal
改成macosx

到这里我把报错都解决了

5.创建TestDemo



给TestDemo绑定依赖关系,TestDemo -> Build Phases -> Dependencies
添加objc


给TestDemo添加库,TestDemo -> Build Phases -> Link Binary With Libraries
添加libobjc.A.dylib


6.开始调试了

打印了Hello,World!
,成功运行

7.接下来就可以各种调试了,创建Person

8.我们打断点调试发现断点无效

解决办法:TestDemo -> Build Phases -> Compile Sources
中 main.m
拖到最上面


- 结束,虽然解决办法是在网上搜的,但也算是自己重头到尾做了一遍。
参考:
https://www.jianshu.com/p/d2f589e3e1ef
https://www.jianshu.com/p/3db5d0bde015