blob: 509904082158cede631671d296c1fee4beab114f [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
Greg Clayton7f982402013-07-15 22:54:20 +000051 DebuggerInitialize (lldb_private::Debugger &debugger);
52
53 static void
Greg Claytonf9765ac2011-07-15 03:27:12 +000054 Terminate();
55
Greg Clayton57abc5d2013-05-10 21:47:16 +000056 static lldb_private::ConstString
Greg Claytonf9765ac2011-07-15 03:27:12 +000057 GetPluginNameStatic();
58
59 static const char *
60 GetPluginDescriptionStatic();
61
62 //------------------------------------------------------------------
63 // Constructors and Destructors
64 //------------------------------------------------------------------
65 ProcessKDP(lldb_private::Target& target, lldb_private::Listener &listener);
66
67 virtual
68 ~ProcessKDP();
69
70 //------------------------------------------------------------------
71 // Check if a given Process
72 //------------------------------------------------------------------
73 virtual bool
Greg Clayton3a29bdb2011-07-17 20:36:25 +000074 CanDebug (lldb_private::Target &target,
75 bool plugin_specified_by_name);
Greg Claytonf9765ac2011-07-15 03:27:12 +000076
Greg Clayton1d19a2f2012-10-19 22:22:57 +000077 virtual lldb_private::CommandObject *
78 GetPluginCommandObject();
Greg Claytonf9765ac2011-07-15 03:27:12 +000079
80 //------------------------------------------------------------------
81 // Creating a new process, or attaching to an existing one
82 //------------------------------------------------------------------
83 virtual lldb_private::Error
84 WillLaunch (lldb_private::Module* module);
85
86 virtual lldb_private::Error
Greg Clayton982c9762011-11-03 21:22:33 +000087 DoLaunch (lldb_private::Module *exe_module,
88 const lldb_private::ProcessLaunchInfo &launch_info);
Greg Claytonf9765ac2011-07-15 03:27:12 +000089
90 virtual lldb_private::Error
91 WillAttachToProcessWithID (lldb::pid_t pid);
92
93 virtual lldb_private::Error
94 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
95
96 virtual lldb_private::Error
Jason Molenda4bd4e7e2012-09-29 04:02:01 +000097 DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
Greg Claytonf9765ac2011-07-15 03:27:12 +000098
99 virtual lldb_private::Error
100 DoAttachToProcessWithID (lldb::pid_t pid);
101
102 virtual lldb_private::Error
Han Ming Ong84647042012-02-25 01:07:38 +0000103 DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
104
105 virtual lldb_private::Error
106 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const lldb_private::ProcessAttachInfo &attach_info);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000107
108 virtual void
109 DidAttach ();
110
Jason Molenda5e8534e2012-10-03 01:29:34 +0000111 lldb::addr_t
112 GetImageInfoAddress();
113
114 lldb_private::DynamicLoader *
115 GetDynamicLoader ();
116
Greg Claytonf9765ac2011-07-15 03:27:12 +0000117 //------------------------------------------------------------------
118 // PluginInterface protocol
119 //------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +0000120 virtual lldb_private::ConstString
Greg Claytonf9765ac2011-07-15 03:27:12 +0000121 GetPluginName();
122
Greg Claytonf9765ac2011-07-15 03:27:12 +0000123 virtual uint32_t
124 GetPluginVersion();
125
126 //------------------------------------------------------------------
127 // Process Control
128 //------------------------------------------------------------------
129 virtual lldb_private::Error
130 WillResume ();
131
132 virtual lldb_private::Error
133 DoResume ();
134
135 virtual lldb_private::Error
136 DoHalt (bool &caused_stop);
137
138 virtual lldb_private::Error
Jim Inghamacff8952013-05-02 00:27:30 +0000139 DoDetach (bool keep_stopped);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000140
141 virtual lldb_private::Error
142 DoSignal (int signal);
143
144 virtual lldb_private::Error
145 DoDestroy ();
146
147 virtual void
148 RefreshStateAfterStop();
149
150 //------------------------------------------------------------------
151 // Process Queries
152 //------------------------------------------------------------------
153 virtual bool
154 IsAlive ();
155
156 //------------------------------------------------------------------
157 // Process Memory
158 //------------------------------------------------------------------
159 virtual size_t
160 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
161
162 virtual size_t
163 DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
164
165 virtual lldb::addr_t
166 DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
167
168 virtual lldb_private::Error
169 DoDeallocateMemory (lldb::addr_t ptr);
170
171 //----------------------------------------------------------------------
172 // Process Breakpoints
173 //----------------------------------------------------------------------
174 virtual lldb_private::Error
Jim Ingham299c0c12013-02-15 02:06:30 +0000175 EnableBreakpointSite (lldb_private::BreakpointSite *bp_site);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000176
177 virtual lldb_private::Error
Jim Ingham299c0c12013-02-15 02:06:30 +0000178 DisableBreakpointSite (lldb_private::BreakpointSite *bp_site);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000179
180 //----------------------------------------------------------------------
181 // Process Watchpoints
182 //----------------------------------------------------------------------
183 virtual lldb_private::Error
Jim Ingham1b5792e2012-12-18 02:03:49 +0000184 EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000185
186 virtual lldb_private::Error
Jim Ingham1b5792e2012-12-18 02:03:49 +0000187 DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000188
Greg Claytona63d08c2011-07-19 03:57:15 +0000189 CommunicationKDP &
190 GetCommunication()
191 {
192 return m_comm;
193 }
194
Greg Claytonf9765ac2011-07-15 03:27:12 +0000195protected:
196 friend class ThreadKDP;
197 friend class CommunicationKDP;
198
199 //----------------------------------------------------------------------
200 // Accessors
201 //----------------------------------------------------------------------
202 bool
203 IsRunning ( lldb::StateType state )
204 {
205 return state == lldb::eStateRunning || IsStepping(state);
206 }
207
208 bool
209 IsStepping ( lldb::StateType state)
210 {
211 return state == lldb::eStateStepping;
212 }
213
214 bool
215 CanResume ( lldb::StateType state)
216 {
217 return state == lldb::eStateStopped;
218 }
219
220 bool
221 HasExited (lldb::StateType state)
222 {
223 return state == lldb::eStateExited;
224 }
225
226 bool
227 ProcessIDIsValid ( ) const;
228
Greg Claytonf9765ac2011-07-15 03:27:12 +0000229 void
230 Clear ( );
231
Greg Clayton9fc13552012-04-10 00:18:59 +0000232 virtual bool
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000233 UpdateThreadList (lldb_private::ThreadList &old_thread_list,
234 lldb_private::ThreadList &new_thread_list);
Greg Claytonf9765ac2011-07-15 03:27:12 +0000235
Greg Claytonf9765ac2011-07-15 03:27:12 +0000236 enum
237 {
238 eBroadcastBitAsyncContinue = (1 << 0),
239 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
240 };
Greg Clayton7925fbb2012-09-21 16:31:20 +0000241
Greg Clayton97d5cf02012-09-25 02:40:06 +0000242 lldb::ThreadSP
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000243 GetKernelThread ();
Greg Claytonf9765ac2011-07-15 03:27:12 +0000244
245 //------------------------------------------------------------------
246 /// Broadcaster event bits definitions.
247 //------------------------------------------------------------------
248 CommunicationKDP m_comm;
249 lldb_private::Broadcaster m_async_broadcaster;
250 lldb::thread_t m_async_thread;
Jason Molenda2e56a252013-05-11 03:09:05 +0000251 lldb_private::ConstString m_dyld_plugin_name;
Jason Molenda5e8534e2012-10-03 01:29:34 +0000252 lldb::addr_t m_kernel_load_addr;
Greg Clayton1d19a2f2012-10-19 22:22:57 +0000253 lldb::CommandObjectSP m_command_sp;
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000254 lldb::ThreadWP m_kernel_thread_wp;
Greg Clayton1d19a2f2012-10-19 22:22:57 +0000255
Greg Claytonf9765ac2011-07-15 03:27:12 +0000256
257 bool
258 StartAsyncThread ();
259
260 void
261 StopAsyncThread ();
262
263 static void *
264 AsyncThread (void *arg);
265
Greg Claytonf9765ac2011-07-15 03:27:12 +0000266private:
267 //------------------------------------------------------------------
268 // For ProcessKDP only
269 //------------------------------------------------------------------
270
271 DISALLOW_COPY_AND_ASSIGN (ProcessKDP);
272
273};
274
275#endif // liblldb_ProcessKDP_h_