1 //===-- Process.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Process_h_
11 #define liblldb_Process_h_
13 #include "lldb/Host/Config.h"
23 // Other libraries and framework includes
25 #include "lldb/lldb-private.h"
26 #include "lldb/Core/ArchSpec.h"
27 #include "lldb/Core/Broadcaster.h"
28 #include "lldb/Core/Communication.h"
29 #include "lldb/Core/Error.h"
30 #include "lldb/Core/Event.h"
31 #include "lldb/Core/RangeMap.h"
32 #include "lldb/Core/StringList.h"
33 #include "lldb/Core/ThreadSafeValue.h"
34 #include "lldb/Core/PluginInterface.h"
35 #include "lldb/Core/UserSettingsController.h"
36 #include "lldb/Breakpoint/BreakpointSiteList.h"
37 #include "lldb/Expression/ClangPersistentVariables.h"
38 #include "lldb/Expression/IRDynamicChecks.h"
39 #include "lldb/Host/FileSpec.h"
40 #include "lldb/Host/Host.h"
41 #include "lldb/Host/HostThread.h"
42 #include "lldb/Host/ProcessRunLock.h"
43 #include "lldb/Interpreter/Args.h"
44 #include "lldb/Interpreter/Options.h"
45 #include "lldb/Target/ExecutionContextScope.h"
46 #include "lldb/Target/JITLoaderList.h"
47 #include "lldb/Target/Memory.h"
48 #include "lldb/Target/MemoryRegionInfo.h"
49 #include "lldb/Target/ProcessInfo.h"
50 #include "lldb/Target/ProcessLaunchInfo.h"
51 #include "lldb/Target/QueueList.h"
52 #include "lldb/Target/ThreadList.h"
53 #include "lldb/Target/UnixSignals.h"
54 #include "lldb/Utility/PseudoTerminal.h"
55 #include "lldb/Target/InstrumentationRuntime.h"
57 namespace lldb_private {
59 //----------------------------------------------------------------------
61 //----------------------------------------------------------------------
62 class ProcessProperties : public Properties
65 // Pass NULL for "process" if the ProcessProperties are to be the global copy
66 ProcessProperties (lldb_private::Process *process);
72 GetDisableMemoryCache() const;
75 GetMemoryCacheLineSize () const;
78 GetExtraStartupCommands () const;
81 SetExtraStartupCommands (const Args &args);
84 GetPythonOSPluginPath () const;
87 SetPythonOSPluginPath (const FileSpec &file);
90 GetIgnoreBreakpointsInExpressions () const;
93 SetIgnoreBreakpointsInExpressions (bool ignore);
96 GetUnwindOnErrorInExpressions () const;
99 SetUnwindOnErrorInExpressions (bool ignore);
102 GetStopOnSharedLibraryEvents () const;
105 SetStopOnSharedLibraryEvents (bool stop);
108 GetDetachKeepsStopped () const;
111 SetDetachKeepsStopped (bool keep_stopped);
116 OptionValueChangedCallback (void *baton, OptionValue *option_value);
118 Process * m_process; // Can be NULL for global ProcessProperties
121 typedef std::shared_ptr<ProcessProperties> ProcessPropertiesSP;
123 //----------------------------------------------------------------------
124 // ProcessInstanceInfo
126 // Describes an existing process and any discoverable information that
127 // pertains to that process.
128 //----------------------------------------------------------------------
129 class ProcessInstanceInfo : public ProcessInfo
132 ProcessInstanceInfo () :
136 m_parent_pid (LLDB_INVALID_PROCESS_ID)
140 ProcessInstanceInfo (const char *name,
141 const ArchSpec &arch,
143 ProcessInfo (name, arch, pid),
146 m_parent_pid (LLDB_INVALID_PROCESS_ID)
153 ProcessInfo::Clear();
156 m_parent_pid = LLDB_INVALID_PROCESS_ID;
160 GetEffectiveUserID() const
166 GetEffectiveGroupID() const
172 EffectiveUserIDIsValid () const
174 return m_euid != UINT32_MAX;
178 EffectiveGroupIDIsValid () const
180 return m_egid != UINT32_MAX;
184 SetEffectiveUserID (uint32_t uid)
190 SetEffectiveGroupID (uint32_t gid)
196 GetParentProcessID () const
202 SetParentProcessID (lldb::pid_t pid)
208 ParentProcessIDIsValid() const
210 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
214 Dump (Stream &s, Platform *platform) const;
217 DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose);
220 DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const;
225 lldb::pid_t m_parent_pid;
228 //----------------------------------------------------------------------
231 // Describes any information that is required to attach to a process.
232 //----------------------------------------------------------------------
234 class ProcessAttachInfo : public ProcessInstanceInfo
237 ProcessAttachInfo() :
238 ProcessInstanceInfo(),
240 m_hijack_listener_sp(),
243 m_wait_for_launch (false),
244 m_ignore_existing (true),
245 m_continue_once_attached (false),
246 m_detach_on_error (true)
250 ProcessAttachInfo (const ProcessLaunchInfo &launch_info) :
251 ProcessInstanceInfo(),
253 m_hijack_listener_sp(),
256 m_wait_for_launch (false),
257 m_ignore_existing (true),
258 m_continue_once_attached (false),
259 m_detach_on_error(true)
261 ProcessInfo::operator= (launch_info);
262 SetProcessPluginName (launch_info.GetProcessPluginName());
263 SetResumeCount (launch_info.GetResumeCount());
264 SetListener(launch_info.GetListener());
265 SetHijackListener(launch_info.GetHijackListener());
266 m_detach_on_error = launch_info.GetDetachOnError();
270 GetWaitForLaunch () const
272 return m_wait_for_launch;
276 SetWaitForLaunch (bool b)
278 m_wait_for_launch = b;
282 GetIgnoreExisting () const
284 return m_ignore_existing;
288 SetIgnoreExisting (bool b)
290 m_ignore_existing = b;
294 GetContinueOnceAttached () const
296 return m_continue_once_attached;
300 SetContinueOnceAttached (bool b)
302 m_continue_once_attached = b;
306 GetResumeCount () const
308 return m_resume_count;
312 SetResumeCount (uint32_t c)
318 GetProcessPluginName () const
320 if (m_plugin_name.empty())
322 return m_plugin_name.c_str();
326 SetProcessPluginName (const char *plugin)
328 if (plugin && plugin[0])
329 m_plugin_name.assign (plugin);
331 m_plugin_name.clear();
337 ProcessInstanceInfo::Clear();
338 m_plugin_name.clear();
340 m_wait_for_launch = false;
341 m_ignore_existing = true;
342 m_continue_once_attached = false;
346 ProcessInfoSpecified () const
348 if (GetExecutableFile())
350 if (GetProcessID() != LLDB_INVALID_PROCESS_ID)
352 if (GetParentProcessID() != LLDB_INVALID_PROCESS_ID)
358 GetHijackListener () const
360 return m_hijack_listener_sp;
364 SetHijackListener (const lldb::ListenerSP &listener_sp)
366 m_hijack_listener_sp = listener_sp;
370 GetDetachOnError () const
372 return m_detach_on_error;
376 SetDetachOnError (bool enable)
378 m_detach_on_error = enable;
381 // Get and set the actual listener that will be used for the process events
385 return m_listener_sp;
389 SetListener (const lldb::ListenerSP &listener_sp)
391 m_listener_sp = listener_sp;
396 GetListenerForProcess (Debugger &debugger);
399 lldb::ListenerSP m_listener_sp;
400 lldb::ListenerSP m_hijack_listener_sp;
401 std::string m_plugin_name;
402 uint32_t m_resume_count; // How many times do we resume after launching
403 bool m_wait_for_launch;
404 bool m_ignore_existing;
405 bool m_continue_once_attached; // Supports the use-case scenario of immediately continuing the process once attached.
406 bool m_detach_on_error; // If we are debugging remotely, instruct the stub to detach rather than killing the target on error.
409 class ProcessLaunchCommandOptions : public Options
413 ProcessLaunchCommandOptions (CommandInterpreter &interpreter) :
416 // Keep default values of all options in one place: OptionParsingStarting ()
417 OptionParsingStarting ();
420 ~ProcessLaunchCommandOptions ()
425 SetOptionValue (uint32_t option_idx, const char *option_arg);
428 OptionParsingStarting ()
431 disable_aslr = eLazyBoolCalculate;
434 const OptionDefinition*
437 return g_option_table;
440 // Options table: Required for subclasses of Options.
442 static OptionDefinition g_option_table[];
444 // Instance variables to hold the values for command options.
446 ProcessLaunchInfo launch_info;
447 lldb_private::LazyBool disable_aslr;
450 //----------------------------------------------------------------------
451 // ProcessInstanceInfoMatch
453 // A class to help matching one ProcessInstanceInfo to another.
454 //----------------------------------------------------------------------
456 class ProcessInstanceInfoMatch
459 ProcessInstanceInfoMatch () :
461 m_name_match_type (eNameMatchIgnore),
462 m_match_all_users (false)
466 ProcessInstanceInfoMatch (const char *process_name,
467 NameMatchType process_name_match_type) :
469 m_name_match_type (process_name_match_type),
470 m_match_all_users (false)
472 m_match_info.GetExecutableFile().SetFile(process_name, false);
475 ProcessInstanceInfo &
481 const ProcessInstanceInfo &
482 GetProcessInfo () const
488 GetMatchAllUsers () const
490 return m_match_all_users;
494 SetMatchAllUsers (bool b)
496 m_match_all_users = b;
500 GetNameMatchType () const
502 return m_name_match_type;
506 SetNameMatchType (NameMatchType name_match_type)
508 m_name_match_type = name_match_type;
512 NameMatches (const char *process_name) const;
515 Matches (const ProcessInstanceInfo &proc_info) const;
518 MatchAllProcesses () const;
523 ProcessInstanceInfo m_match_info;
524 NameMatchType m_name_match_type;
525 bool m_match_all_users;
528 class ProcessInstanceInfoList
531 ProcessInstanceInfoList () :
545 return m_infos.size();
549 Append (const ProcessInstanceInfo &info)
551 m_infos.push_back (info);
555 GetProcessNameAtIndex (size_t idx)
557 if (idx < m_infos.size())
558 return m_infos[idx].GetName();
563 GetProcessNameLengthAtIndex (size_t idx)
565 if (idx < m_infos.size())
566 return m_infos[idx].GetNameLength();
571 GetProcessIDAtIndex (size_t idx)
573 if (idx < m_infos.size())
574 return m_infos[idx].GetProcessID();
579 GetInfoAtIndex (size_t idx, ProcessInstanceInfo &info)
581 if (idx < m_infos.size())
589 // You must ensure "idx" is valid before calling this function
590 const ProcessInstanceInfo &
591 GetProcessInfoAtIndex (size_t idx) const
593 assert (idx < m_infos.size());
598 typedef std::vector<ProcessInstanceInfo> collection;
603 // This class tracks the Modification state of the process. Things that can currently modify
604 // the program are running the program (which will up the StopID) and writing memory (which
605 // will up the MemoryID.)
606 // FIXME: Should we also include modification of register states?
610 friend bool operator== (const ProcessModID &lhs, const ProcessModID &rhs);
614 m_last_natural_stop_id(0),
617 m_last_user_expression_resume (0),
618 m_running_user_expression (false)
621 ProcessModID (const ProcessModID &rhs) :
622 m_stop_id (rhs.m_stop_id),
623 m_memory_id (rhs.m_memory_id)
626 const ProcessModID & operator= (const ProcessModID &rhs)
630 m_stop_id = rhs.m_stop_id;
631 m_memory_id = rhs.m_memory_id;
640 if (!IsLastResumeForUserExpression())
641 m_last_natural_stop_id++;
644 void BumpMemoryID () { m_memory_id++; }
646 void BumpResumeID () {
648 if (m_running_user_expression > 0)
649 m_last_user_expression_resume = m_resume_id;
652 uint32_t GetStopID() const { return m_stop_id; }
653 uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; }
654 uint32_t GetMemoryID () const { return m_memory_id; }
655 uint32_t GetResumeID () const { return m_resume_id; }
656 uint32_t GetLastUserExpressionResumeID () const { return m_last_user_expression_resume; }
658 bool MemoryIDEqual (const ProcessModID &compare) const
660 return m_memory_id == compare.m_memory_id;
663 bool StopIDEqual (const ProcessModID &compare) const
665 return m_stop_id == compare.m_stop_id;
670 m_stop_id = UINT32_MAX;
673 bool IsValid () const
675 return m_stop_id != UINT32_MAX;
679 IsLastResumeForUserExpression () const
681 return m_resume_id == m_last_user_expression_resume;
685 SetRunningUserExpression (bool on)
687 // REMOVEME printf ("Setting running user expression %s at resume id %d - value: %d.\n", on ? "on" : "off", m_resume_id, m_running_user_expression);
689 m_running_user_expression++;
691 m_running_user_expression--;
696 uint32_t m_last_natural_stop_id;
697 uint32_t m_resume_id;
698 uint32_t m_memory_id;
699 uint32_t m_last_user_expression_resume;
700 uint32_t m_running_user_expression;
702 inline bool operator== (const ProcessModID &lhs, const ProcessModID &rhs)
704 if (lhs.StopIDEqual (rhs)
705 && lhs.MemoryIDEqual (rhs))
711 inline bool operator!= (const ProcessModID &lhs, const ProcessModID &rhs)
713 if (!lhs.StopIDEqual (rhs)
714 || !lhs.MemoryIDEqual (rhs))
720 //----------------------------------------------------------------------
721 /// @class Process Process.h "lldb/Target/Process.h"
722 /// @brief A plug-in interface definition class for debugging a process.
723 //----------------------------------------------------------------------
725 public std::enable_shared_from_this<Process>,
726 public ProcessProperties,
729 public ExecutionContextScope,
730 public PluginInterface
732 friend class ClangFunction; // For WaitForStateChangeEventsPrivate
733 friend class Debugger; // For PopProcessIOHandler and ProcessIOHandlerIsActive
734 friend class ProcessEventData;
735 friend class StopInfo;
737 friend class ThreadList;
741 //------------------------------------------------------------------
742 /// Broadcaster event bits definitions.
743 //------------------------------------------------------------------
746 eBroadcastBitStateChanged = (1 << 0),
747 eBroadcastBitInterrupt = (1 << 1),
748 eBroadcastBitSTDOUT = (1 << 2),
749 eBroadcastBitSTDERR = (1 << 3),
750 eBroadcastBitProfileData = (1 << 4)
755 eBroadcastInternalStateControlStop = (1<<0),
756 eBroadcastInternalStateControlPause = (1<<1),
757 eBroadcastInternalStateControlResume = (1<<2)
760 typedef Range<lldb::addr_t, lldb::addr_t> LoadRange;
761 // We use a read/write lock to allow on or more clients to
762 // access the process state while the process is stopped (reader).
763 // We lock the write lock to control access to the process
764 // while it is running (readers, or clients that want the process
765 // stopped can block waiting for the process to stop, or just
766 // try to lock it to see if they can immediately access the stopped
767 // process. If the try read lock fails, then the process is running.
768 typedef ProcessRunLock::ProcessRunLocker StopLocker;
770 // These two functions fill out the Broadcaster interface:
772 static ConstString &GetStaticBroadcasterClass ();
774 virtual ConstString &GetBroadcasterClass() const
776 return GetStaticBroadcasterClass();
780 //------------------------------------------------------------------
781 /// A notification structure that can be used by clients to listen
782 /// for changes in a process's lifetime.
784 /// @see RegisterNotificationCallbacks (const Notifications&)
785 /// @see UnregisterNotificationCallbacks (const Notifications&)
786 //------------------------------------------------------------------
791 void (*initialize)(void *baton, Process *process);
792 void (*process_state_changed) (void *baton, Process *process, lldb::StateType state);
795 class ProcessEventData :
798 friend class Process;
802 ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state);
804 virtual ~ProcessEventData();
806 static const ConstString &
809 virtual const ConstString &
812 const lldb::ProcessSP &
823 GetRestarted () const
829 GetNumRestartedReasons ()
831 return m_restarted_reasons.size();
835 GetRestartedReasonAtIndex(size_t idx)
837 if (idx > m_restarted_reasons.size())
840 return m_restarted_reasons[idx].c_str();
844 GetInterrupted () const
846 return m_interrupted;
850 Dump (Stream *s) const;
853 DoOnRemoval (Event *event_ptr);
855 static const Process::ProcessEventData *
856 GetEventDataFromEvent (const Event *event_ptr);
858 static lldb::ProcessSP
859 GetProcessFromEvent (const Event *event_ptr);
861 static lldb::StateType
862 GetStateFromEvent (const Event *event_ptr);
865 GetRestartedFromEvent (const Event *event_ptr);
868 GetNumRestartedReasons(const Event *event_ptr);
871 GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx);
874 AddRestartedReason (Event *event_ptr, const char *reason);
877 SetRestartedInEvent (Event *event_ptr, bool new_value);
880 GetInterruptedFromEvent (const Event *event_ptr);
883 SetInterruptedInEvent (Event *event_ptr, bool new_value);
886 SetUpdateStateOnRemoval (Event *event_ptr);
891 SetUpdateStateOnRemoval()
896 SetRestarted (bool new_value)
898 m_restarted = new_value;
901 SetInterrupted (bool new_value)
903 m_interrupted = new_value;
906 AddRestartedReason (const char *reason)
908 m_restarted_reasons.push_back(reason);
911 lldb::ProcessSP m_process_sp;
912 lldb::StateType m_state;
913 std::vector<std::string> m_restarted_reasons;
914 bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted.
917 DISALLOW_COPY_AND_ASSIGN (ProcessEventData);
924 SettingsInitialize ();
927 SettingsTerminate ();
929 static const ProcessPropertiesSP &
930 GetGlobalProperties();
932 //------------------------------------------------------------------
933 /// Construct with a shared pointer to a target, and the Process listener.
934 /// Uses the Host UnixSignalsSP by default.
935 //------------------------------------------------------------------
936 Process(Target &target, Listener &listener);
938 //------------------------------------------------------------------
939 /// Construct with a shared pointer to a target, the Process listener,
940 /// and the appropriate UnixSignalsSP for the process.
941 //------------------------------------------------------------------
942 Process(Target &target, Listener &listener, const UnixSignalsSP &unix_signals_sp);
944 //------------------------------------------------------------------
947 /// The destructor is virtual since this class is designed to be
948 /// inherited from by the plug-in instance.
949 //------------------------------------------------------------------
953 //------------------------------------------------------------------
954 /// Find a Process plug-in that can debug \a module using the
955 /// currently selected architecture.
957 /// Scans all loaded plug-in interfaces that implement versions of
958 /// the Process plug-in interface and returns the first instance
959 /// that can debug the file.
961 /// @param[in] module_sp
962 /// The module shared pointer that this process will debug.
964 /// @param[in] plugin_name
965 /// If NULL, select the best plug-in for the binary. If non-NULL
966 /// then look for a plugin whose PluginInfo's name matches
969 /// @see Process::CanDebug ()
970 //------------------------------------------------------------------
971 static lldb::ProcessSP
972 FindPlugin (Target &target,
973 const char *plugin_name,
975 const FileSpec *crash_file_path);
979 //------------------------------------------------------------------
980 /// Static function that can be used with the \b host function
981 /// Host::StartMonitoringChildProcess ().
983 /// This function can be used by lldb_private::Process subclasses
984 /// when they want to watch for a local process and have its exit
985 /// status automatically set when the host child process exits.
986 /// Subclasses should call Host::StartMonitoringChildProcess ()
988 /// callback = Process::SetHostProcessExitStatus
989 /// callback_baton = NULL
990 /// pid = Process::GetID()
991 /// monitor_signals = false
992 //------------------------------------------------------------------
994 SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL
995 lldb::pid_t pid, // The process ID we want to monitor
997 int signo, // Zero for no signal
998 int status); // Exit value of process if signal is zero
1001 GetByteOrder () const;
1004 GetAddressByteSize () const;
1009 return m_process_unique_id;
1011 //------------------------------------------------------------------
1012 /// Check if a plug-in instance can debug the file in \a module.
1014 /// Each plug-in is given a chance to say whether it can debug
1015 /// the file in \a module. If the Process plug-in instance can
1016 /// debug a file on the current system, it should return \b true.
1019 /// Returns \b true if this Process plug-in instance can
1020 /// debug the executable, \b false otherwise.
1021 //------------------------------------------------------------------
1023 CanDebug (Target &target,
1024 bool plugin_specified_by_name) = 0;
1027 //------------------------------------------------------------------
1028 /// This object is about to be destroyed, do any necessary cleanup.
1030 /// Subclasses that override this method should always call this
1031 /// superclass method.
1032 //------------------------------------------------------------------
1037 //------------------------------------------------------------------
1038 /// Return whether this object is valid (i.e. has not been finalized.)
1041 /// Returns \b true if this Process has not been finalized
1042 /// and \b false otherwise.
1043 //------------------------------------------------------------------
1047 return !m_finalize_called;
1050 //------------------------------------------------------------------
1051 /// Return a multi-word command object that can be used to expose
1052 /// plug-in specific commands.
1054 /// This object will be used to resolve plug-in commands and can be
1055 /// triggered by a call to:
1057 /// (lldb) process commmand <args>
1060 /// A CommandObject which can be one of the concrete subclasses
1061 /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
1062 /// or CommandObjectMultiword.
1063 //------------------------------------------------------------------
1064 virtual CommandObject *
1065 GetPluginCommandObject()
1070 //------------------------------------------------------------------
1071 /// Launch a new process.
1073 /// Launch a new process by spawning a new process using the
1074 /// target object's executable module's file as the file to launch.
1076 /// This function is not meant to be overridden by Process
1077 /// subclasses. It will first call Process::WillLaunch (Module *)
1078 /// and if that returns \b true, Process::DoLaunch (Module*,
1079 /// char const *[],char const *[],const char *,const char *,
1080 /// const char *) will be called to actually do the launching. If
1081 /// DoLaunch returns \b true, then Process::DidLaunch() will be
1084 /// @param[in] launch_info
1085 /// Details regarding the environment, STDIN/STDOUT/STDERR
1086 /// redirection, working path, etc. related to the requested launch.
1089 /// An error object. Call GetID() to get the process ID if
1090 /// the error object is success.
1091 //------------------------------------------------------------------
1093 Launch (ProcessLaunchInfo &launch_info);
1102 error.SetErrorStringWithFormat("error: %s does not support loading core files.", GetPluginName().GetCString());
1106 //------------------------------------------------------------------
1107 /// Get the dynamic loader plug-in for this process.
1109 /// The default action is to let the DynamicLoader plug-ins check
1110 /// the main executable and the DynamicLoader will select itself
1111 /// automatically. Subclasses can override this if inspecting the
1112 /// executable is not desired, or if Process subclasses can only
1113 /// use a specific DynamicLoader plug-in.
1114 //------------------------------------------------------------------
1115 virtual DynamicLoader *
1116 GetDynamicLoader ();
1118 //------------------------------------------------------------------
1119 // Returns AUXV structure found in many ELF-based environments.
1121 // The default action is to return an empty data buffer.
1124 // A data buffer containing the contents of the AUXV data.
1125 //------------------------------------------------------------------
1126 virtual const lldb::DataBufferSP
1130 virtual JITLoaderList &
1134 //------------------------------------------------------------------
1135 /// Get the system runtime plug-in for this process.
1138 /// Returns a pointer to the SystemRuntime plugin for this Process
1139 /// if one is available. Else returns NULL.
1140 //------------------------------------------------------------------
1141 virtual SystemRuntime *
1142 GetSystemRuntime ();
1144 //------------------------------------------------------------------
1145 /// Attach to an existing process using the process attach info.
1147 /// This function is not meant to be overridden by Process
1148 /// subclasses. It will first call WillAttach (lldb::pid_t)
1149 /// or WillAttach (const char *), and if that returns \b
1150 /// true, DoAttach (lldb::pid_t) or DoAttach (const char *) will
1151 /// be called to actually do the attach. If DoAttach returns \b
1152 /// true, then Process::DidAttach() will be called.
1155 /// The process ID that we should attempt to attach to.
1158 /// Returns \a pid if attaching was successful, or
1159 /// LLDB_INVALID_PROCESS_ID if attaching fails.
1160 //------------------------------------------------------------------
1162 Attach (ProcessAttachInfo &attach_info);
1164 //------------------------------------------------------------------
1165 /// Attach to a remote system via a URL
1168 /// A stream where output intended for the user
1169 /// (if the driver has a way to display that) generated during
1170 /// the connection. This may be NULL if no output is needed.A
1172 /// @param[in] remote_url
1173 /// The URL format that we are connecting to.
1176 /// Returns an error object.
1177 //------------------------------------------------------------------
1179 ConnectRemote (Stream *strm, const char *remote_url);
1182 GetShouldDetach () const
1184 return m_should_detach;
1188 SetShouldDetach (bool b)
1190 m_should_detach = b;
1193 //------------------------------------------------------------------
1194 /// Get the image information address for the current process.
1196 /// Some runtimes have system functions that can help dynamic
1197 /// loaders locate the dynamic loader information needed to observe
1198 /// shared libraries being loaded or unloaded. This function is
1199 /// in the Process interface (as opposed to the DynamicLoader
1200 /// interface) to ensure that remote debugging can take advantage of
1201 /// this functionality.
1204 /// The address of the dynamic loader information, or
1205 /// LLDB_INVALID_ADDRESS if this is not supported by this
1207 //------------------------------------------------------------------
1208 virtual lldb::addr_t
1209 GetImageInfoAddress ();
1211 //------------------------------------------------------------------
1212 /// Load a shared library into this process.
1214 /// Try and load a shared library into the current process. This
1215 /// call might fail in the dynamic loader plug-in says it isn't safe
1216 /// to try and load shared libraries at the moment.
1218 /// @param[in] image_spec
1219 /// The image file spec that points to the shared library that
1220 /// you want to load.
1222 /// @param[out] error
1223 /// An error object that gets filled in with any errors that
1224 /// might occur when trying to load the shared library.
1227 /// A token that represents the shared library that can be
1228 /// later used to unload the shared library. A value of
1229 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
1230 /// library can't be opened.
1231 //------------------------------------------------------------------
1233 LoadImage (const FileSpec &image_spec, Error &error);
1236 UnloadImage (uint32_t image_token);
1238 //------------------------------------------------------------------
1239 /// Register for process and thread notifications.
1241 /// Clients can register notification callbacks by filling out a
1242 /// Process::Notifications structure and calling this function.
1244 /// @param[in] callbacks
1245 /// A structure that contains the notification baton and
1246 /// callback functions.
1248 /// @see Process::Notifications
1249 //------------------------------------------------------------------
1252 RegisterNotificationCallbacks (const Process::Notifications& callbacks);
1254 //------------------------------------------------------------------
1255 /// Unregister for process and thread notifications.
1257 /// Clients can unregister notification callbacks by passing a copy of
1258 /// the original baton and callbacks in \a callbacks.
1260 /// @param[in] callbacks
1261 /// A structure that contains the notification baton and
1262 /// callback functions.
1265 /// Returns \b true if the notification callbacks were
1266 /// successfully removed from the process, \b false otherwise.
1268 /// @see Process::Notifications
1269 //------------------------------------------------------------------
1272 UnregisterNotificationCallbacks (const Process::Notifications& callbacks);
1274 //==================================================================
1275 // Built in Process Control functions
1276 //==================================================================
1277 //------------------------------------------------------------------
1278 /// Resumes all of a process's threads as configured using the
1279 /// Thread run control functions.
1281 /// Threads for a process should be updated with one of the run
1282 /// control actions (resume, step, or suspend) that they should take
1283 /// when the process is resumed. If no run control action is given
1284 /// to a thread it will be resumed by default.
1286 /// This function is not meant to be overridden by Process
1287 /// subclasses. This function will take care of disabling any
1288 /// breakpoints that threads may be stopped at, single stepping, and
1289 /// re-enabling breakpoints, and enabling the basic flow control
1290 /// that the plug-in instances need not worry about.
1292 /// N.B. This function also sets the Write side of the Run Lock,
1293 /// which is unset when the corresponding stop event is pulled off
1294 /// the Public Event Queue. If you need to resume the process without
1295 /// setting the Run Lock, use PrivateResume (though you should only do
1296 /// that from inside the Process class.
1299 /// Returns an error object.
1301 /// @see Thread:Resume()
1302 /// @see Thread:Step()
1303 /// @see Thread:Suspend()
1304 //------------------------------------------------------------------
1309 ResumeSynchronous (Stream *stream);
1310 //------------------------------------------------------------------
1311 /// Halts a running process.
1313 /// This function is not meant to be overridden by Process
1315 /// If the process is successfully halted, a eStateStopped
1316 /// process event with GetInterrupted will be broadcast. If false, we will
1317 /// halt the process with no events generated by the halt.
1319 /// @param[in] clear_thread_plans
1320 /// If true, when the process stops, clear all thread plans.
1323 /// Returns an error object. If the error is empty, the process is halted.
1324 /// otherwise the halt has failed.
1325 //------------------------------------------------------------------
1327 Halt (bool clear_thread_plans = false);
1329 //------------------------------------------------------------------
1330 /// Detaches from a running or stopped process.
1332 /// This function is not meant to be overridden by Process
1335 /// @param[in] keep_stopped
1336 /// If true, don't resume the process on detach.
1339 /// Returns an error object.
1340 //------------------------------------------------------------------
1342 Detach (bool keep_stopped);
1344 //------------------------------------------------------------------
1345 /// Kills the process and shuts down all threads that were spawned
1346 /// to track and monitor the process.
1348 /// This function is not meant to be overridden by Process
1352 /// Returns an error object.
1353 //------------------------------------------------------------------
1357 //------------------------------------------------------------------
1358 /// Sends a process a UNIX signal \a signal.
1360 /// This function is not meant to be overridden by Process
1364 /// Returns an error object.
1365 //------------------------------------------------------------------
1367 Signal (int signal);
1370 SetUnixSignals (const UnixSignalsSP &signals_sp)
1372 assert (signals_sp && "null signals_sp");
1373 m_unix_signals_sp = signals_sp;
1379 assert (m_unix_signals_sp && "null m_unix_signals_sp");
1380 return *m_unix_signals_sp;
1383 //==================================================================
1384 // Plug-in Process Control Overrides
1385 //==================================================================
1387 //------------------------------------------------------------------
1388 /// Called before attaching to a process.
1390 /// Allow Process plug-ins to execute some code before attaching a
1394 /// Returns an error object.
1395 //------------------------------------------------------------------
1397 WillAttachToProcessWithID (lldb::pid_t pid)
1402 //------------------------------------------------------------------
1403 /// Called before attaching to a process.
1405 /// Allow Process plug-ins to execute some code before attaching a
1409 /// Returns an error object.
1410 //------------------------------------------------------------------
1412 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
1417 //------------------------------------------------------------------
1418 /// Attach to a remote system via a URL
1421 /// A stream where output intended for the user
1422 /// (if the driver has a way to display that) generated during
1423 /// the connection. This may be NULL if no output is needed.A
1425 /// @param[in] remote_url
1426 /// The URL format that we are connecting to.
1429 /// Returns an error object.
1430 //------------------------------------------------------------------
1432 DoConnectRemote (Stream *strm, const char *remote_url)
1435 error.SetErrorString ("remote connections are not supported");
1439 //------------------------------------------------------------------
1440 /// Attach to an existing process using a process ID.
1443 /// The process ID that we should attempt to attach to.
1446 /// Returns \a pid if attaching was successful, or
1447 /// LLDB_INVALID_PROCESS_ID if attaching fails.
1448 //------------------------------------------------------------------
1450 DoAttachToProcessWithID (lldb::pid_t pid)
1453 error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString());
1457 //------------------------------------------------------------------
1458 /// Attach to an existing process using a process ID.
1461 /// The process ID that we should attempt to attach to.
1463 /// @param[in] attach_info
1464 /// Information on how to do the attach. For example, GetUserID()
1465 /// will return the uid to attach as.
1468 /// Returns \a pid if attaching was successful, or
1469 /// LLDB_INVALID_PROCESS_ID if attaching fails.
1470 /// hanming : need flag
1471 //------------------------------------------------------------------
1473 DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info)
1476 error.SetErrorStringWithFormat("error: %s does not support attaching to a process by pid", GetPluginName().GetCString());
1480 //------------------------------------------------------------------
1481 /// Attach to an existing process using a partial process name.
1483 /// @param[in] process_name
1484 /// The name of the process to attach to.
1486 /// @param[in] attach_info
1487 /// Information on how to do the attach. For example, GetUserID()
1488 /// will return the uid to attach as.
1491 /// Returns an error object.
1492 //------------------------------------------------------------------
1494 DoAttachToProcessWithName (const char *process_name, const ProcessAttachInfo &attach_info)
1497 error.SetErrorString("attach by name is not supported");
1501 //------------------------------------------------------------------
1502 /// Called after attaching a process.
1504 /// @param[in] process_arch
1505 /// If you can figure out the process architecture after attach, fill it in here.
1507 /// Allow Process plug-ins to execute some code after attaching to
1509 //------------------------------------------------------------------
1511 DidAttach (ArchSpec &process_arch)
1513 process_arch.Clear();
1517 //------------------------------------------------------------------
1518 /// Called after a process re-execs itself.
1520 /// Allow Process plug-ins to execute some code after a process has
1521 /// exec'ed itself. Subclasses typically should override DoDidExec()
1522 /// as the lldb_private::Process class needs to remove its dynamic
1523 /// loader, runtime, ABI and other plug-ins, as well as unload all
1524 /// shared libraries.
1525 //------------------------------------------------------------------
1529 //------------------------------------------------------------------
1530 /// Subclasses of Process should implement this function if they
1531 /// need to do anything after a process exec's itself.
1532 //------------------------------------------------------------------
1538 //------------------------------------------------------------------
1539 /// Called before launching to a process.
1541 /// Allow Process plug-ins to execute some code before launching a
1545 /// Returns an error object.
1546 //------------------------------------------------------------------
1548 WillLaunch (Module* module)
1553 //------------------------------------------------------------------
1554 /// Launch a new process.
1556 /// Launch a new process by spawning a new process using
1557 /// \a exe_module's file as the file to launch. Launch details are
1558 /// provided in \a launch_info.
1560 /// @param[in] exe_module
1561 /// The module from which to extract the file specification and
1564 /// @param[in] launch_info
1565 /// Details (e.g. arguments, stdio redirection, etc.) for the
1566 /// requested launch.
1569 /// An Error instance indicating success or failure of the
1571 //------------------------------------------------------------------
1573 DoLaunch (Module *exe_module,
1574 ProcessLaunchInfo &launch_info)
1577 error.SetErrorStringWithFormat("error: %s does not support launching processes", GetPluginName().GetCString());
1582 //------------------------------------------------------------------
1583 /// Called after launching a process.
1585 /// Allow Process plug-ins to execute some code after launching
1587 //------------------------------------------------------------------
1593 //------------------------------------------------------------------
1594 /// Called before resuming to a process.
1596 /// Allow Process plug-ins to execute some code before resuming a
1600 /// Returns an error object.
1601 //------------------------------------------------------------------
1603 WillResume () { return Error(); }
1605 //------------------------------------------------------------------
1606 /// Resumes all of a process's threads as configured using the
1607 /// Thread run control functions.
1609 /// Threads for a process should be updated with one of the run
1610 /// control actions (resume, step, or suspend) that they should take
1611 /// when the process is resumed. If no run control action is given
1612 /// to a thread it will be resumed by default.
1615 /// Returns \b true if the process successfully resumes using
1616 /// the thread run control actions, \b false otherwise.
1618 /// @see Thread:Resume()
1619 /// @see Thread:Step()
1620 /// @see Thread:Suspend()
1621 //------------------------------------------------------------------
1626 error.SetErrorStringWithFormat("error: %s does not support resuming processes", GetPluginName().GetCString());
1631 //------------------------------------------------------------------
1632 /// Called after resuming a process.
1634 /// Allow Process plug-ins to execute some code after resuming
1636 //------------------------------------------------------------------
1641 //------------------------------------------------------------------
1642 /// Called before halting to a process.
1644 /// Allow Process plug-ins to execute some code before halting a
1648 /// Returns an error object.
1649 //------------------------------------------------------------------
1651 WillHalt () { return Error(); }
1653 //------------------------------------------------------------------
1654 /// Halts a running process.
1656 /// DoHalt must produce one and only one stop StateChanged event if it actually
1657 /// stops the process. If the stop happens through some natural event (for
1658 /// instance a SIGSTOP), then forwarding that event will do. Otherwise, you must
1659 /// generate the event manually. Note also, the private event thread is stopped when
1660 /// DoHalt is run to prevent the events generated while halting to trigger
1661 /// other state changes before the halt is complete.
1663 /// @param[out] caused_stop
1664 /// If true, then this Halt caused the stop, otherwise, the
1665 /// process was already stopped.
1668 /// Returns \b true if the process successfully halts, \b false
1670 //------------------------------------------------------------------
1672 DoHalt (bool &caused_stop)
1675 error.SetErrorStringWithFormat("error: %s does not support halting processes", GetPluginName().GetCString());
1680 //------------------------------------------------------------------
1681 /// Called after halting a process.
1683 /// Allow Process plug-ins to execute some code after halting
1685 //------------------------------------------------------------------
1689 //------------------------------------------------------------------
1690 /// Called before detaching from a process.
1692 /// Allow Process plug-ins to execute some code before detaching
1696 /// Returns an error object.
1697 //------------------------------------------------------------------
1704 //------------------------------------------------------------------
1705 /// Detaches from a running or stopped process.
1708 /// Returns \b true if the process successfully detaches, \b
1709 /// false otherwise.
1710 //------------------------------------------------------------------
1712 DoDetach (bool keep_stopped)
1715 error.SetErrorStringWithFormat("error: %s does not support detaching from processes", GetPluginName().GetCString());
1720 //------------------------------------------------------------------
1721 /// Called after detaching from a process.
1723 /// Allow Process plug-ins to execute some code after detaching
1725 //------------------------------------------------------------------
1730 DetachRequiresHalt() { return false; }
1732 //------------------------------------------------------------------
1733 /// Called before sending a signal to a process.
1735 /// Allow Process plug-ins to execute some code before sending a
1736 /// signal to a process.
1739 /// Returns no error if it is safe to proceed with a call to
1740 /// Process::DoSignal(int), otherwise an error describing what
1741 /// prevents the signal from being sent.
1742 //------------------------------------------------------------------
1744 WillSignal () { return Error(); }
1746 //------------------------------------------------------------------
1747 /// Sends a process a UNIX signal \a signal.
1750 /// Returns an error object.
1751 //------------------------------------------------------------------
1753 DoSignal (int signal)
1756 error.SetErrorStringWithFormat("error: %s does not support sending signals to processes", GetPluginName().GetCString());
1761 WillDestroy () { return Error(); }
1770 DestroyRequiresHalt() { return true; }
1773 //------------------------------------------------------------------
1774 /// Called after sending a signal to a process.
1776 /// Allow Process plug-ins to execute some code after sending a
1777 /// signal to a process.
1778 //------------------------------------------------------------------
1782 //------------------------------------------------------------------
1783 /// Currently called as part of ShouldStop.
1784 /// FIXME: Should really happen when the target stops before the
1785 /// event is taken from the queue...
1787 /// This callback is called as the event
1788 /// is about to be queued up to allow Process plug-ins to execute
1789 /// some code prior to clients being notified that a process was
1790 /// stopped. Common operations include updating the thread list,
1791 /// invalidating any thread state (registers, stack, etc) prior to
1792 /// letting the notification go out.
1794 //------------------------------------------------------------------
1796 RefreshStateAfterStop () = 0;
1798 //------------------------------------------------------------------
1799 /// Get the target object pointer for this module.
1802 /// A Target object pointer to the target that owns this
1804 //------------------------------------------------------------------
1811 //------------------------------------------------------------------
1812 /// Get the const target object pointer for this module.
1815 /// A const Target object pointer to the target that owns this
1817 //------------------------------------------------------------------
1824 //------------------------------------------------------------------
1825 /// Flush all data in the process.
1827 /// Flush the memory caches, all threads, and any other cached data
1830 /// This function can be called after a world changing event like
1831 /// adding a new symbol file, or after the process makes a large
1832 /// context switch (from boot ROM to booted into an OS).
1833 //------------------------------------------------------------------
1837 //------------------------------------------------------------------
1838 /// Get accessor for the current process state.
1841 /// The current state of the process.
1843 /// @see lldb::StateType
1844 //------------------------------------------------------------------
1848 lldb::ExpressionResults
1849 RunThreadPlan (ExecutionContext &exe_ctx,
1850 lldb::ThreadPlanSP &thread_plan_sp,
1851 const EvaluateExpressionOptions &options,
1855 ExecutionResultAsCString (lldb::ExpressionResults result);
1858 GetStatus (Stream &ostrm);
1861 GetThreadStatus (Stream &ostrm,
1862 bool only_threads_with_stop_reason,
1863 uint32_t start_frame,
1864 uint32_t num_frames,
1865 uint32_t num_frames_with_source);
1868 SendAsyncInterrupt ();
1871 ModulesDidLoad (ModuleList &module_list);
1876 SetState (lldb::EventSP &event_sp);
1881 //------------------------------------------------------------------
1882 /// The "private" side of resuming a process. This doesn't alter the
1883 /// state of m_run_lock, but just causes the process to resume.
1886 /// An Error object describing the success or failure of the resume.
1887 //------------------------------------------------------------------
1891 //------------------------------------------------------------------
1892 // Called internally
1893 //------------------------------------------------------------------
1898 //------------------------------------------------------------------
1899 /// Get the exit status for a process.
1902 /// The process's return code, or -1 if the current process
1903 /// state is not eStateExited.
1904 //------------------------------------------------------------------
1908 //------------------------------------------------------------------
1909 /// Get a textual description of what the process exited.
1912 /// The textual description of why the process exited, or NULL
1913 /// if there is no description available.
1914 //------------------------------------------------------------------
1916 GetExitDescription ();
1924 //------------------------------------------------------------------
1925 /// Get the Modification ID of the process.
1928 /// The modification ID of the process.
1929 //------------------------------------------------------------------
1936 const ProcessModID &
1937 GetModIDRef () const
1945 return m_mod_id.GetStopID();
1949 GetResumeID () const
1951 return m_mod_id.GetResumeID();
1955 GetLastUserExpressionResumeID () const
1957 return m_mod_id.GetLastUserExpressionResumeID();
1961 GetLastNaturalStopID()
1963 return m_mod_id.GetLastNaturalStopID();
1966 //------------------------------------------------------------------
1967 /// Set accessor for the process exit status (return code).
1969 /// Sometimes a child exits and the exit can be detected by global
1970 /// functions (signal handler for SIGCHLD for example). This
1971 /// accessor allows the exit status to be set from an external
1974 /// Setting this will cause a eStateExited event to be posted to
1975 /// the process event queue.
1977 /// @param[in] exit_status
1978 /// The value for the process's return code.
1980 /// @see lldb::StateType
1981 //------------------------------------------------------------------
1983 SetExitStatus (int exit_status, const char *cstr);
1985 //------------------------------------------------------------------
1986 /// Check if a process is still alive.
1989 /// Returns \b true if the process is still valid, \b false
1991 //------------------------------------------------------------------
1995 //------------------------------------------------------------------
1996 /// Before lldb detaches from a process, it warns the user that they are about to lose their debug session.
1997 /// In some cases, this warning doesn't need to be emitted -- for instance, with core file debugging where
1998 /// the user can reconstruct the "state" by simply re-running the debugger on the core file.
2001 // true if the user should be warned about detaching from this process.
2002 //------------------------------------------------------------------
2004 WarnBeforeDetach () const
2009 //------------------------------------------------------------------
2010 /// Actually do the reading of memory from a process.
2012 /// Subclasses must override this function and can return fewer
2013 /// bytes than requested when memory requests are too large. This
2014 /// class will break up the memory requests and keep advancing the
2015 /// arguments along as needed.
2017 /// @param[in] vm_addr
2018 /// A virtual load address that indicates where to start reading
2022 /// The number of bytes to read.
2025 /// A byte buffer that is at least \a size bytes long that
2026 /// will receive the memory bytes.
2029 /// The number of bytes that were actually read into \a buf.
2030 //------------------------------------------------------------------
2032 DoReadMemory (lldb::addr_t vm_addr,
2037 //------------------------------------------------------------------
2038 /// Read of memory from a process.
2040 /// This function will read memory from the current process's
2041 /// address space and remove any traps that may have been inserted
2042 /// into the memory.
2044 /// This function is not meant to be overridden by Process
2045 /// subclasses, the subclasses should implement
2046 /// Process::DoReadMemory (lldb::addr_t, size_t, void *).
2048 /// @param[in] vm_addr
2049 /// A virtual load address that indicates where to start reading
2053 /// A byte buffer that is at least \a size bytes long that
2054 /// will receive the memory bytes.
2057 /// The number of bytes to read.
2060 /// The number of bytes that were actually read into \a buf. If
2061 /// the returned number is greater than zero, yet less than \a
2062 /// size, then this function will get called again with \a
2063 /// vm_addr, \a buf, and \a size updated appropriately. Zero is
2064 /// returned to indicate an error.
2065 //------------------------------------------------------------------
2067 ReadMemory (lldb::addr_t vm_addr,
2072 //------------------------------------------------------------------
2073 /// Read a NULL terminated string from memory
2075 /// This function will read a cache page at a time until a NULL
2076 /// string terminator is found. It will stop reading if an aligned
2077 /// sequence of NULL termination \a type_width bytes is not found
2078 /// before reading \a cstr_max_len bytes. The results are always
2079 /// guaranteed to be NULL terminated, and that no more than
2080 /// (max_bytes - type_width) bytes will be read.
2082 /// @param[in] vm_addr
2083 /// The virtual load address to start the memory read.
2086 /// A character buffer containing at least max_bytes.
2088 /// @param[in] max_bytes
2089 /// The maximum number of bytes to read.
2091 /// @param[in] error
2092 /// The error status of the read operation.
2094 /// @param[in] type_width
2095 /// The size of the null terminator (1 to 4 bytes per
2096 /// character). Defaults to 1.
2099 /// The error status or the number of bytes prior to the null terminator.
2100 //------------------------------------------------------------------
2102 ReadStringFromMemory (lldb::addr_t vm_addr,
2106 size_t type_width = 1);
2108 //------------------------------------------------------------------
2109 /// Read a NULL terminated C string from memory
2111 /// This function will read a cache page at a time until the NULL
2112 /// C string terminator is found. It will stop reading if the NULL
2113 /// termination byte isn't found before reading \a cstr_max_len
2114 /// bytes, and the results are always guaranteed to be NULL
2115 /// terminated (at most cstr_max_len - 1 bytes will be read).
2116 //------------------------------------------------------------------
2118 ReadCStringFromMemory (lldb::addr_t vm_addr,
2120 size_t cstr_max_len,
2124 ReadCStringFromMemory (lldb::addr_t vm_addr,
2125 std::string &out_str,
2129 ReadMemoryFromInferior (lldb::addr_t vm_addr,
2134 //------------------------------------------------------------------
2135 /// Reads an unsigned integer of the specified byte size from
2138 /// @param[in] load_addr
2139 /// A load address of the integer to read.
2141 /// @param[in] byte_size
2142 /// The size in byte of the integer to read.
2144 /// @param[in] fail_value
2145 /// The value to return if we fail to read an integer.
2147 /// @param[out] error
2148 /// An error that indicates the success or failure of this
2149 /// operation. If error indicates success (error.Success()),
2150 /// then the value returned can be trusted, otherwise zero
2151 /// will be returned.
2154 /// The unsigned integer that was read from the process memory
2155 /// space. If the integer was smaller than a uint64_t, any
2156 /// unused upper bytes will be zero filled. If the process
2157 /// byte order differs from the host byte order, the integer
2158 /// value will be appropriately byte swapped into host byte
2160 //------------------------------------------------------------------
2162 ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
2164 uint64_t fail_value,
2168 ReadPointerFromMemory (lldb::addr_t vm_addr,
2172 WritePointerToMemory (lldb::addr_t vm_addr,
2173 lldb::addr_t ptr_value,
2176 //------------------------------------------------------------------
2177 /// Actually do the writing of memory to a process.
2179 /// @param[in] vm_addr
2180 /// A virtual load address that indicates where to start writing
2184 /// A byte buffer that is at least \a size bytes long that
2185 /// contains the data to write.
2188 /// The number of bytes to write.
2190 /// @param[out] error
2191 /// An error value in case the memory write fails.
2194 /// The number of bytes that were actually written.
2195 //------------------------------------------------------------------
2197 DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error)
2199 error.SetErrorStringWithFormat("error: %s does not support writing to processes", GetPluginName().GetCString());
2204 //------------------------------------------------------------------
2205 /// Write all or part of a scalar value to memory.
2207 /// The value contained in \a scalar will be swapped to match the
2208 /// byte order of the process that is being debugged. If \a size is
2209 /// less than the size of scalar, the least significant \a size bytes
2210 /// from scalar will be written. If \a size is larger than the byte
2211 /// size of scalar, then the extra space will be padded with zeros
2212 /// and the scalar value will be placed in the least significant
2213 /// bytes in memory.
2215 /// @param[in] vm_addr
2216 /// A virtual load address that indicates where to start writing
2219 /// @param[in] scalar
2220 /// The scalar to write to the debugged process.
2223 /// This value can be smaller or larger than the scalar value
2224 /// itself. If \a size is smaller than the size of \a scalar,
2225 /// the least significant bytes in \a scalar will be used. If
2226 /// \a size is larger than the byte size of \a scalar, then
2227 /// the extra space will be padded with zeros. If \a size is
2228 /// set to UINT32_MAX, then the size of \a scalar will be used.
2230 /// @param[out] error
2231 /// An error value in case the memory write fails.
2234 /// The number of bytes that were actually written.
2235 //------------------------------------------------------------------
2237 WriteScalarToMemory (lldb::addr_t vm_addr,
2238 const Scalar &scalar,
2243 ReadScalarIntegerFromMemory (lldb::addr_t addr,
2249 //------------------------------------------------------------------
2250 /// Write memory to a process.
2252 /// This function will write memory to the current process's
2253 /// address space and maintain any traps that might be present due
2254 /// to software breakpoints.
2256 /// This function is not meant to be overridden by Process
2257 /// subclasses, the subclasses should implement
2258 /// Process::DoWriteMemory (lldb::addr_t, size_t, void *).
2260 /// @param[in] vm_addr
2261 /// A virtual load address that indicates where to start writing
2265 /// A byte buffer that is at least \a size bytes long that
2266 /// contains the data to write.
2269 /// The number of bytes to write.
2272 /// The number of bytes that were actually written.
2273 //------------------------------------------------------------------
2275 WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error);
2278 //------------------------------------------------------------------
2279 /// Actually allocate memory in the process.
2281 /// This function will allocate memory in the process's address
2282 /// space. This can't rely on the generic function calling mechanism,
2283 /// since that requires this function.
2286 /// The size of the allocation requested.
2289 /// The address of the allocated buffer in the process, or
2290 /// LLDB_INVALID_ADDRESS if the allocation failed.
2291 //------------------------------------------------------------------
2293 virtual lldb::addr_t
2294 DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
2296 error.SetErrorStringWithFormat("error: %s does not support allocating in the debug process", GetPluginName().GetCString());
2297 return LLDB_INVALID_ADDRESS;
2301 //------------------------------------------------------------------
2302 /// The public interface to allocating memory in the process.
2304 /// This function will allocate memory in the process's address
2305 /// space. This can't rely on the generic function calling mechanism,
2306 /// since that requires this function.
2309 /// The size of the allocation requested.
2311 /// @param[in] permissions
2312 /// Or together any of the lldb::Permissions bits. The permissions on
2313 /// a given memory allocation can't be changed after allocation. Note
2314 /// that a block that isn't set writable can still be written on from lldb,
2315 /// just not by the process itself.
2317 /// @param[in/out] error
2318 /// An error object to fill in if things go wrong.
2320 /// The address of the allocated buffer in the process, or
2321 /// LLDB_INVALID_ADDRESS if the allocation failed.
2322 //------------------------------------------------------------------
2325 AllocateMemory (size_t size, uint32_t permissions, Error &error);
2328 //------------------------------------------------------------------
2329 /// Resolve dynamically loaded indirect functions.
2331 /// @param[in] address
2332 /// The load address of the indirect function to resolve.
2334 /// @param[out] error
2335 /// An error value in case the resolve fails.
2338 /// The address of the resolved function.
2339 /// LLDB_INVALID_ADDRESS if the resolution failed.
2340 //------------------------------------------------------------------
2342 virtual lldb::addr_t
2343 ResolveIndirectFunction(const Address *address, Error &error);
2346 GetMemoryRegionInfo (lldb::addr_t load_addr,
2347 MemoryRegionInfo &range_info)
2350 error.SetErrorString ("Process::GetMemoryRegionInfo() not supported");
2355 GetWatchpointSupportInfo (uint32_t &num)
2359 error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported");
2364 GetWatchpointSupportInfo (uint32_t &num, bool& after)
2369 error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported");
2374 ReadModuleFromMemory (const FileSpec& file_spec,
2375 lldb::addr_t header_addr,
2376 size_t size_to_read = 512);
2378 //------------------------------------------------------------------
2379 /// Attempt to get the attributes for a region of memory in the process.
2381 /// It may be possible for the remote debug server to inspect attributes
2382 /// for a region of memory in the process, such as whether there is a
2383 /// valid page of memory at a given address or whether that page is
2384 /// readable/writable/executable by the process.
2386 /// @param[in] load_addr
2387 /// The address of interest in the process.
2389 /// @param[out] permissions
2390 /// If this call returns successfully, this bitmask will have
2391 /// its Permissions bits set to indicate whether the region is
2392 /// readable/writable/executable. If this call fails, the
2393 /// bitmask values are undefined.
2396 /// Returns true if it was able to determine the attributes of the
2397 /// memory region. False if not.
2398 //------------------------------------------------------------------
2401 GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions)
2403 MemoryRegionInfo range_info;
2405 Error error (GetMemoryRegionInfo (load_addr, range_info));
2406 if (!error.Success())
2408 if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow
2409 || range_info.GetWritable() == MemoryRegionInfo::eDontKnow
2410 || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow)
2415 if (range_info.GetReadable() == MemoryRegionInfo::eYes)
2416 permissions |= lldb::ePermissionsReadable;
2418 if (range_info.GetWritable() == MemoryRegionInfo::eYes)
2419 permissions |= lldb::ePermissionsWritable;
2421 if (range_info.GetExecutable() == MemoryRegionInfo::eYes)
2422 permissions |= lldb::ePermissionsExecutable;
2427 //------------------------------------------------------------------
2428 /// Determines whether executing JIT-compiled code in this process
2432 /// True if execution of JIT code is possible; false otherwise.
2433 //------------------------------------------------------------------
2436 //------------------------------------------------------------------
2437 /// Sets whether executing JIT-compiled code in this process
2440 /// @param[in] can_jit
2441 /// True if execution of JIT code is possible; false otherwise.
2442 //------------------------------------------------------------------
2443 void SetCanJIT (bool can_jit);
2445 //------------------------------------------------------------------
2446 /// Actually deallocate memory in the process.
2448 /// This function will deallocate memory in the process's address
2449 /// space that was allocated with AllocateMemory.
2452 /// A return value from AllocateMemory, pointing to the memory you
2453 /// want to deallocate.
2456 /// \btrue if the memory was deallocated, \bfalse otherwise.
2457 //------------------------------------------------------------------
2460 DoDeallocateMemory (lldb::addr_t ptr)
2463 error.SetErrorStringWithFormat("error: %s does not support deallocating in the debug process", GetPluginName().GetCString());
2468 //------------------------------------------------------------------
2469 /// The public interface to deallocating memory in the process.
2471 /// This function will deallocate memory in the process's address
2472 /// space that was allocated with AllocateMemory.
2475 /// A return value from AllocateMemory, pointing to the memory you
2476 /// want to deallocate.
2479 /// \btrue if the memory was deallocated, \bfalse otherwise.
2480 //------------------------------------------------------------------
2483 DeallocateMemory (lldb::addr_t ptr);
2485 //------------------------------------------------------------------
2486 /// Get any available STDOUT.
2488 /// Calling this method is a valid operation only if all of the
2489 /// following conditions are true:
2490 /// 1) The process was launched, and not attached to.
2491 /// 2) The process was not launched with eLaunchFlagDisableSTDIO.
2492 /// 3) The process was launched without supplying a valid file path
2495 /// Note that the implementation will probably need to start a read
2496 /// thread in the background to make sure that the pipe is drained
2497 /// and the STDOUT buffered appropriately, to prevent the process
2498 /// from deadlocking trying to write to a full buffer.
2500 /// Events will be queued indicating that there is STDOUT available
2501 /// that can be retrieved using this function.
2504 /// A buffer that will receive any STDOUT bytes that are
2505 /// currently available.
2507 /// @param[in] buf_size
2508 /// The size in bytes for the buffer \a buf.
2511 /// The number of bytes written into \a buf. If this value is
2512 /// equal to \a buf_size, another call to this function should
2513 /// be made to retrieve more STDOUT data.
2514 //------------------------------------------------------------------
2516 GetSTDOUT (char *buf, size_t buf_size, Error &error);
2518 //------------------------------------------------------------------
2519 /// Get any available STDERR.
2521 /// Calling this method is a valid operation only if all of the
2522 /// following conditions are true:
2523 /// 1) The process was launched, and not attached to.
2524 /// 2) The process was not launched with eLaunchFlagDisableSTDIO.
2525 /// 3) The process was launched without supplying a valid file path
2528 /// Note that the implementation will probably need to start a read
2529 /// thread in the background to make sure that the pipe is drained
2530 /// and the STDERR buffered appropriately, to prevent the process
2531 /// from deadlocking trying to write to a full buffer.
2533 /// Events will be queued indicating that there is STDERR available
2534 /// that can be retrieved using this function.
2537 /// A buffer that will receive any STDERR bytes that are
2538 /// currently available.
2540 /// @param[out] buf_size
2541 /// The size in bytes for the buffer \a buf.
2544 /// The number of bytes written into \a buf. If this value is
2545 /// equal to \a buf_size, another call to this function should
2546 /// be made to retrieve more STDERR data.
2547 //------------------------------------------------------------------
2549 GetSTDERR (char *buf, size_t buf_size, Error &error);
2551 //------------------------------------------------------------------
2552 /// Puts data into this process's STDIN.
2554 /// Calling this method is a valid operation only if all of the
2555 /// following conditions are true:
2556 /// 1) The process was launched, and not attached to.
2557 /// 2) The process was not launched with eLaunchFlagDisableSTDIO.
2558 /// 3) The process was launched without supplying a valid file path
2562 /// A buffer that contains the data to write to the process's STDIN.
2564 /// @param[in] buf_size
2565 /// The size in bytes for the buffer \a buf.
2568 /// The number of bytes written into \a buf. If this value is
2569 /// less than \a buf_size, another call to this function should
2570 /// be made to write the rest of the data.
2571 //------------------------------------------------------------------
2573 PutSTDIN (const char *buf, size_t buf_size, Error &error)
2575 error.SetErrorString("stdin unsupported");
2579 //------------------------------------------------------------------
2580 /// Get any available profile data.
2583 /// A buffer that will receive any profile data bytes that are
2584 /// currently available.
2586 /// @param[out] buf_size
2587 /// The size in bytes for the buffer \a buf.
2590 /// The number of bytes written into \a buf. If this value is
2591 /// equal to \a buf_size, another call to this function should
2592 /// be made to retrieve more profile data.
2593 //------------------------------------------------------------------
2595 GetAsyncProfileData (char *buf, size_t buf_size, Error &error);
2597 //----------------------------------------------------------------------
2598 // Process Breakpoints
2599 //----------------------------------------------------------------------
2601 GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site);
2604 EnableBreakpointSite (BreakpointSite *bp_site)
2607 error.SetErrorStringWithFormat("error: %s does not support enabling breakpoints", GetPluginName().GetCString());
2613 DisableBreakpointSite (BreakpointSite *bp_site)
2616 error.SetErrorStringWithFormat("error: %s does not support disabling breakpoints", GetPluginName().GetCString());
2621 // This is implemented completely using the lldb::Process API. Subclasses
2622 // don't need to implement this function unless the standard flow of
2623 // read existing opcode, write breakpoint opcode, verify breakpoint opcode
2624 // doesn't work for a specific process plug-in.
2626 EnableSoftwareBreakpoint (BreakpointSite *bp_site);
2628 // This is implemented completely using the lldb::Process API. Subclasses
2629 // don't need to implement this function unless the standard flow of
2630 // restoring original opcode in memory and verifying the restored opcode
2631 // doesn't work for a specific process plug-in.
2633 DisableSoftwareBreakpoint (BreakpointSite *bp_site);
2635 BreakpointSiteList &
2636 GetBreakpointSiteList();
2638 const BreakpointSiteList &
2639 GetBreakpointSiteList() const;
2642 DisableAllBreakpointSites ();
2645 ClearBreakpointSiteByID (lldb::user_id_t break_id);
2648 CreateBreakpointSite (const lldb::BreakpointLocationSP &owner,
2652 DisableBreakpointSiteByID (lldb::user_id_t break_id);
2655 EnableBreakpointSiteByID (lldb::user_id_t break_id);
2658 // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove
2659 // themselves from the owner's list of this breakpoint sites.
2661 RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id,
2662 lldb::user_id_t owner_loc_id,
2663 lldb::BreakpointSiteSP &bp_site_sp);
2665 //----------------------------------------------------------------------
2666 // Process Watchpoints (optional)
2667 //----------------------------------------------------------------------
2669 EnableWatchpoint (Watchpoint *wp, bool notify = true);
2672 DisableWatchpoint (Watchpoint *wp, bool notify = true);
2674 //------------------------------------------------------------------
2676 //------------------------------------------------------------------
2678 UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) = 0;
2681 UpdateThreadListIfNeeded ();
2686 return m_thread_list;
2689 // When ExtendedBacktraces are requested, the HistoryThreads that are
2690 // created need an owner -- they're saved here in the Process. The
2691 // threads in this list are not iterated over - driver programs need to
2692 // request the extended backtrace calls starting from a root concrete
2693 // thread one by one.
2695 GetExtendedThreadList ()
2697 return m_extended_thread_list;
2700 ThreadList::ThreadIterable
2703 return m_thread_list.Threads();
2707 GetNextThreadIndexID (uint64_t thread_id);
2710 CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
2712 // Returns true if an index id has been assigned to a thread.
2714 HasAssignedIndexIDToThread(uint64_t sb_thread_id);
2716 // Given a thread_id, it will assign a more reasonable index id for display to the user.
2717 // If the thread_id has previously been assigned, the same index id will be used.
2719 AssignIndexIDToThread(uint64_t thread_id);
2721 //------------------------------------------------------------------
2723 //------------------------------------------------------------------
2726 UpdateQueueListIfNeeded ();
2731 UpdateQueueListIfNeeded();
2732 return m_queue_list;
2735 QueueList::QueueIterable
2738 UpdateQueueListIfNeeded();
2739 return m_queue_list.Queues();
2742 //------------------------------------------------------------------
2744 //------------------------------------------------------------------
2746 GetNextEvent (lldb::EventSP &event_sp);
2748 // Returns the process state when it is stopped. If specified, event_sp_ptr
2749 // is set to the event which triggered the stop. If wait_always = false,
2750 // and the process is already stopped, this function returns immediately.
2752 WaitForProcessToStop (const TimeValue *timeout,
2753 lldb::EventSP *event_sp_ptr = NULL,
2754 bool wait_always = true,
2755 Listener *hijack_listener = NULL,
2756 Stream *stream = NULL);
2759 //--------------------------------------------------------------------------------------
2760 /// Waits for the process state to be running within a given msec timeout.
2762 /// The main purpose of this is to implement an interlock waiting for HandlePrivateEvent
2763 /// to push an IOHandler.
2765 /// @param[in] timeout_msec
2766 /// The maximum time length to wait for the process to transition to the
2767 /// eStateRunning state, specified in milliseconds.
2770 /// true if successfully signalled that process started and IOHandler pushes, false
2771 /// if it timed out.
2772 //--------------------------------------------------------------------------------------
2774 SyncIOHandler (uint64_t timeout_msec);
2778 WaitForStateChangedEvents (const TimeValue *timeout,
2779 lldb::EventSP &event_sp,
2780 Listener *hijack_listener); // Pass NULL to use builtin listener
2782 //--------------------------------------------------------------------------------------
2783 /// Centralize the code that handles and prints descriptions for process state changes.
2785 /// @param[in] event_sp
2786 /// The process state changed event
2788 /// @param[in] stream
2789 /// The output stream to get the state change description
2791 /// @param[inout] pop_process_io_handler
2792 /// If this value comes in set to \b true, then pop the Process IOHandler if needed.
2793 /// Else this variable will be set to \b true or \b false to indicate if the process
2794 /// needs to have its process IOHandler popped.
2797 /// \b true if the event describes a process state changed event, \b false otherwise.
2798 //--------------------------------------------------------------------------------------
2800 HandleProcessStateChangedEvent (const lldb::EventSP &event_sp,
2802 bool &pop_process_io_handler);
2804 PeekAtStateChangedEvents ();
2808 ProcessEventHijacker
2811 ProcessEventHijacker (Process &process, Listener *listener) :
2814 m_process.HijackProcessEvents (listener);
2816 ~ProcessEventHijacker ()
2818 m_process.RestoreProcessEvents();
2824 friend class ProcessEventHijacker;
2825 friend class ProcessProperties;
2826 //------------------------------------------------------------------
2827 /// If you need to ensure that you and only you will hear about some public
2828 /// event, then make a new listener, set to listen to process events, and
2829 /// then call this with that listener. Then you will have to wait on that
2830 /// listener explicitly for events (rather than using the GetNextEvent & WaitFor*
2831 /// calls above. Be sure to call RestoreProcessEvents when you are done.
2833 /// @param[in] listener
2834 /// This is the new listener to whom all process events will be delivered.
2837 /// Returns \b true if the new listener could be installed,
2838 /// \b false otherwise.
2839 //------------------------------------------------------------------
2841 HijackProcessEvents (Listener *listener);
2843 //------------------------------------------------------------------
2844 /// Restores the process event broadcasting to its normal state.
2846 //------------------------------------------------------------------
2848 RestoreProcessEvents ();
2851 //------------------------------------------------------------------
2852 /// This is the part of the event handling that for a process event.
2853 /// It decides what to do with the event and returns true if the
2854 /// event needs to be propagated to the user, and false otherwise.
2855 /// If the event is not propagated, this call will most likely set
2856 /// the target to executing again.
2857 /// There is only one place where this call should be called, HandlePrivateEvent.
2858 /// Don't call it from anywhere else...
2860 /// @param[in] event_ptr
2861 /// This is the event we are handling.
2864 /// Returns \b true if the event should be reported to the
2865 /// user, \b false otherwise.
2866 //------------------------------------------------------------------
2868 ShouldBroadcastEvent (Event *event_ptr);
2875 GetOperatingSystem ()
2877 return m_os_ap.get();
2880 ArchSpec::StopInfoOverrideCallbackType
2881 GetStopInfoOverrideCallback () const
2883 return m_stop_info_override_callback;
2886 virtual LanguageRuntime *
2887 GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true);
2889 virtual CPPLanguageRuntime *
2890 GetCPPLanguageRuntime (bool retry_if_null = true);
2892 virtual ObjCLanguageRuntime *
2893 GetObjCLanguageRuntime (bool retry_if_null = true);
2896 IsPossibleDynamicValue (ValueObject& in_value);
2901 DynamicCheckerFunctions *GetDynamicCheckers()
2903 return m_dynamic_checkers_ap.get();
2906 void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers)
2908 m_dynamic_checkers_ap.reset(dynamic_checkers);
2911 //------------------------------------------------------------------
2912 /// Call this to set the lldb in the mode where it breaks on new thread
2913 /// creations, and then auto-restarts. This is useful when you are trying
2914 /// to run only one thread, but either that thread or the kernel is creating
2915 /// new threads in the process. If you stop when the thread is created, you
2916 /// can immediately suspend it, and keep executing only the one thread you intend.
2919 /// Returns \b true if we were able to start up the notification
2920 /// \b false otherwise.
2921 //------------------------------------------------------------------
2923 StartNoticingNewThreads()
2928 //------------------------------------------------------------------
2929 /// Call this to turn off the stop & notice new threads mode.
2932 /// Returns \b true if we were able to start up the notification
2933 /// \b false otherwise.
2934 //------------------------------------------------------------------
2936 StopNoticingNewThreads()
2942 SetRunningUserExpression (bool on);
2944 //------------------------------------------------------------------
2945 // lldb::ExecutionContextScope pure virtual functions
2946 //------------------------------------------------------------------
2947 virtual lldb::TargetSP
2950 virtual lldb::ProcessSP
2953 return shared_from_this();
2956 virtual lldb::ThreadSP
2959 return lldb::ThreadSP();
2962 virtual lldb::StackFrameSP
2963 CalculateStackFrame ()
2965 return lldb::StackFrameSP();
2969 CalculateExecutionContext (ExecutionContext &exe_ctx);
2972 SetSTDIOFileDescriptor (int file_descriptor);
2974 //------------------------------------------------------------------
2975 // Add a permanent region of memory that should never be read or
2976 // written to. This can be used to ensure that memory reads or writes
2977 // to certain areas of memory never end up being sent to the
2978 // DoReadMemory or DoWriteMemory functions which can improve
2980 //------------------------------------------------------------------
2982 AddInvalidMemoryRegion (const LoadRange ®ion);
2984 //------------------------------------------------------------------
2985 // Remove a permanent region of memory that should never be read or
2986 // written to that was previously added with AddInvalidMemoryRegion.
2987 //------------------------------------------------------------------
2989 RemoveInvalidMemoryRange (const LoadRange ®ion);
2991 //------------------------------------------------------------------
2992 // If the setup code of a thread plan needs to do work that might involve
2993 // calling a function in the target, it should not do that work directly
2994 // in one of the thread plan functions (DidPush/WillResume) because
2995 // such work needs to be handled carefully. Instead, put that work in
2996 // a PreResumeAction callback, and register it with the process. It will
2997 // get done before the actual "DoResume" gets called.
2998 //------------------------------------------------------------------
3000 typedef bool (PreResumeActionCallback)(void *);
3003 AddPreResumeAction (PreResumeActionCallback callback, void *baton);
3006 RunPreResumeActions ();
3009 ClearPreResumeActions ();
3014 if (m_private_state_thread.EqualsThread(Host::GetCurrentThread()))
3015 return m_private_run_lock;
3017 return m_public_run_lock;
3022 SendEventData(const char *data)
3024 Error return_error ("Sending an event is not supported for this process.");
3025 return return_error;
3028 lldb::ThreadCollectionSP
3029 GetHistoryThreads(lldb::addr_t addr);
3031 lldb::InstrumentationRuntimeSP
3032 GetInstrumentationRuntime(lldb::InstrumentationRuntimeType type);
3036 //------------------------------------------------------------------
3037 // NextEventAction provides a way to register an action on the next
3038 // event that is delivered to this process. There is currently only
3039 // one next event action allowed in the process at one time. If a
3040 // new "NextEventAction" is added while one is already present, the
3041 // old action will be discarded (with HandleBeingUnshipped called
3042 // after it is discarded.)
3044 // If you want to resume the process as a result of a resume action,
3045 // call RequestResume, don't call Resume directly.
3046 //------------------------------------------------------------------
3047 class NextEventAction
3050 typedef enum EventActionResult
3052 eEventActionSuccess,
3055 } EventActionResult;
3057 NextEventAction (Process *process) :
3067 virtual EventActionResult PerformAction (lldb::EventSP &event_sp) = 0;
3068 virtual void HandleBeingUnshipped () {}
3069 virtual EventActionResult HandleBeingInterrupted () = 0;
3070 virtual const char *GetExitString() = 0;
3071 void RequestResume()
3073 m_process->m_resume_requested = true;
3079 void SetNextEventAction (Process::NextEventAction *next_event_action)
3081 if (m_next_event_action_ap.get())
3082 m_next_event_action_ap->HandleBeingUnshipped();
3084 m_next_event_action_ap.reset(next_event_action);
3087 // This is the completer for Attaching:
3088 class AttachCompletionHandler : public NextEventAction
3091 AttachCompletionHandler (Process *process, uint32_t exec_count);
3094 ~AttachCompletionHandler()
3098 virtual EventActionResult PerformAction (lldb::EventSP &event_sp);
3099 virtual EventActionResult HandleBeingInterrupted ();
3100 virtual const char *GetExitString();
3102 uint32_t m_exec_count;
3103 std::string m_exit_string;
3107 HijackPrivateProcessEvents (Listener *listener);
3110 RestorePrivateProcessEvents ();
3113 PrivateStateThreadIsValid () const
3115 return m_private_state_thread.IsJoinable();
3119 ForceNextEventDelivery()
3121 m_force_next_event_delivery = true;
3124 //------------------------------------------------------------------
3126 //------------------------------------------------------------------
3127 typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection;
3129 struct PreResumeCallbackAndBaton
3131 bool (*callback) (void *);
3133 PreResumeCallbackAndBaton (PreResumeActionCallback in_callback, void *in_baton) :
3134 callback (in_callback),
3140 //------------------------------------------------------------------
3142 //------------------------------------------------------------------
3143 Target & m_target; ///< The target that owns this process.
3144 ThreadSafeValue<lldb::StateType> m_public_state;
3145 ThreadSafeValue<lldb::StateType> m_private_state; // The actual state of our process
3146 Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener.
3147 Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread.
3148 Listener m_private_state_listener; // This is the listener for the private state thread.
3149 Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete.
3150 HostThread m_private_state_thread; // Thread ID for the thread that watches internal state events
3151 ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations.
3152 uint32_t m_process_unique_id; ///< Each lldb_private::Process class that is created gets a unique integer ID that increments with each new instance
3153 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used.
3154 std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map;
3155 int m_exit_status; ///< The exit status of the process, or -1 if not set.
3156 std::string m_exit_string; ///< A textual description of why a process exited.
3157 Mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can be safely accessed from multiple threads
3158 Mutex m_thread_mutex;
3159 ThreadList m_thread_list_real; ///< The threads for this process as are known to the protocol we are debugging with
3160 ThreadList m_thread_list; ///< The threads for this process as the user will see them. This is usually the same as
3161 ///< m_thread_list_real, but might be different if there is an OS plug-in creating memory threads
3162 ThreadList m_extended_thread_list; ///< Owner for extended threads that may be generated, cleared on natural stops
3163 uint32_t m_extended_thread_stop_id; ///< The natural stop id when extended_thread_list was last updated
3164 QueueList m_queue_list; ///< The list of libdispatch queues at a given stop point
3165 uint32_t m_queue_list_stop_id; ///< The natural stop id when queue list was last fetched
3166 std::vector<Notifications> m_notifications; ///< The list of notifications that this process can deliver.
3167 std::vector<lldb::addr_t> m_image_tokens;
3168 Listener &m_listener;
3169 BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend to insert in the target.
3170 std::unique_ptr<DynamicLoader> m_dyld_ap;
3171 std::unique_ptr<JITLoaderList> m_jit_loaders_ap;
3172 std::unique_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use.
3173 std::unique_ptr<OperatingSystem> m_os_ap;
3174 std::unique_ptr<SystemRuntime> m_system_runtime_ap;
3175 UnixSignalsSP m_unix_signals_sp; /// This is the current signal set for this process.
3176 lldb::ABISP m_abi_sp;
3177 lldb::IOHandlerSP m_process_input_reader;
3178 Communication m_stdio_communication;
3179 Mutex m_stdio_communication_mutex;
3180 std::string m_stdout_data;
3181 std::string m_stderr_data;
3182 Mutex m_profile_data_comm_mutex;
3183 std::vector<std::string> m_profile_data;
3184 Predicate<bool> m_iohandler_sync;
3185 MemoryCache m_memory_cache;
3186 AllocatedMemoryCache m_allocated_memory_cache;
3187 bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach?
3188 LanguageRuntimeCollection m_language_runtimes;
3189 InstrumentationRuntimeCollection m_instrumentation_runtimes;
3190 std::unique_ptr<NextEventAction> m_next_event_action_ap;
3191 std::vector<PreResumeCallbackAndBaton> m_pre_resume_actions;
3192 ProcessRunLock m_public_run_lock;
3193 ProcessRunLock m_private_run_lock;
3194 Predicate<bool> m_currently_handling_event; // This predicate is set in HandlePrivateEvent while all its business is being done.
3195 ArchSpec::StopInfoOverrideCallbackType m_stop_info_override_callback;
3196 bool m_currently_handling_do_on_removals;
3197 bool m_resume_requested; // If m_currently_handling_event or m_currently_handling_do_on_removals are true, Resume will only request a resume, using this flag to check.
3198 bool m_finalize_called;
3199 bool m_clear_thread_plans_on_stop;
3200 bool m_force_next_event_delivery;
3201 lldb::StateType m_last_broadcast_state; /// This helps with the Public event coalescing in ShouldBroadcastEvent.
3202 std::map<lldb::addr_t,lldb::addr_t> m_resolved_indirect_addresses;
3203 bool m_destroy_in_process;
3212 RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const;
3215 SynchronouslyNotifyStateChanged (lldb::StateType state);
3218 SetPublicState (lldb::StateType new_state, bool restarted);
3221 SetPrivateState (lldb::StateType state);
3224 StartPrivateStateThread (bool force = false);
3227 StopPrivateStateThread ();
3230 PausePrivateStateThread ();
3233 ResumePrivateStateThread ();
3235 static lldb::thread_result_t
3236 PrivateStateThread (void *arg);
3238 lldb::thread_result_t
3239 RunPrivateStateThread ();
3242 HandlePrivateEvent (lldb::EventSP &event_sp);
3245 WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
3247 // This waits for both the state change broadcaster, and the control broadcaster.
3248 // If control_only, it only waits for the control broadcaster.
3251 WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only);
3254 WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
3257 WaitForState (const TimeValue *timeout,
3258 const lldb::StateType *match_states,
3259 const uint32_t num_match_states);
3262 WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error);
3265 AppendSTDOUT (const char *s, size_t len);
3268 AppendSTDERR (const char *s, size_t len);
3271 BroadcastAsyncProfileData(const std::string &one_profile_data);
3274 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
3277 PushProcessIOHandler ();
3280 PopProcessIOHandler ();
3283 ProcessIOHandlerIsActive ();
3286 HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp);
3289 StateChangedIsExternallyHijacked();
3292 LoadOperatingSystemPlugin(bool flush);
3294 //------------------------------------------------------------------
3296 //------------------------------------------------------------------
3297 void ControlPrivateStateThread (uint32_t signal);
3299 DISALLOW_COPY_AND_ASSIGN (Process);
3303 } // namespace lldb_private
3305 #endif // liblldb_Process_h_