Greg Clayton | 269f91e | 2011-07-15 18:02:58 +0000 | [diff] [blame] | 1 | //===-- ProcessKDP.h --------------------------------------------*- C++ -*-===// |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 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 |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 68 | CanDebug (lldb_private::Target &target, |
| 69 | bool plugin_specified_by_name); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 0fa5124 | 2011-07-19 03:57:15 +0000 | [diff] [blame^] | 186 | CommunicationKDP & |
| 187 | GetCommunication() |
| 188 | { |
| 189 | return m_comm; |
| 190 | } |
| 191 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 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 | UpdateThreadListIfNeeded (); |
| 237 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 238 | enum |
| 239 | { |
| 240 | eBroadcastBitAsyncContinue = (1 << 0), |
| 241 | eBroadcastBitAsyncThreadShouldExit = (1 << 1) |
| 242 | }; |
| 243 | |
| 244 | lldb_private::Error |
| 245 | InterruptIfRunning (bool discard_thread_plans, |
| 246 | bool catch_stop_event, |
| 247 | lldb::EventSP &stop_event_sp); |
| 248 | |
| 249 | //------------------------------------------------------------------ |
| 250 | /// Broadcaster event bits definitions. |
| 251 | //------------------------------------------------------------------ |
| 252 | CommunicationKDP m_comm; |
| 253 | lldb_private::Broadcaster m_async_broadcaster; |
| 254 | lldb::thread_t m_async_thread; |
| 255 | |
| 256 | bool |
| 257 | StartAsyncThread (); |
| 258 | |
| 259 | void |
| 260 | StopAsyncThread (); |
| 261 | |
| 262 | static void * |
| 263 | AsyncThread (void *arg); |
| 264 | |
| 265 | lldb::StateType |
| 266 | SetThreadStopInfo (StringExtractor& stop_packet); |
| 267 | |
| 268 | static size_t |
| 269 | AttachInputReaderCallback (void *baton, |
| 270 | lldb_private::InputReader *reader, |
| 271 | lldb::InputReaderAction notification, |
| 272 | const char *bytes, |
| 273 | size_t bytes_len); |
| 274 | |
| 275 | private: |
| 276 | //------------------------------------------------------------------ |
| 277 | // For ProcessKDP only |
| 278 | //------------------------------------------------------------------ |
| 279 | |
| 280 | DISALLOW_COPY_AND_ASSIGN (ProcessKDP); |
| 281 | |
| 282 | }; |
| 283 | |
| 284 | #endif // liblldb_ProcessKDP_h_ |