Skip to content

Commit c24989e

Browse files
authored
Add basic GDB remote protocol encoding/decoding (#204)
See GDB and LLDB remote protocol documentation for more details: * https://sourceware.org/gdb/current/onlinedocs/gdb.html/Remote-Protocol.html * https://lldb.llvm.org/resources/lldbgdbremote.html
1 parent 0acc106 commit c24989e

File tree

14 files changed

+1138
-8
lines changed

14 files changed

+1138
-8
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ jobs:
4545
wasi-swift-sdk-download: "https://download.swift.org/development/wasm-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm.artifactbundle.tar.gz"
4646
wasi-swift-sdk-id: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm
4747
wasi-swift-sdk-checksum: "b64dfad9e1c9ccdf06f35cf9b1a00317e000df0c0de0b3eb9f49d6db0fcba4d9"
48-
test-args: "--sanitize address"
48+
test-args: "--sanitize address --traits WasmDebuggingSupport"
4949
# Swift 6.2
5050
- os: macos-15
5151
xcode: Xcode_26.0
5252
development-toolchain-tag: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a
5353
wasi-swift-sdk-download: "https://download.swift.org/development/wasm-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm.artifactbundle.tar.gz"
5454
wasi-swift-sdk-id: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm
5555
wasi-swift-sdk-checksum: "b64dfad9e1c9ccdf06f35cf9b1a00317e000df0c0de0b3eb9f49d6db0fcba4d9"
56-
test-args: "--sanitize address"
56+
test-args: "--sanitize address --traits WasmDebuggingSupport"
5757

5858
runs-on: ${{ matrix.os }}
5959
name: "build-macos (${{ matrix.xcode }})"
@@ -123,24 +123,26 @@ jobs:
123123
wasi-swift-sdk-download: "https://download.swift.org/development/wasm-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm.artifactbundle.tar.gz"
124124
wasi-swift-sdk-id: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm
125125
wasi-swift-sdk-checksum: "b64dfad9e1c9ccdf06f35cf9b1a00317e000df0c0de0b3eb9f49d6db0fcba4d9"
126+
test-args: "--traits WasmDebuggingSupport"
126127
- swift: "swift:6.2-amazonlinux2"
127128
development-toolchain-download: "https://download.swift.org/development/amazonlinux2/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a-amazonlinux2.tar.gz"
128129
wasi-swift-sdk-download: "https://download.swift.org/development/wasm-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm.artifactbundle.tar.gz"
129130
wasi-swift-sdk-id: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm
130131
wasi-swift-sdk-checksum: "b64dfad9e1c9ccdf06f35cf9b1a00317e000df0c0de0b3eb9f49d6db0fcba4d9"
132+
test-args: "--traits WasmDebuggingSupport"
131133
- swift: "swift:6.2-noble"
132134
development-toolchain-download: "https://download.swift.org/development/ubuntu2404/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a-ubuntu24.04.tar.gz"
133135
wasi-swift-sdk-download: "https://download.swift.org/development/wasm-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm.artifactbundle.tar.gz"
134136
wasi-swift-sdk-id: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm
135137
wasi-swift-sdk-checksum: "b64dfad9e1c9ccdf06f35cf9b1a00317e000df0c0de0b3eb9f49d6db0fcba4d9"
136-
test-args: "--enable-code-coverage"
138+
test-args: "--traits WasmDebuggingSupport --enable-code-coverage"
137139
build-dev-dashboard: true
138140
- swift: "swiftlang/swift:nightly-main-noble"
139141
development-toolchain-download: "https://download.swift.org/development/ubuntu2404/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a-ubuntu24.04.tar.gz"
140142
wasi-swift-sdk-download: "https://download.swift.org/development/wasm-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a/swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm.artifactbundle.tar.gz"
141143
wasi-swift-sdk-id: swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm
142144
wasi-swift-sdk-checksum: "b64dfad9e1c9ccdf06f35cf9b1a00317e000df0c0de0b3eb9f49d6db0fcba4d9"
143-
test-args: "-Xswiftc -DWASMKIT_CI_TOOLCHAIN_NIGHTLY"
145+
test-args: "--traits WasmDebuggingSupport -Xswiftc -DWASMKIT_CI_TOOLCHAIN_NIGHTLY"
144146

145147
runs-on: ubuntu-24.04
146148
name: "build-linux (${{ matrix.swift }})"
@@ -222,9 +224,9 @@ jobs:
222224
run: ./build-exec swift sdk install "${{ matrix.musl-swift-sdk-download }}" --checksum "${{ matrix.musl-swift-sdk-checksum }}"
223225

224226
- name: Build (x86_64-swift-linux-musl)
225-
run: ./build-exec swift build --swift-sdk x86_64-swift-linux-musl
227+
run: ./build-exec swift build --swift-sdk x86_64-swift-linux-musl --traits WasmDebuggingSupport
226228
- name: Build (aarch64-swift-linux-musl)
227-
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl
229+
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl --traits WasmDebuggingSupport
228230

229231
build-android:
230232
runs-on: ubuntu-24.04
@@ -282,5 +284,5 @@ jobs:
282284
- name: Install Swift SDK
283285
run: swift sdk install https://download.swift.org/swift-6.2-release/wasm/swift-6.2-RELEASE/swift-6.2-RELEASE_wasm.artifactbundle.tar.gz --checksum fe4e8648309fce86ea522e9e0d1dc48e82df6ba6e5743dbf0c53db8429fb5224
284286
- name: Build with the Swift SDK
285-
run: swift build --swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm"
286-
287+
run: swift build --swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm" --product wasmkit-cli
288+

.sourcekit-lsp/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"swiftPM": {
3+
"traits": ["WasmDebuggingSupport"]
4+
}
5+
}

