blob: 15ccb34ef3a3c91d9109a3864798ab756b2ba21d [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Claytonc1f45872011-02-12 06:28:37 +000017#include <vector>
Chris Lattner24943d22010-06-08 16:52:24 +000018
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 Ingham7508e732010-08-09 23:31:02 +000025#include "lldb/Core/StringList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Core/ThreadSafeValue.h"
27#include "lldb/Target/Process.h"
28#include "lldb/Target/Thread.h"
29
Greg Clayton61d043b2011-03-22 04:00:09 +000030#include "GDBRemoteCommunicationClient.h"
Greg Clayton54e7afa2010-07-09 20:39:50 +000031#include "Utility/StringExtractor.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "GDBRemoteRegisterContext.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033
34class ThreadGDBRemote;
35
36class ProcessGDBRemote : public lldb_private::Process
37{
38public:
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 Clayton8d2ea282011-07-17 20:36:25 +000069 CanDebug (lldb_private::Target &target,
70 bool plugin_specified_by_name);
Chris Lattner24943d22010-06-08 16:52:24 +000071
Greg Claytone4b9c1f2011-03-08 22:40:15 +000072// virtual uint32_t
73// ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids);
Jim Ingham7508e732010-08-09 23:31:02 +000074
Chris Lattner24943d22010-06-08 16:52:24 +000075 //------------------------------------------------------------------
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 Clayton36bc5ea2011-11-03 21:22:33 +000082 DoLaunch (lldb_private::Module *exe_module,
83 const lldb_private::ProcessLaunchInfo &launch_info);
Chris Lattner24943d22010-06-08 16:52:24 +000084
85 virtual void
86 DidLaunch ();
87
88 virtual lldb_private::Error
Greg Clayton20d338f2010-11-18 05:57:03 +000089 WillAttachToProcessWithID (lldb::pid_t pid);
Chris Lattner24943d22010-06-08 16:52:24 +000090
91 virtual lldb_private::Error
Greg Clayton20d338f2010-11-18 05:57:03 +000092 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
Chris Lattner24943d22010-06-08 16:52:24 +000093
Greg Claytone71e2582011-02-04 01:58:07 +000094 virtual lldb_private::Error
95 DoConnectRemote (const char *remote_url);
96
Chris Lattner24943d22010-06-08 16:52:24 +000097 lldb_private::Error
98 WillLaunchOrAttach ();
99
100 virtual lldb_private::Error
Greg Clayton54e7afa2010-07-09 20:39:50 +0000101 DoAttachToProcessWithID (lldb::pid_t pid);
Chris Lattner24943d22010-06-08 16:52:24 +0000102
103 virtual lldb_private::Error
Greg Clayton54e7afa2010-07-09 20:39:50 +0000104 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch);
Chris Lattner24943d22010-06-08 16:52:24 +0000105
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 Lattner24943d22010-06-08 16:52:24 +0000121 //------------------------------------------------------------------
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 Ingham3ae449a2010-11-17 02:32:00 +0000131 DoHalt (bool &caused_stop);
Chris Lattner24943d22010-06-08 16:52:24 +0000132
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
Greg Claytona9385532011-11-18 07:03:08 +0000170 GetMemoryRegionInfo (lldb::addr_t load_addr,
171 lldb_private::MemoryRegionInfo &region_info);
172
173 virtual lldb_private::Error
Chris Lattner24943d22010-06-08 16:52:24 +0000174 DoDeallocateMemory (lldb::addr_t ptr);
175
176 //------------------------------------------------------------------
177 // Process STDIO
178 //------------------------------------------------------------------
179 virtual size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000180 PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error);
181
182 //----------------------------------------------------------------------
183 // Process Breakpoints
184 //----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +0000185 virtual lldb_private::Error
186 EnableBreakpoint (lldb_private::BreakpointSite *bp_site);
187
188 virtual lldb_private::Error
189 DisableBreakpoint (lldb_private::BreakpointSite *bp_site);
190
191 //----------------------------------------------------------------------
192 // Process Watchpoints
193 //----------------------------------------------------------------------
194 virtual lldb_private::Error
Johnny Chenecd4feb2011-10-14 00:42:25 +0000195 EnableWatchpoint (lldb_private::Watchpoint *wp);
Chris Lattner24943d22010-06-08 16:52:24 +0000196
197 virtual lldb_private::Error
Johnny Chenecd4feb2011-10-14 00:42:25 +0000198 DisableWatchpoint (lldb_private::Watchpoint *wp);
Chris Lattner24943d22010-06-08 16:52:24 +0000199
Jim Ingham55e01d82011-01-22 01:33:44 +0000200 virtual bool
201 StartNoticingNewThreads();
202
203 virtual bool
204 StopNoticingNewThreads();
Chris Lattner24943d22010-06-08 16:52:24 +0000205
206protected:
207 friend class ThreadGDBRemote;
Greg Clayton61d043b2011-03-22 04:00:09 +0000208 friend class GDBRemoteCommunicationClient;
Chris Lattner24943d22010-06-08 16:52:24 +0000209 friend class GDBRemoteRegisterContext;
210
Chris Lattner24943d22010-06-08 16:52:24 +0000211 //----------------------------------------------------------------------
212 // Accessors
213 //----------------------------------------------------------------------
214 bool
215 IsRunning ( lldb::StateType state )
216 {
217 return state == lldb::eStateRunning || IsStepping(state);
218 }
219
220 bool
221 IsStepping ( lldb::StateType state)
222 {
223 return state == lldb::eStateStepping;
224 }
225 bool
226 CanResume ( lldb::StateType state)
227 {
228 return state == lldb::eStateStopped;
229 }
230
231 bool
232 HasExited (lldb::StateType state)
233 {
234 return state == lldb::eStateExited;
235 }
236
237 bool
238 ProcessIDIsValid ( ) const;
239
Chris Lattner24943d22010-06-08 16:52:24 +0000240 void
241 Clear ( );
242
243 lldb_private::Flags &
244 GetFlags ()
245 {
246 return m_flags;
247 }
248
249 const lldb_private::Flags &
250 GetFlags () const
251 {
252 return m_flags;
253 }
254
255 uint32_t
Greg Clayton37f962e2011-08-22 02:49:39 +0000256 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
257 lldb_private::ThreadList &new_thread_list);
Chris Lattner24943d22010-06-08 16:52:24 +0000258
259 lldb_private::Error
Greg Claytonb72d0f02011-04-12 05:54:46 +0000260 StartDebugserverProcess (const char *debugserver_url);
Chris Lattner24943d22010-06-08 16:52:24 +0000261
262 void
263 KillDebugserverProcess ();
264
265 void
Greg Clayton7e2f91c2011-01-29 07:10:55 +0000266 BuildDynamicRegisterInfo (bool force);
Chris Lattner24943d22010-06-08 16:52:24 +0000267
Greg Clayton61d043b2011-03-22 04:00:09 +0000268 GDBRemoteCommunicationClient &
Chris Lattner24943d22010-06-08 16:52:24 +0000269 GetGDBRemote()
270 {
271 return m_gdb_comm;
272 }
273
274 //------------------------------------------------------------------
275 /// Broadcaster event bits definitions.
276 //------------------------------------------------------------------
277 enum
278 {
279 eBroadcastBitAsyncContinue = (1 << 0),
280 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
281 };
282
Chris Lattner24943d22010-06-08 16:52:24 +0000283 lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
Greg Clayton61d043b2011-03-22 04:00:09 +0000284 GDBRemoteCommunicationClient m_gdb_comm;
Chris Lattner24943d22010-06-08 16:52:24 +0000285 lldb::pid_t m_debugserver_pid;
Greg Clayton261a18b2011-06-02 22:22:38 +0000286 StringExtractorGDBRemote m_last_stop_packet;
Chris Lattner24943d22010-06-08 16:52:24 +0000287 GDBRemoteDynamicRegisterInfo m_register_info;
288 lldb_private::Broadcaster m_async_broadcaster;
289 lldb::thread_t m_async_thread;
Greg Claytonc1f45872011-02-12 06:28:37 +0000290 typedef std::vector<lldb::tid_t> tid_collection;
291 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
Greg Clayton2f085c62011-05-15 01:25:55 +0000292 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
Greg Claytonc1f45872011-02-12 06:28:37 +0000293 tid_collection m_continue_c_tids; // 'c' for continue
294 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
295 tid_collection m_continue_s_tids; // 's' for step
296 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
Chris Lattner24943d22010-06-08 16:52:24 +0000297 lldb::addr_t m_dispatch_queue_offsets_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000298 size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
Chris Lattner24943d22010-06-08 16:52:24 +0000299 bool m_waiting_for_attach;
Jim Ingham55e01d82011-01-22 01:33:44 +0000300 std::vector<lldb::user_id_t> m_thread_observation_bps;
Greg Clayton2f085c62011-05-15 01:25:55 +0000301 MMapMap m_addr_to_mmap_size;
Chris Lattner24943d22010-06-08 16:52:24 +0000302 bool
303 StartAsyncThread ();
304
305 void
306 StopAsyncThread ();
307
308 static void *
309 AsyncThread (void *arg);
310
311 static bool
312 MonitorDebugserverProcess (void *callback_baton,
313 lldb::pid_t pid,
Greg Clayton1c4642c2011-11-16 05:37:56 +0000314 bool exited,
315 int signo,
316 int exit_status);
Chris Lattner24943d22010-06-08 16:52:24 +0000317
318 lldb::StateType
319 SetThreadStopInfo (StringExtractor& stop_packet);
320
321 void
322 DidLaunchOrAttach ();
323
324 lldb_private::Error
325 ConnectToDebugserver (const char *host_port);
326
327 const char *
328 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
329 std::string &dispatch_queue_name);
330
331 static size_t
332 AttachInputReaderCallback (void *baton,
333 lldb_private::InputReader *reader,
334 lldb::InputReaderAction notification,
335 const char *bytes,
336 size_t bytes_len);
337
Greg Clayton72e1c782011-01-22 23:43:18 +0000338 lldb_private::Error
339 InterruptIfRunning (bool discard_thread_plans,
340 bool catch_stop_event,
Greg Clayton72e1c782011-01-22 23:43:18 +0000341 lldb::EventSP &stop_event_sp);
342
Chris Lattner24943d22010-06-08 16:52:24 +0000343private:
344 //------------------------------------------------------------------
345 // For ProcessGDBRemote only
346 //------------------------------------------------------------------
Jim Ingham55e01d82011-01-22 01:33:44 +0000347 static bool
348 NewThreadNotifyBreakpointHit (void *baton,
349 lldb_private::StoppointCallbackContext *context,
350 lldb::user_id_t break_id,
351 lldb::user_id_t break_loc_id);
352
Chris Lattner24943d22010-06-08 16:52:24 +0000353 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
354
Chris Lattner24943d22010-06-08 16:52:24 +0000355};
356
357#endif // liblldb_ProcessGDBRemote_h_