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