[email protected]

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// swift-tools-version:6.1
2+
3+
import PackageDescription
4+
5+
import class Foundation.ProcessInfo
6+
7+
let DarwinPlatforms: [Platform] = [.macOS, .iOS, .watchOS, .tvOS, .visionOS]
8+
9+
let package = Package(
10+
name: "WasmKit",
11+
platforms: [.macOS(.v15), .iOS(.v17)],
12+
products: [
13+
.executable(name: "wasmkit-cli", targets: ["CLI"]),
14+
.library(name: "WasmKit", targets: ["WasmKit"]),
15+
.library(name: "WasmKitWASI", targets: ["WasmKitWASI"]),
16+
.library(name: "WASI", targets: ["WASI"]),
17+
.library(name: "WasmParser", targets: ["WasmParser"]),
18+
.library(name: "WAT", targets: ["WAT"]),
19+
.library(name: "WIT", targets: ["WIT"]),
20+
.library(name: "_CabiShims", targets: ["_CabiShims"]),
21+
],
22+
traits: [
23+
.default(enabledTraits: []),
24+
"WasmDebuggingSupport"
25+
],
26+
targets: [
27+
.executableTarget(
28+
name: "CLI",
29+
dependencies: [
30+
"WAT",
31+
"WasmKit",
32+
"WasmKitWASI",
33+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
34+
.product(name: "SystemPackage", package: "swift-system"),
35+
],
36+
exclude: ["CMakeLists.txt"]
37+
),
38+
39+
.target(
40+
name: "WasmKit",
41+
dependencies: [
42+
"_CWasmKit",
43+
"WasmParser",
44+
"WasmTypes",
45+
"SystemExtras",
46+
.product(name: "SystemPackage", package: "swift-system"),
47+
],
48+
exclude: ["CMakeLists.txt"]
49+
),
50+
.target(name: "_CWasmKit"),
51+
.target(
52+
name: "WasmKitFuzzing",
53+
dependencies: ["WasmKit"],
54+
path: "FuzzTesting/Sources/WasmKitFuzzing"
55+
),
56+
.testTarget(
57+
name: "WasmKitTests",
58+
dependencies: ["WasmKit", "WAT", "WasmKitFuzzing"],
59+
exclude: ["ExtraSuite"]
60+
),
61+
62+
.target(
63+
name: "WAT",
64+
dependencies: ["WasmParser"],
65+
exclude: ["CMakeLists.txt"]
66+
),
67+
.testTarget(name: "WATTests", dependencies: ["WAT"]),
68+
69+
.target(
70+
name: "WasmParser",
71+
dependencies: [
72+
"WasmTypes",
73+
.product(name: "SystemPackage", package: "swift-system"),
74+
],
75+
exclude: ["CMakeLists.txt"]
76+
),
77+
.testTarget(name: "WasmParserTests", dependencies: ["WasmParser"]),
78+
79+
.target(name: "WasmTypes", exclude: ["CMakeLists.txt"]),
80+
81+
.target(
82+
name: "WasmKitWASI",
83+
dependencies: ["WasmKit", "WASI"],
84+
exclude: ["CMakeLists.txt"]
85+
),
86+
.target(
87+
name: "WASI",
88+
dependencies: ["WasmTypes", "SystemExtras"],
89+
exclude: ["CMakeLists.txt"]
90+
),
91+
.testTarget(name: "WASITests", dependencies: ["WASI", "WasmKitWASI"]),
92+
93+
.target(
94+
name: "SystemExtras",
95+
dependencies: [
96+
.product(name: "SystemPackage", package: "swift-system"),
97+
.target(name: "CSystemExtras", condition: .when(platforms: [.wasi])),
98+
],
99+
exclude: ["CMakeLists.txt"],
100+
swiftSettings: [
101+
.define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms))
102+
]
103+
),
104+
105+
.target(name: "CSystemExtras"),
106+
107+
.executableTarget(
108+
name: "WITTool",
109+
dependencies: [
110+
"WIT",
111+
"WITOverlayGenerator",
112+
"WITExtractor",
113+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
114+
]
115+
),
116+
117+
.target(name: "WIT"),
118+
.testTarget(name: "WITTests", dependencies: ["WIT"]),
119+
120+
.target(name: "WITOverlayGenerator", dependencies: ["WIT"]),
121+
.target(name: "_CabiShims"),
122+
123+
.target(name: "WITExtractor"),
124+
.testTarget(name: "WITExtractorTests", dependencies: ["WITExtractor", "WIT"]),
125+
126+
.target(name: "GDBRemoteProtocol",
127+
dependencies: [
128+
.product(name: "Logging", package: "swift-log"),
129+
.product(name: "NIOCore", package: "swift-nio"),
130+
]
131+
),
132+
.testTarget(name: "GDBRemoteProtocolTests", dependencies: ["GDBRemoteProtocol"]),
133+
],
134+
)
135+
136+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
137+
package.dependencies += [
138+
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.1"),
139+
.package(url: "https://github.com/apple/swift-system", from: "1.5.0"),
140+
.package(url: "https://github.com/apple/swift-nio", from: "2.86.2"),
141+
.package(url: "https://github.com/apple/swift-log", from: "1.6.4"),
142+
]
143+
} else {
144+
package.dependencies += [
145+
.package(path: "../swift-argument-parser"),
146+
.package(path: "../swift-system"),
147+
.package(path: "../swift-nio"),
148+
.package(path: "../swift-log"),
149+
]
150+
}
151+
152+
#if !os(Windows)
153+
// Add build tool plugins only for non-Windows platforms
154+
package.products.append(contentsOf: [
155+
.plugin(name: "WITOverlayPlugin", targets: ["WITOverlayPlugin"]),
156+
.plugin(name: "WITExtractorPlugin", targets: ["WITExtractorPlugin"]),
157+
])
158+
159+
package.targets.append(contentsOf: [
160+
.plugin(name: "WITOverlayPlugin", capability: .buildTool(), dependencies: ["WITTool"]),
161+
.plugin(name: "GenerateOverlayForTesting", capability: .buildTool(), dependencies: ["WITTool"]),
162+
.testTarget(
163+
name: "WITOverlayGeneratorTests",
164+
dependencies: ["WITOverlayGenerator", "WasmKit", "WasmKitWASI"],
165+
exclude: ["Fixtures", "Compiled", "Generated", "EmbeddedSupport"],
166+
plugins: [.plugin(name: "GenerateOverlayForTesting")]
167+
),
168+
.plugin(
169+
name: "WITExtractorPlugin",
170+
capability: .command(
171+
intent: .custom(verb: "extract-wit", description: "Extract WIT definition from Swift module"),
172+
permissions: []
173+
),
174+
dependencies: ["WITTool"]
175+
),
176+
.testTarget(
177+
name: "WITExtractorPluginTests",
178+
exclude: ["Fixtures"]
179+
),
180+
181+
.target(
182+
name: "WasmKitGDBHandler",
183+
dependencies: [
184+
.product(name: "_NIOFileSystem", package: "swift-nio"),
185+
.product(name: "NIOCore", package: "swift-nio"),
186+
.product(name: "SystemPackage", package: "swift-system"),
187+
"WasmKit",
188+
"WasmKitWASI",
189+
"GDBRemoteProtocol",
190+
],
191+
),
192+
])
193+
#endif

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@ $ swift test
9393
This project was originally developed by [@akkyie](https://github.com/akkyie), and is now maintained by the community.
9494

9595
[^1]: On a 2020 Mac mini (M1, 16GB RAM) with Swift 5.10. Measured by `swift package resolve && swift package clean && time swift build --product PrintAdd`.
96+
License
97+
98+
## License
99+
100+
WasmKit runtime modules are licensed under MIT License. See [LICENSE](https://raw.githubusercontent.com/swiftwasm/WasmKit/refs/heads/main/LICENSE) file for license information.
101+
102+
GDB Remote Protocol support (`GDBRemoteProtocol` and `WasmKitGDBHandler` modules) is licensed separately under Apache License v2.0 with Runtime Library Exception, Copyright 2025 Apple Inc. and the Swift project authors.
103+
104+
See https://swift.org/LICENSE.txt for license information.
105+
106+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors.

0 commit comments

Comments
 (0)