xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XKit / Installation / Debugger.swift
Debugger.swift35 lines · 978 BRaw
| 1 | // |
| 2 | // Debugger.swift |
| 3 | // XKit |
| 4 | // |
| 5 | // Created by Kabir Oberai on 26/03/21. |
| 6 | // Copyright © 2021 Kabir Oberai. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import Foundation |
| 10 | import SwiftyMobileDevice |
| 11 | |
| 12 | public actor Debugger { |
| 13 | |
| 14 | private let client: DebugserverClient |
| 15 | public init(connection: Connection) async throws { |
| 16 | client = try await connection.startClient() |
| 17 | try client.send(command: "QSetMaxPacketSize:", arguments: ["1024"]) |
| 18 | } |
| 19 | |
| 20 | public enum Error: Swift.Error { |
| 21 | case userCancelled |
| 22 | } |
| 23 | |
| 24 | // if the receiver is released before the completion handler is called, the |
| 25 | // method will fail with `Debugger.Error.userCancelled` |
| 26 | public func attach(toProcess process: String) async throws { |
| 27 | var resp: Data |
| 28 | repeat { |
| 29 | try Task.checkCancellation() |
| 30 | resp = try self.client.send(command: "vAttachWait;", arguments: [process]) |
| 31 | } while resp.isEmpty |
| 32 | try self.client.send(command: "D", arguments: []) |
| 33 | } |
| 34 | |
| 35 | } |