Process.h revision 0a8dcacde404c520f1131c641041dceb9f68b6fa
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 partial process name.
1893    ///
1894    /// @param[in] process_name
1895    ///     The name of the process to attach to.
1896    ///
1897    /// @param[in] wait_for_launch
1898    ///     If \b true, wait for the process to be launched and attach
1899    ///     as soon as possible after it does launch. If \b false, then
1900    ///     search for a matching process the currently exists.
1901    ///
1902    /// @return
1903    ///     Returns \a pid if attaching was successful, or
1904    ///     LLDB_INVALID_PROCESS_ID if attaching fails.
1905    //------------------------------------------------------------------
1906    virtual Error
1907    DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
1908    {
1909        Error error;
1910        error.SetErrorString("attach by name is not supported");
1911        return error;
1912    }
1913
1914    //------------------------------------------------------------------
1915    /// Called after attaching a process.
1916    ///
1917    /// Allow Process plug-ins to execute some code after attaching to
1918    /// a process.
1919    //------------------------------------------------------------------
1920    virtual void
1921    DidAttach () {}
1922
1923
1924    //------------------------------------------------------------------
1925    /// Called before launching to a process.
1926    ///
1927    /// Allow Process plug-ins to execute some code before launching a
1928    /// process.
1929    ///
1930    /// @return
1931    ///     Returns an error object.
1932    //------------------------------------------------------------------
1933    virtual Error
1934    WillLaunch (Module* module)
1935    {
1936        return Error();
1937    }
1938
1939    //------------------------------------------------------------------
1940    /// Launch a new process.
1941    ///
1942    /// Launch a new process by spawning a new process using \a module's
1943    /// file as the file to launch. Arguments are given in \a argv,
1944    /// and the environment variables are in \a envp. Standard input
1945    /// and output files can be optionally re-directed to \a stdin_path,
1946    /// \a stdout_path, and \a stderr_path.
1947    ///
1948    /// @param[in] module
1949    ///     The module from which to extract the file specification and
1950    ///     launch.
1951    ///
1952    /// @param[in] argv
1953    ///     The argument array.
1954    ///
1955    /// @param[in] envp
1956    ///     The environment array.
1957    ///
1958    /// @param[in] launch_flags
1959    ///     Flags to modify the launch (@see lldb::LaunchFlags)
1960    ///
1961    /// @param[in] stdin_path
1962    ///     The path to use when re-directing the STDIN of the new
1963    ///     process. If all stdXX_path arguments are NULL, a pseudo
1964    ///     terminal will be used.
1965    ///
1966    /// @param[in] stdout_path
1967    ///     The path to use when re-directing the STDOUT of the new
1968    ///     process. If all stdXX_path arguments are NULL, a pseudo
1969    ///     terminal will be used.
1970    ///
1971    /// @param[in] stderr_path
1972    ///     The path to use when re-directing the STDERR of the new
1973    ///     process. If all stdXX_path arguments are NULL, a pseudo
1974    ///     terminal will be used.
1975    ///
1976    /// @param[in] working_directory
1977    ///     The working directory to have the child process run in
1978    ///
1979    /// @return
1980    ///     A new valid process ID, or LLDB_INVALID_PROCESS_ID if
1981    ///     launching fails.
1982    //------------------------------------------------------------------
1983    virtual Error
1984    DoLaunch (Module *exe_module,
1985              const ProcessLaunchInfo &launch_info)
1986    {
1987        Error error;
1988        error.SetErrorStringWithFormat("error: %s does not support launching processes", GetShortPluginName());
1989        return error;
1990    }
1991
1992
1993    //------------------------------------------------------------------
1994    /// Called after launching a process.
1995    ///
1996    /// Allow Process plug-ins to execute some code after launching
1997    /// a process.
1998    //------------------------------------------------------------------
1999    virtual void
2000    DidLaunch () {}
2001
2002
2003
2004    //------------------------------------------------------------------
2005    /// Called before resuming to a process.
2006    ///
2007    /// Allow Process plug-ins to execute some code before resuming a
2008    /// process.
2009    ///
2010    /// @return
2011    ///     Returns an error object.
2012    //------------------------------------------------------------------
2013    virtual Error
2014    WillResume () { return Error(); }
2015
2016    //------------------------------------------------------------------
2017    /// Resumes all of a process's threads as configured using the
2018    /// Thread run control functions.
2019    ///
2020    /// Threads for a process should be updated with one of the run
2021    /// control actions (resume, step, or suspend) that they should take
2022    /// when the process is resumed. If no run control action is given
2023    /// to a thread it will be resumed by default.
2024    ///
2025    /// @return
2026    ///     Returns \b true if the process successfully resumes using
2027    ///     the thread run control actions, \b false otherwise.
2028    ///
2029    /// @see Thread:Resume()
2030    /// @see Thread:Step()
2031    /// @see Thread:Suspend()
2032    //------------------------------------------------------------------
2033    virtual Error
2034    DoResume ()
2035    {
2036        Error error;
2037        error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetShortPluginName());
2038        return error;
2039    }
2040
2041
2042    //------------------------------------------------------------------
2043    /// Called after resuming a process.
2044    ///
2045    /// Allow Process plug-ins to execute some code after resuming
2046    /// a process.
2047    //------------------------------------------------------------------
2048    virtual void
2049    DidResume () {}
2050
2051
2052    //------------------------------------------------------------------
2053    /// Called before halting to a process.
2054    ///
2055    /// Allow Process plug-ins to execute some code before halting a
2056    /// process.
2057    ///
2058    /// @return
2059    ///     Returns an error object.
2060    //------------------------------------------------------------------
2061    virtual Error
2062    WillHalt () { return Error(); }
2063
2064    //------------------------------------------------------------------
2065    /// Halts a running process.
2066    ///
2067    /// DoHalt must produce one and only one stop StateChanged event if it actually
2068    /// stops the process.  If the stop happens through some natural event (for
2069    /// instance a SIGSTOP), then forwarding that event will do.  Otherwise, you must
2070    /// generate the event manually.  Note also, the private event thread is stopped when
2071    /// DoHalt is run to prevent the events generated while halting to trigger
2072    /// other state changes before the halt is complete.
2073    ///
2074    /// @param[out] caused_stop
2075    ///     If true, then this Halt caused the stop, otherwise, the
2076    ///     process was already stopped.
2077    ///
2078    /// @return
2079    ///     Returns \b true if the process successfully halts, \b false
2080    ///     otherwise.
2081    //------------------------------------------------------------------
2082    virtual Error
2083    DoHalt (bool &caused_stop)
2084    {
2085        Error error;
2086        error.SetErrorStringWithFormat("error: %s does not support halting processes", GetShortPluginName());
2087        return error;
2088    }
2089
2090
2091    //------------------------------------------------------------------
2092    /// Called after halting a process.
2093    ///
2094    /// Allow Process plug-ins to execute some code after halting
2095    /// a process.
2096    //------------------------------------------------------------------
2097    virtual void
2098    DidHalt () {}
2099
2100    //------------------------------------------------------------------
2101    /// Called before detaching from a process.
2102    ///
2103    /// Allow Process plug-ins to execute some code before detaching
2104    /// from a process.
2105    ///
2106    /// @return
2107    ///     Returns an error object.
2108    //------------------------------------------------------------------
2109    virtual Error
2110    WillDetach ()
2111    {
2112        return Error();
2113    }
2114
2115    //------------------------------------------------------------------
2116    /// Detaches from a running or stopped process.
2117    ///
2118    /// @return
2119    ///     Returns \b true if the process successfully detaches, \b
2120    ///     false otherwise.
2121    //------------------------------------------------------------------
2122    virtual Error
2123    DoDetach ()
2124    {
2125        Error error;
2126        error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetShortPluginName());
2127        return error;
2128    }
2129
2130
2131    //------------------------------------------------------------------
2132    /// Called after detaching from a process.
2133    ///
2134    /// Allow Process plug-ins to execute some code after detaching
2135    /// from a process.
2136    //------------------------------------------------------------------
2137    virtual void
2138    DidDetach () {}
2139
2140    //------------------------------------------------------------------
2141    /// Called before sending a signal to a process.
2142    ///
2143    /// Allow Process plug-ins to execute some code before sending a
2144    /// signal to a process.
2145    ///
2146    /// @return
2147    ///     Returns no error if it is safe to proceed with a call to
2148    ///     Process::DoSignal(int), otherwise an error describing what
2149    ///     prevents the signal from being sent.
2150    //------------------------------------------------------------------
2151    virtual Error
2152    WillSignal () { return Error(); }
2153
2154    //------------------------------------------------------------------
2155    /// Sends a process a UNIX signal \a signal.
2156    ///
2157    /// @return
2158    ///     Returns an error object.
2159    //------------------------------------------------------------------
2160    virtual Error
2161    DoSignal (int signal)
2162    {
2163        Error error;
2164        error.SetErrorStringWithFormat("error: %s does not support senging signals to processes", GetShortPluginName());
2165        return error;
2166    }
2167
2168    virtual Error
2169    WillDestroy () { return Error(); }
2170
2171    virtual Error
2172    DoDestroy () = 0;
2173
2174    virtual void
2175    DidDestroy () { }
2176
2177
2178    //------------------------------------------------------------------
2179    /// Called after sending a signal to a process.
2180    ///
2181    /// Allow Process plug-ins to execute some code after sending a
2182    /// signal to a process.
2183    //------------------------------------------------------------------
2184    virtual void
2185    DidSignal () {}
2186
2187    //------------------------------------------------------------------
2188    /// Currently called as part of ShouldStop.
2189    /// FIXME: Should really happen when the target stops before the
2190    /// event is taken from the queue...
2191    ///
2192    /// This callback is called as the event
2193    /// is about to be queued up to allow Process plug-ins to execute
2194    /// some code prior to clients being notified that a process was
2195    /// stopped. Common operations include updating the thread list,
2196    /// invalidating any thread state (registers, stack, etc) prior to
2197    /// letting the notification go out.
2198    ///
2199    //------------------------------------------------------------------
2200    virtual void
2201    RefreshStateAfterStop () = 0;
2202
2203    //------------------------------------------------------------------
2204    /// Get the target object pointer for this module.
2205    ///
2206    /// @return
2207    ///     A Target object pointer to the target that owns this
2208    ///     module.
2209    //------------------------------------------------------------------
2210    Target &
2211    GetTarget ()
2212    {
2213        return m_target;
2214    }
2215
2216    //------------------------------------------------------------------
2217    /// Get the const target object pointer for this module.
2218    ///
2219    /// @return
2220    ///     A const Target object pointer to the target that owns this
2221    ///     module.
2222    //------------------------------------------------------------------
2223    const Target &
2224    GetTarget () const
2225    {
2226        return m_target;
2227    }
2228
2229
2230    //------------------------------------------------------------------
2231    /// Get accessor for the current process state.
2232    ///
2233    /// @return
2234    ///     The current state of the process.
2235    ///
2236    /// @see lldb::StateType
2237    //------------------------------------------------------------------
2238    lldb::StateType
2239    GetState ();
2240
2241    ExecutionResults
2242    RunThreadPlan (ExecutionContext &exe_ctx,
2243                    lldb::ThreadPlanSP &thread_plan_sp,
2244                    bool stop_others,
2245                    bool try_all_threads,
2246                    bool discard_on_error,
2247                    uint32_t single_thread_timeout_usec,
2248                    Stream &errors);
2249
2250    static const char *
2251    ExecutionResultAsCString (ExecutionResults result);
2252
2253    void
2254    GetStatus (Stream &ostrm);
2255
2256    size_t
2257    GetThreadStatus (Stream &ostrm,
2258                     bool only_threads_with_stop_reason,
2259                     uint32_t start_frame,
2260                     uint32_t num_frames,
2261                     uint32_t num_frames_with_source);
2262
2263protected:
2264
2265    void
2266    SetState (lldb::EventSP &event_sp);
2267
2268    lldb::StateType
2269    GetPrivateState ();
2270
2271    //------------------------------------------------------------------
2272    // Called internally
2273    //------------------------------------------------------------------
2274    void
2275    CompleteAttach ();
2276
2277public:
2278    //------------------------------------------------------------------
2279    /// Get the exit status for a process.
2280    ///
2281    /// @return
2282    ///     The process's return code, or -1 if the current process
2283    ///     state is not eStateExited.
2284    //------------------------------------------------------------------
2285    int
2286    GetExitStatus ();
2287
2288    //------------------------------------------------------------------
2289    /// Get a textual description of what the process exited.
2290    ///
2291    /// @return
2292    ///     The textual description of why the process exited, or NULL
2293    ///     if there is no description available.
2294    //------------------------------------------------------------------
2295    const char *
2296    GetExitDescription ();
2297
2298
2299    virtual void
2300    DidExit ()
2301    {
2302    }
2303
2304    //------------------------------------------------------------------
2305    /// Get the Modification ID of the process.
2306    ///
2307    /// @return
2308    ///     The modification ID of the process.
2309    //------------------------------------------------------------------
2310    ProcessModID
2311    GetModID () const
2312    {
2313        return m_mod_id;
2314    }
2315
2316    const ProcessModID &
2317    GetModIDRef () const
2318    {
2319        return m_mod_id;
2320    }
2321
2322    uint32_t
2323    GetStopID () const
2324    {
2325        return m_mod_id.GetStopID();
2326    }
2327
2328    uint32_t
2329    GetResumeID () const
2330    {
2331        return m_mod_id.GetResumeID();
2332    }
2333
2334    uint32_t
2335    GetLastUserExpressionResumeID () const
2336    {
2337        return m_mod_id.GetLastUserExpressionResumeID();
2338    }
2339
2340    //------------------------------------------------------------------
2341    /// Set accessor for the process exit status (return code).
2342    ///
2343    /// Sometimes a child exits and the exit can be detected by global
2344    /// functions (signal handler for SIGCHLD for example). This
2345    /// accessor allows the exit status to be set from an external
2346    /// source.
2347    ///
2348    /// Setting this will cause a eStateExited event to be posted to
2349    /// the process event queue.
2350    ///
2351    /// @param[in] exit_status
2352    ///     The value for the process's return code.
2353    ///
2354    /// @see lldb::StateType
2355    //------------------------------------------------------------------
2356    virtual bool
2357    SetExitStatus (int exit_status, const char *cstr);
2358
2359    //------------------------------------------------------------------
2360    /// Check if a process is still alive.
2361    ///
2362    /// @return
2363    ///     Returns \b true if the process is still valid, \b false
2364    ///     otherwise.
2365    //------------------------------------------------------------------
2366    virtual bool
2367    IsAlive () = 0;
2368
2369    //------------------------------------------------------------------
2370    /// Actually do the reading of memory from a process.
2371    ///
2372    /// Subclasses must override this function and can return fewer
2373    /// bytes than requested when memory requests are too large. This
2374    /// class will break up the memory requests and keep advancing the
2375    /// arguments along as needed.
2376    ///
2377    /// @param[in] vm_addr
2378    ///     A virtual load address that indicates where to start reading
2379    ///     memory from.
2380    ///
2381    /// @param[in] size
2382    ///     The number of bytes to read.
2383    ///
2384    /// @param[out] buf
2385    ///     A byte buffer that is at least \a size bytes long that
2386    ///     will receive the memory bytes.
2387    ///
2388    /// @return
2389    ///     The number of bytes that were actually read into \a buf.
2390    //------------------------------------------------------------------
2391    virtual size_t
2392    DoReadMemory (lldb::addr_t vm_addr,
2393                  void *buf,
2394                  size_t size,
2395                  Error &error) = 0;
2396
2397    //------------------------------------------------------------------
2398    /// Read of memory from a process.
2399    ///
2400    /// This function will read memory from the current process's
2401    /// address space and remove any traps that may have been inserted
2402    /// into the memory.
2403    ///
2404    /// This function is not meant to be overridden by Process
2405    /// subclasses, the subclasses should implement
2406    /// Process::DoReadMemory (lldb::addr_t, size_t, void *).
2407    ///
2408    /// @param[in] vm_addr
2409    ///     A virtual load address that indicates where to start reading
2410    ///     memory from.
2411    ///
2412    /// @param[out] buf
2413    ///     A byte buffer that is at least \a size bytes long that
2414    ///     will receive the memory bytes.
2415    ///
2416    /// @param[in] size
2417    ///     The number of bytes to read.
2418    ///
2419    /// @return
2420    ///     The number of bytes that were actually read into \a buf. If
2421    ///     the returned number is greater than zero, yet less than \a
2422    ///     size, then this function will get called again with \a
2423    ///     vm_addr, \a buf, and \a size updated appropriately. Zero is
2424    ///     returned to indicate an error.
2425    //------------------------------------------------------------------
2426    virtual size_t
2427    ReadMemory (lldb::addr_t vm_addr,
2428                void *buf,
2429                size_t size,
2430                Error &error);
2431
2432    //------------------------------------------------------------------
2433    /// Read a NULL terminated C string from memory
2434    ///
2435    /// This function will read a cache page at a time until the NULL
2436    /// C stirng terminator is found. It will stop reading if the NULL
2437    /// termination byte isn't found before reading \a cstr_max_len
2438    /// bytes, and the results are always guaranteed to be NULL
2439    /// terminated (at most cstr_max_len - 1 bytes will be read).
2440    //------------------------------------------------------------------
2441    size_t
2442    ReadCStringFromMemory (lldb::addr_t vm_addr,
2443                           char *cstr,
2444                           size_t cstr_max_len,
2445                           Error &error);
2446
2447    size_t
2448    ReadMemoryFromInferior (lldb::addr_t vm_addr,
2449                            void *buf,
2450                            size_t size,
2451                            Error &error);
2452
2453    //------------------------------------------------------------------
2454    /// Reads an unsigned integer of the specified byte size from
2455    /// process memory.
2456    ///
2457    /// @param[in] load_addr
2458    ///     A load address of the integer to read.
2459    ///
2460    /// @param[in] byte_size
2461    ///     The size in byte of the integer to read.
2462    ///
2463    /// @param[in] fail_value
2464    ///     The value to return if we fail to read an integer.
2465    ///
2466    /// @param[out] error
2467    ///     An error that indicates the success or failure of this
2468    ///     operation. If error indicates success (error.Success()),
2469    ///     then the value returned can be trusted, otherwise zero
2470    ///     will be returned.
2471    ///
2472    /// @return
2473    ///     The unsigned integer that was read from the process memory
2474    ///     space. If the integer was smaller than a uint64_t, any
2475    ///     unused upper bytes will be zero filled. If the process
2476    ///     byte order differs from the host byte order, the integer
2477    ///     value will be appropriately byte swapped into host byte
2478    ///     order.
2479    //------------------------------------------------------------------
2480    uint64_t
2481    ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
2482                                   size_t byte_size,
2483                                   uint64_t fail_value,
2484                                   Error &error);
2485
2486    lldb::addr_t
2487    ReadPointerFromMemory (lldb::addr_t vm_addr,
2488                           Error &error);
2489
2490    bool
2491    WritePointerToMemory (lldb::addr_t vm_addr,
2492                          lldb::addr_t ptr_value,
2493                          Error &error);
2494
2495    //------------------------------------------------------------------
2496    /// Actually do the writing of memory to a process.
2497    ///
2498    /// @param[in] vm_addr
2499    ///     A virtual load address that indicates where to start writing
2500    ///     memory to.
2501    ///
2502    /// @param[in] buf
2503    ///     A byte buffer that is at least \a size bytes long that
2504    ///     contains the data to write.
2505    ///
2506    /// @param[in] size
2507    ///     The number of bytes to write.
2508    ///
2509    /// @param[out] error
2510    ///     An error value in case the memory write fails.
2511    ///
2512    /// @return
2513    ///     The number of bytes that were actually written.
2514    //------------------------------------------------------------------
2515    virtual size_t
2516    DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error)
2517    {
2518        error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetShortPluginName());
2519        return 0;
2520    }
2521
2522
2523    //------------------------------------------------------------------
2524    /// Write all or part of a scalar value to memory.
2525    ///
2526    /// The value contained in \a scalar will be swapped to match the
2527    /// byte order of the process that is being debugged. If \a size is
2528    /// less than the size of scalar, the least significate \a size bytes
2529    /// from scalar will be written. If \a size is larger than the byte
2530    /// size of scalar, then the extra space will be padded with zeros
2531    /// and the scalar value will be placed in the least significant
2532    /// bytes in memory.
2533    ///
2534    /// @param[in] vm_addr
2535    ///     A virtual load address that indicates where to start writing
2536    ///     memory to.
2537    ///
2538    /// @param[in] scalar
2539    ///     The scalar to write to the debugged process.
2540    ///
2541    /// @param[in] size
2542    ///     This value can be smaller or larger than the scalar value
2543    ///     itself. If \a size is smaller than the size of \a scalar,
2544    ///     the least significant bytes in \a scalar will be used. If
2545    ///     \a size is larger than the byte size of \a scalar, then
2546    ///     the extra space will be padded with zeros. If \a size is
2547    ///     set to UINT32_MAX, then the size of \a scalar will be used.
2548    ///
2549    /// @param[out] error
2550    ///     An error value in case the memory write fails.
2551    ///
2552    /// @return
2553    ///     The number of bytes that were actually written.
2554    //------------------------------------------------------------------
2555    size_t
2556    WriteScalarToMemory (lldb::addr_t vm_addr,
2557                         const Scalar &scalar,
2558                         uint32_t size,
2559                         Error &error);
2560
2561    size_t
2562    ReadScalarIntegerFromMemory (lldb::addr_t addr,
2563                                 uint32_t byte_size,
2564                                 bool is_signed,
2565                                 Scalar &scalar,
2566                                 Error &error);
2567
2568    //------------------------------------------------------------------
2569    /// Write memory to a process.
2570    ///
2571    /// This function will write memory to the current process's
2572    /// address space and maintain any traps that might be present due
2573    /// to software breakpoints.
2574    ///
2575    /// This function is not meant to be overridden by Process
2576    /// subclasses, the subclasses should implement
2577    /// Process::DoWriteMemory (lldb::addr_t, size_t, void *).
2578    ///
2579    /// @param[in] vm_addr
2580    ///     A virtual load address that indicates where to start writing
2581    ///     memory to.
2582    ///
2583    /// @param[in] buf
2584    ///     A byte buffer that is at least \a size bytes long that
2585    ///     contains the data to write.
2586    ///
2587    /// @param[in] size
2588    ///     The number of bytes to write.
2589    ///
2590    /// @return
2591    ///     The number of bytes that were actually written.
2592    //------------------------------------------------------------------
2593    size_t
2594    WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error);
2595
2596
2597    //------------------------------------------------------------------
2598    /// Actually allocate memory in the process.
2599    ///
2600    /// This function will allocate memory in the process's address
2601    /// space.  This can't rely on the generic function calling mechanism,
2602    /// since that requires this function.
2603    ///
2604    /// @param[in] size
2605    ///     The size of the allocation requested.
2606    ///
2607    /// @return
2608    ///     The address of the allocated buffer in the process, or
2609    ///     LLDB_INVALID_ADDRESS if the allocation failed.
2610    //------------------------------------------------------------------
2611
2612    virtual lldb::addr_t
2613    DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
2614    {
2615        error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetShortPluginName());
2616        return LLDB_INVALID_ADDRESS;
2617    }
2618
2619
2620    //------------------------------------------------------------------
2621    /// The public interface to allocating memory in the process.
2622    ///
2623    /// This function will allocate memory in the process's address
2624    /// space.  This can't rely on the generic function calling mechanism,
2625    /// since that requires this function.
2626    ///
2627    /// @param[in] size
2628    ///     The size of the allocation requested.
2629    ///
2630    /// @param[in] permissions
2631    ///     Or together any of the lldb::Permissions bits.  The permissions on
2632    ///     a given memory allocation can't be changed after allocation.  Note
2633    ///     that a block that isn't set writable can still be written on from lldb,
2634    ///     just not by the process itself.
2635    ///
2636    /// @param[in/out] error
2637    ///     An error object to fill in if things go wrong.
2638    /// @return
2639    ///     The address of the allocated buffer in the process, or
2640    ///     LLDB_INVALID_ADDRESS if the allocation failed.
2641    //------------------------------------------------------------------
2642
2643    lldb::addr_t
2644    AllocateMemory (size_t size, uint32_t permissions, Error &error);
2645
2646    virtual Error
2647    GetMemoryRegionInfo (lldb::addr_t load_addr,
2648                        MemoryRegionInfo &range_info)
2649    {
2650        Error error;
2651        error.SetErrorString ("Process::GetMemoryRegionInfo() not supported");
2652        return error;
2653    }
2654
2655    lldb::ModuleSP
2656    ReadModuleFromMemory (const FileSpec& file_spec,
2657                          lldb::addr_t header_addr,
2658                          bool add_image_to_target,
2659                          bool load_sections_in_target);
2660
2661    //------------------------------------------------------------------
2662    /// Attempt to get the attributes for a region of memory in the process.
2663    ///
2664    /// It may be possible for the remote debug server to inspect attributes
2665    /// for a region of memory in the process, such as whether there is a
2666    /// valid page of memory at a given address or whether that page is
2667    /// readable/writable/executable by the process.
2668    ///
2669    /// @param[in] load_addr
2670    ///     The address of interest in the process.
2671    ///
2672    /// @param[out] permissions
2673    ///     If this call returns successfully, this bitmask will have
2674    ///     its Permissions bits set to indicate whether the region is
2675    ///     readable/writable/executable.  If this call fails, the
2676    ///     bitmask values are undefined.
2677    ///
2678    /// @return
2679    ///     Returns true if it was able to determine the attributes of the
2680    ///     memory region.  False if not.
2681    //------------------------------------------------------------------
2682
2683    virtual bool
2684    GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions)
2685    {
2686        MemoryRegionInfo range_info;
2687        permissions = 0;
2688        Error error (GetMemoryRegionInfo (load_addr, range_info));
2689        if (!error.Success())
2690            return false;
2691        if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow
2692            || range_info.GetWritable() == MemoryRegionInfo::eDontKnow
2693            || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow)
2694        {
2695            return false;
2696        }
2697
2698        if (range_info.GetReadable() == MemoryRegionInfo::eYes)
2699            permissions |= lldb::ePermissionsReadable;
2700
2701        if (range_info.GetWritable() == MemoryRegionInfo::eYes)
2702            permissions |= lldb::ePermissionsWritable;
2703
2704        if (range_info.GetExecutable() == MemoryRegionInfo::eYes)
2705            permissions |= lldb::ePermissionsExecutable;
2706
2707        return true;
2708    }
2709
2710    //------------------------------------------------------------------
2711    /// Determines whether executing JIT-compiled code in this process
2712    /// is possible.
2713    ///
2714    /// @return
2715    ///     True if execution of JIT code is possible; false otherwise.
2716    //------------------------------------------------------------------
2717    bool CanJIT ();
2718
2719    //------------------------------------------------------------------
2720    /// Sets whether executing JIT-compiled code in this process
2721    /// is possible.
2722    ///
2723    /// @param[in] can_jit
2724    ///     True if execution of JIT code is possible; false otherwise.
2725    //------------------------------------------------------------------
2726    void SetCanJIT (bool can_jit);
2727
2728    //------------------------------------------------------------------
2729    /// Actually deallocate memory in the process.
2730    ///
2731    /// This function will deallocate memory in the process's address
2732    /// space that was allocated with AllocateMemory.
2733    ///
2734    /// @param[in] ptr
2735    ///     A return value from AllocateMemory, pointing to the memory you
2736    ///     want to deallocate.
2737    ///
2738    /// @return
2739    ///     \btrue if the memory was deallocated, \bfalse otherwise.
2740    //------------------------------------------------------------------
2741
2742    virtual Error
2743    DoDeallocateMemory (lldb::addr_t ptr)
2744    {
2745        Error error;
2746        error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetShortPluginName());
2747        return error;
2748    }
2749
2750
2751    //------------------------------------------------------------------
2752    /// The public interface to deallocating memory in the process.
2753    ///
2754    /// This function will deallocate memory in the process's address
2755    /// space that was allocated with AllocateMemory.
2756    ///
2757    /// @param[in] ptr
2758    ///     A return value from AllocateMemory, pointing to the memory you
2759    ///     want to deallocate.
2760    ///
2761    /// @return
2762    ///     \btrue if the memory was deallocated, \bfalse otherwise.
2763    //------------------------------------------------------------------
2764
2765    Error
2766    DeallocateMemory (lldb::addr_t ptr);
2767
2768    //------------------------------------------------------------------
2769    /// Get any available STDOUT.
2770    ///
2771    /// If the process was launched without supplying valid file paths
2772    /// for stdin, stdout, and stderr, then the Process class might
2773    /// try to cache the STDOUT for the process if it is able. Events
2774    /// will be queued indicating that there is STDOUT available that
2775    /// can be retrieved using this function.
2776    ///
2777    /// @param[out] buf
2778    ///     A buffer that will receive any STDOUT bytes that are
2779    ///     currently available.
2780    ///
2781    /// @param[out] buf_size
2782    ///     The size in bytes for the buffer \a buf.
2783    ///
2784    /// @return
2785    ///     The number of bytes written into \a buf. If this value is
2786    ///     equal to \a buf_size, another call to this function should
2787    ///     be made to retrieve more STDOUT data.
2788    //------------------------------------------------------------------
2789    virtual size_t
2790    GetSTDOUT (char *buf, size_t buf_size, Error &error);
2791
2792    //------------------------------------------------------------------
2793    /// Get any available STDERR.
2794    ///
2795    /// If the process was launched without supplying valid file paths
2796    /// for stdin, stdout, and stderr, then the Process class might
2797    /// try to cache the STDERR for the process if it is able. Events
2798    /// will be queued indicating that there is STDERR available that
2799    /// can be retrieved using this function.
2800    ///
2801    /// @param[out] buf
2802    ///     A buffer that will receive any STDERR bytes that are
2803    ///     currently available.
2804    ///
2805    /// @param[out] buf_size
2806    ///     The size in bytes for the buffer \a buf.
2807    ///
2808    /// @return
2809    ///     The number of bytes written into \a buf. If this value is
2810    ///     equal to \a buf_size, another call to this function should
2811    ///     be made to retrieve more STDERR data.
2812    //------------------------------------------------------------------
2813    virtual size_t
2814    GetSTDERR (char *buf, size_t buf_size, Error &error);
2815
2816    virtual size_t
2817    PutSTDIN (const char *buf, size_t buf_size, Error &error)
2818    {
2819        error.SetErrorString("stdin unsupported");
2820        return 0;
2821    }
2822
2823    //----------------------------------------------------------------------
2824    // Process Breakpoints
2825    //----------------------------------------------------------------------
2826    size_t
2827    GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site);
2828
2829    virtual Error
2830    EnableBreakpoint (BreakpointSite *bp_site)
2831    {
2832        Error error;
2833        error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetShortPluginName());
2834        return error;
2835    }
2836
2837
2838    virtual Error
2839    DisableBreakpoint (BreakpointSite *bp_site)
2840    {
2841        Error error;
2842        error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetShortPluginName());
2843        return error;
2844    }
2845
2846
2847    // This is implemented completely using the lldb::Process API. Subclasses
2848    // don't need to implement this function unless the standard flow of
2849    // read existing opcode, write breakpoint opcode, verify breakpoint opcode
2850    // doesn't work for a specific process plug-in.
2851    virtual Error
2852    EnableSoftwareBreakpoint (BreakpointSite *bp_site);
2853
2854    // This is implemented completely using the lldb::Process API. Subclasses
2855    // don't need to implement this function unless the standard flow of
2856    // restoring original opcode in memory and verifying the restored opcode
2857    // doesn't work for a specific process plug-in.
2858    virtual Error
2859    DisableSoftwareBreakpoint (BreakpointSite *bp_site);
2860
2861    BreakpointSiteList &
2862    GetBreakpointSiteList();
2863
2864    const BreakpointSiteList &
2865    GetBreakpointSiteList() const;
2866
2867    void
2868    DisableAllBreakpointSites ();
2869
2870    Error
2871    ClearBreakpointSiteByID (lldb::user_id_t break_id);
2872
2873    lldb::break_id_t
2874    CreateBreakpointSite (const lldb::BreakpointLocationSP &owner,
2875                          bool use_hardware);
2876
2877    Error
2878    DisableBreakpointSiteByID (lldb::user_id_t break_id);
2879
2880    Error
2881    EnableBreakpointSiteByID (lldb::user_id_t break_id);
2882
2883
2884    // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove
2885    // themselves from the owner's list of this breakpoint sites.  This has to
2886    // be a static function because you can't be sure that removing the
2887    // breakpoint from it's containing map won't delete the breakpoint site,
2888    // and doing that in an instance method isn't copasetic.
2889    void
2890    RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id,
2891                                   lldb::user_id_t owner_loc_id,
2892                                   lldb::BreakpointSiteSP &bp_site_sp);
2893
2894    //----------------------------------------------------------------------
2895    // Process Watchpoints (optional)
2896    //----------------------------------------------------------------------
2897    virtual Error
2898    EnableWatchpoint (Watchpoint *wp);
2899
2900    virtual Error
2901    DisableWatchpoint (Watchpoint *wp);
2902
2903    //------------------------------------------------------------------
2904    // Thread Queries
2905    //------------------------------------------------------------------
2906    virtual uint32_t
2907    UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0;
2908
2909    void
2910    UpdateThreadListIfNeeded ();
2911
2912    ThreadList &
2913    GetThreadList ()
2914    {
2915        return m_thread_list;
2916    }
2917
2918
2919    uint32_t
2920    GetNextThreadIndexID ();
2921
2922    //------------------------------------------------------------------
2923    // Event Handling
2924    //------------------------------------------------------------------
2925    lldb::StateType
2926    GetNextEvent (lldb::EventSP &event_sp);
2927
2928    lldb::StateType
2929    WaitForProcessToStop (const TimeValue *timeout);
2930
2931    lldb::StateType
2932    WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp);
2933
2934    Event *
2935    PeekAtStateChangedEvents ();
2936
2937
2938    class
2939    ProcessEventHijacker
2940    {
2941    public:
2942        ProcessEventHijacker (Process &process, Listener *listener) :
2943            m_process (process),
2944            m_listener (listener)
2945        {
2946            m_process.HijackProcessEvents (listener);
2947        }
2948        ~ProcessEventHijacker ()
2949        {
2950            m_process.RestoreProcessEvents();
2951        }
2952
2953    private:
2954        Process &m_process;
2955        Listener *m_listener;
2956    };
2957    friend class ProcessEventHijacker;
2958    //------------------------------------------------------------------
2959    /// If you need to ensure that you and only you will hear about some public
2960    /// event, then make a new listener, set to listen to process events, and
2961    /// then call this with that listener.  Then you will have to wait on that
2962    /// listener explicitly for events (rather than using the GetNextEvent & WaitFor*
2963    /// calls above.  Be sure to call RestoreProcessEvents when you are done.
2964    ///
2965    /// @param[in] listener
2966    ///     This is the new listener to whom all process events will be delivered.
2967    ///
2968    /// @return
2969    ///     Returns \b true if the new listener could be installed,
2970    ///     \b false otherwise.
2971    //------------------------------------------------------------------
2972    bool
2973    HijackProcessEvents (Listener *listener);
2974
2975    //------------------------------------------------------------------
2976    /// Restores the process event broadcasting to its normal state.
2977    ///
2978    //------------------------------------------------------------------
2979    void
2980    RestoreProcessEvents ();
2981
2982protected:
2983    //------------------------------------------------------------------
2984    /// This is the part of the event handling that for a process event.
2985    /// It decides what to do with the event and returns true if the
2986    /// event needs to be propagated to the user, and false otherwise.
2987    /// If the event is not propagated, this call will most likely set
2988    /// the target to executing again.
2989    ///
2990    /// @param[in] event_ptr
2991    ///     This is the event we are handling.
2992    ///
2993    /// @return
2994    ///     Returns \b true if the event should be reported to the
2995    ///     user, \b false otherwise.
2996    //------------------------------------------------------------------
2997    bool
2998    ShouldBroadcastEvent (Event *event_ptr);
2999
3000public:
3001    const lldb::ABISP &
3002    GetABI ();
3003
3004    OperatingSystem *
3005    GetOperatingSystem ()
3006    {
3007        return m_os_ap.get();
3008    }
3009
3010
3011    virtual LanguageRuntime *
3012    GetLanguageRuntime (lldb::LanguageType language);
3013
3014    virtual CPPLanguageRuntime *
3015    GetCPPLanguageRuntime ();
3016
3017    virtual ObjCLanguageRuntime *
3018    GetObjCLanguageRuntime ();
3019
3020    bool
3021    IsRunning () const;
3022
3023    DynamicCheckerFunctions *GetDynamicCheckers()
3024    {
3025        return m_dynamic_checkers_ap.get();
3026    }
3027
3028    void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers)
3029    {
3030        m_dynamic_checkers_ap.reset(dynamic_checkers);
3031    }
3032
3033    //------------------------------------------------------------------
3034    /// Call this to set the lldb in the mode where it breaks on new thread
3035    /// creations, and then auto-restarts.  This is useful when you are trying
3036    /// to run only one thread, but either that thread or the kernel is creating
3037    /// new threads in the process.  If you stop when the thread is created, you
3038    /// can immediately suspend it, and keep executing only the one thread you intend.
3039    ///
3040    /// @return
3041    ///     Returns \b true if we were able to start up the notification
3042    ///     \b false otherwise.
3043    //------------------------------------------------------------------
3044    virtual bool
3045    StartNoticingNewThreads()
3046    {
3047        return true;
3048    }
3049
3050    //------------------------------------------------------------------
3051    /// Call this to turn off the stop & notice new threads mode.
3052    ///
3053    /// @return
3054    ///     Returns \b true if we were able to start up the notification
3055    ///     \b false otherwise.
3056    //------------------------------------------------------------------
3057    virtual bool
3058    StopNoticingNewThreads()
3059    {
3060        return true;
3061    }
3062
3063    void
3064    SetRunningUserExpression (bool on);
3065
3066    //------------------------------------------------------------------
3067    // lldb::ExecutionContextScope pure virtual functions
3068    //------------------------------------------------------------------
3069    virtual lldb::TargetSP
3070    CalculateTarget ();
3071
3072    virtual lldb::ProcessSP
3073    CalculateProcess ()
3074    {
3075        return shared_from_this();
3076    }
3077
3078    virtual lldb::ThreadSP
3079    CalculateThread ()
3080    {
3081        return lldb::ThreadSP();
3082    }
3083
3084    virtual lldb::StackFrameSP
3085    CalculateStackFrame ()
3086    {
3087        return lldb::StackFrameSP();
3088    }
3089
3090    virtual void
3091    CalculateExecutionContext (ExecutionContext &exe_ctx);
3092
3093    void
3094    SetSTDIOFileDescriptor (int file_descriptor);
3095
3096    //------------------------------------------------------------------
3097    // Add a permanent region of memory that should never be read or
3098    // written to. This can be used to ensure that memory reads or writes
3099    // to certain areas of memory never end up being sent to the
3100    // DoReadMemory or DoWriteMemory functions which can improve
3101    // performance.
3102    //------------------------------------------------------------------
3103    void
3104    AddInvalidMemoryRegion (const LoadRange &region);
3105
3106    //------------------------------------------------------------------
3107    // Remove a permanent region of memory that should never be read or
3108    // written to that was previously added with AddInvalidMemoryRegion.
3109    //------------------------------------------------------------------
3110    bool
3111    RemoveInvalidMemoryRange (const LoadRange &region);
3112
3113protected:
3114    //------------------------------------------------------------------
3115    // NextEventAction provides a way to register an action on the next
3116    // event that is delivered to this process.  There is currently only
3117    // one next event action allowed in the process at one time.  If a
3118    // new "NextEventAction" is added while one is already present, the
3119    // old action will be discarded (with HandleBeingUnshipped called
3120    // after it is discarded.)
3121    //------------------------------------------------------------------
3122    class NextEventAction
3123    {
3124    public:
3125        typedef enum EventActionResult
3126        {
3127            eEventActionSuccess,
3128            eEventActionRetry,
3129            eEventActionExit
3130        } EventActionResult;
3131
3132        NextEventAction (Process *process) :
3133            m_process(process)
3134        {
3135        }
3136
3137        virtual
3138        ~NextEventAction()
3139        {
3140        }
3141
3142        virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0;
3143        virtual void HandleBeingUnshipped () {};
3144        virtual EventActionResult HandleBeingInterrupted () = 0;
3145        virtual const char *GetExitString() = 0;
3146    protected:
3147        Process *m_process;
3148    };
3149
3150    void SetNextEventAction (Process::NextEventAction *next_event_action)
3151    {
3152        if (m_next_event_action_ap.get())
3153            m_next_event_action_ap->HandleBeingUnshipped();
3154
3155        m_next_event_action_ap.reset(next_event_action);
3156    }
3157
3158    // This is the completer for Attaching:
3159    class AttachCompletionHandler : public NextEventAction
3160    {
3161    public:
3162        AttachCompletionHandler (Process *process, uint32_t exec_count) :
3163            NextEventAction (process),
3164            m_exec_count (exec_count)
3165        {
3166        }
3167
3168        virtual
3169        ~AttachCompletionHandler()
3170        {
3171        }
3172
3173        virtual EventActionResult PerformAction (lldb::EventSP &event_sp);
3174        virtual EventActionResult HandleBeingInterrupted ();
3175        virtual const char *GetExitString();
3176    private:
3177        uint32_t m_exec_count;
3178        std::string m_exit_string;
3179    };
3180
3181    bool
3182    HijackPrivateProcessEvents (Listener *listener);
3183
3184    void
3185    RestorePrivateProcessEvents ();
3186
3187    bool
3188    PrivateStateThreadIsValid () const
3189    {
3190        return m_private_state_thread != LLDB_INVALID_HOST_THREAD;
3191    }
3192
3193    //------------------------------------------------------------------
3194    // Member variables
3195    //------------------------------------------------------------------
3196    Target &                    m_target;               ///< The target that owns this process.
3197    ThreadSafeValue<lldb::StateType>  m_public_state;
3198    ThreadSafeValue<lldb::StateType>  m_private_state; // The actual state of our process
3199    Broadcaster                 m_private_state_broadcaster;  // This broadcaster feeds state changed events into the private state thread's listener.
3200    Broadcaster                 m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread.
3201    Listener                    m_private_state_listener;     // This is the listener for the private state thread.
3202    Predicate<bool>             m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete.
3203    lldb::thread_t              m_private_state_thread;  // Thread ID for the thread that watches interal state events
3204    ProcessModID                m_mod_id;              ///< Tracks the state of the process over stops and other alterations.
3205    uint32_t                    m_thread_index_id;      ///< Each thread is created with a 1 based index that won't get re-used.
3206    int                         m_exit_status;          ///< The exit status of the process, or -1 if not set.
3207    std::string                 m_exit_string;          ///< A textual description of why a process exited.
3208    ThreadList                  m_thread_list;          ///< The threads for this process.
3209    std::vector<Notifications>  m_notifications;        ///< The list of notifications that this process can deliver.
3210    std::vector<lldb::addr_t>   m_image_tokens;
3211    Listener                    &m_listener;
3212    BreakpointSiteList          m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend
3213                                                        ///< to insert in the target.
3214    std::auto_ptr<DynamicLoader> m_dyld_ap;
3215    std::auto_ptr<DynamicCheckerFunctions>  m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use.
3216    std::auto_ptr<OperatingSystem>     m_os_ap;
3217    UnixSignals                 m_unix_signals;         /// This is the current signal set for this process.
3218    lldb::ABISP                 m_abi_sp;
3219    lldb::InputReaderSP         m_process_input_reader;
3220    lldb_private::Communication m_stdio_communication;
3221    lldb_private::Mutex         m_stdio_communication_mutex;
3222    std::string                 m_stdout_data;
3223    std::string                 m_stderr_data;
3224    MemoryCache                 m_memory_cache;
3225    AllocatedMemoryCache        m_allocated_memory_cache;
3226    bool                        m_should_detach;   /// Should we detach if the process object goes away with an explicit call to Kill or Detach?
3227
3228    typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection;
3229    LanguageRuntimeCollection m_language_runtimes;
3230    std::auto_ptr<NextEventAction> m_next_event_action_ap;
3231
3232    enum {
3233        eCanJITDontKnow= 0,
3234        eCanJITYes,
3235        eCanJITNo
3236    } m_can_jit;
3237
3238    size_t
3239    RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const;
3240
3241    void
3242    SynchronouslyNotifyStateChanged (lldb::StateType state);
3243
3244    void
3245    SetPublicState (lldb::StateType new_state);
3246
3247    void
3248    SetPrivateState (lldb::StateType state);
3249
3250    bool
3251    StartPrivateStateThread ();
3252
3253    void
3254    StopPrivateStateThread ();
3255
3256    void
3257    PausePrivateStateThread ();
3258
3259    void
3260    ResumePrivateStateThread ();
3261
3262    static void *
3263    PrivateStateThread (void *arg);
3264
3265    void *
3266    RunPrivateStateThread ();
3267
3268    void
3269    HandlePrivateEvent (lldb::EventSP &event_sp);
3270
3271    lldb::StateType
3272    WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
3273
3274    // This waits for both the state change broadcaster, and the control broadcaster.
3275    // If control_only, it only waits for the control broadcaster.
3276
3277    bool
3278    WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only);
3279
3280    lldb::StateType
3281    WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
3282
3283    lldb::StateType
3284    WaitForState (const TimeValue *timeout,
3285                  const lldb::StateType *match_states,
3286                  const uint32_t num_match_states);
3287
3288    size_t
3289    WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error);
3290
3291    void
3292    AppendSTDOUT (const char *s, size_t len);
3293
3294    void
3295    AppendSTDERR (const char *s, size_t len);
3296
3297    static void
3298    STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
3299
3300    void
3301    PushProcessInputReader ();
3302
3303    void
3304    PopProcessInputReader ();
3305
3306    void
3307    ResetProcessInputReader ();
3308
3309    static size_t
3310    ProcessInputReaderCallback (void *baton,
3311                                InputReader &reader,
3312                                lldb::InputReaderAction notification,
3313                                const char *bytes,
3314                                size_t bytes_len);
3315
3316
3317private:
3318    //------------------------------------------------------------------
3319    // For Process only
3320    //------------------------------------------------------------------
3321    void ControlPrivateStateThread (uint32_t signal);
3322
3323    DISALLOW_COPY_AND_ASSIGN (Process);
3324
3325};
3326
3327} // namespace lldb_private
3328
3329#endif  // liblldb_Process_h_
3330