Objective-C RunTime

iOS-底层原理 03:objc4-781 源码编译 & 调试

2020-09-06  本文已影响0人  Style_月月

iOS 底层原理 文章汇总

本文主要是通过将objc4-781的源码编译成功,然后在源码中进行调试,便于跟踪方法的底层实现流程

准备工作

环境版本 & 最新objc源码

依赖文件下载

需要下载以下依赖文件


image

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

源码编译

源码编译就是不断的调试修改源码的问题,主要有以下问题

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

image

问题二:文件找不到的报错问题

【1】'sys/reason.h' file not found

image

【2】'mach-o/dyld_priv.h' file not found

#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

【3】'os/lock_private.h' file not found 和 'os/base_private.h' file not found

【4】'pthread/tsd_private.h' file not found 和 'pthread/spinlock_private.h' file not found

【5】'System/machine/cpu_capabilities.h' file not found

【6】os/tsd.h' file not found

【7】'System/pthread_machdep.h' file not found

在最新版的macOS 10.15中最新版下载的libc中没有这个h文件,需要下载Libc-583版本

【8】'CrashReporterClient.h' file not found

【9】'objc-shared-cache.h' file not found

【10】Mismatch in debug-ness macros

【11】'_simple.h' file not found

【12】'kern/restartable.h' file not found

【13】'Block_private.h' file not found

【14】libobjc.order 路径问题

问题描述为:can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order

【14】Xcode 脚本编译问题
问题描述为:/xcodebuild:1:1: SDK "macosx.internal" cannot be located.

编译调试

源码调试

补充

如果有以下调试问题,可以根据提供的方案进行尝试

创建的调试target中main的断点无法断住的问题

2021-03-22 补充

由于xcode12上无法运行781源码,所以再次提供一个xcode12以上版本可以跑的源码 objc4-818.2

上一篇下一篇

猜你喜欢

热点阅读