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 
10e996fd30SGreg Clayton #include "PlatformLinux.h"
11e996fd30SGreg Clayton 
12e996fd30SGreg Clayton // C Includes
13ecc11474SStephen Wilson #include <stdio.h>
14ecc11474SStephen Wilson #include <sys/utsname.h>
15ecc11474SStephen Wilson 
16e996fd30SGreg Clayton // C++ Includes
17e996fd30SGreg Clayton // Other libraries and framework includes
18e996fd30SGreg Clayton // Project includes
19e996fd30SGreg Clayton #include "lldb/Core/Error.h"
2028041352SGreg Clayton #include "lldb/Core/Debugger.h"
21e996fd30SGreg Clayton #include "lldb/Core/Module.h"
22e996fd30SGreg Clayton #include "lldb/Core/ModuleList.h"
231f746071SGreg Clayton #include "lldb/Core/ModuleSpec.h"
24ecc11474SStephen Wilson #include "lldb/Core/PluginManager.h"
25e996fd30SGreg Clayton #include "lldb/Core/StreamString.h"
26e996fd30SGreg Clayton #include "lldb/Host/FileSpec.h"
27e996fd30SGreg Clayton #include "lldb/Host/Host.h"
28ecc11474SStephen Wilson #include "lldb/Target/Target.h"
29e996fd30SGreg Clayton #include "lldb/Target/Process.h"
30e996fd30SGreg Clayton 
31e996fd30SGreg Clayton using namespace lldb;
32e996fd30SGreg Clayton using namespace lldb_private;
33e996fd30SGreg Clayton 
3428041352SGreg Clayton static uint32_t g_initialize_count = 0;
3528041352SGreg Clayton 
36ecc11474SStephen Wilson Platform *
37b3a40ba8SGreg Clayton PlatformLinux::CreateInstance (bool force, const ArchSpec *arch)
38ecc11474SStephen Wilson {
39b3a40ba8SGreg Clayton     bool create = force;
40b3a40ba8SGreg Clayton     if (create == false && arch && arch->IsValid())
41b3a40ba8SGreg Clayton     {
42b3a40ba8SGreg Clayton         const llvm::Triple &triple = arch->GetTriple();
4370512317SGreg Clayton         switch (triple.getVendor())
4470512317SGreg Clayton         {
4570512317SGreg Clayton             case llvm::Triple::PC:
46b3a40ba8SGreg Clayton                 create = true;
4770512317SGreg Clayton                 break;
4870512317SGreg Clayton 
49*dbc6c0bbSGreg Clayton #if defined(__linux__)
50*dbc6c0bbSGreg Clayton             // Only accept "unknown" for the vendor if the host is linux and
51*dbc6c0bbSGreg Clayton             // it "unknown" wasn't specified (it was just returned becasue it
52*dbc6c0bbSGreg Clayton             // was NOT specified_
5370512317SGreg Clayton             case llvm::Triple::UnknownArch:
5470512317SGreg Clayton                 create = !arch->TripleVendorWasSpecified();
5570512317SGreg Clayton                 break;
56*dbc6c0bbSGreg Clayton #endif
5770512317SGreg Clayton             default:
5870512317SGreg Clayton                 break;
5970512317SGreg Clayton         }
6070512317SGreg Clayton 
6170512317SGreg Clayton         if (create)
6270512317SGreg Clayton         {
6370512317SGreg Clayton             switch (triple.getOS())
6470512317SGreg Clayton             {
6570512317SGreg Clayton                 case llvm::Triple::Linux:
6670512317SGreg Clayton                     break;
6770512317SGreg Clayton 
68*dbc6c0bbSGreg Clayton #if defined(__linux__)
69*dbc6c0bbSGreg Clayton                 // Only accept "unknown" for the OS if the host is linux and
70*dbc6c0bbSGreg Clayton                 // it "unknown" wasn't specified (it was just returned becasue it
71*dbc6c0bbSGreg Clayton                 // was NOT specified)
7270512317SGreg Clayton                 case llvm::Triple::UnknownOS:
7370512317SGreg Clayton                     create = !arch->TripleOSWasSpecified();
7470512317SGreg Clayton                     break;
75*dbc6c0bbSGreg Clayton #endif
7670512317SGreg Clayton                 default:
7770512317SGreg Clayton                     create = false;
7870512317SGreg Clayton                     break;
7970512317SGreg Clayton             }
8070512317SGreg Clayton         }
81b3a40ba8SGreg Clayton     }
82b3a40ba8SGreg Clayton     if (create)
8328041352SGreg Clayton         return new PlatformLinux(true);
84b3a40ba8SGreg Clayton     return NULL;
85ecc11474SStephen Wilson }
86ecc11474SStephen Wilson 
87ecc11474SStephen Wilson const char *
88ecc11474SStephen Wilson PlatformLinux::GetPluginNameStatic()
89ecc11474SStephen Wilson {
90ecc11474SStephen Wilson     return "plugin.platform.linux";
91ecc11474SStephen Wilson }
92ecc11474SStephen Wilson 
93ecc11474SStephen Wilson const char *
9428041352SGreg Clayton PlatformLinux::GetShortPluginNameStatic (bool is_host)
95ecc11474SStephen Wilson {
9628041352SGreg Clayton     if (is_host)
9728041352SGreg Clayton         return Platform::GetHostPlatformName ();
9828041352SGreg Clayton     else
9928041352SGreg Clayton         return "remote-linux";
10028041352SGreg Clayton }
10128041352SGreg Clayton 
10228041352SGreg Clayton const char *
10328041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic (bool is_host)
10428041352SGreg Clayton {
10528041352SGreg Clayton     if (is_host)
10628041352SGreg Clayton         return "Local Linux user platform plug-in.";
10728041352SGreg Clayton     else
10828041352SGreg Clayton         return "Remote Linux user platform plug-in.";
109ecc11474SStephen Wilson }
110ecc11474SStephen Wilson 
111e996fd30SGreg Clayton void
112e996fd30SGreg Clayton PlatformLinux::Initialize ()
113e996fd30SGreg Clayton {
11428041352SGreg Clayton     if (g_initialize_count++ == 0)
115ecc11474SStephen Wilson     {
11628041352SGreg Clayton #if defined(__linux__)
11728041352SGreg Clayton         PlatformSP default_platform_sp (new PlatformLinux(true));
11828041352SGreg Clayton         default_platform_sp->SetSystemArchitecture (Host::GetArchitecture());
119e996fd30SGreg Clayton         Platform::SetDefaultPlatform (default_platform_sp);
12028041352SGreg Clayton #endif
12128041352SGreg Clayton         PluginManager::RegisterPlugin(PlatformLinux::GetShortPluginNameStatic(false),
12228041352SGreg Clayton                                       PlatformLinux::GetPluginDescriptionStatic(false),
12328041352SGreg Clayton                                       PlatformLinux::CreateInstance);
124ecc11474SStephen Wilson     }
125e996fd30SGreg Clayton }
126e996fd30SGreg Clayton 
127e996fd30SGreg Clayton void
128e996fd30SGreg Clayton PlatformLinux::Terminate ()
129e996fd30SGreg Clayton {
13028041352SGreg Clayton     if (g_initialize_count > 0)
13128041352SGreg Clayton     {
13228041352SGreg Clayton         if (--g_initialize_count == 0)
13328041352SGreg Clayton         {
13428041352SGreg Clayton             PluginManager::UnregisterPlugin (PlatformLinux::CreateInstance);
135e996fd30SGreg Clayton         }
13628041352SGreg Clayton     }
13728041352SGreg Clayton }
138e996fd30SGreg Clayton 
139e996fd30SGreg Clayton Error
140e996fd30SGreg Clayton PlatformLinux::ResolveExecutable (const FileSpec &exe_file,
141e996fd30SGreg Clayton                                   const ArchSpec &exe_arch,
142ea5e0cc3SGreg Clayton                                   lldb::ModuleSP &exe_module_sp,
143ea5e0cc3SGreg Clayton                                   const FileSpecList *module_search_paths_ptr)
144e996fd30SGreg Clayton {
145e996fd30SGreg Clayton     Error error;
146e996fd30SGreg Clayton     // Nothing special to do here, just use the actual file and architecture
147e996fd30SGreg Clayton 
14828041352SGreg Clayton     char exe_path[PATH_MAX];
149e996fd30SGreg Clayton     FileSpec resolved_exe_file (exe_file);
150e996fd30SGreg Clayton 
15128041352SGreg Clayton     if (IsHost())
15228041352SGreg Clayton     {
15328041352SGreg Clayton         // If we have "ls" as the exe_file, resolve the executable location based on
154e996fd30SGreg Clayton         // the current path variables
155e996fd30SGreg Clayton         if (!resolved_exe_file.Exists())
15628041352SGreg Clayton         {
15728041352SGreg Clayton             exe_file.GetPath(exe_path, sizeof(exe_path));
15828041352SGreg Clayton             resolved_exe_file.SetFile(exe_path, true);
15928041352SGreg Clayton         }
16028041352SGreg Clayton 
16128041352SGreg Clayton         if (!resolved_exe_file.Exists())
162e996fd30SGreg Clayton             resolved_exe_file.ResolveExecutableLocation ();
163e996fd30SGreg Clayton 
16428041352SGreg Clayton         if (resolved_exe_file.Exists())
16528041352SGreg Clayton             error.Clear();
16628041352SGreg Clayton         else
16728041352SGreg Clayton         {
16828041352SGreg Clayton             exe_file.GetPath(exe_path, sizeof(exe_path));
16928041352SGreg Clayton             error.SetErrorStringWithFormat("unable to find executable for '%s'", exe_path);
17028041352SGreg Clayton         }
17128041352SGreg Clayton     }
17228041352SGreg Clayton     else
17328041352SGreg Clayton     {
17428041352SGreg Clayton         if (m_remote_platform_sp)
17528041352SGreg Clayton         {
17628041352SGreg Clayton             error = m_remote_platform_sp->ResolveExecutable (exe_file,
17728041352SGreg Clayton                                                              exe_arch,
1780c90ef47SGreg Clayton                                                              exe_module_sp,
1790c90ef47SGreg Clayton                                                              NULL);
18028041352SGreg Clayton         }
18128041352SGreg Clayton         else
18228041352SGreg Clayton         {
18328041352SGreg Clayton             // We may connect to a process and use the provided executable (Don't use local $PATH).
184e996fd30SGreg Clayton 
185e996fd30SGreg Clayton             if (resolved_exe_file.Exists())
18628041352SGreg Clayton                 error.Clear();
18728041352SGreg Clayton             else
18828041352SGreg Clayton                 error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", exe_path);
18928041352SGreg Clayton         }
19028041352SGreg Clayton     }
19128041352SGreg Clayton 
19228041352SGreg Clayton     if (error.Success())
193e996fd30SGreg Clayton     {
194ea5e0cc3SGreg Clayton         ModuleSpec module_spec (resolved_exe_file, exe_arch);
195e996fd30SGreg Clayton         if (exe_arch.IsValid())
196e996fd30SGreg Clayton         {
197ea5e0cc3SGreg Clayton             error = ModuleList::GetSharedModule (module_spec,
198e996fd30SGreg Clayton                                                  exe_module_sp,
199e996fd30SGreg Clayton                                                  NULL,
2000c90ef47SGreg Clayton                                                  NULL,
201e996fd30SGreg Clayton                                                  NULL);
202e996fd30SGreg Clayton 
203e635db49SSean Callanan             // TODO find out why exe_module_sp might be NULL
204e635db49SSean Callanan             if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
205e996fd30SGreg Clayton             {
206e996fd30SGreg Clayton                 exe_module_sp.reset();
207e996fd30SGreg Clayton                 error.SetErrorStringWithFormat ("'%s%s%s' doesn't contain the architecture %s",
208e996fd30SGreg Clayton                                                 exe_file.GetDirectory().AsCString(""),
209e996fd30SGreg Clayton                                                 exe_file.GetDirectory() ? "/" : "",
210e996fd30SGreg Clayton                                                 exe_file.GetFilename().AsCString(""),
211e996fd30SGreg Clayton                                                 exe_arch.GetArchitectureName());
212e996fd30SGreg Clayton             }
213e996fd30SGreg Clayton         }
214e996fd30SGreg Clayton         else
215e996fd30SGreg Clayton         {
216e996fd30SGreg Clayton             // No valid architecture was specified, ask the platform for
217e996fd30SGreg Clayton             // the architectures that we should be using (in the correct order)
218e996fd30SGreg Clayton             // and see if we can find a match that way
219e996fd30SGreg Clayton             StreamString arch_names;
220ea5e0cc3SGreg Clayton             for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx)
221e996fd30SGreg Clayton             {
222ea5e0cc3SGreg Clayton                 error = ModuleList::GetSharedModule (module_spec,
223e996fd30SGreg Clayton                                                      exe_module_sp,
224e996fd30SGreg Clayton                                                      NULL,
2250c90ef47SGreg Clayton                                                      NULL,
226e996fd30SGreg Clayton                                                      NULL);
227e996fd30SGreg Clayton                 // Did we find an executable using one of the
228e996fd30SGreg Clayton                 if (error.Success())
229e996fd30SGreg Clayton                 {
230e996fd30SGreg Clayton                     if (exe_module_sp && exe_module_sp->GetObjectFile())
231e996fd30SGreg Clayton                         break;
232e996fd30SGreg Clayton                     else
233e996fd30SGreg Clayton                         error.SetErrorToGenericError();
234e996fd30SGreg Clayton                 }
235e996fd30SGreg Clayton 
236e996fd30SGreg Clayton                 if (idx > 0)
237e996fd30SGreg Clayton                     arch_names.PutCString (", ");
238ea5e0cc3SGreg Clayton                 arch_names.PutCString (module_spec.GetArchitecture().GetArchitectureName());
239e996fd30SGreg Clayton             }
240e996fd30SGreg Clayton 
241e996fd30SGreg Clayton             if (error.Fail() || !exe_module_sp)
242e996fd30SGreg Clayton             {
243e996fd30SGreg Clayton                 error.SetErrorStringWithFormat ("'%s%s%s' doesn't contain any '%s' platform architectures: %s",
244e996fd30SGreg Clayton                                                 exe_file.GetDirectory().AsCString(""),
245e996fd30SGreg Clayton                                                 exe_file.GetDirectory() ? "/" : "",
246e996fd30SGreg Clayton                                                 exe_file.GetFilename().AsCString(""),
247e996fd30SGreg Clayton                                                 GetShortPluginName(),
248e996fd30SGreg Clayton                                                 arch_names.GetString().c_str());
249e996fd30SGreg Clayton             }
250e996fd30SGreg Clayton         }
251e996fd30SGreg Clayton     }
252e996fd30SGreg Clayton 
253e996fd30SGreg Clayton     return error;
254e996fd30SGreg Clayton }
255e996fd30SGreg Clayton 
256e996fd30SGreg Clayton Error
25778decfd0SStephen Wilson PlatformLinux::GetFile (const FileSpec &platform_file,
25828041352SGreg Clayton                         const UUID *uuid_ptr, FileSpec &local_file)
259e996fd30SGreg Clayton {
26028041352SGreg Clayton     if (IsRemote())
26128041352SGreg Clayton     {
26228041352SGreg Clayton         if (m_remote_platform_sp)
26328041352SGreg Clayton             return m_remote_platform_sp->GetFile (platform_file, uuid_ptr, local_file);
26428041352SGreg Clayton     }
26528041352SGreg Clayton 
266e996fd30SGreg Clayton     // Default to the local case
267e996fd30SGreg Clayton     local_file = platform_file;
268e996fd30SGreg Clayton     return Error();
269e996fd30SGreg Clayton }
270e996fd30SGreg Clayton 
271e996fd30SGreg Clayton 
272e996fd30SGreg Clayton //------------------------------------------------------------------
273e996fd30SGreg Clayton /// Default Constructor
274e996fd30SGreg Clayton //------------------------------------------------------------------
27528041352SGreg Clayton PlatformLinux::PlatformLinux (bool is_host) :
27628041352SGreg Clayton     Platform(is_host),  // This is the local host platform
27728041352SGreg Clayton     m_remote_platform_sp ()
278e996fd30SGreg Clayton {
279e996fd30SGreg Clayton }
280e996fd30SGreg Clayton 
281e996fd30SGreg Clayton //------------------------------------------------------------------
282e996fd30SGreg Clayton /// Destructor.
283e996fd30SGreg Clayton ///
284e996fd30SGreg Clayton /// The destructor is virtual since this class is designed to be
285e996fd30SGreg Clayton /// inherited from by the plug-in instance.
286e996fd30SGreg Clayton //------------------------------------------------------------------
287e996fd30SGreg Clayton PlatformLinux::~PlatformLinux()
288e996fd30SGreg Clayton {
289e996fd30SGreg Clayton }
290e996fd30SGreg Clayton 
291e996fd30SGreg Clayton bool
29213e8e1c3SJohnny Chen PlatformLinux::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
293e996fd30SGreg Clayton {
29428041352SGreg Clayton     bool success = false;
29528041352SGreg Clayton     if (IsHost())
29628041352SGreg Clayton     {
29728041352SGreg Clayton         success = Platform::GetProcessInfo (pid, process_info);
29828041352SGreg Clayton     }
29928041352SGreg Clayton     else
30028041352SGreg Clayton     {
30128041352SGreg Clayton         if (m_remote_platform_sp)
30228041352SGreg Clayton             success = m_remote_platform_sp->GetProcessInfo (pid, process_info);
30328041352SGreg Clayton     }
30428041352SGreg Clayton     return success;
305e996fd30SGreg Clayton }
306e996fd30SGreg Clayton 
307e996fd30SGreg Clayton bool
308e996fd30SGreg Clayton PlatformLinux::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
309e996fd30SGreg Clayton {
310e996fd30SGreg Clayton     if (idx == 0)
311e996fd30SGreg Clayton     {
312e996fd30SGreg Clayton         arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
313e996fd30SGreg Clayton         return arch.IsValid();
314e996fd30SGreg Clayton     }
315e996fd30SGreg Clayton     return false;
316e996fd30SGreg Clayton }
317ecc11474SStephen Wilson 
318ecc11474SStephen Wilson void
319ecc11474SStephen Wilson PlatformLinux::GetStatus (Stream &strm)
320ecc11474SStephen Wilson {
321ecc11474SStephen Wilson     struct utsname un;
322ecc11474SStephen Wilson 
323ecc11474SStephen Wilson     if (uname(&un)) {
324ecc11474SStephen Wilson         strm << "Linux";
325ecc11474SStephen Wilson         return;
326ecc11474SStephen Wilson     }
327ecc11474SStephen Wilson 
328ecc11474SStephen Wilson     strm << un.sysname << ' ' << un.release << ' ' << un.version << '\n';
329ecc11474SStephen Wilson }
330ecc11474SStephen Wilson 
331ecc11474SStephen Wilson size_t
332ecc11474SStephen Wilson PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target,
333ecc11474SStephen Wilson                                                 BreakpointSite *bp_site)
334ecc11474SStephen Wilson {
335ecc11474SStephen Wilson     ArchSpec arch = target.GetArchitecture();
33628041352SGreg Clayton     const uint8_t *trap_opcode = NULL;
33728041352SGreg Clayton     size_t trap_opcode_size = 0;
338ecc11474SStephen Wilson 
339ecc11474SStephen Wilson     switch (arch.GetCore())
340ecc11474SStephen Wilson     {
341ecc11474SStephen Wilson     default:
342ecc11474SStephen Wilson         assert(false && "CPU type not supported!");
343ecc11474SStephen Wilson         break;
344ecc11474SStephen Wilson 
345ecc11474SStephen Wilson     case ArchSpec::eCore_x86_32_i386:
346ecc11474SStephen Wilson     case ArchSpec::eCore_x86_64_x86_64:
34728041352SGreg Clayton         {
34828041352SGreg Clayton             static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
34928041352SGreg Clayton             trap_opcode = g_i386_breakpoint_opcode;
35028041352SGreg Clayton             trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
35128041352SGreg Clayton         }
352ecc11474SStephen Wilson         break;
353ecc11474SStephen Wilson     }
354ecc11474SStephen Wilson 
35528041352SGreg Clayton     if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
35628041352SGreg Clayton         return trap_opcode_size;
35728041352SGreg Clayton     return 0;
35828041352SGreg Clayton }
35928041352SGreg Clayton 
36028041352SGreg Clayton Error
36128041352SGreg Clayton PlatformLinux::LaunchProcess (ProcessLaunchInfo &launch_info)
36228041352SGreg Clayton {
36328041352SGreg Clayton     Error error;
36428041352SGreg Clayton 
36528041352SGreg Clayton     if (IsHost())
36628041352SGreg Clayton     {
36728041352SGreg Clayton         if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
36828041352SGreg Clayton         {
36928041352SGreg Clayton             const bool is_localhost = true;
370d1cf11a7SGreg Clayton             const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
371d1cf11a7SGreg Clayton             const bool first_arg_is_full_shell_command = false;
372d1cf11a7SGreg Clayton             if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
373d1cf11a7SGreg Clayton                                                                   is_localhost,
374d1cf11a7SGreg Clayton                                                                   will_debug,
375d1cf11a7SGreg Clayton                                                                   first_arg_is_full_shell_command))
37628041352SGreg Clayton                 return error;
37728041352SGreg Clayton         }
37828041352SGreg Clayton         error = Platform::LaunchProcess (launch_info);
37928041352SGreg Clayton     }
38028041352SGreg Clayton     else
38128041352SGreg Clayton     {
38228041352SGreg Clayton         error.SetErrorString ("the platform is not currently connected");
38328041352SGreg Clayton     }
38428041352SGreg Clayton     return error;
385ecc11474SStephen Wilson }
38613e8e1c3SJohnny Chen 
38713e8e1c3SJohnny Chen lldb::ProcessSP
388fb2b629dSPeter Collingbourne PlatformLinux::Attach(ProcessAttachInfo &attach_info,
38913e8e1c3SJohnny Chen                       Debugger &debugger,
39013e8e1c3SJohnny Chen                       Target *target,
39113e8e1c3SJohnny Chen                       Listener &listener,
39213e8e1c3SJohnny Chen                       Error &error)
39313e8e1c3SJohnny Chen {
39428041352SGreg Clayton     lldb::ProcessSP process_sp;
39528041352SGreg Clayton     if (IsHost())
39628041352SGreg Clayton     {
39728041352SGreg Clayton         if (target == NULL)
39828041352SGreg Clayton         {
39928041352SGreg Clayton             TargetSP new_target_sp;
40028041352SGreg Clayton             FileSpec emptyFileSpec;
40128041352SGreg Clayton             ArchSpec emptyArchSpec;
40228041352SGreg Clayton 
40328041352SGreg Clayton             error = debugger.GetTargetList().CreateTarget (debugger,
40428041352SGreg Clayton                                                            emptyFileSpec,
40528041352SGreg Clayton                                                            emptyArchSpec,
40628041352SGreg Clayton                                                            false,
40728041352SGreg Clayton                                                            m_remote_platform_sp,
40828041352SGreg Clayton                                                            new_target_sp);
40928041352SGreg Clayton             target = new_target_sp.get();
41028041352SGreg Clayton         }
41128041352SGreg Clayton         else
41228041352SGreg Clayton             error.Clear();
41328041352SGreg Clayton 
41428041352SGreg Clayton         if (target && error.Success())
41528041352SGreg Clayton         {
41628041352SGreg Clayton             debugger.GetTargetList().SetSelectedTarget(target);
41728041352SGreg Clayton 
4180c90ef47SGreg Clayton             process_sp = target->CreateProcess (listener,
4190c90ef47SGreg Clayton                                                 attach_info.GetProcessPluginName(),
4200c90ef47SGreg Clayton                                                 NULL);
42128041352SGreg Clayton 
42228041352SGreg Clayton             if (process_sp)
42328041352SGreg Clayton                 error = process_sp->Attach (attach_info);
42428041352SGreg Clayton         }
42528041352SGreg Clayton     }
42628041352SGreg Clayton     else
42728041352SGreg Clayton     {
42828041352SGreg Clayton         if (m_remote_platform_sp)
42928041352SGreg Clayton             process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, listener, error);
43028041352SGreg Clayton         else
43128041352SGreg Clayton             error.SetErrorString ("the platform is not currently connected");
43228041352SGreg Clayton     }
43328041352SGreg Clayton     return process_sp;
43413e8e1c3SJohnny Chen }
435