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