Process.h revision 1ebef44c126bd3a615b3ad844c46a82a82efa0e7
1//===-- Process.h -----------------------------------------------*- 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#ifndef liblldb_Process_h_
11#define liblldb_Process_h_
12
13// C Includes
14// C++ Includes
15#include <list>
16
17// Other libraries and framework includes
18// Project includes
19#include "lldb/lldb-private.h"
20#include "lldb/Interpreter/Args.h"
21#include "lldb/Interpreter/Options.h"
22#include "lldb/Core/Broadcaster.h"
23#include "lldb/Core/Error.h"
24#include "lldb/Core/Event.h"
25#include "lldb/Core/StringList.h"
26#include "lldb/Core/ThreadSafeValue.h"
27#include "lldb/Core/PluginInterface.h"
28#include "lldb/Core/UserSettingsController.h"
29#include "lldb/Breakpoint/BreakpointSiteList.h"
30#include "lldb/Expression/ClangPersistentVariables.h"
31#include "lldb/Expression/IRDynamicChecks.h"
32#include "lldb/Target/ExecutionContextScope.h"
33#include "lldb/Target/ObjCObjectPrinter.h"
34#include "lldb/Target/ThreadList.h"
35#include "lldb/Target/UnixSignals.h"
36
37namespace lldb_private {
38
39
40typedef enum ProcessPlugins
41{
42    eMacosx,
43    eRemoteDebugger
44} ProcessPlugins;
45
46
47class ProcessInstanceSettings : public InstanceSettings
48{
49public:
50
51    ProcessInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
52
53    ProcessInstanceSettings (const ProcessInstanceSettings &rhs);
54
55    virtual
56    ~ProcessInstanceSettings ();
57
58    ProcessInstanceSettings&
59    operator= (const ProcessInstanceSettings &rhs);
60
61
62    void
63    UpdateInstanceSettingsVariable (const ConstString &var_name,
64                                    const char *index_value,
65                                    const char *value,
66                                    const ConstString &instance_name,
67                                    const SettingEntry &entry,
68                                    lldb::VarSetOperationType op,
69                                    Error &err,
70                                    bool pending);
71
72    bool
73    GetInstanceSettingsValue (const SettingEntry &entry,
74                              const ConstString &var_name,
75                              StringList &value,
76                              Error *err);
77
78
79    const Args &
80    GetRunArguments () const
81    {
82        return m_run_args;
83    }
84
85    void
86    SetRunArguments (const Args &args)
87    {
88        m_run_args = args;
89    }
90
91    size_t
92    GetEnvironmentAsArgs (Args &env) const
93    {
94        dictionary::const_iterator pos, end = m_env_vars.end();
95        for (pos = m_env_vars.begin(); pos != end; ++pos)
96        {
97            std::string env_var_equal_value (pos->first);
98            env_var_equal_value.append(1, '=');
99            env_var_equal_value.append (pos->second);
100            env.AppendArgument (env_var_equal_value.c_str());
101        }
102        return env.GetArgumentCount();
103    }
104
105    const char *
106    GetStandardInputPath () const
107    {
108        if (m_input_path.empty())
109            return NULL;
110        return m_input_path.c_str();
111    }
112
113    void
114    SetStandardInputPath (const char *path)
115    {
116        if (path && path[0])
117            m_input_path.assign (path);
118        else
119        {
120            // Make sure we deallocate memory in string...
121            std::string tmp;
122            tmp.swap (m_input_path);
123        }
124    }
125
126    const char *
127    GetStandardOutputPath () const
128    {
129        if (m_output_path.empty())
130            return NULL;
131        return m_output_path.c_str();
132    }
133
134    void
135    SetStandardOutputPath (const char *path)
136    {
137        if (path && path[0])
138            m_output_path.assign (path);
139        else
140        {
141            // Make sure we deallocate memory in string...
142            std::string tmp;
143            tmp.swap (m_output_path);
144        }
145    }
146
147    const char *
148    GetStandardErrorPath () const
149    {
150        if (m_error_path.empty())
151            return NULL;
152        return m_error_path.c_str();
153    }
154
155    void
156    SetStandardErrorPath (const char *path)
157    {
158        if (path && path[0])
159            m_error_path.assign (path);
160        else
161        {
162            // Make sure we deallocate memory in string...
163            std::string tmp;
164            tmp.swap (m_error_path);
165        }
166    }
167
168    bool
169    GetDisableASLR () const
170    {
171        return m_disable_aslr;
172    }
173
174    void
175    SetDisableASLR (bool b)
176    {
177        m_disable_aslr = b;
178    }
179
180protected:
181
182    void
183    CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
184                          bool pending);
185
186    const ConstString
187    CreateInstanceName ();
188
189    static const ConstString &
190    RunArgsVarName ();
191
192    static const ConstString &
193    EnvVarsVarName ();
194
195    static const ConstString &
196    InputPathVarName ();
197
198    static const ConstString &
199    OutputPathVarName ();
200
201    static const ConstString &
202    ErrorPathVarName ();
203
204    static const ConstString &
205    PluginVarName ();
206
207    static const ConstString &
208    DisableASLRVarName();
209
210
211private:
212
213    typedef std::map<std::string, std::string> dictionary;
214    Args m_run_args;
215    dictionary m_env_vars;
216    std::string m_input_path;
217    std::string m_output_path;
218    std::string m_error_path;
219    ProcessPlugins m_plugin;
220    bool m_disable_aslr;
221};
222
223
224//----------------------------------------------------------------------
225/// @class Process Process.h "lldb/Target/Process.h"
226/// @brief A plug-in interface definition class for debugging a process.
227//----------------------------------------------------------------------
228class Process :
229    public UserID,
230    public Broadcaster,
231    public ExecutionContextScope,
232    public PluginInterface,
233    public ProcessInstanceSettings
234{
235friend class ThreadList;
236
237public:
238
239    //------------------------------------------------------------------
240    /// Broadcaster event bits definitions.
241    //------------------------------------------------------------------
242    enum
243    {
244        eBroadcastBitStateChanged   = (1 << 0),
245        eBroadcastBitInterrupt      = (1 << 1),
246        eBroadcastBitSTDOUT         = (1 << 2),
247        eBroadcastBitSTDERR         = (1 << 3)
248    };
249
250    enum
251    {
252        eBroadcastInternalStateControlStop = (1<<0),
253        eBroadcastInternalStateControlPause = (1<<1),
254        eBroadcastInternalStateControlResume = (1<<2)
255    };
256
257    //------------------------------------------------------------------
258    /// A notification structure that can be used by clients to listen
259    /// for changes in a process's lifetime.
260    ///
261    /// @see RegisterNotificationCallbacks (const Notifications&)
262    /// @see UnregisterNotificationCallbacks (const Notifications&)
263    //------------------------------------------------------------------
264#ifndef SWIG
265    typedef struct
266    {
267        void *baton;
268        void (*initialize)(void *baton, Process *process);
269        void (*process_state_changed) (void *baton, Process *process, lldb::StateType state);
270    } Notifications;
271
272    class ProcessEventData :
273        public EventData
274    {
275        public:
276            ProcessEventData ();
277            ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state);
278
279            virtual ~ProcessEventData();
280
281            static const ConstString &
282            GetFlavorString ();
283
284            virtual const ConstString &
285            GetFlavor () const;
286
287            const lldb::ProcessSP &
288            GetProcessSP() const;
289
290            lldb::StateType
291            GetState() const;
292
293            bool
294            GetRestarted () const;
295
296            virtual void
297            Dump (Stream *s) const;
298
299            virtual void
300            DoOnRemoval (Event *event_ptr);
301
302            static const Process::ProcessEventData *
303            GetEventDataFromEvent (const Event *event_ptr);
304
305            static lldb::ProcessSP
306            GetProcessFromEvent (const Event *event_ptr);
307
308            static lldb::StateType
309            GetStateFromEvent (const Event *event_ptr);
310
311            static bool
312            GetRestartedFromEvent (const Event *event_ptr);
313
314            static void
315            SetRestartedInEvent (Event *event_ptr, bool new_value);
316
317            static bool
318            SetUpdateStateOnRemoval (Event *event_ptr);
319
320
321       private:
322
323            void
324            SetUpdateStateOnRemoval();
325
326            void
327            SetRestarted (bool new_value);
328
329            lldb::ProcessSP m_process_sp;
330            lldb::StateType m_state;
331            bool m_restarted;  // For "eStateStopped" events, this is true if the target was automatically restarted.
332            bool m_update_state;
333            DISALLOW_COPY_AND_ASSIGN (ProcessEventData);
334
335    };
336
337    class SettingsController : public UserSettingsController
338    {
339    public:
340
341        SettingsController ();
342
343        virtual
344        ~SettingsController ();
345
346        static SettingEntry global_settings_table[];
347        static SettingEntry instance_settings_table[];
348
349    protected:
350
351        lldb::InstanceSettingsSP
352        CreateInstanceSettings (const char *instance_name);
353
354        static lldb::OptionEnumValueElement g_plugins[];
355
356    private:
357
358        // Class-wide settings.
359
360        DISALLOW_COPY_AND_ASSIGN (SettingsController);
361    };
362
363#endif
364
365    static lldb::UserSettingsControllerSP
366    GetSettingsController (bool finish = false);
367
368    void
369    UpdateInstanceName ();
370
371    //------------------------------------------------------------------
372    /// Construct with a shared pointer to a target, and the Process listener.
373    //------------------------------------------------------------------
374    Process(Target &target, Listener &listener);
375
376    //------------------------------------------------------------------
377    /// Destructor.
378    ///
379    /// The destructor is virtual since this class is designed to be
380    /// inherited from by the plug-in instance.
381    //------------------------------------------------------------------
382    virtual
383    ~Process();
384
385    //------------------------------------------------------------------
386    /// Find a Process plug-in that can debug \a module using the
387    /// currently selected architecture.
388    ///
389    /// Scans all loaded plug-in interfaces that implement versions of
390    /// the Process plug-in interface and returns the first instance
391    /// that can debug the file.
392    ///
393    /// @param[in] module_sp
394    ///     The module shared pointer that this process will debug.
395    ///
396    /// @param[in] plugin_name
397    ///     If NULL, select the best plug-in for the binary. If non-NULL
398    ///     then look for a plugin whose PluginInfo's name matches
399    ///     this string.
400    ///
401    /// @see Process::CanDebug ()
402    //------------------------------------------------------------------
403    static Process*
404    FindPlugin (Target &target, const char *plugin_name, Listener &listener);
405
406
407
408    //------------------------------------------------------------------
409    /// Static function that can be used with the \b host function
410    /// Host::StartMonitoringChildProcess ().
411    ///
412    /// This function can be used by lldb_private::Process subclasses
413    /// when they want to watch for a local process and have its exit
414    /// status automatically set when the host child process exits.
415    /// Subclasses should call Host::StartMonitoringChildProcess ()
416    /// with:
417    ///     callback = Process::SetHostProcessExitStatus
418    ///     callback_baton = NULL
419    ///     pid = Process::GetID()
420    ///     monitor_signals = false
421    //------------------------------------------------------------------
422    static bool
423    SetProcessExitStatus (void *callback_baton,   // The callback baton which should be set to NULL
424                          lldb::pid_t pid,        // The process ID we want to monitor
425                          int signo,              // Zero for no signal
426                          int status);            // Exit value of process if signal is zero
427
428    //------------------------------------------------------------------
429    /// Check if a plug-in instance can debug the file in \a module.
430    ///
431    /// Each plug-in is given a chance to say whether it can debug
432    /// the file in \a module. If the Process plug-in instance can
433    /// debug a file on the current system, it should return \b true.
434    ///
435    /// @return
436    ///     Returns \b true if this Process plug-in instance can
437    ///     debug the executable, \b false otherwise.
438    //------------------------------------------------------------------
439    virtual bool
440    CanDebug (Target &target) = 0;
441
442
443    //------------------------------------------------------------------
444    /// This object is about to be destroyed, do any necessary cleanup.
445    ///
446    /// Subclasses that override this method should always call this
447    /// superclass method.
448    //------------------------------------------------------------------
449    virtual void
450    Finalize();
451
452    //------------------------------------------------------------------
453    /// Launch a new process.
454    ///
455    /// Launch a new process by spawning a new process using the
456    /// target object's executable module's file as the file to launch.
457    /// Arguments are given in \a argv, and the environment variables
458    /// are in \a envp. Standard input and output files can be
459    /// optionally re-directed to \a stdin_path, \a stdout_path, and
460    /// \a stderr_path.
461    ///
462    /// This function is not meant to be overridden by Process
463    /// subclasses. It will first call Process::WillLaunch (Module *)
464    /// and if that returns \b true, Process::DoLaunch (Module*,
465    /// char const *[],char const *[],const char *,const char *,
466    /// const char *) will be called to actually do the launching. If
467    /// DoLaunch returns \b true, then Process::DidLaunch() will be
468    /// called.
469    ///
470    /// @param[in] argv
471    ///     The argument array.
472    ///
473    /// @param[in] envp
474    ///     The environment array.
475    ///
476    /// @param[in] launch_flags
477    ///     Flags to modify the launch (@see lldb::LaunchFlags)
478    ///
479    /// @param[in] stdin_path
480    ///     The path to use when re-directing the STDIN of the new
481    ///     process. If all stdXX_path arguments are NULL, a pseudo
482    ///     terminal will be used.
483    ///
484    /// @param[in] stdout_path
485    ///     The path to use when re-directing the STDOUT of the new
486    ///     process. If all stdXX_path arguments are NULL, a pseudo
487    ///     terminal will be used.
488    ///
489    /// @param[in] stderr_path
490    ///     The path to use when re-directing the STDERR of the new
491    ///     process. If all stdXX_path arguments are NULL, a pseudo
492    ///     terminal will be used.
493    ///
494    /// @return
495    ///     An error object. Call GetID() to get the process ID if
496    ///     the error object is success.
497    //------------------------------------------------------------------
498    virtual Error
499    Launch (char const *argv[],
500            char const *envp[],
501            uint32_t launch_flags,
502            const char *stdin_path,
503            const char *stdout_path,
504            const char *stderr_path);
505
506    //------------------------------------------------------------------
507    /// Attach to an existing process using a process ID.
508    ///
509    /// This function is not meant to be overridden by Process
510    /// subclasses. It will first call Process::WillAttach (lldb::pid_t)
511    /// and if that returns \b true, Process::DoAttach (lldb::pid_t) will
512    /// be called to actually do the attach. If DoAttach returns \b
513    /// true, then Process::DidAttach() will be called.
514    ///
515    /// @param[in] pid
516    ///     The process ID that we should attempt to attach to.
517    ///
518    /// @return
519    ///     Returns \a pid if attaching was successful, or
520    ///     LLDB_INVALID_PROCESS_ID if attaching fails.
521    //------------------------------------------------------------------
522    virtual Error
523    Attach (lldb::pid_t pid);
524
525    //------------------------------------------------------------------
526    /// Attach to an existing process by process name.
527    ///
528    /// This function is not meant to be overridden by Process
529    /// subclasses. It will first call
530    /// Process::WillAttach (const char *) and if that returns \b
531    /// true, Process::DoAttach (const char *) will be called to
532    /// actually do the attach. If DoAttach returns \b true, then
533    /// Process::DidAttach() will be called.
534    ///
535    /// @param[in] process_name
536    ///     A process name to match against the current process list.
537    ///
538    /// @return
539    ///     Returns \a pid if attaching was successful, or
540    ///     LLDB_INVALID_PROCESS_ID if attaching fails.
541    //------------------------------------------------------------------
542    virtual Error
543    Attach (const char *process_name, bool wait_for_launch);
544
545    //------------------------------------------------------------------
546    /// List the processes matching the given partial name.
547    ///
548    /// FIXME: Is it too heavyweight to create an entire process object to do this?
549    /// The problem is for remote processes we're going to have to set up the same transport
550    /// to get this data as to actually attach.  So we need to factor out transport
551    /// and process before we can do this separately from the process.
552    ///
553    /// @param[in] name
554    ///     A partial name to match against the current process list.
555    ///
556    /// @param[out] matches
557    ///     The list of process names matching \a name.
558    ///
559    /// @param[in] pids
560    ///     A vector filled with the pids that correspond to the names in \a matches.
561    ///
562    /// @return
563    ///     Returns the number of matching processes.
564    //------------------------------------------------------------------
565
566    virtual uint32_t
567    ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids);
568
569    //------------------------------------------------------------------
570    /// Find the architecture of a process by pid.
571    ///
572    /// FIXME: See comment for ListProcessesMatchingName.
573    ///
574    /// @param[in] pid
575    ///     A pid to inspect.
576    ///
577    /// @return
578    ///     Returns the architecture of the process or an invalid architecture if the process can't be found.
579    //------------------------------------------------------------------
580    virtual ArchSpec
581    GetArchSpecForExistingProcess (lldb::pid_t pid);
582
583    //------------------------------------------------------------------
584    /// Find the architecture of a process by name.
585    ///
586    /// FIXME: See comment for ListProcessesMatchingName.
587    ///
588    /// @param[in] process_name
589    ///     The process name to inspect.
590    ///
591    /// @return
592    ///     Returns the architecture of the process or an invalid architecture if the process can't be found.
593    //------------------------------------------------------------------
594    virtual ArchSpec
595    GetArchSpecForExistingProcess (const char *process_name);
596
597    uint32_t
598    GetAddressByteSize();
599
600    //------------------------------------------------------------------
601    /// Get the image information address for the current process.
602    ///
603    /// Some runtimes have system functions that can help dynamic
604    /// loaders locate the dynamic loader information needed to observe
605    /// shared libraries being loaded or unloaded. This function is
606    /// in the Process interface (as opposed to the DynamicLoader
607    /// interface) to ensure that remote debugging can take advantage of
608    /// this functionality.
609    ///
610    /// @return
611    ///     The address of the dynamic loader information, or
612    ///     LLDB_INVALID_ADDRESS if this is not supported by this
613    ///     interface.
614    //------------------------------------------------------------------
615    virtual lldb::addr_t
616    GetImageInfoAddress ();
617
618    //------------------------------------------------------------------
619    /// Register for process and thread notifications.
620    ///
621    /// Clients can register nofication callbacks by filling out a
622    /// Process::Notifications structure and calling this function.
623    ///
624    /// @param[in] callbacks
625    ///     A structure that contains the notification baton and
626    ///     callback functions.
627    ///
628    /// @see Process::Notifications
629    //------------------------------------------------------------------
630#ifndef SWIG
631    void
632    RegisterNotificationCallbacks (const Process::Notifications& callbacks);
633#endif
634    //------------------------------------------------------------------
635    /// Unregister for process and thread notifications.
636    ///
637    /// Clients can unregister nofication callbacks by passing a copy of
638    /// the original baton and callbacks in \a callbacks.
639    ///
640    /// @param[in] callbacks
641    ///     A structure that contains the notification baton and
642    ///     callback functions.
643    ///
644    /// @return
645    ///     Returns \b true if the notification callbacks were
646    ///     successfully removed from the process, \b false otherwise.
647    ///
648    /// @see Process::Notifications
649    //------------------------------------------------------------------
650#ifndef SWIG
651    bool
652    UnregisterNotificationCallbacks (const Process::Notifications& callbacks);
653#endif
654    //==================================================================
655    // Built in Process Control functions
656    //==================================================================
657    //------------------------------------------------------------------
658    /// Resumes all of a process's threads as configured using the
659    /// Thread run control functions.
660    ///
661    /// Threads for a process should be updated with one of the run
662    /// control actions (resume, step, or suspend) that they should take
663    /// when the process is resumed. If no run control action is given
664    /// to a thread it will be resumed by default.
665    ///
666    /// This function is not meant to be overridden by Process
667    /// subclasses. This function will take care of disabling any
668    /// breakpoints that threads may be stopped at, single stepping, and
669    /// re-enabling breakpoints, and enabling the basic flow control
670    /// that the plug-in instances need not worry about.
671    ///
672    /// @return
673    ///     Returns an error object.
674    ///
675    /// @see Thread:Resume()
676    /// @see Thread:Step()
677    /// @see Thread:Suspend()
678    //------------------------------------------------------------------
679    virtual Error
680    Resume ();
681
682    //------------------------------------------------------------------
683    /// Halts a running process.
684    ///
685    /// This function is not meant to be overridden by Process
686    /// subclasses.
687    ///
688    /// @return
689    ///     Returns an error object.
690    //------------------------------------------------------------------
691    virtual Error
692    Halt ();
693
694    //------------------------------------------------------------------
695    /// Detaches from a running or stopped process.
696    ///
697    /// This function is not meant to be overridden by Process
698    /// subclasses.
699    ///
700    /// @return
701    ///     Returns an error object.
702    //------------------------------------------------------------------
703    virtual Error
704    Detach ();
705
706    //------------------------------------------------------------------
707    /// Kills the process and shuts down all threads that were spawned
708    /// to track and monitor the process.
709    ///
710    /// This function is not meant to be overridden by Process
711    /// subclasses.
712    ///
713    /// @return
714    ///     Returns an error object.
715    //------------------------------------------------------------------
716    virtual Error
717    Destroy();
718
719    //------------------------------------------------------------------
720    /// Sends a process a UNIX signal \a signal.
721    ///
722    /// This function is not meant to be overridden by Process
723    /// subclasses.
724    ///
725    /// @return
726    ///     Returns an error object.
727    //------------------------------------------------------------------
728    virtual Error
729    Signal (int signal);
730
731    virtual UnixSignals &
732    GetUnixSignals ();
733
734
735    //==================================================================
736    // Plug-in Process Control Overrides
737    //==================================================================
738
739    //------------------------------------------------------------------
740    /// Called before attaching to a process.
741    ///
742    /// Allow Process plug-ins to execute some code before attaching a
743    /// process.
744    ///
745    /// @return
746    ///     Returns an error object.
747    //------------------------------------------------------------------
748    virtual Error
749    WillAttachToProcessWithID (lldb::pid_t pid)
750    {
751        return Error();
752    }
753
754    //------------------------------------------------------------------
755    /// Called before attaching to a process.
756    ///
757    /// Allow Process plug-ins to execute some code before attaching a
758    /// process.
759    ///
760    /// @return
761    ///     Returns an error object.
762    //------------------------------------------------------------------
763    virtual Error
764    WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
765    {
766        return Error();
767    }
768
769    //------------------------------------------------------------------
770    /// Attach to an existing process using a process ID.
771    ///
772    /// @param[in] pid
773    ///     The process ID that we should attempt to attach to.
774    ///
775    /// @return
776    ///     Returns \a pid if attaching was successful, or
777    ///     LLDB_INVALID_PROCESS_ID if attaching fails.
778    //------------------------------------------------------------------
779    virtual Error
780    DoAttachToProcessWithID (lldb::pid_t pid) = 0;
781
782    //------------------------------------------------------------------
783    /// Attach to an existing process using a partial process name.
784    ///
785    /// @param[in] process_name
786    ///     The name of the process to attach to.
787    ///
788    /// @param[in] wait_for_launch
789    ///     If \b true, wait for the process to be launched and attach
790    ///     as soon as possible after it does launch. If \b false, then
791    ///     search for a matching process the currently exists.
792    ///
793    /// @return
794    ///     Returns \a pid if attaching was successful, or
795    ///     LLDB_INVALID_PROCESS_ID if attaching fails.
796    //------------------------------------------------------------------
797    virtual Error
798    DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
799    {
800        Error error;
801        error.SetErrorString("attach by name is not supported");
802        return error;
803    }
804
805    //------------------------------------------------------------------
806    /// Called after attaching a process.
807    ///
808    /// Allow Process plug-ins to execute some code after attaching to
809    /// a process.
810    //------------------------------------------------------------------
811    virtual void
812    DidAttach () {}
813
814
815    //------------------------------------------------------------------
816    /// Called before launching to a process.
817    ///
818    /// Allow Process plug-ins to execute some code before launching a
819    /// process.
820    ///
821    /// @return
822    ///     Returns an error object.
823    //------------------------------------------------------------------
824    virtual Error
825    WillLaunch (Module* module)
826    {
827        return Error();
828    }
829
830    //------------------------------------------------------------------
831    /// Launch a new process.
832    ///
833    /// Launch a new process by spawning a new process using \a module's
834    /// file as the file to launch. Arguments are given in \a argv,
835    /// and the environment variables are in \a envp. Standard input
836    /// and output files can be optionally re-directed to \a stdin_path,
837    /// \a stdout_path, and \a stderr_path.
838    ///
839    /// @param[in] module
840    ///     The module from which to extract the file specification and
841    ///     launch.
842    ///
843    /// @param[in] argv
844    ///     The argument array.
845    ///
846    /// @param[in] envp
847    ///     The environment array.
848    ///
849    /// @param[in] launch_flags
850    ///     Flags to modify the launch (@see lldb::LaunchFlags)
851    ///
852    /// @param[in] stdin_path
853    ///     The path to use when re-directing the STDIN of the new
854    ///     process. If all stdXX_path arguments are NULL, a pseudo
855    ///     terminal will be used.
856    ///
857    /// @param[in] stdout_path
858    ///     The path to use when re-directing the STDOUT of the new
859    ///     process. If all stdXX_path arguments are NULL, a pseudo
860    ///     terminal will be used.
861    ///
862    /// @param[in] stderr_path
863    ///     The path to use when re-directing the STDERR of the new
864    ///     process. If all stdXX_path arguments are NULL, a pseudo
865    ///     terminal will be used.
866    ///
867    /// @return
868    ///     A new valid process ID, or LLDB_INVALID_PROCESS_ID if
869    ///     launching fails.
870    //------------------------------------------------------------------
871    virtual Error
872    DoLaunch (Module* module,
873              char const *argv[],
874              char const *envp[],
875              uint32_t launch_flags,
876              const char *stdin_path,
877              const char *stdout_path,
878              const char *stderr_path) = 0;
879
880    //------------------------------------------------------------------
881    /// Called after launching a process.
882    ///
883    /// Allow Process plug-ins to execute some code after launching
884    /// a process.
885    //------------------------------------------------------------------
886    virtual void
887    DidLaunch () {}
888
889
890
891    //------------------------------------------------------------------
892    /// Called before resuming to a process.
893    ///
894    /// Allow Process plug-ins to execute some code before resuming a
895    /// process.
896    ///
897    /// @return
898    ///     Returns an error object.
899    //------------------------------------------------------------------
900    virtual Error
901    WillResume () { return Error(); }
902
903    //------------------------------------------------------------------
904    /// Resumes all of a process's threads as configured using the
905    /// Thread run control functions.
906    ///
907    /// Threads for a process should be updated with one of the run
908    /// control actions (resume, step, or suspend) that they should take
909    /// when the process is resumed. If no run control action is given
910    /// to a thread it will be resumed by default.
911    ///
912    /// @return
913    ///     Returns \b true if the process successfully resumes using
914    ///     the thread run control actions, \b false otherwise.
915    ///
916    /// @see Thread:Resume()
917    /// @see Thread:Step()
918    /// @see Thread:Suspend()
919    //------------------------------------------------------------------
920    virtual Error
921    DoResume () = 0;
922
923    //------------------------------------------------------------------
924    /// Called after resuming a process.
925    ///
926    /// Allow Process plug-ins to execute some code after resuming
927    /// a process.
928    //------------------------------------------------------------------
929    virtual void
930    DidResume () {}
931
932
933    //------------------------------------------------------------------
934    /// Called before halting to a process.
935    ///
936    /// Allow Process plug-ins to execute some code before halting a
937    /// process.
938    ///
939    /// @return
940    ///     Returns an error object.
941    //------------------------------------------------------------------
942    virtual Error
943    WillHalt () { return Error(); }
944
945    //------------------------------------------------------------------
946    /// Halts a running process.
947    ///
948    /// @return
949    ///     Returns \b true if the process successfully halts, \b false
950    ///     otherwise.
951    //------------------------------------------------------------------
952    virtual Error
953    DoHalt () = 0;
954
955    //------------------------------------------------------------------
956    /// Called after halting a process.
957    ///
958    /// Allow Process plug-ins to execute some code after halting
959    /// a process.
960    //------------------------------------------------------------------
961    virtual void
962    DidHalt () {}
963
964    //------------------------------------------------------------------
965    /// Called before detaching from a process.
966    ///
967    /// Allow Process plug-ins to execute some code before detaching
968    /// from a process.
969    ///
970    /// @return
971    ///     Returns an error object.
972    //------------------------------------------------------------------
973    virtual Error
974    WillDetach ()
975    {
976        return Error();
977    }
978
979    //------------------------------------------------------------------
980    /// Detaches from a running or stopped process.
981    ///
982    /// @return
983    ///     Returns \b true if the process successfully detaches, \b
984    ///     false otherwise.
985    //------------------------------------------------------------------
986    virtual Error
987    DoDetach () = 0;
988
989    //------------------------------------------------------------------
990    /// Called after detaching from a process.
991    ///
992    /// Allow Process plug-ins to execute some code after detaching
993    /// from a process.
994    //------------------------------------------------------------------
995    virtual void
996    DidDetach () {}
997
998    //------------------------------------------------------------------
999    /// Called before sending a signal to a process.
1000    ///
1001    /// Allow Process plug-ins to execute some code before sending a
1002    /// signal to a process.
1003    ///
1004    /// @return
1005    ///     Returns no error if it is safe to proceed with a call to
1006    ///     Process::DoSignal(int), otherwise an error describing what
1007    ///     prevents the signal from being sent.
1008    //------------------------------------------------------------------
1009    virtual Error
1010    WillSignal () { return Error(); }
1011
1012    //------------------------------------------------------------------
1013    /// Sends a process a UNIX signal \a signal.
1014    ///
1015    /// @return
1016    ///     Returns an error object.
1017    //------------------------------------------------------------------
1018    virtual Error
1019    DoSignal (int signal) = 0;
1020
1021
1022
1023    virtual Error
1024    WillDestroy () { return Error(); }
1025
1026    virtual Error
1027    DoDestroy () = 0;
1028
1029    virtual void
1030    DidDestroy () { }
1031
1032
1033    //------------------------------------------------------------------
1034    /// Called after sending a signal to a process.
1035    ///
1036    /// Allow Process plug-ins to execute some code after sending a
1037    /// signal to a process.
1038    //------------------------------------------------------------------
1039    virtual void
1040    DidSignal () {}
1041
1042
1043    //------------------------------------------------------------------
1044    /// Currently called as part of ShouldStop.
1045    /// FIXME: Should really happen when the target stops before the
1046    /// event is taken from the queue...
1047    ///
1048    /// This callback is called as the event
1049    /// is about to be queued up to allow Process plug-ins to execute
1050    /// some code prior to clients being notified that a process was
1051    /// stopped. Common operations include updating the thread list,
1052    /// invalidating any thread state (registers, stack, etc) prior to
1053    /// letting the notification go out.
1054    ///
1055    //------------------------------------------------------------------
1056    virtual void
1057    RefreshStateAfterStop () = 0;
1058
1059    //------------------------------------------------------------------
1060    /// Get the target object pointer for this module.
1061    ///
1062    /// @return
1063    ///     A Target object pointer to the target that owns this
1064    ///     module.
1065    //------------------------------------------------------------------
1066    Target &
1067    GetTarget ();
1068
1069    //------------------------------------------------------------------
1070    /// Get the const target object pointer for this module.
1071    ///
1072    /// @return
1073    ///     A const Target object pointer to the target that owns this
1074    ///     module.
1075    //------------------------------------------------------------------
1076    const Target &
1077    GetTarget () const;
1078
1079    //------------------------------------------------------------------
1080    /// Get accessor for the current process state.
1081    ///
1082    /// @return
1083    ///     The current state of the process.
1084    ///
1085    /// @see lldb::StateType
1086    //------------------------------------------------------------------
1087    lldb::StateType
1088    GetState ();
1089
1090protected:
1091    friend class CommandObjectProcessLaunch;
1092    friend class ProcessEventData;
1093    friend class CommandObjectBreakpointCommand;
1094
1095    void
1096    SetState (lldb::EventSP &event_sp);
1097
1098    lldb::StateType
1099    GetPrivateState ();
1100
1101public:
1102    //------------------------------------------------------------------
1103    /// Get the exit status for a process.
1104    ///
1105    /// @return
1106    ///     The process's return code, or -1 if the current process
1107    ///     state is not eStateExited.
1108    //------------------------------------------------------------------
1109    int
1110    GetExitStatus ();
1111
1112    //------------------------------------------------------------------
1113    /// Get a textual description of what the process exited.
1114    ///
1115    /// @return
1116    ///     The textual description of why the process exited, or NULL
1117    ///     if there is no description available.
1118    //------------------------------------------------------------------
1119    const char *
1120    GetExitDescription ();
1121
1122
1123    virtual void
1124    DidExit ()
1125    {
1126    }
1127
1128    //------------------------------------------------------------------
1129    /// Get the number of times this process has posted a stop event.
1130    ///
1131    /// @return
1132    ///     The number of times this process has stopped while being
1133    ///     debugged.
1134    //------------------------------------------------------------------
1135    uint32_t
1136    GetStopID () const;
1137
1138    //------------------------------------------------------------------
1139    /// Set accessor for the process exit status (return code).
1140    ///
1141    /// Sometimes a child exits and the exit can be detected by global
1142    /// functions (signal handler for SIGCHLD for example). This
1143    /// accessor allows the exit status to be set from an external
1144    /// source.
1145    ///
1146    /// Setting this will cause a eStateExited event to be posted to
1147    /// the process event queue.
1148    ///
1149    /// @param[in] exit_status
1150    ///     The value for the process's return code.
1151    ///
1152    /// @see lldb::StateType
1153    //------------------------------------------------------------------
1154    virtual void
1155    SetExitStatus (int exit_status, const char *cstr);
1156
1157    //------------------------------------------------------------------
1158    /// Check if a process is still alive.
1159    ///
1160    /// @return
1161    ///     Returns \b true if the process is still valid, \b false
1162    ///     otherwise.
1163    //------------------------------------------------------------------
1164    virtual bool
1165    IsAlive () = 0;
1166
1167    //------------------------------------------------------------------
1168    /// Actually do the reading of memory from a process.
1169    ///
1170    /// Subclasses must override this function and can return fewer
1171    /// bytes than requested when memory requests are too large. This
1172    /// class will break up the memory requests and keep advancing the
1173    /// arguments along as needed.
1174    ///
1175    /// @param[in] vm_addr
1176    ///     A virtual load address that indicates where to start reading
1177    ///     memory from.
1178    ///
1179    /// @param[in] size
1180    ///     The number of bytes to read.
1181    ///
1182    /// @param[out] buf
1183    ///     A byte buffer that is at least \a size bytes long that
1184    ///     will receive the memory bytes.
1185    ///
1186    /// @return
1187    ///     The number of bytes that were actually read into \a buf.
1188    //------------------------------------------------------------------
1189    virtual size_t
1190    DoReadMemory (lldb::addr_t vm_addr,
1191                  void *buf,
1192                  size_t size,
1193                  Error &error) = 0;
1194
1195    //------------------------------------------------------------------
1196    /// Read of memory from a process.
1197    ///
1198    /// This function will read memory from the current process's
1199    /// address space and remove any traps that may have been inserted
1200    /// into the memory.
1201    ///
1202    /// This function is not meant to be overridden by Process
1203    /// subclasses, the subclasses should implement
1204    /// Process::DoReadMemory (lldb::addr_t, size_t, void *).
1205    ///
1206    /// @param[in] vm_addr
1207    ///     A virtual load address that indicates where to start reading
1208    ///     memory from.
1209    ///
1210    /// @param[out] buf
1211    ///     A byte buffer that is at least \a size bytes long that
1212    ///     will receive the memory bytes.
1213    ///
1214    /// @param[in] size
1215    ///     The number of bytes to read.
1216    ///
1217    /// @return
1218    ///     The number of bytes that were actually read into \a buf. If
1219    ///     the returned number is greater than zero, yet less than \a
1220    ///     size, then this function will get called again with \a
1221    ///     vm_addr, \a buf, and \a size updated appropriately. Zero is
1222    ///     returned to indicate an error.
1223    //------------------------------------------------------------------
1224    size_t
1225    ReadMemory (lldb::addr_t vm_addr,
1226                void *buf,
1227                size_t size,
1228                Error &error);
1229
1230    //------------------------------------------------------------------
1231    /// Actually do the writing of memory to a process.
1232    ///
1233    /// @param[in] vm_addr
1234    ///     A virtual load address that indicates where to start writing
1235    ///     memory to.
1236    ///
1237    /// @param[in] buf
1238    ///     A byte buffer that is at least \a size bytes long that
1239    ///     contains the data to write.
1240    ///
1241    /// @param[in] size
1242    ///     The number of bytes to write.
1243    ///
1244    /// @return
1245    ///     The number of bytes that were actually written.
1246    //------------------------------------------------------------------
1247    virtual size_t
1248    DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) = 0;
1249
1250    //------------------------------------------------------------------
1251    /// Write memory to a process.
1252    ///
1253    /// This function will write memory to the current process's
1254    /// address space and maintain any traps that might be present due
1255    /// to software breakpoints.
1256    ///
1257    /// This function is not meant to be overridden by Process
1258    /// subclasses, the subclasses should implement
1259    /// Process::DoWriteMemory (lldb::addr_t, size_t, void *).
1260    ///
1261    /// @param[in] vm_addr
1262    ///     A virtual load address that indicates where to start writing
1263    ///     memory to.
1264    ///
1265    /// @param[in] buf
1266    ///     A byte buffer that is at least \a size bytes long that
1267    ///     contains the data to write.
1268    ///
1269    /// @param[in] size
1270    ///     The number of bytes to write.
1271    ///
1272    /// @return
1273    ///     The number of bytes that were actually written.
1274    //------------------------------------------------------------------
1275    size_t
1276    WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error);
1277
1278
1279    //------------------------------------------------------------------
1280    /// Actually allocate memory in the process.
1281    ///
1282    /// This function will allocate memory in the process's address
1283    /// space.  This can't rely on the generic function calling mechanism,
1284    /// since that requires this function.
1285    ///
1286    /// @param[in] size
1287    ///     The size of the allocation requested.
1288    ///
1289    /// @return
1290    ///     The address of the allocated buffer in the process, or
1291    ///     LLDB_INVALID_ADDRESS if the allocation failed.
1292    //------------------------------------------------------------------
1293
1294    virtual lldb::addr_t
1295    DoAllocateMemory (size_t size, uint32_t permissions, Error &error) = 0;
1296
1297    //------------------------------------------------------------------
1298    /// The public interface to allocating memory in the process.
1299    ///
1300    /// This function will allocate memory in the process's address
1301    /// space.  This can't rely on the generic function calling mechanism,
1302    /// since that requires this function.
1303    ///
1304    /// @param[in] size
1305    ///     The size of the allocation requested.
1306    ///
1307    /// @param[in] permissions
1308    ///     Or together any of the lldb::Permissions bits.  The permissions on
1309    ///     a given memory allocation can't be changed after allocation.  Note
1310    ///     that a block that isn't set writable can still be written on from lldb,
1311    ///     just not by the process itself.
1312    ///
1313    /// @return
1314    ///     The address of the allocated buffer in the process, or
1315    ///     LLDB_INVALID_ADDRESS if the allocation failed.
1316    //------------------------------------------------------------------
1317
1318    lldb::addr_t
1319    AllocateMemory (size_t size, uint32_t permissions, Error &error);
1320
1321    //------------------------------------------------------------------
1322    /// Actually deallocate memory in the process.
1323    ///
1324    /// This function will deallocate memory in the process's address
1325    /// space that was allocated with AllocateMemory.
1326    ///
1327    /// @param[in] ptr
1328    ///     A return value from AllocateMemory, pointing to the memory you
1329    ///     want to deallocate.
1330    ///
1331    /// @return
1332    ///     \btrue if the memory was deallocated, \bfalse otherwise.
1333    //------------------------------------------------------------------
1334
1335    virtual Error
1336    DoDeallocateMemory (lldb::addr_t ptr) = 0;
1337
1338    //------------------------------------------------------------------
1339    /// The public interface to deallocating memory in the process.
1340    ///
1341    /// This function will deallocate memory in the process's address
1342    /// space that was allocated with AllocateMemory.
1343    ///
1344    /// @param[in] ptr
1345    ///     A return value from AllocateMemory, pointing to the memory you
1346    ///     want to deallocate.
1347    ///
1348    /// @return
1349    ///     \btrue if the memory was deallocated, \bfalse otherwise.
1350    //------------------------------------------------------------------
1351
1352    Error
1353    DeallocateMemory (lldb::addr_t ptr);
1354
1355    //------------------------------------------------------------------
1356    /// Get any available STDOUT.
1357    ///
1358    /// If the process was launched without supplying valid file paths
1359    /// for stdin, stdout, and stderr, then the Process class might
1360    /// try to cache the STDOUT for the process if it is able. Events
1361    /// will be queued indicating that there is STDOUT available that
1362    /// can be retrieved using this function.
1363    ///
1364    /// @param[out] buf
1365    ///     A buffer that will receive any STDOUT bytes that are
1366    ///     currently available.
1367    ///
1368    /// @param[out] buf_size
1369    ///     The size in bytes for the buffer \a buf.
1370    ///
1371    /// @return
1372    ///     The number of bytes written into \a buf. If this value is
1373    ///     equal to \a buf_size, another call to this function should
1374    ///     be made to retrieve more STDOUT data.
1375    //------------------------------------------------------------------
1376    virtual size_t
1377    GetSTDOUT (char *buf, size_t buf_size, Error &error)
1378    {
1379        error.SetErrorString("stdout unsupported");
1380        return 0;
1381    }
1382
1383
1384    //------------------------------------------------------------------
1385    /// Get any available STDERR.
1386    ///
1387    /// If the process was launched without supplying valid file paths
1388    /// for stdin, stdout, and stderr, then the Process class might
1389    /// try to cache the STDERR for the process if it is able. Events
1390    /// will be queued indicating that there is STDERR available that
1391    /// can be retrieved using this function.
1392    ///
1393    /// @param[out] buf
1394    ///     A buffer that will receive any STDERR bytes that are
1395    ///     currently available.
1396    ///
1397    /// @param[out] buf_size
1398    ///     The size in bytes for the buffer \a buf.
1399    ///
1400    /// @return
1401    ///     The number of bytes written into \a buf. If this value is
1402    ///     equal to \a buf_size, another call to this function should
1403    ///     be made to retrieve more STDERR data.
1404    //------------------------------------------------------------------
1405    virtual size_t
1406    GetSTDERR (char *buf, size_t buf_size, Error &error)
1407    {
1408        error.SetErrorString("stderr unsupported");
1409        return 0;
1410    }
1411
1412    virtual size_t
1413    PutSTDIN (const char *buf, size_t buf_size, Error &error)
1414    {
1415        error.SetErrorString("stdin unsupported");
1416        return 0;
1417    }
1418
1419    //----------------------------------------------------------------------
1420    // Process Breakpoints
1421    //----------------------------------------------------------------------
1422    virtual size_t
1423    GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) = 0;
1424
1425    virtual Error
1426    EnableBreakpoint (BreakpointSite *bp_site) = 0;
1427
1428    virtual Error
1429    DisableBreakpoint (BreakpointSite *bp_site) = 0;
1430
1431    // This is implemented completely using the lldb::Process API. Subclasses
1432    // don't need to implement this function unless the standard flow of
1433    // read existing opcode, write breakpoint opcode, verify breakpoint opcode
1434    // doesn't work for a specific process plug-in.
1435    virtual Error
1436    EnableSoftwareBreakpoint (BreakpointSite *bp_site);
1437
1438    // This is implemented completely using the lldb::Process API. Subclasses
1439    // don't need to implement this function unless the standard flow of
1440    // restoring original opcode in memory and verifying the restored opcode
1441    // doesn't work for a specific process plug-in.
1442    virtual Error
1443    DisableSoftwareBreakpoint (BreakpointSite *bp_site);
1444
1445    BreakpointSiteList &
1446    GetBreakpointSiteList();
1447
1448    const BreakpointSiteList &
1449    GetBreakpointSiteList() const;
1450
1451    void
1452    DisableAllBreakpointSites ();
1453
1454    Error
1455    ClearBreakpointSiteByID (lldb::user_id_t break_id);
1456
1457    lldb::break_id_t
1458    CreateBreakpointSite (lldb::BreakpointLocationSP &owner,
1459                          bool use_hardware);
1460
1461    Error
1462    DisableBreakpointSiteByID (lldb::user_id_t break_id);
1463
1464    Error
1465    EnableBreakpointSiteByID (lldb::user_id_t break_id);
1466
1467
1468    // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove
1469    // themselves from the owner's list of this breakpoint sites.  This has to
1470    // be a static function because you can't be sure that removing the
1471    // breakpoint from it's containing map won't delete the breakpoint site,
1472    // and doing that in an instance method isn't copasetic.
1473    void
1474    RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id,
1475                                   lldb::user_id_t owner_loc_id,
1476                                   lldb::BreakpointSiteSP &bp_site_sp);
1477
1478    //----------------------------------------------------------------------
1479    // Process Watchpoints (optional)
1480    //----------------------------------------------------------------------
1481    virtual Error
1482    EnableWatchpoint (WatchpointLocation *bp_loc);
1483
1484    virtual Error
1485    DisableWatchpoint (WatchpointLocation *bp_loc);
1486
1487    //------------------------------------------------------------------
1488    // Thread Queries
1489    //------------------------------------------------------------------
1490    virtual uint32_t
1491    UpdateThreadListIfNeeded () = 0;
1492
1493    ThreadList &
1494    GetThreadList ();
1495
1496    const ThreadList &
1497    GetThreadList () const;
1498
1499    uint32_t
1500    GetNextThreadIndexID ();
1501
1502    //------------------------------------------------------------------
1503    // Event Handling
1504    //------------------------------------------------------------------
1505    lldb::StateType
1506    GetNextEvent (lldb::EventSP &event_sp);
1507
1508    lldb::StateType
1509    WaitForProcessToStop (const TimeValue *timeout);
1510
1511    lldb::StateType
1512    WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp);
1513
1514    Event *
1515    PeekAtStateChangedEvents ();
1516
1517    //------------------------------------------------------------------
1518    /// This is the part of the event handling that for a process event.
1519    /// It decides what to do with the event and returns true if the
1520    /// event needs to be propagated to the user, and false otherwise.
1521    /// If the event is not propagated, this call will most likely set
1522    /// the target to executing again.
1523    ///
1524    /// @param[in] event_ptr
1525    ///     This is the event we are handling.
1526    ///
1527    /// @return
1528    ///     Returns \b true if the event should be reported to the
1529    ///     user, \b false otherwise.
1530    //------------------------------------------------------------------
1531    bool
1532    ShouldBroadcastEvent (Event *event_ptr);
1533
1534    //------------------------------------------------------------------
1535    /// Gets the byte order for this process.
1536    ///
1537    /// @return
1538    ///     A valid ByteOrder enumeration, or eByteOrderInvalid.
1539    //------------------------------------------------------------------
1540    virtual lldb::ByteOrder
1541    GetByteOrder () const = 0;
1542
1543    const ConstString &
1544    GetTargetTriple ()
1545    {
1546        return m_target_triple;
1547    }
1548
1549    const ABI *
1550    GetABI ();
1551
1552    virtual DynamicLoader *
1553    GetDynamicLoader ();
1554
1555    virtual LanguageRuntime *
1556    GetLanguageRuntime (lldb::LanguageType language);
1557
1558    virtual CPPLanguageRuntime *
1559    GetCPPLanguageRuntime ();
1560
1561    virtual ObjCLanguageRuntime *
1562    GetObjCLanguageRuntime ();
1563
1564    bool
1565    IsRunning () const;
1566
1567    DynamicCheckerFunctions *GetDynamicCheckers()
1568    {
1569        return m_dynamic_checkers.get();
1570    }
1571
1572    void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers)
1573    {
1574        m_dynamic_checkers.reset(dynamic_checkers);
1575    }
1576
1577    //------------------------------------------------------------------
1578    // lldb::ExecutionContextScope pure virtual functions
1579    //------------------------------------------------------------------
1580    virtual Target *
1581    CalculateTarget ();
1582
1583    virtual Process *
1584    CalculateProcess ();
1585
1586    virtual Thread *
1587    CalculateThread ();
1588
1589    virtual StackFrame *
1590    CalculateStackFrame ();
1591
1592    virtual void
1593    Calculate (ExecutionContext &exe_ctx);
1594
1595    lldb::ProcessSP
1596    GetSP ();
1597
1598    ClangPersistentVariables &
1599    GetPersistentVariables();
1600
1601    ObjCObjectPrinter &
1602    GetObjCObjectPrinter();
1603
1604protected:
1605    //------------------------------------------------------------------
1606    // Member variables
1607    //------------------------------------------------------------------
1608    Target &                    m_target;               ///< The target that owns this process.
1609    ThreadSafeValue<lldb::StateType>  m_public_state;
1610    ThreadSafeValue<lldb::StateType>  m_private_state; // The actual state of our process
1611    Broadcaster                 m_private_state_broadcaster;  // This broadcaster feeds state changed events into the private state thread's listener.
1612    Broadcaster                 m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread.
1613    Listener                    m_private_state_listener;     // This is the listener for the private state thread.
1614    Predicate<bool>             m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete.
1615    lldb::thread_t              m_private_state_thread;  // Thread ID for the thread that watches interal state events
1616    uint32_t                    m_stop_id;              ///< A count of many times the process has stopped.
1617    uint32_t                    m_thread_index_id;      ///< Each thread is created with a 1 based index that won't get re-used.
1618    int                         m_exit_status;          ///< The exit status of the process, or -1 if not set.
1619    std::string                 m_exit_string;          ///< A textual description of why a process exited.
1620    ThreadList                  m_thread_list;          ///< The threads for this process.
1621    std::vector<Notifications>  m_notifications;        ///< The list of notifications that this process can deliver.
1622    Listener                    &m_listener;
1623    BreakpointSiteList          m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend
1624                                                        ///< to insert in the target.
1625    ClangPersistentVariables    m_persistent_vars;      ///< These are the persistent variables associated with this process for the expression parser.
1626    std::auto_ptr<DynamicCheckerFunctions>  m_dynamic_checkers; ///< The functions used by the expression parser to validate data that expressions use.
1627    UnixSignals                 m_unix_signals;         /// This is the current signal set for this process.
1628    ConstString                 m_target_triple;
1629    lldb::ABISP                 m_abi_sp;
1630    ObjCObjectPrinter           m_objc_object_printer;
1631
1632    typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection;
1633    LanguageRuntimeCollection m_language_runtimes;
1634
1635    size_t
1636    RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const;
1637
1638    void
1639    SynchronouslyNotifyStateChanged (lldb::StateType state);
1640
1641    void
1642    SetPublicState (lldb::StateType new_state);
1643
1644    void
1645    SetPrivateState (lldb::StateType state);
1646
1647    bool
1648    StartPrivateStateThread ();
1649
1650    void
1651    StopPrivateStateThread ();
1652
1653    void
1654    PausePrivateStateThread ();
1655
1656    void
1657    ResumePrivateStateThread ();
1658
1659    static void *
1660    PrivateStateThread (void *arg);
1661
1662    void *
1663    RunPrivateStateThread ();
1664
1665    void
1666    HandlePrivateEvent (lldb::EventSP &event_sp);
1667
1668    lldb::StateType
1669    WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
1670
1671    Error
1672    CompleteAttach ();
1673
1674
1675    // This waits for both the state change broadcaster, and the control broadcaster.
1676    // If control_only, it only waits for the control broadcaster.
1677
1678    bool
1679    WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only);
1680
1681    lldb::StateType
1682    WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
1683
1684    lldb::StateType
1685    WaitForState (const TimeValue *timeout,
1686                  const lldb::StateType *match_states,
1687                  const uint32_t num_match_states);
1688
1689    size_t
1690    WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error);
1691
1692private:
1693    //------------------------------------------------------------------
1694    // For Process only
1695    //------------------------------------------------------------------
1696    void ControlPrivateStateThread (uint32_t signal);
1697
1698    DISALLOW_COPY_AND_ASSIGN (Process);
1699
1700};
1701
1702} // namespace lldb_private
1703
1704#endif  // liblldb_Process_h_
1705