blob: 9de262322ae27b1d0f9163842a1bc81dc6e2f24e [file] [log] [blame]
Greg Clayton269f91e2011-07-15 18:02:58 +00001//===-- ProcessKDP.h --------------------------------------------*- C++ -*-===//
Greg Clayton363be3f2011-07-15 03:27:12 +00002//
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_ProcessKDP_h_
11#define liblldb_ProcessKDP_h_
12
13// C Includes
14
15// C++ Includes
16#include <list>
17#include <vector>
18
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"
25#include "lldb/Core/StringList.h"
26#include "lldb/Core/ThreadSafeValue.h"
27#include "lldb/Target/Process.h"
28#include "lldb/Target/Thread.h"
29
30#include "CommunicationKDP.h"
31#include "Utility/StringExtractor.h"
32
33class ThreadKDP;
34
35class ProcessKDP : public lldb_private::Process
36{
37public:
38 //------------------------------------------------------------------
39 // Constructors and Destructors
40 //------------------------------------------------------------------
Greg Clayton46c9a352012-02-09 06:16:32 +000041 static lldb::ProcessSP
42 CreateInstance (lldb_private::Target& target,
43 lldb_private::Listener &listener,
44 const lldb_private::FileSpec *crash_file_path);
Greg Clayton363be3f2011-07-15 03:27:12 +000045
46 static void
47 Initialize();
48
49 static void
50 Terminate();
51
52 static const char *
53 GetPluginNameStatic();
54
55 static const char *
56 GetPluginDescriptionStatic();
57
58 //------------------------------------------------------------------
59 // Constructors and Destructors
60 //------------------------------------------------------------------
61 ProcessKDP(lldb_private::Target& target, lldb_private::Listener &listener);
62
63 virtual
64 ~ProcessKDP();
65
66 //------------------------------------------------------------------
67 // Check if a given Process
68 //------------------------------------------------------------------
69 virtual bool
Greg Clayton8d2ea282011-07-17 20:36:25 +000070 CanDebug (lldb_private::Target &target,
71 bool plugin_specified_by_name);
Greg Clayton363be3f2011-07-15 03:27:12 +000072
Greg Clayton307c7fd2012-10-19 22:22:57 +000073 virtual lldb_private::CommandObject *
74 GetPluginCommandObject();
Greg Clayton363be3f2011-07-15 03:27:12 +000075
76 //------------------------------------------------------------------
77 // Creating a new process, or attaching to an existing one
78 //------------------------------------------------------------------
79 virtual lldb_private::Error
80 WillLaunch (lldb_private::Module* module);
81
82 virtual lldb_private::Error
Greg Clayton36bc5ea2011-11-03 21:22:33 +000083 DoLaunch (lldb_private::Module *exe_module,
84 const lldb_private::ProcessLaunchInfo &launch_info);
Greg Clayton363be3f2011-07-15 03:27:12 +000085
86 virtual lldb_private::Error
87 WillAttachToProcessWithID (lldb::pid_t pid);
88
89 virtual lldb_private::Error
90 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
91
92 virtual lldb_private::Error
Jason Molendafac2e622012-09-29 04:02:01 +000093 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
Greg Clayton363be3f2011-07-15 03:27:12 +000094
95 virtual lldb_private::Error
96 DoAttachToProcessWithID (lldb::pid_t pid);
97
98 virtual lldb_private::Error
Han Ming Ongd1040dd2012-02-25 01:07:38 +000099 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
100
101 virtual lldb_private::Error
102 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const lldb_private::ProcessAttachInfo &attach_info);
Greg Clayton363be3f2011-07-15 03:27:12 +0000103
104 virtual void
105 DidAttach ();
106
Jason Molendab46937c2012-10-03 01:29:34 +0000107 lldb::addr_t
108 GetImageInfoAddress();
109
110 lldb_private::DynamicLoader *
111 GetDynamicLoader ();
112
Greg Clayton363be3f2011-07-15 03:27:12 +0000113 //------------------------------------------------------------------
114 // PluginInterface protocol
115 //------------------------------------------------------------------
116 virtual const char *
117 GetPluginName();
118
119 virtual const char *
120 GetShortPluginName();
121
122 virtual uint32_t
123 GetPluginVersion();
124
125 //------------------------------------------------------------------
126 // Process Control
127 //------------------------------------------------------------------
128 virtual lldb_private::Error
129 WillResume ();
130
131 virtual lldb_private::Error
132 DoResume ();
133
134 virtual lldb_private::Error
135 DoHalt (bool &caused_stop);
136
137 virtual lldb_private::Error
Jim Ingham761afb82013-05-02 00:27:30 +0000138 DoDetach (bool keep_stopped);
Greg Clayton363be3f2011-07-15 03:27:12 +0000139
140 virtual lldb_private::Error
141 DoSignal (int signal);
142
143 virtual lldb_private::Error
144 DoDestroy ();
145
146 virtual void
147 RefreshStateAfterStop();
148
149 //------------------------------------------------------------------
150 // Process Queries
151 //------------------------------------------------------------------
152 virtual bool
153 IsAlive ();
154
155 //------------------------------------------------------------------
156 // Process Memory
157 //------------------------------------------------------------------
158 virtual size_t
159 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
160
161 virtual size_t
162 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
163
164 virtual lldb::addr_t
165 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
166
167 virtual lldb_private::Error
168 DoDeallocateMemory (lldb::addr_t ptr);
169
170 //----------------------------------------------------------------------
171 // Process Breakpoints
172 //----------------------------------------------------------------------
173 virtual lldb_private::Error
Jim Inghamefb4aeb2013-02-15 02:06:30 +0000174 EnableBreakpointSite (lldb_private::BreakpointSite *bp_site);
Greg Clayton363be3f2011-07-15 03:27:12 +0000175
176 virtual lldb_private::Error
Jim Inghamefb4aeb2013-02-15 02:06:30 +0000177 DisableBreakpointSite (lldb_private::BreakpointSite *bp_site);
Greg Clayton363be3f2011-07-15 03:27:12 +0000178
179 //----------------------------------------------------------------------
180 // Process Watchpoints
181 //----------------------------------------------------------------------
182 virtual lldb_private::Error
Jim Ingham9c970a32012-12-18 02:03:49 +0000183 EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
Greg Clayton363be3f2011-07-15 03:27:12 +0000184
185 virtual lldb_private::Error
Jim Ingham9c970a32012-12-18 02:03:49 +0000186 DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
Greg Clayton363be3f2011-07-15 03:27:12 +0000187
Greg Clayton0fa51242011-07-19 03:57:15 +0000188 CommunicationKDP &
189 GetCommunication()
190 {
191 return m_comm;
192 }
193
Greg Clayton363be3f2011-07-15 03:27:12 +0000194protected:
195 friend class ThreadKDP;
196 friend class CommunicationKDP;
197
198 //----------------------------------------------------------------------
199 // Accessors
200 //----------------------------------------------------------------------
201 bool
202 IsRunning ( lldb::StateType state )
203 {
204 return state == lldb::eStateRunning || IsStepping(state);
205 }
206
207 bool
208 IsStepping ( lldb::StateType state)
209 {
210 return state == lldb::eStateStepping;
211 }
212
213 bool
214 CanResume ( lldb::StateType state)
215 {
216 return state == lldb::eStateStopped;
217 }
218
219 bool
220 HasExited (lldb::StateType state)
221 {
222 return state == lldb::eStateExited;
223 }
224
225 bool
226 ProcessIDIsValid ( ) const;
227
228 // static void
229 // STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
230
231 // void
232 // AppendSTDOUT (const char* s, size_t len);
233
234 void
235 Clear ( );
236
Greg Claytonae932352012-04-10 00:18:59 +0000237 virtual bool
Greg Clayton37f962e2011-08-22 02:49:39 +0000238 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
239 lldb_private::ThreadList &new_thread_list);
Greg Clayton363be3f2011-07-15 03:27:12 +0000240
Greg Clayton363be3f2011-07-15 03:27:12 +0000241 enum
242 {
243 eBroadcastBitAsyncContinue = (1 << 0),
244 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
245 };
Greg Claytone76f8c42012-09-21 16:31:20 +0000246
Greg Clayton3acaa922012-09-25 02:40:06 +0000247 lldb::ThreadSP
248 GetKernelThread (lldb_private::ThreadList &old_thread_list,
249 lldb_private::ThreadList &new_thread_list);
Greg Clayton363be3f2011-07-15 03:27:12 +0000250
251 //------------------------------------------------------------------
252 /// Broadcaster event bits definitions.
253 //------------------------------------------------------------------
254 CommunicationKDP m_comm;
255 lldb_private::Broadcaster m_async_broadcaster;
256 lldb::thread_t m_async_thread;
Jason Molendab46937c2012-10-03 01:29:34 +0000257 std::string m_dyld_plugin_name;
258 lldb::addr_t m_kernel_load_addr;
Greg Clayton307c7fd2012-10-19 22:22:57 +0000259 lldb::CommandObjectSP m_command_sp;
260
Greg Clayton363be3f2011-07-15 03:27:12 +0000261
262 bool
263 StartAsyncThread ();
264
265 void
266 StopAsyncThread ();
267
268 static void *
269 AsyncThread (void *arg);
270
Greg Clayton363be3f2011-07-15 03:27:12 +0000271private:
272 //------------------------------------------------------------------
273 // For ProcessKDP only
274 //------------------------------------------------------------------
275
276 DISALLOW_COPY_AND_ASSIGN (ProcessKDP);
277
278};
279
280#endif // liblldb_ProcessKDP_h_