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/Host/HostThread.h"
29 #include "lldb/lldb-private-forward.h"
30 #include "lldb/Target/Process.h"
31 #include "lldb/Target/Thread.h"
33 #include "GDBRemoteCommunicationClient.h"
34 #include "Utility/StringExtractor.h"
35 #include "GDBRemoteRegisterContext.h"
37 class ThreadGDBRemote;
39 class ProcessGDBRemote : public lldb_private::Process
42 //------------------------------------------------------------------
43 // Constructors and Destructors
44 //------------------------------------------------------------------
45 static lldb::ProcessSP
46 CreateInstance (lldb_private::Target& target,
47 lldb_private::Listener &listener,
48 const lldb_private::FileSpec *crash_file_path);
54 DebuggerInitialize (lldb_private::Debugger &debugger);
59 static lldb_private::ConstString
60 GetPluginNameStatic();
63 GetPluginDescriptionStatic();
65 //------------------------------------------------------------------
66 // Constructors and Destructors
67 //------------------------------------------------------------------
68 ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener);
73 //------------------------------------------------------------------
74 // Check if a given Process
75 //------------------------------------------------------------------
77 CanDebug (lldb_private::Target &target,
78 bool plugin_specified_by_name) override;
80 virtual lldb_private::CommandObject *
81 GetPluginCommandObject() override;
83 //------------------------------------------------------------------
84 // Creating a new process, or attaching to an existing one
85 //------------------------------------------------------------------
86 virtual lldb_private::Error
87 WillLaunch (lldb_private::Module* module) override;
89 virtual lldb_private::Error
90 DoLaunch (lldb_private::Module *exe_module,
91 lldb_private::ProcessLaunchInfo &launch_info) override;
94 DidLaunch () override;
96 virtual lldb_private::Error
97 WillAttachToProcessWithID (lldb::pid_t pid) override;
99 virtual lldb_private::Error
100 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) override;
102 virtual lldb_private::Error
103 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url) override;
106 WillLaunchOrAttach ();
108 virtual lldb_private::Error
109 DoAttachToProcessWithID (lldb::pid_t pid) override;
111 virtual lldb_private::Error
112 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override;
114 virtual lldb_private::Error
115 DoAttachToProcessWithName (const char *process_name,
116 const lldb_private::ProcessAttachInfo &attach_info) override;
119 DidAttach (lldb_private::ArchSpec &process_arch) override;
121 //------------------------------------------------------------------
122 // PluginInterface protocol
123 //------------------------------------------------------------------
124 virtual lldb_private::ConstString
125 GetPluginName() override;
128 GetPluginVersion() override;
130 //------------------------------------------------------------------
132 //------------------------------------------------------------------
133 virtual lldb_private::Error
134 WillResume () override;
136 virtual lldb_private::Error
137 DoResume () override;
139 virtual lldb_private::Error
140 DoHalt (bool &caused_stop) override;
142 virtual lldb_private::Error
143 DoDetach (bool keep_stopped) override;
146 DetachRequiresHalt() override { return true; }
148 virtual lldb_private::Error
149 DoSignal (int signal) override;
151 virtual lldb_private::Error
152 DoDestroy () override;
155 RefreshStateAfterStop() override;
157 //------------------------------------------------------------------
159 //------------------------------------------------------------------
164 GetImageInfoAddress() override;
166 //------------------------------------------------------------------
168 //------------------------------------------------------------------
170 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error) override;
173 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error) override;
176 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error) override;
178 virtual lldb_private::Error
179 GetMemoryRegionInfo (lldb::addr_t load_addr,
180 lldb_private::MemoryRegionInfo ®ion_info) override;
182 virtual lldb_private::Error
183 DoDeallocateMemory (lldb::addr_t ptr) override;
185 //------------------------------------------------------------------
187 //------------------------------------------------------------------
189 PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error) override;
191 //----------------------------------------------------------------------
192 // Process Breakpoints
193 //----------------------------------------------------------------------
194 virtual lldb_private::Error
195 EnableBreakpointSite (lldb_private::BreakpointSite *bp_site) override;
197 virtual lldb_private::Error
198 DisableBreakpointSite (lldb_private::BreakpointSite *bp_site) override;
200 //----------------------------------------------------------------------
201 // Process Watchpoints
202 //----------------------------------------------------------------------
203 virtual lldb_private::Error
204 EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true) override;
206 virtual lldb_private::Error
207 DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true) override;
209 virtual lldb_private::Error
210 GetWatchpointSupportInfo (uint32_t &num) override;
212 virtual lldb_private::Error
213 GetWatchpointSupportInfo (uint32_t &num, bool& after) override;
216 StartNoticingNewThreads() override;
219 StopNoticingNewThreads() override;
221 GDBRemoteCommunicationClient &
227 virtual lldb_private::Error
228 SendEventData(const char *data) override;
230 //----------------------------------------------------------------------
231 // Override SetExitStatus so we can disconnect from the remote GDB server
232 //----------------------------------------------------------------------
234 SetExitStatus (int exit_status, const char *cstr) override;
237 SetUserSpecifiedMaxMemoryTransferSize (uint64_t user_specified_max);
240 friend class ThreadGDBRemote;
241 friend class GDBRemoteCommunicationClient;
242 friend class GDBRemoteRegisterContext;
244 //----------------------------------------------------------------------
246 //----------------------------------------------------------------------
248 IsRunning ( lldb::StateType state )
250 return state == lldb::eStateRunning || IsStepping(state);
254 IsStepping ( lldb::StateType state)
256 return state == lldb::eStateStepping;
259 CanResume ( lldb::StateType state)
261 return state == lldb::eStateStopped;
265 HasExited (lldb::StateType state)
267 return state == lldb::eStateExited;
271 ProcessIDIsValid ( ) const;
276 lldb_private::Flags &
282 const lldb_private::Flags &
289 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
290 lldb_private::ThreadList &new_thread_list) override;
293 LaunchAndConnectToDebugserver (const lldb_private::ProcessInfo &process_info);
296 KillDebugserverProcess ();
299 BuildDynamicRegisterInfo (bool force);
302 SetLastStopPacket (const StringExtractorGDBRemote &response);
305 ParsePythonTargetDefinition(const lldb_private::FileSpec &target_definition_fspec);
308 ParseRegisters(lldb_private::ScriptInterpreterObject *registers_array);
310 const lldb::DataBufferSP
311 GetAuxvData() override;
313 lldb_private::StructuredData::ObjectSP
314 GetExtendedInfoForThread (lldb::tid_t tid);
319 //------------------------------------------------------------------
320 /// Broadcaster event bits definitions.
321 //------------------------------------------------------------------
324 eBroadcastBitAsyncContinue = (1 << 0),
325 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
326 eBroadcastBitAsyncThreadDidExit = (1 << 2)
329 lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
330 GDBRemoteCommunicationClient m_gdb_comm;
331 std::atomic<lldb::pid_t> m_debugserver_pid;
332 StringExtractorGDBRemote m_last_stop_packet;
333 lldb_private::Mutex m_last_stop_packet_mutex;
334 GDBRemoteDynamicRegisterInfo m_register_info;
335 lldb_private::Broadcaster m_async_broadcaster;
336 lldb_private::HostThread m_async_thread;
337 lldb_private::Mutex m_async_thread_state_mutex;
338 typedef std::vector<lldb::tid_t> tid_collection;
339 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
340 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
341 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
342 tid_collection m_continue_c_tids; // 'c' for continue
343 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
344 tid_collection m_continue_s_tids; // 's' for step
345 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
346 uint64_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
347 uint64_t m_remote_stub_max_memory_size; // The maximum memory size the remote gdb stub can handle
348 MMapMap m_addr_to_mmap_size;
349 lldb::BreakpointSP m_thread_create_bp_sp;
350 bool m_waiting_for_attach;
351 bool m_destroy_tried_resuming;
352 lldb::CommandObjectSP m_command_sp;
353 int64_t m_breakpoint_pc_offset;
361 static lldb::thread_result_t
362 AsyncThread (void *arg);
365 MonitorDebugserverProcess (void *callback_baton,
372 SetThreadStopInfo (StringExtractor& stop_packet);
375 ClearThreadIDList ();
378 UpdateThreadIDList ();
381 DidLaunchOrAttach (lldb_private::ArchSpec& process_arch);
384 ConnectToDebugserver (const char *host_port);
387 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
388 std::string &dispatch_queue_name);
390 lldb_private::DynamicLoader *
391 GetDynamicLoader () override;
394 //------------------------------------------------------------------
395 // For ProcessGDBRemote only
396 //------------------------------------------------------------------
398 NewThreadNotifyBreakpointHit (void *baton,
399 lldb_private::StoppointCallbackContext *context,
400 lldb::user_id_t break_id,
401 lldb::user_id_t break_loc_id);
403 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
407 #endif // liblldb_ProcessGDBRemote_h_