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/StreamString.h"
25 #include "lldb/Core/StringList.h"
26 #include "lldb/Core/StructuredData.h"
27 #include "lldb/Core/ThreadSafeValue.h"
28 #include "lldb/lldb-private-forward.h"
29 #include "lldb/Target/Process.h"
30 #include "lldb/Target/Thread.h"
32 #include "GDBRemoteCommunicationClient.h"
33 #include "Utility/StringExtractor.h"
34 #include "GDBRemoteRegisterContext.h"
36 class ThreadGDBRemote;
38 class ProcessGDBRemote : public lldb_private::Process
41 //------------------------------------------------------------------
42 // Constructors and Destructors
43 //------------------------------------------------------------------
44 static lldb::ProcessSP
45 CreateInstance (lldb_private::Target& target,
46 lldb_private::Listener &listener,
47 const lldb_private::FileSpec *crash_file_path);
53 DebuggerInitialize (lldb_private::Debugger &debugger);
58 static lldb_private::ConstString
59 GetPluginNameStatic();
62 GetPluginDescriptionStatic();
64 //------------------------------------------------------------------
65 // Constructors and Destructors
66 //------------------------------------------------------------------
67 ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener);
72 //------------------------------------------------------------------
73 // Check if a given Process
74 //------------------------------------------------------------------
76 CanDebug (lldb_private::Target &target,
77 bool plugin_specified_by_name);
79 virtual lldb_private::CommandObject *
80 GetPluginCommandObject();
82 //------------------------------------------------------------------
83 // Creating a new process, or attaching to an existing one
84 //------------------------------------------------------------------
85 virtual lldb_private::Error
86 WillLaunch (lldb_private::Module* module);
88 virtual lldb_private::Error
89 DoLaunch (lldb_private::Module *exe_module,
90 lldb_private::ProcessLaunchInfo &launch_info);
95 virtual lldb_private::Error
96 WillAttachToProcessWithID (lldb::pid_t pid);
98 virtual lldb_private::Error
99 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
101 virtual lldb_private::Error
102 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
105 WillLaunchOrAttach ();
107 virtual lldb_private::Error
108 DoAttachToProcessWithID (lldb::pid_t pid);
110 virtual lldb_private::Error
111 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
113 virtual lldb_private::Error
114 DoAttachToProcessWithName (const char *process_name,
115 const lldb_private::ProcessAttachInfo &attach_info);
118 DidAttach (lldb_private::ArchSpec &process_arch);
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 &
226 virtual lldb_private::Error
227 SendEventData(const char *data);
229 //----------------------------------------------------------------------
230 // Override SetExitStatus so we can disconnect from the remote GDB server
231 //----------------------------------------------------------------------
233 SetExitStatus (int exit_status, const char *cstr);
236 SetUserSpecifiedMaxMemoryTransferSize (uint64_t user_specified_max);
239 friend class ThreadGDBRemote;
240 friend class GDBRemoteCommunicationClient;
241 friend class GDBRemoteRegisterContext;
243 //----------------------------------------------------------------------
245 //----------------------------------------------------------------------
247 IsRunning ( lldb::StateType state )
249 return state == lldb::eStateRunning || IsStepping(state);
253 IsStepping ( lldb::StateType state)
255 return state == lldb::eStateStepping;
258 CanResume ( lldb::StateType state)
260 return state == lldb::eStateStopped;
264 HasExited (lldb::StateType state)
266 return state == lldb::eStateExited;
270 ProcessIDIsValid ( ) const;
275 lldb_private::Flags &
281 const lldb_private::Flags &
288 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
289 lldb_private::ThreadList &new_thread_list);
292 LaunchAndConnectToDebugserver (const lldb_private::ProcessInfo &process_info);
295 KillDebugserverProcess ();
298 BuildDynamicRegisterInfo (bool force);
301 SetLastStopPacket (const StringExtractorGDBRemote &response);
304 ParsePythonTargetDefinition(const lldb_private::FileSpec &target_definition_fspec);
307 ParseRegisters(lldb_private::ScriptInterpreterObject *registers_array);
309 const lldb::DataBufferSP
310 GetAuxvData() override;
312 lldb_private::StructuredData::ObjectSP
313 GetExtendedInfoForThread (lldb::tid_t tid);
318 //------------------------------------------------------------------
319 /// Broadcaster event bits definitions.
320 //------------------------------------------------------------------
323 eBroadcastBitAsyncContinue = (1 << 0),
324 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
325 eBroadcastBitAsyncThreadDidExit = (1 << 2)
328 typedef enum AsyncThreadState
330 eAsyncThreadNotStarted,
335 lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
336 GDBRemoteCommunicationClient m_gdb_comm;
337 lldb::pid_t m_debugserver_pid;
338 StringExtractorGDBRemote m_last_stop_packet;
339 lldb_private::Mutex m_last_stop_packet_mutex;
340 GDBRemoteDynamicRegisterInfo m_register_info;
341 lldb_private::Broadcaster m_async_broadcaster;
342 lldb::thread_t m_async_thread;
343 AsyncThreadState m_async_thread_state;
344 lldb_private::Mutex m_async_thread_state_mutex;
345 typedef std::vector<lldb::tid_t> tid_collection;
346 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
347 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
348 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
349 tid_collection m_continue_c_tids; // 'c' for continue
350 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
351 tid_collection m_continue_s_tids; // 's' for step
352 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
353 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
354 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote gdb stub can handle
355 MMapMap m_addr_to_mmap_size;
356 lldb::BreakpointSP m_thread_create_bp_sp;
357 bool m_waiting_for_attach;
358 bool m_destroy_tried_resuming;
359 lldb::CommandObjectSP m_command_sp;
360 int64_t m_breakpoint_pc_offset;
368 static lldb::thread_result_t
369 AsyncThread (void *arg);
372 MonitorDebugserverProcess (void *callback_baton,
379 SetThreadStopInfo (StringExtractor& stop_packet);
382 ClearThreadIDList ();
385 UpdateThreadIDList ();
388 DidLaunchOrAttach (lldb_private::ArchSpec& process_arch);
391 ConnectToDebugserver (const char *host_port);
394 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
395 std::string &dispatch_queue_name);
397 lldb_private::DynamicLoader *
401 //------------------------------------------------------------------
402 // For ProcessGDBRemote only
403 //------------------------------------------------------------------
405 NewThreadNotifyBreakpointHit (void *baton,
406 lldb_private::StoppointCallbackContext *context,
407 lldb::user_id_t break_id,
408 lldb::user_id_t break_loc_id);
410 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
414 #endif // liblldb_ProcessGDBRemote_h_