iOS技术积累

不管生活有多不容易,都要守住自己的那一份优雅。

调试 Swift StdLib

https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md

我的构建方式

 mkdir swift-project
 cd swift-project
 git clone git@github.com:apple/swift.git
 brew install cmake ninja sccache
 cd swift
 utils/update-checkout --clone-with-ssh
 export SCCACHE_CACHE_SIZE="50G"
utils/build-script --skip-build-benchmarks \  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \  --sccache --debug --swift-disable-dead-stripping \  --bootstrapping=hosttools --xcode

TODO:
直接构建 all_build target 会失败

  1. 打开
    ~/workspace/ana/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/Swift.xcodeproj
  2. 创建 commandline工程 依赖 swift-stdlib-macos-arm64
  3. 开始构建,过程中会碰见 llvm 很多库没有,缺什么 构建什么就可以了,
    有可能会缺少一个文件 复制下就行
    cp build/Ninja-DebugAssert/llvm-macosx-arm64/tools/clang/include/clang/Driver/Options.inc 
    /Users/bytedance/workspace/ana/swift-project/llvm-project/clang/include/clang/Driver/

别人的构建方式

 mkdir swift-project
 cd swift-project
git clone https://github.com/apple/swift 
brew install cmake ninja sccache
 cd swift
./swift/utils/update-checkout --scheme=main  --clone --clean --reset-to-remote
./swift/utils/build-script \
--skip-build-benchmarks \      # 跳过构建基准测试,可能是出于节省构建时间的考虑
--debug-swift-stdlib \         # 以调试模式构建Swift标准库,这样在调试时可以获取更多的信息
--reconfigure \                # 重新配置项目,主要是如果有任何设置改动时,保证这些改动可以在构建过程中反映出来
--enable-experimental-cxx-interop \   # 开启C++互操作性的实验性支持,这意味着你的Swift代码可以调用C++代码
--skip-ios --skip-watchos --skip-tvos \   # 不构建适用于iOS、watchOS和tvOS的版本,您可能只关心macOS的版本
--swift-darwin-supported-archs "$(uname -m)" \   # 指定构建适用于当前架构的Swift,$(uname -m)是一个bash命令,得出当前机器的架构
--sccache \                    # 使用sccache来缓存构建的中间文件,这样可以加快反复的构建过程
--release-debuginfo \          # 在发布版本中包含调试信息,这通常会使得构建的产物更大,但在调试时提供了更多信息
--swift-disable-dead-stripping # 禁用dead-stripping,也就是不移除未使用的代码和数据,这可以使得调试过程更方便,但会使得构建的产物更大

接下来全文搜索你关注的兴趣点 开始调试 swift-frontend

$ lldb ./build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-arm64/bin/swift-frontend -- \
-c ./main.swift \
-target arm64-apple-macos10.13 \
-sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk \
-Xcc -DDEBUG\=1 \
-target-sdk-version 14.0 \
-target-sdk-name macosx14.0

后面就是设置断点,
打印变量

$ br set --file YOUR_PATH/MiscDiagnostics.cpp --line 1400
(lldb) frame variable --show-types
(lldb) p fnExpr->getLoc()

执行单侧

./swift/utils/run-test \
--build-dir ./build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-arm64/ \
test/Constraints/diagnostics.swift

评论卡