1e996fd30SGreg Clayton //===-- PlatformLinux.cpp ---------------------------------------*- C++ -*-===//
2e996fd30SGreg Clayton //
3e996fd30SGreg Clayton //                     The LLVM Compiler Infrastructure
4e996fd30SGreg Clayton //
5e996fd30SGreg Clayton // This file is distributed under the University of Illinois Open Source
6e996fd30SGreg Clayton // License. See LICENSE.TXT for details.
7e996fd30SGreg Clayton //
8e996fd30SGreg Clayton //===----------------------------------------------------------------------===//
9e996fd30SGreg Clayton 
1093a64300SDaniel Malea #include "lldb/lldb-python.h"
1193a64300SDaniel Malea 
12e996fd30SGreg Clayton #include "PlatformLinux.h"
13b2f1fb29SVirgile Bello #include "lldb/Host/Config.h"
14e996fd30SGreg Clayton 
15e996fd30SGreg Clayton // C Includes
16ecc11474SStephen Wilson #include <stdio.h>
17b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX
18ecc11474SStephen Wilson #include <sys/utsname.h>
19b2f1fb29SVirgile Bello #endif
20ecc11474SStephen Wilson 
21e996fd30SGreg Clayton // C++ Includes
22e996fd30SGreg Clayton // Other libraries and framework includes
23e996fd30SGreg Clayton // Project includes
24e996fd30SGreg Clayton #include "lldb/Core/Error.h"
2528041352SGreg Clayton #include "lldb/Core/Debugger.h"
26e996fd30SGreg Clayton #include "lldb/Core/Module.h"
27e996fd30SGreg Clayton #include "lldb/Core/ModuleList.h"
281f746071SGreg Clayton #include "lldb/Core/ModuleSpec.h"
29ecc11474SStephen Wilson #include "lldb/Core/PluginManager.h"
30e996fd30SGreg Clayton #include "lldb/Core/StreamString.h"
31e996fd30SGreg Clayton #include "lldb/Host/FileSpec.h"
32e996fd30SGreg Clayton #include "lldb/Host/Host.h"
33ecc11474SStephen Wilson #include "lldb/Target/Target.h"
34e996fd30SGreg Clayton #include "lldb/Target/Process.h"
35e996fd30SGreg Clayton 
36e996fd30SGreg Clayton using namespace lldb;
37e996fd30SGreg Clayton using namespace lldb_private;
38e996fd30SGreg Clayton 
3928041352SGreg Clayton static uint32_t g_initialize_count = 0;
4028041352SGreg Clayton 
41ecc11474SStephen Wilson Platform *
42b3a40ba8SGreg Clayton PlatformLinux::CreateInstance (bool force, const ArchSpec *arch)
43ecc11474SStephen Wilson {
44b3a40ba8SGreg Clayton     bool create = force;
45b3a40ba8SGreg Clayton     if (create == false && arch && arch->IsValid())
46b3a40ba8SGreg Clayton     {
47b3a40ba8SGreg Clayton         const llvm::Triple &triple = arch->GetTriple();
4870512317SGreg Clayton         switch (triple.getVendor())
4970512317SGreg Clayton         {
5070512317SGreg Clayton             case llvm::Triple::PC:
51b3a40ba8SGreg Clayton                 create = true;
5270512317SGreg Clayton                 break;
5370512317SGreg Clayton 
54dbc6c0bbSGreg Clayton #if defined(__linux__)
55dbc6c0bbSGreg Clayton             // Only accept "unknown" for the vendor if the host is linux and
56dbc6c0bbSGreg Clayton             // it "unknown" wasn't specified (it was just returned becasue it
57dbc6c0bbSGreg Clayton             // was NOT specified_
5870512317SGreg Clayton             case llvm::Triple::UnknownArch:
5970512317SGreg Clayton                 create = !arch->TripleVendorWasSpecified();
6070512317SGreg Clayton                 break;
61dbc6c0bbSGreg Clayton #endif
6270512317SGreg Clayton             default:
6370512317SGreg Clayton                 break;
6470512317SGreg Clayton         }
6570512317SGreg Clayton 
6670512317SGreg Clayton         if (create)
6770512317SGreg Clayton         {
6870512317SGreg Clayton             switch (triple.getOS())
6970512317SGreg Clayton             {
7070512317SGreg Clayton                 case llvm::Triple::Linux:
7170512317SGreg Clayton                     break;
7270512317SGreg Clayton 
73dbc6c0bbSGreg Clayton #if defined(__linux__)
74dbc6c0bbSGreg Clayton                 // Only accept "unknown" for the OS if the host is linux and
75dbc6c0bbSGreg Clayton                 // it "unknown" wasn't specified (it was just returned becasue it
76dbc6c0bbSGreg Clayton                 // was NOT specified)
7770512317SGreg Clayton                 case llvm::Triple::UnknownOS:
7870512317SGreg Clayton                     create = !arch->TripleOSWasSpecified();
7970512317SGreg Clayton                     break;
80dbc6c0bbSGreg Clayton #endif
8170512317SGreg Clayton                 default:
8270512317SGreg Clayton                     create = false;
8370512317SGreg Clayton                     break;
8470512317SGreg Clayton             }
8570512317SGreg Clayton         }
86b3a40ba8SGreg Clayton     }
87b3a40ba8SGreg Clayton     if (create)
88a4756939STodd Fiala         return new PlatformLinux(false);
89b3a40ba8SGreg Clayton     return NULL;
90ecc11474SStephen Wilson }
91ecc11474SStephen Wilson 
92ecc11474SStephen Wilson 
9357abc5d6SGreg Clayton lldb_private::ConstString
9457abc5d6SGreg Clayton PlatformLinux::GetPluginNameStatic (bool is_host)
95ecc11474SStephen Wilson {
9628041352SGreg Clayton     if (is_host)
9757abc5d6SGreg Clayton     {
9857abc5d6SGreg Clayton         static ConstString g_host_name(Platform::GetHostPlatformName ());
9957abc5d6SGreg Clayton         return g_host_name;
10057abc5d6SGreg Clayton     }
10128041352SGreg Clayton     else
10257abc5d6SGreg Clayton     {
10357abc5d6SGreg Clayton         static ConstString g_remote_name("remote-linux");
10457abc5d6SGreg Clayton         return g_remote_name;
10557abc5d6SGreg Clayton     }
10628041352SGreg Clayton }
10728041352SGreg Clayton 
10828041352SGreg Clayton const char *
10928041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic (bool is_host)
11028041352SGreg Clayton {
11128041352SGreg Clayton     if (is_host)
11228041352SGreg Clayton         return "Local Linux user platform plug-in.";
11328041352SGreg Clayton     else
11428041352SGreg Clayton         return "Remote Linux user platform plug-in.";
115ecc11474SStephen Wilson }
116ecc11474SStephen Wilson 
11757abc5d6SGreg Clayton lldb_private::ConstString
11857abc5d6SGreg Clayton PlatformLinux::GetPluginName()
11957abc5d6SGreg Clayton {
12057abc5d6SGreg Clayton     return GetPluginNameStatic(IsHost());
12157abc5d6SGreg Clayton }
12257abc5d6SGreg Clayton 
123e996fd30SGreg Clayton void
124e996fd30SGreg Clayton PlatformLinux::Initialize ()
125e996fd30SGreg Clayton {
12628041352SGreg Clayton     if (g_initialize_count++ == 0)
127ecc11474SStephen Wilson     {
12828041352SGreg Clayton #if defined(__linux__)
12928041352SGreg Clayton         PlatformSP default_platform_sp (new PlatformLinux(true));
13028041352SGreg Clayton         default_platform_sp->SetSystemArchitecture (Host::GetArchitecture());
131e996fd30SGreg Clayton         Platform::SetDefaultPlatform (default_platform_sp);
13228041352SGreg Clayton #endif
13357abc5d6SGreg Clayton         PluginManager::RegisterPlugin(PlatformLinux::GetPluginNameStatic(false),
13428041352SGreg Clayton                                       PlatformLinux::GetPluginDescriptionStatic(false),
13528041352SGreg Clayton                                       PlatformLinux::CreateInstance);
136ecc11474SStephen Wilson     }
137e996fd30SGreg Clayton }
138e996fd30SGreg Clayton 
139e996fd30SGreg Clayton void
140e996fd30SGreg Clayton PlatformLinux::Terminate ()
141e996fd30SGreg Clayton {
14228041352SGreg Clayton     if (g_initialize_count > 0)
14328041352SGreg Clayton     {
14428041352SGreg Clayton         if (--g_initialize_count == 0)
14528041352SGreg Clayton         {
14628041352SGreg Clayton             PluginManager::UnregisterPlugin (PlatformLinux::CreateInstance);
147e996fd30SGreg Clayton         }
14828041352SGreg Clayton     }
14928041352SGreg Clayton }
150e996fd30SGreg Clayton 
151e996fd30SGreg Clayton Error
152e996fd30SGreg Clayton PlatformLinux::ResolveExecutable (const FileSpec &exe_file,
153e996fd30SGreg Clayton                                   const ArchSpec &exe_arch,
154ea5e0cc3SGreg Clayton                                   lldb::ModuleSP &exe_module_sp,
155ea5e0cc3SGreg Clayton                                   const FileSpecList *module_search_paths_ptr)
156e996fd30SGreg Clayton {
157e996fd30SGreg Clayton     Error error;
158e996fd30SGreg Clayton     // Nothing special to do here, just use the actual file and architecture
159e996fd30SGreg Clayton 
16028041352SGreg Clayton     char exe_path[PATH_MAX];
161e996fd30SGreg Clayton     FileSpec resolved_exe_file (exe_file);
162e996fd30SGreg Clayton 
16328041352SGreg Clayton     if (IsHost())
16428041352SGreg Clayton     {
16528041352SGreg Clayton         // If we have "ls" as the exe_file, resolve the executable location based on
166e996fd30SGreg Clayton         // the current path variables
167e996fd30SGreg Clayton         if (!resolved_exe_file.Exists())
16828041352SGreg Clayton         {
16928041352SGreg Clayton             exe_file.GetPath(exe_path, sizeof(exe_path));
17028041352SGreg Clayton             resolved_exe_file.SetFile(exe_path, true);
17128041352SGreg Clayton         }
17228041352SGreg Clayton 
17328041352SGreg Clayton         if (!resolved_exe_file.Exists())
174e996fd30SGreg Clayton             resolved_exe_file.ResolveExecutableLocation ();
175e996fd30SGreg Clayton 
17628041352SGreg Clayton         if (resolved_exe_file.Exists())
17728041352SGreg Clayton             error.Clear();
17828041352SGreg Clayton         else
17928041352SGreg Clayton         {
18028041352SGreg Clayton             exe_file.GetPath(exe_path, sizeof(exe_path));
18128041352SGreg Clayton             error.SetErrorStringWithFormat("unable to find executable for '%s'", exe_path);
18228041352SGreg Clayton         }
18328041352SGreg Clayton     }
18428041352SGreg Clayton     else
18528041352SGreg Clayton     {
18628041352SGreg Clayton         if (m_remote_platform_sp)
18728041352SGreg Clayton         {
18828041352SGreg Clayton             error = m_remote_platform_sp->ResolveExecutable (exe_file,
18928041352SGreg Clayton                                                              exe_arch,
1900c90ef47SGreg Clayton                                                              exe_module_sp,
1910c90ef47SGreg Clayton                                                              NULL);
19228041352SGreg Clayton         }
19328041352SGreg Clayton         else
19428041352SGreg Clayton         {
19528041352SGreg Clayton             // We may connect to a process and use the provided executable (Don't use local $PATH).
196e996fd30SGreg Clayton 
197e996fd30SGreg Clayton             if (resolved_exe_file.Exists())
19828041352SGreg Clayton                 error.Clear();
19928041352SGreg Clayton             else
20028041352SGreg Clayton                 error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", exe_path);
20128041352SGreg Clayton         }
20228041352SGreg Clayton     }
20328041352SGreg Clayton 
20428041352SGreg Clayton     if (error.Success())
205e996fd30SGreg Clayton     {
206ea5e0cc3SGreg Clayton         ModuleSpec module_spec (resolved_exe_file, exe_arch);
207e996fd30SGreg Clayton         if (exe_arch.IsValid())
208e996fd30SGreg Clayton         {
209ea5e0cc3SGreg Clayton             error = ModuleList::GetSharedModule (module_spec,
210e996fd30SGreg Clayton                                                  exe_module_sp,
211e996fd30SGreg Clayton                                                  NULL,
2120c90ef47SGreg Clayton                                                  NULL,
213e996fd30SGreg Clayton                                                  NULL);
2149f0013d8SMichael Sartain             if (error.Fail())
2159f0013d8SMichael Sartain             {
2169f0013d8SMichael Sartain                 // If we failed, it may be because the vendor and os aren't known. If that is the
2179f0013d8SMichael Sartain                 // case, try setting them to the host architecture and give it another try.
2189f0013d8SMichael Sartain                 llvm::Triple &module_triple = module_spec.GetArchitecture().GetTriple();
2199f0013d8SMichael Sartain                 bool is_vendor_specified = (module_triple.getVendor() != llvm::Triple::UnknownVendor);
2209f0013d8SMichael Sartain                 bool is_os_specified = (module_triple.getOS() != llvm::Triple::UnknownOS);
2219f0013d8SMichael Sartain                 if (!is_vendor_specified || !is_os_specified)
2229f0013d8SMichael Sartain                 {
2239f0013d8SMichael Sartain                     const llvm::Triple &host_triple = Host::GetArchitecture (Host::eSystemDefaultArchitecture).GetTriple();
2249f0013d8SMichael Sartain 
2259f0013d8SMichael Sartain                     if (!is_vendor_specified)
2269f0013d8SMichael Sartain                         module_triple.setVendorName (host_triple.getVendorName());
2279f0013d8SMichael Sartain                     if (!is_os_specified)
2289f0013d8SMichael Sartain                         module_triple.setOSName (host_triple.getOSName());
2299f0013d8SMichael Sartain 
2309f0013d8SMichael Sartain                     error = ModuleList::GetSharedModule (module_spec,
2319f0013d8SMichael Sartain                                                          exe_module_sp,
2329f0013d8SMichael Sartain                                                          NULL,
2339f0013d8SMichael Sartain                                                          NULL,
2349f0013d8SMichael Sartain                                                          NULL);
2359f0013d8SMichael Sartain                 }
2369f0013d8SMichael Sartain             }
237e996fd30SGreg Clayton 
238e635db49SSean Callanan             // TODO find out why exe_module_sp might be NULL
239e635db49SSean Callanan             if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
240e996fd30SGreg Clayton             {
241e996fd30SGreg Clayton                 exe_module_sp.reset();
242b5ad4ec7SGreg Clayton                 error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s",
243b5ad4ec7SGreg Clayton                                                 exe_file.GetPath().c_str(),
244e996fd30SGreg Clayton                                                 exe_arch.GetArchitectureName());
245e996fd30SGreg Clayton             }
246e996fd30SGreg Clayton         }
247e996fd30SGreg Clayton         else
248e996fd30SGreg Clayton         {
249e996fd30SGreg Clayton             // No valid architecture was specified, ask the platform for
250e996fd30SGreg Clayton             // the architectures that we should be using (in the correct order)
251e996fd30SGreg Clayton             // and see if we can find a match that way
252e996fd30SGreg Clayton             StreamString arch_names;
253ea5e0cc3SGreg Clayton             for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx)
254e996fd30SGreg Clayton             {
255ea5e0cc3SGreg Clayton                 error = ModuleList::GetSharedModule (module_spec,
256e996fd30SGreg Clayton                                                      exe_module_sp,
257e996fd30SGreg Clayton                                                      NULL,
2580c90ef47SGreg Clayton                                                      NULL,
259e996fd30SGreg Clayton                                                      NULL);
260e996fd30SGreg Clayton                 // Did we find an executable using one of the
261e996fd30SGreg Clayton                 if (error.Success())
262e996fd30SGreg Clayton                 {
263e996fd30SGreg Clayton                     if (exe_module_sp && exe_module_sp->GetObjectFile())
264e996fd30SGreg Clayton                         break;
265e996fd30SGreg Clayton                     else
266e996fd30SGreg Clayton                         error.SetErrorToGenericError();
267e996fd30SGreg Clayton                 }
268e996fd30SGreg Clayton 
269e996fd30SGreg Clayton                 if (idx > 0)
270e996fd30SGreg Clayton                     arch_names.PutCString (", ");
271ea5e0cc3SGreg Clayton                 arch_names.PutCString (module_spec.GetArchitecture().GetArchitectureName());
272e996fd30SGreg Clayton             }
273e996fd30SGreg Clayton 
274e996fd30SGreg Clayton             if (error.Fail() || !exe_module_sp)
275e996fd30SGreg Clayton             {
276b5ad4ec7SGreg Clayton                 error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
277b5ad4ec7SGreg Clayton                                                 exe_file.GetPath().c_str(),
27857abc5d6SGreg Clayton                                                 GetPluginName().GetCString(),
279e996fd30SGreg Clayton                                                 arch_names.GetString().c_str());
280e996fd30SGreg Clayton             }
281e996fd30SGreg Clayton         }
282e996fd30SGreg Clayton     }
283e996fd30SGreg Clayton 
284e996fd30SGreg Clayton     return error;
285e996fd30SGreg Clayton }
286e996fd30SGreg Clayton 
287e996fd30SGreg Clayton Error
288*fc995725SSteve Pucci PlatformLinux::GetFileWithUUID (const FileSpec &platform_file,
28928041352SGreg Clayton                                 const UUID *uuid_ptr, FileSpec &local_file)
290e996fd30SGreg Clayton {
29128041352SGreg Clayton     if (IsRemote())
29228041352SGreg Clayton     {
29328041352SGreg Clayton         if (m_remote_platform_sp)
294*fc995725SSteve Pucci             return m_remote_platform_sp->GetFileWithUUID (platform_file, uuid_ptr, local_file);
29528041352SGreg Clayton     }
29628041352SGreg Clayton 
297e996fd30SGreg Clayton     // Default to the local case
298e996fd30SGreg Clayton     local_file = platform_file;
299e996fd30SGreg Clayton     return Error();
300e996fd30SGreg Clayton }
301e996fd30SGreg Clayton 
302e996fd30SGreg Clayton 
303e996fd30SGreg Clayton //------------------------------------------------------------------
304e996fd30SGreg Clayton /// Default Constructor
305e996fd30SGreg Clayton //------------------------------------------------------------------
30628041352SGreg Clayton PlatformLinux::PlatformLinux (bool is_host) :
30728041352SGreg Clayton     Platform(is_host),  // This is the local host platform
30828041352SGreg Clayton     m_remote_platform_sp ()
309e996fd30SGreg Clayton {
310e996fd30SGreg Clayton }
311e996fd30SGreg Clayton 
312e996fd30SGreg Clayton //------------------------------------------------------------------
313e996fd30SGreg Clayton /// Destructor.
314e996fd30SGreg Clayton ///
315e996fd30SGreg Clayton /// The destructor is virtual since this class is designed to be
316e996fd30SGreg Clayton /// inherited from by the plug-in instance.
317e996fd30SGreg Clayton //------------------------------------------------------------------
318e996fd30SGreg Clayton PlatformLinux::~PlatformLinux()
319e996fd30SGreg Clayton {
320e996fd30SGreg Clayton }
321e996fd30SGreg Clayton 
322e996fd30SGreg Clayton bool
32313e8e1c3SJohnny Chen PlatformLinux::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
324e996fd30SGreg Clayton {
32528041352SGreg Clayton     bool success = false;
32628041352SGreg Clayton     if (IsHost())
32728041352SGreg Clayton     {
32828041352SGreg Clayton         success = Platform::GetProcessInfo (pid, process_info);
32928041352SGreg Clayton     }
33028041352SGreg Clayton     else
33128041352SGreg Clayton     {
33228041352SGreg Clayton         if (m_remote_platform_sp)
33328041352SGreg Clayton             success = m_remote_platform_sp->GetProcessInfo (pid, process_info);
33428041352SGreg Clayton     }
33528041352SGreg Clayton     return success;
336e996fd30SGreg Clayton }
337e996fd30SGreg Clayton 
338e996fd30SGreg Clayton bool
339e996fd30SGreg Clayton PlatformLinux::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
340e996fd30SGreg Clayton {
341e996fd30SGreg Clayton     if (idx == 0)
342e996fd30SGreg Clayton     {
343e996fd30SGreg Clayton         arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
344e996fd30SGreg Clayton         return arch.IsValid();
345e996fd30SGreg Clayton     }
346542e4075SGreg Clayton     else if (idx == 1)
347542e4075SGreg Clayton     {
348542e4075SGreg Clayton         // If the default host architecture is 64-bit, look for a 32-bit variant
349542e4075SGreg Clayton         ArchSpec hostArch
350542e4075SGreg Clayton                       = Host::GetArchitecture(Host::eSystemDefaultArchitecture);
351542e4075SGreg Clayton         if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit())
352542e4075SGreg Clayton         {
353542e4075SGreg Clayton             arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
354542e4075SGreg Clayton             return arch.IsValid();
355542e4075SGreg Clayton         }
356542e4075SGreg Clayton     }
357e996fd30SGreg Clayton     return false;
358e996fd30SGreg Clayton }
359ecc11474SStephen Wilson 
360ecc11474SStephen Wilson void
361ecc11474SStephen Wilson PlatformLinux::GetStatus (Stream &strm)
362ecc11474SStephen Wilson {
3633be69dacSDaniel Malea     Platform::GetStatus(strm);
364ecc11474SStephen Wilson 
365b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX
366b2f1fb29SVirgile Bello     struct utsname un;
367b2f1fb29SVirgile Bello 
3683be69dacSDaniel Malea     if (uname(&un))
3693be69dacSDaniel Malea         return;
3703be69dacSDaniel Malea 
3713be69dacSDaniel Malea     strm.Printf ("    Kernel: %s\n", un.sysname);
3723be69dacSDaniel Malea     strm.Printf ("   Release: %s\n", un.release);
3733be69dacSDaniel Malea     strm.Printf ("   Version: %s\n", un.version);
374b2f1fb29SVirgile Bello #endif
375ecc11474SStephen Wilson }
376ecc11474SStephen Wilson 
377ecc11474SStephen Wilson size_t
378ecc11474SStephen Wilson PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target,
379ecc11474SStephen Wilson                                                 BreakpointSite *bp_site)
380ecc11474SStephen Wilson {
381ecc11474SStephen Wilson     ArchSpec arch = target.GetArchitecture();
38228041352SGreg Clayton     const uint8_t *trap_opcode = NULL;
38328041352SGreg Clayton     size_t trap_opcode_size = 0;
384ecc11474SStephen Wilson 
385ecc11474SStephen Wilson     switch (arch.GetCore())
386ecc11474SStephen Wilson     {
387ecc11474SStephen Wilson     default:
388ecc11474SStephen Wilson         assert(false && "CPU type not supported!");
389ecc11474SStephen Wilson         break;
390ecc11474SStephen Wilson 
391ecc11474SStephen Wilson     case ArchSpec::eCore_x86_32_i386:
392ecc11474SStephen Wilson     case ArchSpec::eCore_x86_64_x86_64:
39328041352SGreg Clayton         {
39428041352SGreg Clayton             static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
39528041352SGreg Clayton             trap_opcode = g_i386_breakpoint_opcode;
39628041352SGreg Clayton             trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
39728041352SGreg Clayton         }
398ecc11474SStephen Wilson         break;
399ecc11474SStephen Wilson     }
400ecc11474SStephen Wilson 
40128041352SGreg Clayton     if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
40228041352SGreg Clayton         return trap_opcode_size;
40328041352SGreg Clayton     return 0;
40428041352SGreg Clayton }
40528041352SGreg Clayton 
40628041352SGreg Clayton Error
40728041352SGreg Clayton PlatformLinux::LaunchProcess (ProcessLaunchInfo &launch_info)
40828041352SGreg Clayton {
40928041352SGreg Clayton     Error error;
41028041352SGreg Clayton 
41128041352SGreg Clayton     if (IsHost())
41228041352SGreg Clayton     {
41328041352SGreg Clayton         if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
41428041352SGreg Clayton         {
41528041352SGreg Clayton             const bool is_localhost = true;
416d1cf11a7SGreg Clayton             const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
417d1cf11a7SGreg Clayton             const bool first_arg_is_full_shell_command = false;
418d3990793SJim Ingham             uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
419d1cf11a7SGreg Clayton             if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
420d1cf11a7SGreg Clayton                                                                   is_localhost,
421d1cf11a7SGreg Clayton                                                                   will_debug,
422df0ae22fSJim Ingham                                                                   first_arg_is_full_shell_command,
423df0ae22fSJim Ingham                                                                   num_resumes))
42428041352SGreg Clayton                 return error;
42528041352SGreg Clayton         }
42628041352SGreg Clayton         error = Platform::LaunchProcess (launch_info);
42728041352SGreg Clayton     }
42828041352SGreg Clayton     else
42928041352SGreg Clayton     {
43028041352SGreg Clayton         error.SetErrorString ("the platform is not currently connected");
43128041352SGreg Clayton     }
43228041352SGreg Clayton     return error;
433ecc11474SStephen Wilson }
43413e8e1c3SJohnny Chen 
43513e8e1c3SJohnny Chen lldb::ProcessSP
436fb2b629dSPeter Collingbourne PlatformLinux::Attach(ProcessAttachInfo &attach_info,
43713e8e1c3SJohnny Chen                       Debugger &debugger,
43813e8e1c3SJohnny Chen                       Target *target,
43913e8e1c3SJohnny Chen                       Listener &listener,
44013e8e1c3SJohnny Chen                       Error &error)
44113e8e1c3SJohnny Chen {
44228041352SGreg Clayton     lldb::ProcessSP process_sp;
44328041352SGreg Clayton     if (IsHost())
44428041352SGreg Clayton     {
44528041352SGreg Clayton         if (target == NULL)
44628041352SGreg Clayton         {
44728041352SGreg Clayton             TargetSP new_target_sp;
44828041352SGreg Clayton             ArchSpec emptyArchSpec;
44928041352SGreg Clayton 
45028041352SGreg Clayton             error = debugger.GetTargetList().CreateTarget (debugger,
451a0ca6601SGreg Clayton                                                            NULL,
45228041352SGreg Clayton                                                            emptyArchSpec,
45328041352SGreg Clayton                                                            false,
45428041352SGreg Clayton                                                            m_remote_platform_sp,
45528041352SGreg Clayton                                                            new_target_sp);
45628041352SGreg Clayton             target = new_target_sp.get();
45728041352SGreg Clayton         }
45828041352SGreg Clayton         else
45928041352SGreg Clayton             error.Clear();
46028041352SGreg Clayton 
46128041352SGreg Clayton         if (target && error.Success())
46228041352SGreg Clayton         {
46328041352SGreg Clayton             debugger.GetTargetList().SetSelectedTarget(target);
46428041352SGreg Clayton 
4650c90ef47SGreg Clayton             process_sp = target->CreateProcess (listener,
4660c90ef47SGreg Clayton                                                 attach_info.GetProcessPluginName(),
4670c90ef47SGreg Clayton                                                 NULL);
46828041352SGreg Clayton 
46928041352SGreg Clayton             if (process_sp)
47028041352SGreg Clayton                 error = process_sp->Attach (attach_info);
47128041352SGreg Clayton         }
47228041352SGreg Clayton     }
47328041352SGreg Clayton     else
47428041352SGreg Clayton     {
47528041352SGreg Clayton         if (m_remote_platform_sp)
47628041352SGreg Clayton             process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, listener, error);
47728041352SGreg Clayton         else
47828041352SGreg Clayton             error.SetErrorString ("the platform is not currently connected");
47928041352SGreg Clayton     }
48028041352SGreg Clayton     return process_sp;
48113e8e1c3SJohnny Chen }
482