1 //===-- ProcessGDBRemote.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ProcessGDBRemote_h_
11 #define liblldb_ProcessGDBRemote_h_
19 // Other libraries and framework includes
20 #include "lldb/Core/ArchSpec.h"
21 #include "lldb/Core/Broadcaster.h"
22 #include "lldb/Core/ConstString.h"
23 #include "lldb/Core/Error.h"
24 #include "lldb/Core/InputReader.h"
25 #include "lldb/Core/StreamString.h"
26 #include "lldb/Core/StringList.h"
27 #include "lldb/Core/ThreadSafeValue.h"
28 #include "lldb/Target/Process.h"
29 #include "lldb/Target/Thread.h"
31 #include "GDBRemoteCommunicationClient.h"
32 #include "Utility/StringExtractor.h"
33 #include "GDBRemoteRegisterContext.h"
35 class ThreadGDBRemote;
37 class ProcessGDBRemote : public lldb_private::Process
40 //------------------------------------------------------------------
41 // Constructors and Destructors
42 //------------------------------------------------------------------
43 static lldb::ProcessSP
44 CreateInstance (lldb_private::Target& target,
45 lldb_private::Listener &listener,
46 const lldb_private::FileSpec *crash_file_path);
52 DebuggerInitialize (lldb_private::Debugger &debugger);
57 static lldb_private::ConstString
58 GetPluginNameStatic();
61 GetPluginDescriptionStatic();
63 //------------------------------------------------------------------
64 // Constructors and Destructors
65 //------------------------------------------------------------------
66 ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener);
71 //------------------------------------------------------------------
72 // Check if a given Process
73 //------------------------------------------------------------------
75 CanDebug (lldb_private::Target &target,
76 bool plugin_specified_by_name);
78 virtual lldb_private::CommandObject *
79 GetPluginCommandObject();
81 //------------------------------------------------------------------
82 // Creating a new process, or attaching to an existing one
83 //------------------------------------------------------------------
84 virtual lldb_private::Error
85 WillLaunch (lldb_private::Module* module);
87 virtual lldb_private::Error
88 DoLaunch (lldb_private::Module *exe_module,
89 const lldb_private::ProcessLaunchInfo &launch_info);
94 virtual lldb_private::Error
95 WillAttachToProcessWithID (lldb::pid_t pid);
97 virtual lldb_private::Error
98 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
100 virtual lldb_private::Error
101 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
104 WillLaunchOrAttach ();
106 virtual lldb_private::Error
107 DoAttachToProcessWithID (lldb::pid_t pid);
109 virtual lldb_private::Error
110 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
112 virtual lldb_private::Error
113 DoAttachToProcessWithName (const char *process_name,
114 bool wait_for_launch,
115 const lldb_private::ProcessAttachInfo &attach_info);
120 //------------------------------------------------------------------
121 // PluginInterface protocol
122 //------------------------------------------------------------------
123 virtual lldb_private::ConstString
129 //------------------------------------------------------------------
131 //------------------------------------------------------------------
132 virtual lldb_private::Error
135 virtual lldb_private::Error
138 virtual lldb_private::Error
139 DoHalt (bool &caused_stop);
141 virtual lldb_private::Error
142 DoDetach (bool keep_stopped);
145 DetachRequiresHalt() { return true; }
147 virtual lldb_private::Error
148 DoSignal (int signal);
150 virtual lldb_private::Error
154 RefreshStateAfterStop();
156 //------------------------------------------------------------------
158 //------------------------------------------------------------------
163 GetImageInfoAddress();
165 //------------------------------------------------------------------
167 //------------------------------------------------------------------
169 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
172 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
175 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
177 virtual lldb_private::Error
178 GetMemoryRegionInfo (lldb::addr_t load_addr,
179 lldb_private::MemoryRegionInfo ®ion_info);
181 virtual lldb_private::Error
182 DoDeallocateMemory (lldb::addr_t ptr);
184 //------------------------------------------------------------------
186 //------------------------------------------------------------------
188 PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error);
190 //----------------------------------------------------------------------
191 // Process Breakpoints
192 //----------------------------------------------------------------------
193 virtual lldb_private::Error
194 EnableBreakpointSite (lldb_private::BreakpointSite *bp_site);
196 virtual lldb_private::Error
197 DisableBreakpointSite (lldb_private::BreakpointSite *bp_site);
199 //----------------------------------------------------------------------
200 // Process Watchpoints
201 //----------------------------------------------------------------------
202 virtual lldb_private::Error
203 EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
205 virtual lldb_private::Error
206 DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
208 virtual lldb_private::Error
209 GetWatchpointSupportInfo (uint32_t &num);
211 virtual lldb_private::Error
212 GetWatchpointSupportInfo (uint32_t &num, bool& after);
215 StartNoticingNewThreads();
218 StopNoticingNewThreads();
220 GDBRemoteCommunicationClient &
227 friend class ThreadGDBRemote;
228 friend class GDBRemoteCommunicationClient;
229 friend class GDBRemoteRegisterContext;
231 //----------------------------------------------------------------------
233 //----------------------------------------------------------------------
235 IsRunning ( lldb::StateType state )
237 return state == lldb::eStateRunning || IsStepping(state);
241 IsStepping ( lldb::StateType state)
243 return state == lldb::eStateStepping;
246 CanResume ( lldb::StateType state)
248 return state == lldb::eStateStopped;
252 HasExited (lldb::StateType state)
254 return state == lldb::eStateExited;
258 ProcessIDIsValid ( ) const;
263 lldb_private::Flags &
269 const lldb_private::Flags &
276 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
277 lldb_private::ThreadList &new_thread_list);
280 StartDebugserverProcess (const char *debugserver_url);
283 StartDebugserverProcess (const char *debugserver_url, const lldb_private::ProcessInfo &process_info);
286 KillDebugserverProcess ();
289 BuildDynamicRegisterInfo (bool force);
292 SetLastStopPacket (const StringExtractorGDBRemote &response);
294 //------------------------------------------------------------------
295 /// Broadcaster event bits definitions.
296 //------------------------------------------------------------------
299 eBroadcastBitAsyncContinue = (1 << 0),
300 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
301 eBroadcastBitAsyncThreadDidExit = (1 << 2)
304 typedef enum AsyncThreadState
306 eAsyncThreadNotStarted,
311 lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
312 GDBRemoteCommunicationClient m_gdb_comm;
313 lldb::pid_t m_debugserver_pid;
314 StringExtractorGDBRemote m_last_stop_packet;
315 lldb_private::Mutex m_last_stop_packet_mutex;
316 GDBRemoteDynamicRegisterInfo m_register_info;
317 lldb_private::Broadcaster m_async_broadcaster;
318 lldb::thread_t m_async_thread;
319 AsyncThreadState m_async_thread_state;
320 lldb_private::Mutex m_async_thread_state_mutex;
321 typedef std::vector<lldb::tid_t> tid_collection;
322 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
323 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
324 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
325 tid_collection m_continue_c_tids; // 'c' for continue
326 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
327 tid_collection m_continue_s_tids; // 's' for step
328 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
329 lldb::addr_t m_dispatch_queue_offsets_addr;
330 size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
331 MMapMap m_addr_to_mmap_size;
332 lldb::BreakpointSP m_thread_create_bp_sp;
333 bool m_waiting_for_attach;
334 bool m_destroy_tried_resuming;
335 lldb::CommandObjectSP m_command_sp;
344 AsyncThread (void *arg);
347 MonitorDebugserverProcess (void *callback_baton,
354 SetThreadStopInfo (StringExtractor& stop_packet);
357 ClearThreadIDList ();
360 UpdateThreadIDList ();
363 DidLaunchOrAttach ();
366 ConnectToDebugserver (const char *host_port);
369 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
370 std::string &dispatch_queue_name);
373 AttachInputReaderCallback (void *baton,
374 lldb_private::InputReader *reader,
375 lldb::InputReaderAction notification,
379 lldb_private::DynamicLoader *
383 //------------------------------------------------------------------
384 // For ProcessGDBRemote only
385 //------------------------------------------------------------------
387 NewThreadNotifyBreakpointHit (void *baton,
388 lldb_private::StoppointCallbackContext *context,
389 lldb::user_id_t break_id,
390 lldb::user_id_t break_loc_id);
392 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
396 #endif // liblldb_ProcessGDBRemote_h_