From 14f1b3e8826ce43b978db93a62d1166055db5394 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 2 Jan 2017 19:26:05 +0000 Subject: Vendor import of lldb trunk r290819: https://llvm.org/svn/llvm-project/lldb/trunk@290819 --- .../Process/Windows/Common/DebuggerThread.h | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 source/Plugins/Process/Windows/Common/DebuggerThread.h (limited to 'source/Plugins/Process/Windows/Common/DebuggerThread.h') diff --git a/source/Plugins/Process/Windows/Common/DebuggerThread.h b/source/Plugins/Process/Windows/Common/DebuggerThread.h new file mode 100644 index 0000000000000..ef4b47bab8c7b --- /dev/null +++ b/source/Plugins/Process/Windows/Common/DebuggerThread.h @@ -0,0 +1,106 @@ +//===-- DebuggerThread.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_ +#define liblldb_Plugins_Process_Windows_DebuggerThread_H_ + +#include +#include + +#include "ForwardDecl.h" +#include "lldb/Host/HostProcess.h" +#include "lldb/Host/HostThread.h" +#include "lldb/Host/Predicate.h" +#include "lldb/Host/windows/windows.h" + +namespace lldb_private { + +//---------------------------------------------------------------------- +// DebuggerThread +// +// Debugs a single process, notifying listeners as appropriate when interesting +// things occur. +//---------------------------------------------------------------------- +class DebuggerThread : public std::enable_shared_from_this { +public: + DebuggerThread(DebugDelegateSP debug_delegate); + virtual ~DebuggerThread(); + + Error DebugLaunch(const ProcessLaunchInfo &launch_info); + Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info); + + HostProcess GetProcess() const { return m_process; } + HostThread GetMainThread() const { return m_main_thread; } + std::weak_ptr GetActiveException() { + return m_active_exception; + } + + Error StopDebugging(bool terminate); + + void ContinueAsyncException(ExceptionResult result); + +private: + void FreeProcessHandles(); + void DebugLoop(); + ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, + DWORD thread_id); + DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, + DWORD thread_id); + DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, + DWORD thread_id); + DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, + DWORD thread_id); + DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, + DWORD thread_id); + DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id); + DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, + DWORD thread_id); + DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id); + DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id); + + DebugDelegateSP m_debug_delegate; + + HostProcess m_process; // The process being debugged. + HostThread m_main_thread; // The main thread of the inferior. + + // The image file of the process being debugged. + HANDLE m_image_file = nullptr; + + // The current exception waiting to be handled + ExceptionRecordSP m_active_exception; + + // A predicate which gets signalled when an exception is finished processing + // and the debug loop can be continued. + Predicate m_exception_pred; + + // An event which gets signalled by the debugger thread when it exits the + // debugger loop and is detached from the inferior. + HANDLE m_debugging_ended_event = nullptr; + + // Signals the loop to detach from the process (specified by pid). + std::atomic m_pid_to_detach; + + // Signals the debug loop to stop processing certain types of events that + // block shutdown. + std::atomic m_is_shutting_down; + + // Indicates we've detached from the inferior process and the debug loop can + // exit. + bool m_detached = false; + + static lldb::thread_result_t DebuggerThreadLaunchRoutine(void *data); + lldb::thread_result_t + DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info); + static lldb::thread_result_t DebuggerThreadAttachRoutine(void *data); + lldb::thread_result_t + DebuggerThreadAttachRoutine(lldb::pid_t pid, + const ProcessAttachInfo &launch_info); +}; +} +#endif -- cgit v1.2.3