]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Process/Windows/Live/DebuggerThread.h
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / source / Plugins / Process / Windows / Live / DebuggerThread.h
1 //===-- DebuggerThread.h ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_
11 #define liblldb_Plugins_Process_Windows_DebuggerThread_H_
12
13 #include <atomic>
14 #include <memory>
15
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"
21
22 namespace lldb_private
23 {
24
25 //----------------------------------------------------------------------
26 // DebuggerThread
27 //
28 // Debugs a single process, notifying listeners as appropriate when interesting
29 // things occur.
30 //----------------------------------------------------------------------
31 class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
32 {
33   public:
34     DebuggerThread(DebugDelegateSP debug_delegate);
35     virtual ~DebuggerThread();
36
37     Error DebugLaunch(const ProcessLaunchInfo &launch_info);
38     Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
39
40     HostProcess
41     GetProcess() const
42     {
43         return m_process;
44     }
45     HostThread
46     GetMainThread() const
47     {
48         return m_main_thread;
49     }
50     std::weak_ptr<ExceptionRecord>
51     GetActiveException()
52     {
53         return m_active_exception;
54     }
55
56     Error StopDebugging(bool terminate);
57
58     void ContinueAsyncException(ExceptionResult result);
59
60   private:
61     void FreeProcessHandles();
62     void DebugLoop();
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);
72
73     DebugDelegateSP m_debug_delegate;
74
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.
78
79     ExceptionRecordSP m_active_exception; // The current exception waiting to be handled
80
81     Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
82                                                  // is finished processing and the debug loop can be
83                                                  // continued.
84
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.
87
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.
92
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);
97 };
98 }
99
100 #endif