blob: da2ee3f44a920df24681f6e1efcce48c6d9179a1 [file] [log] [blame]
Greg Clayton59ec5122011-07-15 18:02:58 +00001//===-- ProcessKDP.h --------------------------------------------*- C++ -*-===//
Greg Claytonf9765ac2011-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"
Jason Molenda2e56a252013-05-11 03:09:05 +000022#include "lldb/Core/ConstString.h"
Greg Claytonf9765ac2011-07-15 03:27:12 +000023#include "lldb/Core/Error.h"
24#include "lldb/Core/InputReader.h"
25#include "lldb/Core/StreamString.h"
26#include "lldb/Core/StringList.h"
27#include "lldb/Core/ThreadSafeValue.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/Thread.h"
30
31#include "CommunicationKDP.h"
32#include "Utility/StringExtractor.h"
33
34class ThreadKDP;
35
36class ProcessKDP : public lldb_private::Process
37{
38public:
39 //------------------------------------------------------------------
40 // Constructors and Destructors
41 //------------------------------------------------------------------
Greg Claytonc3776bf2012-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);
Greg Claytonf9765ac2011-07-15 03:27:12 +000046
47 static void
48 Initialize();
49
50 static void
51 Terminate();
52
Greg Clayton57abc5d2013-05-10 21:47:16 +000053 static lldb_private::ConstString
Greg Claytonf9765ac2011-07-15 03:27:12 +000054 GetPluginNameStatic();
55
56 static const char *
57 GetPluginDescriptionStatic();
58
59 //------------------------------------------------------------------
60 // Constructors and Destructors
61 //------------------------------------------------------------------
62 ProcessKDP(lldb_private::Target& target, lldb_private::Listener &listener);
63
64 virtual
65 ~ProcessKDP();
66
67 //------------------------------------------------------------------
68 // Check if a given Process
69 //------------------------------------------------------------------
70 virtual bool
Greg Clayton3a29bdb2011-07-17 20:36:25 +000071 CanDebug (lldb_private::Target &target,
72 bool plugin_specified_by_name);
Greg Claytonf9765ac2011-07-15 03:27:12 +000073
Greg Clayton1d19a2f2012-10-19 22:22:57 +000074 virtual lldb_private::CommandObject *
75 GetPluginCommandObject();
Greg Claytonf9765ac2011-07-15 03:27:12 +000076
77 //------------------------------------------------------------------
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 Clayton982c9762011-11-03 21:22:33 +000084 DoLaunch (lldb_private::Module *exe_module,
85 const lldb_private::ProcessLaunchInfo &launch_info);
Greg Claytonf9765ac2011-07-15 03:27:12 +000086
87 virtual lldb_private::Error
88 WillAttachToProcessWithID (lldb::pid_t pid);
89
90 virtual lldb_private::Error
91 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
92
93 virtual lldb_private::Error
Jason Molenda4bd4e7e2012-09-29 04:02:01 +000094 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
Greg Claytonf9765ac2011-07-15 03:27:12 +000095
96 virtual lldb_private::Error
97 DoAttachToProcessWithID (lldb::pid_t pid);
98
99 virtual lldb_private::Error
Han Ming Ong84647042012-02-25 01:07:38 +0000100 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
101
102 virtual lldb_private::Error
103 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const lldb_private::ProcessAttachInfo &attach_info);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000104
105 virtual void
106 DidAttach ();
107
Jason Molenda5e8534e2012-10-03 01:29:34 +0000108 lldb::addr_t
109 GetImageInfoAddress();
110
111 lldb_private::DynamicLoader *
112 GetDynamicLoader ();
113
Greg Claytonf9765ac2011-07-15 03:27:12 +0000114 //------------------------------------------------------------------
115 // PluginInterface protocol
116 //------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +0000117 virtual lldb_private::ConstString
Greg Claytonf9765ac2011-07-15 03:27:12 +0000118 GetPluginName();
119
Greg Claytonf9765ac2011-07-15 03:27:12 +0000120 virtual uint32_t
121 GetPluginVersion();
122
123 //------------------------------------------------------------------
124 // Process Control
125 //------------------------------------------------------------------
126 virtual lldb_private::Error
127 WillResume ();
128
129 virtual lldb_private::Error
130 DoResume ();
131
132 virtual lldb_private::Error
133 DoHalt (bool &caused_stop);
134
135 virtual lldb_private::Error
Jim Inghamacff8952013-05-02 00:27:30 +0000136 DoDetach (bool keep_stopped);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000137
138 virtual lldb_private::Error
139 DoSignal (int signal);
140
141 virtual lldb_private::Error
142 DoDestroy ();
143
144 virtual void
145 RefreshStateAfterStop();
146
147 //------------------------------------------------------------------
148 // Process Queries
149 //------------------------------------------------------------------
150 virtual bool
151 IsAlive ();
152
153 //------------------------------------------------------------------
154 // Process Memory
155 //------------------------------------------------------------------
156 virtual size_t
157 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
158
159 virtual size_t
160 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
161
162 virtual lldb::addr_t
163 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
164
165 virtual lldb_private::Error
166 DoDeallocateMemory (lldb::addr_t ptr);
167
168 //----------------------------------------------------------------------
169 // Process Breakpoints
170 //----------------------------------------------------------------------
171 virtual lldb_private::Error
Jim Ingham299c0c12013-02-15 02:06:30 +0000172 EnableBreakpointSite (lldb_private::BreakpointSite *bp_site);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000173
174 virtual lldb_private::Error
Jim Ingham299c0c12013-02-15 02:06:30 +0000175 DisableBreakpointSite (lldb_private::BreakpointSite *bp_site);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000176
177 //----------------------------------------------------------------------
178 // Process Watchpoints
179 //----------------------------------------------------------------------
180 virtual lldb_private::Error
Jim Ingham1b5792e2012-12-18 02:03:49 +0000181 EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000182
183 virtual lldb_private::Error
Jim Ingham1b5792e2012-12-18 02:03:49 +0000184 DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000185
Greg Claytona63d08c2011-07-19 03:57:15 +0000186 CommunicationKDP &
187 GetCommunication()
188 {
189 return m_comm;
190 }
191
Greg Claytonf9765ac2011-07-15 03:27:12 +0000192protected:
193 friend class ThreadKDP;
194 friend class CommunicationKDP;
195
196 //----------------------------------------------------------------------
197 // Accessors
198 //----------------------------------------------------------------------
199 bool
200 IsRunning ( lldb::StateType state )
201 {
202 return state == lldb::eStateRunning || IsStepping(state);
203 }
204
205 bool
206 IsStepping ( lldb::StateType state)
207 {
208 return state == lldb::eStateStepping;
209 }
210
211 bool
212 CanResume ( lldb::StateType state)
213 {
214 return state == lldb::eStateStopped;
215 }
216
217 bool
218 HasExited (lldb::StateType state)
219 {
220 return state == lldb::eStateExited;
221 }
222
223 bool
224 ProcessIDIsValid ( ) const;
225
Greg Claytonf9765ac2011-07-15 03:27:12 +0000226 void
227 Clear ( );
228
Greg Clayton9fc13552012-04-10 00:18:59 +0000229 virtual bool
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000230 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
231 lldb_private::ThreadList &new_thread_list);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000232
Greg Claytonf9765ac2011-07-15 03:27:12 +0000233 enum
234 {
235 eBroadcastBitAsyncContinue = (1 << 0),
236 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
237 };
Greg Clayton7925fbb2012-09-21 16:31:20 +0000238
Greg Clayton97d5cf02012-09-25 02:40:06 +0000239 lldb::ThreadSP
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000240 GetKernelThread ();
Greg Claytonf9765ac2011-07-15 03:27:12 +0000241
242 //------------------------------------------------------------------
243 /// Broadcaster event bits definitions.
244 //------------------------------------------------------------------
245 CommunicationKDP m_comm;
246 lldb_private::Broadcaster m_async_broadcaster;
247 lldb::thread_t m_async_thread;
Jason Molenda2e56a252013-05-11 03:09:05 +0000248 lldb_private::ConstString m_dyld_plugin_name;
Jason Molenda5e8534e2012-10-03 01:29:34 +0000249 lldb::addr_t m_kernel_load_addr;
Greg Clayton1d19a2f2012-10-19 22:22:57 +0000250 lldb::CommandObjectSP m_command_sp;
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000251 lldb::ThreadWP m_kernel_thread_wp;
Greg Clayton1d19a2f2012-10-19 22:22:57 +0000252
Greg Claytonf9765ac2011-07-15 03:27:12 +0000253
254 bool
255 StartAsyncThread ();
256
257 void
258 StopAsyncThread ();
259
260 static void *
261 AsyncThread (void *arg);
262
Greg Claytonf9765ac2011-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_