1 //===-- PlatformRemoteGDBServer.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 "lldb/lldb-python.h"
11 
12 #include "PlatformRemoteGDBServer.h"
13 #include "lldb/Host/Config.h"
14 
15 // C++ Includes
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/Breakpoint/BreakpointLocation.h"
19 #include "lldb/Core/Debugger.h"
20 #include "lldb/Core/Error.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Module.h"
23 #include "lldb/Core/ModuleList.h"
24 #include "lldb/Core/ModuleSpec.h"
25 #include "lldb/Core/PluginManager.h"
26 #include "lldb/Core/StreamString.h"
27 #include "lldb/Host/ConnectionFileDescriptor.h"
28 #include "lldb/Host/FileSpec.h"
29 #include "lldb/Host/Host.h"
30 #include "lldb/Target/Process.h"
31 #include "lldb/Target/Target.h"
32 
33 #include "Utility/UriParser.h"
34 
35 using namespace lldb;
36 using namespace lldb_private;
37 
38 static bool g_initialized = false;
39 
40 void
41 PlatformRemoteGDBServer::Initialize ()
42 {
43     if (g_initialized == false)
44     {
45         g_initialized = true;
46         PluginManager::RegisterPlugin (PlatformRemoteGDBServer::GetPluginNameStatic(),
47                                        PlatformRemoteGDBServer::GetDescriptionStatic(),
48                                        PlatformRemoteGDBServer::CreateInstance);
49     }
50 }
51 
52 void
53 PlatformRemoteGDBServer::Terminate ()
54 {
55     if (g_initialized)
56     {
57         g_initialized = false;
58         PluginManager::UnregisterPlugin (PlatformRemoteGDBServer::CreateInstance);
59     }
60 }
61 
62 PlatformSP
63 PlatformRemoteGDBServer::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
64 {
65     bool create = force;
66     if (!create)
67     {
68         create = !arch->TripleVendorWasSpecified() && !arch->TripleOSWasSpecified();
69     }
70     if (create)
71         return PlatformSP(new PlatformRemoteGDBServer());
72     return PlatformSP();
73 }
74 
75 
76 lldb_private::ConstString
77 PlatformRemoteGDBServer::GetPluginNameStatic()
78 {
79     static ConstString g_name("remote-gdb-server");
80     return g_name;
81 }
82 
83 const char *
84 PlatformRemoteGDBServer::GetDescriptionStatic()
85 {
86     return "A platform that uses the GDB remote protocol as the communication transport.";
87 }
88 
89 const char *
90 PlatformRemoteGDBServer::GetDescription ()
91 {
92     if (m_platform_description.empty())
93     {
94         if (IsConnected())
95         {
96             // Send the get description packet
97         }
98     }
99 
100     if (!m_platform_description.empty())
101         return m_platform_description.c_str();
102     return GetDescriptionStatic();
103 }
104 
105 Error
106 PlatformRemoteGDBServer::ResolveExecutable (const ModuleSpec &module_spec,
107                                             lldb::ModuleSP &exe_module_sp,
108                                             const FileSpecList *module_search_paths_ptr)
109 {
110     // copied from PlatformRemoteiOS
111 
112     Error error;
113     // Nothing special to do here, just use the actual file and architecture
114 
115     ModuleSpec resolved_module_spec(module_spec);
116 
117     // Resolve any executable within an apk on Android?
118     //Host::ResolveExecutableInBundle (resolved_module_spec.GetFileSpec());
119 
120     if (resolved_module_spec.GetFileSpec().Exists())
121     {
122         if (resolved_module_spec.GetArchitecture().IsValid() || resolved_module_spec.GetUUID().IsValid())
123         {
124             error = ModuleList::GetSharedModule (resolved_module_spec,
125                                                  exe_module_sp,
126                                                  NULL,
127                                                  NULL,
128                                                  NULL);
129 
130             if (exe_module_sp && exe_module_sp->GetObjectFile())
131                 return error;
132             exe_module_sp.reset();
133         }
134         // No valid architecture was specified or the exact arch wasn't
135         // found so ask the platform for the architectures that we should be
136         // using (in the correct order) and see if we can find a match that way
137         StreamString arch_names;
138         for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx)
139         {
140             error = ModuleList::GetSharedModule (resolved_module_spec,
141                                                  exe_module_sp,
142                                                  NULL,
143                                                  NULL,
144                                                  NULL);
145             // Did we find an executable using one of the
146             if (error.Success())
147             {
148                 if (exe_module_sp && exe_module_sp->GetObjectFile())
149                     break;
150                 else
151                     error.SetErrorToGenericError();
152             }
153 
154             if (idx > 0)
155                 arch_names.PutCString (", ");
156             arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName());
157         }
158 
159         if (error.Fail() || !exe_module_sp)
160         {
161             if (resolved_module_spec.GetFileSpec().Readable())
162             {
163                 error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
164                                                 resolved_module_spec.GetFileSpec().GetPath().c_str(),
165                                                 GetPluginName().GetCString(),
166                                                 arch_names.GetString().c_str());
167             }
168             else
169             {
170                 error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str());
171             }
172         }
173     }
174     else
175     {
176         error.SetErrorStringWithFormat ("'%s' does not exist",
177                                         resolved_module_spec.GetFileSpec().GetPath().c_str());
178     }
179 
180     return error;
181 }
182 
183 Error
184 PlatformRemoteGDBServer::GetFileWithUUID (const FileSpec &platform_file,
185                                           const UUID *uuid_ptr,
186                                           FileSpec &local_file)
187 {
188     // Default to the local case
189     local_file = platform_file;
190     return Error();
191 }
192 
193 //------------------------------------------------------------------
194 /// Default Constructor
195 //------------------------------------------------------------------
196 PlatformRemoteGDBServer::PlatformRemoteGDBServer () :
197     Platform(false), // This is a remote platform
198     m_gdb_client(true)
199 {
200 }
201 
202 //------------------------------------------------------------------
203 /// Destructor.
204 ///
205 /// The destructor is virtual since this class is designed to be
206 /// inherited from by the plug-in instance.
207 //------------------------------------------------------------------
208 PlatformRemoteGDBServer::~PlatformRemoteGDBServer()
209 {
210 }
211 
212 bool
213 PlatformRemoteGDBServer::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
214 {
215     ArchSpec remote_arch = m_gdb_client.GetSystemArchitecture();
216 
217     // TODO: 64 bit systems should also advertize support for 32 bit arch
218     // unknown CPU, we just support the one arch
219     if (idx == 0)
220     {
221         arch = remote_arch;
222         return true;
223     }
224     return false;
225 }
226 
227 size_t
228 PlatformRemoteGDBServer::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site)
229 {
230     // This isn't needed if the z/Z packets are supported in the GDB remote
231     // server. But we might need a packet to detect this.
232     return 0;
233 }
234 
235 bool
236 PlatformRemoteGDBServer::GetRemoteOSVersion ()
237 {
238     uint32_t major, minor, update;
239     if (m_gdb_client.GetOSVersion (major, minor, update))
240     {
241         m_major_os_version = major;
242         m_minor_os_version = minor;
243         m_update_os_version = update;
244         return true;
245     }
246     return false;
247 }
248 
249 bool
250 PlatformRemoteGDBServer::GetRemoteOSBuildString (std::string &s)
251 {
252     return m_gdb_client.GetOSBuildString (s);
253 }
254 
255 bool
256 PlatformRemoteGDBServer::GetRemoteOSKernelDescription (std::string &s)
257 {
258     return m_gdb_client.GetOSKernelDescription (s);
259 }
260 
261 // Remote Platform subclasses need to override this function
262 ArchSpec
263 PlatformRemoteGDBServer::GetRemoteSystemArchitecture ()
264 {
265     return m_gdb_client.GetSystemArchitecture();
266 }
267 
268 lldb_private::ConstString
269 PlatformRemoteGDBServer::GetRemoteWorkingDirectory()
270 {
271     if (IsConnected())
272     {
273         Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
274         std::string cwd;
275         if (m_gdb_client.GetWorkingDir(cwd))
276         {
277             ConstString working_dir(cwd.c_str());
278             if (log)
279                 log->Printf("PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'", working_dir.GetCString());
280             return working_dir;
281         }
282         else
283         {
284             return ConstString();
285         }
286     }
287     else
288     {
289         return Platform::GetRemoteWorkingDirectory();
290     }
291 }
292 
293 bool
294 PlatformRemoteGDBServer::SetRemoteWorkingDirectory(const lldb_private::ConstString &path)
295 {
296     if (IsConnected())
297     {
298         // Clear the working directory it case it doesn't get set correctly. This will
299         // for use to re-read it
300         Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
301         if (log)
302             log->Printf("PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')", path.GetCString());
303         return m_gdb_client.SetWorkingDir(path.GetCString()) == 0;
304     }
305     else
306         return Platform::SetRemoteWorkingDirectory(path);
307 }
308 
309 bool
310 PlatformRemoteGDBServer::IsConnected () const
311 {
312     return m_gdb_client.IsConnected();
313 }
314 
315 Error
316 PlatformRemoteGDBServer::ConnectRemote (Args& args)
317 {
318     Error error;
319     if (IsConnected())
320     {
321         error.SetErrorStringWithFormat ("the platform is already connected to '%s', execute 'platform disconnect' to close the current connection",
322                                         GetHostname());
323     }
324     else
325     {
326         if (args.GetArgumentCount() == 1)
327         {
328             const char *url = args.GetArgumentAtIndex(0);
329             m_gdb_client.SetConnection (new ConnectionFileDescriptor());
330 
331             // we're going to reuse the hostname when we connect to the debugserver
332             std::string scheme;
333             int port;
334             std::string path;
335             if ( !UriParser::Parse(url, scheme, m_platform_hostname, port, path) )
336             {
337                 error.SetErrorString("invalid uri");
338                 return error;
339             }
340 
341             const ConnectionStatus status = m_gdb_client.Connect(url, &error);
342             if (status == eConnectionStatusSuccess)
343             {
344                 if (m_gdb_client.HandshakeWithServer(&error))
345                 {
346                     m_gdb_client.GetHostInfo();
347                     // If a working directory was set prior to connecting, send it down now
348                     if (m_working_dir)
349                         m_gdb_client.SetWorkingDir(m_working_dir.GetCString());
350                 }
351                 else
352                 {
353                     m_gdb_client.Disconnect();
354                     if (error.Success())
355                         error.SetErrorString("handshake failed");
356                 }
357             }
358         }
359         else
360         {
361             error.SetErrorString ("\"platform connect\" takes a single argument: <connect-url>");
362         }
363     }
364 
365     return error;
366 }
367 
368 Error
369 PlatformRemoteGDBServer::DisconnectRemote ()
370 {
371     Error error;
372     m_gdb_client.Disconnect(&error);
373     return error;
374 }
375 
376 const char *
377 PlatformRemoteGDBServer::GetHostname ()
378 {
379     m_gdb_client.GetHostname (m_name);
380     if (m_name.empty())
381         return NULL;
382     return m_name.c_str();
383 }
384 
385 const char *
386 PlatformRemoteGDBServer::GetUserName (uint32_t uid)
387 {
388     // Try and get a cache user name first
389     const char *cached_user_name = Platform::GetUserName(uid);
390     if (cached_user_name)
391         return cached_user_name;
392     std::string name;
393     if (m_gdb_client.GetUserName(uid, name))
394         return SetCachedUserName(uid, name.c_str(), name.size());
395 
396     SetUserNameNotFound(uid); // Negative cache so we don't keep sending packets
397     return NULL;
398 }
399 
400 const char *
401 PlatformRemoteGDBServer::GetGroupName (uint32_t gid)
402 {
403     const char *cached_group_name = Platform::GetGroupName(gid);
404     if (cached_group_name)
405         return cached_group_name;
406     std::string name;
407     if (m_gdb_client.GetGroupName(gid, name))
408         return SetCachedGroupName(gid, name.c_str(), name.size());
409 
410     SetGroupNameNotFound(gid); // Negative cache so we don't keep sending packets
411     return NULL;
412 }
413 
414 uint32_t
415 PlatformRemoteGDBServer::FindProcesses (const ProcessInstanceInfoMatch &match_info,
416                                         ProcessInstanceInfoList &process_infos)
417 {
418     return m_gdb_client.FindProcesses (match_info, process_infos);
419 }
420 
421 bool
422 PlatformRemoteGDBServer::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
423 {
424     return m_gdb_client.GetProcessInfo (pid, process_info);
425 }
426 
427 
428 Error
429 PlatformRemoteGDBServer::LaunchProcess (ProcessLaunchInfo &launch_info)
430 {
431     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
432     Error error;
433     lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
434 
435     if (log)
436         log->Printf ("PlatformRemoteGDBServer::%s() called", __FUNCTION__);
437 
438     m_gdb_client.SetSTDIN ("/dev/null");
439     m_gdb_client.SetSTDOUT ("/dev/null");
440     m_gdb_client.SetSTDERR ("/dev/null");
441     m_gdb_client.SetDisableASLR (launch_info.GetFlags().Test (eLaunchFlagDisableASLR));
442     m_gdb_client.SetDetachOnError (launch_info.GetFlags().Test (eLaunchFlagDetachOnError));
443 
444     const char *working_dir = launch_info.GetWorkingDirectory();
445     if (working_dir && working_dir[0])
446     {
447         m_gdb_client.SetWorkingDir (working_dir);
448     }
449 
450     // Send the environment and the program + arguments after we connect
451     const char **envp = launch_info.GetEnvironmentEntries().GetConstArgumentVector();
452 
453     if (envp)
454     {
455         const char *env_entry;
456         for (int i=0; (env_entry = envp[i]); ++i)
457         {
458             if (m_gdb_client.SendEnvironmentPacket(env_entry) != 0)
459                 break;
460         }
461     }
462 
463     ArchSpec arch_spec = launch_info.GetArchitecture();
464     const char *arch_triple = arch_spec.GetTriple().str().c_str();
465 
466     m_gdb_client.SendLaunchArchPacket(arch_triple);
467     if (log)
468         log->Printf ("PlatformRemoteGDBServer::%s() set launch architecture triple to '%s'", __FUNCTION__, arch_triple ? arch_triple : "<NULL>");
469 
470     const uint32_t old_packet_timeout = m_gdb_client.SetPacketTimeout (5);
471     int arg_packet_err = m_gdb_client.SendArgumentsPacket (launch_info);
472     m_gdb_client.SetPacketTimeout (old_packet_timeout);
473     if (arg_packet_err == 0)
474     {
475         std::string error_str;
476         if (m_gdb_client.GetLaunchSuccess (error_str))
477         {
478             pid = m_gdb_client.GetCurrentProcessID ();
479             if (pid != LLDB_INVALID_PROCESS_ID)
480             {
481                 launch_info.SetProcessID (pid);
482                 if (log)
483                     log->Printf ("PlatformRemoteGDBServer::%s() pid %" PRIu64 " launched successfully", __FUNCTION__, pid);
484             }
485             else
486             {
487                 if (log)
488                     log->Printf ("PlatformRemoteGDBServer::%s() launch succeeded but we didn't get a valid process id back!", __FUNCTION__);
489                 // FIXME isn't this an error condition? Do we need to set an error here?  Check with Greg.
490             }
491         }
492         else
493         {
494             error.SetErrorString (error_str.c_str());
495             if (log)
496                 log->Printf ("PlatformRemoteGDBServer::%s() launch failed: %s", __FUNCTION__, error.AsCString ());
497         }
498     }
499     else
500     {
501         error.SetErrorStringWithFormat("'A' packet returned an error: %i", arg_packet_err);
502     }
503     return error;
504 }
505 
506 lldb::ProcessSP
507 PlatformRemoteGDBServer::DebugProcess (lldb_private::ProcessLaunchInfo &launch_info,
508                                        lldb_private::Debugger &debugger,
509                                        lldb_private::Target *target,       // Can be NULL, if NULL create a new target, else use existing one
510                                        lldb_private::Error &error)
511 {
512     lldb::ProcessSP process_sp;
513     if (IsRemote())
514     {
515         if (IsConnected())
516         {
517             lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
518             ArchSpec remote_arch = GetRemoteSystemArchitecture();
519             llvm::Triple &remote_triple = remote_arch.GetTriple();
520             uint16_t port = 0;
521             if (remote_triple.getVendor() == llvm::Triple::Apple && remote_triple.getOS() == llvm::Triple::IOS)
522             {
523                 // When remote debugging to iOS, we use a USB mux that always talks
524                 // to localhost, so we will need the remote debugserver to accept connections
525                 // only from localhost, no matter what our current hostname is
526                 port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "127.0.0.1");
527             }
528             else
529             {
530                 // All other hosts should use their actual hostname
531                 port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, NULL);
532             }
533 
534             if (port == 0)
535             {
536                 error.SetErrorStringWithFormat ("unable to launch a GDB server on '%s'", GetHostname ());
537             }
538             else
539             {
540                 if (target == NULL)
541                 {
542                     TargetSP new_target_sp;
543 
544                     error = debugger.GetTargetList().CreateTarget (debugger,
545                                                                    NULL,
546                                                                    NULL,
547                                                                    false,
548                                                                    NULL,
549                                                                    new_target_sp);
550                     target = new_target_sp.get();
551                 }
552                 else
553                     error.Clear();
554 
555                 if (target && error.Success())
556                 {
557                     debugger.GetTargetList().SetSelectedTarget(target);
558 
559                     // The darwin always currently uses the GDB remote debugger plug-in
560                     // so even when debugging locally we are debugging remotely!
561                     process_sp = target->CreateProcess (launch_info.GetListenerForProcess(debugger), "gdb-remote", NULL);
562 
563                     if (process_sp)
564                     {
565                         char connect_url[256];
566                         const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
567                         const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
568                         int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
569                         const int connect_url_len = ::snprintf (connect_url,
570                                                                 sizeof(connect_url),
571                                                                 "connect://%s:%u",
572                                                                 override_hostname ? override_hostname : m_platform_hostname.c_str(),
573                                                                 port + port_offset);
574                         assert (connect_url_len < (int)sizeof(connect_url));
575                         error = process_sp->ConnectRemote (NULL, connect_url);
576                         // Retry the connect remote one time...
577                         if (error.Fail())
578                             error = process_sp->ConnectRemote (NULL, connect_url);
579                         if (error.Success())
580                             error = process_sp->Launch(launch_info);
581                         else if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
582                         {
583                             printf ("error: connect remote failed (%s)\n", error.AsCString());
584                             m_gdb_client.KillSpawnedProcess(debugserver_pid);
585                         }
586                     }
587                 }
588             }
589         }
590         else
591         {
592             error.SetErrorString("not connected to remote gdb server");
593         }
594     }
595     return process_sp;
596 
597 }
598 
599 lldb::ProcessSP
600 PlatformRemoteGDBServer::Attach (lldb_private::ProcessAttachInfo &attach_info,
601                                  Debugger &debugger,
602                                  Target *target,       // Can be NULL, if NULL create a new target, else use existing one
603                                  Error &error)
604 {
605     lldb::ProcessSP process_sp;
606     if (IsRemote())
607     {
608         if (IsConnected())
609         {
610             lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
611             ArchSpec remote_arch = GetRemoteSystemArchitecture();
612             llvm::Triple &remote_triple = remote_arch.GetTriple();
613             uint16_t port = 0;
614             if (remote_triple.getVendor() == llvm::Triple::Apple && remote_triple.getOS() == llvm::Triple::IOS)
615             {
616                 // When remote debugging to iOS, we use a USB mux that always talks
617                 // to localhost, so we will need the remote debugserver to accept connections
618                 // only from localhost, no matter what our current hostname is
619                 port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "127.0.0.1");
620             }
621             else
622             {
623                 // All other hosts should use their actual hostname
624                 port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, NULL);
625             }
626 
627             if (port == 0)
628             {
629                 error.SetErrorStringWithFormat ("unable to launch a GDB server on '%s'", GetHostname ());
630             }
631             else
632             {
633                 if (target == NULL)
634                 {
635                     TargetSP new_target_sp;
636 
637                     error = debugger.GetTargetList().CreateTarget (debugger,
638                                                                    NULL,
639                                                                    NULL,
640                                                                    false,
641                                                                    NULL,
642                                                                    new_target_sp);
643                     target = new_target_sp.get();
644                 }
645                 else
646                     error.Clear();
647 
648                 if (target && error.Success())
649                 {
650                     debugger.GetTargetList().SetSelectedTarget(target);
651 
652                     // The darwin always currently uses the GDB remote debugger plug-in
653                     // so even when debugging locally we are debugging remotely!
654                     process_sp = target->CreateProcess (attach_info.GetListenerForProcess(debugger), "gdb-remote", NULL);
655 
656                     if (process_sp)
657                     {
658                         char connect_url[256];
659                         const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
660                         const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
661                         int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
662                         const int connect_url_len = ::snprintf (connect_url,
663                                                                 sizeof(connect_url),
664                                                                 "connect://%s:%u",
665                                                                 override_hostname ? override_hostname : m_platform_hostname.c_str(),
666                                                                 port + port_offset);
667                         assert (connect_url_len < (int)sizeof(connect_url));
668                         error = process_sp->ConnectRemote (NULL, connect_url);
669                         if (error.Success())
670                             error = process_sp->Attach(attach_info);
671                         else if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
672                         {
673                             m_gdb_client.KillSpawnedProcess(debugserver_pid);
674                         }
675                     }
676                 }
677             }
678         }
679         else
680         {
681             error.SetErrorString("not connected to remote gdb server");
682         }
683     }
684     return process_sp;
685 }
686 
687 Error
688 PlatformRemoteGDBServer::MakeDirectory (const char *path, uint32_t mode)
689 {
690     Error error = m_gdb_client.MakeDirectory(path,mode);
691     Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
692     if (log)
693         log->Printf ("PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) error = %u (%s)", path, mode, error.GetError(), error.AsCString());
694     return error;
695 }
696 
697 
698 Error
699 PlatformRemoteGDBServer::GetFilePermissions (const char *path, uint32_t &file_permissions)
700 {
701     Error error = m_gdb_client.GetFilePermissions(path, file_permissions);
702     Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
703     if (log)
704         log->Printf ("PlatformRemoteGDBServer::GetFilePermissions(path='%s', file_permissions=%o) error = %u (%s)", path, file_permissions, error.GetError(), error.AsCString());
705     return error;
706 }
707 
708 Error
709 PlatformRemoteGDBServer::SetFilePermissions (const char *path, uint32_t file_permissions)
710 {
711     Error error = m_gdb_client.SetFilePermissions(path, file_permissions);
712     Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
713     if (log)
714         log->Printf ("PlatformRemoteGDBServer::SetFilePermissions(path='%s', file_permissions=%o) error = %u (%s)", path, file_permissions, error.GetError(), error.AsCString());
715     return error;
716 }
717 
718 
719 lldb::user_id_t
720 PlatformRemoteGDBServer::OpenFile (const lldb_private::FileSpec& file_spec,
721                                    uint32_t flags,
722                                    uint32_t mode,
723                                    Error &error)
724 {
725     return m_gdb_client.OpenFile (file_spec, flags, mode, error);
726 }
727 
728 bool
729 PlatformRemoteGDBServer::CloseFile (lldb::user_id_t fd, Error &error)
730 {
731     return m_gdb_client.CloseFile (fd, error);
732 }
733 
734 lldb::user_id_t
735 PlatformRemoteGDBServer::GetFileSize (const lldb_private::FileSpec& file_spec)
736 {
737     return m_gdb_client.GetFileSize(file_spec);
738 }
739 
740 uint64_t
741 PlatformRemoteGDBServer::ReadFile (lldb::user_id_t fd,
742                                    uint64_t offset,
743                                    void *dst,
744                                    uint64_t dst_len,
745                                    Error &error)
746 {
747     return m_gdb_client.ReadFile (fd, offset, dst, dst_len, error);
748 }
749 
750 uint64_t
751 PlatformRemoteGDBServer::WriteFile (lldb::user_id_t fd,
752                                     uint64_t offset,
753                                     const void* src,
754                                     uint64_t src_len,
755                                     Error &error)
756 {
757     return m_gdb_client.WriteFile (fd, offset, src, src_len, error);
758 }
759 
760 lldb_private::Error
761 PlatformRemoteGDBServer::PutFile (const lldb_private::FileSpec& source,
762          const lldb_private::FileSpec& destination,
763          uint32_t uid,
764          uint32_t gid)
765 {
766     return Platform::PutFile(source,destination,uid,gid);
767 }
768 
769 Error
770 PlatformRemoteGDBServer::CreateSymlink (const char *src,    // The name of the link is in src
771                                         const char *dst)    // The symlink points to dst
772 {
773     Error error = m_gdb_client.CreateSymlink (src, dst);
774     Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
775     if (log)
776         log->Printf ("PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') error = %u (%s)", src, dst, error.GetError(), error.AsCString());
777     return error;
778 }
779 
780 Error
781 PlatformRemoteGDBServer::Unlink (const char *path)
782 {
783     Error error = m_gdb_client.Unlink (path);
784     Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
785     if (log)
786         log->Printf ("PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)", path, error.GetError(), error.AsCString());
787     return error;
788 }
789 
790 bool
791 PlatformRemoteGDBServer::GetFileExists (const lldb_private::FileSpec& file_spec)
792 {
793     return m_gdb_client.GetFileExists (file_spec);
794 }
795 
796 lldb_private::Error
797 PlatformRemoteGDBServer::RunShellCommand (const char *command,           // Shouldn't be NULL
798                                           const char *working_dir,       // Pass NULL to use the current working directory
799                                           int *status_ptr,               // Pass NULL if you don't want the process exit status
800                                           int *signo_ptr,                // Pass NULL if you don't want the signal that caused the process to exit
801                                           std::string *command_output,   // Pass NULL if you don't want the command output
802                                           uint32_t timeout_sec)          // Timeout in seconds to wait for shell program to finish
803 {
804     return m_gdb_client.RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
805 }
806 
807 void
808 PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames ()
809 {
810     m_trap_handlers.push_back (ConstString ("_sigtramp"));
811 }
812