Run a virtual iPhone on an Apple Silicon Mac.
Swift
Add kernel GDB debug stub option and validation
Lakr8545dbd9bbc8
diff --git a/sources/vphone-cli/VPhoneAppDelegate.swift b/sources/vphone-cli/VPhoneAppDelegate.swiftindex 72fb6777..816ac804 100644--- a/sources/vphone-cli/VPhoneAppDelegate.swift+++ b/sources/vphone-cli/VPhoneAppDelegate.swift@@ -62,9 +62,10 @@ class VPhoneAppDelegate: NSObject, NSApplicationDelegate {print("Screen: \(cli.screenWidth)x\(cli.screenHeight) @ \(cli.screenPpi) PPI (scale \(cli.screenScale)x)")- print("SEP : enabled")- print(" storage: \(cli.sepStorage)")- print(" rom : \(cli.sepRom)")+ print("Kernel debug stub : 127.0.0.1:\(cli.kernelDebugPort)")+ print("SEP : enabled")+ print(" storage : \(cli.sepStorage)")+ print(" rom : \(cli.sepRom)")print("")let options = VPhoneVirtualMachine.Options(@@ -79,7 +80,8 @@ class VPhoneAppDelegate: NSObject, NSApplicationDelegate {screenWidth: cli.screenWidth,screenHeight: cli.screenHeight,screenPPI: cli.screenPpi,- screenScale: cli.screenScale+ screenScale: cli.screenScale,+ kernelDebugPort: cli.kernelDebugPort)let vm = try VPhoneVirtualMachine(options: options)diff --git a/sources/vphone-cli/VPhoneCLI.swift b/sources/vphone-cli/VPhoneCLI.swiftindex 2e6a22bb..d1a2f840 100644--- a/sources/vphone-cli/VPhoneCLI.swift+++ b/sources/vphone-cli/VPhoneCLI.swift@@ -58,6 +58,9 @@ struct VPhoneCLI: ParsableCommand {@Option(help: "Window scale divisor (default: 3.0)")var screenScale: Double = 3.0+ @Option(help: "Kernel GDB debug stub port on host (default: 5909)")+ var kernelDebugPort: Int = 5909+@Flag(help: "Run without GUI (headless)")var noGraphics: Bool = falsediff --git a/sources/vphone-cli/VPhoneError.swift b/sources/vphone-cli/VPhoneError.swiftindex 56b313cd..48f2e078 100644--- a/sources/vphone-cli/VPhoneError.swift+++ b/sources/vphone-cli/VPhoneError.swift@@ -4,6 +4,7 @@ enum VPhoneError: Error, CustomStringConvertible {case hardwareModelNotSupportedcase romNotFound(String)case diskNotFound(String)+ case invalidKernelDebugPort(Int)var description: String {switch self {@@ -19,6 +20,8 @@ enum VPhoneError: Error, CustomStringConvertible {"ROM not found: \(p)"case let .diskNotFound(p):"Disk image not found: \(p)"+ case let .invalidKernelDebugPort(port):+ "Invalid kernel debug port: \(port) (expected 1...65535)"}}}diff --git a/sources/vphone-cli/VPhoneMenuBattery.swift b/sources/vphone-cli/VPhoneMenuBattery.swiftindex bc36af84..292e3978 100644--- a/sources/vphone-cli/VPhoneMenuBattery.swift+++ b/sources/vphone-cli/VPhoneMenuBattery.swift@@ -67,7 +67,7 @@ extension VPhoneMenuController {var pastSeparator = falsefor mi in menu.items {if mi.isSeparatorItem { pastSeparator = true; continue }- if pastSeparator && mi.state == .on { return mi.tag }+ if pastSeparator, mi.state == .on { return mi.tag }}return 1}diff --git a/sources/vphone-cli/VPhoneVirtualMachine.swift b/sources/vphone-cli/VPhoneVirtualMachine.swiftindex 062dc7b0..bb03ac1d 100644--- a/sources/vphone-cli/VPhoneVirtualMachine.swift+++ b/sources/vphone-cli/VPhoneVirtualMachine.swift@@ -24,6 +24,7 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {var screenHeight: Int = 2796var screenPPI: Int = 460var screenScale: Double = 3.0+ var kernelDebugPort: Int = 5909}init(options: Options) throws {@@ -162,8 +163,19 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {print("[vphone] Synthetic battery configured (100%, charging)")}- // GDB debug stub (default init, system-assigned port)- Dynamic(config)._setDebugStub(Dynamic._VZGDBDebugStubConfiguration().asObject)+ guard (1 ... 65535).contains(options.kernelDebugPort) else {+ throw VPhoneError.invalidKernelDebugPort(options.kernelDebugPort)+ }++ // Kernel GDB debug stub (fixed host port for deterministic LLDB attach)+ let kernelDebugPort = options.kernelDebugPort+ if let kernelDebugStub = Dynamic._VZGDBDebugStubConfiguration(port: kernelDebugPort).asObject {+ Dynamic(config)._setDebugStub(kernelDebugStub)+ print("[vphone] Kernel GDB debug stub: tcp://127.0.0.1:\(kernelDebugPort)")+ } else {+ Dynamic(config)._setDebugStub(Dynamic._VZGDBDebugStubConfiguration().asObject)+ print("[vphone] Kernel GDB debug stub enabled (system-assigned port)")+ }// Coprocessorslet sepConfig = Dynamic._VZSEPCoprocessorConfiguration(storageURL: options.sepStorageURL)