14ad5def9SAdrian McCarthy //===-- DebuggerThread.h ----------------------------------------*- C++ -*-===// 24ad5def9SAdrian McCarthy // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64ad5def9SAdrian McCarthy // 74ad5def9SAdrian McCarthy //===----------------------------------------------------------------------===// 84ad5def9SAdrian McCarthy 94ad5def9SAdrian McCarthy #ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_ 104ad5def9SAdrian McCarthy #define liblldb_Plugins_Process_Windows_DebuggerThread_H_ 114ad5def9SAdrian McCarthy 124ad5def9SAdrian McCarthy #include <atomic> 134ad5def9SAdrian McCarthy #include <memory> 144ad5def9SAdrian McCarthy 154ad5def9SAdrian McCarthy #include "ForwardDecl.h" 164ad5def9SAdrian McCarthy #include "lldb/Host/HostProcess.h" 174ad5def9SAdrian McCarthy #include "lldb/Host/HostThread.h" 184ad5def9SAdrian McCarthy #include "lldb/Host/windows/windows.h" 197fae4932SRaphael Isemann #include "lldb/Utility/Predicate.h" 204ad5def9SAdrian McCarthy 214ad5def9SAdrian McCarthy namespace lldb_private { 224ad5def9SAdrian McCarthy 234ad5def9SAdrian McCarthy // DebuggerThread 244ad5def9SAdrian McCarthy // 254ad5def9SAdrian McCarthy // Debugs a single process, notifying listeners as appropriate when interesting 264ad5def9SAdrian McCarthy // things occur. 274ad5def9SAdrian McCarthy class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> { 284ad5def9SAdrian McCarthy public: 294ad5def9SAdrian McCarthy DebuggerThread(DebugDelegateSP debug_delegate); 304ad5def9SAdrian McCarthy virtual ~DebuggerThread(); 314ad5def9SAdrian McCarthy 3297206d57SZachary Turner Status DebugLaunch(const ProcessLaunchInfo &launch_info); 3397206d57SZachary Turner Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info); 344ad5def9SAdrian McCarthy GetProcess()354ad5def9SAdrian McCarthy HostProcess GetProcess() const { return m_process; } GetMainThread()364ad5def9SAdrian McCarthy HostThread GetMainThread() const { return m_main_thread; } GetActiveException()374ad5def9SAdrian McCarthy std::weak_ptr<ExceptionRecord> GetActiveException() { 384ad5def9SAdrian McCarthy return m_active_exception; 394ad5def9SAdrian McCarthy } 404ad5def9SAdrian McCarthy 4197206d57SZachary Turner Status StopDebugging(bool terminate); 424ad5def9SAdrian McCarthy 434ad5def9SAdrian McCarthy void ContinueAsyncException(ExceptionResult result); 444ad5def9SAdrian McCarthy 454ad5def9SAdrian McCarthy private: 464ad5def9SAdrian McCarthy void FreeProcessHandles(); 474ad5def9SAdrian McCarthy void DebugLoop(); 484ad5def9SAdrian McCarthy ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, 494ad5def9SAdrian McCarthy DWORD thread_id); 504ad5def9SAdrian McCarthy DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, 514ad5def9SAdrian McCarthy DWORD thread_id); 524ad5def9SAdrian McCarthy DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, 534ad5def9SAdrian McCarthy DWORD thread_id); 544ad5def9SAdrian McCarthy DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, 554ad5def9SAdrian McCarthy DWORD thread_id); 564ad5def9SAdrian McCarthy DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, 574ad5def9SAdrian McCarthy DWORD thread_id); 584ad5def9SAdrian McCarthy DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id); 594ad5def9SAdrian McCarthy DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, 604ad5def9SAdrian McCarthy DWORD thread_id); 614ad5def9SAdrian McCarthy DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id); 624ad5def9SAdrian McCarthy DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id); 634ad5def9SAdrian McCarthy 644ad5def9SAdrian McCarthy DebugDelegateSP m_debug_delegate; 654ad5def9SAdrian McCarthy 664ad5def9SAdrian McCarthy HostProcess m_process; // The process being debugged. 674ad5def9SAdrian McCarthy HostThread m_main_thread; // The main thread of the inferior. 684ad5def9SAdrian McCarthy 694ad5def9SAdrian McCarthy // The image file of the process being debugged. 704ad5def9SAdrian McCarthy HANDLE m_image_file = nullptr; 714ad5def9SAdrian McCarthy 724ad5def9SAdrian McCarthy // The current exception waiting to be handled 734ad5def9SAdrian McCarthy ExceptionRecordSP m_active_exception; 744ad5def9SAdrian McCarthy 754ad5def9SAdrian McCarthy // A predicate which gets signalled when an exception is finished processing 764ad5def9SAdrian McCarthy // and the debug loop can be continued. 774ad5def9SAdrian McCarthy Predicate<ExceptionResult> m_exception_pred; 784ad5def9SAdrian McCarthy 794ad5def9SAdrian McCarthy // An event which gets signalled by the debugger thread when it exits the 804ad5def9SAdrian McCarthy // debugger loop and is detached from the inferior. 814ad5def9SAdrian McCarthy HANDLE m_debugging_ended_event = nullptr; 824ad5def9SAdrian McCarthy 834ad5def9SAdrian McCarthy // Signals the loop to detach from the process (specified by pid). 844ad5def9SAdrian McCarthy std::atomic<DWORD> m_pid_to_detach; 854ad5def9SAdrian McCarthy 864ad5def9SAdrian McCarthy // Signals the debug loop to stop processing certain types of events that 874ad5def9SAdrian McCarthy // block shutdown. 884ad5def9SAdrian McCarthy std::atomic<bool> m_is_shutting_down; 894ad5def9SAdrian McCarthy 904ad5def9SAdrian McCarthy // Indicates we've detached from the inferior process and the debug loop can 914ad5def9SAdrian McCarthy // exit. 924ad5def9SAdrian McCarthy bool m_detached = false; 934ad5def9SAdrian McCarthy 944ad5def9SAdrian McCarthy lldb::thread_result_t 954ad5def9SAdrian McCarthy DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info); 964ad5def9SAdrian McCarthy lldb::thread_result_t 974ad5def9SAdrian McCarthy DebuggerThreadAttachRoutine(lldb::pid_t pid, 984ad5def9SAdrian McCarthy const ProcessAttachInfo &launch_info); 994ad5def9SAdrian McCarthy }; 1004ad5def9SAdrian McCarthy } 1014ad5def9SAdrian McCarthy #endif 102