[Lldb-commits] [lldb] r209852 - iOS simulator cleanup to make sure we use "*-apple-ios" for iOS simulator apps and binaries.

Greg Clayton gclayton at apple.com
Thu May 29 14:33:45 PDT 2014


Author: gclayton
Date: Thu May 29 16:33:45 2014
New Revision: 209852

URL: http://llvm.org/viewvc/llvm-project?rev=209852&view=rev
Log:
iOS simulator cleanup to make sure we use "*-apple-ios" for iOS simulator apps and binaries.

Changes include:
- ObjectFileMachO can now determine if a binary is "*-apple-ios" or "*-apple-macosx" by checking the min OS and SDK load commands
- ArchSpec now says "<arch>-apple-macosx" is equivalent to "<arch>-apple-ios" since the simulator mixes and matches binaries (some from the system and most from the iOS SDK).
- Getting process inforamtion on MacOSX now correctly classifies iOS simulator processes so they have "*-apple-ios" architectures in the ProcessInstanceInfo
- PlatformiOSSimulator can now list iOS simulator processes correctly instead of showing nothing by using:
    (lldb) platform select ios-simulator
    (lldb) platform process list
- debugserver can now properly return "*-apple-ios" for the triple in the process info packets for iOS simulator executables
- GDBRemoteCommunicationClient now correctly passes along the triples it gets for process info by setting the OS in the llvm::Triple correctly

<rdar://problem/17060217>


Modified:
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Host/macosx/Host.mm
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/tools/debugserver/source/RNBRemote.cpp

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Thu May 29 16:33:45 2014
@@ -844,10 +844,34 @@ ArchSpec::IsEqualTo (const ArchSpec& rhs
                 if (rhs_os_specified && lhs_os_specified)
                     return false;
             }
-            // Only fail if both os types are not unknown
-            if (lhs_triple_os != llvm::Triple::UnknownOS &&
-                rhs_triple_os != llvm::Triple::UnknownOS)
-                return false;
+            
+            bool ios_simulator_compatible = false;
+            // Check for iOS desktop simulator matches where:
+            // x86_64-apple-ios is compatible with x86_64-apple-macosx
+            // i386-apple-ios is compatible with i386-apple-macosx
+            if (lhs_triple_vendor == llvm::Triple::Apple)
+            {
+                const llvm::Triple::ArchType lhs_arch = lhs_triple.getArch();
+                if (lhs_arch == llvm::Triple::x86_64 ||
+                    lhs_arch == llvm::Triple::x86)
+                {
+                    if ((lhs_triple_os == llvm::Triple::MacOSX && rhs_triple_os == llvm::Triple::IOS    ) ||
+                        (lhs_triple_os == llvm::Triple::IOS    && rhs_triple_os == llvm::Triple::MacOSX ))
+                    {
+                        ios_simulator_compatible = true;
+                    }
+                        
+                }
+            }
+            
+            // Only fail if both os types are not unknown or if we determined the triples
+            // match for x86_64 or x86 iOS simulator
+            if (!ios_simulator_compatible)
+            {
+                if (lhs_triple_os != llvm::Triple::UnknownOS &&
+                    rhs_triple_os != llvm::Triple::UnknownOS)
+                    return false;
+            }
         }
 
         const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Thu May 29 16:33:45 2014
