1 //===-- DebuggerThread.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_
11 #define liblldb_Plugins_Process_Windows_DebuggerThread_H_
16 #include "ForwardDecl.h"
17 #include "lldb/Host/HostProcess.h"
18 #include "lldb/Host/HostThread.h"
19 #include "lldb/Host/Predicate.h"
20 #include "lldb/Host/windows/windows.h"
22 namespace lldb_private
25 //----------------------------------------------------------------------
28 // Debugs a single process, notifying listeners as appropriate when interesting
30 //----------------------------------------------------------------------
31 class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
34 DebuggerThread(DebugDelegateSP debug_delegate);
35 virtual ~DebuggerThread();
37 Error DebugLaunch(const ProcessLaunchInfo &launch_info);
38 Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
50 std::weak_ptr<ExceptionRecord>
53 return m_active_exception;
56 Error StopDebugging(bool terminate);
58 void ContinueAsyncException(ExceptionResult result);
61 void FreeProcessHandles();
63 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id);
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);
73 DebugDelegateSP m_debug_delegate;
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.
79 ExceptionRecordSP m_active_exception; // The current exception waiting to be handled
81 Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
82 // is finished processing and the debug loop can be
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.
88 std::atomic<DWORD> m_pid_to_detach; // Signals the loop to detach from the process (specified by pid).
89 std::atomic<bool> m_is_shutting_down; // Signals the debug loop to stop processing certain types of
90 // events that block shutdown.
91 bool m_detached; // Indicates we've detached from the inferior process and the debug loop can exit.
93 static lldb::thread_result_t DebuggerThreadLaunchRoutine(void *data);
94 lldb::thread_result_t DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info);
95 static lldb::thread_result_t DebuggerThreadAttachRoutine(void *data);
96 lldb::thread_result_t DebuggerThreadAttachRoutine(lldb::pid_t pid, const ProcessAttachInfo &launch_info);