Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 1 | //===-- ProcessMonitor.h -------------------------------------- -*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef liblldb_ProcessMonitor_H_ |
| 10 | #define liblldb_ProcessMonitor_H_ |
| 11 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 12 | #include <semaphore.h> |
| 13 | #include <signal.h> |
| 14 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 15 | #include <mutex> |
| 16 | |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 17 | #include "lldb/Host/HostThread.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/FileSpec.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/lldb-types.h" |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | namespace lldb_private { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 22 | class Status; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 23 | class Module; |
| 24 | class Scalar; |
| 25 | } // End lldb_private namespace. |
| 26 | |
| 27 | class ProcessFreeBSD; |
| 28 | class Operation; |
| 29 | |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 30 | /// \class ProcessMonitor |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 31 | /// Manages communication with the inferior (debugee) process. |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 32 | /// |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 33 | /// Upon construction, this class prepares and launches an inferior process |
| 34 | /// for debugging. |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 35 | /// |
| 36 | /// Changes in the inferior process state are propagated to the associated |
| 37 | /// ProcessFreeBSD instance by calling ProcessFreeBSD::SendMessage with the |
| 38 | /// appropriate ProcessMessage events. |
| 39 | /// |
| 40 | /// A purposely minimal set of operations are provided to interrogate and change |
| 41 | /// the inferior process state. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | class ProcessMonitor { |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 43 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | /// Launches an inferior process ready for debugging. Forms the |
| 45 | /// implementation of Process::DoLaunch. |
| 46 | ProcessMonitor(ProcessFreeBSD *process, lldb_private::Module *module, |
Pavel Labath | 75c6de0 | 2018-01-10 13:53:40 +0000 | [diff] [blame] | 47 | char const *argv[], lldb_private::Environment env, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | const lldb_private::FileSpec &stdin_file_spec, |
| 49 | const lldb_private::FileSpec &stdout_file_spec, |
| 50 | const lldb_private::FileSpec &stderr_file_spec, |
| 51 | const lldb_private::FileSpec &working_dir, |
| 52 | const lldb_private::ProcessLaunchInfo &launch_info, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 53 | lldb_private::Status &error); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 56 | lldb_private::Status &error); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | ~ProcessMonitor(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | /// Provides the process number of debugee. |
| 61 | lldb::pid_t GetPID() const { return m_pid; } |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | /// Returns the process associated with this ProcessMonitor. |
| 64 | ProcessFreeBSD &GetProcess() { return *m_process; } |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 65 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | /// Returns a file descriptor to the controlling terminal of the inferior |
| 67 | /// process. |
| 68 | /// |
| 69 | /// Reads from this file descriptor yield both the standard output and |
| 70 | /// standard error of this debugee. Even if stderr and stdout were |
| 71 | /// redirected on launch it may still happen that data is available on this |
| 72 | /// descriptor (if the inferior process opens /dev/tty, for example). This |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 73 | /// descriptor is closed after a call to StopMonitor(). |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | /// |
| 75 | /// If this monitor was attached to an existing process this method returns |
| 76 | /// -1. |
| 77 | int GetTerminalFD() const { return m_terminal_fd; } |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 78 | |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 79 | /// Reads \p size bytes from address @vm_adder in the inferior process |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | /// address space. |
| 81 | /// |
| 82 | /// This method is provided to implement Process::DoReadMemory. |
| 83 | size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 84 | lldb_private::Status &error); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 85 | |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 86 | /// Writes \p size bytes from address \p vm_adder in the inferior process |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | /// address space. |
| 88 | /// |
| 89 | /// This method is provided to implement Process::DoWriteMemory. |
| 90 | size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 91 | lldb_private::Status &error); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 92 | |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 93 | /// Reads the contents from the register identified by the given |
| 94 | /// (architecture dependent) offset. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | /// |
| 96 | /// This method is provided for use by RegisterContextFreeBSD derivatives. |
| 97 | bool ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name, |
| 98 | unsigned size, lldb_private::RegisterValue &value); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | /// Writes the given value to the register identified by the given |
| 101 | /// (architecture dependent) offset. |
| 102 | /// |
| 103 | /// This method is provided for use by RegisterContextFreeBSD derivatives. |
| 104 | bool WriteRegisterValue(lldb::tid_t tid, unsigned offset, |
| 105 | const char *reg_name, |
| 106 | const lldb_private::RegisterValue &value); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | /// Reads the contents from the debug register identified by the given |
| 109 | /// (architecture dependent) offset. |
| 110 | /// |
| 111 | /// This method is provided for use by RegisterContextFreeBSD derivatives. |
| 112 | bool ReadDebugRegisterValue(lldb::tid_t tid, unsigned offset, |
| 113 | const char *reg_name, unsigned size, |
| 114 | lldb_private::RegisterValue &value); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 115 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | /// Writes the given value to the debug register identified by the given |
| 117 | /// (architecture dependent) offset. |
| 118 | /// |
| 119 | /// This method is provided for use by RegisterContextFreeBSD derivatives. |
| 120 | bool WriteDebugRegisterValue(lldb::tid_t tid, unsigned offset, |
| 121 | const char *reg_name, |
| 122 | const lldb_private::RegisterValue &value); |
| 123 | /// Reads all general purpose registers into the specified buffer. |
| 124 | bool ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size); |
Ed Maste | a4be2c5 | 2014-02-19 18:34:06 +0000 | [diff] [blame] | 125 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | /// Reads all floating point registers into the specified buffer. |
| 127 | bool ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 128 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | /// Reads the specified register set into the specified buffer. |
| 130 | /// |
| 131 | /// This method is provided for use by RegisterContextFreeBSD derivatives. |
| 132 | bool ReadRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, |
| 133 | unsigned int regset); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 134 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | /// Writes all general purpose registers into the specified buffer. |
| 136 | bool WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size); |
Ashok Thirumurthi | 0f3b9b8 | 2013-05-01 20:38:19 +0000 | [diff] [blame] | 137 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | /// Writes all floating point registers into the specified buffer. |
| 139 | bool WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | /// Writes the specified register set into the specified buffer. |
| 142 | /// |
| 143 | /// This method is provided for use by RegisterContextFreeBSD derivatives. |
| 144 | bool WriteRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, |
| 145 | unsigned int regset); |
Ashok Thirumurthi | 0f3b9b8 | 2013-05-01 20:38:19 +0000 | [diff] [blame] | 146 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 147 | /// Reads the value of the thread-specific pointer for a given thread ID. |
| 148 | bool ReadThreadPointer(lldb::tid_t tid, lldb::addr_t &value); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | /// Returns current thread IDs in process |
| 151 | size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids); |
Ed Maste | 68f5179 | 2013-10-18 19:16:44 +0000 | [diff] [blame] | 152 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | /// Writes a ptrace_lwpinfo structure corresponding to the given thread ID |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 154 | /// to the memory region pointed to by \p lwpinfo. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | bool GetLwpInfo(lldb::tid_t tid, void *lwpinfo, int &error_no); |
Ed Maste | 7fd845c | 2013-12-09 15:51:17 +0000 | [diff] [blame] | 156 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | /// Suspends or unsuspends a thread prior to process resume or step. |
| 158 | bool ThreadSuspend(lldb::tid_t tid, bool suspend); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 159 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) |
| 161 | /// corresponding to the given thread IDto the memory pointed to by @p |
| 162 | /// message. |
| 163 | bool GetEventMessage(lldb::tid_t tid, unsigned long *message); |
Ed Maste | 7fd845c | 2013-12-09 15:51:17 +0000 | [diff] [blame] | 164 | |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 165 | /// Resumes the process. If \p signo is anything but |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process. |
| 167 | bool Resume(lldb::tid_t unused, uint32_t signo); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 168 | |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 169 | /// Single steps the process. If \p signo is anything but |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process. |
| 171 | bool SingleStep(lldb::tid_t unused, uint32_t signo); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 172 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 173 | /// Terminate the traced process. |
| 174 | bool Kill(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 175 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 176 | lldb_private::Status Detach(lldb::tid_t tid); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | void StopMonitor(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 179 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | // Waits for the initial stop message from a new thread. |
| 181 | bool WaitForInitialTIDStop(lldb::tid_t tid); |
Andrew Kaylor | d4d5499 | 2013-09-17 00:30:24 +0000 | [diff] [blame] | 182 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 183 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | ProcessFreeBSD *m_process; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 185 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | lldb_private::HostThread m_operation_thread; |
| 187 | lldb_private::HostThread m_monitor_thread; |
| 188 | lldb::pid_t m_pid; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 189 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | int m_terminal_fd; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | // current operation which must be executed on the privileged thread |
| 193 | Operation *m_operation; |
| 194 | std::mutex m_operation_mutex; |
Ed Maste | 756e1ff | 2013-09-18 19:34:08 +0000 | [diff] [blame] | 195 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | // semaphores notified when Operation is ready to be processed and when |
| 197 | // the operation is complete. |
| 198 | sem_t m_operation_pending; |
| 199 | sem_t m_operation_done; |
Ed Maste | 41fba2b | 2015-06-01 15:24:37 +0000 | [diff] [blame] | 200 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | struct OperationArgs { |
| 202 | OperationArgs(ProcessMonitor *monitor); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 203 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | ~OperationArgs(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | ProcessMonitor *m_monitor; // The monitor performing the attach. |
| 207 | sem_t m_semaphore; // Posted to once operation complete. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 208 | lldb_private::Status m_error; // Set if process operation failed. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | }; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 210 | |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame^] | 211 | /// \class LauchArgs |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 212 | /// |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 213 | /// Simple structure to pass data to the thread responsible for launching a |
| 214 | /// child process. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 215 | struct LaunchArgs : OperationArgs { |
| 216 | LaunchArgs(ProcessMonitor *monitor, lldb_private::Module *module, |
Pavel Labath | 75c6de0 | 2018-01-10 13:53:40 +0000 | [diff] [blame] | 217 | char const **argv, lldb_private::Environment env, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | const lldb_private::FileSpec &stdin_file_spec, |
| 219 | const lldb_private::FileSpec &stdout_file_spec, |
| 220 | const lldb_private::FileSpec &stderr_file_spec, |
| 221 | const lldb_private::FileSpec &working_dir); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 222 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 223 | ~LaunchArgs(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 224 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 225 | lldb_private::Module *m_module; // The executable image to launch. |
| 226 | char const **m_argv; // Process arguments. |
Pavel Labath | 75c6de0 | 2018-01-10 13:53:40 +0000 | [diff] [blame] | 227 | lldb_private::Environment m_env; // Process environment. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 228 | const lldb_private::FileSpec m_stdin_file_spec; // Redirect stdin or empty. |
| 229 | const lldb_private::FileSpec |
| 230 | m_stdout_file_spec; // Redirect stdout or empty. |
| 231 | const lldb_private::FileSpec |
| 232 | m_stderr_file_spec; // Redirect stderr or empty. |
| 233 | const lldb_private::FileSpec m_working_dir; // Working directory or empty. |
| 234 | }; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 235 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 236 | void StartLaunchOpThread(LaunchArgs *args, lldb_private::Status &error); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 237 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 238 | static void *LaunchOpThread(void *arg); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 239 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 240 | static bool Launch(LaunchArgs *args); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 241 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | struct AttachArgs : OperationArgs { |
| 243 | AttachArgs(ProcessMonitor *monitor, lldb::pid_t pid); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 244 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | ~AttachArgs(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 246 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | lldb::pid_t m_pid; // pid of the process to be attached. |
| 248 | }; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 249 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 250 | void StartAttachOpThread(AttachArgs *args, lldb_private::Status &error); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 251 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 252 | static void *AttachOpThread(void *args); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 253 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | static void Attach(AttachArgs *args); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 255 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 256 | static void ServeOperation(OperationArgs *args); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 257 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | static bool DupDescriptor(const lldb_private::FileSpec &file_spec, int fd, |
| 259 | int flags); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 260 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | static bool MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid, |
| 262 | bool exited, int signal, int status); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 263 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 264 | static ProcessMessage MonitorSIGTRAP(ProcessMonitor *monitor, |
| 265 | const siginfo_t *info, lldb::pid_t pid); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 266 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | static ProcessMessage MonitorSignal(ProcessMonitor *monitor, |
| 268 | const siginfo_t *info, lldb::pid_t pid); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 269 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | void DoOperation(Operation *op); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 271 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | /// Stops the child monitor thread. |
| 273 | void StopMonitoringChildProcess(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 274 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | /// Stops the operation thread used to attach/launch a process. |
| 276 | void StopOpThread(); |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | #endif // #ifndef liblldb_ProcessMonitor_H_ |