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