This is the 9th day of my participation in the August More Text Challenge
Compile environment
- MacOS Big Sur 11.0.1
- Xcode 12.2
- Python 2.x
- brew install cmake ninja
Compilation step
The preparatory work
-
Create a new folder and name it swift-source
-
Because in the process of pulling resources, we need to access the Internet, so we need a ladder (you can solve the problem by yourself)
Step 1: Clone Swift source code
Swift-5.3.1-release is compiled here. You can find the corresponding branch on the official website. It should be noted that the swift source version should match the Xcode version (the official compilation document has instructions).
Git clone - branch swift - 5.3.1 - RELEASE at https://github.com/apple/swift.gitCopy the code
Step 2: update-checkout
This step is mainly to clone the swift related library, otherwise the compile will fail, this step is very important! (The compilation process will take a long time, so it is recommended to compile at a break.)
./swift/utils/build-script -r --debug-swift-stdlib --lldb
Copy the code
Note here: the file path should avoid Chinese, Chinese has a high probability of error
Step 3: Ninja compile
You can either use Ninja or Xcode, but Xcode is not very supportive after compilation, so ninja compilation is used here
./swift/utils/build-script -r --debug-swift-stdlib --lldb
Copy the code
Step 4: debug Swift using VSCode
- First, install the plug-in in VSCode
- Adding a Configuration File
launch.json
And modify
Note that the path of program needs to be the same as the path of the file you compiled
{" version ":" 0.2.0, "" configurations: [{" type" : "LLDB", "request" : "launch", "name" : "Debug", "the program" : "${workspaceFolder}/build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-x86_64/bin/swift", "args": [], "cwd": "${workspaceFolder}" } ] }Copy the code
- Click on the
Debug
Run, break
And then you go over the break pointThe operation is successful if you see the following results
- Then switch to terminal, we can start source debugging.
- Enter the following code in the terminal (you can also copy it from the SWIFT file)
- Source search
swift_allocObject
(this is covered in a later article, just as an example of debugging), add a breakpoint
- Continue typing at the terminal
var t = CJLTeacher()
And press enter
In this way, we can debug Swift source code pleasantly, remember (° °) Blue ✿