blob: 7ecd2fffef7639a8b726bd108e35c40f400542ab [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 //------------------------------------------------------------------
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
Greg Clayton8d2ea282011-07-17 20:36:25 +000068 CanDebug (lldb_private::Target &target,
69 bool plugin_specified_by_name);
Greg Clayton363be3f2011-07-15 03:27:12 +000070
71 // virtual uint32_t
72 // ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids);
73
74 //------------------------------------------------------------------
75 // Creating a new process, or attaching to an existing one
76 //------------------------------------------------------------------
77 virtual lldb_private::Error
78 WillLaunch (lldb_private::Module* module);
79
80 virtual lldb_private::Error
Greg Clayton36bc5ea2011-11-03 21:22:33 +000081 DoLaunch (lldb_private::Module *exe_module,
82 const lldb_private::ProcessLaunchInfo &launch_info);
Greg Clayton363be3f2011-07-15 03:27:12 +000083
84 virtual lldb_private::Error
85 WillAttachToProcessWithID (lldb::pid_t pid);
86
87 virtual lldb_private::Error
88 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
89
90 virtual lldb_private::Error
91 DoConnectRemote (const char *remote_url);
92
93 virtual lldb_private::Error
94 DoAttachToProcessWithID (lldb::pid_t pid);
95
96 virtual lldb_private::Error
97 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch);
98
99 virtual void
100 DidAttach ();
101
102 //------------------------------------------------------------------
103 // PluginInterface protocol
104 //------------------------------------------------------------------
105 virtual const char *
106 GetPluginName();
107
108 virtual const char *
109 GetShortPluginName();
110
111 virtual uint32_t
112 GetPluginVersion();
113
114 //------------------------------------------------------------------
115 // Process Control
116 //------------------------------------------------------------------
117 virtual lldb_private::Error
118 WillResume ();
119
120 virtual lldb_private::Error
121 DoResume ();
122
123 virtual lldb_private::Error
124 DoHalt (bool &caused_stop);
125
126 virtual lldb_private::Error
127 WillDetach ();
128
129 virtual lldb_private::Error
130 DoDetach ();
131
132 virtual lldb_private::Error
133 DoSignal (int signal);
134
135 virtual lldb_private::Error
136 DoDestroy ();
137
138 virtual void
139 RefreshStateAfterStop();
140
141 //------------------------------------------------------------------
142 // Process Queries
143 //------------------------------------------------------------------
144 virtual bool
145 IsAlive ();
146
147 //------------------------------------------------------------------
148 // Process Memory
149 //------------------------------------------------------------------
150 virtual size_t
151 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
152
153 virtual size_t
154 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
155
156 virtual lldb::addr_t
157 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
158
159 virtual lldb_private::Error
160 DoDeallocateMemory (lldb::addr_t ptr);
161
162 //----------------------------------------------------------------------
163 // Process Breakpoints
164 //----------------------------------------------------------------------
165 virtual lldb_private::Error
166 EnableBreakpoint (lldb_private::BreakpointSite *bp_site);
167
168 virtual lldb_private::Error
169 DisableBreakpoint (lldb_private::BreakpointSite *bp_site);
170
171 //----------------------------------------------------------------------
172 // Process Watchpoints
173 //----------------------------------------------------------------------
174 virtual lldb_private::Error
Johnny Chenecd4feb2011-10-14 00:42:25 +0000175 EnableWatchpoint (lldb_private::Watchpoint *wp);
Greg Clayton363be3f2011-07-15 03:27:12 +0000176
177 virtual lldb_private::Error
Johnny Chenecd4feb2011-10-14 00:42:25 +0000178 DisableWatchpoint (lldb_private::Watchpoint *wp);
Greg Clayton363be3f2011-07-15 03:27:12 +0000179
Greg Clayton0fa51242011-07-19 03:57:15 +0000180 CommunicationKDP &
181 GetCommunication()
182 {
183 return m_comm;
184 }
185
Greg Clayton363be3f2011-07-15 03:27:12 +0000186protected:
187 friend class ThreadKDP;
188 friend class CommunicationKDP;
189
190 //----------------------------------------------------------------------
191 // Accessors
192 //----------------------------------------------------------------------
193 bool
194 IsRunning ( lldb::StateType state )
195 {
196 return state == lldb::eStateRunning || IsStepping(state);
197 }
198
199 bool
200 IsStepping ( lldb::StateType state)
201 {
202 return state == lldb::eStateStepping;
203 }
204
205 bool
206 CanResume ( lldb::StateType state)
207 {
208 return state == lldb::eStateStopped;
209 }
210
211 bool
212 HasExited (lldb::StateType state)
213 {
214 return state == lldb::eStateExited;
215 }
216
217 bool
218 ProcessIDIsValid ( ) const;
219
220 // static void
221 // STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
222
223 // void
224 // AppendSTDOUT (const char* s, size_t len);
225
226 void
227 Clear ( );
228
229 uint32_t
Greg Clayton37f962e2011-08-22 02:49:39 +0000230 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
231 lldb_private::ThreadList &new_thread_list);
Greg Clayton363be3f2011-07-15 03:27:12 +0000232
Greg Clayton363be3f2011-07-15 03:27:12 +0000233 enum
234 {
235 eBroadcastBitAsyncContinue = (1 << 0),
236 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
237 };
238
239 lldb_private::Error
240 InterruptIfRunning (bool discard_thread_plans,
241 bool catch_stop_event,
242 lldb::EventSP &stop_event_sp);
243
244 //------------------------------------------------------------------
245 /// Broadcaster event bits definitions.
246 //------------------------------------------------------------------
247 CommunicationKDP m_comm;
248 lldb_private::Broadcaster m_async_broadcaster;
249 lldb::thread_t m_async_thread;
250
251 bool
252 StartAsyncThread ();
253
254 void
255 StopAsyncThread ();
256
257 static void *
258 AsyncThread (void *arg);
259
260 lldb::StateType
261 SetThreadStopInfo (StringExtractor& stop_packet);
262
Greg Clayton363be3f2011-07-15 03:27:12 +0000263private:
264 //------------------------------------------------------------------
265 // For ProcessKDP only
266 //------------------------------------------------------------------
267
268 DISALLOW_COPY_AND_ASSIGN (ProcessKDP);
269
270};
271
272#endif // liblldb_ProcessKDP_h_