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 // C Includes 14 15 // C++ Includes 16 #include <list> 17 #include <vector> 18 19 // Other libraries and framework includes 20 #include "lldb/Core/ArchSpec.h" 21 #include "lldb/Core/Broadcaster.h" 22 #include "lldb/Core/Error.h" 23 #include "lldb/Core/InputReader.h" 24 #include "lldb/Core/StreamString.h" 25 #include "lldb/Core/StringList.h" 26 #include "lldb/Core/ThreadSafeValue.h" 27 #include "lldb/Target/Process.h" 28 #include "lldb/Target/Thread.h" 29 30 #include "CommunicationKDP.h" 31 #include "Utility/StringExtractor.h" 32 33 class ThreadKDP; 34 35 class ProcessKDP : public lldb_private::Process 36 { 37 public: 38 //------------------------------------------------------------------ 39 // Constructors and Destructors 40 //------------------------------------------------------------------ 41 static Process* 42 CreateInstance (lldb_private::Target& target, lldb_private::Listener &listener); 43 44 static void 45 Initialize(); 46 47 static void 48 Terminate(); 49 50 static const char * 51 GetPluginNameStatic(); 52 53 static const char * 54 GetPluginDescriptionStatic(); 55 56 //------------------------------------------------------------------ 57 // Constructors and Destructors 58 //------------------------------------------------------------------ 59 ProcessKDP(lldb_private::Target& target, lldb_private::Listener &listener); 60 61 virtual 62 ~ProcessKDP(); 63 64 //------------------------------------------------------------------ 65 // Check if a given Process 66 //------------------------------------------------------------------ 67 virtual bool 68 CanDebug (lldb_private::Target &target, 69 bool plugin_specified_by_name); 70 71 // virtual uint32_t 72 // ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids); 73 74 //------------------------------------------------------------------ 75 // Creating a new process, or attaching to an existing one 76 //------------------------------------------------------------------ 77 virtual lldb_private::Error 78 WillLaunch (lldb_private::Module* module); 79 80 virtual lldb_private::Error 81 DoLaunch (lldb_private::Module* module, 82 char const *argv[], // Can be NULL 83 char const *envp[], // Can be NULL 84 uint32_t flags, 85 const char *stdin_path, // Can be NULL 86 const char *stdout_path, // Can be NULL 87 const char *stderr_path, // Can be NULL 88 const char *working_dir); // Can be NULL 89 90 virtual lldb_private::Error 91 WillAttachToProcessWithID (lldb::pid_t pid); 92 93 virtual lldb_private::Error 94 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch); 95 96 virtual lldb_private::Error 97 DoConnectRemote (const char *remote_url); 98 99 virtual lldb_private::Error 100 DoAttachToProcessWithID (lldb::pid_t pid); 101 102 virtual lldb_private::Error 103 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch); 104 105 virtual void 106 DidAttach (); 107 108 //------------------------------------------------------------------ 109 // PluginInterface protocol 110 //------------------------------------------------------------------ 111 virtual const char * 112 GetPluginName(); 113 114 virtual const char * 115 GetShortPluginName(); 116 117 virtual uint32_t 118 GetPluginVersion(); 119 120 //------------------------------------------------------------------ 121 // Process Control 122 //------------------------------------------------------------------ 123 virtual lldb_private::Error 124 WillResume (); 125 126 virtual lldb_private::Error 127 DoResume (); 128 129 virtual lldb_private::Error 130 DoHalt (bool &caused_stop); 131 132 virtual lldb_private::Error 133 WillDetach (); 134 135 virtual lldb_private::Error 136 DoDetach (); 137 138 virtual lldb_private::Error 139 DoSignal (int signal); 140 141 virtual lldb_private::Error 142 DoDestroy (); 143 144 virtual void 145 RefreshStateAfterStop(); 146 147 //------------------------------------------------------------------ 148 // Process Queries 149 //------------------------------------------------------------------ 150 virtual bool 151 IsAlive (); 152 153 //------------------------------------------------------------------ 154 // Process Memory 155 //------------------------------------------------------------------ 156 virtual size_t 157 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error); 158 159 virtual size_t 160 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error); 161 162 virtual lldb::addr_t 163 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error); 164 165 virtual lldb_private::Error 166 DoDeallocateMemory (lldb::addr_t ptr); 167 168 //---------------------------------------------------------------------- 169 // Process Breakpoints 170 //---------------------------------------------------------------------- 171 virtual lldb_private::Error 172 EnableBreakpoint (lldb_private::BreakpointSite *bp_site); 173 174 virtual lldb_private::Error 175 DisableBreakpoint (lldb_private::BreakpointSite *bp_site); 176 177 //---------------------------------------------------------------------- 178 // Process Watchpoints 179 //---------------------------------------------------------------------- 180 virtual lldb_private::Error 181 EnableWatchpoint (lldb_private::WatchpointLocation *wp_loc); 182 183 virtual lldb_private::Error 184 DisableWatchpoint (lldb_private::WatchpointLocation *wp_loc); 185 186 CommunicationKDP & 187 GetCommunication() 188 { 189 return m_comm; 190 } 191 192 protected: 193 friend class ThreadKDP; 194 friend class CommunicationKDP; 195 196 //---------------------------------------------------------------------- 197 // Accessors 198 //---------------------------------------------------------------------- 199 bool 200 IsRunning ( lldb::StateType state ) 201 { 202 return state == lldb::eStateRunning || IsStepping(state); 203 } 204 205 bool 206 IsStepping ( lldb::StateType state) 207 { 208 return state == lldb::eStateStepping; 209 } 210 211 bool 212 CanResume ( lldb::StateType state) 213 { 214 return state == lldb::eStateStopped; 215 } 216 217 bool 218 HasExited (lldb::StateType state) 219 { 220 return state == lldb::eStateExited; 221 } 222 223 bool 224 ProcessIDIsValid ( ) const; 225 226 // static void 227 // STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); 228 229 // void 230 // AppendSTDOUT (const char* s, size_t len); 231 232 void 233 Clear ( ); 234 235 uint32_t 236 UpdateThreadList (lldb_private::ThreadList &old_thread_list, 237 lldb_private::ThreadList &new_thread_list); 238 239 enum 240 { 241 eBroadcastBitAsyncContinue = (1 << 0), 242 eBroadcastBitAsyncThreadShouldExit = (1 << 1) 243 }; 244 245 lldb_private::Error 246 InterruptIfRunning (bool discard_thread_plans, 247 bool catch_stop_event, 248 lldb::EventSP &stop_event_sp); 249 250 //------------------------------------------------------------------ 251 /// Broadcaster event bits definitions. 252 //------------------------------------------------------------------ 253 CommunicationKDP m_comm; 254 lldb_private::Broadcaster m_async_broadcaster; 255 lldb::thread_t m_async_thread; 256 257 bool 258 StartAsyncThread (); 259 260 void 261 StopAsyncThread (); 262 263 static void * 264 AsyncThread (void *arg); 265 266 lldb::StateType 267 SetThreadStopInfo (StringExtractor& stop_packet); 268 269 private: 270 //------------------------------------------------------------------ 271 // For ProcessKDP only 272 //------------------------------------------------------------------ 273 274 DISALLOW_COPY_AND_ASSIGN (ProcessKDP); 275 276 }; 277 278 #endif // liblldb_ProcessKDP_h_ 279