@@ -187,16 +187,46 @@ Module::Module (const ModuleSpec &module
     ModuleSpec matching_module_spec;
     if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
         return;
-    m_mod_time = module_spec.GetFileSpec().GetModificationTime();
-    if (module_spec.GetArchitecture().IsValid())
+    
+    if (module_spec.GetFileSpec())
+        m_mod_time = module_spec.GetFileSpec().GetModificationTime();
+    else if (matching_module_spec.GetFileSpec())
+        m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
+    
+    // Copy the architecture from the actual spec if we got one back, else use the one that was specified
+    if (matching_module_spec.GetArchitecture().IsValid())
+        m_arch = matching_module_spec.GetArchitecture();
+    else if (module_spec.GetArchitecture().IsValid())
         m_arch = module_spec.GetArchitecture();
+    
+    // Copy the file spec over and use the specfied one (if there was one) so we
+    // don't use a path that might have gotten resolved a path in 'matching_module_spec'
+    if (module_spec.GetFileSpec())
+        m_file = module_spec.GetFileSpec();
+    else if (matching_module_spec.GetFileSpec())
+        m_file = matching_module_spec.GetFileSpec();
+
+    // Copy the platform file spec over
+    if (module_spec.GetPlatformFileSpec())
+        m_platform_file = module_spec.GetPlatformFileSpec();
+    else if (matching_module_spec.GetPlatformFileSpec())
+        m_platform_file = matching_module_spec.GetPlatformFileSpec();
+    
+    // Copy the symbol file spec over
+    if (module_spec.GetSymbolFileSpec())
+        m_symfile_spec = module_spec.GetSymbolFileSpec();
+    else if (matching_module_spec.GetSymbolFileSpec())
+        m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
+    
+    // Copy the object name over
+    if (matching_module_spec.GetObjectName())
+        m_object_name = matching_module_spec.GetObjectName();
     else
-        m_arch = matching_module_spec.GetArchitecture();
-    m_mod_time = module_spec.GetFileSpec().GetModificationTime();
-    m_file = module_spec.GetFileSpec();
-    m_platform_file = module_spec.GetPlatformFileSpec();
-    m_symfile_spec = module_spec.GetSymbolFileSpec();
-    m_object_name = module_spec.GetObjectName();
+        m_object_name = module_spec.GetObjectName();
+    
+    // Always trust the object offset (file offset) and object modification
+    // time (for mod time in a BSD static archive) of from the matching
+    // module specification
     m_object_offset = matching_module_spec.GetObjectOffset();
     m_object_mod_time = matching_module_spec.GetObjectModificationTime();
     

Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Thu May 29 16:33:45 2014
@@ -1151,6 +1151,11 @@ GetMacOSXProcessArgs (const ProcessInsta
             uint32_t argc = data.GetU32 (&offset);
             const char *cstr;
             
+            
+            llvm::Triple &triple = process_info.GetArchitecture().GetTriple();
+            const llvm::Triple::ArchType triple_arch = triple.getArch();
+            const bool check_for_ios_simulator = (triple_arch == llvm::Triple::x86 || triple_arch == llvm::Triple::x86_64);
+            
             cstr = data.GetCStr (&offset);
             if (cstr)
             {
@@ -1177,6 +1182,21 @@ GetMacOSXProcessArgs (const ProcessInsta
                         if (cstr)
                             proc_args.AppendArgument(cstr);
                     }
+                    
+                    Args &proc_env = process_info.GetEnvironmentEntries ();
+                    while ((cstr = data.GetCStr(&offset)))
+                    {
+                        if (cstr[0] == '\0')
+                            break;
+                        
+                        if (check_for_ios_simulator)
+                        {
+                            if (strncmp(cstr, "SIMULATOR_UDID=", strlen("SIMULATOR_UDID=")) == 0)
+                                process_info.GetArchitecture().GetTriple().setOS(llvm::Triple::IOS);
+                        }
+
+                        proc_env.AppendArgument(cstr);
+                    }
                     return true;
                 }
             }
@@ -1285,11 +1305,14 @@ Host::FindProcesses (const ProcessInstan
         // Make sure our info matches before we go fetch the name and cpu type
         if (match_info.Matches (process_info))
         {
-            if (GetMacOSXProcessArgs (&match_info, process_info))
+            // Get CPU type first so we can know to look for iOS simulator is we have x86 or x86_64
+            if (GetMacOSXProcessCPUType (process_info))
             {
-                GetMacOSXProcessCPUType (process_info);
-                if (match_info.Matches (process_info))
-                    process_infos.Append (process_info);
+                if (GetMacOSXProcessArgs (&match_info, process_info))
+                {
+                    if (match_info.Matches (process_info))
+                        process_infos.Append (process_info);
+                }
             }
         }
     }    
@@ -1301,11 +1324,12 @@ Host::GetProcessInfo (lldb::pid_t pid, P
 {
     process_info.SetProcessID(pid);
     bool success = false;
-    
-    if (GetMacOSXProcessArgs (NULL, process_info))
+
+    // Get CPU type first so we can know to look for iOS simulator is we have x86 or x86_64
+    if (GetMacOSXProcessCPUType (process_info))
         success = true;
     
-    if (GetMacOSXProcessCPUType (process_info))
+    if (GetMacOSXProcessArgs (NULL, process_info))
         success = true;
     
     if (GetMacOSXProcessUserAndGroup (process_info))

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu May 29 16:33:45 2014
@@ -647,18 +647,15 @@ ObjectFileMachO::GetModuleSpecifications
             {
                 ModuleSpec spec;
                 spec.GetFileSpec() = file;
-                spec.GetArchitecture().SetArchitecture(eArchTypeMachO,
-                                                       header.cputype,
-                                                       header.cpusubtype);
-                if (header.filetype == MH_PRELOAD) // 0x5u
-                {
-                    // Set OS to "unknown" - this is a standalone binary with no dyld et al
-                    spec.GetArchitecture().GetTriple().setOS (llvm::Triple::UnknownOS);
-                }
-                if (spec.GetArchitecture().IsValid())
+                spec.SetObjectOffset(file_offset);
+                
+                if (GetArchitecture (header, data, data_offset, spec.GetArchitecture()))
                 {
-                    GetUUID (header, data, data_offset, spec.GetUUID());
-                    specs.Append(spec);
+                    if (spec.GetArchitecture().IsValid())
+                    {
+                        GetUUID (header, data, data_offset, spec.GetUUID());
+                        specs.Append(spec);
+                    }
                 }
             }
         }
@@ -854,36 +851,40 @@ ObjectFileMachO::ParseHeader ()
         {
             m_data.GetU32(&offset, &m_header.cputype, 6);
 
-            ArchSpec mach_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
-
-            // Check if the module has a required architecture
-            const ArchSpec &module_arch = module_sp->GetArchitecture();
-            if (module_arch.IsValid() && !module_arch.IsCompatibleMatch(mach_arch))
-                return false;
-
-            if (SetModulesArchitecture (mach_arch))
+            
+            ArchSpec mach_arch;
+            
+            if (GetArchitecture (mach_arch))
             {
-                const size_t header_and_lc_size = m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic);
-                if (m_data.GetByteSize() < header_and_lc_size)
+                // Check if the module has a required architecture
+                const ArchSpec &module_arch = module_sp->GetArchitecture();
+                if (module_arch.IsValid() && !module_arch.IsCompatibleMatch(mach_arch))
+                    return false;
+
+                if (SetModulesArchitecture (mach_arch))
                 {
-                    DataBufferSP data_sp;
-                    ProcessSP process_sp (m_process_wp.lock());
-                    if (process_sp)
-                    {
-                        data_sp = ReadMemory (process_sp, m_memory_addr, header_and_lc_size);
-                    }
-                    else
+                    const size_t header_and_lc_size = m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic);
+                    if (m_data.GetByteSize() < header_and_lc_size)
                     {
-                        // Read in all only the load command data from the file on disk
-                        data_sp = m_file.ReadFileContents(m_file_offset, header_and_lc_size);
-                        if (data_sp->GetByteSize() != header_and_lc_size)
-                            return false;
+                        DataBufferSP data_sp;
+                        ProcessSP process_sp (m_process_wp.lock());
+                        if (process_sp)
+                        {
+                            data_sp = ReadMemory (process_sp, m_memory_addr, header_and_lc_size);
+                        }
+                        else
+                        {
+                            // Read in all only the load command data from the file on disk
+                            data_sp = m_file.ReadFileContents(m_file_offset, header_and_lc_size);
+                            if (data_sp->GetByteSize() != header_and_lc_size)
+                                return false;
+                        }
+                        if (data_sp)
+                            m_data.SetData (data_sp);
                     }
-                    if (data_sp)
-                        m_data.SetData (data_sp);
                 }
+                return true;
             }
-            return true;
         }
         else
         {
@@ -2182,7 +2183,8 @@ ObjectFileMachO::ParseSymtab ()
 
             // Next we need to determine the correct path for the dyld shared cache.
 
-            ArchSpec header_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
+            ArchSpec header_arch;
+            GetArchitecture(header_arch);
             char dsc_path[PATH_MAX];
 
             snprintf(dsc_path, sizeof(dsc_path), "%s%s%s",
@@ -4098,7 +4100,8 @@ ObjectFileMachO::Dump (Stream *s)
         else
             s->PutCString("ObjectFileMachO32");
 
-        ArchSpec header_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
+        ArchSpec header_arch;
+        GetArchitecture(header_arch);
 
         *s << ", file = '" << m_file << "', arch = " << header_arch.GetArchitectureName() << "\n";
 
@@ -4155,6 +4158,61 @@ ObjectFileMachO::GetUUID (const llvm::Ma
     return false;
 }
 
+
+bool
+ObjectFileMachO::GetArchitecture (const llvm::MachO::mach_header &header,
+                                  const lldb_private::DataExtractor &data,
+                                  lldb::offset_t lc_offset,
+                                  ArchSpec &arch)
+{
+    arch.SetArchitecture (eArchTypeMachO, header.cputype, header.cpusubtype);
+
+    if (arch.IsValid())
+    {
+        llvm::Triple &triple = arch.GetTriple();
+        if (header.filetype == MH_PRELOAD)
+        {
+            // Set OS to "unknown" - this is a standalone binary with no dyld et al
+            triple.setOS(llvm::Triple::UnknownOS);
+            return true;
+        }
+        else
+        {
+            struct load_command load_cmd;
+            
+            lldb::offset_t offset = lc_offset;
+            for (uint32_t i=0; i<header.ncmds; ++i)
+            {
+                const lldb::offset_t cmd_offset = offset;
+                if (data.GetU32(&offset, &load_cmd, 2) == NULL)
+                    break;
+                
+                switch (load_cmd.cmd)
+                {
+                    case LC_VERSION_MIN_IPHONEOS:
+                        triple.setOS (llvm::Triple::IOS);
+                        return true;
+                        
+                    case LC_VERSION_MIN_MACOSX:
+                        triple.setOS (llvm::Triple::MacOSX);
+                        return true;
+                        
+                    default:
+                        break;
+                }
+
+                offset = cmd_offset + load_cmd.cmdsize;
+            }
+            
+            if (header.cputype == CPU_TYPE_ARM || header.cputype == CPU_TYPE_ARM64)
+                triple.setOS (llvm::Triple::IOS);
+            else
+                triple.setOS (llvm::Triple::MacOSX);
+        }
+    }
+    return arch.IsValid();
+}
+
 bool
 ObjectFileMachO::GetUUID (lldb_private::UUID* uuid)
 {
@@ -4627,16 +4685,7 @@ ObjectFileMachO::GetArchitecture (ArchSp
     if (module_sp)
     {
         lldb_private::Mutex::Locker locker(module_sp->GetMutex());
-        arch.SetArchitecture (eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
-
-        // Files with type MH_PRELOAD are currently used in cases where the image
-        // debugs at the addresses in the file itself. Below we set the OS to
-        // unknown to make sure we use the DynamicLoaderStatic()...
-        if (m_header.filetype == MH_PRELOAD)
-        {
-            arch.GetTriple().setOS (llvm::Triple::UnknownOS);
-        }
-        return true;
+        return GetArchitecture (m_header, m_data, MachHeaderSizeFromMagic(m_header.magic), arch);
     }
     return false;
 }

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h Thu May 29 16:33:45 2014
@@ -182,6 +182,12 @@ protected:
              lldb::offset_t lc_offset, // Offset to the first load command
              lldb_private::UUID& uuid);
     
+    static bool
+    GetArchitecture (const llvm::MachO::mach_header &header,
+                     const lldb_private::DataExtractor &data,
+                     lldb::offset_t lc_offset,
+                     lldb_private::ArchSpec &arch);
+
     // Intended for same-host arm device debugging where lldb needs to
     // detect libraries in the shared cache and augment the nlist entries
     // with an on-disk dyld_shared_cache file.  The process will record

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp Thu May 29 16:33:45 2014
@@ -397,30 +397,63 @@ uint32_t
 PlatformiOSSimulator::FindProcesses (const ProcessInstanceInfoMatch &match_info,
                                      ProcessInstanceInfoList &process_infos)
 {
-    // TODO: if connected, send a packet to get the remote process infos by name
-    process_infos.Clear();
-    return 0;
+    ProcessInstanceInfoList all_osx_process_infos;
+    // First we get all OSX processes
+    const uint32_t n = Host::FindProcesses (match_info, all_osx_process_infos);
+
+    // Now we filter them down to only the iOS triples
+    for (uint32_t i=0; i<n; ++i)
+    {
+        const ProcessInstanceInfo &proc_info = all_osx_process_infos.GetProcessInfoAtIndex(i);
+        if (proc_info.GetArchitecture().GetTriple().getOS() == llvm::Triple::IOS) {
+            process_infos.Append(proc_info);
+        }
+    }
+    return process_infos.GetSize();
 }
 
 bool
 PlatformiOSSimulator::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
 {
+    static const ArchSpec platform_arch (Host::GetArchitecture (Host::eSystemDefaultArchitecture));
+    static const ArchSpec platform_arch64 (Host::GetArchitecture (Host::eSystemDefaultArchitecture64));
+
     if (idx == 0)
     {
-        arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
-        return arch.IsValid();
+        arch = platform_arch;
+        if (arch.IsValid())
+        {
+            arch.GetTriple().setOS (llvm::Triple::IOS);
+            return true;
+        }
     }
-    else if (idx == 1)
+    else
     {
-        ArchSpec platform_arch (Host::GetArchitecture (Host::eSystemDefaultArchitecture));
-        ArchSpec platform_arch64 (Host::GetArchitecture (Host::eSystemDefaultArchitecture64));
         if (platform_arch.IsExactMatch(platform_arch64))
         {
-            // This macosx platform supports both 32 and 64 bit. Since we already
-            // returned the 64 bit arch for idx == 0, return the 32 bit arch 
-            // for idx == 1
-            arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
-            return arch.IsValid();
+            // This macosx platform supports both 32 and 64 bit.
+            if (idx == 1)
+            {
+                // 32/64: return "x86_64-apple-macosx" for architecture 1
+                arch = platform_arch64;
+            }
+            else if (idx == 2 || idx == 3)
+            {
+                arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
+                if (arch.IsValid())
+                {
+                    if (idx == 2)
+                        arch.GetTriple().setOS (llvm::Triple::IOS);
+                    // 32/64: return "i386-apple-ios" for architecture 2
+                    // 32/64: return "i386-apple-macosx" for architecture 3
+                    return true;
+                }
+            }
+        }
+        else if (idx == 1)
+        {
+            // This macosx platform supports only 32 bit, so return the *-apple-macosx version
+            arch = platform_arch;
         }
     }
     return false;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Thu May 29 16:33:45 2014
@@ -2440,10 +2440,11 @@ GDBRemoteCommunicationClient::GetCurrent
                 {
                     assert (pointer_byte_size == m_process_arch.GetAddressByteSize());
                 }
+                m_process_arch.GetTriple().setOSName(llvm::StringRef (os_name));
                 m_host_arch.GetTriple().setVendorName (llvm::StringRef (vendor_name));
                 m_host_arch.GetTriple().setOSName (llvm::StringRef (os_name));
-                return true;
             }
+            return true;
         }
     }
     else

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=209852&r1=209851&r2=209852&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Thu May 29 16:33:45 2014
@@ -21,6 +21,7 @@
 #include <sys/sysctl.h>
 
 #include "DNB.h"
+#include "DNBDataRef.h"
 #include "DNBLog.h"
 #include "DNBThreadResumeActions.h"
 #include "RNBContext.h"
@@ -4047,7 +4048,60 @@ RNBRemote::HandlePacket_qProcessInfo (co
     if (cputype == CPU_TYPE_ARM || cputype == CPU_TYPE_ARM64)
         rep << "ostype:ios;";
     else
-        rep << "ostype:macosx;";
+    {
+        bool is_ios_simulator = false;
+        if (cputype == CPU_TYPE_X86 || cputype == CPU_TYPE_X86_64)
+        {
+            // Check for iOS simulator binaries by getting the process argument
+            // and environment and checking for SIMULATOR_UDID in the environment
+            int proc_args_mib[3] = { CTL_KERN, KERN_PROCARGS2, (int)pid };
+            
+            uint8_t arg_data[8192];
+            size_t arg_data_size = sizeof(arg_data);
+            if (::sysctl (proc_args_mib, 3, arg_data, &arg_data_size , NULL, 0) == 0)
+            {
+                DNBDataRef data (arg_data, arg_data_size, false);
+                DNBDataRef::offset_t offset = 0;
+                uint32_t argc = data.Get32 (&offset);
+                const char *cstr;
+                
+                cstr = data.GetCStr (&offset);
+                if (cstr)
+                {
+                    // Skip NULLs
+                    while (1)
+                    {
+                        const char *p = data.PeekCStr(offset);
+                        if ((p == NULL) || (*p != '\0'))
+                            break;
+                        ++offset;
+                    }
+                    // Now skip all arguments
+                    for (int i=0; i<static_cast<int>(argc); ++i)
+                    {
+                        cstr = data.GetCStr(&offset);
+                    }
+                    
+                    // Now iterate across all environment variables
+                    while ((cstr = data.GetCStr(&offset)))
+                    {
+                        if (strncmp(cstr, "SIMULATOR_UDID=", strlen("SIMULATOR_UDID=")) == 0)
+                        {
+                            is_ios_simulator = true;
+                            break;
+                        }
+                        if (cstr[0] == '\0')
+                            break;
+                        
+                    }
+                }
+            }
+        }
+        if (is_ios_simulator)
+            rep << "ostype:ios;";
+        else
+            rep << "ostype:macosx;";
+    }
 
     rep << "vendor:apple;";
 





More information about the lldb-commits mailing list