文章目录
编译环境
mac 10.15.4
Xcode: 11.6
python: 2.7 3.7均有
ninja:brew install ninja
CMake:brew install CMake
编译步骤:(如前两步未成功,可直接跳转第三步)
1. clone swift源码
git clone --branch swift-5.3.1-RELEASE https://github.com/apple/swift.git
2. update-checkout(这步clone编译swift相关的库,非常关键,一定要成功!!!!)
./swift/utils/build-script -r --debug-swift-stdlib --lldb
3. 采用ninja编译
如果前两步未成功,则将前两步拉下来的源码直接下载到本地硬盘,继续执行以下命令进行编译操作
./swift/utils/build-script -r --debug-swift-stdlib --lldb
4、使用VSCode调试Swift
-
安装插件codelldb
-
添加配置文件launch.json,并修改
文件内容如下, 确保与你编译的文件路径一致
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-x86_64/bin/swift",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
点击debug运行,看到
过掉断点,继续看到如下结果便是运行成功了
可能会出现的问题
- 断点过程中,vscode不显示变量信息(左侧红圈标注)
解决办法:
1、将 编译后的源码项目路径/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/lldb-macosx-x86_64/bin/里的内容拷贝到~/.vscode/extensions/vadimcn.vscode-lldb-1.6.0/lldb/bin/路径下
2、拷贝编译后的源码项目路径/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/lldb-macosx-x86_64/bin/lldb文件到~/.vscode/extensions/vadimcn.vscode-lldb-1.6.0/lldb/lib/路径下, 并将文件重命名为liblldb.dylib,替换原有存在的liblldb.dylib文件
- import six No module named six
解决:pip3 install six