1 //===-- ProcessWindows.h ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
10 #define liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
11 
12 #include "lldb/Target/Process.h"
13 #include "lldb/Utility/Status.h"
14 #include "lldb/lldb-forward.h"
15 
16 #include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h"
17 #include "ProcessDebugger.h"
18 
19 namespace lldb_private {
20 
21 class HostProcess;
22 
23 class ProcessWindows : public Process, public ProcessDebugger {
24 public:
25   // Static functions.
26   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
27                                         lldb::ListenerSP listener_sp,
28                                         const FileSpec *,
29                                         bool can_connect);
30 
31   static void Initialize();
32 
33   static void Terminate();
34 
GetPluginNameStatic()35   static llvm::StringRef GetPluginNameStatic() { return "windows"; }
36 
37   static llvm::StringRef GetPluginDescriptionStatic();
38 
39   // Constructors and destructors
40   ProcessWindows(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
41 
42   ~ProcessWindows();
43 
44   size_t GetSTDOUT(char *buf, size_t buf_size, Status &error) override;
45   size_t GetSTDERR(char *buf, size_t buf_size, Status &error) override;
46   size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
47 
GetPluginName()48   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
49 
50   Status EnableBreakpointSite(BreakpointSite *bp_site) override;
51   Status DisableBreakpointSite(BreakpointSite *bp_site) override;
52 
53   Status DoDetach(bool keep_stopped) override;
54   Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
55   Status DoAttachToProcessWithID(
56       lldb::pid_t pid,
57       const lldb_private::ProcessAttachInfo &attach_info) override;
58   Status DoResume() override;
59   Status DoDestroy() override;
60   Status DoHalt(bool &caused_stop) override;
61 
62   void DidLaunch() override;
63   void DidAttach(lldb_private::ArchSpec &arch_spec) override;
64 
65   void RefreshStateAfterStop() override;
66 
67   bool CanDebug(lldb::TargetSP target_sp,
68                 bool plugin_specified_by_name) override;
DestroyRequiresHalt()69   bool DestroyRequiresHalt() override { return false; }
70   bool DoUpdateThreadList(ThreadList &old_thread_list,
71                           ThreadList &new_thread_list) override;
72   bool IsAlive() override;
73 
74   ArchSpec GetSystemArchitecture() override;
75 
76   size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
77                       Status &error) override;
78   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
79                        Status &error) override;
80   lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
81                                 Status &error) override;
82   Status DoDeallocateMemory(lldb::addr_t ptr) override;
83 
84   lldb::addr_t GetImageInfoAddress() override;
85 
86   DynamicLoaderWindowsDYLD *GetDynamicLoader() override;
87 
88   // IDebugDelegate overrides.
89   void OnExitProcess(uint32_t exit_code) override;
90   void OnDebuggerConnected(lldb::addr_t image_base) override;
91   ExceptionResult OnDebugException(bool first_chance,
92                                    const ExceptionRecord &record) override;
93   void OnCreateThread(const HostThread &thread) override;
94   void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override;
95   void OnLoadDll(const ModuleSpec &module_spec,
96                  lldb::addr_t module_addr) override;
97   void OnUnloadDll(lldb::addr_t module_addr) override;
98   void OnDebugString(const std::string &string) override;
99   void OnDebuggerError(const Status &error, uint32_t type) override;
100 
101   Status GetWatchpointSupportInfo(uint32_t &num) override;
102   Status GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
103   Status EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
104   Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
105 
106 protected:
107   Status DoGetMemoryRegionInfo(lldb::addr_t vm_addr,
108                                MemoryRegionInfo &info) override;
109 
110 private:
111   struct WatchpointInfo {
112     uint32_t slot_id;
113     lldb::addr_t address;
114     uint32_t size;
115     bool read;
116     bool write;
117   };
118   std::map<lldb::break_id_t, WatchpointInfo> m_watchpoints;
119   std::vector<lldb::break_id_t> m_watchpoint_ids;
120 };
121 } // namespace lldb_private
122 
123 #endif // liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
124