blob: 5c642d44597a203cfe5ae6fa57366299f4d978bc [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 //------------------------------------------------------------------
Greg Clayton46c9a352012-02-09 06:16:32 +000042 static lldb::ProcessSP
43 CreateInstance (lldb_private::Target& target,
44 lldb_private::Listener &listener,
45 const lldb_private::FileSpec *crash_file_path);
Chris Lattner24943d22010-06-08 16:52:24 +000046
47 static void
48 Initialize();
49
50 static void
51 Terminate();
52
53 static const char *
54 GetPluginNameStatic();
55
56 static const char *
57 GetPluginDescriptionStatic();
58
59 //------------------------------------------------------------------
60 // Constructors and Destructors
61 //------------------------------------------------------------------
62 ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener);
63
64 virtual
65 ~ProcessGDBRemote();
66
67 //------------------------------------------------------------------
68 // Check if a given Process
69 //------------------------------------------------------------------
70 virtual bool
Greg Clayton8d2ea282011-07-17 20:36:25 +000071 CanDebug (lldb_private::Target &target,
72 bool plugin_specified_by_name);
Chris Lattner24943d22010-06-08 16:52:24 +000073
Greg Clayton13193d52012-10-13 02:07:45 +000074 virtual lldb_private::CommandObject *
75 GetPluginCommandObject();
Jim Ingham7508e732010-08-09 23:31:02 +000076
Chris Lattner24943d22010-06-08 16:52:24 +000077 //------------------------------------------------------------------
78 // Creating a new process, or attaching to an existing one
79 //------------------------------------------------------------------
80 virtual lldb_private::Error
81 WillLaunch (lldb_private::Module* module);
82
83 virtual lldb_private::Error
Greg Clayton36bc5ea2011-11-03 21:22:33 +000084 DoLaunch (lldb_private::Module *exe_module,
85 const lldb_private::ProcessLaunchInfo &launch_info);
Chris Lattner24943d22010-06-08 16:52:24 +000086
87 virtual void
88 DidLaunch ();
89
90 virtual lldb_private::Error
Greg Clayton20d338f2010-11-18 05:57:03 +000091 WillAttachToProcessWithID (lldb::pid_t pid);
Chris Lattner24943d22010-06-08 16:52:24 +000092
93 virtual lldb_private::Error
Greg Clayton20d338f2010-11-18 05:57:03 +000094 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
Chris Lattner24943d22010-06-08 16:52:24 +000095
Greg Claytone71e2582011-02-04 01:58:07 +000096 virtual lldb_private::Error
Jason Molendafac2e622012-09-29 04:02:01 +000097 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
Greg Claytone71e2582011-02-04 01:58:07 +000098
Chris Lattner24943d22010-06-08 16:52:24 +000099 lldb_private::Error
100 WillLaunchOrAttach ();
101
102 virtual lldb_private::Error
Greg Clayton54e7afa2010-07-09 20:39:50 +0000103 DoAttachToProcessWithID (lldb::pid_t pid);
Chris Lattner24943d22010-06-08 16:52:24 +0000104
105 virtual lldb_private::Error
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000106 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
107
108 virtual lldb_private::Error
109 DoAttachToProcessWithName (const char *process_name,
110 bool wait_for_launch,
111 const lldb_private::ProcessAttachInfo &attach_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000112
113 virtual void
114 DidAttach ();
115
116 //------------------------------------------------------------------
117 // PluginInterface protocol
118 //------------------------------------------------------------------
119 virtual const char *
120 GetPluginName();
121
122 virtual const char *
123 GetShortPluginName();
124
125 virtual uint32_t
126 GetPluginVersion();
127
Chris Lattner24943d22010-06-08 16:52:24 +0000128 //------------------------------------------------------------------
129 // Process Control
130 //------------------------------------------------------------------
131 virtual lldb_private::Error
132 WillResume ();
133
134 virtual lldb_private::Error
135 DoResume ();
136
137 virtual lldb_private::Error
Jim Ingham3ae449a2010-11-17 02:32:00 +0000138 DoHalt (bool &caused_stop);
Chris Lattner24943d22010-06-08 16:52:24 +0000139
140 virtual lldb_private::Error
141 WillDetach ();
142
143 virtual lldb_private::Error
144 DoDetach ();
145
146 virtual lldb_private::Error
147 DoSignal (int signal);
148
149 virtual lldb_private::Error
150 DoDestroy ();
151
152 virtual void
153 RefreshStateAfterStop();
154
155 //------------------------------------------------------------------
156 // Process Queries
157 //------------------------------------------------------------------
158 virtual bool
159 IsAlive ();
160
161 virtual lldb::addr_t
162 GetImageInfoAddress();
163
164 //------------------------------------------------------------------
165 // Process Memory
166 //------------------------------------------------------------------
167 virtual size_t
168 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
169
170 virtual size_t
171 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
172
173 virtual lldb::addr_t
174 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
175
176 virtual lldb_private::Error
Greg Claytona9385532011-11-18 07:03:08 +0000177 GetMemoryRegionInfo (lldb::addr_t load_addr,
178 lldb_private::MemoryRegionInfo &region_info);
179
180 virtual lldb_private::Error
Chris Lattner24943d22010-06-08 16:52:24 +0000181 DoDeallocateMemory (lldb::addr_t ptr);
182
183 //------------------------------------------------------------------
184 // Process STDIO
185 //------------------------------------------------------------------
186 virtual size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000187 PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error);
188
189 //----------------------------------------------------------------------
190 // Process Breakpoints
191 //----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +0000192 virtual lldb_private::Error
193 EnableBreakpoint (lldb_private::BreakpointSite *bp_site);
194
195 virtual lldb_private::Error
196 DisableBreakpoint (lldb_private::BreakpointSite *bp_site);
197
198 //----------------------------------------------------------------------
199 // Process Watchpoints
200 //----------------------------------------------------------------------
201 virtual lldb_private::Error
Johnny Chenecd4feb2011-10-14 00:42:25 +0000202 EnableWatchpoint (lldb_private::Watchpoint *wp);
Chris Lattner24943d22010-06-08 16:52:24 +0000203
204 virtual lldb_private::Error
Johnny Chenecd4feb2011-10-14 00:42:25 +0000205 DisableWatchpoint (lldb_private::Watchpoint *wp);
Chris Lattner24943d22010-06-08 16:52:24 +0000206
Johnny Chen7cbdcfb2012-05-23 21:09:52 +0000207 virtual lldb_private::Error
208 GetWatchpointSupportInfo (uint32_t &num);
209
Enrico Granata7de2a3b2012-07-13 23:18:48 +0000210 virtual lldb_private::Error
211 GetWatchpointSupportInfo (uint32_t &num, bool& after);
212
Jim Ingham55e01d82011-01-22 01:33:44 +0000213 virtual bool
214 StartNoticingNewThreads();
215
216 virtual bool
217 StopNoticingNewThreads();
Chris Lattner24943d22010-06-08 16:52:24 +0000218
Greg Clayton451fa822012-04-09 22:46:21 +0000219 GDBRemoteCommunicationClient &
220 GetGDBRemote()
221 {
222 return m_gdb_comm;
223 }
224
Chris Lattner24943d22010-06-08 16:52:24 +0000225protected:
226 friend class ThreadGDBRemote;
Greg Clayton61d043b2011-03-22 04:00:09 +0000227 friend class GDBRemoteCommunicationClient;
Chris Lattner24943d22010-06-08 16:52:24 +0000228 friend class GDBRemoteRegisterContext;
229
Chris Lattner24943d22010-06-08 16:52:24 +0000230 //----------------------------------------------------------------------
231 // Accessors
232 //----------------------------------------------------------------------
233 bool
234 IsRunning ( lldb::StateType state )
235 {
236 return state == lldb::eStateRunning || IsStepping(state);
237 }
238
239 bool
240 IsStepping ( lldb::StateType state)
241 {
242 return state == lldb::eStateStepping;
243 }
244 bool
245 CanResume ( lldb::StateType state)
246 {
247 return state == lldb::eStateStopped;
248 }
249
250 bool
251 HasExited (lldb::StateType state)
252 {
253 return state == lldb::eStateExited;
254 }
255
256 bool
257 ProcessIDIsValid ( ) const;
258
Chris Lattner24943d22010-06-08 16:52:24 +0000259 void
260 Clear ( );
261
262 lldb_private::Flags &
263 GetFlags ()
264 {
265 return m_flags;
266 }
267
268 const lldb_private::Flags &
269 GetFlags () const
270 {
271 return m_flags;
272 }
273
Greg Claytonae932352012-04-10 00:18:59 +0000274 virtual bool
Greg Clayton37f962e2011-08-22 02:49:39 +0000275 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
276 lldb_private::ThreadList &new_thread_list);
Chris Lattner24943d22010-06-08 16:52:24 +0000277
278 lldb_private::Error
Greg Claytonb72d0f02011-04-12 05:54:46 +0000279 StartDebugserverProcess (const char *debugserver_url);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000280
281 lldb_private::Error
282 StartDebugserverProcess (const char *debugserver_url, const lldb_private::ProcessInfo &process_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000283
284 void
285 KillDebugserverProcess ();
286
287 void
Greg Clayton7e2f91c2011-01-29 07:10:55 +0000288 BuildDynamicRegisterInfo (bool force);
Chris Lattner24943d22010-06-08 16:52:24 +0000289
Greg Clayton06709002011-12-06 04:51:14 +0000290 void
291 SetLastStopPacket (const StringExtractorGDBRemote &response)
292 {
293 lldb_private::Mutex::Locker locker (m_last_stop_packet_mutex);
294 m_last_stop_packet = response;
295 }
Jason Molendab0e3c7c2012-09-29 08:03:33 +0000296
297 void
Jason Molendab46937c2012-10-03 01:29:34 +0000298 CheckForKernel (lldb_private::Stream *strm);
Jason Molendab0e3c7c2012-09-29 08:03:33 +0000299
Chris Lattner24943d22010-06-08 16:52:24 +0000300 //------------------------------------------------------------------
301 /// Broadcaster event bits definitions.
302 //------------------------------------------------------------------
303 enum
304 {
305 eBroadcastBitAsyncContinue = (1 << 0),
Jim Ingham7fa7b2f2012-04-12 18:49:31 +0000306 eBroadcastBitAsyncThreadShouldExit = (1 << 1),
307 eBroadcastBitAsyncThreadDidExit = (1 << 2)
Chris Lattner24943d22010-06-08 16:52:24 +0000308 };
309
Chris Lattner24943d22010-06-08 16:52:24 +0000310 lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
Greg Clayton61d043b2011-03-22 04:00:09 +0000311 GDBRemoteCommunicationClient m_gdb_comm;
Chris Lattner24943d22010-06-08 16:52:24 +0000312 lldb::pid_t m_debugserver_pid;
Greg Clayton261a18b2011-06-02 22:22:38 +0000313 StringExtractorGDBRemote m_last_stop_packet;
Greg Clayton06709002011-12-06 04:51:14 +0000314 lldb_private::Mutex m_last_stop_packet_mutex;
Chris Lattner24943d22010-06-08 16:52:24 +0000315 GDBRemoteDynamicRegisterInfo m_register_info;
316 lldb_private::Broadcaster m_async_broadcaster;
317 lldb::thread_t m_async_thread;
Greg Claytonc1f45872011-02-12 06:28:37 +0000318 typedef std::vector<lldb::tid_t> tid_collection;
319 typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
Greg Clayton2f085c62011-05-15 01:25:55 +0000320 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
Greg Clayton5a9f85c2012-04-10 02:25:43 +0000321 tid_collection m_thread_ids; // Thread IDs for all threads. This list gets updated after stopping
Greg Claytonc1f45872011-02-12 06:28:37 +0000322 tid_collection m_continue_c_tids; // 'c' for continue
323 tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
324 tid_collection m_continue_s_tids; // 's' for step
325 tid_sig_collection m_continue_S_tids; // 'S' for step with signal
Chris Lattner24943d22010-06-08 16:52:24 +0000326 lldb::addr_t m_dispatch_queue_offsets_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000327 size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
Greg Clayton2f085c62011-05-15 01:25:55 +0000328 MMapMap m_addr_to_mmap_size;
Greg Claytonbd5c23d2012-05-15 02:33:01 +0000329 lldb::BreakpointSP m_thread_create_bp_sp;
330 bool m_waiting_for_attach;
Jim Ingham06b84492012-07-04 00:35:43 +0000331 bool m_destroy_tried_resuming;
Jason Molendab46937c2012-10-03 01:29:34 +0000332 std::string m_dyld_plugin_name;
333 lldb::addr_t m_kernel_load_addr;
Greg Clayton13193d52012-10-13 02:07:45 +0000334 lldb::CommandObjectSP m_command_sp;
Greg Claytonbd5c23d2012-05-15 02:33:01 +0000335
Chris Lattner24943d22010-06-08 16:52:24 +0000336 bool
337 StartAsyncThread ();
338
339 void
340 StopAsyncThread ();
341
342 static void *
343 AsyncThread (void *arg);
344
345 static bool
346 MonitorDebugserverProcess (void *callback_baton,
347 lldb::pid_t pid,
Greg Clayton1c4642c2011-11-16 05:37:56 +0000348 bool exited,
349 int signo,
350 int exit_status);
Chris Lattner24943d22010-06-08 16:52:24 +0000351
352 lldb::StateType
353 SetThreadStopInfo (StringExtractor& stop_packet);
354
355 void
Greg Clayton5a9f85c2012-04-10 02:25:43 +0000356 ClearThreadIDList ();
357
358 bool
359 UpdateThreadIDList ();
360
361 void
Chris Lattner24943d22010-06-08 16:52:24 +0000362 DidLaunchOrAttach ();
363
364 lldb_private::Error
365 ConnectToDebugserver (const char *host_port);
366
367 const char *
368 GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
369 std::string &dispatch_queue_name);
370
371 static size_t
372 AttachInputReaderCallback (void *baton,
373 lldb_private::InputReader *reader,
374 lldb::InputReaderAction notification,
375 const char *bytes,
376 size_t bytes_len);
377
Greg Clayton72e1c782011-01-22 23:43:18 +0000378 lldb_private::Error
379 InterruptIfRunning (bool discard_thread_plans,
380 bool catch_stop_event,
Greg Clayton72e1c782011-01-22 23:43:18 +0000381 lldb::EventSP &stop_event_sp);
382
Jason Molendab46937c2012-10-03 01:29:34 +0000383 lldb_private::DynamicLoader *
384 GetDynamicLoader ();
385
Chris Lattner24943d22010-06-08 16:52:24 +0000386private:
387 //------------------------------------------------------------------
388 // For ProcessGDBRemote only
389 //------------------------------------------------------------------
Jim Ingham55e01d82011-01-22 01:33:44 +0000390 static bool
391 NewThreadNotifyBreakpointHit (void *baton,
392 lldb_private::StoppointCallbackContext *context,
393 lldb::user_id_t break_id,
394 lldb::user_id_t break_loc_id);
395
Chris Lattner24943d22010-06-08 16:52:24 +0000396 DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
397
Chris Lattner24943d22010-06-08 16:52:24 +0000398};
399
400#endif // liblldb_ProcessGDBRemote_h_