102 lines · c
1//===-- DebuggerThread.h ----------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_10#define liblldb_Plugins_Process_Windows_DebuggerThread_H_11 12#include <atomic>13#include <memory>14 15#include "ForwardDecl.h"16#include "lldb/Host/HostProcess.h"17#include "lldb/Host/HostThread.h"18#include "lldb/Host/windows/windows.h"19#include "lldb/Utility/Predicate.h"20 21namespace lldb_private {22 23// DebuggerThread24//25// Debugs a single process, notifying listeners as appropriate when interesting26// things occur.27class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> {28public:29 DebuggerThread(DebugDelegateSP debug_delegate);30 virtual ~DebuggerThread();31 32 Status DebugLaunch(const ProcessLaunchInfo &launch_info);33 Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);34 35 HostProcess GetProcess() const { return m_process; }36 HostThread GetMainThread() const { return m_main_thread; }37 std::weak_ptr<ExceptionRecord> GetActiveException() {38 return m_active_exception;39 }40 41 Status StopDebugging(bool terminate);42 43 void ContinueAsyncException(ExceptionResult result);44 45private:46 void FreeProcessHandles();47 void DebugLoop();48 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,49 DWORD thread_id, bool shutting_down);50 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,51 DWORD thread_id);52 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,53 DWORD thread_id);54 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,55 DWORD thread_id);56 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,57 DWORD thread_id);58 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);59 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,60 DWORD thread_id);61 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);62 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);63 64 DebugDelegateSP m_debug_delegate;65 66 HostProcess m_process; // The process being debugged.67 HostThread m_main_thread; // The main thread of the inferior.68 69 // The image file of the process being debugged.70 HANDLE m_image_file = nullptr;71 72 // The current exception waiting to be handled73 ExceptionRecordSP m_active_exception;74 75 // A predicate which gets signalled when an exception is finished processing76 // and the debug loop can be continued.77 Predicate<ExceptionResult> m_exception_pred;78 79 // An event which gets signalled by the debugger thread when it exits the80 // debugger loop and is detached from the inferior.81 HANDLE m_debugging_ended_event = nullptr;82 83 // Signals the loop to detach from the process (specified by pid).84 std::atomic<DWORD> m_pid_to_detach;85 86 // Signals the debug loop to stop processing certain types of events that87 // block shutdown.88 std::atomic<bool> m_is_shutting_down;89 90 // Indicates we've detached from the inferior process and the debug loop can91 // exit.92 bool m_detached = false;93 94 lldb::thread_result_t95 DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info);96 lldb::thread_result_t97 DebuggerThreadAttachRoutine(lldb::pid_t pid,98 const ProcessAttachInfo &launch_info);99};100}101#endif102