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