diff options
Diffstat (limited to 'include/lldb/Target/Process.h')
-rw-r--r-- | include/lldb/Target/Process.h | 163 |
1 files changed, 141 insertions, 22 deletions
diff --git a/include/lldb/Target/Process.h b/include/lldb/Target/Process.h index 641707c58deb..e04de511c797 100644 --- a/include/lldb/Target/Process.h +++ b/include/lldb/Target/Process.h @@ -38,6 +38,7 @@ #include "lldb/Expression/IRDynamicChecks.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" +#include "lldb/Host/HostThread.h" #include "lldb/Host/ProcessRunLock.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/Options.h" @@ -51,6 +52,7 @@ #include "lldb/Target/ThreadList.h" #include "lldb/Target/UnixSignals.h" #include "lldb/Utility/PseudoTerminal.h" +#include "lldb/Target/InstrumentationRuntime.h" namespace lldb_private { @@ -60,7 +62,8 @@ namespace lldb_private { class ProcessProperties : public Properties { public: - ProcessProperties(bool is_global); + // Pass NULL for "process" if the ProcessProperties are to be the global copy + ProcessProperties (lldb_private::Process *process); virtual ~ProcessProperties(); @@ -68,6 +71,9 @@ public: bool GetDisableMemoryCache() const; + uint64_t + GetMemoryCacheLineSize () const; + Args GetExtraStartupCommands () const; @@ -103,6 +109,13 @@ public: void SetDetachKeepsStopped (bool keep_stopped); + +protected: + + static void + OptionValueChangedCallback (void *baton, OptionValue *option_value); + + Process * m_process; // Can be NULL for global ProcessProperties }; typedef std::shared_ptr<ProcessProperties> ProcessPropertiesSP; @@ -223,6 +236,8 @@ class ProcessAttachInfo : public ProcessInstanceInfo public: ProcessAttachInfo() : ProcessInstanceInfo(), + m_listener_sp(), + m_hijack_listener_sp(), m_plugin_name (), m_resume_count (0), m_wait_for_launch (false), @@ -234,6 +249,8 @@ public: ProcessAttachInfo (const ProcessLaunchInfo &launch_info) : ProcessInstanceInfo(), + m_listener_sp(), + m_hijack_listener_sp(), m_plugin_name (), m_resume_count (0), m_wait_for_launch (false), @@ -244,6 +261,7 @@ public: ProcessInfo::operator= (launch_info); SetProcessPluginName (launch_info.GetProcessPluginName()); SetResumeCount (launch_info.GetResumeCount()); + SetListener(launch_info.GetListener()); SetHijackListener(launch_info.GetHijackListener()); m_detach_on_error = launch_info.GetDetachOnError(); } @@ -359,8 +377,26 @@ public: { m_detach_on_error = enable; } - + + // Get and set the actual listener that will be used for the process events + lldb::ListenerSP + GetListener () const + { + return m_listener_sp; + } + + void + SetListener (const lldb::ListenerSP &listener_sp) + { + m_listener_sp = listener_sp; + } + + + Listener & + GetListenerForProcess (Debugger &debugger); + protected: + lldb::ListenerSP m_listener_sp; lldb::ListenerSP m_hijack_listener_sp; std::string m_plugin_name; uint32_t m_resume_count; // How many times do we resume after launching @@ -1268,7 +1304,9 @@ public: //------------------------------------------------------------------ Error Resume(); - + + Error + ResumeSynchronous (Stream *stream); //------------------------------------------------------------------ /// Halts a running process. /// @@ -2447,17 +2485,26 @@ public: //------------------------------------------------------------------ /// Get any available STDOUT. /// - /// If the process was launched without supplying valid file paths - /// for stdin, stdout, and stderr, then the Process class might - /// try to cache the STDOUT for the process if it is able. Events - /// will be queued indicating that there is STDOUT available that - /// can be retrieved using this function. + /// Calling this method is a valid operation only if all of the + /// following conditions are true: + /// 1) The process was launched, and not attached to. + /// 2) The process was not launched with eLaunchFlagDisableSTDIO. + /// 3) The process was launched without supplying a valid file path + /// for STDOUT. + /// + /// Note that the implementation will probably need to start a read + /// thread in the background to make sure that the pipe is drained + /// and the STDOUT buffered appropriately, to prevent the process + /// from deadlocking trying to write to a full buffer. + /// + /// Events will be queued indicating that there is STDOUT available + /// that can be retrieved using this function. /// /// @param[out] buf /// A buffer that will receive any STDOUT bytes that are /// currently available. /// - /// @param[out] buf_size + /// @param[in] buf_size /// The size in bytes for the buffer \a buf. /// /// @return @@ -2471,13 +2518,22 @@ public: //------------------------------------------------------------------ /// Get any available STDERR. /// - /// If the process was launched without supplying valid file paths - /// for stdin, stdout, and stderr, then the Process class might - /// try to cache the STDERR for the process if it is able. Events - /// will be queued indicating that there is STDERR available that - /// can be retrieved using this function. + /// Calling this method is a valid operation only if all of the + /// following conditions are true: + /// 1) The process was launched, and not attached to. + /// 2) The process was not launched with eLaunchFlagDisableSTDIO. + /// 3) The process was launched without supplying a valid file path + /// for STDERR. /// - /// @param[out] buf + /// Note that the implementation will probably need to start a read + /// thread in the background to make sure that the pipe is drained + /// and the STDERR buffered appropriately, to prevent the process + /// from deadlocking trying to write to a full buffer. + /// + /// Events will be queued indicating that there is STDERR available + /// that can be retrieved using this function. + /// + /// @param[in] buf /// A buffer that will receive any STDERR bytes that are /// currently available. /// @@ -2492,6 +2548,27 @@ public: virtual size_t GetSTDERR (char *buf, size_t buf_size, Error &error); + //------------------------------------------------------------------ + /// Puts data into this process's STDIN. + /// + /// Calling this method is a valid operation only if all of the + /// following conditions are true: + /// 1) The process was launched, and not attached to. + /// 2) The process was not launched with eLaunchFlagDisableSTDIO. + /// 3) The process was launched without supplying a valid file path + /// for STDIN. + /// + /// @param[in] buf + /// A buffer that contains the data to write to the process's STDIN. + /// + /// @param[in] buf_size + /// The size in bytes for the buffer \a buf. + /// + /// @return + /// The number of bytes written into \a buf. If this value is + /// less than \a buf_size, another call to this function should + /// be made to write the rest of the data. + //------------------------------------------------------------------ virtual size_t PutSTDIN (const char *buf, size_t buf_size, Error &error) { @@ -2675,7 +2752,8 @@ public: WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr = NULL, bool wait_always = true, - Listener *hijack_listener = NULL); + Listener *hijack_listener = NULL, + Stream *stream = NULL); //-------------------------------------------------------------------------------------- @@ -2700,7 +2778,28 @@ public: WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp, Listener *hijack_listener); // Pass NULL to use builtin listener - + + //-------------------------------------------------------------------------------------- + /// Centralize the code that handles and prints descriptions for process state changes. + /// + /// @param[in] event_sp + /// The process state changed event + /// + /// @param[in] stream + /// The output stream to get the state change description + /// + /// @param[inout] pop_process_io_handler + /// If this value comes in set to \b true, then pop the Process IOHandler if needed. + /// Else this variable will be set to \b true or \b false to indicate if the process + /// needs to have its process IOHandler popped. + /// + /// @return + /// \b true if the event describes a process state changed event, \b false otherwise. + //-------------------------------------------------------------------------------------- + static bool + HandleProcessStateChangedEvent (const lldb::EventSP &event_sp, + Stream *stream, + bool &pop_process_io_handler); Event * PeekAtStateChangedEvents (); @@ -2723,6 +2822,7 @@ public: Process &m_process; }; friend class ProcessEventHijacker; + friend class ProcessProperties; //------------------------------------------------------------------ /// If you need to ensure that you and only you will hear about some public /// event, then make a new listener, set to listen to process events, and @@ -2776,7 +2876,12 @@ public: { return m_os_ap.get(); } - + + ArchSpec::StopInfoOverrideCallbackType + GetStopInfoOverrideCallback () const + { + return m_stop_info_override_callback; + } virtual LanguageRuntime * GetLanguageRuntime (lldb::LanguageType language, bool retry_if_null = true); @@ -2906,7 +3011,7 @@ public: ProcessRunLock & GetRunLock () { - if (Host::GetCurrentThread() == m_private_state_thread) + if (m_private_state_thread.EqualsThread(Host::GetCurrentThread())) return m_private_run_lock; else return m_public_run_lock; @@ -2919,6 +3024,12 @@ public: Error return_error ("Sending an event is not supported for this process."); return return_error; } + + lldb::ThreadCollectionSP + GetHistoryThreads(lldb::addr_t addr); + + lldb::InstrumentationRuntimeSP + GetInstrumentationRuntime(lldb::InstrumentationRuntimeType type); protected: @@ -3001,7 +3112,7 @@ protected: bool PrivateStateThreadIsValid () const { - return IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); + return m_private_state_thread.IsJoinable(); } void @@ -3036,13 +3147,14 @@ protected: Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. Listener m_private_state_listener; // This is the listener for the private state thread. Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. - lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches internal state events + HostThread m_private_state_thread; // Thread ID for the thread that watches internal state events ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations. 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 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map; int m_exit_status; ///< The exit status of the process, or -1 if not set. std::string m_exit_string; ///< A textual description of why a process exited. + Mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can be safely accessed from multiple threads Mutex m_thread_mutex; ThreadList m_thread_list_real; ///< The threads for this process as are known to the protocol we are debugging with ThreadList m_thread_list; ///< The threads for this process as the user will see them. This is usually the same as @@ -3074,11 +3186,13 @@ protected: AllocatedMemoryCache m_allocated_memory_cache; bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach? LanguageRuntimeCollection m_language_runtimes; + InstrumentationRuntimeCollection m_instrumentation_runtimes; std::unique_ptr<NextEventAction> m_next_event_action_ap; std::vector<PreResumeCallbackAndBaton> m_pre_resume_actions; ProcessRunLock m_public_run_lock; ProcessRunLock m_private_run_lock; Predicate<bool> m_currently_handling_event; // This predicate is set in HandlePrivateEvent while all its business is being done. + ArchSpec::StopInfoOverrideCallbackType m_stop_info_override_callback; bool m_currently_handling_do_on_removals; 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. bool m_finalize_called; @@ -3170,7 +3284,12 @@ protected: Error HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp); - + + bool + StateChangedIsExternallyHijacked(); + + void + LoadOperatingSystemPlugin(bool flush); private: //------------------------------------------------------------------ // For Process only |