]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/Process.h
Merge ACPICA 20150619.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / Process.h
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 #include "lldb/Host/Config.h"
14
15 // C Includes
16 #include <limits.h>
17
18 // C++ Includes
19 #include <list>
20 #include <iosfwd>
21 #include <vector>
22
23 // Other libraries and framework includes
24 // Project includes
25 #include "lldb/lldb-private.h"
26 #include "lldb/Core/ArchSpec.h"
27 #include "lldb/Core/Broadcaster.h"
28 #include "lldb/Core/Communication.h"
29 #include "lldb/Core/Error.h"
30 #include "lldb/Core/Event.h"
31 #include "lldb/Core/RangeMap.h"
32 #include "lldb/Core/StringList.h"
33 #include "lldb/Core/ThreadSafeValue.h"
34 #include "lldb/Core/PluginInterface.h"
35 #include "lldb/Core/UserSettingsController.h"
36 #include "lldb/Breakpoint/BreakpointSiteList.h"
37 #include "lldb/Expression/ClangPersistentVariables.h"
38 #include "lldb/Expression/IRDynamicChecks.h"
39 #include "lldb/Host/FileSpec.h"
40 #include "lldb/Host/Host.h"
41 #include "lldb/Host/HostThread.h"
42 #include "lldb/Host/ProcessRunLock.h"
43 #include "lldb/Interpreter/Args.h"
44 #include "lldb/Interpreter/Options.h"
45 #include "lldb/Target/ExecutionContextScope.h"
46 #include "lldb/Target/JITLoaderList.h"
47 #include "lldb/Target/Memory.h"
48 #include "lldb/Target/MemoryRegionInfo.h"
49 #include "lldb/Target/ProcessInfo.h"
50 #include "lldb/Target/ProcessLaunchInfo.h"
51 #include "lldb/Target/QueueList.h"
52 #include "lldb/Target/ThreadList.h"
53 #include "lldb/Target/UnixSignals.h"
54 #include "lldb/Utility/PseudoTerminal.h"
55 #include "lldb/Target/InstrumentationRuntime.h"
56
57 namespace lldb_private {
58
59 //----------------------------------------------------------------------
60 // ProcessProperties
61 //----------------------------------------------------------------------
62 class ProcessProperties : public Properties
63 {
64 public:
65     // Pass NULL for "process" if the ProcessProperties are to be the global copy
66     ProcessProperties (lldb_private::Process *process);
67
68     virtual
69     ~ProcessProperties();
70     
71     bool
72     GetDisableMemoryCache() const;
73
74     uint64_t
75     GetMemoryCacheLineSize () const;
76
77     Args
78     GetExtraStartupCommands () const;
79
80     void
81     SetExtraStartupCommands (const Args &args);
82     
83     FileSpec
84     GetPythonOSPluginPath () const;
85
86     void
87     SetPythonOSPluginPath (const FileSpec &file);
88     
89     bool
90     GetIgnoreBreakpointsInExpressions () const;
91     
92     void
93     SetIgnoreBreakpointsInExpressions (bool ignore);
94
95     bool
96     GetUnwindOnErrorInExpressions () const;
97     
98     void
99     SetUnwindOnErrorInExpressions (bool ignore);
100     
101     bool
102     GetStopOnSharedLibraryEvents () const;
103     
104     void
105     SetStopOnSharedLibraryEvents (bool stop);
106     
107     bool
108     GetDetachKeepsStopped () const;
109     
110     void
111     SetDetachKeepsStopped (bool keep_stopped);
112
113 protected:
114
115     static void
116     OptionValueChangedCallback (void *baton, OptionValue *option_value);
117
118     Process * m_process; // Can be NULL for global ProcessProperties
119 };
120
121 typedef std::shared_ptr<ProcessProperties> ProcessPropertiesSP;
122
123 //----------------------------------------------------------------------
124 // ProcessInstanceInfo
125 //
126 // Describes an existing process and any discoverable information that
127 // pertains to that process.
128 //----------------------------------------------------------------------
129 class ProcessInstanceInfo : public ProcessInfo
130 {
131 public:
132     ProcessInstanceInfo () :
133         ProcessInfo (),
134         m_euid (UINT32_MAX),
135         m_egid (UINT32_MAX),
136         m_parent_pid (LLDB_INVALID_PROCESS_ID)
137     {
138     }
139
140     ProcessInstanceInfo (const char *name,
141                  const ArchSpec &arch,
142                  lldb::pid_t pid) :
143         ProcessInfo (name, arch, pid),
144         m_euid (UINT32_MAX),
145         m_egid (UINT32_MAX),
146         m_parent_pid (LLDB_INVALID_PROCESS_ID)
147     {
148     }
149     
150     void
151     Clear ()
152     {
153         ProcessInfo::Clear();
154         m_euid = UINT32_MAX;
155         m_egid = UINT32_MAX;
156         m_parent_pid = LLDB_INVALID_PROCESS_ID;
157     }
158     
159     uint32_t
160     GetEffectiveUserID() const
161     {
162         return m_euid;
163     }
164
165     uint32_t
166     GetEffectiveGroupID() const
167     {
168         return m_egid;
169     }
170     
171     bool
172     EffectiveUserIDIsValid () const
173     {
174         return m_euid != UINT32_MAX;
175     }
176
177     bool
178     EffectiveGroupIDIsValid () const
179     {
180         return m_egid != UINT32_MAX;
181     }
182
183     void
184     SetEffectiveUserID (uint32_t uid)
185     {
186         m_euid = uid;
187     }
188     
189     void
190     SetEffectiveGroupID (uint32_t gid)
191     {
192         m_egid = gid;
193     }
194
195     lldb::pid_t
196     GetParentProcessID () const
197     {
198         return m_parent_pid;
199     }
200     
201     void
202     SetParentProcessID (lldb::pid_t pid)
203     {
204         m_parent_pid = pid;
205     }
206     
207     bool
208     ParentProcessIDIsValid() const
209     {
210         return m_parent_pid != LLDB_INVALID_PROCESS_ID;
211     }
212     
213     void
214     Dump (Stream &s, Platform *platform) const;
215
216     static void
217     DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose);
218
219     void
220     DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const;
221     
222 protected:
223     uint32_t m_euid;
224     uint32_t m_egid;    
225     lldb::pid_t m_parent_pid;
226 };
227
228 //----------------------------------------------------------------------
229 // ProcessAttachInfo
230 //
231 // Describes any information that is required to attach to a process.
232 //----------------------------------------------------------------------
233     
234 class ProcessAttachInfo : public ProcessInstanceInfo
235 {
236 public:
237     ProcessAttachInfo() :
238         ProcessInstanceInfo(),
239         m_listener_sp(),
240         m_hijack_listener_sp(),
241         m_plugin_name (),
242         m_resume_count (0),
243         m_wait_for_launch (false),
244         m_ignore_existing (true),
245         m_continue_once_attached (false),
246         m_detach_on_error (true)
247     {
248     }
249
250     ProcessAttachInfo (const ProcessLaunchInfo &launch_info) :
251         ProcessInstanceInfo(),
252         m_listener_sp(),
253         m_hijack_listener_sp(),
254         m_plugin_name (),
255         m_resume_count (0),
256         m_wait_for_launch (false),
257         m_ignore_existing (true),
258         m_continue_once_attached (false),
259         m_detach_on_error(true)
260     {
261         ProcessInfo::operator= (launch_info);
262         SetProcessPluginName (launch_info.GetProcessPluginName());
263         SetResumeCount (launch_info.GetResumeCount());
264         SetListener(launch_info.GetListener());
265         SetHijackListener(launch_info.GetHijackListener());
266         m_detach_on_error = launch_info.GetDetachOnError();
267     }
268     
269     bool
270     GetWaitForLaunch () const
271     {
272         return m_wait_for_launch;
273     }
274     
275     void
276     SetWaitForLaunch (bool b)
277     {
278         m_wait_for_launch = b;
279     }
280
281     bool
282     GetIgnoreExisting () const
283     {
284         return m_ignore_existing;
285     }
286     
287     void
288     SetIgnoreExisting (bool b)
289     {
290         m_ignore_existing = b;
291     }
292
293     bool
294     GetContinueOnceAttached () const
295     {
296         return m_continue_once_attached;
297     }
298     
299     void
300     SetContinueOnceAttached (bool b)
301     {
302         m_continue_once_attached = b;
303     }
304
305     uint32_t
306     GetResumeCount () const
307     {
308         return m_resume_count;
309     }
310     
311     void
312     SetResumeCount (uint32_t c)
313     {
314         m_resume_count = c;
315     }
316     
317     const char *
318     GetProcessPluginName () const
319     {
320         if (m_plugin_name.empty())
321             return NULL;
322         return m_plugin_name.c_str();
323     }
324     
325     void
326     SetProcessPluginName (const char *plugin)
327     {
328         if (plugin && plugin[0])
329             m_plugin_name.assign (plugin);
330         else
331             m_plugin_name.clear();
332     }
333
334     void
335     Clear ()
336     {
337         ProcessInstanceInfo::Clear();
338         m_plugin_name.clear();
339         m_resume_count = 0;
340         m_wait_for_launch = false;
341         m_ignore_existing = true;
342         m_continue_once_attached = false;
343     }
344
345     bool
346     ProcessInfoSpecified () const
347     {
348         if (GetExecutableFile())
349             return true;
350         if (GetProcessID() != LLDB_INVALID_PROCESS_ID)
351             return true;
352         if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID)
353             return true;
354         return false;
355     }
356     
357     lldb::ListenerSP
358     GetHijackListener () const
359     {
360         return m_hijack_listener_sp;
361     }
362     
363     void
364     SetHijackListener (const lldb::ListenerSP &listener_sp)
365     {
366         m_hijack_listener_sp = listener_sp;
367     }
368     
369     bool
370     GetDetachOnError () const
371     {
372         return m_detach_on_error;
373     }
374     
375     void
376     SetDetachOnError (bool enable)
377     {
378         m_detach_on_error = enable;
379     }
380
381     // Get and set the actual listener that will be used for the process events
382     lldb::ListenerSP
383     GetListener () const
384     {
385         return m_listener_sp;
386     }
387
388     void
389     SetListener (const lldb::ListenerSP &listener_sp)
390     {
391         m_listener_sp = listener_sp;
392     }
393
394
395     Listener &
396     GetListenerForProcess (Debugger &debugger);
397
398 protected:
399     lldb::ListenerSP m_listener_sp;
400     lldb::ListenerSP m_hijack_listener_sp;
401     std::string m_plugin_name;
402     uint32_t m_resume_count; // How many times do we resume after launching
403     bool m_wait_for_launch;
404     bool m_ignore_existing;
405     bool m_continue_once_attached; // Supports the use-case scenario of immediately continuing the process once attached.
406     bool m_detach_on_error;  // If we are debugging remotely, instruct the stub to detach rather than killing the target on error.
407 };
408
409 class ProcessLaunchCommandOptions : public Options
410 {
411 public:
412     
413     ProcessLaunchCommandOptions (CommandInterpreter &interpreter) :
414         Options(interpreter)
415     {
416         // Keep default values of all options in one place: OptionParsingStarting ()
417         OptionParsingStarting ();
418     }
419     
420     ~ProcessLaunchCommandOptions ()
421     {
422     }
423     
424     Error
425     SetOptionValue (uint32_t option_idx, const char *option_arg);
426     
427     void
428     OptionParsingStarting ()
429     {
430         launch_info.Clear();
431         disable_aslr = eLazyBoolCalculate;
432     }
433     
434     const OptionDefinition*
435     GetDefinitions ()
436     {
437         return g_option_table;
438     }
439     
440     // Options table: Required for subclasses of Options.
441     
442     static OptionDefinition g_option_table[];
443     
444     // Instance variables to hold the values for command options.
445     
446     ProcessLaunchInfo launch_info;
447     lldb_private::LazyBool disable_aslr;
448 };
449
450 //----------------------------------------------------------------------
451 // ProcessInstanceInfoMatch
452 //
453 // A class to help matching one ProcessInstanceInfo to another.
454 //----------------------------------------------------------------------
455
456 class ProcessInstanceInfoMatch
457 {
458 public:
459     ProcessInstanceInfoMatch () :
460         m_match_info (),
461         m_name_match_type (eNameMatchIgnore),
462         m_match_all_users (false)
463     {
464     }
465
466     ProcessInstanceInfoMatch (const char *process_name, 
467                               NameMatchType process_name_match_type) :
468         m_match_info (),
469         m_name_match_type (process_name_match_type),
470         m_match_all_users (false)
471     {
472         m_match_info.GetExecutableFile().SetFile(process_name, false);
473     }
474
475     ProcessInstanceInfo &
476     GetProcessInfo ()
477     {
478         return m_match_info;
479     }
480
481     const ProcessInstanceInfo &
482     GetProcessInfo () const
483     {
484         return m_match_info;
485     }
486     
487     bool
488     GetMatchAllUsers () const
489     {
490         return m_match_all_users;
491     }
492
493     void
494     SetMatchAllUsers (bool b)
495     {
496         m_match_all_users = b;
497     }
498
499     NameMatchType
500     GetNameMatchType () const
501     {
502         return m_name_match_type;
503     }
504
505     void
506     SetNameMatchType (NameMatchType name_match_type)
507     {
508         m_name_match_type = name_match_type;
509     }
510     
511     bool
512     NameMatches (const char *process_name) const;
513
514     bool
515     Matches (const ProcessInstanceInfo &proc_info) const;
516
517     bool
518     MatchAllProcesses () const;
519     void
520     Clear ();
521
522 protected:
523     ProcessInstanceInfo m_match_info;
524     NameMatchType m_name_match_type;
525     bool m_match_all_users;
526 };
527
528 class ProcessInstanceInfoList
529 {
530 public:
531     ProcessInstanceInfoList () :
532         m_infos()
533     {
534     }
535     
536     void
537     Clear()
538     {
539         m_infos.clear();
540     }
541     
542     size_t
543     GetSize()
544     {
545         return m_infos.size();
546     }
547     
548     void
549     Append (const ProcessInstanceInfo &info)
550     {
551         m_infos.push_back (info);
552     }
553
554     const char *
555     GetProcessNameAtIndex (size_t idx)
556     {
557         if (idx < m_infos.size())
558             return m_infos[idx].GetName();
559         return NULL;
560     }
561
562     size_t
563     GetProcessNameLengthAtIndex (size_t idx)
564     {
565         if (idx < m_infos.size())
566             return m_infos[idx].GetNameLength();
567         return 0;
568     }
569
570     lldb::pid_t
571     GetProcessIDAtIndex (size_t idx)
572     {
573         if (idx < m_infos.size())
574             return m_infos[idx].GetProcessID();
575         return 0;
576     }
577
578     bool
579     GetInfoAtIndex (size_t idx, ProcessInstanceInfo &info)
580     {
581         if (idx < m_infos.size())
582         {
583             info = m_infos[idx];
584             return true;
585         }
586         return false;
587     }
588     
589     // You must ensure "idx" is valid before calling this function
590     const ProcessInstanceInfo &
591     GetProcessInfoAtIndex (size_t idx) const
592     {
593         assert (idx < m_infos.size());
594         return m_infos[idx];
595     }
596     
597 protected:
598     typedef std::vector<ProcessInstanceInfo> collection;
599     collection m_infos;
600 };
601
602
603 // This class tracks the Modification state of the process.  Things that can currently modify
604 // the program are running the program (which will up the StopID) and writing memory (which
605 // will up the MemoryID.)  
606 // FIXME: Should we also include modification of register states?
607
608 class ProcessModID
609 {
610 friend bool operator== (const ProcessModID &lhs, const ProcessModID &rhs);   
611 public:
612     ProcessModID () : 
613         m_stop_id (0),
614         m_last_natural_stop_id(0),
615         m_resume_id (0), 
616         m_memory_id (0),
617         m_last_user_expression_resume (0),
618         m_running_user_expression (false)
619     {}
620     
621     ProcessModID (const ProcessModID &rhs) :
622         m_stop_id (rhs.m_stop_id),
623         m_memory_id (rhs.m_memory_id)
624     {}
625     
626     const ProcessModID & operator= (const ProcessModID &rhs)
627     {
628         if (this != &rhs)
629         {
630             m_stop_id = rhs.m_stop_id;
631             m_memory_id = rhs.m_memory_id;
632         }
633         return *this;
634     }
635     
636     ~ProcessModID () {}
637     
638     void BumpStopID () { 
639         m_stop_id++;
640         if (!IsLastResumeForUserExpression())
641             m_last_natural_stop_id++;
642     }
643     
644     void BumpMemoryID () { m_memory_id++; }
645     
646     void BumpResumeID () {
647         m_resume_id++;
648         if (m_running_user_expression > 0)
649             m_last_user_expression_resume = m_resume_id;
650     }
651     
652     uint32_t GetStopID() const { return m_stop_id; }
653     uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; }
654     uint32_t GetMemoryID () const { return m_memory_id; }
655     uint32_t GetResumeID () const { return m_resume_id; }
656     uint32_t GetLastUserExpressionResumeID () const { return m_last_user_expression_resume; }
657     
658     bool MemoryIDEqual (const ProcessModID &compare) const
659     {
660         return m_memory_id == compare.m_memory_id;
661     }
662     
663     bool StopIDEqual (const ProcessModID &compare) const
664     {
665         return m_stop_id == compare.m_stop_id;
666     }
667     
668     void SetInvalid ()
669     {
670         m_stop_id = UINT32_MAX;
671     }
672     
673     bool IsValid () const
674     {
675         return m_stop_id != UINT32_MAX;
676     }
677     
678     bool
679     IsLastResumeForUserExpression () const
680     {
681         return m_resume_id == m_last_user_expression_resume;
682     }
683     
684     void
685     SetRunningUserExpression (bool on)
686     {
687         // REMOVEME printf ("Setting running user expression %s at resume id %d - value: %d.\n", on ? "on" : "off", m_resume_id, m_running_user_expression);
688         if (on)
689             m_running_user_expression++;
690         else
691             m_running_user_expression--;
692     }
693     
694 private:
695     uint32_t m_stop_id;
696     uint32_t m_last_natural_stop_id;
697     uint32_t m_resume_id;
698     uint32_t m_memory_id;
699     uint32_t m_last_user_expression_resume;
700     uint32_t m_running_user_expression;
701 };
702 inline bool operator== (const ProcessModID &lhs, const ProcessModID &rhs)
703 {
704     if (lhs.StopIDEqual (rhs)
705         && lhs.MemoryIDEqual (rhs))
706         return true;
707     else
708         return false;
709 }
710
711 inline bool operator!= (const ProcessModID &lhs, const ProcessModID &rhs)
712 {
713     if (!lhs.StopIDEqual (rhs)
714         || !lhs.MemoryIDEqual (rhs))
715         return true;
716     else
717         return false;
718 }
719     
720 //----------------------------------------------------------------------
721 /// @class Process Process.h "lldb/Target/Process.h"
722 /// @brief A plug-in interface definition class for debugging a process.
723 //----------------------------------------------------------------------
724 class Process :
725     public std::enable_shared_from_this<Process>,
726     public ProcessProperties,
727     public UserID,
728     public Broadcaster,
729     public ExecutionContextScope,
730     public PluginInterface
731 {
732     friend class ClangFunction;     // For WaitForStateChangeEventsPrivate
733     friend class Debugger;          // For PopProcessIOHandler and ProcessIOHandlerIsActive
734     friend class ProcessEventData;
735     friend class StopInfo;
736     friend class Target;
737     friend class ThreadList;
738
739 public:
740
741     //------------------------------------------------------------------
742     /// Broadcaster event bits definitions.
743     //------------------------------------------------------------------
744     enum
745     {
746         eBroadcastBitStateChanged   = (1 << 0),
747         eBroadcastBitInterrupt      = (1 << 1),
748         eBroadcastBitSTDOUT         = (1 << 2),
749         eBroadcastBitSTDERR         = (1 << 3),
750         eBroadcastBitProfileData    = (1 << 4)
751     };
752
753     enum
754     {
755         eBroadcastInternalStateControlStop = (1<<0),
756         eBroadcastInternalStateControlPause = (1<<1),
757         eBroadcastInternalStateControlResume = (1<<2)
758     };
759     
760     typedef Range<lldb::addr_t, lldb::addr_t> LoadRange;
761     // We use a read/write lock to allow on or more clients to
762     // access the process state while the process is stopped (reader).
763     // We lock the write lock to control access to the process
764     // while it is running (readers, or clients that want the process
765     // stopped can block waiting for the process to stop, or just
766     // try to lock it to see if they can immediately access the stopped
767     // process. If the try read lock fails, then the process is running.
768     typedef ProcessRunLock::ProcessRunLocker StopLocker;
769
770     // These two functions fill out the Broadcaster interface:
771     
772     static ConstString &GetStaticBroadcasterClass ();
773
774     virtual ConstString &GetBroadcasterClass() const
775     {
776         return GetStaticBroadcasterClass();
777     }
778
779     
780     //------------------------------------------------------------------
781     /// A notification structure that can be used by clients to listen
782     /// for changes in a process's lifetime.
783     ///
784     /// @see RegisterNotificationCallbacks (const Notifications&)
785     /// @see UnregisterNotificationCallbacks (const Notifications&)
786     //------------------------------------------------------------------
787 #ifndef SWIG
788     typedef struct
789     {
790         void *baton;
791         void (*initialize)(void *baton, Process *process);
792         void (*process_state_changed) (void *baton, Process *process, lldb::StateType state);
793     } Notifications;
794
795     class ProcessEventData :
796         public EventData
797     {
798         friend class Process;
799         
800         public:
801             ProcessEventData ();
802             ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state);
803
804             virtual ~ProcessEventData();
805
806             static const ConstString &
807             GetFlavorString ();
808
809             virtual const ConstString &
810             GetFlavor () const;
811
812             const lldb::ProcessSP &
813             GetProcessSP() const
814             {
815                 return m_process_sp;
816             }
817             lldb::StateType
818             GetState() const
819             {
820                 return m_state;
821             }
822             bool
823             GetRestarted () const
824             {
825                 return m_restarted;
826             }
827         
828             size_t
829             GetNumRestartedReasons ()
830             {
831                 return m_restarted_reasons.size();
832             }
833         
834             const char *
835             GetRestartedReasonAtIndex(size_t idx)
836             {
837                 if (idx > m_restarted_reasons.size())
838                     return NULL;
839                 else
840                     return m_restarted_reasons[idx].c_str();
841             }
842         
843             bool
844             GetInterrupted () const
845             {
846                 return m_interrupted;
847             }
848
849             virtual void
850             Dump (Stream *s) const;
851
852             virtual void
853             DoOnRemoval (Event *event_ptr);
854
855             static const Process::ProcessEventData *
856             GetEventDataFromEvent (const Event *event_ptr);
857
858             static lldb::ProcessSP
859             GetProcessFromEvent (const Event *event_ptr);
860
861             static lldb::StateType
862             GetStateFromEvent (const Event *event_ptr);
863
864             static bool
865             GetRestartedFromEvent (const Event *event_ptr);
866         
867             static size_t
868             GetNumRestartedReasons(const Event *event_ptr);
869         
870             static const char *
871             GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx);
872         
873             static void
874             AddRestartedReason (Event *event_ptr, const char *reason);
875
876             static void
877             SetRestartedInEvent (Event *event_ptr, bool new_value);
878
879             static bool
880             GetInterruptedFromEvent (const Event *event_ptr);
881
882             static void
883             SetInterruptedInEvent (Event *event_ptr, bool new_value);
884
885             static bool
886             SetUpdateStateOnRemoval (Event *event_ptr);
887
888        private:
889
890             void
891             SetUpdateStateOnRemoval()
892             {
893                 m_update_state++;
894             }
895             void
896             SetRestarted (bool new_value)
897             {
898                 m_restarted = new_value;
899             }
900             void
901             SetInterrupted (bool new_value)
902             {
903                 m_interrupted = new_value;
904             }
905             void
906             AddRestartedReason (const char *reason)
907             {
908                 m_restarted_reasons.push_back(reason);
909             }
910
911             lldb::ProcessSP m_process_sp;
912             lldb::StateType m_state;
913             std::vector<std::string> m_restarted_reasons;
914             bool m_restarted;  // For "eStateStopped" events, this is true if the target was automatically restarted.
915             int m_update_state;
916             bool m_interrupted;
917             DISALLOW_COPY_AND_ASSIGN (ProcessEventData);
918
919     };
920
921 #endif
922
923     static void
924     SettingsInitialize ();
925
926     static void
927     SettingsTerminate ();
928     
929     static const ProcessPropertiesSP &
930     GetGlobalProperties();
931
932     //------------------------------------------------------------------
933     /// Construct with a shared pointer to a target, and the Process listener.
934     /// Uses the Host UnixSignalsSP by default.
935     //------------------------------------------------------------------
936     Process(Target &target, Listener &listener);
937
938     //------------------------------------------------------------------
939     /// Construct with a shared pointer to a target, the Process listener,
940     /// and the appropriate UnixSignalsSP for the process.
941     //------------------------------------------------------------------
942     Process(Target &target, Listener &listener, const UnixSignalsSP &unix_signals_sp);
943
944     //------------------------------------------------------------------
945     /// Destructor.
946     ///
947     /// The destructor is virtual since this class is designed to be
948     /// inherited from by the plug-in instance.
949     //------------------------------------------------------------------
950     virtual
951     ~Process();
952
953     //------------------------------------------------------------------
954     /// Find a Process plug-in that can debug \a module using the
955     /// currently selected architecture.
956     ///
957     /// Scans all loaded plug-in interfaces that implement versions of
958     /// the Process plug-in interface and returns the first instance
959     /// that can debug the file.
960     ///
961     /// @param[in] module_sp
962     ///     The module shared pointer that this process will debug.
963     ///
964     /// @param[in] plugin_name
965     ///     If NULL, select the best plug-in for the binary. If non-NULL
966     ///     then look for a plugin whose PluginInfo's name matches
967     ///     this string.
968     ///
969     /// @see Process::CanDebug ()
970     //------------------------------------------------------------------
971     static lldb::ProcessSP
972     FindPlugin (Target &target, 
973                 const char *plugin_name, 
974                 Listener &listener, 
975                 const FileSpec *crash_file_path);
976
977
978
979     //------------------------------------------------------------------
980     /// Static function that can be used with the \b host function
981     /// Host::StartMonitoringChildProcess ().
982     ///
983     /// This function can be used by lldb_private::Process subclasses
984     /// when they want to watch for a local process and have its exit
985     /// status automatically set when the host child process exits.
986     /// Subclasses should call Host::StartMonitoringChildProcess ()
987     /// with:
988     ///     callback = Process::SetHostProcessExitStatus
989     ///     callback_baton = NULL
990     ///     pid = Process::GetID()
991     ///     monitor_signals = false
992     //------------------------------------------------------------------
993     static bool
994     SetProcessExitStatus (void *callback_baton,   // The callback baton which should be set to NULL
995                           lldb::pid_t pid,        // The process ID we want to monitor
996                           bool exited,
997                           int signo,              // Zero for no signal
998                           int status);            // Exit value of process if signal is zero
999
1000     lldb::ByteOrder
1001     GetByteOrder () const;
1002     
1003     uint32_t
1004     GetAddressByteSize () const;
1005
1006     uint32_t
1007     GetUniqueID() const
1008     {
1009         return m_process_unique_id;
1010     }
1011     //------------------------------------------------------------------
1012     /// Check if a plug-in instance can debug the file in \a module.
1013     ///
1014     /// Each plug-in is given a chance to say whether it can debug
1015     /// the file in \a module. If the Process plug-in instance can
1016     /// debug a file on the current system, it should return \b true.
1017     ///
1018     /// @return
1019     ///     Returns \b true if this Process plug-in instance can
1020     ///     debug the executable, \b false otherwise.
1021     //------------------------------------------------------------------
1022     virtual bool
1023     CanDebug (Target &target,
1024               bool plugin_specified_by_name) = 0;
1025
1026
1027     //------------------------------------------------------------------
1028     /// This object is about to be destroyed, do any necessary cleanup.
1029     ///
1030     /// Subclasses that override this method should always call this
1031     /// superclass method.
1032     //------------------------------------------------------------------
1033     virtual void
1034     Finalize();
1035     
1036     
1037     //------------------------------------------------------------------
1038     /// Return whether this object is valid (i.e. has not been finalized.)
1039     ///
1040     /// @return
1041     ///     Returns \b true if this Process has not been finalized
1042     ///     and \b false otherwise.
1043     //------------------------------------------------------------------
1044     bool
1045     IsValid() const
1046     {
1047         return !m_finalize_called;
1048     }
1049
1050     //------------------------------------------------------------------
1051     /// Return a multi-word command object that can be used to expose
1052     /// plug-in specific commands.
1053     ///
1054     /// This object will be used to resolve plug-in commands and can be
1055     /// triggered by a call to:
1056     ///
1057     ///     (lldb) process commmand <args>
1058     ///
1059     /// @return
1060     ///     A CommandObject which can be one of the concrete subclasses
1061     ///     of CommandObject like CommandObjectRaw, CommandObjectParsed,
1062     ///     or CommandObjectMultiword.
1063     //------------------------------------------------------------------
1064     virtual CommandObject *
1065     GetPluginCommandObject()
1066     {
1067         return NULL;
1068     }
1069
1070     //------------------------------------------------------------------
1071     /// Launch a new process.
1072     ///
1073     /// Launch a new process by spawning a new process using the
1074     /// target object's executable module's file as the file to launch.
1075     ///
1076     /// This function is not meant to be overridden by Process
1077     /// subclasses. It will first call Process::WillLaunch (Module *)
1078     /// and if that returns \b true, Process::DoLaunch (Module*,
1079     /// char const *[],char const *[],const char *,const char *,
1080     /// const char *) will be called to actually do the launching. If
1081     /// DoLaunch returns \b true, then Process::DidLaunch() will be
1082     /// called.
1083     ///
1084     /// @param[in] launch_info
1085     ///     Details regarding the environment, STDIN/STDOUT/STDERR
1086     ///     redirection, working path, etc. related to the requested launch.
1087     ///
1088     /// @return
1089     ///     An error object. Call GetID() to get the process ID if
1090     ///     the error object is success.
1091     //------------------------------------------------------------------
1092     virtual Error
1093     Launch (ProcessLaunchInfo &launch_info);
1094
1095     virtual Error
1096     LoadCore ();
1097
1098     virtual Error
1099     DoLoadCore ()
1100     {
1101         Error error;
1102         error.SetErrorStringWithFormat("error: %s does not support loading core files.", GetPluginName().GetCString());
1103         return error;
1104     }
1105
1106     //------------------------------------------------------------------
1107     /// Get the dynamic loader plug-in for this process. 
1108     ///
1109     /// The default action is to let the DynamicLoader plug-ins check
1110     /// the main executable and the DynamicLoader will select itself
1111     /// automatically. Subclasses can override this if inspecting the
1112     /// executable is not desired, or if Process subclasses can only
1113     /// use a specific DynamicLoader plug-in.
1114     //------------------------------------------------------------------
1115     virtual DynamicLoader *
1116     GetDynamicLoader ();
1117
1118     //------------------------------------------------------------------
1119     // Returns AUXV structure found in many ELF-based environments.
1120     //
1121     // The default action is to return an empty data buffer.
1122     //
1123     // @return
1124     //    A data buffer containing the contents of the AUXV data.
1125     //------------------------------------------------------------------
1126     virtual const lldb::DataBufferSP
1127     GetAuxvData();
1128
1129 protected:
1130     virtual JITLoaderList &
1131     GetJITLoaders ();
1132
1133 public:
1134     //------------------------------------------------------------------
1135     /// Get the system runtime plug-in for this process. 
1136     ///
1137     /// @return
1138     ///   Returns a pointer to the SystemRuntime plugin for this Process
1139     ///   if one is available.  Else returns NULL.
1140     //------------------------------------------------------------------
1141     virtual SystemRuntime *
1142     GetSystemRuntime ();
1143
1144     //------------------------------------------------------------------
1145     /// Attach to an existing process using the process attach info.
1146     ///
1147     /// This function is not meant to be overridden by Process
1148     /// subclasses. It will first call WillAttach (lldb::pid_t)
1149     /// or WillAttach (const char *), and if that returns \b 
1150     /// true, DoAttach (lldb::pid_t) or DoAttach (const char *) will
1151     /// be called to actually do the attach. If DoAttach returns \b
1152     /// true, then Process::DidAttach() will be called.
1153     ///
1154     /// @param[in] pid
1155     ///     The process ID that we should attempt to attach to.
1156     ///
1157     /// @return
1158     ///     Returns \a pid if attaching was successful, or
1159     ///     LLDB_INVALID_PROCESS_ID if attaching fails.
1160     //------------------------------------------------------------------
1161     virtual Error
1162     Attach (ProcessAttachInfo &attach_info);
1163
1164     //------------------------------------------------------------------
1165     /// Attach to a remote system via a URL
1166     ///
1167     /// @param[in] strm
1168     ///     A stream where output intended for the user
1169     ///     (if the driver has a way to display that) generated during
1170     ///     the connection.  This may be NULL if no output is needed.A
1171     ///
1172     /// @param[in] remote_url
1173     ///     The URL format that we are connecting to.
1174     ///
1175     /// @return
1176     ///     Returns an error object.
1177     //------------------------------------------------------------------
1178     virtual Error
1179     ConnectRemote (Stream *strm, const char *remote_url);
1180
1181     bool
1182     GetShouldDetach () const
1183     {
1184         return m_should_detach;
1185     }
1186
1187     void
1188     SetShouldDetach (bool b)
1189     {
1190         m_should_detach = b;
1191     }
1192
1193     //------------------------------------------------------------------
1194     /// Get the image information address for the current process.
1195     ///
1196     /// Some runtimes have system functions that can help dynamic
1197     /// loaders locate the dynamic loader information needed to observe
1198     /// shared libraries being loaded or unloaded. This function is
1199     /// in the Process interface (as opposed to the DynamicLoader
1200     /// interface) to ensure that remote debugging can take advantage of
1201     /// this functionality.
1202     ///
1203     /// @return
1204     ///     The address of the dynamic loader information, or
1205     ///     LLDB_INVALID_ADDRESS if this is not supported by this
1206     ///     interface.
1207     //------------------------------------------------------------------
1208     virtual lldb::addr_t
1209     GetImageInfoAddress ();
1210
1211     //------------------------------------------------------------------
1212     /// Load a shared library into this process.
1213     ///
1214     /// Try and load a shared library into the current process. This
1215     /// call might fail in the dynamic loader plug-in says it isn't safe
1216     /// to try and load shared libraries at the moment.
1217     ///
1218     /// @param[in] image_spec
1219     ///     The image file spec that points to the shared library that
1220     ///     you want to load.
1221     ///
1222     /// @param[out] error
1223     ///     An error object that gets filled in with any errors that
1224     ///     might occur when trying to load the shared library.
1225     ///
1226     /// @return
1227     ///     A token that represents the shared library that can be
1228     ///     later used to unload the shared library. A value of
1229     ///     LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
1230     ///     library can't be opened.
1231     //------------------------------------------------------------------
1232     virtual uint32_t
1233     LoadImage (const FileSpec &image_spec, Error &error);
1234
1235     virtual Error
1236     UnloadImage (uint32_t image_token);
1237
1238     //------------------------------------------------------------------
1239     /// Register for process and thread notifications.
1240     ///
1241     /// Clients can register notification callbacks by filling out a
1242     /// Process::Notifications structure and calling this function.
1243     ///
1244     /// @param[in] callbacks
1245     ///     A structure that contains the notification baton and
1246     ///     callback functions.
1247     ///
1248     /// @see Process::Notifications
1249     //------------------------------------------------------------------
1250 #ifndef SWIG
1251     void
1252     RegisterNotificationCallbacks (const Process::Notifications& callbacks);
1253 #endif
1254     //------------------------------------------------------------------
1255     /// Unregister for process and thread notifications.
1256     ///
1257     /// Clients can unregister notification callbacks by passing a copy of
1258     /// the original baton and callbacks in \a callbacks.
1259     ///
1260     /// @param[in] callbacks
1261     ///     A structure that contains the notification baton and
1262     ///     callback functions.
1263     ///
1264     /// @return
1265     ///     Returns \b true if the notification callbacks were
1266     ///     successfully removed from the process, \b false otherwise.
1267     ///
1268     /// @see Process::Notifications
1269     //------------------------------------------------------------------
1270 #ifndef SWIG
1271     bool
1272     UnregisterNotificationCallbacks (const Process::Notifications& callbacks);
1273 #endif
1274     //==================================================================
1275     // Built in Process Control functions
1276     //==================================================================
1277     //------------------------------------------------------------------
1278     /// Resumes all of a process's threads as configured using the
1279     /// Thread run control functions.
1280     ///
1281     /// Threads for a process should be updated with one of the run
1282     /// control actions (resume, step, or suspend) that they should take
1283     /// when the process is resumed. If no run control action is given
1284     /// to a thread it will be resumed by default.
1285     ///
1286     /// This function is not meant to be overridden by Process
1287     /// subclasses. This function will take care of disabling any
1288     /// breakpoints that threads may be stopped at, single stepping, and
1289     /// re-enabling breakpoints, and enabling the basic flow control
1290     /// that the plug-in instances need not worry about.
1291     ///
1292     /// N.B. This function also sets the Write side of the Run Lock,
1293     /// which is unset when the corresponding stop event is pulled off
1294     /// the Public Event Queue.  If you need to resume the process without
1295     /// setting the Run Lock, use PrivateResume (though you should only do
1296     /// that from inside the Process class.
1297     ///
1298     /// @return
1299     ///     Returns an error object.
1300     ///
1301     /// @see Thread:Resume()
1302     /// @see Thread:Step()
1303     /// @see Thread:Suspend()
1304     //------------------------------------------------------------------
1305     Error
1306     Resume();
1307
1308     Error
1309     ResumeSynchronous (Stream *stream);
1310     //------------------------------------------------------------------
1311     /// Halts a running process.
1312     ///
1313     /// This function is not meant to be overridden by Process
1314     /// subclasses.
1315     /// If the process is successfully halted, a eStateStopped
1316     /// process event with GetInterrupted will be broadcast.  If false, we will
1317     /// halt the process with no events generated by the halt.
1318     ///
1319     /// @param[in] clear_thread_plans
1320     ///     If true, when the process stops, clear all thread plans.
1321     ///
1322     /// @return
1323     ///     Returns an error object.  If the error is empty, the process is halted.
1324     ///     otherwise the halt has failed.
1325     //------------------------------------------------------------------
1326     Error
1327     Halt (bool clear_thread_plans = false);
1328
1329     //------------------------------------------------------------------
1330     /// Detaches from a running or stopped process.
1331     ///
1332     /// This function is not meant to be overridden by Process
1333     /// subclasses.
1334     ///
1335     /// @param[in] keep_stopped
1336     ///     If true, don't resume the process on detach.
1337     ///
1338     /// @return
1339     ///     Returns an error object.
1340     //------------------------------------------------------------------
1341     Error
1342     Detach (bool keep_stopped);
1343
1344     //------------------------------------------------------------------
1345     /// Kills the process and shuts down all threads that were spawned
1346     /// to track and monitor the process.
1347     ///
1348     /// This function is not meant to be overridden by Process
1349     /// subclasses.
1350     ///
1351     /// @return
1352     ///     Returns an error object.
1353     //------------------------------------------------------------------
1354     Error
1355     Destroy();
1356
1357     //------------------------------------------------------------------
1358     /// Sends a process a UNIX signal \a signal.
1359     ///
1360     /// This function is not meant to be overridden by Process
1361     /// subclasses.
1362     ///
1363     /// @return
1364     ///     Returns an error object.
1365     //------------------------------------------------------------------
1366     Error
1367     Signal (int signal);
1368
1369     void
1370     SetUnixSignals (const UnixSignalsSP &signals_sp)
1371     {
1372         assert (signals_sp && "null signals_sp");
1373         m_unix_signals_sp = signals_sp;
1374     }
1375
1376     UnixSignals &
1377     GetUnixSignals ()
1378     {
1379         assert (m_unix_signals_sp && "null m_unix_signals_sp");
1380         return *m_unix_signals_sp;
1381     }
1382
1383     //==================================================================
1384     // Plug-in Process Control Overrides
1385     //==================================================================
1386
1387     //------------------------------------------------------------------
1388     /// Called before attaching to a process.
1389     ///
1390     /// Allow Process plug-ins to execute some code before attaching a
1391     /// process.
1392     ///
1393     /// @return
1394     ///     Returns an error object.
1395     //------------------------------------------------------------------
1396     virtual Error
1397     WillAttachToProcessWithID (lldb::pid_t pid) 
1398     {
1399         return Error(); 
1400     }
1401
1402     //------------------------------------------------------------------
1403     /// Called before attaching to a process.
1404     ///
1405     /// Allow Process plug-ins to execute some code before attaching a
1406     /// process.
1407     ///
1408     /// @return
1409     ///     Returns an error object.
1410     //------------------------------------------------------------------
1411     virtual Error
1412     WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) 
1413     { 
1414         return Error(); 
1415     }
1416
1417     //------------------------------------------------------------------
1418     /// Attach to a remote system via a URL
1419     ///
1420     /// @param[in] strm
1421     ///     A stream where output intended for the user 
1422     ///     (if the driver has a way to display that) generated during
1423     ///     the connection.  This may be NULL if no output is needed.A
1424     ///
1425     /// @param[in] remote_url
1426     ///     The URL format that we are connecting to.
1427     ///
1428     /// @return
1429     ///     Returns an error object.
1430     //------------------------------------------------------------------
1431     virtual Error
1432     DoConnectRemote (Stream *strm, const char *remote_url)
1433     {
1434         Error error;
1435         error.SetErrorString ("remote connections are not supported");
1436         return error;
1437     }
1438
1439     //------------------------------------------------------------------
1440     /// Attach to an existing process using a process ID.
1441     ///
1442     /// @param[in] pid
1443     ///     The process ID that we should attempt to attach to.
1444     ///
1445     /// @return
1446     ///     Returns \a pid if attaching was successful, or
1447     ///     LLDB_INVALID_PROCESS_ID if attaching fails.
1448     //------------------------------------------------------------------
1449     virtual Error
1450     DoAttachToProcessWithID (lldb::pid_t pid)
1451     {
1452         Error error;
1453         error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString());
1454         return error;
1455     }
1456
1457     //------------------------------------------------------------------
1458     /// Attach to an existing process using a process ID.
1459     ///
1460     /// @param[in] pid
1461     ///     The process ID that we should attempt to attach to.
1462     ///
1463     /// @param[in] attach_info
1464     ///     Information on how to do the attach. For example, GetUserID()
1465     ///     will return the uid to attach as.
1466     ///
1467     /// @return
1468     ///     Returns \a pid if attaching was successful, or
1469     ///     LLDB_INVALID_PROCESS_ID if attaching fails.
1470     /// hanming : need flag
1471     //------------------------------------------------------------------
1472     virtual Error
1473     DoAttachToProcessWithID (lldb::pid_t pid,  const ProcessAttachInfo &attach_info)
1474     {
1475         Error error;
1476         error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString());
1477         return error;
1478     }
1479
1480     //------------------------------------------------------------------
1481     /// Attach to an existing process using a partial process name.
1482     ///
1483     /// @param[in] process_name
1484     ///     The name of the process to attach to.
1485     ///
1486     /// @param[in] attach_info
1487     ///     Information on how to do the attach. For example, GetUserID()
1488     ///     will return the uid to attach as.
1489     ///
1490     /// @return
1491     ///     Returns an error object.
1492     //------------------------------------------------------------------
1493     virtual Error
1494     DoAttachToProcessWithName (const char *process_name, const ProcessAttachInfo &attach_info)
1495     {
1496         Error error;
1497         error.SetErrorString("attach by name is not supported");
1498         return error;
1499     }
1500
1501     //------------------------------------------------------------------
1502     /// Called after attaching a process.
1503     ///
1504     /// @param[in] process_arch
1505     ///     If you can figure out the process architecture after attach, fill it in here.
1506     ///
1507     /// Allow Process plug-ins to execute some code after attaching to
1508     /// a process.
1509     //------------------------------------------------------------------
1510     virtual void
1511     DidAttach (ArchSpec &process_arch)
1512     {
1513         process_arch.Clear();
1514     }
1515
1516
1517     //------------------------------------------------------------------
1518     /// Called after a process re-execs itself.
1519     ///
1520     /// Allow Process plug-ins to execute some code after a process has
1521     /// exec'ed itself. Subclasses typically should override DoDidExec()
1522     /// as the lldb_private::Process class needs to remove its dynamic
1523     /// loader, runtime, ABI and other plug-ins, as well as unload all
1524     /// shared libraries.
1525     //------------------------------------------------------------------
1526     virtual void
1527     DidExec ();
1528
1529     //------------------------------------------------------------------
1530     /// Subclasses of Process should implement this function if they
1531     /// need to do anything after a process exec's itself.
1532     //------------------------------------------------------------------
1533     virtual void
1534     DoDidExec ()
1535     {
1536     }
1537
1538     //------------------------------------------------------------------
1539     /// Called before launching to a process.
1540     ///
1541     /// Allow Process plug-ins to execute some code before launching a
1542     /// process.
1543     ///
1544     /// @return
1545     ///     Returns an error object.
1546     //------------------------------------------------------------------
1547     virtual Error
1548     WillLaunch (Module* module)
1549     {
1550         return Error();
1551     }
1552
1553     //------------------------------------------------------------------
1554     /// Launch a new process.
1555     ///
1556     /// Launch a new process by spawning a new process using
1557     /// \a exe_module's file as the file to launch. Launch details are
1558     /// provided in \a launch_info.
1559     ///
1560     /// @param[in] exe_module
1561     ///     The module from which to extract the file specification and
1562     ///     launch.
1563     ///
1564     /// @param[in] launch_info
1565     ///     Details (e.g. arguments, stdio redirection, etc.) for the
1566     ///     requested launch.
1567     ///
1568     /// @return
1569     ///     An Error instance indicating success or failure of the
1570     ///     operation.
1571     //------------------------------------------------------------------
1572     virtual Error
1573     DoLaunch (Module *exe_module,
1574               ProcessLaunchInfo &launch_info)
1575     {
1576         Error error;
1577         error.SetErrorStringWithFormat("error: %s does not support launching processes", GetPluginName().GetCString());
1578         return error;
1579     }
1580
1581     
1582     //------------------------------------------------------------------
1583     /// Called after launching a process.
1584     ///
1585     /// Allow Process plug-ins to execute some code after launching
1586     /// a process.
1587     //------------------------------------------------------------------
1588     virtual void
1589     DidLaunch () {}
1590
1591
1592
1593     //------------------------------------------------------------------
1594     /// Called before resuming to a process.
1595     ///
1596     /// Allow Process plug-ins to execute some code before resuming a
1597     /// process.
1598     ///
1599     /// @return
1600     ///     Returns an error object.
1601     //------------------------------------------------------------------
1602     virtual Error
1603     WillResume () { return Error(); }
1604
1605     //------------------------------------------------------------------
1606     /// Resumes all of a process's threads as configured using the
1607     /// Thread run control functions.
1608     ///
1609     /// Threads for a process should be updated with one of the run
1610     /// control actions (resume, step, or suspend) that they should take
1611     /// when the process is resumed. If no run control action is given
1612     /// to a thread it will be resumed by default.
1613     ///
1614     /// @return
1615     ///     Returns \b true if the process successfully resumes using
1616     ///     the thread run control actions, \b false otherwise.
1617     ///
1618     /// @see Thread:Resume()
1619     /// @see Thread:Step()
1620     /// @see Thread:Suspend()
1621     //------------------------------------------------------------------
1622     virtual Error
1623     DoResume ()
1624     {
1625         Error error;
1626         error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetPluginName().GetCString());
1627         return error;
1628     }
1629
1630
1631     //------------------------------------------------------------------
1632     /// Called after resuming a process.
1633     ///
1634     /// Allow Process plug-ins to execute some code after resuming
1635     /// a process.
1636     //------------------------------------------------------------------
1637     virtual void
1638     DidResume () {}
1639
1640
1641     //------------------------------------------------------------------
1642     /// Called before halting to a process.
1643     ///
1644     /// Allow Process plug-ins to execute some code before halting a
1645     /// process.
1646     ///
1647     /// @return
1648     ///     Returns an error object.
1649     //------------------------------------------------------------------
1650     virtual Error
1651     WillHalt () { return Error(); }
1652
1653     //------------------------------------------------------------------
1654     /// Halts a running process.
1655     ///
1656     /// DoHalt must produce one and only one stop StateChanged event if it actually
1657     /// stops the process.  If the stop happens through some natural event (for
1658     /// instance a SIGSTOP), then forwarding that event will do.  Otherwise, you must 
1659     /// generate the event manually.  Note also, the private event thread is stopped when 
1660     /// DoHalt is run to prevent the events generated while halting to trigger
1661     /// other state changes before the halt is complete.
1662     ///
1663     /// @param[out] caused_stop
1664     ///     If true, then this Halt caused the stop, otherwise, the 
1665     ///     process was already stopped.
1666     ///
1667     /// @return
1668     ///     Returns \b true if the process successfully halts, \b false
1669     ///     otherwise.
1670     //------------------------------------------------------------------
1671     virtual Error
1672     DoHalt (bool &caused_stop)
1673     {
1674         Error error;
1675         error.SetErrorStringWithFormat("error: %s does not support halting processes", GetPluginName().GetCString());
1676         return error;
1677     }
1678
1679
1680     //------------------------------------------------------------------
1681     /// Called after halting a process.
1682     ///
1683     /// Allow Process plug-ins to execute some code after halting
1684     /// a process.
1685     //------------------------------------------------------------------
1686     virtual void
1687     DidHalt () {}
1688
1689     //------------------------------------------------------------------
1690     /// Called before detaching from a process.
1691     ///
1692     /// Allow Process plug-ins to execute some code before detaching
1693     /// from a process.
1694     ///
1695     /// @return
1696     ///     Returns an error object.
1697     //------------------------------------------------------------------
1698     virtual Error
1699     WillDetach () 
1700     {
1701         return Error(); 
1702     }
1703
1704     //------------------------------------------------------------------
1705     /// Detaches from a running or stopped process.
1706     ///
1707     /// @return
1708     ///     Returns \b true if the process successfully detaches, \b
1709     ///     false otherwise.
1710     //------------------------------------------------------------------
1711     virtual Error
1712     DoDetach (bool keep_stopped)
1713     {
1714         Error error;
1715         error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetPluginName().GetCString());
1716         return error;
1717     }
1718
1719
1720     //------------------------------------------------------------------
1721     /// Called after detaching from a process.
1722     ///
1723     /// Allow Process plug-ins to execute some code after detaching
1724     /// from a process.
1725     //------------------------------------------------------------------
1726     virtual void
1727     DidDetach () {}
1728     
1729     virtual bool
1730     DetachRequiresHalt() { return false; }
1731
1732     //------------------------------------------------------------------
1733     /// Called before sending a signal to a process.
1734     ///
1735     /// Allow Process plug-ins to execute some code before sending a
1736     /// signal to a process.
1737     ///
1738     /// @return
1739     ///     Returns no error if it is safe to proceed with a call to
1740     ///     Process::DoSignal(int), otherwise an error describing what
1741     ///     prevents the signal from being sent.
1742     //------------------------------------------------------------------
1743     virtual Error
1744     WillSignal () { return Error(); }
1745
1746     //------------------------------------------------------------------
1747     /// Sends a process a UNIX signal \a signal.
1748     ///
1749     /// @return
1750     ///     Returns an error object.
1751     //------------------------------------------------------------------
1752     virtual Error
1753     DoSignal (int signal)
1754     {
1755         Error error;
1756         error.SetErrorStringWithFormat("error: %s does not support sending signals to processes", GetPluginName().GetCString());
1757         return error;
1758     }
1759
1760     virtual Error
1761     WillDestroy () { return Error(); }
1762
1763     virtual Error
1764     DoDestroy () = 0;
1765
1766     virtual void
1767     DidDestroy () { }
1768     
1769     virtual bool
1770     DestroyRequiresHalt() { return true; }
1771
1772
1773     //------------------------------------------------------------------
1774     /// Called after sending a signal to a process.
1775     ///
1776     /// Allow Process plug-ins to execute some code after sending a
1777     /// signal to a process.
1778     //------------------------------------------------------------------
1779     virtual void
1780     DidSignal () {}
1781
1782     //------------------------------------------------------------------
1783     /// Currently called as part of ShouldStop.
1784     /// FIXME: Should really happen when the target stops before the
1785     /// event is taken from the queue...
1786     ///
1787     /// This callback is called as the event
1788     /// is about to be queued up to allow Process plug-ins to execute
1789     /// some code prior to clients being notified that a process was
1790     /// stopped. Common operations include updating the thread list,
1791     /// invalidating any thread state (registers, stack, etc) prior to
1792     /// letting the notification go out.
1793     ///
1794     //------------------------------------------------------------------
1795     virtual void
1796     RefreshStateAfterStop () = 0;
1797
1798     //------------------------------------------------------------------
1799     /// Get the target object pointer for this module.
1800     ///
1801     /// @return
1802     ///     A Target object pointer to the target that owns this
1803     ///     module.
1804     //------------------------------------------------------------------
1805     Target &
1806     GetTarget ()
1807     {
1808         return m_target;
1809     }
1810
1811     //------------------------------------------------------------------
1812     /// Get the const target object pointer for this module.
1813     ///
1814     /// @return
1815     ///     A const Target object pointer to the target that owns this
1816     ///     module.
1817     //------------------------------------------------------------------
1818     const Target &
1819     GetTarget () const
1820     {
1821         return m_target;
1822     }
1823
1824     //------------------------------------------------------------------
1825     /// Flush all data in the process.
1826     ///
1827     /// Flush the memory caches, all threads, and any other cached data
1828     /// in the process.
1829     ///
1830     /// This function can be called after a world changing event like
1831     /// adding a new symbol file, or after the process makes a large
1832     /// context switch (from boot ROM to booted into an OS).
1833     //------------------------------------------------------------------
1834     void
1835     Flush ();
1836
1837     //------------------------------------------------------------------
1838     /// Get accessor for the current process state.
1839     ///
1840     /// @return
1841     ///     The current state of the process.
1842     ///
1843     /// @see lldb::StateType
1844     //------------------------------------------------------------------
1845     lldb::StateType
1846     GetState ();
1847     
1848     lldb::ExpressionResults
1849     RunThreadPlan (ExecutionContext &exe_ctx,    
1850                     lldb::ThreadPlanSP &thread_plan_sp,
1851                     const EvaluateExpressionOptions &options,
1852                     Stream &errors);
1853
1854     static const char *
1855     ExecutionResultAsCString (lldb::ExpressionResults result);
1856
1857     void
1858     GetStatus (Stream &ostrm);
1859
1860     size_t
1861     GetThreadStatus (Stream &ostrm, 
1862                      bool only_threads_with_stop_reason,
1863                      uint32_t start_frame, 
1864                      uint32_t num_frames, 
1865                      uint32_t num_frames_with_source);
1866
1867     void
1868     SendAsyncInterrupt ();
1869     
1870     void
1871     ModulesDidLoad (ModuleList &module_list);
1872
1873 protected:
1874     
1875     void
1876     SetState (lldb::EventSP &event_sp);
1877
1878     lldb::StateType
1879     GetPrivateState ();
1880
1881     //------------------------------------------------------------------
1882     /// The "private" side of resuming a process.  This doesn't alter the
1883     /// state of m_run_lock, but just causes the process to resume.
1884     ///
1885     /// @return
1886     ///     An Error object describing the success or failure of the resume.
1887     //------------------------------------------------------------------
1888     Error
1889     PrivateResume ();
1890
1891     //------------------------------------------------------------------
1892     // Called internally
1893     //------------------------------------------------------------------
1894     void
1895     CompleteAttach ();
1896     
1897 public:
1898     //------------------------------------------------------------------
1899     /// Get the exit status for a process.
1900     ///
1901     /// @return
1902     ///     The process's return code, or -1 if the current process
1903     ///     state is not eStateExited.
1904     //------------------------------------------------------------------
1905     int
1906     GetExitStatus ();
1907
1908     //------------------------------------------------------------------
1909     /// Get a textual description of what the process exited.
1910     ///
1911     /// @return
1912     ///     The textual description of why the process exited, or NULL
1913     ///     if there is no description available.
1914     //------------------------------------------------------------------
1915     const char *
1916     GetExitDescription ();
1917
1918
1919     virtual void
1920     DidExit ()
1921     {
1922     }
1923
1924     //------------------------------------------------------------------
1925     /// Get the Modification ID of the process.
1926     ///
1927     /// @return
1928     ///     The modification ID of the process.
1929     //------------------------------------------------------------------
1930     ProcessModID
1931     GetModID () const
1932     {
1933         return m_mod_id;
1934     }
1935     
1936     const ProcessModID &
1937     GetModIDRef () const
1938     {
1939         return m_mod_id;
1940     }
1941     
1942     uint32_t
1943     GetStopID () const
1944     {
1945         return m_mod_id.GetStopID();
1946     }
1947     
1948     uint32_t
1949     GetResumeID () const
1950     {
1951         return m_mod_id.GetResumeID();
1952     }
1953     
1954     uint32_t
1955     GetLastUserExpressionResumeID () const
1956     {
1957         return m_mod_id.GetLastUserExpressionResumeID();
1958     }
1959     
1960     uint32_t
1961     GetLastNaturalStopID()
1962     {
1963         return m_mod_id.GetLastNaturalStopID();
1964     }
1965     
1966     //------------------------------------------------------------------
1967     /// Set accessor for the process exit status (return code).
1968     ///
1969     /// Sometimes a child exits and the exit can be detected by global
1970     /// functions (signal handler for SIGCHLD for example). This
1971     /// accessor allows the exit status to be set from an external
1972     /// source.
1973     ///
1974     /// Setting this will cause a eStateExited event to be posted to
1975     /// the process event queue.
1976     ///
1977     /// @param[in] exit_status
1978     ///     The value for the process's return code.
1979     ///
1980     /// @see lldb::StateType
1981     //------------------------------------------------------------------
1982     virtual bool
1983     SetExitStatus (int exit_status, const char *cstr);
1984
1985     //------------------------------------------------------------------
1986     /// Check if a process is still alive.
1987     ///
1988     /// @return
1989     ///     Returns \b true if the process is still valid, \b false
1990     ///     otherwise.
1991     //------------------------------------------------------------------
1992     virtual bool
1993     IsAlive () = 0;
1994
1995     //------------------------------------------------------------------
1996     /// Before lldb detaches from a process, it warns the user that they are about to lose their debug session.
1997     /// In some cases, this warning doesn't need to be emitted -- for instance, with core file debugging where 
1998     /// the user can reconstruct the "state" by simply re-running the debugger on the core file.  
1999     ///
2000     /// @return
2001     //      true if the user should be warned about detaching from this process.
2002     //------------------------------------------------------------------
2003     virtual bool
2004     WarnBeforeDetach () const
2005     {
2006         return true;
2007     }
2008
2009     //------------------------------------------------------------------
2010     /// Actually do the reading of memory from a process.
2011     ///
2012     /// Subclasses must override this function and can return fewer 
2013     /// bytes than requested when memory requests are too large. This
2014     /// class will break up the memory requests and keep advancing the
2015     /// arguments along as needed. 
2016     ///
2017     /// @param[in] vm_addr
2018     ///     A virtual load address that indicates where to start reading
2019     ///     memory from.
2020     ///
2021     /// @param[in] size
2022     ///     The number of bytes to read.
2023     ///
2024     /// @param[out] buf
2025     ///     A byte buffer that is at least \a size bytes long that
2026     ///     will receive the memory bytes.
2027     ///
2028     /// @return
2029     ///     The number of bytes that were actually read into \a buf.
2030     //------------------------------------------------------------------
2031     virtual size_t
2032     DoReadMemory (lldb::addr_t vm_addr, 
2033                   void *buf, 
2034                   size_t size,
2035                   Error &error) = 0;
2036
2037     //------------------------------------------------------------------
2038     /// Read of memory from a process.
2039     ///
2040     /// This function will read memory from the current process's
2041     /// address space and remove any traps that may have been inserted
2042     /// into the memory.
2043     ///
2044     /// This function is not meant to be overridden by Process
2045     /// subclasses, the subclasses should implement
2046     /// Process::DoReadMemory (lldb::addr_t, size_t, void *).
2047     ///
2048     /// @param[in] vm_addr
2049     ///     A virtual load address that indicates where to start reading
2050     ///     memory from.
2051     ///
2052     /// @param[out] buf
2053     ///     A byte buffer that is at least \a size bytes long that
2054     ///     will receive the memory bytes.
2055     ///
2056     /// @param[in] size
2057     ///     The number of bytes to read.
2058     ///
2059     /// @return
2060     ///     The number of bytes that were actually read into \a buf. If
2061     ///     the returned number is greater than zero, yet less than \a
2062     ///     size, then this function will get called again with \a 
2063     ///     vm_addr, \a buf, and \a size updated appropriately. Zero is
2064     ///     returned to indicate an error.
2065     //------------------------------------------------------------------
2066     virtual size_t
2067     ReadMemory (lldb::addr_t vm_addr, 
2068                 void *buf, 
2069                 size_t size,
2070                 Error &error);
2071
2072     //------------------------------------------------------------------
2073     /// Read a NULL terminated string from memory
2074     ///
2075     /// This function will read a cache page at a time until a NULL
2076     /// string terminator is found. It will stop reading if an aligned
2077     /// sequence of NULL termination \a type_width bytes is not found
2078     /// before reading \a cstr_max_len bytes.  The results are always 
2079     /// guaranteed to be NULL terminated, and that no more than
2080     /// (max_bytes - type_width) bytes will be read.
2081     ///
2082     /// @param[in] vm_addr
2083     ///     The virtual load address to start the memory read.
2084     ///
2085     /// @param[in] str
2086     ///     A character buffer containing at least max_bytes.
2087     ///
2088     /// @param[in] max_bytes
2089     ///     The maximum number of bytes to read.
2090     ///
2091     /// @param[in] error
2092     ///     The error status of the read operation.
2093     ///
2094     /// @param[in] type_width
2095     ///     The size of the null terminator (1 to 4 bytes per
2096     ///     character).  Defaults to 1.
2097     ///
2098     /// @return
2099     ///     The error status or the number of bytes prior to the null terminator.
2100     //------------------------------------------------------------------
2101     size_t
2102     ReadStringFromMemory (lldb::addr_t vm_addr, 
2103                            char *str, 
2104                            size_t max_bytes,
2105                            Error &error,
2106                            size_t type_width = 1);
2107
2108     //------------------------------------------------------------------
2109     /// Read a NULL terminated C string from memory
2110     ///
2111     /// This function will read a cache page at a time until the NULL
2112     /// C string terminator is found. It will stop reading if the NULL
2113     /// termination byte isn't found before reading \a cstr_max_len
2114     /// bytes, and the results are always guaranteed to be NULL 
2115     /// terminated (at most cstr_max_len - 1 bytes will be read).
2116     //------------------------------------------------------------------
2117     size_t
2118     ReadCStringFromMemory (lldb::addr_t vm_addr, 
2119                            char *cstr, 
2120                            size_t cstr_max_len,
2121                            Error &error);
2122
2123     size_t
2124     ReadCStringFromMemory (lldb::addr_t vm_addr,
2125                            std::string &out_str,
2126                            Error &error);
2127
2128     size_t
2129     ReadMemoryFromInferior (lldb::addr_t vm_addr, 
2130                             void *buf, 
2131                             size_t size,
2132                             Error &error);
2133     
2134     //------------------------------------------------------------------
2135     /// Reads an unsigned integer of the specified byte size from 
2136     /// process memory.
2137     ///
2138     /// @param[in] load_addr
2139     ///     A load address of the integer to read.
2140     ///
2141     /// @param[in] byte_size
2142     ///     The size in byte of the integer to read.
2143     ///
2144     /// @param[in] fail_value
2145     ///     The value to return if we fail to read an integer.
2146     ///
2147     /// @param[out] error
2148     ///     An error that indicates the success or failure of this
2149     ///     operation. If error indicates success (error.Success()), 
2150     ///     then the value returned can be trusted, otherwise zero
2151     ///     will be returned.
2152     ///
2153     /// @return
2154     ///     The unsigned integer that was read from the process memory
2155     ///     space. If the integer was smaller than a uint64_t, any
2156     ///     unused upper bytes will be zero filled. If the process
2157     ///     byte order differs from the host byte order, the integer
2158     ///     value will be appropriately byte swapped into host byte
2159     ///     order.
2160     //------------------------------------------------------------------
2161     uint64_t
2162     ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr, 
2163                                    size_t byte_size,
2164                                    uint64_t fail_value, 
2165                                    Error &error);
2166     
2167     lldb::addr_t
2168     ReadPointerFromMemory (lldb::addr_t vm_addr, 
2169                            Error &error);
2170
2171     bool
2172     WritePointerToMemory (lldb::addr_t vm_addr, 
2173                           lldb::addr_t ptr_value, 
2174                           Error &error);
2175
2176     //------------------------------------------------------------------
2177     /// Actually do the writing of memory to a process.
2178     ///
2179     /// @param[in] vm_addr
2180     ///     A virtual load address that indicates where to start writing
2181     ///     memory to.
2182     ///
2183     /// @param[in] buf
2184     ///     A byte buffer that is at least \a size bytes long that
2185     ///     contains the data to write.
2186     ///
2187     /// @param[in] size
2188     ///     The number of bytes to write.
2189     ///
2190     /// @param[out] error
2191     ///     An error value in case the memory write fails.
2192     ///
2193     /// @return
2194     ///     The number of bytes that were actually written.
2195     //------------------------------------------------------------------
2196     virtual size_t
2197     DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error)
2198     {
2199         error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetPluginName().GetCString());
2200         return 0;
2201     }
2202
2203
2204     //------------------------------------------------------------------
2205     /// Write all or part of a scalar value to memory.
2206     ///
2207     /// The value contained in \a scalar will be swapped to match the
2208     /// byte order of the process that is being debugged. If \a size is
2209     /// less than the size of scalar, the least significant \a size bytes
2210     /// from scalar will be written. If \a size is larger than the byte
2211     /// size of scalar, then the extra space will be padded with zeros
2212     /// and the scalar value will be placed in the least significant
2213     /// bytes in memory.
2214     ///
2215     /// @param[in] vm_addr
2216     ///     A virtual load address that indicates where to start writing
2217     ///     memory to.
2218     ///
2219     /// @param[in] scalar
2220     ///     The scalar to write to the debugged process.
2221     ///
2222     /// @param[in] size
2223     ///     This value can be smaller or larger than the scalar value
2224     ///     itself. If \a size is smaller than the size of \a scalar, 
2225     ///     the least significant bytes in \a scalar will be used. If
2226     ///     \a size is larger than the byte size of \a scalar, then 
2227     ///     the extra space will be padded with zeros. If \a size is
2228     ///     set to UINT32_MAX, then the size of \a scalar will be used.
2229     ///
2230     /// @param[out] error
2231     ///     An error value in case the memory write fails.
2232     ///
2233     /// @return
2234     ///     The number of bytes that were actually written.
2235     //------------------------------------------------------------------
2236     size_t
2237     WriteScalarToMemory (lldb::addr_t vm_addr, 
2238                          const Scalar &scalar, 
2239                          size_t size, 
2240                          Error &error);
2241
2242     size_t
2243     ReadScalarIntegerFromMemory (lldb::addr_t addr, 
2244                                  uint32_t byte_size, 
2245                                  bool is_signed, 
2246                                  Scalar &scalar, 
2247                                  Error &error);
2248
2249     //------------------------------------------------------------------
2250     /// Write memory to a process.
2251     ///
2252     /// This function will write memory to the current process's
2253     /// address space and maintain any traps that might be present due
2254     /// to software breakpoints.
2255     ///
2256     /// This function is not meant to be overridden by Process
2257     /// subclasses, the subclasses should implement
2258     /// Process::DoWriteMemory (lldb::addr_t, size_t, void *).
2259     ///
2260     /// @param[in] vm_addr
2261     ///     A virtual load address that indicates where to start writing
2262     ///     memory to.
2263     ///
2264     /// @param[in] buf
2265     ///     A byte buffer that is at least \a size bytes long that
2266     ///     contains the data to write.
2267     ///
2268     /// @param[in] size
2269     ///     The number of bytes to write.
2270     ///
2271     /// @return
2272     ///     The number of bytes that were actually written.
2273     //------------------------------------------------------------------
2274     size_t
2275     WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error);
2276
2277
2278     //------------------------------------------------------------------
2279     /// Actually allocate memory in the process.
2280     ///
2281     /// This function will allocate memory in the process's address
2282     /// space.  This can't rely on the generic function calling mechanism,
2283     /// since that requires this function.
2284     ///
2285     /// @param[in] size
2286     ///     The size of the allocation requested.
2287     ///
2288     /// @return
2289     ///     The address of the allocated buffer in the process, or
2290     ///     LLDB_INVALID_ADDRESS if the allocation failed.
2291     //------------------------------------------------------------------
2292
2293     virtual lldb::addr_t
2294     DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
2295     {
2296         error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetPluginName().GetCString());
2297         return LLDB_INVALID_ADDRESS;
2298     }
2299
2300
2301     //------------------------------------------------------------------
2302     /// The public interface to allocating memory in the process.
2303     ///
2304     /// This function will allocate memory in the process's address
2305     /// space.  This can't rely on the generic function calling mechanism,
2306     /// since that requires this function.
2307     ///
2308     /// @param[in] size
2309     ///     The size of the allocation requested.
2310     ///
2311     /// @param[in] permissions
2312     ///     Or together any of the lldb::Permissions bits.  The permissions on
2313     ///     a given memory allocation can't be changed after allocation.  Note
2314     ///     that a block that isn't set writable can still be written on from lldb,
2315     ///     just not by the process itself.
2316     ///
2317     /// @param[in/out] error
2318     ///     An error object to fill in if things go wrong.
2319     /// @return
2320     ///     The address of the allocated buffer in the process, or
2321     ///     LLDB_INVALID_ADDRESS if the allocation failed.
2322     //------------------------------------------------------------------
2323
2324     lldb::addr_t
2325     AllocateMemory (size_t size, uint32_t permissions, Error &error);
2326
2327
2328     //------------------------------------------------------------------
2329     /// Resolve dynamically loaded indirect functions.
2330     ///
2331     /// @param[in] address
2332     ///     The load address of the indirect function to resolve.
2333     ///
2334     /// @param[out] error
2335     ///     An error value in case the resolve fails.
2336     ///
2337     /// @return
2338     ///     The address of the resolved function.
2339     ///     LLDB_INVALID_ADDRESS if the resolution failed.
2340     //------------------------------------------------------------------
2341
2342     virtual lldb::addr_t
2343     ResolveIndirectFunction(const Address *address, Error &error);
2344
2345     virtual Error
2346     GetMemoryRegionInfo (lldb::addr_t load_addr,
2347                          MemoryRegionInfo &range_info)
2348     {
2349         Error error;
2350         error.SetErrorString ("Process::GetMemoryRegionInfo() not supported");
2351         return error;
2352     }
2353
2354     virtual Error
2355     GetWatchpointSupportInfo (uint32_t &num)
2356     {
2357         Error error;
2358         num = 0;
2359         error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported");
2360         return error;
2361     }
2362
2363     virtual Error
2364     GetWatchpointSupportInfo (uint32_t &num, bool& after)
2365     {
2366         Error error;
2367         num = 0;
2368         after = true;
2369         error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported");
2370         return error;
2371     }
2372     
2373     lldb::ModuleSP
2374     ReadModuleFromMemory (const FileSpec& file_spec, 
2375                           lldb::addr_t header_addr,
2376                           size_t size_to_read = 512);
2377
2378     //------------------------------------------------------------------
2379     /// Attempt to get the attributes for a region of memory in the process.
2380     ///
2381     /// It may be possible for the remote debug server to inspect attributes
2382     /// for a region of memory in the process, such as whether there is a
2383     /// valid page of memory at a given address or whether that page is 
2384     /// readable/writable/executable by the process.
2385     ///
2386     /// @param[in] load_addr
2387     ///     The address of interest in the process.
2388     ///
2389     /// @param[out] permissions
2390     ///     If this call returns successfully, this bitmask will have
2391     ///     its Permissions bits set to indicate whether the region is
2392     ///     readable/writable/executable.  If this call fails, the
2393     ///     bitmask values are undefined.
2394     ///
2395     /// @return
2396     ///     Returns true if it was able to determine the attributes of the
2397     ///     memory region.  False if not.
2398     //------------------------------------------------------------------
2399
2400     virtual bool
2401     GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions)
2402     {
2403         MemoryRegionInfo range_info;
2404         permissions = 0;
2405         Error error (GetMemoryRegionInfo (load_addr, range_info));
2406         if (!error.Success())
2407             return false;
2408         if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow 
2409             || range_info.GetWritable() == MemoryRegionInfo::eDontKnow 
2410             || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow)
2411         {
2412             return false;
2413         }
2414
2415         if (range_info.GetReadable() == MemoryRegionInfo::eYes)
2416             permissions |= lldb::ePermissionsReadable;
2417
2418         if (range_info.GetWritable() == MemoryRegionInfo::eYes)
2419             permissions |= lldb::ePermissionsWritable;
2420
2421         if (range_info.GetExecutable() == MemoryRegionInfo::eYes)
2422             permissions |= lldb::ePermissionsExecutable;
2423
2424         return true;
2425     }
2426
2427     //------------------------------------------------------------------
2428     /// Determines whether executing JIT-compiled code in this process 
2429     /// is possible.
2430     ///
2431     /// @return
2432     ///     True if execution of JIT code is possible; false otherwise.
2433     //------------------------------------------------------------------    
2434     bool CanJIT ();
2435     
2436     //------------------------------------------------------------------
2437     /// Sets whether executing JIT-compiled code in this process 
2438     /// is possible.
2439     ///
2440     /// @param[in] can_jit
2441     ///     True if execution of JIT code is possible; false otherwise.
2442     //------------------------------------------------------------------
2443     void SetCanJIT (bool can_jit);
2444     
2445     //------------------------------------------------------------------
2446     /// Actually deallocate memory in the process.
2447     ///
2448     /// This function will deallocate memory in the process's address
2449     /// space that was allocated with AllocateMemory.
2450     ///
2451     /// @param[in] ptr
2452     ///     A return value from AllocateMemory, pointing to the memory you
2453     ///     want to deallocate.
2454     ///
2455     /// @return
2456     ///     \btrue if the memory was deallocated, \bfalse otherwise.
2457     //------------------------------------------------------------------
2458
2459     virtual Error
2460     DoDeallocateMemory (lldb::addr_t ptr)
2461     {
2462         Error error;
2463         error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetPluginName().GetCString());
2464         return error;
2465     }
2466
2467
2468     //------------------------------------------------------------------
2469     /// The public interface to deallocating memory in the process.
2470     ///
2471     /// This function will deallocate memory in the process's address
2472     /// space that was allocated with AllocateMemory.
2473     ///
2474     /// @param[in] ptr
2475     ///     A return value from AllocateMemory, pointing to the memory you
2476     ///     want to deallocate.
2477     ///
2478     /// @return
2479     ///     \btrue if the memory was deallocated, \bfalse otherwise.
2480     //------------------------------------------------------------------
2481
2482     Error
2483     DeallocateMemory (lldb::addr_t ptr);
2484     
2485     //------------------------------------------------------------------
2486     /// Get any available STDOUT.
2487     ///
2488     /// Calling this method is a valid operation only if all of the
2489     /// following conditions are true:
2490     /// 1) The process was launched, and not attached to.
2491     /// 2) The process was not launched with eLaunchFlagDisableSTDIO.
2492     /// 3) The process was launched without supplying a valid file path
2493     ///    for STDOUT.
2494     ///
2495     /// Note that the implementation will probably need to start a read
2496     /// thread in the background to make sure that the pipe is drained
2497     /// and the STDOUT buffered appropriately, to prevent the process
2498     /// from deadlocking trying to write to a full buffer.
2499     ///
2500     /// Events will be queued indicating that there is STDOUT available
2501     /// that can be retrieved using this function.
2502     ///
2503     /// @param[out] buf
2504     ///     A buffer that will receive any STDOUT bytes that are
2505     ///     currently available.
2506     ///
2507     /// @param[in] buf_size
2508     ///     The size in bytes for the buffer \a buf.
2509     ///
2510     /// @return
2511     ///     The number of bytes written into \a buf. If this value is
2512     ///     equal to \a buf_size, another call to this function should
2513     ///     be made to retrieve more STDOUT data.
2514     //------------------------------------------------------------------
2515     virtual size_t
2516     GetSTDOUT (char *buf, size_t buf_size, Error &error);
2517
2518     //------------------------------------------------------------------
2519     /// Get any available STDERR.
2520     ///
2521     /// Calling this method is a valid operation only if all of the
2522     /// following conditions are true:
2523     /// 1) The process was launched, and not attached to.
2524     /// 2) The process was not launched with eLaunchFlagDisableSTDIO.
2525     /// 3) The process was launched without supplying a valid file path
2526     ///    for STDERR.
2527     ///
2528     /// Note that the implementation will probably need to start a read
2529     /// thread in the background to make sure that the pipe is drained
2530     /// and the STDERR buffered appropriately, to prevent the process
2531     /// from deadlocking trying to write to a full buffer.
2532     ///
2533     /// Events will be queued indicating that there is STDERR available
2534     /// that can be retrieved using this function.
2535     ///
2536     /// @param[in] buf
2537     ///     A buffer that will receive any STDERR bytes that are
2538     ///     currently available.
2539     ///
2540     /// @param[out] buf_size
2541     ///     The size in bytes for the buffer \a buf.
2542     ///
2543     /// @return
2544     ///     The number of bytes written into \a buf. If this value is
2545     ///     equal to \a buf_size, another call to this function should
2546     ///     be made to retrieve more STDERR data.
2547     //------------------------------------------------------------------
2548     virtual size_t
2549     GetSTDERR (char *buf, size_t buf_size, Error &error);
2550
2551     //------------------------------------------------------------------
2552     /// Puts data into this process's STDIN.
2553     ///
2554     /// Calling this method is a valid operation only if all of the
2555     /// following conditions are true:
2556     /// 1) The process was launched, and not attached to.
2557     /// 2) The process was not launched with eLaunchFlagDisableSTDIO.
2558     /// 3) The process was launched without supplying a valid file path
2559     ///    for STDIN.
2560     ///
2561     /// @param[in] buf
2562     ///     A buffer that contains the data to write to the process's STDIN.
2563     ///
2564     /// @param[in] buf_size
2565     ///     The size in bytes for the buffer \a buf.
2566     ///
2567     /// @return
2568     ///     The number of bytes written into \a buf. If this value is
2569     ///     less than \a buf_size, another call to this function should
2570     ///     be made to write the rest of the data.
2571     //------------------------------------------------------------------
2572     virtual size_t
2573     PutSTDIN (const char *buf, size_t buf_size, Error &error) 
2574     {
2575         error.SetErrorString("stdin unsupported");
2576         return 0;
2577     }
2578
2579     //------------------------------------------------------------------
2580     /// Get any available profile data.
2581     ///
2582     /// @param[out] buf
2583     ///     A buffer that will receive any profile data bytes that are
2584     ///     currently available.
2585     ///
2586     /// @param[out] buf_size
2587     ///     The size in bytes for the buffer \a buf.
2588     ///
2589     /// @return
2590     ///     The number of bytes written into \a buf. If this value is
2591     ///     equal to \a buf_size, another call to this function should
2592     ///     be made to retrieve more profile data.
2593     //------------------------------------------------------------------
2594     virtual size_t
2595     GetAsyncProfileData (char *buf, size_t buf_size, Error &error);
2596     
2597     //----------------------------------------------------------------------
2598     // Process Breakpoints
2599     //----------------------------------------------------------------------
2600     size_t
2601     GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site);
2602
2603     virtual Error
2604     EnableBreakpointSite (BreakpointSite *bp_site)
2605     {
2606         Error error;
2607         error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetPluginName().GetCString());
2608         return error;
2609     }
2610
2611
2612     virtual Error
2613     DisableBreakpointSite (BreakpointSite *bp_site)
2614     {
2615         Error error;
2616         error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetPluginName().GetCString());
2617         return error;
2618     }
2619
2620
2621     // This is implemented completely using the lldb::Process API. Subclasses
2622     // don't need to implement this function unless the standard flow of
2623     // read existing opcode, write breakpoint opcode, verify breakpoint opcode
2624     // doesn't work for a specific process plug-in.
2625     virtual Error
2626     EnableSoftwareBreakpoint (BreakpointSite *bp_site);
2627
2628     // This is implemented completely using the lldb::Process API. Subclasses
2629     // don't need to implement this function unless the standard flow of
2630     // restoring original opcode in memory and verifying the restored opcode
2631     // doesn't work for a specific process plug-in.
2632     virtual Error
2633     DisableSoftwareBreakpoint (BreakpointSite *bp_site);
2634
2635     BreakpointSiteList &
2636     GetBreakpointSiteList();
2637
2638     const BreakpointSiteList &
2639     GetBreakpointSiteList() const;
2640
2641     void
2642     DisableAllBreakpointSites ();
2643
2644     Error
2645     ClearBreakpointSiteByID (lldb::user_id_t break_id);
2646
2647     lldb::break_id_t
2648     CreateBreakpointSite (const lldb::BreakpointLocationSP &owner,
2649                           bool use_hardware);
2650
2651     Error
2652     DisableBreakpointSiteByID (lldb::user_id_t break_id);
2653
2654     Error
2655     EnableBreakpointSiteByID (lldb::user_id_t break_id);
2656
2657
2658     // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove
2659     // themselves from the owner's list of this breakpoint sites.
2660     void
2661     RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id,
2662                                    lldb::user_id_t owner_loc_id,
2663                                    lldb::BreakpointSiteSP &bp_site_sp);
2664
2665     //----------------------------------------------------------------------
2666     // Process Watchpoints (optional)
2667     //----------------------------------------------------------------------
2668     virtual Error
2669     EnableWatchpoint (Watchpoint *wp, bool notify = true);
2670
2671     virtual Error
2672     DisableWatchpoint (Watchpoint *wp, bool notify = true);
2673
2674     //------------------------------------------------------------------
2675     // Thread Queries
2676     //------------------------------------------------------------------
2677     virtual bool
2678     UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0;
2679
2680     void
2681     UpdateThreadListIfNeeded ();
2682
2683     ThreadList &
2684     GetThreadList ()
2685     {
2686         return m_thread_list;
2687     }
2688
2689     // When ExtendedBacktraces are requested, the HistoryThreads that are
2690     // created need an owner -- they're saved here in the Process.  The
2691     // threads in this list are not iterated over - driver programs need to
2692     // request the extended backtrace calls starting from a root concrete
2693     // thread one by one.
2694     ThreadList &
2695     GetExtendedThreadList ()
2696     {
2697         return m_extended_thread_list;
2698     }
2699
2700     ThreadList::ThreadIterable
2701     Threads ()
2702     {
2703         return m_thread_list.Threads();
2704     }
2705
2706     uint32_t
2707     GetNextThreadIndexID (uint64_t thread_id);
2708
2709     lldb::ThreadSP
2710     CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
2711     
2712     // Returns true if an index id has been assigned to a thread.
2713     bool
2714     HasAssignedIndexIDToThread(uint64_t sb_thread_id);
2715     
2716     // Given a thread_id, it will assign a more reasonable index id for display to the user.
2717     // If the thread_id has previously been assigned, the same index id will be used.
2718     uint32_t
2719     AssignIndexIDToThread(uint64_t thread_id);
2720
2721     //------------------------------------------------------------------
2722     // Queue Queries
2723     //------------------------------------------------------------------
2724
2725     void
2726     UpdateQueueListIfNeeded ();
2727
2728     QueueList &
2729     GetQueueList ()
2730     {
2731         UpdateQueueListIfNeeded();
2732         return m_queue_list;
2733     }
2734
2735     QueueList::QueueIterable
2736     Queues ()
2737     {
2738         UpdateQueueListIfNeeded();
2739         return m_queue_list.Queues();
2740     }
2741
2742     //------------------------------------------------------------------
2743     // Event Handling
2744     //------------------------------------------------------------------
2745     lldb::StateType
2746     GetNextEvent (lldb::EventSP &event_sp);
2747
2748     // Returns the process state when it is stopped. If specified, event_sp_ptr
2749     // is set to the event which triggered the stop. If wait_always = false,
2750     // and the process is already stopped, this function returns immediately.
2751     lldb::StateType
2752     WaitForProcessToStop (const TimeValue *timeout,
2753                           lldb::EventSP *event_sp_ptr = NULL,
2754                           bool wait_always = true,
2755                           Listener *hijack_listener = NULL,
2756                           Stream *stream = NULL);
2757
2758
2759     //--------------------------------------------------------------------------------------
2760     /// Waits for the process state to be running within a given msec timeout.
2761     ///
2762     /// The main purpose of this is to implement an interlock waiting for HandlePrivateEvent
2763     /// to push an IOHandler.
2764     ///
2765     /// @param[in] timeout_msec
2766     ///     The maximum time length to wait for the process to transition to the
2767     ///     eStateRunning state, specified in milliseconds.
2768     ///
2769     /// @return
2770     ///     true if successfully signalled that process started and IOHandler pushes, false
2771     ///     if it timed out.
2772     //--------------------------------------------------------------------------------------
2773     bool
2774     SyncIOHandler (uint64_t timeout_msec);
2775
2776
2777     lldb::StateType
2778     WaitForStateChangedEvents (const TimeValue *timeout,
2779                                lldb::EventSP &event_sp,
2780                                Listener *hijack_listener); // Pass NULL to use builtin listener
2781
2782     //--------------------------------------------------------------------------------------
2783     /// Centralize the code that handles and prints descriptions for process state changes.
2784     ///
2785     /// @param[in] event_sp
2786     ///     The process state changed event
2787     ///
2788     /// @param[in] stream
2789     ///     The output stream to get the state change description
2790     ///
2791     /// @param[inout] pop_process_io_handler
2792     ///     If this value comes in set to \b true, then pop the Process IOHandler if needed.
2793     ///     Else this variable will be set to \b true or \b false to indicate if the process
2794     ///     needs to have its process IOHandler popped.
2795     ///
2796     /// @return
2797     ///     \b true if the event describes a process state changed event, \b false otherwise.
2798     //--------------------------------------------------------------------------------------
2799     static bool
2800     HandleProcessStateChangedEvent (const lldb::EventSP &event_sp,
2801                                     Stream *stream,
2802                                     bool &pop_process_io_handler);
2803     Event *
2804     PeekAtStateChangedEvents ();
2805     
2806
2807     class
2808     ProcessEventHijacker
2809     {
2810     public:
2811         ProcessEventHijacker (Process &process, Listener *listener) :
2812             m_process (process)
2813         {
2814             m_process.HijackProcessEvents (listener);
2815         }
2816         ~ProcessEventHijacker ()
2817         {
2818             m_process.RestoreProcessEvents();
2819         }
2820          
2821     private:
2822         Process &m_process;
2823     };
2824     friend class ProcessEventHijacker;
2825     friend class ProcessProperties;
2826     //------------------------------------------------------------------
2827     /// If you need to ensure that you and only you will hear about some public
2828     /// event, then make a new listener, set to listen to process events, and
2829     /// then call this with that listener.  Then you will have to wait on that
2830     /// listener explicitly for events (rather than using the GetNextEvent & WaitFor*
2831     /// calls above.  Be sure to call RestoreProcessEvents when you are done.
2832     ///
2833     /// @param[in] listener
2834     ///     This is the new listener to whom all process events will be delivered.
2835     ///
2836     /// @return
2837     ///     Returns \b true if the new listener could be installed,
2838     ///     \b false otherwise.
2839     //------------------------------------------------------------------
2840     bool
2841     HijackProcessEvents (Listener *listener);
2842     
2843     //------------------------------------------------------------------
2844     /// Restores the process event broadcasting to its normal state.
2845     ///
2846     //------------------------------------------------------------------
2847     void
2848     RestoreProcessEvents ();
2849
2850 private:
2851     //------------------------------------------------------------------
2852     /// This is the part of the event handling that for a process event.
2853     /// It decides what to do with the event and returns true if the
2854     /// event needs to be propagated to the user, and false otherwise.
2855     /// If the event is not propagated, this call will most likely set
2856     /// the target to executing again.
2857     /// There is only one place where this call should be called, HandlePrivateEvent.
2858     /// Don't call it from anywhere else...
2859     ///
2860     /// @param[in] event_ptr
2861     ///     This is the event we are handling.
2862     ///
2863     /// @return
2864     ///     Returns \b true if the event should be reported to the
2865     ///     user, \b false otherwise.
2866     //------------------------------------------------------------------
2867     bool
2868     ShouldBroadcastEvent (Event *event_ptr);
2869
2870 public:
2871     const lldb::ABISP &
2872     GetABI ();
2873
2874     OperatingSystem *
2875     GetOperatingSystem ()
2876     {
2877         return m_os_ap.get();
2878     }
2879
2880     ArchSpec::StopInfoOverrideCallbackType
2881     GetStopInfoOverrideCallback () const
2882     {
2883         return m_stop_info_override_callback;
2884     }
2885
2886     virtual LanguageRuntime *
2887     GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true);
2888
2889     virtual CPPLanguageRuntime *
2890     GetCPPLanguageRuntime (bool retry_if_null = true);
2891
2892     virtual ObjCLanguageRuntime *
2893     GetObjCLanguageRuntime (bool retry_if_null = true);
2894     
2895     bool
2896     IsPossibleDynamicValue (ValueObject& in_value);
2897     
2898     bool
2899     IsRunning () const;
2900     
2901     DynamicCheckerFunctions *GetDynamicCheckers()
2902     {
2903         return m_dynamic_checkers_ap.get();
2904     }
2905     
2906     void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers)
2907     {
2908         m_dynamic_checkers_ap.reset(dynamic_checkers);
2909     }
2910
2911     //------------------------------------------------------------------
2912     /// Call this to set the lldb in the mode where it breaks on new thread
2913     /// creations, and then auto-restarts.  This is useful when you are trying
2914     /// to run only one thread, but either that thread or the kernel is creating
2915     /// new threads in the process.  If you stop when the thread is created, you
2916     /// can immediately suspend it, and keep executing only the one thread you intend.
2917     ///
2918     /// @return
2919     ///     Returns \b true if we were able to start up the notification
2920     ///     \b false otherwise.
2921     //------------------------------------------------------------------
2922     virtual bool
2923     StartNoticingNewThreads()
2924     {   
2925         return true;
2926     }
2927     
2928     //------------------------------------------------------------------
2929     /// Call this to turn off the stop & notice new threads mode.
2930     ///
2931     /// @return
2932     ///     Returns \b true if we were able to start up the notification
2933     ///     \b false otherwise.
2934     //------------------------------------------------------------------
2935     virtual bool
2936     StopNoticingNewThreads()
2937     {   
2938         return true;
2939     }
2940     
2941     void
2942     SetRunningUserExpression (bool on);
2943     
2944     //------------------------------------------------------------------
2945     // lldb::ExecutionContextScope pure virtual functions
2946     //------------------------------------------------------------------
2947     virtual lldb::TargetSP
2948     CalculateTarget ();
2949     
2950     virtual lldb::ProcessSP
2951     CalculateProcess ()
2952     {
2953         return shared_from_this();
2954     }
2955     
2956     virtual lldb::ThreadSP
2957     CalculateThread ()
2958     {
2959         return lldb::ThreadSP();
2960     }
2961     
2962     virtual lldb::StackFrameSP
2963     CalculateStackFrame ()
2964     {
2965         return lldb::StackFrameSP();
2966     }
2967
2968     virtual void
2969     CalculateExecutionContext (ExecutionContext &exe_ctx);
2970     
2971     void
2972     SetSTDIOFileDescriptor (int file_descriptor);
2973
2974     //------------------------------------------------------------------
2975     // Add a permanent region of memory that should never be read or 
2976     // written to. This can be used to ensure that memory reads or writes
2977     // to certain areas of memory never end up being sent to the 
2978     // DoReadMemory or DoWriteMemory functions which can improve 
2979     // performance.
2980     //------------------------------------------------------------------
2981     void
2982     AddInvalidMemoryRegion (const LoadRange &region);
2983     
2984     //------------------------------------------------------------------
2985     // Remove a permanent region of memory that should never be read or 
2986     // written to that was previously added with AddInvalidMemoryRegion.
2987     //------------------------------------------------------------------
2988     bool
2989     RemoveInvalidMemoryRange (const LoadRange &region);
2990     
2991     //------------------------------------------------------------------
2992     // If the setup code of a thread plan needs to do work that might involve 
2993     // calling a function in the target, it should not do that work directly
2994     // in one of the thread plan functions (DidPush/WillResume) because
2995     // such work needs to be handled carefully.  Instead, put that work in
2996     // a PreResumeAction callback, and register it with the process.  It will
2997     // get done before the actual "DoResume" gets called.
2998     //------------------------------------------------------------------
2999     
3000     typedef bool (PreResumeActionCallback)(void *);
3001
3002     void
3003     AddPreResumeAction (PreResumeActionCallback callback, void *baton);
3004     
3005     bool
3006     RunPreResumeActions ();
3007     
3008     void
3009     ClearPreResumeActions ();
3010                               
3011     ProcessRunLock &
3012     GetRunLock ()
3013     {
3014         if (m_private_state_thread.EqualsThread(Host::GetCurrentThread()))
3015             return m_private_run_lock;
3016         else
3017             return m_public_run_lock;
3018     }
3019
3020 public:
3021     virtual Error
3022     SendEventData(const char *data)
3023     {
3024         Error return_error ("Sending an event is not supported for this process.");
3025         return return_error;
3026     }
3027     
3028     lldb::ThreadCollectionSP
3029     GetHistoryThreads(lldb::addr_t addr);
3030
3031     lldb::InstrumentationRuntimeSP
3032     GetInstrumentationRuntime(lldb::InstrumentationRuntimeType type);
3033
3034 protected:
3035
3036     //------------------------------------------------------------------
3037     // NextEventAction provides a way to register an action on the next
3038     // event that is delivered to this process.  There is currently only
3039     // one next event action allowed in the process at one time.  If a
3040     // new "NextEventAction" is added while one is already present, the
3041     // old action will be discarded (with HandleBeingUnshipped called 
3042     // after it is discarded.)
3043     //
3044     // If you want to resume the process as a result of a resume action,
3045     // call RequestResume, don't call Resume directly.
3046     //------------------------------------------------------------------
3047     class NextEventAction
3048     {
3049     public:
3050         typedef enum EventActionResult
3051         {
3052             eEventActionSuccess,
3053             eEventActionRetry,
3054             eEventActionExit
3055         } EventActionResult;
3056         
3057         NextEventAction (Process *process) : 
3058             m_process(process)
3059         {
3060         }
3061
3062         virtual
3063         ~NextEventAction() 
3064         {
3065         }
3066         
3067         virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0;
3068         virtual void HandleBeingUnshipped () {}
3069         virtual EventActionResult HandleBeingInterrupted () = 0;
3070         virtual const char *GetExitString() = 0;
3071         void RequestResume()
3072         {
3073             m_process->m_resume_requested = true;
3074         }
3075     protected:
3076         Process *m_process;
3077     };
3078     
3079     void SetNextEventAction (Process::NextEventAction *next_event_action)
3080     {
3081         if (m_next_event_action_ap.get())
3082             m_next_event_action_ap->HandleBeingUnshipped();
3083
3084         m_next_event_action_ap.reset(next_event_action);
3085     }
3086     
3087     // This is the completer for Attaching:
3088     class AttachCompletionHandler : public NextEventAction
3089     {
3090     public:
3091         AttachCompletionHandler (Process *process, uint32_t exec_count);
3092
3093         virtual
3094         ~AttachCompletionHandler() 
3095         {
3096         }
3097         
3098         virtual EventActionResult PerformAction (lldb::EventSP &event_sp);
3099         virtual EventActionResult HandleBeingInterrupted ();
3100         virtual const char *GetExitString();
3101     private:
3102         uint32_t m_exec_count;
3103         std::string m_exit_string;
3104     };
3105
3106     bool 
3107     HijackPrivateProcessEvents (Listener *listener);
3108     
3109     void 
3110     RestorePrivateProcessEvents ();
3111     
3112     bool
3113     PrivateStateThreadIsValid () const
3114     {
3115         return m_private_state_thread.IsJoinable();
3116     }
3117     
3118     void
3119     ForceNextEventDelivery()
3120     {
3121         m_force_next_event_delivery = true;
3122     }
3123
3124     //------------------------------------------------------------------
3125     // Type definitions
3126     //------------------------------------------------------------------
3127     typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection;
3128
3129     struct PreResumeCallbackAndBaton
3130     {
3131         bool (*callback) (void *);
3132         void *baton;
3133         PreResumeCallbackAndBaton (PreResumeActionCallback in_callback, void *in_baton) :
3134             callback (in_callback),
3135             baton (in_baton)
3136         {
3137         }
3138     };
3139     
3140     //------------------------------------------------------------------
3141     // Member variables
3142     //------------------------------------------------------------------
3143     Target &                    m_target;               ///< The target that owns this process.
3144     ThreadSafeValue<lldb::StateType>  m_public_state;
3145     ThreadSafeValue<lldb::StateType>  m_private_state; // The actual state of our process
3146     Broadcaster                 m_private_state_broadcaster;  // This broadcaster feeds state changed events into the private state thread's listener.
3147     Broadcaster                 m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread.
3148     Listener                    m_private_state_listener;     // This is the listener for the private state thread.
3149     Predicate<bool>             m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete.
3150     HostThread m_private_state_thread;                        // Thread ID for the thread that watches internal state events
3151     ProcessModID                m_mod_id;               ///< Tracks the state of the process over stops and other alterations.
3152     uint32_t                    m_process_unique_id;    ///< Each lldb_private::Process class that is created gets a unique integer ID that increments with each new instance
3153     uint32_t                    m_thread_index_id;      ///< Each thread is created with a 1 based index that won't get re-used.
3154     std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map;
3155     int                         m_exit_status;          ///< The exit status of the process, or -1 if not set.
3156     std::string                 m_exit_string;          ///< A textual description of why a process exited.
3157     Mutex                       m_exit_status_mutex;    ///< Mutex so m_exit_status m_exit_string can be safely accessed from multiple threads
3158     Mutex                       m_thread_mutex;
3159     ThreadList                  m_thread_list_real;     ///< The threads for this process as are known to the protocol we are debugging with
3160     ThreadList                  m_thread_list;          ///< The threads for this process as the user will see them. This is usually the same as
3161                                                         ///< m_thread_list_real, but might be different if there is an OS plug-in creating memory threads
3162     ThreadList                  m_extended_thread_list; ///< Owner for extended threads that may be generated, cleared on natural stops
3163     uint32_t                    m_extended_thread_stop_id; ///< The natural stop id when extended_thread_list was last updated
3164     QueueList                   m_queue_list;           ///< The list of libdispatch queues at a given stop point
3165     uint32_t                    m_queue_list_stop_id;   ///< The natural stop id when queue list was last fetched
3166     std::vector<Notifications>  m_notifications;        ///< The list of notifications that this process can deliver.
3167     std::vector<lldb::addr_t>   m_image_tokens;
3168     Listener                    &m_listener;
3169     BreakpointSiteList          m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend to insert in the target.
3170     std::unique_ptr<DynamicLoader> m_dyld_ap;
3171     std::unique_ptr<JITLoaderList> m_jit_loaders_ap;
3172     std::unique_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use.
3173     std::unique_ptr<OperatingSystem> m_os_ap;
3174     std::unique_ptr<SystemRuntime> m_system_runtime_ap;
3175     UnixSignalsSP               m_unix_signals_sp;         /// This is the current signal set for this process.
3176     lldb::ABISP                 m_abi_sp;
3177     lldb::IOHandlerSP           m_process_input_reader;
3178     Communication               m_stdio_communication;
3179     Mutex                       m_stdio_communication_mutex;
3180     std::string                 m_stdout_data;
3181     std::string                 m_stderr_data;
3182     Mutex                       m_profile_data_comm_mutex;
3183     std::vector<std::string>    m_profile_data;
3184     Predicate<bool>             m_iohandler_sync;
3185     MemoryCache                 m_memory_cache;
3186     AllocatedMemoryCache        m_allocated_memory_cache;
3187     bool                        m_should_detach;   /// Should we detach if the process object goes away with an explicit call to Kill or Detach?
3188     LanguageRuntimeCollection   m_language_runtimes;
3189     InstrumentationRuntimeCollection m_instrumentation_runtimes;
3190     std::unique_ptr<NextEventAction> m_next_event_action_ap;
3191     std::vector<PreResumeCallbackAndBaton> m_pre_resume_actions;
3192     ProcessRunLock              m_public_run_lock;
3193     ProcessRunLock              m_private_run_lock;
3194     Predicate<bool>             m_currently_handling_event; // This predicate is set in HandlePrivateEvent while all its business is being done.
3195     ArchSpec::StopInfoOverrideCallbackType m_stop_info_override_callback;
3196     bool                        m_currently_handling_do_on_removals;
3197     bool                        m_resume_requested;         // If m_currently_handling_event or m_currently_handling_do_on_removals are true, Resume will only request a resume, using this flag to check.
3198     bool                        m_finalize_called;
3199     bool                        m_clear_thread_plans_on_stop;
3200     bool                        m_force_next_event_delivery;
3201     lldb::StateType             m_last_broadcast_state;   /// This helps with the Public event coalescing in ShouldBroadcastEvent.
3202     std::map<lldb::addr_t,lldb::addr_t> m_resolved_indirect_addresses;
3203     bool m_destroy_in_process;
3204     
3205     enum {
3206         eCanJITDontKnow= 0,
3207         eCanJITYes,
3208         eCanJITNo
3209     } m_can_jit;
3210
3211     size_t
3212     RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const;
3213
3214     void
3215     SynchronouslyNotifyStateChanged (lldb::StateType state);
3216
3217     void
3218     SetPublicState (lldb::StateType new_state, bool restarted);
3219
3220     void
3221     SetPrivateState (lldb::StateType state);
3222
3223     bool
3224     StartPrivateStateThread (bool force = false);
3225
3226     void
3227     StopPrivateStateThread ();
3228
3229     void
3230     PausePrivateStateThread ();
3231
3232     void
3233     ResumePrivateStateThread ();
3234
3235     static lldb::thread_result_t
3236     PrivateStateThread (void *arg);
3237
3238     lldb::thread_result_t
3239     RunPrivateStateThread ();
3240
3241     void
3242     HandlePrivateEvent (lldb::EventSP &event_sp);
3243
3244     lldb::StateType
3245     WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
3246
3247     // This waits for both the state change broadcaster, and the control broadcaster.
3248     // If control_only, it only waits for the control broadcaster.
3249
3250     bool
3251     WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only);
3252
3253     lldb::StateType
3254     WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
3255
3256     lldb::StateType
3257     WaitForState (const TimeValue *timeout,
3258                   const lldb::StateType *match_states,
3259                   const uint32_t num_match_states);
3260
3261     size_t
3262     WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error);
3263     
3264     void
3265     AppendSTDOUT (const char *s, size_t len);
3266     
3267     void
3268     AppendSTDERR (const char *s, size_t len);
3269     
3270     void
3271     BroadcastAsyncProfileData(const std::string &one_profile_data);
3272     
3273     static void
3274     STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
3275     
3276     bool
3277     PushProcessIOHandler ();
3278     
3279     bool
3280     PopProcessIOHandler ();
3281     
3282     bool
3283     ProcessIOHandlerIsActive ();
3284     
3285     Error
3286     HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp);
3287
3288     bool
3289     StateChangedIsExternallyHijacked();
3290
3291     void
3292     LoadOperatingSystemPlugin(bool flush);
3293 private:
3294     //------------------------------------------------------------------
3295     // For Process only
3296     //------------------------------------------------------------------
3297     void ControlPrivateStateThread (uint32_t signal);
3298     
3299     DISALLOW_COPY_AND_ASSIGN (Process);
3300
3301 };
3302
3303 } // namespace lldb_private
3304
3305 #endif  // liblldb_Process_h_