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