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