Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 1 | //===-- DebuggerThread.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_Plugins_Process_Windows_DebuggerThread_H_ |
| 11 | #define liblldb_Plugins_Process_Windows_DebuggerThread_H_ |
| 12 | |
Adrian McCarthy | a59a721 | 2015-06-19 18:26:53 +0000 | [diff] [blame] | 13 | #include <atomic> |
Zachary Turner | fb6c3494 | 2014-12-10 23:25:10 +0000 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 16 | #include "ForwardDecl.h" |
| 17 | #include "lldb/Host/HostProcess.h" |
| 18 | #include "lldb/Host/HostThread.h" |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 19 | #include "lldb/Host/Predicate.h" |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 20 | #include "lldb/Host/windows/windows.h" |
| 21 | |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 22 | namespace lldb_private |
| 23 | { |
| 24 | |
| 25 | //---------------------------------------------------------------------- |
| 26 | // DebuggerThread |
| 27 | // |
| 28 | // Debugs a single process, notifying listeners as appropriate when interesting |
| 29 | // things occur. |
| 30 | //---------------------------------------------------------------------- |
| 31 | class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> |
| 32 | { |
| 33 | public: |
| 34 | DebuggerThread(DebugDelegateSP debug_delegate); |
| 35 | virtual ~DebuggerThread(); |
| 36 | |
Zachary Turner | 3985f89 | 2014-11-10 22:32:18 +0000 | [diff] [blame] | 37 | Error DebugLaunch(const ProcessLaunchInfo &launch_info); |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 38 | Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info); |
Zachary Turner | 3985f89 | 2014-11-10 22:32:18 +0000 | [diff] [blame] | 39 | |
| 40 | HostProcess |
| 41 | GetProcess() const |
| 42 | { |
| 43 | return m_process; |
| 44 | } |
| 45 | HostThread |
| 46 | GetMainThread() const |
| 47 | { |
| 48 | return m_main_thread; |
| 49 | } |
Zachary Turner | fb6c3494 | 2014-12-10 23:25:10 +0000 | [diff] [blame] | 50 | std::weak_ptr<ExceptionRecord> |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 51 | GetActiveException() |
| 52 | { |
Zachary Turner | fb6c3494 | 2014-12-10 23:25:10 +0000 | [diff] [blame] | 53 | return m_active_exception; |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | Error StopDebugging(bool terminate); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 57 | |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 58 | void ContinueAsyncException(ExceptionResult result); |
| 59 | |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 60 | private: |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 61 | void FreeProcessHandles(); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 62 | void DebugLoop(); |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 63 | ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 64 | DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id); |
| 65 | DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD thread_id); |
| 66 | DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD thread_id); |
| 67 | DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id); |
| 68 | DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id); |
| 69 | DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id); |
| 70 | DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id); |
| 71 | DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id); |
| 72 | |
| 73 | DebugDelegateSP m_debug_delegate; |
| 74 | |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 75 | HostProcess m_process; // The process being debugged. |
| 76 | HostThread m_main_thread; // The main thread of the inferior. |
| 77 | HANDLE m_image_file; // The image file of the process being debugged. |
| 78 | |
Zachary Turner | fb6c3494 | 2014-12-10 23:25:10 +0000 | [diff] [blame] | 79 | ExceptionRecordSP m_active_exception; // The current exception waiting to be handled |
Zachary Turner | c6a6653 | 2014-12-03 22:04:18 +0000 | [diff] [blame] | 80 | |
| 81 | Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception |
| 82 | // is finished processing and the debug loop can be |
| 83 | // continued. |
Zachary Turner | dcd8037 | 2014-11-11 00:00:14 +0000 | [diff] [blame] | 84 | |
Zachary Turner | 3c1c5b9 | 2015-05-21 19:56:26 +0000 | [diff] [blame] | 85 | HANDLE m_debugging_ended_event; // An event which gets signalled by the debugger thread when it |
| 86 | // exits the debugger loop and is detached from the inferior. |
| 87 | |
Adrian McCarthy | a59a721 | 2015-06-19 18:26:53 +0000 | [diff] [blame] | 88 | std::atomic<DWORD> m_pid_to_detach; // Signals the loop to detach from the process (specified by pid). |
| 89 | bool m_detached; // Indicates we've detached from the inferior process and the debug loop can exit. |
| 90 | |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 91 | static lldb::thread_result_t DebuggerThreadLaunchRoutine(void *data); |
| 92 | lldb::thread_result_t DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info); |
| 93 | static lldb::thread_result_t DebuggerThreadAttachRoutine(void *data); |
| 94 | lldb::thread_result_t DebuggerThreadAttachRoutine(lldb::pid_t pid, const ProcessAttachInfo &launch_info); |
Zachary Turner | 02862bc | 2014-11-07 23:44:13 +0000 | [diff] [blame] | 95 | }; |
| 96 | } |
| 97 | |
| 98 | #endif |