1254721Semaste//===-- Platform.h ----------------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_Platform_h_
11254721Semaste#define liblldb_Platform_h_
12254721Semaste
13254721Semaste// C Includes
14254721Semaste// C++ Includes
15254721Semaste#include <map>
16254721Semaste#include <string>
17254721Semaste#include <vector>
18254721Semaste
19254721Semaste// Other libraries and framework includes
20254721Semaste// Project includes
21254721Semaste#include "lldb/lldb-public.h"
22254721Semaste#include "lldb/Core/ArchSpec.h"
23254721Semaste#include "lldb/Core/ConstString.h"
24254721Semaste#include "lldb/Core/PluginInterface.h"
25263363Semaste#include "lldb/Interpreter/Options.h"
26254721Semaste#include "lldb/Host/Mutex.h"
27254721Semaste
28254721Semastenamespace lldb_private {
29254721Semaste
30254721Semaste    //----------------------------------------------------------------------
31254721Semaste    /// @class Platform Platform.h "lldb/Target/Platform.h"
32254721Semaste    /// @brief A plug-in interface definition class for debug platform that
33254721Semaste    /// includes many platform abilities such as:
34254721Semaste    ///     @li getting platform information such as supported architectures,
35254721Semaste    ///         supported binary file formats and more
36254721Semaste    ///     @li launching new processes
37254721Semaste    ///     @li attaching to existing processes
38254721Semaste    ///     @li download/upload files
39254721Semaste    ///     @li execute shell commands
40254721Semaste    ///     @li listing and getting info for existing processes
41254721Semaste    ///     @li attaching and possibly debugging the platform's kernel
42254721Semaste    //----------------------------------------------------------------------
43263367Semaste    class Platform :
44263367Semaste        public PluginInterface
45254721Semaste    {
46254721Semaste    public:
47254721Semaste
48254721Semaste        //------------------------------------------------------------------
49254721Semaste        /// Get the native host platform plug-in.
50254721Semaste        ///
51254721Semaste        /// There should only be one of these for each host that LLDB runs
52254721Semaste        /// upon that should be statically compiled in and registered using
53254721Semaste        /// preprocessor macros or other similar build mechanisms in a
54254721Semaste        /// PlatformSubclass::Initialize() function.
55254721Semaste        ///
56254721Semaste        /// This platform will be used as the default platform when launching
57254721Semaste        /// or attaching to processes unless another platform is specified.
58254721Semaste        //------------------------------------------------------------------
59254721Semaste        static lldb::PlatformSP
60254721Semaste        GetDefaultPlatform ();
61254721Semaste
62254721Semaste        static lldb::PlatformSP
63254721Semaste        GetPlatformForArchitecture (const ArchSpec &arch,
64254721Semaste                                    ArchSpec *platform_arch_ptr);
65254721Semaste
66254721Semaste        static const char *
67254721Semaste        GetHostPlatformName ();
68254721Semaste
69254721Semaste        static void
70254721Semaste        SetDefaultPlatform (const lldb::PlatformSP &platform_sp);
71254721Semaste
72254721Semaste        static lldb::PlatformSP
73254721Semaste        Create (const char *platform_name, Error &error);
74254721Semaste
75254721Semaste        static lldb::PlatformSP
76254721Semaste        Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error);
77254721Semaste
78254721Semaste        static uint32_t
79254721Semaste        GetNumConnectedRemotePlatforms ();
80254721Semaste
81254721Semaste        static lldb::PlatformSP
82254721Semaste        GetConnectedRemotePlatformAtIndex (uint32_t idx);
83254721Semaste
84254721Semaste        //------------------------------------------------------------------
85254721Semaste        /// Default Constructor
86254721Semaste        //------------------------------------------------------------------
87254721Semaste        Platform (bool is_host_platform);
88254721Semaste
89254721Semaste        //------------------------------------------------------------------
90254721Semaste        /// Destructor.
91254721Semaste        ///
92254721Semaste        /// The destructor is virtual since this class is designed to be
93254721Semaste        /// inherited from by the plug-in instance.
94254721Semaste        //------------------------------------------------------------------
95254721Semaste        virtual
96254721Semaste        ~Platform();
97254721Semaste
98254721Semaste        //------------------------------------------------------------------
99254721Semaste        /// Find a platform plugin for a given process.
100254721Semaste        ///
101254721Semaste        /// Scans the installed Platform plug-ins and tries to find
102254721Semaste        /// an instance that can be used for \a process
103254721Semaste        ///
104254721Semaste        /// @param[in] process
105254721Semaste        ///     The process for which to try and locate a platform
106254721Semaste        ///     plug-in instance.
107254721Semaste        ///
108254721Semaste        /// @param[in] plugin_name
109254721Semaste        ///     An optional name of a specific platform plug-in that
110254721Semaste        ///     should be used. If NULL, pick the best plug-in.
111254721Semaste        //------------------------------------------------------------------
112254721Semaste        static Platform*
113254721Semaste        FindPlugin (Process *process, const ConstString &plugin_name);
114254721Semaste
115254721Semaste        //------------------------------------------------------------------
116254721Semaste        /// Set the target's executable based off of the existing
117254721Semaste        /// architecture information in \a target given a path to an
118254721Semaste        /// executable \a exe_file.
119254721Semaste        ///
120254721Semaste        /// Each platform knows the architectures that it supports and can
121254721Semaste        /// select the correct architecture slice within \a exe_file by
122254721Semaste        /// inspecting the architecture in \a target. If the target had an
123254721Semaste        /// architecture specified, then in can try and obey that request
124254721Semaste        /// and optionally fail if the architecture doesn't match up.
125254721Semaste        /// If no architecture is specified, the platform should select the
126254721Semaste        /// default architecture from \a exe_file. Any application bundles
127254721Semaste        /// or executable wrappers can also be inspected for the actual
128254721Semaste        /// application binary within the bundle that should be used.
129254721Semaste        ///
130254721Semaste        /// @return
131254721Semaste        ///     Returns \b true if this Platform plug-in was able to find
132254721Semaste        ///     a suitable executable, \b false otherwise.
133254721Semaste        //------------------------------------------------------------------
134254721Semaste        virtual Error
135254721Semaste        ResolveExecutable (const FileSpec &exe_file,
136254721Semaste                           const ArchSpec &arch,
137254721Semaste                           lldb::ModuleSP &module_sp,
138254721Semaste                           const FileSpecList *module_search_paths_ptr);
139254721Semaste
140254721Semaste
141254721Semaste        //------------------------------------------------------------------
142254721Semaste        /// Find a symbol file given a symbol file module specification.
143254721Semaste        ///
144254721Semaste        /// Each platform might have tricks to find symbol files for an
145254721Semaste        /// executable given information in a symbol file ModuleSpec. Some
146254721Semaste        /// platforms might also support symbol files that are bundles and
147254721Semaste        /// know how to extract the right symbol file given a bundle.
148254721Semaste        ///
149254721Semaste        /// @param[in] target
150254721Semaste        ///     The target in which we are trying to resolve the symbol file.
151254721Semaste        ///     The target has a list of modules that we might be able to
152254721Semaste        ///     use in order to help find the right symbol file. If the
153254721Semaste        ///     "m_file" or "m_platform_file" entries in the \a sym_spec
154254721Semaste        ///     are filled in, then we might be able to locate a module in
155254721Semaste        ///     the target, extract its UUID and locate a symbol file.
156254721Semaste        ///     If just the "m_uuid" is specified, then we might be able
157254721Semaste        ///     to find the module in the target that matches that UUID
158254721Semaste        ///     and pair the symbol file along with it. If just "m_symbol_file"
159254721Semaste        ///     is specified, we can use a variety of tricks to locate the
160254721Semaste        ///     symbols in an SDK, PDK, or other development kit location.
161254721Semaste        ///
162254721Semaste        /// @param[in] sym_spec
163254721Semaste        ///     A module spec that describes some information about the
164254721Semaste        ///     symbol file we are trying to resolve. The ModuleSpec might
165254721Semaste        ///     contain the following:
166254721Semaste        ///     m_file - A full or partial path to an executable from the
167254721Semaste        ///              target (might be empty).
168254721Semaste        ///     m_platform_file - Another executable hint that contains
169254721Semaste        ///                       the path to the file as known on the
170254721Semaste        ///                       local/remote platform.
171254721Semaste        ///     m_symbol_file - A full or partial path to a symbol file
172254721Semaste        ///                     or symbol bundle that should be used when
173254721Semaste        ///                     trying to resolve the symbol file.
174254721Semaste        ///     m_arch - The architecture we are looking for when resolving
175254721Semaste        ///              the symbol file.
176254721Semaste        ///     m_uuid - The UUID of the executable and symbol file. This
177254721Semaste        ///              can often be used to match up an exectuable with
178254721Semaste        ///              a symbol file, or resolve an symbol file in a
179254721Semaste        ///              symbol file bundle.
180254721Semaste        ///
181254721Semaste        /// @param[out] sym_file
182254721Semaste        ///     The resolved symbol file spec if the returned error
183254721Semaste        ///     indicates succes.
184254721Semaste        ///
185254721Semaste        /// @return
186254721Semaste        ///     Returns an error that describes success or failure.
187254721Semaste        //------------------------------------------------------------------
188254721Semaste        virtual Error
189254721Semaste        ResolveSymbolFile (Target &target,
190254721Semaste                           const ModuleSpec &sym_spec,
191254721Semaste                           FileSpec &sym_file);
192254721Semaste
193254721Semaste        //------------------------------------------------------------------
194254721Semaste        /// Resolves the FileSpec to a (possibly) remote path. Remote
195254721Semaste        /// platforms must override this to resolve to a path on the remote
196254721Semaste        /// side.
197254721Semaste        //------------------------------------------------------------------
198254721Semaste        virtual bool
199254721Semaste        ResolveRemotePath (const FileSpec &platform_path,
200254721Semaste                           FileSpec &resolved_platform_path);
201254721Semaste
202254721Semaste        bool
203254721Semaste        GetOSVersion (uint32_t &major,
204254721Semaste                      uint32_t &minor,
205254721Semaste                      uint32_t &update);
206254721Semaste
207254721Semaste        bool
208254721Semaste        SetOSVersion (uint32_t major,
209254721Semaste                      uint32_t minor,
210254721Semaste                      uint32_t update);
211254721Semaste
212254721Semaste        bool
213254721Semaste        GetOSBuildString (std::string &s);
214254721Semaste
215254721Semaste        bool
216254721Semaste        GetOSKernelDescription (std::string &s);
217254721Semaste
218263367Semaste        // Returns the the name of the platform
219254721Semaste        ConstString
220254721Semaste        GetName ();
221254721Semaste
222254721Semaste        virtual const char *
223254721Semaste        GetHostname ();
224254721Semaste
225254721Semaste        virtual const char *
226254721Semaste        GetDescription () = 0;
227254721Semaste
228254721Semaste        //------------------------------------------------------------------
229254721Semaste        /// Report the current status for this platform.
230254721Semaste        ///
231254721Semaste        /// The returned string usually involves returning the OS version
232254721Semaste        /// (if available), and any SDK directory that might be being used
233254721Semaste        /// for local file caching, and if connected a quick blurb about
234254721Semaste        /// what this platform is connected to.
235254721Semaste        //------------------------------------------------------------------
236254721Semaste        virtual void
237254721Semaste        GetStatus (Stream &strm);
238254721Semaste
239254721Semaste        //------------------------------------------------------------------
240254721Semaste        // Subclasses must be able to fetch the current OS version
241254721Semaste        //
242254721Semaste        // Remote classes must be connected for this to succeed. Local
243254721Semaste        // subclasses don't need to override this function as it will just
244254721Semaste        // call the Host::GetOSVersion().
245254721Semaste        //------------------------------------------------------------------
246254721Semaste        virtual bool
247254721Semaste        GetRemoteOSVersion ()
248254721Semaste        {
249254721Semaste            return false;
250254721Semaste        }
251254721Semaste
252254721Semaste        virtual bool
253254721Semaste        GetRemoteOSBuildString (std::string &s)
254254721Semaste        {
255254721Semaste            s.clear();
256254721Semaste            return false;
257254721Semaste        }
258254721Semaste
259254721Semaste        virtual bool
260254721Semaste        GetRemoteOSKernelDescription (std::string &s)
261254721Semaste        {
262254721Semaste            s.clear();
263254721Semaste            return false;
264254721Semaste        }
265254721Semaste
266254721Semaste        // Remote Platform subclasses need to override this function
267254721Semaste        virtual ArchSpec
268254721Semaste        GetRemoteSystemArchitecture ()
269254721Semaste        {
270254721Semaste            return ArchSpec(); // Return an invalid architecture
271254721Semaste        }
272263367Semaste
273263367Semaste        virtual ConstString
274263367Semaste        GetRemoteWorkingDirectory()
275263367Semaste        {
276263367Semaste            return m_working_dir;
277263367Semaste        }
278263367Semaste
279263367Semaste        virtual bool
280263367Semaste        SetRemoteWorkingDirectory(const ConstString &path);
281254721Semaste
282254721Semaste        virtual const char *
283254721Semaste        GetUserName (uint32_t uid);
284254721Semaste
285254721Semaste        virtual const char *
286254721Semaste        GetGroupName (uint32_t gid);
287254721Semaste
288254721Semaste        //------------------------------------------------------------------
289254721Semaste        /// Locate a file for a platform.
290254721Semaste        ///
291254721Semaste        /// The default implementation of this function will return the same
292254721Semaste        /// file patch in \a local_file as was in \a platform_file.
293254721Semaste        ///
294254721Semaste        /// @param[in] platform_file
295254721Semaste        ///     The platform file path to locate and cache locally.
296254721Semaste        ///
297254721Semaste        /// @param[in] uuid_ptr
298254721Semaste        ///     If we know the exact UUID of the file we are looking for, it
299254721Semaste        ///     can be specified. If it is not specified, we might now know
300254721Semaste        ///     the exact file. The UUID is usually some sort of MD5 checksum
301254721Semaste        ///     for the file and is sometimes known by dynamic linkers/loaders.
302254721Semaste        ///     If the UUID is known, it is best to supply it to platform
303254721Semaste        ///     file queries to ensure we are finding the correct file, not
304254721Semaste        ///     just a file at the correct path.
305254721Semaste        ///
306254721Semaste        /// @param[out] local_file
307254721Semaste        ///     A locally cached version of the platform file. For platforms
308254721Semaste        ///     that describe the current host computer, this will just be
309254721Semaste        ///     the same file. For remote platforms, this file might come from
310254721Semaste        ///     and SDK directory, or might need to be sync'ed over to the
311254721Semaste        ///     current machine for efficient debugging access.
312254721Semaste        ///
313254721Semaste        /// @return
314254721Semaste        ///     An error object.
315254721Semaste        //------------------------------------------------------------------
316254721Semaste        virtual Error
317269024Semaste        GetFileWithUUID (const FileSpec &platform_file,
318269024Semaste                         const UUID *uuid_ptr,
319269024Semaste                         FileSpec &local_file);
320254721Semaste
321254721Semaste        //----------------------------------------------------------------------
322254721Semaste        // Locate the scripting resource given a module specification.
323254721Semaste        //
324254721Semaste        // Locating the file should happen only on the local computer or using
325254721Semaste        // the current computers global settings.
326254721Semaste        //----------------------------------------------------------------------
327254721Semaste        virtual FileSpecList
328254721Semaste        LocateExecutableScriptingResources (Target *target,
329254721Semaste                                            Module &module);
330254721Semaste
331254721Semaste        virtual Error
332254721Semaste        GetSharedModule (const ModuleSpec &module_spec,
333254721Semaste                         lldb::ModuleSP &module_sp,
334254721Semaste                         const FileSpecList *module_search_paths_ptr,
335254721Semaste                         lldb::ModuleSP *old_module_sp_ptr,
336254721Semaste                         bool *did_create_ptr);
337254721Semaste
338254721Semaste        virtual Error
339254721Semaste        ConnectRemote (Args& args);
340254721Semaste
341254721Semaste        virtual Error
342254721Semaste        DisconnectRemote ();
343254721Semaste
344254721Semaste        //------------------------------------------------------------------
345254721Semaste        /// Get the platform's supported architectures in the order in which
346254721Semaste        /// they should be searched.
347254721Semaste        ///
348254721Semaste        /// @param[in] idx
349254721Semaste        ///     A zero based architecture index
350254721Semaste        ///
351254721Semaste        /// @param[out] arch
352254721Semaste        ///     A copy of the archgitecture at index if the return value is
353254721Semaste        ///     \b true.
354254721Semaste        ///
355254721Semaste        /// @return
356254721Semaste        ///     \b true if \a arch was filled in and is valid, \b false
357254721Semaste        ///     otherwise.
358254721Semaste        //------------------------------------------------------------------
359254721Semaste        virtual bool
360254721Semaste        GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) = 0;
361254721Semaste
362254721Semaste        virtual size_t
363254721Semaste        GetSoftwareBreakpointTrapOpcode (Target &target,
364254721Semaste                                         BreakpointSite *bp_site) = 0;
365254721Semaste
366254721Semaste        //------------------------------------------------------------------
367254721Semaste        /// Launch a new process on a platform, not necessarily for
368254721Semaste        /// debugging, it could be just for running the process.
369254721Semaste        //------------------------------------------------------------------
370254721Semaste        virtual Error
371254721Semaste        LaunchProcess (ProcessLaunchInfo &launch_info);
372254721Semaste
373254721Semaste        //------------------------------------------------------------------
374254721Semaste        /// Lets a platform answer if it is compatible with a given
375254721Semaste        /// architecture and the target triple contained within.
376254721Semaste        //------------------------------------------------------------------
377254721Semaste        virtual bool
378254721Semaste        IsCompatibleArchitecture (const ArchSpec &arch,
379254721Semaste                                  bool exact_arch_match,
380254721Semaste                                  ArchSpec *compatible_arch_ptr);
381254721Semaste
382254721Semaste        //------------------------------------------------------------------
383254721Semaste        /// Not all platforms will support debugging a process by spawning
384254721Semaste        /// somehow halted for a debugger (specified using the
385254721Semaste        /// "eLaunchFlagDebug" launch flag) and then attaching. If your
386254721Semaste        /// platform doesn't support this, override this function and return
387254721Semaste        /// false.
388254721Semaste        //------------------------------------------------------------------
389254721Semaste        virtual bool
390254721Semaste        CanDebugProcess ()
391254721Semaste        {
392254721Semaste            return true;
393254721Semaste        }
394254721Semaste
395254721Semaste        //------------------------------------------------------------------
396263367Semaste        /// Subclasses do not need to implement this function as it uses
397263367Semaste        /// the Platform::LaunchProcess() followed by Platform::Attach ().
398263367Semaste        /// Remote platforms will want to subclass this function in order
399263367Semaste        /// to be able to intercept STDIO and possibly launch a separate
400263367Semaste        /// process that will debug the debuggee.
401254721Semaste        //------------------------------------------------------------------
402263367Semaste        virtual lldb::ProcessSP
403254721Semaste        DebugProcess (ProcessLaunchInfo &launch_info,
404254721Semaste                      Debugger &debugger,
405254721Semaste                      Target *target,       // Can be NULL, if NULL create a new target, else use existing one
406254721Semaste                      Listener &listener,
407254721Semaste                      Error &error);
408254721Semaste
409254721Semaste        //------------------------------------------------------------------
410254721Semaste        /// Attach to an existing process using a process ID.
411254721Semaste        ///
412254721Semaste        /// Each platform subclass needs to implement this function and
413254721Semaste        /// attempt to attach to the process with the process ID of \a pid.
414254721Semaste        /// The platform subclass should return an appropriate ProcessSP
415254721Semaste        /// subclass that is attached to the process, or an empty shared
416254721Semaste        /// pointer with an appriopriate error.
417254721Semaste        ///
418254721Semaste        /// @param[in] pid
419254721Semaste        ///     The process ID that we should attempt to attach to.
420254721Semaste        ///
421254721Semaste        /// @return
422254721Semaste        ///     An appropriate ProcessSP containing a valid shared pointer
423254721Semaste        ///     to the default Process subclass for the platform that is
424254721Semaste        ///     attached to the process, or an empty shared pointer with an
425254721Semaste        ///     appriopriate error fill into the \a error object.
426254721Semaste        //------------------------------------------------------------------
427254721Semaste        virtual lldb::ProcessSP
428254721Semaste        Attach (ProcessAttachInfo &attach_info,
429254721Semaste                Debugger &debugger,
430254721Semaste                Target *target,       // Can be NULL, if NULL create a new target, else use existing one
431254721Semaste                Listener &listener,
432254721Semaste                Error &error) = 0;
433254721Semaste
434254721Semaste        //------------------------------------------------------------------
435254721Semaste        /// Attach to an existing process by process name.
436254721Semaste        ///
437254721Semaste        /// This function is not meant to be overridden by Process
438254721Semaste        /// subclasses. It will first call
439254721Semaste        /// Process::WillAttach (const char *) and if that returns \b
440254721Semaste        /// true, Process::DoAttach (const char *) will be called to
441254721Semaste        /// actually do the attach. If DoAttach returns \b true, then
442254721Semaste        /// Process::DidAttach() will be called.
443254721Semaste        ///
444254721Semaste        /// @param[in] process_name
445254721Semaste        ///     A process name to match against the current process list.
446254721Semaste        ///
447254721Semaste        /// @return
448254721Semaste        ///     Returns \a pid if attaching was successful, or
449254721Semaste        ///     LLDB_INVALID_PROCESS_ID if attaching fails.
450254721Semaste        //------------------------------------------------------------------
451254721Semaste//        virtual lldb::ProcessSP
452254721Semaste//        Attach (const char *process_name,
453254721Semaste//                bool wait_for_launch,
454254721Semaste//                Error &error) = 0;
455254721Semaste
456254721Semaste        //------------------------------------------------------------------
457254721Semaste        // The base class Platform will take care of the host platform.
458254721Semaste        // Subclasses will need to fill in the remote case.
459254721Semaste        //------------------------------------------------------------------
460254721Semaste        virtual uint32_t
461254721Semaste        FindProcesses (const ProcessInstanceInfoMatch &match_info,
462254721Semaste                       ProcessInstanceInfoList &proc_infos);
463254721Semaste
464254721Semaste        virtual bool
465254721Semaste        GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info);
466254721Semaste
467254721Semaste        //------------------------------------------------------------------
468254721Semaste        // Set a breakpoint on all functions that can end up creating a thread
469254721Semaste        // for this platform. This is needed when running expressions and
470254721Semaste        // also for process control.
471254721Semaste        //------------------------------------------------------------------
472254721Semaste        virtual lldb::BreakpointSP
473254721Semaste        SetThreadCreationBreakpoint (Target &target);
474254721Semaste
475263363Semaste        //------------------------------------------------------------------
476263363Semaste        // Given a target, find the local SDK directory if one exists on the
477263363Semaste        // current host.
478263363Semaste        //------------------------------------------------------------------
479263363Semaste        virtual lldb_private::ConstString
480263363Semaste        GetSDKDirectory (lldb_private::Target &target)
481263363Semaste        {
482263363Semaste            return lldb_private::ConstString();
483263363Semaste        }
484254721Semaste
485254721Semaste        const std::string &
486254721Semaste        GetRemoteURL () const
487254721Semaste        {
488254721Semaste            return m_remote_url;
489254721Semaste        }
490254721Semaste
491254721Semaste        bool
492254721Semaste        IsHost () const
493254721Semaste        {
494254721Semaste            return m_is_host;    // Is this the default host platform?
495254721Semaste        }
496254721Semaste
497254721Semaste        bool
498254721Semaste        IsRemote () const
499254721Semaste        {
500254721Semaste            return !m_is_host;
501254721Semaste        }
502254721Semaste
503254721Semaste        virtual bool
504254721Semaste        IsConnected () const
505254721Semaste        {
506254721Semaste            // Remote subclasses should override this function
507254721Semaste            return IsHost();
508254721Semaste        }
509254721Semaste
510254721Semaste        const ArchSpec &
511254721Semaste        GetSystemArchitecture();
512254721Semaste
513254721Semaste        void
514254721Semaste        SetSystemArchitecture (const ArchSpec &arch)
515254721Semaste        {
516254721Semaste            m_system_arch = arch;
517254721Semaste            if (IsHost())
518254721Semaste                m_os_version_set_while_connected = m_system_arch.IsValid();
519254721Semaste        }
520254721Semaste
521254721Semaste        // Used for column widths
522254721Semaste        size_t
523254721Semaste        GetMaxUserIDNameLength() const
524254721Semaste        {
525254721Semaste            return m_max_uid_name_len;
526254721Semaste        }
527254721Semaste        // Used for column widths
528254721Semaste        size_t
529254721Semaste        GetMaxGroupIDNameLength() const
530254721Semaste        {
531254721Semaste            return m_max_gid_name_len;
532254721Semaste        }
533254721Semaste
534254721Semaste        const ConstString &
535254721Semaste        GetSDKRootDirectory () const
536254721Semaste        {
537254721Semaste            return m_sdk_sysroot;
538254721Semaste        }
539254721Semaste
540254721Semaste        void
541254721Semaste        SetSDKRootDirectory (const ConstString &dir)
542254721Semaste        {
543254721Semaste            m_sdk_sysroot = dir;
544254721Semaste        }
545254721Semaste
546254721Semaste        const ConstString &
547254721Semaste        GetSDKBuild () const
548254721Semaste        {
549254721Semaste            return m_sdk_build;
550254721Semaste        }
551254721Semaste
552254721Semaste        void
553254721Semaste        SetSDKBuild (const ConstString &sdk_build)
554254721Semaste        {
555254721Semaste            m_sdk_build = sdk_build;
556254721Semaste        }
557263367Semaste
558263367Semaste        ConstString
559263367Semaste        GetWorkingDirectory ();
560254721Semaste
561263367Semaste        bool
562263367Semaste        SetWorkingDirectory (const ConstString &path);
563263367Semaste
564254721Semaste        // There may be modules that we don't want to find by default for operations like "setting breakpoint by name".
565254721Semaste        // The platform will return "true" from this call if the passed in module happens to be one of these.
566254721Semaste
567254721Semaste        virtual bool
568254721Semaste        ModuleIsExcludedForNonModuleSpecificSearches (Target &target, const lldb::ModuleSP &module_sp)
569254721Semaste        {
570254721Semaste            return false;
571254721Semaste        }
572254721Semaste
573263367Semaste        virtual Error
574263367Semaste        MakeDirectory (const char *path, uint32_t permissions);
575263363Semaste
576263367Semaste        virtual Error
577263367Semaste        GetFilePermissions (const char *path, uint32_t &file_permissions);
578263367Semaste
579263367Semaste        virtual Error
580263367Semaste        SetFilePermissions (const char *path, uint32_t file_permissions);
581263367Semaste
582263363Semaste        virtual lldb::user_id_t
583263363Semaste        OpenFile (const FileSpec& file_spec,
584263363Semaste                  uint32_t flags,
585263367Semaste                  uint32_t mode,
586263363Semaste                  Error &error)
587263363Semaste        {
588263363Semaste            return UINT64_MAX;
589263363Semaste        }
590263363Semaste
591263363Semaste        virtual bool
592263363Semaste        CloseFile (lldb::user_id_t fd,
593263363Semaste                   Error &error)
594263363Semaste        {
595263363Semaste            return false;
596263363Semaste        }
597263363Semaste
598263363Semaste        virtual lldb::user_id_t
599263363Semaste        GetFileSize (const FileSpec& file_spec)
600263363Semaste        {
601263363Semaste            return UINT64_MAX;
602263363Semaste        }
603263363Semaste
604263363Semaste        virtual uint64_t
605263363Semaste        ReadFile (lldb::user_id_t fd,
606263363Semaste                  uint64_t offset,
607263363Semaste                  void *dst,
608263363Semaste                  uint64_t dst_len,
609263363Semaste                  Error &error)
610263363Semaste        {
611263363Semaste            error.SetErrorStringWithFormat ("Platform::ReadFile() is not supported in the %s platform", GetName().GetCString());
612263363Semaste            return -1;
613263363Semaste        }
614263363Semaste
615263363Semaste        virtual uint64_t
616263363Semaste        WriteFile (lldb::user_id_t fd,
617263363Semaste                   uint64_t offset,
618263363Semaste                   const void* src,
619263363Semaste                   uint64_t src_len,
620263363Semaste                   Error &error)
621263363Semaste        {
622263363Semaste            error.SetErrorStringWithFormat ("Platform::ReadFile() is not supported in the %s platform", GetName().GetCString());
623263363Semaste            return -1;
624263363Semaste        }
625263363Semaste
626263363Semaste        virtual Error
627263367Semaste        GetFile (const FileSpec& source,
628263367Semaste                 const FileSpec& destination);
629263367Semaste
630263367Semaste        virtual Error
631263363Semaste        PutFile (const FileSpec& source,
632263363Semaste                 const FileSpec& destination,
633263363Semaste                 uint32_t uid = UINT32_MAX,
634263363Semaste                 uint32_t gid = UINT32_MAX);
635263367Semaste
636263367Semaste        virtual Error
637263367Semaste        CreateSymlink (const char *src, // The name of the link is in src
638263367Semaste                       const char *dst);// The symlink points to dst
639263367Semaste
640263367Semaste        //----------------------------------------------------------------------
641263367Semaste        /// Install a file or directory to the remote system.
642263367Semaste        ///
643263367Semaste        /// Install is similar to Platform::PutFile(), but it differs in that if
644263367Semaste        /// an application/framework/shared library is installed on a remote
645263367Semaste        /// platform and the remote platform requires something to be done to
646263367Semaste        /// register the application/framework/shared library, then this extra
647263367Semaste        /// registration can be done.
648263367Semaste        ///
649263367Semaste        /// @param[in] src
650263367Semaste        ///     The source file/directory to install on the remote system.
651263367Semaste        ///
652263367Semaste        /// @param[in] dst
653263367Semaste        ///     The destination file/directory where \a src will be installed.
654263367Semaste        ///     If \a dst has no filename specified, then its filename will
655263367Semaste        ///     be set from \a src. It \a dst has no directory specified, it
656263367Semaste        ///     will use the platform working directory. If \a dst has a
657263367Semaste        ///     directory specified, but the directory path is relative, the
658263367Semaste        ///     platform working directory will be prepended to the relative
659263367Semaste        ///     directory.
660263367Semaste        ///
661263367Semaste        /// @return
662263367Semaste        ///     An error object that describes anything that went wrong.
663263367Semaste        //----------------------------------------------------------------------
664263367Semaste        virtual Error
665263367Semaste        Install (const FileSpec& src, const FileSpec& dst);
666263367Semaste
667254721Semaste        virtual size_t
668254721Semaste        GetEnvironment (StringList &environment);
669254721Semaste
670263363Semaste        virtual bool
671263363Semaste        GetFileExists (const lldb_private::FileSpec& file_spec);
672263363Semaste
673263367Semaste        virtual Error
674263367Semaste        Unlink (const char *path);
675263363Semaste
676263363Semaste        virtual bool
677263363Semaste        GetSupportsRSync ()
678263363Semaste        {
679263363Semaste            return m_supports_rsync;
680263363Semaste        }
681263363Semaste
682263363Semaste        virtual void
683263363Semaste        SetSupportsRSync(bool flag)
684263363Semaste        {
685263363Semaste            m_supports_rsync = flag;
686263363Semaste        }
687263363Semaste
688263363Semaste        virtual const char*
689263363Semaste        GetRSyncOpts ()
690263363Semaste        {
691263363Semaste            return m_rsync_opts.c_str();
692263363Semaste        }
693263363Semaste
694263363Semaste        virtual void
695263363Semaste        SetRSyncOpts (const char* opts)
696263363Semaste        {
697263363Semaste            m_rsync_opts.assign(opts);
698263363Semaste        }
699263363Semaste
700263363Semaste        virtual const char*
701263363Semaste        GetRSyncPrefix ()
702263363Semaste        {
703263363Semaste            return m_rsync_prefix.c_str();
704263363Semaste        }
705263363Semaste
706263363Semaste        virtual void
707263363Semaste        SetRSyncPrefix (const char* prefix)
708263363Semaste        {
709263363Semaste            m_rsync_prefix.assign(prefix);
710263363Semaste        }
711263363Semaste
712263363Semaste        virtual bool
713263363Semaste        GetSupportsSSH ()
714263363Semaste        {
715263363Semaste            return m_supports_ssh;
716263363Semaste        }
717263363Semaste
718263363Semaste        virtual void
719263363Semaste        SetSupportsSSH(bool flag)
720263363Semaste        {
721263363Semaste            m_supports_ssh = flag;
722263363Semaste        }
723263363Semaste
724263363Semaste        virtual const char*
725263363Semaste        GetSSHOpts ()
726263363Semaste        {
727263363Semaste            return m_ssh_opts.c_str();
728263363Semaste        }
729263363Semaste
730263363Semaste        virtual void
731263363Semaste        SetSSHOpts (const char* opts)
732263363Semaste        {
733263363Semaste            m_ssh_opts.assign(opts);
734263363Semaste        }
735263363Semaste
736263363Semaste        virtual bool
737263363Semaste        GetIgnoresRemoteHostname ()
738263363Semaste        {
739263363Semaste            return m_ignores_remote_hostname;
740263363Semaste        }
741263363Semaste
742263363Semaste        virtual void
743263363Semaste        SetIgnoresRemoteHostname(bool flag)
744263363Semaste        {
745263363Semaste            m_ignores_remote_hostname = flag;
746263363Semaste        }
747263363Semaste
748263363Semaste        virtual lldb_private::OptionGroupOptions *
749263363Semaste        GetConnectionOptions (CommandInterpreter& interpreter)
750263363Semaste        {
751263363Semaste            return NULL;
752263363Semaste        }
753263363Semaste
754263363Semaste        virtual lldb_private::Error
755263363Semaste        RunShellCommand (const char *command,           // Shouldn't be NULL
756263363Semaste                         const char *working_dir,       // Pass NULL to use the current working directory
757263363Semaste                         int *status_ptr,               // Pass NULL if you don't want the process exit status
758263363Semaste                         int *signo_ptr,                // Pass NULL if you don't want the signal that caused the process to exit
759263363Semaste                         std::string *command_output,   // Pass NULL if you don't want the command output
760263363Semaste                         uint32_t timeout_sec);         // Timeout in seconds to wait for shell program to finish
761263363Semaste
762263363Semaste        virtual void
763263363Semaste        SetLocalCacheDirectory (const char* local);
764263363Semaste
765263363Semaste        virtual const char*
766263363Semaste        GetLocalCacheDirectory ();
767263363Semaste
768263363Semaste        virtual std::string
769263363Semaste        GetPlatformSpecificConnectionInformation()
770263363Semaste        {
771263363Semaste            return "";
772263363Semaste        }
773263363Semaste
774263363Semaste        virtual bool
775263363Semaste        CalculateMD5 (const FileSpec& file_spec,
776263363Semaste                      uint64_t &low,
777263363Semaste                      uint64_t &high);
778263363Semaste
779263363Semaste        virtual int32_t
780263363Semaste        GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info)
781263363Semaste        {
782263363Semaste            return 1;
783263363Semaste        }
784263363Semaste
785263363Semaste        //------------------------------------------------------------------
786263363Semaste        /// Locate a queue name given a thread's qaddr
787263363Semaste        ///
788263363Semaste        /// On a system using libdispatch ("Grand Central Dispatch") style
789263363Semaste        /// queues, a thread may be associated with a GCD queue or not,
790263363Semaste        /// and a queue may be associated with multiple threads.
791263363Semaste        /// The process/thread must provide a way to find the "dispatch_qaddr"
792263363Semaste        /// for each thread, and from that dispatch_qaddr this Platform method
793263363Semaste        /// will locate the queue name and provide that.
794263363Semaste        ///
795263363Semaste        /// @param[in] process
796263363Semaste        ///     A process is required for reading memory.
797263363Semaste        ///
798263363Semaste        /// @param[in] dispatch_qaddr
799263363Semaste        ///     The dispatch_qaddr for this thread.
800263363Semaste        ///
801263363Semaste        /// @return
802263363Semaste        ///     The name of the queue, if there is one.  An empty string
803263363Semaste        ///     means that this thread is not associated with a dispatch
804263363Semaste        ///     queue.
805263363Semaste        //------------------------------------------------------------------
806263363Semaste        virtual std::string
807263363Semaste        GetQueueNameForThreadQAddress (Process *process, lldb::addr_t dispatch_qaddr)
808263363Semaste        {
809263363Semaste            return "";
810263363Semaste        }
811263363Semaste
812263363Semaste        //------------------------------------------------------------------
813263363Semaste        /// Locate a queue ID given a thread's qaddr
814263363Semaste        ///
815263363Semaste        /// On a system using libdispatch ("Grand Central Dispatch") style
816263363Semaste        /// queues, a thread may be associated with a GCD queue or not,
817263363Semaste        /// and a queue may be associated with multiple threads.
818263363Semaste        /// The process/thread must provide a way to find the "dispatch_qaddr"
819263363Semaste        /// for each thread, and from that dispatch_qaddr this Platform method
820263363Semaste        /// will locate the queue ID and provide that.
821263363Semaste        ///
822263363Semaste        /// @param[in] process
823263363Semaste        ///     A process is required for reading memory.
824263363Semaste        ///
825263363Semaste        /// @param[in] dispatch_qaddr
826263363Semaste        ///     The dispatch_qaddr for this thread.
827263363Semaste        ///
828263363Semaste        /// @return
829263363Semaste        ///     The queue_id for this thread, if this thread is associated
830263363Semaste        ///     with a dispatch queue.  Else LLDB_INVALID_QUEUE_ID is returned.
831263363Semaste        //------------------------------------------------------------------
832263363Semaste        virtual lldb::queue_id_t
833263363Semaste        GetQueueIDForThreadQAddress (Process *process, lldb::addr_t dispatch_qaddr)
834263363Semaste        {
835263363Semaste            return LLDB_INVALID_QUEUE_ID;
836263363Semaste        }
837263363Semaste
838269024Semaste        //------------------------------------------------------------------
839269024Semaste        /// Provide a list of trap handler function names for this platform
840269024Semaste        ///
841269024Semaste        /// The unwinder needs to treat trap handlers specially -- the stack
842269024Semaste        /// frame may not be aligned correctly for a trap handler (the kernel
843269024Semaste        /// often won't perturb the stack pointer, or won't re-align it properly,
844269024Semaste        /// in the process of calling the handler) and the frame above the handler
845269024Semaste        /// needs to be treated by the unwinder's "frame 0" rules instead of its
846269024Semaste        /// "middle of the stack frame" rules.
847269024Semaste        ///
848269024Semaste        /// In a user process debugging scenario, the list of trap handlers is
849269024Semaste        /// typically just "_sigtramp".
850269024Semaste        ///
851269024Semaste        /// The Platform base class provides the m_trap_handlers ivar but it does
852269024Semaste        /// not populate it.  Subclasses should add the names of the asynchronous
853269024Semaste        /// signal handler routines as needed.  For most Unix platforms, add _sigtramp.
854269024Semaste        ///
855269024Semaste        /// @return
856269024Semaste        ///     A list of symbol names.  The list may be empty.
857269024Semaste        //------------------------------------------------------------------
858269024Semaste        virtual const std::vector<ConstString> &
859269024Semaste        GetTrapHandlerSymbolNames ();
860269024Semaste
861254721Semaste    protected:
862254721Semaste        bool m_is_host;
863254721Semaste        // Set to true when we are able to actually set the OS version while
864254721Semaste        // being connected. For remote platforms, we might set the version ahead
865254721Semaste        // of time before we actually connect and this version might change when
866254721Semaste        // we actually connect to a remote platform. For the host platform this
867254721Semaste        // will be set to the once we call Host::GetOSVersion().
868254721Semaste        bool m_os_version_set_while_connected;
869254721Semaste        bool m_system_arch_set_while_connected;
870254721Semaste        ConstString m_sdk_sysroot; // the root location of where the SDK files are all located
871254721Semaste        ConstString m_sdk_build;
872263367Semaste        ConstString m_working_dir; // The working directory which is used when installing modules that have no install path set
873254721Semaste        std::string m_remote_url;
874254721Semaste        std::string m_name;
875254721Semaste        uint32_t m_major_os_version;
876254721Semaste        uint32_t m_minor_os_version;
877254721Semaste        uint32_t m_update_os_version;
878254721Semaste        ArchSpec m_system_arch; // The architecture of the kernel or the remote platform
879254721Semaste        typedef std::map<uint32_t, ConstString> IDToNameMap;
880254721Semaste        Mutex m_uid_map_mutex;
881254721Semaste        Mutex m_gid_map_mutex;
882254721Semaste        IDToNameMap m_uid_map;
883254721Semaste        IDToNameMap m_gid_map;
884254721Semaste        size_t m_max_uid_name_len;
885254721Semaste        size_t m_max_gid_name_len;
886263363Semaste        bool m_supports_rsync;
887263363Semaste        std::string m_rsync_opts;
888263363Semaste        std::string m_rsync_prefix;
889263363Semaste        bool m_supports_ssh;
890263363Semaste        std::string m_ssh_opts;
891263363Semaste        bool m_ignores_remote_hostname;
892263363Semaste        std::string m_local_cache_directory;
893269024Semaste        std::vector<ConstString> m_trap_handlers;
894269024Semaste        bool m_calculated_trap_handlers;
895263363Semaste
896269024Semaste        //------------------------------------------------------------------
897269024Semaste        /// Ask the Platform subclass to fill in the list of trap handler names
898269024Semaste        ///
899269024Semaste        /// For most Unix user process environments, this will be a single
900269024Semaste        /// function name, _sigtramp.  More specialized environments may have
901269024Semaste        /// additional handler names.  The unwinder code needs to know when a
902269024Semaste        /// trap handler is on the stack because the unwind rules for the frame
903269024Semaste        /// that caused the trap are different.
904269024Semaste        ///
905269024Semaste        /// The base class Platform ivar m_trap_handlers should be updated by
906269024Semaste        /// the Platform subclass when this method is called.  If there are no
907269024Semaste        /// predefined trap handlers, this method may be a no-op.
908269024Semaste        //------------------------------------------------------------------
909269024Semaste        virtual void
910269024Semaste        CalculateTrapHandlerSymbolNames () = 0;
911269024Semaste
912254721Semaste        const char *
913254721Semaste        GetCachedUserName (uint32_t uid)
914254721Semaste        {
915254721Semaste            Mutex::Locker locker (m_uid_map_mutex);
916254721Semaste            IDToNameMap::iterator pos = m_uid_map.find (uid);
917254721Semaste            if (pos != m_uid_map.end())
918254721Semaste            {
919254721Semaste                // return the empty string if our string is NULL
920254721Semaste                // so we can tell when things were in the negative
921254721Semaste                // cached (didn't find a valid user name, don't keep
922254721Semaste                // trying)
923254721Semaste                return pos->second.AsCString("");
924254721Semaste            }
925254721Semaste            return NULL;
926254721Semaste        }
927254721Semaste
928254721Semaste        const char *
929254721Semaste        SetCachedUserName (uint32_t uid, const char *name, size_t name_len)
930254721Semaste        {
931254721Semaste            Mutex::Locker locker (m_uid_map_mutex);
932254721Semaste            ConstString const_name (name);
933254721Semaste            m_uid_map[uid] = const_name;
934254721Semaste            if (m_max_uid_name_len < name_len)
935254721Semaste                m_max_uid_name_len = name_len;
936254721Semaste            // Const strings lives forever in our const string pool, so we can return the const char *
937254721Semaste            return const_name.GetCString();
938254721Semaste        }
939254721Semaste
940254721Semaste        void
941254721Semaste        SetUserNameNotFound (uint32_t uid)
942254721Semaste        {
943254721Semaste            Mutex::Locker locker (m_uid_map_mutex);
944254721Semaste            m_uid_map[uid] = ConstString();
945254721Semaste        }
946254721Semaste
947254721Semaste
948254721Semaste        void
949254721Semaste        ClearCachedUserNames ()
950254721Semaste        {
951254721Semaste            Mutex::Locker locker (m_uid_map_mutex);
952254721Semaste            m_uid_map.clear();
953254721Semaste        }
954254721Semaste
955254721Semaste        const char *
956254721Semaste        GetCachedGroupName (uint32_t gid)
957254721Semaste        {
958254721Semaste            Mutex::Locker locker (m_gid_map_mutex);
959254721Semaste            IDToNameMap::iterator pos = m_gid_map.find (gid);
960254721Semaste            if (pos != m_gid_map.end())
961254721Semaste            {
962254721Semaste                // return the empty string if our string is NULL
963254721Semaste                // so we can tell when things were in the negative
964254721Semaste                // cached (didn't find a valid group name, don't keep
965254721Semaste                // trying)
966254721Semaste                return pos->second.AsCString("");
967254721Semaste            }
968254721Semaste            return NULL;
969254721Semaste        }
970254721Semaste
971254721Semaste        const char *
972254721Semaste        SetCachedGroupName (uint32_t gid, const char *name, size_t name_len)
973254721Semaste        {
974254721Semaste            Mutex::Locker locker (m_gid_map_mutex);
975254721Semaste            ConstString const_name (name);
976254721Semaste            m_gid_map[gid] = const_name;
977254721Semaste            if (m_max_gid_name_len < name_len)
978254721Semaste                m_max_gid_name_len = name_len;
979254721Semaste            // Const strings lives forever in our const string pool, so we can return the const char *
980254721Semaste            return const_name.GetCString();
981254721Semaste        }
982254721Semaste
983254721Semaste        void
984254721Semaste        SetGroupNameNotFound (uint32_t gid)
985254721Semaste        {
986254721Semaste            Mutex::Locker locker (m_gid_map_mutex);
987254721Semaste            m_gid_map[gid] = ConstString();
988254721Semaste        }
989254721Semaste
990254721Semaste        void
991254721Semaste        ClearCachedGroupNames ()
992254721Semaste        {
993254721Semaste            Mutex::Locker locker (m_gid_map_mutex);
994254721Semaste            m_gid_map.clear();
995254721Semaste        }
996254721Semaste
997254721Semaste    private:
998254721Semaste        DISALLOW_COPY_AND_ASSIGN (Platform);
999254721Semaste    };
1000254721Semaste
1001254721Semaste
1002254721Semaste    class PlatformList
1003254721Semaste    {
1004254721Semaste    public:
1005254721Semaste        PlatformList() :
1006254721Semaste            m_mutex (Mutex::eMutexTypeRecursive),
1007254721Semaste            m_platforms (),
1008254721Semaste            m_selected_platform_sp()
1009254721Semaste        {
1010254721Semaste        }
1011254721Semaste
1012254721Semaste        ~PlatformList()
1013254721Semaste        {
1014254721Semaste        }
1015254721Semaste
1016254721Semaste        void
1017254721Semaste        Append (const lldb::PlatformSP &platform_sp, bool set_selected)
1018254721Semaste        {
1019254721Semaste            Mutex::Locker locker (m_mutex);
1020254721Semaste            m_platforms.push_back (platform_sp);
1021254721Semaste            if (set_selected)
1022254721Semaste                m_selected_platform_sp = m_platforms.back();
1023254721Semaste        }
1024254721Semaste
1025254721Semaste        size_t
1026254721Semaste        GetSize()
1027254721Semaste        {
1028254721Semaste            Mutex::Locker locker (m_mutex);
1029254721Semaste            return m_platforms.size();
1030254721Semaste        }
1031254721Semaste
1032254721Semaste        lldb::PlatformSP
1033254721Semaste        GetAtIndex (uint32_t idx)
1034254721Semaste        {
1035254721Semaste            lldb::PlatformSP platform_sp;
1036254721Semaste            {
1037254721Semaste                Mutex::Locker locker (m_mutex);
1038254721Semaste                if (idx < m_platforms.size())
1039254721Semaste                    platform_sp = m_platforms[idx];
1040254721Semaste            }
1041254721Semaste            return platform_sp;
1042254721Semaste        }
1043254721Semaste
1044254721Semaste        //------------------------------------------------------------------
1045254721Semaste        /// Select the active platform.
1046254721Semaste        ///
1047254721Semaste        /// In order to debug remotely, other platform's can be remotely
1048254721Semaste        /// connected to and set as the selected platform for any subsequent
1049254721Semaste        /// debugging. This allows connection to remote targets and allows
1050254721Semaste        /// the ability to discover process info, launch and attach to remote
1051254721Semaste        /// processes.
1052254721Semaste        //------------------------------------------------------------------
1053254721Semaste        lldb::PlatformSP
1054254721Semaste        GetSelectedPlatform ()
1055254721Semaste        {
1056254721Semaste            Mutex::Locker locker (m_mutex);
1057254721Semaste            if (!m_selected_platform_sp && !m_platforms.empty())
1058254721Semaste                m_selected_platform_sp = m_platforms.front();
1059254721Semaste
1060254721Semaste            return m_selected_platform_sp;
1061254721Semaste        }
1062254721Semaste
1063254721Semaste        void
1064254721Semaste        SetSelectedPlatform (const lldb::PlatformSP &platform_sp)
1065254721Semaste        {
1066254721Semaste            if (platform_sp)
1067254721Semaste            {
1068254721Semaste                Mutex::Locker locker (m_mutex);
1069254721Semaste                const size_t num_platforms = m_platforms.size();
1070254721Semaste                for (size_t idx=0; idx<num_platforms; ++idx)
1071254721Semaste                {
1072254721Semaste                    if (m_platforms[idx].get() == platform_sp.get())
1073254721Semaste                    {
1074254721Semaste                        m_selected_platform_sp = m_platforms[idx];
1075254721Semaste                        return;
1076254721Semaste                    }
1077254721Semaste                }
1078254721Semaste                m_platforms.push_back (platform_sp);
1079254721Semaste                m_selected_platform_sp = m_platforms.back();
1080254721Semaste            }
1081254721Semaste        }
1082254721Semaste
1083254721Semaste    protected:
1084254721Semaste        typedef std::vector<lldb::PlatformSP> collection;
1085254721Semaste        mutable Mutex m_mutex;
1086254721Semaste        collection m_platforms;
1087254721Semaste        lldb::PlatformSP m_selected_platform_sp;
1088254721Semaste
1089254721Semaste    private:
1090254721Semaste        DISALLOW_COPY_AND_ASSIGN (PlatformList);
1091254721Semaste    };
1092263363Semaste
1093263363Semaste    class OptionGroupPlatformRSync : public lldb_private::OptionGroup
1094263363Semaste    {
1095263363Semaste    public:
1096263363Semaste        OptionGroupPlatformRSync ();
1097263363Semaste
1098263363Semaste        virtual
1099263363Semaste        ~OptionGroupPlatformRSync ();
1100263363Semaste
1101263363Semaste        virtual lldb_private::Error
1102263363Semaste        SetOptionValue (CommandInterpreter &interpreter,
1103263363Semaste                        uint32_t option_idx,
1104263363Semaste                        const char *option_value);
1105263363Semaste
1106263363Semaste        void
1107263363Semaste        OptionParsingStarting (CommandInterpreter &interpreter);
1108263363Semaste
1109263363Semaste        const lldb_private::OptionDefinition*
1110263363Semaste        GetDefinitions ();
1111263363Semaste
1112263363Semaste        virtual uint32_t
1113263363Semaste        GetNumDefinitions ();
1114263363Semaste
1115263363Semaste        // Options table: Required for subclasses of Options.
1116263363Semaste
1117263363Semaste        static lldb_private::OptionDefinition g_option_table[];
1118263363Semaste
1119263363Semaste        // Instance variables to hold the values for command options.
1120263363Semaste
1121263363Semaste        bool m_rsync;
1122263363Semaste        std::string m_rsync_opts;
1123263363Semaste        std::string m_rsync_prefix;
1124263363Semaste        bool m_ignores_remote_hostname;
1125263363Semaste    private:
1126263363Semaste        DISALLOW_COPY_AND_ASSIGN(OptionGroupPlatformRSync);
1127263363Semaste    };
1128263363Semaste
1129263363Semaste    class OptionGroupPlatformSSH : public lldb_private::OptionGroup
1130263363Semaste    {
1131263363Semaste    public:
1132263363Semaste        OptionGroupPlatformSSH ();
1133263363Semaste
1134263363Semaste        virtual
1135263363Semaste        ~OptionGroupPlatformSSH ();
1136263363Semaste
1137263363Semaste        virtual lldb_private::Error
1138263363Semaste        SetOptionValue (CommandInterpreter &interpreter,
1139263363Semaste                        uint32_t option_idx,
1140263363Semaste                        const char *option_value);
1141263363Semaste
1142263363Semaste        void
1143263363Semaste        OptionParsingStarting (CommandInterpreter &interpreter);
1144263363Semaste
1145263363Semaste        virtual uint32_t
1146263363Semaste        GetNumDefinitions ();
1147263363Semaste
1148263363Semaste        const lldb_private::OptionDefinition*
1149263363Semaste        GetDefinitions ();
1150263363Semaste
1151263363Semaste        // Options table: Required for subclasses of Options.
1152263363Semaste
1153263363Semaste        static lldb_private::OptionDefinition g_option_table[];
1154263363Semaste
1155263363Semaste        // Instance variables to hold the values for command options.
1156263363Semaste
1157263363Semaste        bool m_ssh;
1158263363Semaste        std::string m_ssh_opts;
1159269024Semaste
1160263363Semaste    private:
1161269024Semaste
1162263363Semaste        DISALLOW_COPY_AND_ASSIGN(OptionGroupPlatformSSH);
1163263363Semaste    };
1164263363Semaste
1165263363Semaste    class OptionGroupPlatformCaching : public lldb_private::OptionGroup
1166263363Semaste    {
1167263363Semaste    public:
1168263363Semaste        OptionGroupPlatformCaching ();
1169263363Semaste
1170263363Semaste        virtual
1171263363Semaste        ~OptionGroupPlatformCaching ();
1172263363Semaste
1173263363Semaste        virtual lldb_private::Error
1174263363Semaste        SetOptionValue (CommandInterpreter &interpreter,
1175263363Semaste                        uint32_t option_idx,
1176263363Semaste                        const char *option_value);
1177263363Semaste
1178263363Semaste        void
1179263363Semaste        OptionParsingStarting (CommandInterpreter &interpreter);
1180263363Semaste
1181263363Semaste        virtual uint32_t
1182263363Semaste        GetNumDefinitions ();
1183263363Semaste
1184263363Semaste        const lldb_private::OptionDefinition*
1185263363Semaste        GetDefinitions ();
1186263363Semaste
1187263363Semaste        // Options table: Required for subclasses of Options.
1188263363Semaste
1189263363Semaste        static lldb_private::OptionDefinition g_option_table[];
1190263363Semaste
1191263363Semaste        // Instance variables to hold the values for command options.
1192263363Semaste
1193263363Semaste        std::string m_cache_dir;
1194263363Semaste    private:
1195263363Semaste        DISALLOW_COPY_AND_ASSIGN(OptionGroupPlatformCaching);
1196263363Semaste    };
1197263363Semaste
1198254721Semaste} // namespace lldb_private
1199254721Semaste
1200254721Semaste#endif  // liblldb_Platform_h_
1201