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/ThreadSafeValue.h"
27 #include "lldb/Target/Process.h"
28 #include "lldb/Target/Thread.h"
30 #include "GDBRemoteCommunicationClient.h"
31 #include "Utility/StringExtractor.h"
32 #include "GDBRemoteRegisterContext.h"
34 class ThreadGDBRemote;
36 class ProcessGDBRemote : public lldb_private::Process
39 //------------------------------------------------------------------
40 // Constructors and Destructors
41 //------------------------------------------------------------------
42 static lldb::ProcessSP
43 CreateInstance (lldb_private::Target& target,
44 lldb_private::Listener &listener,
45 const lldb_private::FileSpec *crash_file_path);
51 DebuggerInitialize (lldb_private::Debugger &debugger);
56 static lldb_private::ConstString
57 GetPluginNameStatic();
60 GetPluginDescriptionStatic();
62 //------------------------------------------------------------------
63 // Constructors and Destructors
64 //------------------------------------------------------------------
65 ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener);
70 //------------------------------------------------------------------
71 // Check if a given Process
72 //------------------------------------------------------------------
74 CanDebug (lldb_private::Target &target,
75 bool plugin_specified_by_name);
77 virtual lldb_private::CommandObject *
78 GetPluginCommandObject();
80 //------------------------------------------------------------------
81 // Creating a new process, or attaching to an existing one
82 //------------------------------------------------------------------
83 virtual lldb_private::Error
84 WillLaunch (lldb_private::Module* module);
86 virtual lldb_private::Error
87 DoLaunch (lldb_private::Module *exe_module,
88 lldb_private::ProcessLaunchInfo &launch_info);
93 virtual lldb_private::Error
94 WillAttachToProcessWithID (lldb::pid_t pid);
96 virtual lldb_private::Error
97 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
99 virtual lldb_private::Error
100 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
103 WillLaunchOrAttach ();
105 virtual lldb_private::Error
106 DoAttachToProcessWithID (lldb::pid_t pid);
108 virtual lldb_private::Error
109 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
111 virtual lldb_private::Error
112 DoAttachToProcessWithName (const char *process_name,
113 const lldb_private::ProcessAttachInfo &attach_info);
118 //------------------------------------------------------------------
119 // PluginInterface protocol
120 //------------------------------------------------------------------
121 virtual lldb_private::ConstString
127 //------------------------------------------------------------------
129 //------------------------------------------------------------------
130 virtual lldb_private::Error
133 virtual lldb_private::Error
136 virtual lldb_private::Error
137 DoHalt (bool &caused_stop);
139 virtual lldb_private::Error
140 DoDetach (bool keep_stopped);
143 DetachRequiresHalt() { return true; }
145 virtual lldb_private::Error
146 DoSignal (int signal);
148 virtual lldb_private::Error
152 RefreshStateAfterStop();
154 //------------------------------------------------------------------
156 //------------------------------------------------------------------
161 GetImageInfoAddress();
163 //------------------------------------------------------------------
165 //------------------------------------------------------------------
167 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
170 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
173 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
175 virtual lldb_private::Error
176 GetMemoryRegionInfo (lldb::addr_t load_addr,
177 lldb_private::MemoryRegionInfo ®ion_info);
179 virtual lldb_private::Error
180 DoDeallocateMemory (lldb::addr_t ptr);
182 //------------------------------------------------------------------
184 //------------------------------------------------------------------
186 PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error);
188 //----------------------------------------------------------------------
189 // Process Breakpoints
190 //----------------------------------------------------------------------
191 virtual lldb_private::Error
192 EnableBreakpointSite (lldb_private::BreakpointSite *bp_site);
194 virtual lldb_private::Error
195 DisableBreakpointSite (lldb_private::BreakpointSite *bp_site);
197 //----------------------------------------------------------------------
198 // Process Watchpoints
199 //----------------------------------------------------------------------
200 virtual lldb_private::Error
201 EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
203 virtual lldb_private::Error
204 DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
206 virtual lldb_private::Error
207 GetWatchpointSupportInfo (uint32_t &num);
209 virtual lldb_private::Error
210 GetWatchpointSupportInfo (uint32_t &num, bool& after);
213 StartNoticingNewThreads();
216 StopNoticingNewThreads();
218 GDBRemoteCommunicationClient &
224 //----------------------------------------------------------------------
225 // Override SetExitStatus so we can disconnect from the remote GDB server
226 //----------------------------------------------------------------------
228 SetExitStatus (int exit_status, const char *cstr);
232 friend class ThreadGDBRemote;
233 friend class GDBRemoteCommunicationClient;
234 friend class GDBRemoteRegisterContext;
236 //----------------------------------------------------------------------
238 //----------------------------------------------------------------------
240 IsRunning ( lldb::StateType state )
242 return state == lldb::eStateRunning || IsStepping(state);
246 IsStepping ( lldb::StateType state)
248 return state == lldb::eStateStepping;
251 CanResume ( lldb::StateType state)
253 return state == lldb::eStateStopped;
257 HasExited (lldb::StateType state)
259 return state == lldb::eStateExited;
263 ProcessIDIsValid ( ) const;
268 lldb_private::Flags &
274 const lldb_private::Flags &
281 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
282 lldb_private::ThreadList &new_thread_list);
285 LaunchAndConnectToDebugserver (const lldb_private::ProcessInfo &process_info);
288 KillDebugserverProcess ();
291 BuildDynamicRegisterInfo (bool force);
294 SetLastStopPacket (const StringExtractorGDBRemote &response);
297 ParsePythonTargetDefinition(const lldb_private::FileSpec &target_definition_fspec);
300 ParseRegisters(lldb_private::ScriptInterpreterObject *registers_array);
302 //------------------------------------------------------------------
303 /// Broadcaster event bits definitions.
304 //------------------------------------------------------------------
307 eBroadcastBitAsyncContinue = (1 << 0),
308 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
309 eBroadcastBitAsyncThreadDidExit = (1 << 2)
312 typedef enum AsyncThreadState
314 eAsyncThreadNotStarted,
319 lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
320 GDBRemoteCommunicationClient m_gdb_comm;
321 lldb::pid_t m_debugserver_pid;
322 StringExtractorGDBRemote m_last_stop_packet;
323 lldb_private::Mutex m_last_stop_packet_mutex;
324 GDBRemoteDynamicRegisterInfo m_register_info;
325 lldb_private::Broadcaster m_async_broadcaster;
326 lldb::thread_t m_async_thread;
327 AsyncThreadState m_async_thread_state;
328 lldb_private::Mutex m_async_thread_state_mutex;
329 typedef std::vector<lldb::tid_t> tid_collection;
330 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
331 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
332 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
333 tid_collection m_continue_c_tids; // 'c' for continue
334 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
335 tid_collection m_continue_s_tids; // 's' for step
336 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
337 size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
338 MMapMap m_addr_to_mmap_size;
339 lldb::BreakpointSP m_thread_create_bp_sp;
340 bool m_waiting_for_attach;
341 bool m_destroy_tried_resuming;
342 lldb::CommandObjectSP m_command_sp;
343 int64_t m_breakpoint_pc_offset;
351 static lldb::thread_result_t
352 AsyncThread (void *arg);
355 MonitorDebugserverProcess (void *callback_baton,
362 SetThreadStopInfo (StringExtractor& stop_packet);
365 ClearThreadIDList ();
368 UpdateThreadIDList ();
371 DidLaunchOrAttach ();
374 ConnectToDebugserver (const char *host_port);
377 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
378 std::string &dispatch_queue_name);
380 lldb_private::DynamicLoader *
384 //------------------------------------------------------------------
385 // For ProcessGDBRemote only
386 //------------------------------------------------------------------
388 NewThreadNotifyBreakpointHit (void *baton,
389 lldb_private::StoppointCallbackContext *context,
390 lldb::user_id_t break_id,
391 lldb::user_id_t break_loc_id);
393 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
397 #endif // liblldb_ProcessGDBRemote_h_