Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ProcessGDBRemote.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_ProcessGDBRemote_h_ |
| 11 | #define liblldb_ProcessGDBRemote_h_ |
| 12 | |
| 13 | // C Includes |
| 14 | |
| 15 | // C++ Includes |
| 16 | #include <list> |
Greg Clayton | c1f4587 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 17 | #include <vector> |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StringList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Core/ThreadSafeValue.h" |
| 27 | #include "lldb/Target/Process.h" |
| 28 | #include "lldb/Target/Thread.h" |
| 29 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 30 | #include "GDBRemoteCommunicationClient.h" |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 31 | #include "Utility/StringExtractor.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "GDBRemoteRegisterContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | |
| 34 | class ThreadGDBRemote; |
| 35 | |
| 36 | class ProcessGDBRemote : public lldb_private::Process |
| 37 | { |
| 38 | public: |
| 39 | //------------------------------------------------------------------ |
| 40 | // Constructors and Destructors |
| 41 | //------------------------------------------------------------------ |
| 42 | static Process* |
| 43 | CreateInstance (lldb_private::Target& target, lldb_private::Listener &listener); |
| 44 | |
| 45 | static void |
| 46 | Initialize(); |
| 47 | |
| 48 | static void |
| 49 | Terminate(); |
| 50 | |
| 51 | static const char * |
| 52 | GetPluginNameStatic(); |
| 53 | |
| 54 | static const char * |
| 55 | GetPluginDescriptionStatic(); |
| 56 | |
| 57 | //------------------------------------------------------------------ |
| 58 | // Constructors and Destructors |
| 59 | //------------------------------------------------------------------ |
| 60 | ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener); |
| 61 | |
| 62 | virtual |
| 63 | ~ProcessGDBRemote(); |
| 64 | |
| 65 | //------------------------------------------------------------------ |
| 66 | // Check if a given Process |
| 67 | //------------------------------------------------------------------ |
| 68 | virtual bool |
Greg Clayton | 8d2ea28 | 2011-07-17 20:36:25 +0000 | [diff] [blame] | 69 | CanDebug (lldb_private::Target &target, |
| 70 | bool plugin_specified_by_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 72 | // virtual uint32_t |
| 73 | // ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | //------------------------------------------------------------------ |
| 76 | // Creating a new process, or attaching to an existing one |
| 77 | //------------------------------------------------------------------ |
| 78 | virtual lldb_private::Error |
| 79 | WillLaunch (lldb_private::Module* module); |
| 80 | |
| 81 | virtual lldb_private::Error |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame^] | 82 | DoLaunch (lldb_private::Module *exe_module, |
| 83 | const lldb_private::ProcessLaunchInfo &launch_info); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | |
| 85 | virtual void |
| 86 | DidLaunch (); |
| 87 | |
| 88 | virtual lldb_private::Error |
Greg Clayton | 20d338f | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 89 | WillAttachToProcessWithID (lldb::pid_t pid); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | |
| 91 | virtual lldb_private::Error |
Greg Clayton | 20d338f | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 92 | WillAttachToProcessWithName (const char *process_name, bool wait_for_launch); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 94 | virtual lldb_private::Error |
| 95 | DoConnectRemote (const char *remote_url); |
| 96 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | lldb_private::Error |
| 98 | WillLaunchOrAttach (); |
| 99 | |
| 100 | virtual lldb_private::Error |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 101 | DoAttachToProcessWithID (lldb::pid_t pid); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | |
| 103 | virtual lldb_private::Error |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 104 | DoAttachToProcessWithName (const char *process_name, bool wait_for_launch); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | |
| 106 | virtual void |
| 107 | DidAttach (); |
| 108 | |
| 109 | //------------------------------------------------------------------ |
| 110 | // PluginInterface protocol |
| 111 | //------------------------------------------------------------------ |
| 112 | virtual const char * |
| 113 | GetPluginName(); |
| 114 | |
| 115 | virtual const char * |
| 116 | GetShortPluginName(); |
| 117 | |
| 118 | virtual uint32_t |
| 119 | GetPluginVersion(); |
| 120 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | //------------------------------------------------------------------ |
| 122 | // Process Control |
| 123 | //------------------------------------------------------------------ |
| 124 | virtual lldb_private::Error |
| 125 | WillResume (); |
| 126 | |
| 127 | virtual lldb_private::Error |
| 128 | DoResume (); |
| 129 | |
| 130 | virtual lldb_private::Error |
Jim Ingham | 3ae449a | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 131 | DoHalt (bool &caused_stop); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 132 | |
| 133 | virtual lldb_private::Error |
| 134 | WillDetach (); |
| 135 | |
| 136 | virtual lldb_private::Error |
| 137 | DoDetach (); |
| 138 | |
| 139 | virtual lldb_private::Error |
| 140 | DoSignal (int signal); |
| 141 | |
| 142 | virtual lldb_private::Error |
| 143 | DoDestroy (); |
| 144 | |
| 145 | virtual void |
| 146 | RefreshStateAfterStop(); |
| 147 | |
| 148 | //------------------------------------------------------------------ |
| 149 | // Process Queries |
| 150 | //------------------------------------------------------------------ |
| 151 | virtual bool |
| 152 | IsAlive (); |
| 153 | |
| 154 | virtual lldb::addr_t |
| 155 | GetImageInfoAddress(); |
| 156 | |
| 157 | //------------------------------------------------------------------ |
| 158 | // Process Memory |
| 159 | //------------------------------------------------------------------ |
| 160 | virtual size_t |
| 161 | DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error); |
| 162 | |
| 163 | virtual size_t |
| 164 | DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error); |
| 165 | |
| 166 | virtual lldb::addr_t |
| 167 | DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error); |
| 168 | |
| 169 | virtual lldb_private::Error |
| 170 | DoDeallocateMemory (lldb::addr_t ptr); |
| 171 | |
| 172 | //------------------------------------------------------------------ |
| 173 | // Process STDIO |
| 174 | //------------------------------------------------------------------ |
| 175 | virtual size_t |
| 176 | GetSTDOUT (char *buf, size_t buf_size, lldb_private::Error &error); |
| 177 | |
| 178 | virtual size_t |
| 179 | GetSTDERR (char *buf, size_t buf_size, lldb_private::Error &error); |
| 180 | |
| 181 | virtual size_t |
| 182 | PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error); |
| 183 | |
| 184 | //---------------------------------------------------------------------- |
| 185 | // Process Breakpoints |
| 186 | //---------------------------------------------------------------------- |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 187 | virtual lldb_private::Error |
| 188 | EnableBreakpoint (lldb_private::BreakpointSite *bp_site); |
| 189 | |
| 190 | virtual lldb_private::Error |
| 191 | DisableBreakpoint (lldb_private::BreakpointSite *bp_site); |
| 192 | |
| 193 | //---------------------------------------------------------------------- |
| 194 | // Process Watchpoints |
| 195 | //---------------------------------------------------------------------- |
| 196 | virtual lldb_private::Error |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 197 | EnableWatchpoint (lldb_private::Watchpoint *wp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | |
| 199 | virtual lldb_private::Error |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 200 | DisableWatchpoint (lldb_private::Watchpoint *wp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | |
Jim Ingham | 55e01d8 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 202 | virtual bool |
| 203 | StartNoticingNewThreads(); |
| 204 | |
| 205 | virtual bool |
| 206 | StopNoticingNewThreads(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | |
| 208 | protected: |
| 209 | friend class ThreadGDBRemote; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 210 | friend class GDBRemoteCommunicationClient; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | friend class GDBRemoteRegisterContext; |
| 212 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | //---------------------------------------------------------------------- |
| 214 | // Accessors |
| 215 | //---------------------------------------------------------------------- |
| 216 | bool |
| 217 | IsRunning ( lldb::StateType state ) |
| 218 | { |
| 219 | return state == lldb::eStateRunning || IsStepping(state); |
| 220 | } |
| 221 | |
| 222 | bool |
| 223 | IsStepping ( lldb::StateType state) |
| 224 | { |
| 225 | return state == lldb::eStateStepping; |
| 226 | } |
| 227 | bool |
| 228 | CanResume ( lldb::StateType state) |
| 229 | { |
| 230 | return state == lldb::eStateStopped; |
| 231 | } |
| 232 | |
| 233 | bool |
| 234 | HasExited (lldb::StateType state) |
| 235 | { |
| 236 | return state == lldb::eStateExited; |
| 237 | } |
| 238 | |
| 239 | bool |
| 240 | ProcessIDIsValid ( ) const; |
| 241 | |
Caroline Tice | 861efb3 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 242 | // static void |
| 243 | // STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 244 | |
Caroline Tice | 861efb3 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 245 | // void |
| 246 | // AppendSTDOUT (const char* s, size_t len); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | void |
| 249 | Clear ( ); |
| 250 | |
| 251 | lldb_private::Flags & |
| 252 | GetFlags () |
| 253 | { |
| 254 | return m_flags; |
| 255 | } |
| 256 | |
| 257 | const lldb_private::Flags & |
| 258 | GetFlags () const |
| 259 | { |
| 260 | return m_flags; |
| 261 | } |
| 262 | |
| 263 | uint32_t |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 264 | UpdateThreadList (lldb_private::ThreadList &old_thread_list, |
| 265 | lldb_private::ThreadList &new_thread_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 266 | |
| 267 | lldb_private::Error |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 268 | StartDebugserverProcess (const char *debugserver_url); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 269 | |
| 270 | void |
| 271 | KillDebugserverProcess (); |
| 272 | |
| 273 | void |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 274 | BuildDynamicRegisterInfo (bool force); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 276 | GDBRemoteCommunicationClient & |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 277 | GetGDBRemote() |
| 278 | { |
| 279 | return m_gdb_comm; |
| 280 | } |
| 281 | |
| 282 | //------------------------------------------------------------------ |
| 283 | /// Broadcaster event bits definitions. |
| 284 | //------------------------------------------------------------------ |
| 285 | enum |
| 286 | { |
| 287 | eBroadcastBitAsyncContinue = (1 << 0), |
| 288 | eBroadcastBitAsyncThreadShouldExit = (1 << 1) |
| 289 | }; |
| 290 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 291 | lldb_private::Flags m_flags; // Process specific flags (see eFlags enums) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | lldb_private::Mutex m_stdio_mutex; // Multithreaded protection for stdio |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 293 | GDBRemoteCommunicationClient m_gdb_comm; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 294 | lldb::pid_t m_debugserver_pid; |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 295 | lldb::thread_t m_debugserver_thread; |
Greg Clayton | 261a18b | 2011-06-02 22:22:38 +0000 | [diff] [blame] | 296 | StringExtractorGDBRemote m_last_stop_packet; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | GDBRemoteDynamicRegisterInfo m_register_info; |
| 298 | lldb_private::Broadcaster m_async_broadcaster; |
| 299 | lldb::thread_t m_async_thread; |
Greg Clayton | c1f4587 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 300 | typedef std::vector<lldb::tid_t> tid_collection; |
| 301 | typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection; |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 302 | typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; |
Greg Clayton | c1f4587 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 303 | tid_collection m_continue_c_tids; // 'c' for continue |
| 304 | tid_sig_collection m_continue_C_tids; // 'C' for continue with signal |
| 305 | tid_collection m_continue_s_tids; // 's' for step |
| 306 | tid_sig_collection m_continue_S_tids; // 'S' for step with signal |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 307 | lldb::addr_t m_dispatch_queue_offsets_addr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 | size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | bool m_waiting_for_attach; |
Jim Ingham | 55e01d8 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 310 | std::vector<lldb::user_id_t> m_thread_observation_bps; |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 311 | MMapMap m_addr_to_mmap_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 312 | bool |
| 313 | StartAsyncThread (); |
| 314 | |
| 315 | void |
| 316 | StopAsyncThread (); |
| 317 | |
| 318 | static void * |
| 319 | AsyncThread (void *arg); |
| 320 | |
| 321 | static bool |
| 322 | MonitorDebugserverProcess (void *callback_baton, |
| 323 | lldb::pid_t pid, |
| 324 | int signo, // Zero for no signal |
| 325 | int exit_status); // Exit value of process if signal is zero |
| 326 | |
| 327 | lldb::StateType |
| 328 | SetThreadStopInfo (StringExtractor& stop_packet); |
| 329 | |
| 330 | void |
| 331 | DidLaunchOrAttach (); |
| 332 | |
| 333 | lldb_private::Error |
| 334 | ConnectToDebugserver (const char *host_port); |
| 335 | |
| 336 | const char * |
| 337 | GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr, |
| 338 | std::string &dispatch_queue_name); |
| 339 | |
| 340 | static size_t |
| 341 | AttachInputReaderCallback (void *baton, |
| 342 | lldb_private::InputReader *reader, |
| 343 | lldb::InputReaderAction notification, |
| 344 | const char *bytes, |
| 345 | size_t bytes_len); |
| 346 | |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 347 | lldb_private::Error |
| 348 | InterruptIfRunning (bool discard_thread_plans, |
| 349 | bool catch_stop_event, |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 350 | lldb::EventSP &stop_event_sp); |
| 351 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | private: |
| 353 | //------------------------------------------------------------------ |
| 354 | // For ProcessGDBRemote only |
| 355 | //------------------------------------------------------------------ |
Jim Ingham | 55e01d8 | 2011-01-22 01:33:44 +0000 | [diff] [blame] | 356 | static bool |
| 357 | NewThreadNotifyBreakpointHit (void *baton, |
| 358 | lldb_private::StoppointCallbackContext *context, |
| 359 | lldb::user_id_t break_id, |
| 360 | lldb::user_id_t break_loc_id); |
| 361 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 362 | DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote); |
| 363 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | #endif // liblldb_ProcessGDBRemote_h_ |