1 //===-- PlatformRemoteiOS.cpp -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "PlatformRemoteiOS.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Breakpoint/BreakpointLocation.h"
17 #include "lldb/Core/ArchSpec.h"
18 #include "lldb/Core/Error.h"
19 #include "lldb/Core/Module.h"
20 #include "lldb/Core/ModuleList.h"
21 #include "lldb/Core/ModuleSpec.h"
22 #include "lldb/Core/PluginManager.h"
23 #include "lldb/Core/StreamString.h"
24 #include "lldb/Host/FileSpec.h"
25 #include "lldb/Host/Host.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Target/Target.h"
28 
29 using namespace lldb;
30 using namespace lldb_private;
31 
32 PlatformRemoteiOS::SDKDirectoryInfo::SDKDirectoryInfo (const lldb_private::FileSpec &sdk_dir) :
33     directory(sdk_dir),
34     build(),
35     version_major(0),
36     version_minor(0),
37     version_update(0),
38     user_cached(false)
39 {
40     const char *dirname_cstr = sdk_dir.GetFilename().GetCString();
41     const char *pos = Args::StringToVersion (dirname_cstr,
42                                              version_major,
43                                              version_minor,
44                                              version_update);
45 
46     if (pos && pos[0] == ' ' && pos[1] == '(')
47     {
48         const char *build_start = pos + 2;
49         const char *end_paren = strchr (build_start, ')');
50         if (end_paren && build_start < end_paren)
51             build.SetCStringWithLength(build_start, end_paren - build_start);
52     }
53 }
54 
55 //------------------------------------------------------------------
56 // Static Variables
57 //------------------------------------------------------------------
58 static uint32_t g_initialize_count = 0;
59 
60 //------------------------------------------------------------------
61 // Static Functions
62 //------------------------------------------------------------------
63 void
64 PlatformRemoteiOS::Initialize ()
65 {
66     if (g_initialize_count++ == 0)
67     {
68         PluginManager::RegisterPlugin (PlatformRemoteiOS::GetShortPluginNameStatic(),
69                                        PlatformRemoteiOS::GetDescriptionStatic(),
70                                        PlatformRemoteiOS::CreateInstance);
71     }
72 }
73 
74 void
75 PlatformRemoteiOS::Terminate ()
76 {
77     if (g_initialize_count > 0)
78     {
79         if (--g_initialize_count == 0)
80         {
81             PluginManager::UnregisterPlugin (PlatformRemoteiOS::CreateInstance);
82         }
83     }
84 }
85 
86 Platform*
87 PlatformRemoteiOS::CreateInstance (bool force, const ArchSpec *arch)
88 {
89     bool create = force;
90     if (create == false && arch && arch->IsValid())
91     {
92         switch (arch->GetMachine())
93         {
94         case llvm::Triple::arm:
95         case llvm::Triple::thumb:
96             {
97                 const llvm::Triple &triple = arch->GetTriple();
98                 llvm::Triple::VendorType vendor = triple.getVendor();
99                 switch (vendor)
100                 {
101                     case llvm::Triple::Apple:
102                         create = true;
103                         break;
104 
105 #if defined(__APPLE__)
106                     // Only accept "unknown" for the vendor if the host is Apple and
107                     // it "unknown" wasn't specified (it was just returned becasue it
108                     // was NOT specified)
109                     case llvm::Triple::UnknownArch:
110                         create = !arch->TripleVendorWasSpecified();
111                         break;
112 
113 #endif
114                     default:
115                         break;
116                 }
117                 if (create)
118                 {
119                     switch (triple.getOS())
120                     {
121                         case llvm::Triple::Darwin:  // Deprecated, but still support Darwin for historical reasons
122                         case llvm::Triple::IOS:     // This is the right triple value for iOS debugging
123                             break;
124 
125 #if defined(__APPLE__)
126                         // Only accept "unknown" for the OS if the host is Apple and
127                         // it "unknown" wasn't specified (it was just returned becasue it
128                         // was NOT specified)
129                         case llvm::Triple::UnknownOS:
130                             create = !arch->TripleOSWasSpecified();
131                             break;
132 #endif
133                         default:
134                             create = false;
135                             break;
136                     }
137                 }
138             }
139             break;
140         default:
141             break;
142         }
143     }
144 
145     if (create)
146         return new PlatformRemoteiOS ();
147     return NULL;
148 }
149 
150 
151 const char *
152 PlatformRemoteiOS::GetPluginNameStatic ()
153 {
154     return "PlatformRemoteiOS";
155 }
156 
157 const char *
158 PlatformRemoteiOS::GetShortPluginNameStatic()
159 {
160     return "remote-ios";
161 }
162 
163 const char *
164 PlatformRemoteiOS::GetDescriptionStatic()
165 {
166     return "Remote iOS platform plug-in.";
167 }
168 
169 
170 //------------------------------------------------------------------
171 /// Default Constructor
172 //------------------------------------------------------------------
173 PlatformRemoteiOS::PlatformRemoteiOS () :
174     PlatformDarwin (false),    // This is a remote platform
175     m_sdk_directory_infos(),
176     m_device_support_directory(),
177     m_device_support_directory_for_os_version (),
178     m_build_update(),
179     m_last_module_sdk_idx(UINT32_MAX)
180 {
181 }
182 
183 //------------------------------------------------------------------
184 /// Destructor.
185 ///
186 /// The destructor is virtual since this class is designed to be
187 /// inherited from by the plug-in instance.
188 //------------------------------------------------------------------
189 PlatformRemoteiOS::~PlatformRemoteiOS()
190 {
191 }
192 
193 
194 void
195 PlatformRemoteiOS::GetStatus (Stream &strm)
196 {
197     Platform::GetStatus (strm);
198     const char *sdk_directory = GetDeviceSupportDirectoryForOSVersion();
199     if (sdk_directory)
200         strm.Printf ("  SDK Path: \"%s\"\n", sdk_directory);
201     else
202         strm.PutCString ("  SDK Path: error: unable to locate SDK\n");
203 
204     const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
205     for (uint32_t i=0; i<num_sdk_infos; ++i)
206     {
207         const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i];
208         strm.Printf (" SDK Roots: [%2u] \"%s/%s\"\n",
209                      i,
210                      sdk_dir_info.directory.GetDirectory().GetCString(),
211                      sdk_dir_info.directory.GetFilename().GetCString());
212     }
213 }
214 
215 
216 Error
217 PlatformRemoteiOS::ResolveExecutable (const FileSpec &exe_file,
218                                       const ArchSpec &exe_arch,
219                                       lldb::ModuleSP &exe_module_sp,
220                                       const FileSpecList *module_search_paths_ptr)
221 {
222     Error error;
223     // Nothing special to do here, just use the actual file and architecture
224 
225     FileSpec resolved_exe_file (exe_file);
226 
227     // If we have "ls" as the exe_file, resolve the executable loation based on
228     // the current path variables
229     // TODO: resolve bare executables in the Platform SDK
230 //    if (!resolved_exe_file.Exists())
231 //        resolved_exe_file.ResolveExecutableLocation ();
232 
233     // Resolve any executable within a bundle on MacOSX
234     // TODO: verify that this handles shallow bundles, if not then implement one ourselves
235     Host::ResolveExecutableInBundle (resolved_exe_file);
236 
237     if (resolved_exe_file.Exists())
238     {
239         if (exe_arch.IsValid())
240         {
241             ModuleSpec module_spec (resolved_exe_file, exe_arch);
242             error = ModuleList::GetSharedModule (module_spec,
243                                                  exe_module_sp,
244                                                  NULL,
245                                                  NULL,
246                                                  NULL);
247 
248             if (exe_module_sp && exe_module_sp->GetObjectFile())
249                 return error;
250             exe_module_sp.reset();
251         }
252         // No valid architecture was specified or the exact ARM slice wasn't
253         // found so ask the platform for the architectures that we should be
254         // using (in the correct order) and see if we can find a match that way
255         StreamString arch_names;
256         ArchSpec platform_arch;
257         for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, platform_arch); ++idx)
258         {
259             ModuleSpec module_spec (resolved_exe_file, platform_arch);
260             error = ModuleList::GetSharedModule (module_spec,
261                                                  exe_module_sp,
262                                                  NULL,
263                                                  NULL,
264                                                  NULL);
265             // Did we find an executable using one of the
266             if (error.Success())
267             {
268                 if (exe_module_sp && exe_module_sp->GetObjectFile())
269                     break;
270                 else
271                     error.SetErrorToGenericError();
272             }
273 
274             if (idx > 0)
275                 arch_names.PutCString (", ");
276             arch_names.PutCString (platform_arch.GetArchitectureName());
277         }
278 
279         if (error.Fail() || !exe_module_sp)
280         {
281             error.SetErrorStringWithFormat ("'%s%s%s' doesn't contain any '%s' platform architectures: %s",
282                                             exe_file.GetDirectory().AsCString(""),
283                                             exe_file.GetDirectory() ? "/" : "",
284                                             exe_file.GetFilename().AsCString(""),
285                                             GetShortPluginName(),
286                                             arch_names.GetString().c_str());
287         }
288     }
289     else
290     {
291         error.SetErrorStringWithFormat ("'%s%s%s' does not exist",
292                                         exe_file.GetDirectory().AsCString(""),
293                                         exe_file.GetDirectory() ? "/" : "",
294                                         exe_file.GetFilename().AsCString(""));
295     }
296 
297     return error;
298 }
299 
300 FileSpec::EnumerateDirectoryResult
301 PlatformRemoteiOS::GetContainedFilesIntoVectorOfStringsCallback (void *baton,
302                                                                  FileSpec::FileType file_type,
303                                                                  const FileSpec &file_spec)
304 {
305     ((PlatformRemoteiOS::SDKDirectoryInfoCollection *)baton)->push_back(PlatformRemoteiOS::SDKDirectoryInfo(file_spec));
306     return FileSpec::eEnumerateDirectoryResultNext;
307 }
308 
309 bool
310 PlatformRemoteiOS::UpdateSDKDirectoryInfosInNeeded()
311 {
312     if (m_sdk_directory_infos.empty())
313     {
314         const char *device_support_dir = GetDeviceSupportDirectory();
315         if (device_support_dir)
316         {
317             const bool find_directories = true;
318             const bool find_files = false;
319             const bool find_other = false;
320             FileSpec::EnumerateDirectory (m_device_support_directory.c_str(),
321                                           find_directories,
322                                           find_files,
323                                           find_other,
324                                           GetContainedFilesIntoVectorOfStringsCallback,
325                                           &m_sdk_directory_infos);
326 
327             const uint32_t num_installed = m_sdk_directory_infos.size();
328             FileSpec local_sdk_cache("~/Library/Developer/Xcode/iOS DeviceSupport", true);
329             if (local_sdk_cache.Exists())
330             {
331                 char path[PATH_MAX];
332                 if (local_sdk_cache.GetPath(path, sizeof(path)))
333                 {
334                     FileSpec::EnumerateDirectory (path,
335                                                   find_directories,
336                                                   find_files,
337                                                   find_other,
338                                                   GetContainedFilesIntoVectorOfStringsCallback,
339                                                   &m_sdk_directory_infos);
340                     const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
341                     // First try for an exact match of major, minor and update
342                     for (uint32_t i=num_installed; i<num_sdk_infos; ++i)
343                     {
344                         m_sdk_directory_infos[i].user_cached = true;
345                     }
346                 }
347             }
348         }
349     }
350     return !m_sdk_directory_infos.empty();
351 }
352 
353 const PlatformRemoteiOS::SDKDirectoryInfo *
354 PlatformRemoteiOS::GetSDKDirectoryForCurrentOSVersion ()
355 {
356     uint32_t i;
357     if (UpdateSDKDirectoryInfosInNeeded())
358     {
359         const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
360 
361         // Check to see if the user specified a build string. If they did, then
362         // be sure to match it.
363         std::vector<bool> check_sdk_info(num_sdk_infos, true);
364         ConstString build(m_sdk_build);
365         if (build)
366         {
367             for (i=0; i<num_sdk_infos; ++i)
368                 check_sdk_info[i] = m_sdk_directory_infos[i].build == build;
369         }
370 
371         // If we are connected we can find the version of the OS the platform
372         // us running on and select the right SDK
373         uint32_t major, minor, update;
374         if (GetOSVersion(major, minor, update))
375         {
376             if (UpdateSDKDirectoryInfosInNeeded())
377             {
378                 // First try for an exact match of major, minor and update
379                 for (i=0; i<num_sdk_infos; ++i)
380                 {
381                     if (check_sdk_info[i])
382                     {
383                         if (m_sdk_directory_infos[i].version_major == major &&
384                             m_sdk_directory_infos[i].version_minor == minor &&
385                             m_sdk_directory_infos[i].version_update == update)
386                         {
387                             return &m_sdk_directory_infos[i];
388                         }
389                     }
390                 }
391                 // First try for an exact match of major and minor
392                 for (i=0; i<num_sdk_infos; ++i)
393                 {
394                     if (check_sdk_info[i])
395                     {
396                         if (m_sdk_directory_infos[i].version_major == major &&
397                             m_sdk_directory_infos[i].version_minor == minor)
398                         {
399                             return &m_sdk_directory_infos[i];
400                         }
401                     }
402                 }
403                 // Lastly try to match of major version only..
404                 for (i=0; i<num_sdk_infos; ++i)
405                 {
406                     if (check_sdk_info[i])
407                     {
408                         if (m_sdk_directory_infos[i].version_major == major)
409                         {
410                             return &m_sdk_directory_infos[i];
411                         }
412                     }
413                 }
414             }
415         }
416         else if (build)
417         {
418             // No version, just a build number, search for the first one that matches
419             for (i=0; i<num_sdk_infos; ++i)
420                 if (check_sdk_info[i])
421                     return &m_sdk_directory_infos[i];
422         }
423     }
424     return NULL;
425 }
426 
427 const PlatformRemoteiOS::SDKDirectoryInfo *
428 PlatformRemoteiOS::GetSDKDirectoryForLatestOSVersion ()
429 {
430     const PlatformRemoteiOS::SDKDirectoryInfo *result = NULL;
431     if (UpdateSDKDirectoryInfosInNeeded())
432     {
433         const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
434         // First try for an exact match of major, minor and update
435         for (uint32_t i=0; i<num_sdk_infos; ++i)
436         {
437             const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i];
438             if (sdk_dir_info.version_major != UINT32_MAX)
439             {
440                 if (result == NULL || sdk_dir_info.version_major > result->version_major)
441                 {
442                     result = &sdk_dir_info;
443                 }
444                 else if (sdk_dir_info.version_major == result->version_major)
445                 {
446                     if (sdk_dir_info.version_minor > result->version_minor)
447                     {
448                         result = &sdk_dir_info;
449                     }
450                     else if (sdk_dir_info.version_minor == result->version_minor)
451                     {
452                         if (sdk_dir_info.version_update > result->version_update)
453                         {
454                             result = &sdk_dir_info;
455                         }
456                     }
457                 }
458             }
459         }
460     }
461     return result;
462 }
463 
464 
465 
466 const char *
467 PlatformRemoteiOS::GetDeviceSupportDirectory()
468 {
469     if (m_device_support_directory.empty())
470     {
471         const char *device_support_dir = GetDeveloperDirectory();
472         if (device_support_dir)
473         {
474             m_device_support_directory.assign (device_support_dir);
475             m_device_support_directory.append ("/Platforms/iPhoneOS.platform/DeviceSupport");
476         }
477         else
478         {
479             // Assign a single NULL character so we know we tried to find the device
480             // support directory and we don't keep trying to find it over and over.
481             m_device_support_directory.assign (1, '\0');
482         }
483     }
484     // We should have put a single NULL character into m_device_support_directory
485     // or it should have a valid path if the code gets here
486     assert (m_device_support_directory.empty() == false);
487     if (m_device_support_directory[0])
488         return m_device_support_directory.c_str();
489     return NULL;
490 }
491 
492 
493 const char *
494 PlatformRemoteiOS::GetDeviceSupportDirectoryForOSVersion()
495 {
496     if (m_sdk_sysroot)
497         return m_sdk_sysroot.GetCString();
498 
499     if (m_device_support_directory_for_os_version.empty())
500     {
501         const PlatformRemoteiOS::SDKDirectoryInfo *sdk_dir_info = GetSDKDirectoryForCurrentOSVersion ();
502         if (sdk_dir_info == NULL)
503             sdk_dir_info = GetSDKDirectoryForLatestOSVersion ();
504         if (sdk_dir_info)
505         {
506             char path[PATH_MAX];
507             if (sdk_dir_info->directory.GetPath(path, sizeof(path)))
508             {
509                 m_device_support_directory_for_os_version = path;
510                 return m_device_support_directory_for_os_version.c_str();
511             }
512         }
513         else
514         {
515             // Assign a single NULL character so we know we tried to find the device
516             // support directory and we don't keep trying to find it over and over.
517             m_device_support_directory_for_os_version.assign (1, '\0');
518         }
519     }
520     // We should have put a single NULL character into m_device_support_directory_for_os_version
521     // or it should have a valid path if the code gets here
522     assert (m_device_support_directory_for_os_version.empty() == false);
523     if (m_device_support_directory_for_os_version[0])
524         return m_device_support_directory_for_os_version.c_str();
525     return NULL;
526 }
527 
528 uint32_t
529 PlatformRemoteiOS::FindFileInAllSDKs (const char *platform_file_path,
530                                       FileSpecList &file_list)
531 {
532     if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosInNeeded())
533     {
534         const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
535         lldb_private::FileSpec local_file;
536         // First try for an exact match of major, minor and update
537         for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
538         {
539             if (GetFileInSDK (platform_file_path,
540                               sdk_idx,
541                               local_file))
542             {
543                 file_list.Append(local_file);
544             }
545         }
546     }
547     return file_list.GetSize();
548 }
549 
550 bool
551 PlatformRemoteiOS::GetFileInSDK (const char *platform_file_path,
552                                  uint32_t sdk_idx,
553                                  lldb_private::FileSpec &local_file)
554 {
555     if (sdk_idx < m_sdk_directory_infos.size())
556     {
557         char sdkroot_path[PATH_MAX];
558         const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[sdk_idx];
559         if (sdk_dir_info.directory.GetPath(sdkroot_path, sizeof(sdkroot_path)))
560         {
561             const bool symbols_dirs_only = true;
562 
563             return GetFileInSDKRoot (platform_file_path,
564                                      sdkroot_path,
565                                      symbols_dirs_only,
566                                      local_file);
567         }
568     }
569     return false;
570 }
571 
572 
573 bool
574 PlatformRemoteiOS::GetFileInSDKRoot (const char *platform_file_path,
575                                      const char *sdkroot_path,
576                                      bool symbols_dirs_only,
577                                      lldb_private::FileSpec &local_file)
578 {
579     if (sdkroot_path && sdkroot_path[0] && platform_file_path && platform_file_path[0])
580     {
581         char resolved_path[PATH_MAX];
582 
583         if (!symbols_dirs_only)
584         {
585             ::snprintf (resolved_path,
586                         sizeof(resolved_path),
587                         "%s/%s",
588                         sdkroot_path,
589                         platform_file_path);
590 
591             local_file.SetFile(resolved_path, true);
592             if (local_file.Exists())
593                 return true;
594         }
595 
596         ::snprintf (resolved_path,
597                     sizeof(resolved_path),
598                     "%s/Symbols.Internal/%s",
599                     sdkroot_path,
600                     platform_file_path);
601 
602         local_file.SetFile(resolved_path, true);
603         if (local_file.Exists())
604             return true;
605         ::snprintf (resolved_path,
606                     sizeof(resolved_path),
607                     "%s/Symbols/%s",
608                     sdkroot_path,
609                     platform_file_path);
610 
611         local_file.SetFile(resolved_path, true);
612         if (local_file.Exists())
613             return true;
614     }
615     return false;
616 }
617 
618 
619 Error
620 PlatformRemoteiOS::GetSymbolFile (const FileSpec &platform_file,
621                                   const UUID *uuid_ptr,
622                                   FileSpec &local_file)
623 {
624     Error error;
625     char platform_file_path[PATH_MAX];
626     if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path)))
627     {
628         char resolved_path[PATH_MAX];
629 
630         const char * os_version_dir = GetDeviceSupportDirectoryForOSVersion();
631         if (os_version_dir)
632         {
633             ::snprintf (resolved_path,
634                         sizeof(resolved_path),
635                         "%s/%s",
636                         os_version_dir,
637                         platform_file_path);
638 
639             local_file.SetFile(resolved_path, true);
640             if (local_file.Exists())
641                 return error;
642 
643             ::snprintf (resolved_path,
644                         sizeof(resolved_path),
645                         "%s/Symbols.Internal/%s",
646                         os_version_dir,
647                         platform_file_path);
648 
649             local_file.SetFile(resolved_path, true);
650             if (local_file.Exists())
651                 return error;
652             ::snprintf (resolved_path,
653                         sizeof(resolved_path),
654                         "%s/Symbols/%s",
655                         os_version_dir,
656                         platform_file_path);
657 
658             local_file.SetFile(resolved_path, true);
659             if (local_file.Exists())
660                 return error;
661 
662         }
663         local_file = platform_file;
664         if (local_file.Exists())
665             return error;
666 
667         error.SetErrorStringWithFormat ("unable to locate a platform file for '%s' in platform '%s'",
668                                         platform_file_path,
669                                         GetPluginName());
670     }
671     else
672     {
673         error.SetErrorString ("invalid platform file argument");
674     }
675     return error;
676 }
677 
678 Error
679 PlatformRemoteiOS::GetSharedModule (const ModuleSpec &module_spec,
680                                     ModuleSP &module_sp,
681                                     const FileSpecList *module_search_paths_ptr,
682                                     ModuleSP *old_module_sp_ptr,
683                                     bool *did_create_ptr)
684 {
685     // For iOS, the SDK files are all cached locally on the host
686     // system. So first we ask for the file in the cached SDK,
687     // then we attempt to get a shared module for the right architecture
688     // with the right UUID.
689     const FileSpec &platform_file = module_spec.GetFileSpec();
690 
691     FileSpec local_file;
692     const UUID *module_uuid_ptr = module_spec.GetUUIDPtr();
693     Error error (GetSymbolFile (platform_file, module_uuid_ptr, local_file));
694     if (error.Success())
695     {
696         error = ResolveExecutable (local_file, module_spec.GetArchitecture(), module_sp, NULL);
697         if (module_sp && ((module_uuid_ptr == NULL) || (module_sp->GetUUID() == *module_uuid_ptr)))
698         {
699             //printf ("found in user specified SDK\n");
700             error.Clear();
701             return error;
702         }
703 
704         char platform_file_path[PATH_MAX];
705         if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path)))
706         {
707             FileSpec local_file;
708             const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
709             // Try the last SDK index if it is set as most files from an SDK
710             // will tend to be valid in that same SDK.
711             if (m_last_module_sdk_idx < num_sdk_infos)
712             {
713                 if (GetFileInSDK (platform_file_path, m_last_module_sdk_idx, local_file))
714                 {
715                     //printf ("sdk[%u] last: '%s/%s'\n", m_last_module_sdk_idx, local_file.GetDirectory().GetCString(), local_file.GetFilename().GetCString());
716                     module_sp.reset();
717                     error = ResolveExecutable (local_file,
718                                                module_spec.GetArchitecture(),
719                                                module_sp,
720                                                NULL);
721                     if (module_sp && ((module_uuid_ptr == NULL) || (module_sp->GetUUID() == *module_uuid_ptr)))
722                     {
723                         //printf ("sdk[%u] last found\n", m_last_module_sdk_idx);
724                         error.Clear();
725                         return error;
726                     }
727                 }
728             }
729 
730             // First try for an exact match of major, minor and update
731             for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
732             {
733                 if (m_last_module_sdk_idx == sdk_idx)
734                 {
735                     // Skip the last module SDK index if we already searched
736                     // it above
737                     continue;
738                 }
739                 if (GetFileInSDK (platform_file_path, sdk_idx, local_file))
740                 {
741                     //printf ("sdk[%u]: '%s/%s'\n", sdk_idx, local_file.GetDirectory().GetCString(), local_file.GetFilename().GetCString());
742 
743                     error = ResolveExecutable (local_file,
744                                                module_spec.GetArchitecture(),
745                                                module_sp,
746                                                NULL);
747                     if (module_sp && ((module_uuid_ptr == NULL) || (module_sp->GetUUID() == *module_uuid_ptr)))
748                     {
749                         // Remember the index of the last SDK that we found a file
750                         // in in case the wrong SDK was selected.
751                         m_last_module_sdk_idx = sdk_idx;
752                         //printf ("sdk[%u]: found (setting last to %u)\n", sdk_idx, m_last_module_sdk_idx);
753                         error.Clear();
754                         return error;
755                     }
756                 }
757             }
758         }
759         // Not the module we are looking for... Nothing to see here...
760         module_sp.reset();
761     }
762 
763     const bool always_create = false;
764     error = ModuleList::GetSharedModule (module_spec,
765                                          module_sp,
766                                          module_search_paths_ptr,
767                                          old_module_sp_ptr,
768                                          did_create_ptr,
769                                          always_create);
770 
771     if (module_sp)
772         module_sp->SetPlatformFileSpec(platform_file);
773 
774     return error;
775 }
776 
777 
778 uint32_t
779 PlatformRemoteiOS::FindProcesses (const ProcessInstanceInfoMatch &match_info,
780                                   ProcessInstanceInfoList &process_infos)
781 {
782     // TODO: if connected, send a packet to get the remote process infos by name
783     process_infos.Clear();
784     return 0;
785 }
786 
787 bool
788 PlatformRemoteiOS::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
789 {
790     // TODO: if connected, send a packet to get the remote process info
791     process_info.Clear();
792     return false;
793 }
794 
795 bool
796 PlatformRemoteiOS::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
797 {
798     return ARMGetSupportedArchitectureAtIndex (idx, arch);
799 }
800