Compile environment
- MacOS Catalina 10.15.6
- Xcode 12.1
- Python 2.7.16
- brew install cmake ninja
Compilation step
The preparatory work
-
Create a new folder and name it swift-source
-
Pull resources need access to the Internet, so need scientific Internet access
Step 1: Clone Swift source code
Swift-5.3.1-release is compiled here. You can find the corresponding branch on the official website, note: swift source version must match Xcode version (official compilation documentation is explained).
Git clone - branch swift - 5.3.1 - RELEASE at https://github.com/apple/swift.gitCopy the code
Step 2: update-checkout
Clone the swift related library, otherwise it will fail at compile time, this step is crucial! (The compilation process can be long)
. / swift/utils/update - checkout - tag swift - 5.2.4 - RELEASE - cloneCopy the code
The path of the file should be avoided as far as possible because there is a high probability of errors
Step 3: Compile with Ninja
You can either use Ninja or Xcode for the build, but it’s not very supportive to actually test Xcode for the build, so ninja is used here
./swift/utils/build-script -r --debug-swift-stdlib --lldb
Copy the code
Step 4: debug Swift using VSCode
-
VSCode download address: official website download
-
VSCode Chinese (System setup Chinese)
- Mac shortcut: Command + Shift + P, enter search configure Language
- In the select Display Language input box, select Install Additional Languages… options
- Select the Chinese (simplified) extension package and click Install
- After the installation is complete, click on the prompt resStart Now in the lower right corner to restart VS Code, or manually close and re-open to take effect
-
Install in VSCode
CodeLLDB
The plug-in -
Adding a Configuration File
launch.json
The path of program needs to be the same as the path of the files you compiled
-
Click on the
Debug
Run, break, continue execution after breaking point -
The operation is successful if you see the following results
-
Switch to terminal debug source code (example)
-
Enter the following code in the terminal
-
Source search
swift_allocObject
, add a breakpoint here -
Continue typing at the terminal
var t = LZTeacher()
Enter to find the breakpoint
At this point we can debug the normal source ~ ~