1 //===-- ProcessWindows.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_Common_ProcessWindows_H_
11 #define liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
12 
13 #include "lldb/Target/Process.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/lldb-forward.h"
16 
17 #include "llvm/Support/Mutex.h"
18 
19 #include "IDebugDelegate.h"
20 
21 namespace lldb_private {
22 
23 class HostProcess;
24 class ProcessWindowsData;
25 
26 class ProcessWindows : public Process, public IDebugDelegate {
27 public:
28   //------------------------------------------------------------------
29   // Static functions.
30   //------------------------------------------------------------------
31   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
32                                         lldb::ListenerSP listener_sp,
33                                         const FileSpec *);
34 
35   static void Initialize();
36 
37   static void Terminate();
38 
39   static lldb_private::ConstString GetPluginNameStatic();
40 
41   static const char *GetPluginDescriptionStatic();
42 
43   //------------------------------------------------------------------
44   // Constructors and destructors
45   //------------------------------------------------------------------
46   ProcessWindows(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
47 
48   ~ProcessWindows();
49 
50   size_t GetSTDOUT(char *buf, size_t buf_size, Status &error) override;
51   size_t GetSTDERR(char *buf, size_t buf_size, Status &error) override;
52   size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
53 
54   // lldb_private::Process overrides
55   ConstString GetPluginName() override;
56   uint32_t GetPluginVersion() override;
57 
58   Status EnableBreakpointSite(BreakpointSite *bp_site) override;
59   Status DisableBreakpointSite(BreakpointSite *bp_site) override;
60 
61   Status DoDetach(bool keep_stopped) override;
62   Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
63   Status DoAttachToProcessWithID(
64       lldb::pid_t pid,
65       const lldb_private::ProcessAttachInfo &attach_info) override;
66   Status DoResume() override;
67   Status DoDestroy() override;
68   Status DoHalt(bool &caused_stop) override;
69 
70   void DidLaunch() override;
71   void DidAttach(lldb_private::ArchSpec &arch_spec) override;
72 
73   void RefreshStateAfterStop() override;
74 
75   bool CanDebug(lldb::TargetSP target_sp,
76                 bool plugin_specified_by_name) override;
77   bool DestroyRequiresHalt() override { return false; }
78   bool UpdateThreadList(ThreadList &old_thread_list,
79                         ThreadList &new_thread_list) override;
80   bool IsAlive() override;
81 
82   size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
83                       Status &error) override;
84   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
85                        Status &error) override;
86   lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
87                                 Status &error) override;
88   Status DoDeallocateMemory(lldb::addr_t ptr) override;
89   Status GetMemoryRegionInfo(lldb::addr_t vm_addr,
90                              MemoryRegionInfo &info) override;
91 
92   lldb::addr_t GetImageInfoAddress() override;
93 
94   // IDebugDelegate overrides.
95   void OnExitProcess(uint32_t exit_code) override;
96   void OnDebuggerConnected(lldb::addr_t image_base) override;
97   ExceptionResult OnDebugException(bool first_chance,
98                                    const ExceptionRecord &record) override;
99   void OnCreateThread(const HostThread &thread) override;
100   void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override;
101   void OnLoadDll(const ModuleSpec &module_spec,
102                  lldb::addr_t module_addr) override;
103   void OnUnloadDll(lldb::addr_t module_addr) override;
104   void OnDebugString(const std::string &string) override;
105   void OnDebuggerError(const Status &error, uint32_t type) override;
106 
107 private:
108   Status WaitForDebuggerConnection(DebuggerThreadSP debugger,
109                                    HostProcess &process);
110 
111   // These decode the page protection bits.
112   static bool IsPageReadable(uint32_t protect);
113   static bool IsPageWritable(uint32_t protect);
114   static bool IsPageExecutable(uint32_t protect);
115 
116   llvm::sys::Mutex m_mutex;
117   std::unique_ptr<ProcessWindowsData> m_session_data;
118 };
119 }
120 
121 #endif // liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
122