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 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 13 | // C++ Includes |
| 14 | #include <unordered_set> |
| 15 | |
| 16 | // Other libraries and framework includes |
| 17 | #include "lldb/Core/ArchSpec.h" |
| 18 | #include "lldb/lldb-types.h" |
| 19 | #include "lldb/Host/Debug.h" |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 20 | #include "lldb/Host/FileSpec.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 21 | #include "lldb/Host/HostThread.h" |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 22 | #include "lldb/Host/Mutex.h" |
| 23 | #include "lldb/Target/MemoryRegionInfo.h" |
| 24 | |
Chaoren Lin | 2fe1d0a | 2015-02-03 01:51:38 +0000 | [diff] [blame] | 25 | #include "lldb/Host/common/NativeProcessProtocol.h" |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame] | 26 | #include "NativeThreadLinux.h" |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 27 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 28 | namespace lldb_private { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 29 | class Error; |
| 30 | class Module; |
| 31 | class Scalar; |
| 32 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 33 | namespace process_linux { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 34 | /// @class NativeProcessLinux |
| 35 | /// @brief Manages communication with the inferior (debugee) process. |
| 36 | /// |
| 37 | /// Upon construction, this class prepares and launches an inferior process for |
| 38 | /// debugging. |
| 39 | /// |
| 40 | /// Changes in the inferior process state are broadcasted. |
| 41 | class NativeProcessLinux: public NativeProcessProtocol |
| 42 | { |
| 43 | public: |
| 44 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 45 | static Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 46 | LaunchProcess ( |
| 47 | Module *exe_module, |
| 48 | ProcessLaunchInfo &launch_info, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 49 | NativeProcessProtocol::NativeDelegate &native_delegate, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 50 | NativeProcessProtocolSP &native_process_sp); |
| 51 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 52 | static Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 53 | AttachToProcess ( |
| 54 | lldb::pid_t pid, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 55 | NativeProcessProtocol::NativeDelegate &native_delegate, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 56 | NativeProcessProtocolSP &native_process_sp); |
| 57 | |
Tamas Berghammer | 068f8a7 | 2015-05-26 11:58:52 +0000 | [diff] [blame] | 58 | //------------------------------------------------------------------------------ |
| 59 | /// @class Operation |
| 60 | /// @brief Represents a NativeProcessLinux operation. |
| 61 | /// |
| 62 | /// Under Linux, it is not possible to ptrace() from any other thread but the |
| 63 | /// one that spawned or attached to the process from the start. Therefore, when |
| 64 | /// a NativeProcessLinux is asked to deliver or change the state of an inferior |
| 65 | /// process the operation must be "funneled" to a specific thread to perform the |
| 66 | /// task. The Operation class provides an abstract base for all services the |
| 67 | /// NativeProcessLinux must perform via the single virtual function Execute, thus |
| 68 | /// encapsulating the code that needs to run in the privileged context. |
| 69 | class Operation |
| 70 | { |
| 71 | public: |
| 72 | Operation () : m_error() { } |
| 73 | |
| 74 | virtual |
| 75 | ~Operation() {} |
| 76 | |
| 77 | virtual void |
| 78 | Execute (NativeProcessLinux *process) = 0; |
| 79 | |
| 80 | const Error & |
| 81 | GetError () const { return m_error; } |
| 82 | |
| 83 | protected: |
| 84 | Error m_error; |
| 85 | }; |
| 86 | |
| 87 | typedef std::unique_ptr<Operation> OperationUP; |
| 88 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 89 | // --------------------------------------------------------------------- |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 90 | // NativeProcessProtocol Interface |
| 91 | // --------------------------------------------------------------------- |
| 92 | Error |
| 93 | Resume (const ResumeActionList &resume_actions) override; |
| 94 | |
| 95 | Error |
| 96 | Halt () override; |
| 97 | |
| 98 | Error |
| 99 | Detach () override; |
| 100 | |
| 101 | Error |
| 102 | Signal (int signo) override; |
| 103 | |
| 104 | Error |
Chaoren Lin | e9547b8 | 2015-02-03 01:51:00 +0000 | [diff] [blame] | 105 | Interrupt () override; |
| 106 | |
| 107 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 108 | Kill () override; |
| 109 | |
| 110 | Error |
| 111 | GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info) override; |
| 112 | |
| 113 | Error |
Chaoren Lin | 3eb4b45 | 2015-04-29 17:24:48 +0000 | [diff] [blame] | 114 | 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] | 115 | |
| 116 | Error |
Chaoren Lin | 3eb4b45 | 2015-04-29 17:24:48 +0000 | [diff] [blame] | 117 | 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] | 118 | |
| 119 | Error |
Chaoren Lin | 3eb4b45 | 2015-04-29 17:24:48 +0000 | [diff] [blame] | 120 | WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override; |
| 121 | |
| 122 | Error |
| 123 | AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) override; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 124 | |
| 125 | Error |
| 126 | DeallocateMemory (lldb::addr_t addr) override; |
| 127 | |
| 128 | lldb::addr_t |
| 129 | GetSharedLibraryInfoAddress () override; |
| 130 | |
| 131 | size_t |
| 132 | UpdateThreads () override; |
| 133 | |
| 134 | bool |
| 135 | GetArchitecture (ArchSpec &arch) const override; |
| 136 | |
| 137 | Error |
| 138 | SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) override; |
| 139 | |
Pavel Labath | 45f5cb3 | 2015-05-05 15:05:50 +0000 | [diff] [blame] | 140 | Error |
| 141 | SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override; |
| 142 | |
| 143 | Error |
| 144 | RemoveWatchpoint (lldb::addr_t addr) override; |
| 145 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 146 | void |
| 147 | DoStopIDBumped (uint32_t newBumpId) override; |
| 148 | |
Oleksiy Vyalov | 8bc34f4 | 2015-02-19 17:58:04 +0000 | [diff] [blame] | 149 | void |
| 150 | Terminate () override; |
| 151 | |
Tamas Berghammer | 068f8a7 | 2015-05-26 11:58:52 +0000 | [diff] [blame] | 152 | Error |
| 153 | GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) override; |
| 154 | |
Tamas Berghammer | 783bfc8 | 2015-06-18 20:43:56 +0000 | [diff] [blame^] | 155 | Error |
| 156 | GetFileLoadAddress(const llvm::StringRef& file_name, lldb::addr_t& load_addr) override; |
| 157 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 158 | // --------------------------------------------------------------------- |
| 159 | // Interface used by NativeRegisterContext-derived classes. |
| 160 | // --------------------------------------------------------------------- |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 161 | Error |
Tamas Berghammer | 068f8a7 | 2015-05-26 11:58:52 +0000 | [diff] [blame] | 162 | DoOperation(Operation* op); |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 163 | |
| 164 | Error |
Tamas Berghammer | 068f8a7 | 2015-05-26 11:58:52 +0000 | [diff] [blame] | 165 | DoOperation(OperationUP op) { return DoOperation(op.get()); } |
| 166 | |
| 167 | static long |
| 168 | PtraceWrapper(int req, lldb::pid_t pid, void *addr, void *data, size_t data_size, Error& error); |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 169 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 170 | protected: |
| 171 | // --------------------------------------------------------------------- |
| 172 | // NativeProcessProtocol protected interface |
| 173 | // --------------------------------------------------------------------- |
| 174 | Error |
| 175 | GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) override; |
| 176 | |
| 177 | private: |
| 178 | |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 179 | class Monitor; |
| 180 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 181 | ArchSpec m_arch; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 182 | |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 183 | std::unique_ptr<Monitor> m_monitor_up; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 184 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 185 | LazyBool m_supports_mem_region; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 186 | std::vector<MemoryRegionInfo> m_mem_region_cache; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 187 | Mutex m_mem_region_cache_mutex; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 188 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 189 | // List of thread ids stepping with a breakpoint with the address of |
| 190 | // the relevan breakpoint |
| 191 | std::map<lldb::tid_t, lldb::addr_t> m_threads_stepping_with_breakpoint; |
| 192 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 193 | /// @class LauchArgs |
| 194 | /// |
| 195 | /// @brief Simple structure to pass data to the thread responsible for |
| 196 | /// launching a child process. |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 197 | struct LaunchArgs |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 198 | { |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 199 | LaunchArgs(Module *module, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 200 | char const **argv, |
| 201 | char const **envp, |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 202 | const FileSpec &stdin_file_spec, |
| 203 | const FileSpec &stdout_file_spec, |
| 204 | const FileSpec &stderr_file_spec, |
| 205 | const FileSpec &working_dir, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 206 | const ProcessLaunchInfo &launch_info); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 207 | |
| 208 | ~LaunchArgs(); |
| 209 | |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 210 | Module *m_module; // The executable image to launch. |
| 211 | char const **m_argv; // Process arguments. |
| 212 | char const **m_envp; // Process environment. |
| 213 | const FileSpec m_stdin_file_spec; // Redirect stdin if not empty. |
| 214 | const FileSpec m_stdout_file_spec; // Redirect stdout if not empty. |
| 215 | const FileSpec m_stderr_file_spec; // Redirect stderr if not empty. |
| 216 | const FileSpec m_working_dir; // Working directory or empty. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 217 | const ProcessLaunchInfo &m_launch_info; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 220 | typedef std::function<::pid_t(Error &)> InitialOperation; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 221 | |
| 222 | // --------------------------------------------------------------------- |
| 223 | // Private Instance Methods |
| 224 | // --------------------------------------------------------------------- |
| 225 | NativeProcessLinux (); |
| 226 | |
| 227 | /// Launches an inferior process ready for debugging. Forms the |
| 228 | /// implementation of Process::DoLaunch. |
| 229 | void |
| 230 | LaunchInferior ( |
| 231 | Module *module, |
| 232 | char const *argv[], |
| 233 | char const *envp[], |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 234 | const FileSpec &stdin_file_spec, |
| 235 | const FileSpec &stdout_file_spec, |
| 236 | const FileSpec &stderr_file_spec, |
| 237 | const FileSpec &working_dir, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 238 | const ProcessLaunchInfo &launch_info, |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 239 | Error &error); |
| 240 | |
| 241 | /// Attaches to an existing process. Forms the |
Tamas Berghammer | 0cbf0b1 | 2015-03-13 11:16:03 +0000 | [diff] [blame] | 242 | /// implementation of Process::DoAttach |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 243 | void |
| 244 | AttachToInferior (lldb::pid_t pid, Error &error); |
| 245 | |
| 246 | void |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 247 | StartMonitorThread(const InitialOperation &operation, Error &error); |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 248 | |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 249 | ::pid_t |
| 250 | Launch(LaunchArgs *args, Error &error); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 251 | |
Pavel Labath | bd7cbc5 | 2015-04-20 13:53:49 +0000 | [diff] [blame] | 252 | ::pid_t |
| 253 | Attach(lldb::pid_t pid, Error &error); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 254 | |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 255 | static Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 256 | SetDefaultPtraceOpts(const lldb::pid_t); |
| 257 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 258 | static bool |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 259 | DupDescriptor(const FileSpec &file_spec, int fd, int flags); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 260 | |
Pavel Labath | 1107b5a | 2015-04-17 14:07:49 +0000 | [diff] [blame] | 261 | static void * |
| 262 | MonitorThread(void *baton); |
| 263 | |
| 264 | void |
| 265 | MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 266 | |
| 267 | void |
Pavel Labath | 426bdf8 | 2015-04-28 07:51:52 +0000 | [diff] [blame] | 268 | WaitForNewThread(::pid_t tid); |
| 269 | |
| 270 | void |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 271 | MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid); |
| 272 | |
| 273 | void |
Chaoren Lin | c16f5dc | 2015-03-19 23:28:10 +0000 | [diff] [blame] | 274 | MonitorTrace(lldb::pid_t pid, NativeThreadProtocolSP thread_sp); |
| 275 | |
| 276 | void |
| 277 | MonitorBreakpoint(lldb::pid_t pid, NativeThreadProtocolSP thread_sp); |
| 278 | |
| 279 | void |
| 280 | MonitorWatchpoint(lldb::pid_t pid, NativeThreadProtocolSP thread_sp, uint32_t wp_index); |
| 281 | |
| 282 | void |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 283 | MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool exited); |
| 284 | |
Tamas Berghammer | e770868 | 2015-04-22 10:00:23 +0000 | [diff] [blame] | 285 | bool |
| 286 | SupportHardwareSingleStepping() const; |
| 287 | |
| 288 | Error |
| 289 | SetupSoftwareSingleStepping(NativeThreadProtocolSP thread_sp); |
| 290 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 291 | #if 0 |
| 292 | static ::ProcessMessage::CrashReason |
| 293 | GetCrashReasonForSIGSEGV(const siginfo_t *info); |
| 294 | |
| 295 | static ::ProcessMessage::CrashReason |
| 296 | GetCrashReasonForSIGILL(const siginfo_t *info); |
| 297 | |
| 298 | static ::ProcessMessage::CrashReason |
| 299 | GetCrashReasonForSIGFPE(const siginfo_t *info); |
| 300 | |
| 301 | static ::ProcessMessage::CrashReason |
| 302 | GetCrashReasonForSIGBUS(const siginfo_t *info); |
| 303 | #endif |
| 304 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 305 | bool |
| 306 | HasThreadNoLock (lldb::tid_t thread_id); |
| 307 | |
| 308 | NativeThreadProtocolSP |
| 309 | MaybeGetThreadNoLock (lldb::tid_t thread_id); |
| 310 | |
| 311 | bool |
| 312 | StopTrackingThread (lldb::tid_t thread_id); |
| 313 | |
| 314 | NativeThreadProtocolSP |
| 315 | AddThread (lldb::tid_t thread_id); |
| 316 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 317 | Error |
Tamas Berghammer | 63c8be9 | 2015-04-15 09:38:48 +0000 | [diff] [blame] | 318 | GetSoftwareBreakpointPCOffset (NativeRegisterContextSP context_sp, uint32_t &actual_opcode_size); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 319 | |
| 320 | Error |
| 321 | FixupBreakpointPCAsNeeded (NativeThreadProtocolSP &thread_sp); |
| 322 | |
| 323 | /// Writes a siginfo_t structure corresponding to the given thread ID to the |
| 324 | /// memory region pointed to by @p siginfo. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 325 | Error |
| 326 | GetSignalInfo(lldb::tid_t tid, void *siginfo); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 327 | |
| 328 | /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) |
| 329 | /// corresponding to the given thread ID to the memory pointed to by @p |
| 330 | /// message. |
Chaoren Lin | 97ccc29 | 2015-02-03 01:51:12 +0000 | [diff] [blame] | 331 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 332 | GetEventMessage(lldb::tid_t tid, unsigned long *message); |
| 333 | |
| 334 | /// Resumes the given thread. If @p signo is anything but |
| 335 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. |
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 | Resume(lldb::tid_t tid, uint32_t signo); |
| 338 | |
| 339 | /// Single steps 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 | SingleStep(lldb::tid_t tid, uint32_t signo); |
| 343 | |
Todd Fiala | 511e5cd | 2014-09-11 23:29:14 +0000 | [diff] [blame] | 344 | void |
Chaoren Lin | fa03ad2 | 2015-02-03 01:50:42 +0000 | [diff] [blame] | 345 | NotifyThreadDeath (lldb::tid_t tid); |
| 346 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 347 | Error |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 348 | Detach(lldb::tid_t tid); |
Chaoren Lin | 86fd8e4 | 2015-02-03 01:51:15 +0000 | [diff] [blame] | 349 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 350 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 351 | // Typedefs. |
| 352 | typedef std::unordered_set<lldb::tid_t> ThreadIDSet; |
| 353 | |
Pavel Labath | 1dbc6c9 | 2015-05-12 08:35:33 +0000 | [diff] [blame] | 354 | // This method is requests a stop on all threads which are still running. It sets up a |
| 355 | // deferred delegate notification, which will fire once threads report as stopped. The |
| 356 | // triggerring_tid will be set as the current thread (main stop reason). |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 357 | void |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 358 | StopRunningThreads(lldb::tid_t triggering_tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 359 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 360 | struct PendingNotification |
| 361 | { |
Pavel Labath | 337f3eb | 2015-05-08 08:57:45 +0000 | [diff] [blame] | 362 | PendingNotification (lldb::tid_t triggering_tid): |
| 363 | triggering_tid (triggering_tid), |
Pavel Labath | 108c325 | 2015-05-12 09:03:18 +0000 | [diff] [blame] | 364 | wait_for_stop_tids () |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 365 | { |
| 366 | } |
| 367 | |
| 368 | const lldb::tid_t triggering_tid; |
| 369 | ThreadIDSet wait_for_stop_tids; |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 370 | }; |
| 371 | typedef std::unique_ptr<PendingNotification> PendingNotificationUP; |
| 372 | |
Pavel Labath | 9eb1ecb | 2015-05-15 13:49:01 +0000 | [diff] [blame] | 373 | // Notify the delegate if all threads have stopped. |
| 374 | void SignalIfAllThreadsStopped(); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 375 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 376 | void |
| 377 | RequestStopOnAllRunningThreads(); |
| 378 | |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 379 | Error |
| 380 | ThreadDidStop(lldb::tid_t tid, bool initiated_by_llgs); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 381 | |
Pavel Labath | 1dbc6c9 | 2015-05-12 08:35:33 +0000 | [diff] [blame] | 382 | // Resume the thread with the given thread id using the request_thread_resume_function |
| 383 | // called. If error_when_already_running is then then an error is raised if we think this |
| 384 | // thread is already running. |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 385 | Error |
Pavel Labath | 1dbc6c9 | 2015-05-12 08:35:33 +0000 | [diff] [blame] | 386 | ResumeThread(lldb::tid_t tid, NativeThreadLinux::ResumeThreadFunction request_thread_resume_function, |
Pavel Labath | 5eb721e | 2015-05-07 08:30:31 +0000 | [diff] [blame] | 387 | bool error_when_already_running); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 388 | |
| 389 | void |
Pavel Labath | ed89c7f | 2015-05-06 12:22:37 +0000 | [diff] [blame] | 390 | DoStopThreads(PendingNotificationUP &¬ification_up); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 391 | |
| 392 | void |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame] | 393 | ThreadWasCreated (lldb::tid_t tid); |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 394 | |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 395 | // Member variables. |
Pavel Labath | c076559 | 2015-05-06 10:46:34 +0000 | [diff] [blame] | 396 | PendingNotificationUP m_pending_notification_up; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 397 | }; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 398 | |
| 399 | } // namespace process_linux |
| 400 | } // namespace lldb_private |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 401 | |
| 402 | #endif // #ifndef liblldb_NativeProcessLinux_H_ |