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