Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -2129,12 +2129,24 @@ if (byte_order != eByteOrderInvalid) { assert(byte_order == m_process_arch.GetByteOrder()); } - m_process_arch.GetTriple().setVendorName(llvm::StringRef(vendor_name)); - m_process_arch.GetTriple().setOSName(llvm::StringRef(os_name)); - m_process_arch.GetTriple().setEnvironmentName(llvm::StringRef(environment)); - m_host_arch.GetTriple().setVendorName(llvm::StringRef(vendor_name)); - m_host_arch.GetTriple().setOSName(llvm::StringRef(os_name)); - m_host_arch.GetTriple().setEnvironmentName(llvm::StringRef(environment)); + auto &process_triple = m_process_arch.GetTriple(); + process_triple.setVendorName(llvm::StringRef(vendor_name)); + process_triple.setOSName(llvm::StringRef(os_name)); + process_triple.setEnvironmentName(llvm::StringRef(environment)); + + // Detect iOS simulators and set the environment + // accordingly. The remote server reads the process info out + // of the Mach-O load commands, which don't distinguish + // between simulator and the real hardware. + if (m_host_arch.GetTriple().getOS() == llvm::Triple::MacOSX) { + if (!process_triple.hasEnvironment()) { + auto process_os = process_triple.getOS(); + if (process_os == llvm::Triple::IOS || + process_os == llvm::Triple::TvOS || + process_os == llvm::Triple::WatchOS) + process_triple.setEnvironment(llvm::Triple::Simulator); + } + } } return true; } Index: lldb/test/API/functionalities/gdb_remote_client/TestIOSSimulator.py =================================================================== --- /dev/null +++ lldb/test/API/functionalities/gdb_remote_client/TestIOSSimulator.py @@ -0,0 +1,32 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from gdbclientutils import * + +class TestIOSSimulator(GDBRemoteTestBase): + + @skipIfRemote + def test(self): + """ + Test that an ios simulator process is recognized as such. + """ + class MyResponder(MockGDBServerResponder): + + def qHostInfo(self): + return "cputype:16777223;cpusubtype:8;ostype:macosx;watchpoint_exceptions_received:after;vendor:apple;os_version:10.15.4;maccatalyst_version:13.4;endian:little;ptrsize:8;" + def qProcessInfo(self): + return "pid:a860;parent-pid:d2a0;real-uid:1f5;real-gid:14;effective-uid:1f5;effective-gid:14;cputype:1000007;cpusubtype:8;ptrsize:8;ostype:ios;vendor:apple;endian:little;" + def vCont(self): + return "vCont;" + + self.server.responder = MyResponder() + if self.TraceOn(): + self.runCmd("log enable gdb-remote packets") + self.addTearDownHook( + lambda: self.runCmd("log disable gdb-remote packets")) + + #self.dbg.SetDefaultArchitecture("armv7em") + target = self.dbg.CreateTargetWithFileAndArch(None, None) + process = self.connect(target) + triple = target.GetTriple() + self.assertEqual(triple, "x86_64h-apple-ios-simulator") Index: lldb/test/API/functionalities/gdb_remote_client/TestWasm.py =================================================================== --- lldb/test/API/functionalities/gdb_remote_client/TestWasm.py +++ lldb/test/API/functionalities/gdb_remote_client/TestWasm.py @@ -31,8 +31,6 @@ MockGDBServerResponder.__init__(self) def respond(self, packet): - if packet == "qProcessInfo": - return self.qProcessInfo() if packet[0:13] == "qRegisterInfo": return self.qRegisterInfo(packet[13:]) return MockGDBServerResponder.respond(self, packet) Index: lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py =================================================================== --- lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py +++ lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py @@ -170,6 +170,8 @@ return self.qQueryGDBServer() if packet == "qHostInfo": return self.qHostInfo() + if packet == "qProcessInfo": + return self.qProcessInfo() if packet == "qGetWorkingDir": return self.qGetWorkingDir() if packet == "qOffsets": @@ -196,6 +198,9 @@ def qHostInfo(self): return "ptrsize:8;endian:little;" + def qProcessInfo(self): + return "pid:1;ptrsize:8;endian:little;" + def qQueryGDBServer(self): return "E04"