Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 1 | //===-- NativeProcessDarwin.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 |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef NativeProcessDarwin_h |
| 10 | #define NativeProcessDarwin_h |
| 11 | |
| 12 | // NOTE: this code should only be compiled on Apple Darwin systems. It is |
| 13 | // not cross-platform code and is not intended to build on any other platform. |
| 14 | // Therefore, platform-specific headers and code are okay here. |
| 15 | |
| 16 | // C includes |
| 17 | #include <mach/mach_types.h> |
| 18 | |
| 19 | // C++ includes |
| 20 | #include <mutex> |
| 21 | #include <unordered_set> |
| 22 | |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 23 | #include "lldb/Host/Debug.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 24 | #include "lldb/Host/HostThread.h" |
| 25 | #include "lldb/Host/Pipe.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | #include "lldb/Host/common/NativeProcessProtocol.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 27 | #include "lldb/Target/MemoryRegionInfo.h" |
Pavel Labath | 2da1b59 | 2017-11-13 16:47:37 +0000 | [diff] [blame] | 28 | #include "lldb/Utility/ArchSpec.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 29 | #include "lldb/Utility/FileSpec.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | #include "lldb/lldb-types.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 31 | |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 32 | #include "LaunchFlavor.h" |
| 33 | #include "MachException.h" |
| 34 | #include "NativeThreadDarwin.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | #include "NativeThreadListDarwin.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 36 | |
| 37 | namespace lldb_private { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 38 | class Status; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | class Scalar; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 40 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | namespace process_darwin { |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | /// @class NativeProcessDarwin |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 44 | /// Manages communication with the inferior (debugee) process. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | /// |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 46 | /// Upon construction, this class prepares and launches an inferior process |
| 47 | /// for debugging. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | /// |
| 49 | /// Changes in the inferior process state are broadcasted. |
| 50 | class NativeProcessDarwin : public NativeProcessProtocol { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 51 | friend Status NativeProcessProtocol::Launch( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, |
| 53 | MainLoop &mainloop, NativeProcessProtocolSP &process_sp); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 54 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 55 | friend Status NativeProcessProtocol::Attach( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate, |
| 57 | MainLoop &mainloop, NativeProcessProtocolSP &process_sp); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | public: |
| 60 | ~NativeProcessDarwin() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | // ----------------------------------------------------------------- |
| 63 | // NativeProcessProtocol Interface |
| 64 | // ----------------------------------------------------------------- |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 65 | Status Resume(const ResumeActionList &resume_actions) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 66 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 67 | Status Halt() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 68 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 69 | Status Detach() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 70 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 71 | Status Signal(int signo) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 72 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 73 | Status Interrupt() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 74 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 75 | Status Kill() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 76 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 77 | Status GetMemoryRegionInfo(lldb::addr_t load_addr, |
| 78 | MemoryRegionInfo &range_info) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 79 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 80 | Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, |
| 81 | size_t &bytes_read) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 82 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 83 | Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, |
| 84 | size_t &bytes_read) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 85 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 86 | Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, |
| 87 | size_t &bytes_written) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 88 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 89 | Status AllocateMemory(size_t size, uint32_t permissions, |
| 90 | lldb::addr_t &addr) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 91 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 92 | Status DeallocateMemory(lldb::addr_t addr) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | lldb::addr_t GetSharedLibraryInfoAddress() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | size_t UpdateThreads() override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 97 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | bool GetArchitecture(ArchSpec &arch) const override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 99 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 100 | Status SetBreakpoint(lldb::addr_t addr, uint32_t size, |
| 101 | bool hardware) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 102 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | void DoStopIDBumped(uint32_t newBumpId) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 104 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 105 | Status GetLoadedModuleFileSpec(const char *module_path, |
| 106 | FileSpec &file_spec) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 107 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 108 | Status GetFileLoadAddress(const llvm::StringRef &file_name, |
| 109 | lldb::addr_t &load_addr) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | NativeThreadDarwinSP GetThreadByID(lldb::tid_t id); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 112 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | task_t GetTask() const { return m_task; } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | // ----------------------------------------------------------------- |
| 116 | // Interface used by NativeRegisterContext-derived classes. |
| 117 | // ----------------------------------------------------------------- |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 118 | static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr, |
| 119 | void *data = nullptr, size_t data_size = 0, |
| 120 | long *result = nullptr); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | bool SupportHardwareSingleStepping() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | protected: |
| 125 | // ----------------------------------------------------------------- |
| 126 | // NativeProcessProtocol protected interface |
| 127 | // ----------------------------------------------------------------- |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 128 | Status |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint, |
| 130 | size_t &actual_opcode_size, |
| 131 | const uint8_t *&trap_opcode_bytes) override; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | private: |
| 134 | // ----------------------------------------------------------------- |
| 135 | /// Mach task-related Member Variables |
| 136 | // ----------------------------------------------------------------- |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 137 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | // The task port for the inferior process. |
| 139 | mutable task_t m_task; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | // True if the inferior process did an exec since we started |
| 142 | // monitoring it. |
| 143 | bool m_did_exec; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | // The CPU type of this process. |
| 146 | mutable cpu_type_t m_cpu_type; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 147 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | // ----------------------------------------------------------------- |
| 149 | /// Exception/Signal Handling Member Variables |
| 150 | // ----------------------------------------------------------------- |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | // Exception port on which we will receive child exceptions |
| 153 | mach_port_t m_exception_port; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 154 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | // Saved state of the child exception port prior to us installing |
| 156 | // our own intercepting port. |
| 157 | MachException::PortInfo m_exc_port_info; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 158 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 159 | // The thread that runs the Mach exception read and reply handler. |
| 160 | pthread_t m_exception_thread; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 161 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 162 | // TODO see if we can remove this if we get the exception collection |
| 163 | // and distribution to happen in a single-threaded fashion. |
| 164 | std::recursive_mutex m_exception_messages_mutex; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | // A collection of exception messages caught when listening to the |
| 167 | // exception port. |
| 168 | MachException::Message::collection m_exception_messages; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 169 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | // When we call MachProcess::Interrupt(), we want to send this |
| 171 | // signal (if non-zero). |
| 172 | int m_sent_interrupt_signo; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 173 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | // If we resume the process and still haven't received our |
| 175 | // interrupt signal (if this is non-zero). |
| 176 | int m_auto_resume_signo; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | // ----------------------------------------------------------------- |
| 179 | /// Thread-related Member Variables |
| 180 | // ----------------------------------------------------------------- |
| 181 | NativeThreadListDarwin m_thread_list; |
| 182 | ResumeActionList m_thread_actions; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | // ----------------------------------------------------------------- |
| 185 | /// Process Lifetime Member Variable |
| 186 | // ----------------------------------------------------------------- |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 187 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 188 | // The pipe over which the waitpid thread and the main loop will |
| 189 | // communicate. |
| 190 | Pipe m_waitpid_pipe; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | // The thread that runs the waitpid handler. |
| 193 | pthread_t m_waitpid_thread; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 194 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | // waitpid reader callback handle. |
| 196 | MainLoop::ReadHandleUP m_waitpid_reader_handle; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 197 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | // ----------------------------------------------------------------- |
| 199 | // Private Instance Methods |
| 200 | // ----------------------------------------------------------------- |
| 201 | NativeProcessDarwin(lldb::pid_t pid, int pty_master_fd); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 202 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 203 | // ----------------------------------------------------------------- |
| 204 | /// Finalize the launch. |
| 205 | /// |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 206 | /// This method associates the NativeProcessDarwin instance with the host |
| 207 | /// process that was just launched. It peforms actions like attaching a |
| 208 | /// listener to the inferior exception port, ptracing the process, and the |
| 209 | /// like. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | /// |
| 211 | /// @param[in] launch_flavor |
| 212 | /// The launch flavor that was used to launch the process. |
| 213 | /// |
| 214 | /// @param[in] main_loop |
| 215 | /// The main loop that will run the process monitor. Work |
| 216 | /// that needs to be done (e.g. reading files) gets registered |
| 217 | /// here along with callbacks to process the work. |
| 218 | /// |
| 219 | /// @return |
| 220 | /// Any error that occurred during the aforementioned |
| 221 | /// operations. Failure here will force termination of the |
| 222 | /// launched process and debugging session. |
| 223 | // ----------------------------------------------------------------- |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 224 | Status FinalizeLaunch(LaunchFlavor launch_flavor, MainLoop &main_loop); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 225 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 226 | Status SaveExceptionPortInfo(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 227 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 228 | void ExceptionMessageReceived(const MachException::Message &message); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 229 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 230 | void MaybeRaiseThreadPriority(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 231 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 232 | Status StartExceptionThread(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 233 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 234 | Status SendInferiorExitStatusToMainLoop(::pid_t pid, int status); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 235 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 236 | Status HandleWaitpidResult(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 237 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 238 | bool ProcessUsingSpringBoard() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 239 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 240 | bool ProcessUsingBackBoard() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 241 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | static void *ExceptionThread(void *arg); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | void *DoExceptionThread(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 245 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 246 | lldb::addr_t GetDYLDAllImageInfosAddress(Status &error) const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 247 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | static uint32_t GetCPUTypeForLocalProcess(::pid_t pid); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 249 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | uint32_t GetCPUType() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 251 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 252 | task_t ExceptionMessageBundleComplete(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 253 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | void StartSTDIOThread(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 255 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 256 | Status StartWaitpidThread(MainLoop &main_loop); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 257 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | static void *WaitpidThread(void *arg); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 259 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | void *DoWaitpidThread(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 261 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 262 | task_t TaskPortForProcessID(Status &error, bool force = false) const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 263 | |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 264 | /// Attaches to an existing process. Forms the implementation of |
| 265 | /// Process::DoAttach. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 266 | void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Status &error); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 267 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 268 | ::pid_t Attach(lldb::pid_t pid, Status &error); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 269 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 270 | Status PrivateResume(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 271 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 272 | Status ReplyToAllExceptions(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 273 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 274 | Status ResumeTask(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 275 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | bool IsTaskValid() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 277 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | bool IsTaskValid(task_t task) const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 279 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | mach_port_t GetExceptionPort() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 281 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 282 | bool IsExceptionPortValid() const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 283 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 284 | Status GetTaskBasicInfo(task_t task, struct task_basic_info *info) const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 285 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 286 | Status SuspendTask(); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 287 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 288 | static Status SetDefaultPtraceOpts(const lldb::pid_t); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 289 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 290 | static void *MonitorThread(void *baton); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 291 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 292 | void MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 293 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 294 | void WaitForNewThread(::pid_t tid); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 295 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | void MonitorSIGTRAP(const siginfo_t &info, NativeThreadDarwin &thread); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 297 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | void MonitorTrace(NativeThreadDarwin &thread); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 299 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 300 | void MonitorBreakpoint(NativeThreadDarwin &thread); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 301 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | void MonitorWatchpoint(NativeThreadDarwin &thread, uint32_t wp_index); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 303 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 304 | void MonitorSignal(const siginfo_t &info, NativeThreadDarwin &thread, |
| 305 | bool exited); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 306 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 307 | Status SetupSoftwareSingleStepping(NativeThreadDarwin &thread); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 308 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 309 | bool HasThreadNoLock(lldb::tid_t thread_id); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 310 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 311 | bool StopTrackingThread(lldb::tid_t thread_id); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 312 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | NativeThreadDarwinSP AddThread(lldb::tid_t thread_id); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 314 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 315 | Status GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 316 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 317 | Status FixupBreakpointPCAsNeeded(NativeThreadDarwin &thread); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | /// Writes a siginfo_t structure corresponding to the given thread |
| 320 | /// ID to the memory region pointed to by @p siginfo. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 321 | Status GetSignalInfo(lldb::tid_t tid, void *siginfo); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 322 | |
| 323 | /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 324 | /// corresponding to the given thread ID to the memory pointed to by @p |
| 325 | /// message. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 326 | Status GetEventMessage(lldb::tid_t tid, unsigned long *message); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 327 | |
| 328 | void NotifyThreadDeath(lldb::tid_t tid); |
| 329 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 330 | Status Detach(lldb::tid_t tid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | |
| 332 | // This method is requests a stop on all threads which are still |
| 333 | // running. It sets up a deferred delegate notification, which will |
| 334 | // fire once threads report as stopped. The triggerring_tid will be |
| 335 | // set as the current thread (main stop reason). |
| 336 | void StopRunningThreads(lldb::tid_t triggering_tid); |
| 337 | |
| 338 | // Notify the delegate if all threads have stopped. |
| 339 | void SignalIfAllThreadsStopped(); |
| 340 | |
| 341 | // Resume the given thread, optionally passing it the given signal. |
| 342 | // The type of resume operation (continue, single-step) depends on |
| 343 | // the state parameter. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 344 | Status ResumeThread(NativeThreadDarwin &thread, lldb::StateType state, |
| 345 | int signo); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 346 | |
| 347 | void ThreadWasCreated(NativeThreadDarwin &thread); |
| 348 | |
| 349 | void SigchldHandler(); |
| 350 | }; |
| 351 | |
| 352 | } // namespace process_darwin |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 353 | } // namespace lldb_private |
| 354 | |
| 355 | #endif /* NativeProcessDarwin_h */ |