1 //===-- ProcessKDP.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_ProcessKDP_h_ 11 #define liblldb_ProcessKDP_h_ 12 13 14 #include <list> 15 #include <vector> 16 17 #include "lldb/Core/Broadcaster.h" 18 #include "lldb/Core/ThreadSafeValue.h" 19 #include "lldb/Host/HostThread.h" 20 #include "lldb/Target/Process.h" 21 #include "lldb/Target/Thread.h" 22 #include "lldb/Utility/ArchSpec.h" 23 #include "lldb/Utility/ConstString.h" 24 #include "lldb/Utility/Status.h" 25 #include "lldb/Utility/StreamString.h" 26 #include "lldb/Utility/StringList.h" 27 28 #include "CommunicationKDP.h" 29 30 class ThreadKDP; 31 32 class ProcessKDP : public lldb_private::Process { 33 public: 34 //------------------------------------------------------------------ 35 // Constructors and Destructors 36 //------------------------------------------------------------------ 37 static lldb::ProcessSP 38 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, 39 const lldb_private::FileSpec *crash_file_path); 40 41 static void Initialize(); 42 43 static void DebuggerInitialize(lldb_private::Debugger &debugger); 44 45 static void Terminate(); 46 47 static lldb_private::ConstString GetPluginNameStatic(); 48 49 static const char *GetPluginDescriptionStatic(); 50 51 //------------------------------------------------------------------ 52 // Constructors and Destructors 53 //------------------------------------------------------------------ 54 ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener); 55 56 ~ProcessKDP() override; 57 58 //------------------------------------------------------------------ 59 // Check if a given Process 60 //------------------------------------------------------------------ 61 bool CanDebug(lldb::TargetSP target_sp, 62 bool plugin_specified_by_name) override; 63 lldb_private::CommandObject *GetPluginCommandObject() override; 64 65 //------------------------------------------------------------------ 66 // Creating a new process, or attaching to an existing one 67 //------------------------------------------------------------------ 68 lldb_private::Status WillLaunch(lldb_private::Module *module) override; 69 70 lldb_private::Status 71 DoLaunch(lldb_private::Module *exe_module, 72 lldb_private::ProcessLaunchInfo &launch_info) override; 73 74 lldb_private::Status WillAttachToProcessWithID(lldb::pid_t pid) override; 75 76 lldb_private::Status 77 WillAttachToProcessWithName(const char *process_name, 78 bool wait_for_launch) override; 79 80 lldb_private::Status DoConnectRemote(lldb_private::Stream *strm, 81 llvm::StringRef remote_url) override; 82 83 lldb_private::Status DoAttachToProcessWithID( 84 lldb::pid_t pid, 85 const lldb_private::ProcessAttachInfo &attach_info) override; 86 87 lldb_private::Status DoAttachToProcessWithName( 88 const char *process_name, 89 const lldb_private::ProcessAttachInfo &attach_info) override; 90 91 void DidAttach(lldb_private::ArchSpec &process_arch) override; 92 93 lldb::addr_t GetImageInfoAddress() override; 94 95 lldb_private::DynamicLoader *GetDynamicLoader() override; 96 97 //------------------------------------------------------------------ 98 // PluginInterface protocol 99 //------------------------------------------------------------------ 100 lldb_private::ConstString GetPluginName() override; 101 102 uint32_t GetPluginVersion() override; 103 104 //------------------------------------------------------------------ 105 // Process Control 106 //------------------------------------------------------------------ 107 lldb_private::Status WillResume() override; 108 109 lldb_private::Status DoResume() override; 110 111 lldb_private::Status DoHalt(bool &caused_stop) override; 112 113 lldb_private::Status DoDetach(bool keep_stopped) override; 114 115 lldb_private::Status DoSignal(int signal) override; 116 117 lldb_private::Status DoDestroy() override; 118 119 void RefreshStateAfterStop() override; 120 121 //------------------------------------------------------------------ 122 // Process Queries 123 //------------------------------------------------------------------ 124 bool IsAlive() override; 125 126 //------------------------------------------------------------------ 127 // Process Memory 128 //------------------------------------------------------------------ 129 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, 130 lldb_private::Status &error) override; 131 132 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, 133 lldb_private::Status &error) override; 134 135 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, 136 lldb_private::Status &error) override; 137 138 lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override; 139 140 //---------------------------------------------------------------------- 141 // Process Breakpoints 142 //---------------------------------------------------------------------- 143 lldb_private::Status 144 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override; 145 146 lldb_private::Status 147 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override; 148 149 //---------------------------------------------------------------------- 150 // Process Watchpoints 151 //---------------------------------------------------------------------- 152 lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp, 153 bool notify = true) override; 154 155 lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp, 156 bool notify = true) override; 157 158 CommunicationKDP &GetCommunication() { return m_comm; } 159 160 protected: 161 friend class ThreadKDP; 162 friend class CommunicationKDP; 163 164 //---------------------------------------------------------------------- 165 // Accessors 166 //---------------------------------------------------------------------- 167 bool IsRunning(lldb::StateType state) { 168 return state == lldb::eStateRunning || IsStepping(state); 169 } 170 171 bool IsStepping(lldb::StateType state) { 172 return state == lldb::eStateStepping; 173 } 174 175 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; } 176 177 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; } 178 179 bool GetHostArchitecture(lldb_private::ArchSpec &arch); 180 181 bool ProcessIDIsValid() const; 182 183 void Clear(); 184 185 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, 186 lldb_private::ThreadList &new_thread_list) override; 187 188 enum { 189 eBroadcastBitAsyncContinue = (1 << 0), 190 eBroadcastBitAsyncThreadShouldExit = (1 << 1) 191 }; 192 193 lldb::ThreadSP GetKernelThread(); 194 195 //------------------------------------------------------------------ 196 /// Broadcaster event bits definitions. 197 //------------------------------------------------------------------ 198 CommunicationKDP m_comm; 199 lldb_private::Broadcaster m_async_broadcaster; 200 lldb_private::HostThread m_async_thread; 201 lldb_private::ConstString m_dyld_plugin_name; 202 lldb::addr_t m_kernel_load_addr; 203 lldb::CommandObjectSP m_command_sp; 204 lldb::ThreadWP m_kernel_thread_wp; 205 206 bool StartAsyncThread(); 207 208 void StopAsyncThread(); 209 210 static void *AsyncThread(void *arg); 211 212 private: 213 //------------------------------------------------------------------ 214 // For ProcessKDP only 215 //------------------------------------------------------------------ 216 217 DISALLOW_COPY_AND_ASSIGN(ProcessKDP); 218 }; 219 220 #endif // liblldb_ProcessKDP_h_ 221