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