blob: 31907dd11ab8b2ee17a9fb27a777157fc9d909ad [file] [log] [blame]
Greg Clayton363be3f2011-07-15 03:27:12 +00001//===-- ProcessKDP.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_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 //------------------------------------------------------------------
41 static Process*
42 CreateInstance (lldb_private::Target& target, lldb_private::Listener &listener);
43
44 static void
45 Initialize();
46
47 static void
48 Terminate();
49
50 static const char *
51 GetPluginNameStatic();
52
53 static const char *
54 GetPluginDescriptionStatic();
55
56 //------------------------------------------------------------------
57 // Constructors and Destructors
58 //------------------------------------------------------------------
59 ProcessKDP(lldb_private::Target& target, lldb_private::Listener &listener);
60
61 virtual
62 ~ProcessKDP();
63
64 //------------------------------------------------------------------
65 // Check if a given Process
66 //------------------------------------------------------------------
67 virtual bool
68 CanDebug (lldb_private::Target &target);
69
70 // virtual uint32_t
71 // ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids);
72
73 //------------------------------------------------------------------
74 // Creating a new process, or attaching to an existing one
75 //------------------------------------------------------------------
76 virtual lldb_private::Error
77 WillLaunch (lldb_private::Module* module);
78
79 virtual lldb_private::Error
80 DoLaunch (lldb_private::Module* module,
81 char const *argv[], // Can be NULL
82 char const *envp[], // Can be NULL
83 uint32_t flags,
84 const char *stdin_path, // Can be NULL
85 const char *stdout_path, // Can be NULL
86 const char *stderr_path, // Can be NULL
87 const char *working_dir); // Can be NULL
88
89 virtual lldb_private::Error
90 WillAttachToProcessWithID (lldb::pid_t pid);
91
92 virtual lldb_private::Error
93 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
94
95 virtual lldb_private::Error
96 DoConnectRemote (const char *remote_url);
97
98 virtual lldb_private::Error
99 DoAttachToProcessWithID (lldb::pid_t pid);
100
101 virtual lldb_private::Error
102 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch);
103
104 virtual void
105 DidAttach ();
106
107 //------------------------------------------------------------------
108 // PluginInterface protocol
109 //------------------------------------------------------------------
110 virtual const char *
111 GetPluginName();
112
113 virtual const char *
114 GetShortPluginName();
115
116 virtual uint32_t
117 GetPluginVersion();
118
119 //------------------------------------------------------------------
120 // Process Control
121 //------------------------------------------------------------------
122 virtual lldb_private::Error
123 WillResume ();
124
125 virtual lldb_private::Error
126 DoResume ();
127
128 virtual lldb_private::Error
129 DoHalt (bool &caused_stop);
130
131 virtual lldb_private::Error
132 WillDetach ();
133
134 virtual lldb_private::Error
135 DoDetach ();
136
137 virtual lldb_private::Error
138 DoSignal (int signal);
139
140 virtual lldb_private::Error
141 DoDestroy ();
142
143 virtual void
144 RefreshStateAfterStop();
145
146 //------------------------------------------------------------------
147 // Process Queries
148 //------------------------------------------------------------------
149 virtual bool
150 IsAlive ();
151
152 //------------------------------------------------------------------
153 // Process Memory
154 //------------------------------------------------------------------
155 virtual size_t
156 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
157
158 virtual size_t
159 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
160
161 virtual lldb::addr_t
162 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
163
164 virtual lldb_private::Error
165 DoDeallocateMemory (lldb::addr_t ptr);
166
167 //----------------------------------------------------------------------
168 // Process Breakpoints
169 //----------------------------------------------------------------------
170 virtual lldb_private::Error
171 EnableBreakpoint (lldb_private::BreakpointSite *bp_site);
172
173 virtual lldb_private::Error
174 DisableBreakpoint (lldb_private::BreakpointSite *bp_site);
175
176 //----------------------------------------------------------------------
177 // Process Watchpoints
178 //----------------------------------------------------------------------
179 virtual lldb_private::Error
180 EnableWatchpoint (lldb_private::WatchpointLocation *wp_loc);
181
182 virtual lldb_private::Error
183 DisableWatchpoint (lldb_private::WatchpointLocation *wp_loc);
184
185protected:
186 friend class ThreadKDP;
187 friend class CommunicationKDP;
188
189 //----------------------------------------------------------------------
190 // Accessors
191 //----------------------------------------------------------------------
192 bool
193 IsRunning ( lldb::StateType state )
194 {
195 return state == lldb::eStateRunning || IsStepping(state);
196 }
197
198 bool
199 IsStepping ( lldb::StateType state)
200 {
201 return state == lldb::eStateStepping;
202 }
203
204 bool
205 CanResume ( lldb::StateType state)
206 {
207 return state == lldb::eStateStopped;
208 }
209
210 bool
211 HasExited (lldb::StateType state)
212 {
213 return state == lldb::eStateExited;
214 }
215
216 bool
217 ProcessIDIsValid ( ) const;
218
219 // static void
220 // STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
221
222 // void
223 // AppendSTDOUT (const char* s, size_t len);
224
225 void
226 Clear ( );
227
228 uint32_t
229 UpdateThreadListIfNeeded ();
230
231 CommunicationKDP &
232 GetCommunication()
233 {
234 return m_comm;
235 }
236
237 enum
238 {
239 eBroadcastBitAsyncContinue = (1 << 0),
240 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
241 };
242
243 lldb_private::Error
244 InterruptIfRunning (bool discard_thread_plans,
245 bool catch_stop_event,
246 lldb::EventSP &stop_event_sp);
247
248 //------------------------------------------------------------------
249 /// Broadcaster event bits definitions.
250 //------------------------------------------------------------------
251 CommunicationKDP m_comm;
252 lldb_private::Broadcaster m_async_broadcaster;
253 lldb::thread_t m_async_thread;
254
255 bool
256 StartAsyncThread ();
257
258 void
259 StopAsyncThread ();
260
261 static void *
262 AsyncThread (void *arg);
263
264 lldb::StateType
265 SetThreadStopInfo (StringExtractor& stop_packet);
266
267 static size_t
268 AttachInputReaderCallback (void *baton,
269 lldb_private::InputReader *reader,
270 lldb::InputReaderAction notification,
271 const char *bytes,
272 size_t bytes_len);
273
274private:
275 //------------------------------------------------------------------
276 // For ProcessKDP only
277 //------------------------------------------------------------------
278
279 DISALLOW_COPY_AND_ASSIGN (ProcessKDP);
280
281};
282
283#endif // liblldb_ProcessKDP_h_