|
48 | 48 | case unknownHexEncodedArguments(String) |
49 | 49 | case unknownWasmLocalArguments(String) |
50 | 50 | case unknownWasmGlobalArguments(String) |
| 51 | + case unknownDetachOnErrorArgument(String) |
51 | 52 | } |
52 | 53 |
|
53 | 54 | private let moduleFilePath: String |
|
62 | 63 | private var userBreakpoints: [Int: Int] = [:] |
63 | 64 | private let wasi: WASIBridgeToHost |
64 | 65 |
|
| 66 | + /// Whether a client that goes away without `k` or `D` leaves the guest running to |
| 67 | + /// completion, as `QSetDetachOnError` selects. |
| 68 | + package private(set) var detachesOnDisconnect = true |
| 69 | + |
65 | 70 | /// Creates a handler debugging the given WebAssembly binary. |
66 | 71 | /// |
67 | 72 | /// The handler is transport- and file-system-free: the caller supplies |
|
128 | 133 | try wasi.close() |
129 | 134 | } |
130 | 135 |
|
| 136 | + /// Lets the guest run to completion, as `D` asks for. The resume is blocking, so a guest |
| 137 | + /// that never terminates keeps the caller here. |
| 138 | + package func detach() throws { |
| 139 | + self.debugger.removeAllBreakpoints() |
| 140 | + self.userBreakpoints.removeAll() |
| 141 | + |
| 142 | + // Resuming a guest that already returned would be a restart, which is unimplemented. |
| 143 | + guard case .stoppedAtBreakpoint = self.debugger.state else { return } |
| 144 | + |
| 145 | + try self.debugger.run() |
| 146 | + } |
| 147 | + |
131 | 148 | enum Endianness { |
132 | 149 | case big, little |
133 | 150 | } |
|
235 | 252 | .symbolLookup, .jsonThreadsInfo, .jsonThreadExtendedInfo: |
236 | 253 | responseKind = .empty |
237 | 254 |
|
| 255 | + case .setDetachOnError: |
| 256 | + switch command.arguments { |
| 257 | + case "0": |
| 258 | + self.detachesOnDisconnect = false |
| 259 | + case "1": |
| 260 | + self.detachesOnDisconnect = true |
| 261 | + default: |
| 262 | + throw Error.unknownDetachOnErrorArgument(command.arguments) |
| 263 | + } |
| 264 | + |
| 265 | + responseKind = .ok |
| 266 | + |
238 | 267 | case .processInfo: |
239 | 268 | responseKind = .keyValuePairs([ |
240 | 269 | ("pid", "1"), |
|
341 | 370 | throw Error.killRequestReceived |
342 | 371 |
|
343 | 372 | case .detach: |
344 | | - self.debugger.removeAllBreakpoints() |
345 | | - self.userBreakpoints.removeAll() |
346 | | - |
347 | | - try self.debugger.run() |
| 373 | + try self.detach() |
348 | 374 | throw Error.killRequestReceived |
349 | 375 |
|
350 | 376 | case .insertSoftwareBreakpoint: |
|
0 commit comments