Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 1 | //===-- NativeProcessLinux.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_NativeProcessLinux_H_ |
| 11 | #define liblldb_NativeProcessLinux_H_ |
| 12 | |
| 13 | // C Includes |
| 14 | #include <semaphore.h> |
| 15 | #include <signal.h> |
| 16 | |
| 17 | // C++ Includes |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 18 | #include <mutex> |
| 19 | #include <unordered_map> |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 20 | #include <unordered_set> |
| 21 | |
| 22 | // Other libraries and framework includes |
| 23 | #include "lldb/Core/ArchSpec.h" |
| 24 | #include "lldb/lldb-types.h" |
| 25 | #include "lldb/Host/Debug.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 26 | #include "lldb/Host/HostThread.h" |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 27 | #include "lldb/Host/Mutex.h" |
| 28 | #include "lldb/Target/MemoryRegionInfo.h" |
| 29 | |
Chaoren Lin | 2fe1d0a | 2015-02-03 01:51:38 +0000 | [diff] [blame] | 30 | #include "lldb/Host/common/NativeProcessProtocol.h" |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 31 | #include "NativeThreadLinux.h" |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 32 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 33 | namespace lldb_private { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 34 | class Error; |
| 35 | class Module; |
| 36 | class Scalar; |
| 37 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 38 | namespace process_linux { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 39 | /// @class NativeProcessLinux |
| 40 | /// @brief Manages communication with the inferior (debugee) process. |
| 41 | /// |
| 42 | /// Upon construction, this class prepares and launches an inferior process for |
| 43 | /// debugging. |
| 44 | /// |
| 45 | /// Changes in the inferior process state are broadcasted. |
| 46 | class NativeProcessLinux: public NativeProcessProtocol |
| 47 | { |
| 48 | public: |
| 49 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 50 | static Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 51 | LaunchProcess ( |
| 52 | Module *exe_module, |
| 53 | ProcessLaunchInfo &launch_info, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 54 | NativeProcessProtocol::NativeDelegate &native_delegate, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 55 | NativeProcessProtocolSP &native_process_sp); |
| 56 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 57 | static Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 58 | AttachToProcess ( |
| 59 | lldb::pid_t pid, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 60 | NativeProcessProtocol::NativeDelegate &native_delegate, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 61 | NativeProcessProtocolSP &native_process_sp); |
| 62 | |
| 63 | // --------------------------------------------------------------------- |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 64 | // NativeProcessProtocol Interface |
| 65 | // --------------------------------------------------------------------- |
| 66 | Error |
| 67 | Resume (const ResumeActionList &resume_actions) override; |
| 68 | |
| 69 | Error |
| 70 | Halt () override; |
| 71 | |
| 72 | Error |
| 73 | Detach () override; |
| 74 | |
| 75 | Error |
| 76 | Signal (int signo) override; |
| 77 | |
| 78 | Error |
Chaoren Lin | e9547b8 | 2015-02-03 01:51:00 +0000 | [diff] [blame] | 79 | Interrupt () override; |
| 80 | |
| 81 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 82 | Kill () override; |
| 83 | |
| 84 | Error |
| 85 | GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info) override; |
| 86 | |
| 87 | Error |
Chaoren Lin | 3eb4b45 | 2015-04-29 17:24:48 +0000 | [diff] [blame] | 88 | ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 89 | |
| 90 | Error |
Chaoren Lin | 3eb4b45 | 2015-04-29 17:24:48 +0000 | [diff] [blame] | 91 | ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 92 | |
| 93 | Error |
Chaoren Lin | 3eb4b45 | 2015-04-29 17:24:48 +0000 | [diff] [blame] | 94 | WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override; |
| 95 | |
| 96 | Error |
| 97 | AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) override; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 98 | |
| 99 | Error |
| 100 | DeallocateMemory (lldb::addr_t addr) override; |
| 101 | |
| 102 | lldb::addr_t |
| 103 | GetSharedLibraryInfoAddress () override; |
| 104 | |
| 105 | size_t |
| 106 | UpdateThreads () override; |
| 107 | |
| 108 | bool |
| 109 | GetArchitecture (ArchSpec &arch) const override; |
| 110 | |
| 111 | Error |
| 112 | SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) override; |
| 113 | |
Pavel Labath | 45f5cb3 | 2015-05-05 15:05:50 +0000 | [diff] [blame] | 114 | Error |
| 115 | SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override; |
| 116 | |
| 117 | Error |
| 118 | RemoveWatchpoint (lldb::addr_t addr) override; |
| 119 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 120 | void |
| 121 | DoStopIDBumped (uint32_t newBumpId) override; |
| 122 | |
Oleksiy Vyalov | 8bc34f4 | 2015-02-19 17:58:04 +0000 | [diff] [blame] | 123 | void |
| 124 | Terminate () override; |
| 125 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 126 | // --------------------------------------------------------------------- |
| 127 | // Interface used by NativeRegisterContext-derived classes. |
| 128 | // --------------------------------------------------------------------- |
| 129 | |
| 130 | /// Reads the contents from the register identified by the given (architecture |
| 131 | /// dependent) offset. |
| 132 | /// |
| 133 | /// This method is provided for use by RegisterContextLinux derivatives. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 134 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 135 | ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 136 | unsigned size, RegisterValue &value); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 137 | |
| 138 | /// Writes the given value to the register identified by the given |
| 139 | /// (architecture dependent) offset. |
| 140 | /// |
| 141 | /// This method is provided for use by RegisterContextLinux derivatives. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 142 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 143 | WriteRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 144 | const RegisterValue &value); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 145 | |
| 146 | /// Reads all general purpose registers into the specified buffer. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 147 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 148 | ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size); |
| 149 | |
| 150 | /// Reads generic floating point registers into the specified buffer. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 151 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 152 | ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size); |
| 153 | |
| 154 | /// Reads the specified register set into the specified buffer. |
| 155 | /// For instance, the extended floating-point register set. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 156 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 157 | ReadRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset); |
| 158 | |
| 159 | /// Writes all general purpose registers into the specified buffer. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 160 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 161 | WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size); |
| 162 | |
| 163 | /// Writes generic floating point registers into the specified buffer. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 164 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 165 | WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size); |
| 166 | |
| 167 | /// Writes the specified register set into the specified buffer. |
| 168 | /// For instance, the extended floating-point register set. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 169 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 170 | WriteRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset); |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 171 | |
| 172 | Error |
| 173 | GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) override; |
| 174 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 175 | protected: |
| 176 | // --------------------------------------------------------------------- |
| 177 | // NativeProcessProtocol protected interface |
| 178 | // --------------------------------------------------------------------- |
| 179 | Error |
| 180 | GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) override; |
| 181 | |
| 182 | private: |
| 183 | |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 184 | class Monitor; |
| 185 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 186 | ArchSpec m_arch; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 187 | |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 188 | std::unique_ptr<Monitor> m_monitor_up; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 189 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 190 | LazyBool m_supports_mem_region; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 191 | std::vector<MemoryRegionInfo> m_mem_region_cache; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 192 | Mutex m_mem_region_cache_mutex; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 193 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 194 | // List of thread ids stepping with a breakpoint with the address of |
| 195 | // the relevan breakpoint |
| 196 | std::map<lldb::tid_t, lldb::addr_t> m_threads_stepping_with_breakpoint; |
| 197 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 198 | /// @class LauchArgs |
| 199 | /// |
| 200 | /// @brief Simple structure to pass data to the thread responsible for |
| 201 | /// launching a child process. |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 202 | struct LaunchArgs |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 203 | { |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 204 | LaunchArgs(Module *module, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 205 | char const **argv, |
| 206 | char const **envp, |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 207 | const std::string &stdin_path, |
| 208 | const std::string &stdout_path, |
| 209 | const std::string &stderr_path, |
Todd Fiala | 0bce1b6 | 2014-08-17 00:10:50 +0000 | [diff] [blame] | 210 | const char *working_dir, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 211 | const ProcessLaunchInfo &launch_info); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 212 | |
| 213 | ~LaunchArgs(); |
| 214 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 215 | Module *m_module; // The executable image to launch. |
| 216 | char const **m_argv; // Process arguments. |
| 217 | char const **m_envp; // Process environment. |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 218 | const std::string &m_stdin_path; // Redirect stdin if not empty. |
| 219 | const std::string &m_stdout_path; // Redirect stdout if not empty. |
| 220 | const std::string &m_stderr_path; // Redirect stderr if not empty. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 221 | const char *m_working_dir; // Working directory or NULL. |
| 222 | const ProcessLaunchInfo &m_launch_info; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 225 | typedef std::function<::pid_t(Error &)> InitialOperation; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 226 | |
| 227 | // --------------------------------------------------------------------- |
| 228 | // Private Instance Methods |
| 229 | // --------------------------------------------------------------------- |
| 230 | NativeProcessLinux (); |
| 231 | |
| 232 | /// Launches an inferior process ready for debugging. Forms the |
| 233 | /// implementation of Process::DoLaunch. |
| 234 | void |
| 235 | LaunchInferior ( |
| 236 | Module *module, |
| 237 | char const *argv[], |
| 238 | char const *envp[], |
Todd Fiala | 75f47c3 | 2014-10-11 21:42:09 +0000 | [diff] [blame] | 239 | const std::string &stdin_path, |
| 240 | const std::string &stdout_path, |
| 241 | const std::string &stderr_path, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 242 | const char *working_dir, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 243 | const ProcessLaunchInfo &launch_info, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 244 | Error &error); |
| 245 | |
| 246 | /// Attaches to an existing process. Forms the |
Tamas Berghammer | 0cbf0b1 | 2015-03-13 11:16:03 +0000 | [diff] [blame] | 247 | /// implementation of Process::DoAttach |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 248 | void |
| 249 | AttachToInferior (lldb::pid_t pid, Error &error); |
| 250 | |
| 251 | void |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 252 | StartMonitorThread(const InitialOperation &operation, Error &error); |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 253 | |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 254 | ::pid_t |
| 255 | Launch(LaunchArgs *args, Error &error); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 256 | |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 257 | ::pid_t |
| 258 | Attach(lldb::pid_t pid, Error &error); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 259 | |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 260 | static Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 261 | SetDefaultPtraceOpts(const lldb::pid_t); |
| 262 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 263 | static bool |
| 264 | DupDescriptor(const char *path, int fd, int flags); |
| 265 | |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 266 | static void * |
| 267 | MonitorThread(void *baton); |
| 268 | |
| 269 | void |
| 270 | MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 271 | |
| 272 | void |
Pavel Labath | 426bdf8 | 2015-04-28 07:51:52 +0000 | [diff] [blame] | 273 | WaitForNewThread(::pid_t tid); |
| 274 | |
| 275 | void |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 276 | MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid); |
| 277 | |
| 278 | void |
Chaoren Lin | c16f5dc | 2015-03-19 23:28:10 +0000 | [diff] [blame] | 279 | MonitorTrace(lldb::pid_t pid, NativeThreadProtocolSP thread_sp); |
| 280 | |
| 281 | void |
| 282 | MonitorBreakpoint(lldb::pid_t pid, NativeThreadProtocolSP thread_sp); |
| 283 | |
| 284 | void |
| 285 | MonitorWatchpoint(lldb::pid_t pid, NativeThreadProtocolSP thread_sp, uint32_t wp_index); |
| 286 | |
| 287 | void |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 288 | MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool exited); |
| 289 | |
Tamas Berghammer | e770868 | 2015-04-22 10:00:23 +0000 | [diff] [blame] | 290 | bool |
| 291 | SupportHardwareSingleStepping() const; |
| 292 | |
| 293 | Error |
| 294 | SetupSoftwareSingleStepping(NativeThreadProtocolSP thread_sp); |
| 295 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 296 | #if 0 |
| 297 | static ::ProcessMessage::CrashReason |
| 298 | GetCrashReasonForSIGSEGV(const siginfo_t *info); |
| 299 | |
| 300 | static ::ProcessMessage::CrashReason |
| 301 | GetCrashReasonForSIGILL(const siginfo_t *info); |
| 302 | |
| 303 | static ::ProcessMessage::CrashReason |
| 304 | GetCrashReasonForSIGFPE(const siginfo_t *info); |
| 305 | |
| 306 | static ::ProcessMessage::CrashReason |
| 307 | GetCrashReasonForSIGBUS(const siginfo_t *info); |
| 308 | #endif |
| 309 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 310 | bool |
| 311 | HasThreadNoLock (lldb::tid_t thread_id); |
| 312 | |
| 313 | NativeThreadProtocolSP |
| 314 | MaybeGetThreadNoLock (lldb::tid_t thread_id); |
| 315 | |
| 316 | bool |
| 317 | StopTrackingThread (lldb::tid_t thread_id); |
| 318 | |
| 319 | NativeThreadProtocolSP |
| 320 | AddThread (lldb::tid_t thread_id); |
| 321 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 322 | Error |
Tamas Berghammer | 63c8be9 | 2015-04-15 09:38:48 +0000 | [diff] [blame] | 323 | GetSoftwareBreakpointPCOffset (NativeRegisterContextSP context_sp, uint32_t &actual_opcode_size); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 324 | |
| 325 | Error |
| 326 | FixupBreakpointPCAsNeeded (NativeThreadProtocolSP &thread_sp); |
| 327 | |
| 328 | /// Writes a siginfo_t structure corresponding to the given thread ID to the |
| 329 | /// memory region pointed to by @p siginfo. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 330 | Error |
| 331 | GetSignalInfo(lldb::tid_t tid, void *siginfo); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 332 | |
| 333 | /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) |
| 334 | /// corresponding to the given thread ID to the memory pointed to by @p |
| 335 | /// message. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 336 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 337 | GetEventMessage(lldb::tid_t tid, unsigned long *message); |
| 338 | |
| 339 | /// Resumes the given thread. If @p signo is anything but |
| 340 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 341 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 342 | Resume(lldb::tid_t tid, uint32_t signo); |
| 343 | |
| 344 | /// Single steps the given thread. If @p signo is anything but |
| 345 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 346 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 347 | SingleStep(lldb::tid_t tid, uint32_t signo); |
| 348 | |
Todd Fiala | 511e5cd | 2014-09-11 23:29:14 +0000 | [diff] [blame] | 349 | void |
Chaoren Lin | fa03ad2 | 2015-02-03 01:50:42 +0000 | [diff] [blame] | 350 | NotifyThreadDeath (lldb::tid_t tid); |
| 351 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 352 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 353 | Detach(lldb::tid_t tid); |
Chaoren Lin | 86fd8e4 | 2015-02-03 01:51:15 +0000 | [diff] [blame] | 354 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 355 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 356 | // Typedefs. |
| 357 | typedef std::unordered_set<lldb::tid_t> ThreadIDSet; |
| 358 | |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 359 | // Notify that a thread is created and/or starting to be tracked. |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 360 | void |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 361 | NotifyThreadCreate(lldb::tid_t tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 362 | |
| 363 | |
Pavel Labath | ed89c7f | 2015-05-06 12:22:37 +0000 | [diff] [blame] | 364 | // Notify the delegate after a given set of threads stops. The triggering_tid will be set |
| 365 | // as the current thread. The error_function will be fired if either the triggering tid |
| 366 | // or any of the wait_for_stop_tids are unknown. |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 367 | void |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 368 | StopThreads(lldb::tid_t triggering_tid, const ThreadIDSet &wait_for_stop_tids); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 369 | |
Pavel Labath | ed89c7f | 2015-05-06 12:22:37 +0000 | [diff] [blame] | 370 | // Notify the delegate after all non-stopped threads stop. The triggering_tid will be set |
| 371 | // as the current thread. The error_function will be fired if the triggering tid |
| 372 | // is unknown. |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 373 | void |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 374 | StopRunningThreads(lldb::tid_t triggering_tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 375 | |
Pavel Labath | ed89c7f | 2015-05-06 12:22:37 +0000 | [diff] [blame] | 376 | // Notify the delegate after all non-stopped threads stop. The triggering_tid will be set |
| 377 | // as the current thread. The error_function will be fired if either the triggering tid |
| 378 | // or any of the wait_for_stop_tids are unknown. This variant will send stop requests to |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 379 | // all non-stopped threads except skip_stop_request_tid. |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 380 | void |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 381 | StopRunningThreadsWithSkipTID(lldb::tid_t triggering_tid, lldb::tid_t skip_stop_request_tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 382 | |
| 383 | // Notify the thread stopped. Will trigger error at time of execution if we |
| 384 | // already think it is stopped. |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 385 | Error |
| 386 | NotifyThreadStop(lldb::tid_t tid, bool initiated_by_llgs); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 387 | |
| 388 | // Request that the given thread id should have the request_thread_resume_function |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 389 | // called. This call signals an error if the thread resume is for |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 390 | // a thread that is already in a running state. |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 391 | Error |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 392 | RequestThreadResume (lldb::tid_t tid, |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 393 | const NativeThreadLinux::ResumeThreadFunction &request_thread_resume_function); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 394 | |
| 395 | // Request that the given thread id should have the request_thread_resume_function |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 396 | // called. This call ignores threads that are already running and |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 397 | // does not trigger an error in that case. |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 398 | Error |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 399 | RequestThreadResumeAsNeeded (lldb::tid_t tid, |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 400 | const NativeThreadLinux::ResumeThreadFunction &request_thread_resume_function); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 401 | |
| 402 | // Indicate the calling process did an exec and that the thread state |
| 403 | // should be 100% cleared. |
| 404 | void |
| 405 | ResetForExec (); |
| 406 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 407 | private: |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 408 | struct PendingNotification |
| 409 | { |
| 410 | PendingNotification (lldb::tid_t triggering_tid, |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 411 | const ThreadIDSet &wait_for_stop_tids, |
| 412 | const ThreadIDSet &skip_stop_request_tids): |
| 413 | triggering_tid (triggering_tid), |
| 414 | wait_for_stop_tids (wait_for_stop_tids), |
| 415 | original_wait_for_stop_tids (wait_for_stop_tids), |
| 416 | request_stop_on_all_unstopped_threads (false), |
| 417 | skip_stop_request_tids (skip_stop_request_tids) |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 418 | { |
| 419 | } |
| 420 | |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 421 | PendingNotification (lldb::tid_t triggering_tid): |
| 422 | triggering_tid (triggering_tid), |
| 423 | wait_for_stop_tids (), |
| 424 | original_wait_for_stop_tids (), |
| 425 | request_stop_on_all_unstopped_threads (true), |
| 426 | skip_stop_request_tids () |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 427 | { |
| 428 | } |
| 429 | |
| 430 | const lldb::tid_t triggering_tid; |
| 431 | ThreadIDSet wait_for_stop_tids; |
| 432 | const ThreadIDSet original_wait_for_stop_tids; |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 433 | const bool request_stop_on_all_unstopped_threads; |
| 434 | ThreadIDSet skip_stop_request_tids; |
| 435 | }; |
| 436 | typedef std::unique_ptr<PendingNotification> PendingNotificationUP; |
| 437 | |
| 438 | // Fire pending notification if no pending thread stops remain. |
| 439 | void SignalIfRequirementsSatisfied(); |
| 440 | |
| 441 | bool |
| 442 | RequestStopOnAllSpecifiedThreads(); |
| 443 | |
| 444 | void |
| 445 | RequestStopOnAllRunningThreads(); |
| 446 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 447 | std::mutex m_event_mutex; // Serializes execution of ProcessEvent. XXX |
| 448 | |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 449 | Error |
| 450 | ThreadDidStop(lldb::tid_t tid, bool initiated_by_llgs); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 451 | |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 452 | Error |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 453 | DoResume(lldb::tid_t tid, NativeThreadLinux::ResumeThreadFunction request_thread_resume_function, |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 454 | bool error_when_already_running); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 455 | |
| 456 | void |
Pavel Labath | ed89c7f | 2015-05-06 12:22:37 +0000 | [diff] [blame] | 457 | DoStopThreads(PendingNotificationUP &¬ification_up); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 458 | |
| 459 | void |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame^] | 460 | ThreadWasCreated (lldb::tid_t tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 461 | |
| 462 | void |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 463 | ThreadDidDie (lldb::tid_t tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 464 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 465 | // Member variables. |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 466 | PendingNotificationUP m_pending_notification_up; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 467 | }; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 468 | |
| 469 | } // namespace process_linux |
| 470 | } // namespace lldb_private |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 471 | |
| 472 | #endif // #ifndef liblldb_NativeProcessLinux_H_ |