blob: 9e4cc568af59166c363ed82a86e572ca8bb942cf [file] [log] [blame]
Greg Clayton269f91e2011-07-15 18:02:58 +00001//===-- ProcessKDP.cpp ------------------------------------------*- 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// C Includes
11#include <errno.h>
12#include <stdlib.h>
13
14// C++ Includes
15// Other libraries and framework includes
Greg Clayton8d2ea282011-07-17 20:36:25 +000016#include "lldb/Core/ConnectionFileDescriptor.h"
Greg Clayton234981a2011-07-20 03:41:06 +000017#include "lldb/Core/Debugger.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000018#include "lldb/Core/PluginManager.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000019#include "lldb/Core/Module.h"
Jason Molendafac2e622012-09-29 04:02:01 +000020#include "lldb/Core/ModuleSpec.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000021#include "lldb/Core/State.h"
Jason Molendafac2e622012-09-29 04:02:01 +000022#include "lldb/Core/UUID.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000023#include "lldb/Host/Host.h"
Jason Molendafac2e622012-09-29 04:02:01 +000024#include "lldb/Host/Symbols.h"
Greg Clayton307c7fd2012-10-19 22:22:57 +000025#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Interpreter/CommandObject.h"
27#include "lldb/Interpreter/CommandObjectMultiword.h"
28#include "lldb/Interpreter/CommandReturnObject.h"
29#include "lldb/Interpreter/OptionGroupString.h"
30#include "lldb/Interpreter/OptionGroupUInt64.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000031#include "lldb/Symbol/ObjectFile.h"
Greg Claytone76f8c42012-09-21 16:31:20 +000032#include "lldb/Target/RegisterContext.h"
Greg Clayton1e5b0212011-07-15 16:31:38 +000033#include "lldb/Target/Target.h"
Greg Clayton0fa51242011-07-19 03:57:15 +000034#include "lldb/Target/Thread.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000035
36// Project includes
37#include "ProcessKDP.h"
38#include "ProcessKDPLog.h"
Greg Clayton0fa51242011-07-19 03:57:15 +000039#include "ThreadKDP.h"
Jason Molendab46937c2012-10-03 01:29:34 +000040#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
Jason Molendad06bb502012-10-25 00:25:13 +000041#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
Greg Clayton307c7fd2012-10-19 22:22:57 +000042#include "Utility/StringExtractor.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000043
44using namespace lldb;
45using namespace lldb_private;
46
47const char *
48ProcessKDP::GetPluginNameStatic()
49{
50 return "kdp-remote";
51}
52
53const char *
54ProcessKDP::GetPluginDescriptionStatic()
55{
56 return "KDP Remote protocol based debugging plug-in for darwin kernel debugging.";
57}
58
59void
60ProcessKDP::Terminate()
61{
62 PluginManager::UnregisterPlugin (ProcessKDP::CreateInstance);
63}
64
65
Greg Clayton46c9a352012-02-09 06:16:32 +000066lldb::ProcessSP
67ProcessKDP::CreateInstance (Target &target,
68 Listener &listener,
69 const FileSpec *crash_file_path)
Greg Clayton363be3f2011-07-15 03:27:12 +000070{
Greg Clayton46c9a352012-02-09 06:16:32 +000071 lldb::ProcessSP process_sp;
72 if (crash_file_path == NULL)
73 process_sp.reset(new ProcessKDP (target, listener));
74 return process_sp;
Greg Clayton363be3f2011-07-15 03:27:12 +000075}
76
77bool
Greg Clayton8d2ea282011-07-17 20:36:25 +000078ProcessKDP::CanDebug(Target &target, bool plugin_specified_by_name)
Greg Clayton363be3f2011-07-15 03:27:12 +000079{
Greg Clayton61ddf562011-10-21 21:41:45 +000080 if (plugin_specified_by_name)
81 return true;
82
Greg Clayton363be3f2011-07-15 03:27:12 +000083 // For now we are just making sure the file exists for a given module
Greg Clayton5beb99d2011-08-11 02:48:45 +000084 Module *exe_module = target.GetExecutableModulePointer();
85 if (exe_module)
Greg Clayton363be3f2011-07-15 03:27:12 +000086 {
87 const llvm::Triple &triple_ref = target.GetArchitecture().GetTriple();
Greg Claytonb170aee2012-05-08 01:45:38 +000088 switch (triple_ref.getOS())
Greg Clayton363be3f2011-07-15 03:27:12 +000089 {
Greg Claytonb170aee2012-05-08 01:45:38 +000090 case llvm::Triple::Darwin: // Should use "macosx" for desktop and "ios" for iOS, but accept darwin just in case
91 case llvm::Triple::MacOSX: // For desktop targets
92 case llvm::Triple::IOS: // For arm targets
93 if (triple_ref.getVendor() == llvm::Triple::Apple)
94 {
95 ObjectFile *exe_objfile = exe_module->GetObjectFile();
96 if (exe_objfile->GetType() == ObjectFile::eTypeExecutable &&
97 exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
98 return true;
99 }
100 break;
101
102 default:
103 break;
Greg Clayton363be3f2011-07-15 03:27:12 +0000104 }
105 }
Greg Clayton61ddf562011-10-21 21:41:45 +0000106 return false;
Greg Clayton363be3f2011-07-15 03:27:12 +0000107}
108
109//----------------------------------------------------------------------
110// ProcessKDP constructor
111//----------------------------------------------------------------------
112ProcessKDP::ProcessKDP(Target& target, Listener &listener) :
113 Process (target, listener),
114 m_comm("lldb.process.kdp-remote.communication"),
Jim Ingham5a15e692012-02-16 06:50:00 +0000115 m_async_broadcaster (NULL, "lldb.process.kdp-remote.async-broadcaster"),
Greg Clayton3acaa922012-09-25 02:40:06 +0000116 m_async_thread (LLDB_INVALID_HOST_THREAD),
Jason Molendab46937c2012-10-03 01:29:34 +0000117 m_dyld_plugin_name (),
Greg Clayton307c7fd2012-10-19 22:22:57 +0000118 m_kernel_load_addr (LLDB_INVALID_ADDRESS),
119 m_command_sp()
Greg Clayton363be3f2011-07-15 03:27:12 +0000120{
Greg Claytone76f8c42012-09-21 16:31:20 +0000121 m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit");
122 m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue");
Greg Clayton363be3f2011-07-15 03:27:12 +0000123}
124
125//----------------------------------------------------------------------
126// Destructor
127//----------------------------------------------------------------------
128ProcessKDP::~ProcessKDP()
129{
130 Clear();
Greg Claytonffa43a62011-11-17 04:46:02 +0000131 // We need to call finalize on the process before destroying ourselves
132 // to make sure all of the broadcaster cleanup goes as planned. If we
133 // destruct this class, then Process::~Process() might have problems
134 // trying to fully destroy the broadcaster.
135 Finalize();
Greg Clayton363be3f2011-07-15 03:27:12 +0000136}
137
138//----------------------------------------------------------------------
139// PluginInterface
140//----------------------------------------------------------------------
141const char *
142ProcessKDP::GetPluginName()
143{
144 return "Process debugging plug-in that uses the Darwin KDP remote protocol";
145}
146
147const char *
148ProcessKDP::GetShortPluginName()
149{
150 return GetPluginNameStatic();
151}
152
153uint32_t
154ProcessKDP::GetPluginVersion()
155{
156 return 1;
157}
158
159Error
160ProcessKDP::WillLaunch (Module* module)
161{
162 Error error;
163 error.SetErrorString ("launching not supported in kdp-remote plug-in");
164 return error;
165}
166
167Error
168ProcessKDP::WillAttachToProcessWithID (lldb::pid_t pid)
169{
170 Error error;
171 error.SetErrorString ("attaching to a by process ID not supported in kdp-remote plug-in");
172 return error;
173}
174
175Error
176ProcessKDP::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
177{
178 Error error;
179 error.SetErrorString ("attaching to a by process name not supported in kdp-remote plug-in");
180 return error;
181}
182
183Error
Jason Molendafac2e622012-09-29 04:02:01 +0000184ProcessKDP::DoConnectRemote (Stream *strm, const char *remote_url)
Greg Clayton363be3f2011-07-15 03:27:12 +0000185{
Greg Clayton363be3f2011-07-15 03:27:12 +0000186 Error error;
Greg Claytone76f8c42012-09-21 16:31:20 +0000187
188 // Don't let any JIT happen when doing KDP as we can't allocate
189 // memory and we don't want to be mucking with threads that might
190 // already be handling exceptions
191 SetCanJIT(false);
192
Greg Clayton8d2ea282011-07-17 20:36:25 +0000193 if (remote_url == NULL || remote_url[0] == '\0')
Greg Claytone76f8c42012-09-21 16:31:20 +0000194 {
195 error.SetErrorStringWithFormat ("invalid connection URL '%s'", remote_url);
196 return error;
197 }
Greg Clayton8d2ea282011-07-17 20:36:25 +0000198
Greg Clayton102b2c22013-04-18 22:45:39 +0000199 std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
Greg Clayton8d2ea282011-07-17 20:36:25 +0000200 if (conn_ap.get())
201 {
202 // Only try once for now.
203 // TODO: check if we should be retrying?
204 const uint32_t max_retry_count = 1;
205 for (uint32_t retry_count = 0; retry_count < max_retry_count; ++retry_count)
206 {
207 if (conn_ap->Connect(remote_url, &error) == eConnectionStatusSuccess)
208 break;
209 usleep (100000);
210 }
211 }
212
213 if (conn_ap->IsConnected())
214 {
215 const uint16_t reply_port = conn_ap->GetReadPort ();
216
217 if (reply_port != 0)
218 {
219 m_comm.SetConnection(conn_ap.release());
220
221 if (m_comm.SendRequestReattach(reply_port))
222 {
223 if (m_comm.SendRequestConnect(reply_port, reply_port, "Greetings from LLDB..."))
224 {
225 m_comm.GetVersion();
226 uint32_t cpu = m_comm.GetCPUType();
227 uint32_t sub = m_comm.GetCPUSubtype();
228 ArchSpec kernel_arch;
229 kernel_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
230 m_target.SetArchitecture(kernel_arch);
Jason Molendafac2e622012-09-29 04:02:01 +0000231
Jason Molendad06bb502012-10-25 00:25:13 +0000232 /* Get the kernel's UUID and load address via KDP_KERNELVERSION packet. */
233 /* An EFI kdp session has neither UUID nor load address. */
234
Jason Molendafac2e622012-09-29 04:02:01 +0000235 UUID kernel_uuid = m_comm.GetUUID ();
236 addr_t kernel_load_addr = m_comm.GetLoadAddress ();
Jason Molendafac2e622012-09-29 04:02:01 +0000237
Jason Molendad06bb502012-10-25 00:25:13 +0000238 if (m_comm.RemoteIsEFI ())
239 {
240 m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic();
241 }
242 else if (kernel_load_addr != LLDB_INVALID_ADDRESS)
Jason Molendafac2e622012-09-29 04:02:01 +0000243 {
Jason Molendab46937c2012-10-03 01:29:34 +0000244 m_kernel_load_addr = kernel_load_addr;
245 m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic();
Jason Molendafac2e622012-09-29 04:02:01 +0000246 }
247
Greg Clayton3acaa922012-09-25 02:40:06 +0000248 // Set the thread ID
249 UpdateThreadListIfNeeded ();
Greg Clayton0fa51242011-07-19 03:57:15 +0000250 SetID (1);
Greg Clayton37f962e2011-08-22 02:49:39 +0000251 GetThreadList ();
Greg Clayton0fa51242011-07-19 03:57:15 +0000252 SetPrivateState (eStateStopped);
Greg Clayton234981a2011-07-20 03:41:06 +0000253 StreamSP async_strm_sp(m_target.GetDebugger().GetAsyncOutputStream());
254 if (async_strm_sp)
255 {
Greg Clayton7b139222011-07-21 01:12:01 +0000256 const char *cstr;
257 if ((cstr = m_comm.GetKernelVersion ()) != NULL)
Greg Clayton234981a2011-07-20 03:41:06 +0000258 {
Greg Clayton7b139222011-07-21 01:12:01 +0000259 async_strm_sp->Printf ("Version: %s\n", cstr);
Greg Clayton234981a2011-07-20 03:41:06 +0000260 async_strm_sp->Flush();
261 }
Greg Clayton7b139222011-07-21 01:12:01 +0000262// if ((cstr = m_comm.GetImagePath ()) != NULL)
263// {
264// async_strm_sp->Printf ("Image Path: %s\n", cstr);
265// async_strm_sp->Flush();
266// }
Greg Clayton234981a2011-07-20 03:41:06 +0000267 }
Greg Clayton8d2ea282011-07-17 20:36:25 +0000268 }
Greg Clayton3acaa922012-09-25 02:40:06 +0000269 else
270 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000271 error.SetErrorString("KDP_REATTACH failed");
272 }
Greg Clayton8d2ea282011-07-17 20:36:25 +0000273 }
274 else
275 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000276 error.SetErrorString("KDP_REATTACH failed");
Greg Clayton8d2ea282011-07-17 20:36:25 +0000277 }
278 }
279 else
280 {
281 error.SetErrorString("invalid reply port from UDP connection");
282 }
283 }
284 else
285 {
286 if (error.Success())
287 error.SetErrorStringWithFormat ("failed to connect to '%s'", remote_url);
288 }
289 if (error.Fail())
290 m_comm.Disconnect();
291
Greg Clayton363be3f2011-07-15 03:27:12 +0000292 return error;
293}
294
295//----------------------------------------------------------------------
296// Process Control
297//----------------------------------------------------------------------
298Error
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000299ProcessKDP::DoLaunch (Module *exe_module,
300 const ProcessLaunchInfo &launch_info)
Greg Clayton363be3f2011-07-15 03:27:12 +0000301{
302 Error error;
303 error.SetErrorString ("launching not supported in kdp-remote plug-in");
304 return error;
305}
306
307
308Error
309ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid)
310{
311 Error error;
312 error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging");
313 return error;
314}
315
Greg Clayton363be3f2011-07-15 03:27:12 +0000316Error
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000317ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info)
318{
319 Error error;
320 error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging");
321 return error;
322}
323
324Error
325ProcessKDP::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info)
Greg Clayton363be3f2011-07-15 03:27:12 +0000326{
327 Error error;
328 error.SetErrorString ("attach to process by name is not suppported in kdp remote debugging");
329 return error;
330}
331
332
333void
334ProcessKDP::DidAttach ()
335{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000336 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
Greg Clayton363be3f2011-07-15 03:27:12 +0000337 if (log)
Johnny Chen01df0572011-10-11 21:17:10 +0000338 log->Printf ("ProcessKDP::DidAttach()");
Greg Clayton363be3f2011-07-15 03:27:12 +0000339 if (GetID() != LLDB_INVALID_PROCESS_ID)
340 {
341 // TODO: figure out the register context that we will use
342 }
343}
344
Jason Molendab46937c2012-10-03 01:29:34 +0000345addr_t
346ProcessKDP::GetImageInfoAddress()
347{
348 return m_kernel_load_addr;
349}
350
351lldb_private::DynamicLoader *
352ProcessKDP::GetDynamicLoader ()
353{
354 if (m_dyld_ap.get() == NULL)
355 m_dyld_ap.reset (DynamicLoader::FindPlugin(this, m_dyld_plugin_name.empty() ? NULL : m_dyld_plugin_name.c_str()));
356 return m_dyld_ap.get();
357}
358
Greg Clayton363be3f2011-07-15 03:27:12 +0000359Error
360ProcessKDP::WillResume ()
361{
362 return Error();
363}
364
365Error
366ProcessKDP::DoResume ()
367{
368 Error error;
Greg Clayton952e9dc2013-03-27 23:08:40 +0000369 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
Greg Claytone76f8c42012-09-21 16:31:20 +0000370 // Only start the async thread if we try to do any process control
371 if (!IS_VALID_LLDB_HOST_THREAD(m_async_thread))
372 StartAsyncThread ();
373
Greg Clayton3acaa922012-09-25 02:40:06 +0000374 bool resume = false;
Greg Claytone76f8c42012-09-21 16:31:20 +0000375
Greg Clayton3acaa922012-09-25 02:40:06 +0000376 // With KDP there is only one thread we can tell what to do
377 ThreadSP kernel_thread_sp (GetKernelThread(m_thread_list, m_thread_list));
378 if (kernel_thread_sp)
Greg Claytonea636012012-09-21 01:55:30 +0000379 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000380 const StateType thread_resume_state = kernel_thread_sp->GetTemporaryResumeState();
Greg Claytone76f8c42012-09-21 16:31:20 +0000381 switch (thread_resume_state)
Greg Claytonea636012012-09-21 01:55:30 +0000382 {
Greg Claytone76f8c42012-09-21 16:31:20 +0000383 case eStateSuspended:
384 // Nothing to do here when a thread will stay suspended
385 // we just leave the CPU mask bit set to zero for the thread
386 break;
387
388 case eStateStepping:
Greg Clayton4ee040c2013-04-02 20:32:37 +0000389 {
390 lldb::RegisterContextSP reg_ctx_sp (kernel_thread_sp->GetRegisterContext());
391
392 if (reg_ctx_sp)
393 {
394 reg_ctx_sp->HardwareSingleStep (true);
395 resume = true;
396 }
397 else
398 {
399 error.SetErrorStringWithFormat("KDP thread 0x%llx has no register context", kernel_thread_sp->GetID());
400 }
401 }
Greg Clayton3acaa922012-09-25 02:40:06 +0000402 break;
403
Greg Claytone76f8c42012-09-21 16:31:20 +0000404 case eStateRunning:
Greg Clayton4ee040c2013-04-02 20:32:37 +0000405 {
406 lldb::RegisterContextSP reg_ctx_sp (kernel_thread_sp->GetRegisterContext());
407
408 if (reg_ctx_sp)
409 {
410 reg_ctx_sp->HardwareSingleStep (false);
411 resume = true;
412 }
413 else
414 {
415 error.SetErrorStringWithFormat("KDP thread 0x%llx has no register context", kernel_thread_sp->GetID());
416 }
417 }
Greg Claytone76f8c42012-09-21 16:31:20 +0000418 break;
Greg Clayton3acaa922012-09-25 02:40:06 +0000419
Greg Claytone76f8c42012-09-21 16:31:20 +0000420 default:
Greg Clayton3acaa922012-09-25 02:40:06 +0000421 // The only valid thread resume states are listed above
Greg Claytone76f8c42012-09-21 16:31:20 +0000422 assert (!"invalid thread resume state");
423 break;
Greg Claytonea636012012-09-21 01:55:30 +0000424 }
425 }
Greg Clayton3acaa922012-09-25 02:40:06 +0000426
427 if (resume)
Greg Claytone76f8c42012-09-21 16:31:20 +0000428 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000429 if (log)
430 log->Printf ("ProcessKDP::DoResume () sending resume");
Greg Claytone76f8c42012-09-21 16:31:20 +0000431
Greg Clayton3acaa922012-09-25 02:40:06 +0000432 if (m_comm.SendRequestResume ())
Greg Claytone76f8c42012-09-21 16:31:20 +0000433 {
434 m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue);
435 SetPrivateState(eStateRunning);
436 }
437 else
438 error.SetErrorString ("KDP resume failed");
439 }
Greg Claytonea636012012-09-21 01:55:30 +0000440 else
Greg Claytone76f8c42012-09-21 16:31:20 +0000441 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000442 error.SetErrorString ("kernel thread is suspended");
Greg Claytone76f8c42012-09-21 16:31:20 +0000443 }
444
Greg Clayton363be3f2011-07-15 03:27:12 +0000445 return error;
446}
447
Greg Clayton3acaa922012-09-25 02:40:06 +0000448lldb::ThreadSP
449ProcessKDP::GetKernelThread(ThreadList &old_thread_list, ThreadList &new_thread_list)
450{
451 // KDP only tells us about one thread/core. Any other threads will usually
452 // be the ones that are read from memory by the OS plug-ins.
453 const lldb::tid_t kernel_tid = 1;
454 ThreadSP thread_sp (old_thread_list.FindThreadByID (kernel_tid, false));
455 if (!thread_sp)
Jim Ingham94a5d0d2012-10-10 18:32:14 +0000456 thread_sp.reset(new ThreadKDP (*this, kernel_tid));
Greg Claytona365dc52013-04-11 22:23:34 +0000457 new_thread_list.AddThread(thread_sp);
Greg Clayton3acaa922012-09-25 02:40:06 +0000458 return thread_sp;
459}
460
461
462
463
Greg Claytonae932352012-04-10 00:18:59 +0000464bool
Greg Clayton37f962e2011-08-22 02:49:39 +0000465ProcessKDP::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
Greg Clayton363be3f2011-07-15 03:27:12 +0000466{
467 // locker will keep a mutex locked until it goes out of scope
Greg Clayton952e9dc2013-03-27 23:08:40 +0000468 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_THREAD));
Greg Clayton363be3f2011-07-15 03:27:12 +0000469 if (log && log->GetMask().Test(KDP_LOG_VERBOSE))
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000470 log->Printf ("ProcessKDP::%s (pid = %" PRIu64 ")", __FUNCTION__, GetID());
Greg Clayton363be3f2011-07-15 03:27:12 +0000471
Greg Claytona365dc52013-04-11 22:23:34 +0000472 // Even though there is a CPU mask, it doesn't mean we can see each CPU
Greg Clayton3acaa922012-09-25 02:40:06 +0000473 // indivudually, there is really only one. Lets call this thread 1.
474 GetKernelThread (old_thread_list, new_thread_list);
475
Greg Claytonae932352012-04-10 00:18:59 +0000476 return new_thread_list.GetSize(false) > 0;
Greg Clayton363be3f2011-07-15 03:27:12 +0000477}
478
Greg Clayton363be3f2011-07-15 03:27:12 +0000479void
480ProcessKDP::RefreshStateAfterStop ()
481{
482 // Let all threads recover from stopping and do any clean up based
483 // on the previous thread state (if any).
484 m_thread_list.RefreshStateAfterStop();
Greg Clayton363be3f2011-07-15 03:27:12 +0000485}
486
487Error
488ProcessKDP::DoHalt (bool &caused_stop)
489{
490 Error error;
491
Greg Clayton3acaa922012-09-25 02:40:06 +0000492 if (m_comm.IsRunning())
Greg Clayton363be3f2011-07-15 03:27:12 +0000493 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000494 if (m_destroy_in_process)
Greg Clayton363be3f2011-07-15 03:27:12 +0000495 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000496 // If we are attemping to destroy, we need to not return an error to
497 // Halt or DoDestroy won't get called.
498 // We are also currently running, so send a process stopped event
499 SetPrivateState (eStateStopped);
Greg Clayton363be3f2011-07-15 03:27:12 +0000500 }
Greg Clayton3acaa922012-09-25 02:40:06 +0000501 else
Greg Clayton363be3f2011-07-15 03:27:12 +0000502 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000503 error.SetErrorString ("KDP cannot interrupt a running kernel");
Greg Clayton363be3f2011-07-15 03:27:12 +0000504 }
505 }
506 return error;
507}
508
509Error
Daniel Malea411ab472013-05-01 19:11:56 +0000510ProcessKDP::DoDetach()
Greg Clayton363be3f2011-07-15 03:27:12 +0000511{
512 Error error;
Greg Clayton952e9dc2013-03-27 23:08:40 +0000513 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Greg Clayton363be3f2011-07-15 03:27:12 +0000514 if (log)
Daniel Malea411ab472013-05-01 19:11:56 +0000515 log->Printf ("ProcessKDP::DoDetach()");
Greg Clayton363be3f2011-07-15 03:27:12 +0000516
Greg Clayton3acaa922012-09-25 02:40:06 +0000517 if (m_comm.IsRunning())
Greg Clayton363be3f2011-07-15 03:27:12 +0000518 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000519 // We are running and we can't interrupt a running kernel, so we need
520 // to just close the connection to the kernel and hope for the best
521 }
522 else
523 {
524 DisableAllBreakpointSites ();
525
526 m_thread_list.DiscardThreadPlans();
527
Daniel Malea411ab472013-05-01 19:11:56 +0000528 if (m_comm.IsConnected())
Greg Clayton8d2ea282011-07-17 20:36:25 +0000529 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000530
531 m_comm.SendRequestDisconnect();
532
533 size_t response_size = m_comm.Disconnect ();
534 if (log)
535 {
536 if (response_size)
537 log->PutCString ("ProcessKDP::DoDetach() detach packet sent successfully");
538 else
539 log->PutCString ("ProcessKDP::DoDetach() detach packet send failed");
540 }
Greg Clayton8d2ea282011-07-17 20:36:25 +0000541 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000542 }
Greg Clayton3acaa922012-09-25 02:40:06 +0000543 StopAsyncThread ();
Greg Claytondb9d6f42012-01-31 04:56:17 +0000544 m_comm.Clear();
Greg Clayton363be3f2011-07-15 03:27:12 +0000545
546 SetPrivateState (eStateDetached);
547 ResumePrivateStateThread();
548
549 //KillDebugserverProcess ();
550 return error;
551}
552
553Error
554ProcessKDP::DoDestroy ()
555{
Greg Claytone76f8c42012-09-21 16:31:20 +0000556 // For KDP there really is no difference between destroy and detach
Daniel Malea411ab472013-05-01 19:11:56 +0000557 return DoDetach();
Greg Clayton363be3f2011-07-15 03:27:12 +0000558}
559
560//------------------------------------------------------------------
561// Process Queries
562//------------------------------------------------------------------
563
564bool
565ProcessKDP::IsAlive ()
566{
567 return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited;
568}
569
570//------------------------------------------------------------------
571// Process Memory
572//------------------------------------------------------------------
573size_t
574ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error)
575{
Greg Clayton0fa51242011-07-19 03:57:15 +0000576 if (m_comm.IsConnected())
577 return m_comm.SendRequestReadMemory (addr, buf, size, error);
578 error.SetErrorString ("not connected");
Greg Clayton363be3f2011-07-15 03:27:12 +0000579 return 0;
580}
581
582size_t
583ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
584{
Greg Claytone76f8c42012-09-21 16:31:20 +0000585 if (m_comm.IsConnected())
586 return m_comm.SendRequestWriteMemory (addr, buf, size, error);
587 error.SetErrorString ("not connected");
Greg Clayton363be3f2011-07-15 03:27:12 +0000588 return 0;
589}
590
591lldb::addr_t
592ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
593{
594 error.SetErrorString ("memory allocation not suppported in kdp remote debugging");
595 return LLDB_INVALID_ADDRESS;
596}
597
598Error
599ProcessKDP::DoDeallocateMemory (lldb::addr_t addr)
600{
601 Error error;
602 error.SetErrorString ("memory deallocation not suppported in kdp remote debugging");
603 return error;
604}
605
606Error
Jim Inghamefb4aeb2013-02-15 02:06:30 +0000607ProcessKDP::EnableBreakpointSite (BreakpointSite *bp_site)
Greg Clayton363be3f2011-07-15 03:27:12 +0000608{
Greg Clayton234981a2011-07-20 03:41:06 +0000609 if (m_comm.LocalBreakpointsAreSupported ())
610 {
611 Error error;
Greg Clayton7b139222011-07-21 01:12:01 +0000612 if (!bp_site->IsEnabled())
613 {
614 if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress()))
615 {
616 bp_site->SetEnabled(true);
617 bp_site->SetType (BreakpointSite::eExternal);
618 }
619 else
620 {
621 error.SetErrorString ("KDP set breakpoint failed");
622 }
623 }
Greg Clayton234981a2011-07-20 03:41:06 +0000624 return error;
625 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000626 return EnableSoftwareBreakpoint (bp_site);
627}
628
629Error
Jim Inghamefb4aeb2013-02-15 02:06:30 +0000630ProcessKDP::DisableBreakpointSite (BreakpointSite *bp_site)
Greg Clayton363be3f2011-07-15 03:27:12 +0000631{
Greg Clayton234981a2011-07-20 03:41:06 +0000632 if (m_comm.LocalBreakpointsAreSupported ())
633 {
634 Error error;
Greg Clayton7b139222011-07-21 01:12:01 +0000635 if (bp_site->IsEnabled())
636 {
637 BreakpointSite::Type bp_type = bp_site->GetType();
638 if (bp_type == BreakpointSite::eExternal)
639 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000640 if (m_destroy_in_process && m_comm.IsRunning())
641 {
642 // We are trying to destroy our connection and we are running
Greg Clayton7b139222011-07-21 01:12:01 +0000643 bp_site->SetEnabled(false);
Greg Clayton3acaa922012-09-25 02:40:06 +0000644 }
Greg Clayton7b139222011-07-21 01:12:01 +0000645 else
Greg Clayton3acaa922012-09-25 02:40:06 +0000646 {
647 if (m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress()))
648 bp_site->SetEnabled(false);
649 else
650 error.SetErrorString ("KDP remove breakpoint failed");
651 }
Greg Clayton7b139222011-07-21 01:12:01 +0000652 }
653 else
654 {
655 error = DisableSoftwareBreakpoint (bp_site);
656 }
657 }
Greg Clayton234981a2011-07-20 03:41:06 +0000658 return error;
659 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000660 return DisableSoftwareBreakpoint (bp_site);
661}
662
663Error
Jim Ingham9c970a32012-12-18 02:03:49 +0000664ProcessKDP::EnableWatchpoint (Watchpoint *wp, bool notify)
Greg Clayton363be3f2011-07-15 03:27:12 +0000665{
666 Error error;
667 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
668 return error;
669}
670
671Error
Jim Ingham9c970a32012-12-18 02:03:49 +0000672ProcessKDP::DisableWatchpoint (Watchpoint *wp, bool notify)
Greg Clayton363be3f2011-07-15 03:27:12 +0000673{
674 Error error;
675 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
676 return error;
677}
678
679void
680ProcessKDP::Clear()
681{
Greg Clayton363be3f2011-07-15 03:27:12 +0000682 m_thread_list.Clear();
683}
684
685Error
686ProcessKDP::DoSignal (int signo)
687{
688 Error error;
689 error.SetErrorString ("sending signals is not suppported in kdp remote debugging");
690 return error;
691}
692
693void
694ProcessKDP::Initialize()
695{
696 static bool g_initialized = false;
697
698 if (g_initialized == false)
699 {
700 g_initialized = true;
701 PluginManager::RegisterPlugin (GetPluginNameStatic(),
702 GetPluginDescriptionStatic(),
703 CreateInstance);
704
705 Log::Callbacks log_callbacks = {
706 ProcessKDPLog::DisableLog,
707 ProcessKDPLog::EnableLog,
708 ProcessKDPLog::ListLogCategories
709 };
710
711 Log::RegisterLogChannel (ProcessKDP::GetPluginNameStatic(), log_callbacks);
712 }
713}
714
715bool
716ProcessKDP::StartAsyncThread ()
717{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000718 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Greg Clayton363be3f2011-07-15 03:27:12 +0000719
720 if (log)
Greg Claytone76f8c42012-09-21 16:31:20 +0000721 log->Printf ("ProcessKDP::StartAsyncThread ()");
Greg Clayton363be3f2011-07-15 03:27:12 +0000722
Greg Claytone76f8c42012-09-21 16:31:20 +0000723 if (IS_VALID_LLDB_HOST_THREAD(m_async_thread))
724 return true;
725
Greg Clayton363be3f2011-07-15 03:27:12 +0000726 m_async_thread = Host::ThreadCreate ("<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this, NULL);
727 return IS_VALID_LLDB_HOST_THREAD(m_async_thread);
728}
729
730void
731ProcessKDP::StopAsyncThread ()
732{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000733 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
Greg Clayton363be3f2011-07-15 03:27:12 +0000734
735 if (log)
Greg Claytone76f8c42012-09-21 16:31:20 +0000736 log->Printf ("ProcessKDP::StopAsyncThread ()");
Greg Clayton363be3f2011-07-15 03:27:12 +0000737
738 m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit);
739
740 // Stop the stdio thread
741 if (IS_VALID_LLDB_HOST_THREAD(m_async_thread))
742 {
743 Host::ThreadJoin (m_async_thread, NULL, NULL);
Greg Claytone76f8c42012-09-21 16:31:20 +0000744 m_async_thread = LLDB_INVALID_HOST_THREAD;
Greg Clayton363be3f2011-07-15 03:27:12 +0000745 }
746}
747
748
749void *
750ProcessKDP::AsyncThread (void *arg)
751{
752 ProcessKDP *process = (ProcessKDP*) arg;
753
Greg Claytone76f8c42012-09-21 16:31:20 +0000754 const lldb::pid_t pid = process->GetID();
755
Greg Clayton952e9dc2013-03-27 23:08:40 +0000756 Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
Greg Clayton363be3f2011-07-15 03:27:12 +0000757 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000758 log->Printf ("ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64 ") thread starting...", arg, pid);
Greg Clayton363be3f2011-07-15 03:27:12 +0000759
760 Listener listener ("ProcessKDP::AsyncThread");
761 EventSP event_sp;
762 const uint32_t desired_event_mask = eBroadcastBitAsyncContinue |
763 eBroadcastBitAsyncThreadShouldExit;
764
Greg Claytone76f8c42012-09-21 16:31:20 +0000765
Greg Clayton363be3f2011-07-15 03:27:12 +0000766 if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask)
767 {
Greg Clayton363be3f2011-07-15 03:27:12 +0000768 bool done = false;
769 while (!done)
770 {
771 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000772 log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...",
Greg Claytone76f8c42012-09-21 16:31:20 +0000773 pid);
Greg Clayton363be3f2011-07-15 03:27:12 +0000774 if (listener.WaitForEvent (NULL, event_sp))
775 {
Greg Claytone76f8c42012-09-21 16:31:20 +0000776 uint32_t event_type = event_sp->GetType();
777 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000778 log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") Got an event of type: %d...",
Greg Claytone76f8c42012-09-21 16:31:20 +0000779 pid,
780 event_type);
781
782 // When we are running, poll for 1 second to try and get an exception
783 // to indicate the process has stopped. If we don't get one, check to
784 // make sure no one asked us to exit
785 bool is_running = false;
786 DataExtractor exc_reply_packet;
787 do
Greg Clayton363be3f2011-07-15 03:27:12 +0000788 {
Greg Clayton363be3f2011-07-15 03:27:12 +0000789 switch (event_type)
790 {
Greg Claytone76f8c42012-09-21 16:31:20 +0000791 case eBroadcastBitAsyncContinue:
Greg Clayton363be3f2011-07-15 03:27:12 +0000792 {
Greg Claytone76f8c42012-09-21 16:31:20 +0000793 is_running = true;
794 if (process->m_comm.WaitForPacketWithTimeoutMicroSeconds (exc_reply_packet, 1 * USEC_PER_SEC))
Greg Clayton363be3f2011-07-15 03:27:12 +0000795 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000796 ThreadSP thread_sp (process->GetKernelThread(process->GetThreadList(), process->GetThreadList()));
Greg Clayton4ee040c2013-04-02 20:32:37 +0000797 if (thread_sp)
798 {
799 lldb::RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext());
800 if (reg_ctx_sp)
801 reg_ctx_sp->InvalidateAllRegisters();
802 static_cast<ThreadKDP *>(thread_sp.get())->SetStopInfoFrom_KDP_EXCEPTION (exc_reply_packet);
803 }
Greg Clayton3acaa922012-09-25 02:40:06 +0000804
Greg Claytone76f8c42012-09-21 16:31:20 +0000805 // TODO: parse the stop reply packet
Greg Clayton3acaa922012-09-25 02:40:06 +0000806 is_running = false;
Greg Claytone76f8c42012-09-21 16:31:20 +0000807 process->SetPrivateState(eStateStopped);
808 }
809 else
810 {
811 // Check to see if we are supposed to exit. There is no way to
812 // interrupt a running kernel, so all we can do is wait for an
813 // exception or detach...
814 if (listener.GetNextEvent(event_sp))
815 {
816 // We got an event, go through the loop again
817 event_type = event_sp->GetType();
818 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000819 }
820 }
Greg Claytone76f8c42012-09-21 16:31:20 +0000821 break;
Greg Clayton363be3f2011-07-15 03:27:12 +0000822
Greg Claytone76f8c42012-09-21 16:31:20 +0000823 case eBroadcastBitAsyncThreadShouldExit:
824 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000825 log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") got eBroadcastBitAsyncThreadShouldExit...",
Greg Claytone76f8c42012-09-21 16:31:20 +0000826 pid);
Greg Clayton363be3f2011-07-15 03:27:12 +0000827 done = true;
Greg Claytone76f8c42012-09-21 16:31:20 +0000828 is_running = false;
829 break;
830
831 default:
832 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000833 log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") got unknown event 0x%8.8x",
Greg Claytone76f8c42012-09-21 16:31:20 +0000834 pid,
835 event_type);
836 done = true;
837 is_running = false;
838 break;
Greg Clayton363be3f2011-07-15 03:27:12 +0000839 }
Greg Claytone76f8c42012-09-21 16:31:20 +0000840 } while (is_running);
Greg Clayton363be3f2011-07-15 03:27:12 +0000841 }
842 else
843 {
844 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000845 log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp) => false",
Greg Claytone76f8c42012-09-21 16:31:20 +0000846 pid);
Greg Clayton363be3f2011-07-15 03:27:12 +0000847 done = true;
848 }
849 }
850 }
851
852 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000853 log->Printf ("ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64 ") thread exiting...",
Greg Claytone76f8c42012-09-21 16:31:20 +0000854 arg,
855 pid);
Greg Clayton363be3f2011-07-15 03:27:12 +0000856
857 process->m_async_thread = LLDB_INVALID_HOST_THREAD;
858 return NULL;
859}
860
861
Greg Clayton307c7fd2012-10-19 22:22:57 +0000862class CommandObjectProcessKDPPacketSend : public CommandObjectParsed
863{
864private:
865
866 OptionGroupOptions m_option_group;
867 OptionGroupUInt64 m_command_byte;
868 OptionGroupString m_packet_data;
869
870 virtual Options *
871 GetOptions ()
872 {
873 return &m_option_group;
874 }
875
876
877public:
878 CommandObjectProcessKDPPacketSend(CommandInterpreter &interpreter) :
879 CommandObjectParsed (interpreter,
880 "process plugin packet send",
881 "Send a custom packet through the KDP protocol by specifying the command byte and the packet payload data. A packet will be sent with a correct header and payload, and the raw result bytes will be displayed as a string value. ",
882 NULL),
883 m_option_group (interpreter),
884 m_command_byte(LLDB_OPT_SET_1, true , "command", 'c', 0, eArgTypeNone, "Specify the command byte to use when sending the KDP request packet.", 0),
885 m_packet_data (LLDB_OPT_SET_1, false, "payload", 'p', 0, eArgTypeNone, "Specify packet payload bytes as a hex ASCII string with no spaces or hex prefixes.", NULL)
886 {
887 m_option_group.Append (&m_command_byte, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
888 m_option_group.Append (&m_packet_data , LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
889 m_option_group.Finalize();
890 }
891
892 ~CommandObjectProcessKDPPacketSend ()
893 {
894 }
895
896 bool
897 DoExecute (Args& command, CommandReturnObject &result)
898 {
899 const size_t argc = command.GetArgumentCount();
900 if (argc == 0)
901 {
902 if (!m_command_byte.GetOptionValue().OptionWasSet())
903 {
904 result.AppendError ("the --command option must be set to a valid command byte");
905 result.SetStatus (eReturnStatusFailed);
906 }
907 else
908 {
909 const uint64_t command_byte = m_command_byte.GetOptionValue().GetUInt64Value(0);
910 if (command_byte > 0 && command_byte <= UINT8_MAX)
911 {
912 ProcessKDP *process = (ProcessKDP *)m_interpreter.GetExecutionContext().GetProcessPtr();
913 if (process)
914 {
915 const StateType state = process->GetState();
916
917 if (StateIsStoppedState (state, true))
918 {
919 std::vector<uint8_t> payload_bytes;
920 const char *ascii_hex_bytes_cstr = m_packet_data.GetOptionValue().GetCurrentValue();
921 if (ascii_hex_bytes_cstr && ascii_hex_bytes_cstr[0])
922 {
923 StringExtractor extractor(ascii_hex_bytes_cstr);
924 const size_t ascii_hex_bytes_cstr_len = extractor.GetStringRef().size();
925 if (ascii_hex_bytes_cstr_len & 1)
926 {
927 result.AppendErrorWithFormat ("payload data must contain an even number of ASCII hex characters: '%s'", ascii_hex_bytes_cstr);
928 result.SetStatus (eReturnStatusFailed);
929 return false;
930 }
931 payload_bytes.resize(ascii_hex_bytes_cstr_len/2);
932 if (extractor.GetHexBytes(&payload_bytes[0], payload_bytes.size(), '\xdd') != payload_bytes.size())
933 {
934 result.AppendErrorWithFormat ("payload data must only contain ASCII hex characters (no spaces or hex prefixes): '%s'", ascii_hex_bytes_cstr);
935 result.SetStatus (eReturnStatusFailed);
936 return false;
937 }
938 }
939 Error error;
940 DataExtractor reply;
941 process->GetCommunication().SendRawRequest (command_byte,
942 payload_bytes.empty() ? NULL : payload_bytes.data(),
943 payload_bytes.size(),
944 reply,
945 error);
946
947 if (error.Success())
948 {
949 // Copy the binary bytes into a hex ASCII string for the result
950 StreamString packet;
951 packet.PutBytesAsRawHex8(reply.GetDataStart(),
952 reply.GetByteSize(),
953 lldb::endian::InlHostByteOrder(),
954 lldb::endian::InlHostByteOrder());
955 result.AppendMessage(packet.GetString().c_str());
956 result.SetStatus (eReturnStatusSuccessFinishResult);
957 return true;
958 }
959 else
960 {
961 const char *error_cstr = error.AsCString();
962 if (error_cstr && error_cstr[0])
963 result.AppendError (error_cstr);
964 else
965 result.AppendErrorWithFormat ("unknown error 0x%8.8x", error.GetError());
966 result.SetStatus (eReturnStatusFailed);
967 return false;
968 }
969 }
970 else
971 {
972 result.AppendErrorWithFormat ("process must be stopped in order to send KDP packets, state is %s", StateAsCString (state));
973 result.SetStatus (eReturnStatusFailed);
974 }
975 }
976 else
977 {
978 result.AppendError ("invalid process");
979 result.SetStatus (eReturnStatusFailed);
980 }
981 }
982 else
983 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000984 result.AppendErrorWithFormat ("invalid command byte 0x%" PRIx64 ", valid values are 1 - 255", command_byte);
Greg Clayton307c7fd2012-10-19 22:22:57 +0000985 result.SetStatus (eReturnStatusFailed);
986 }
987 }
988 }
989 else
990 {
991 result.AppendErrorWithFormat ("'%s' takes no arguments, only options.", m_cmd_name.c_str());
992 result.SetStatus (eReturnStatusFailed);
993 }
994 return false;
995 }
996};
997
998class CommandObjectProcessKDPPacket : public CommandObjectMultiword
999{
1000private:
1001
1002public:
1003 CommandObjectProcessKDPPacket(CommandInterpreter &interpreter) :
1004 CommandObjectMultiword (interpreter,
1005 "process plugin packet",
1006 "Commands that deal with KDP remote packets.",
1007 NULL)
1008 {
1009 LoadSubCommand ("send", CommandObjectSP (new CommandObjectProcessKDPPacketSend (interpreter)));
1010 }
1011
1012 ~CommandObjectProcessKDPPacket ()
1013 {
1014 }
1015};
1016
1017class CommandObjectMultiwordProcessKDP : public CommandObjectMultiword
1018{
1019public:
1020 CommandObjectMultiwordProcessKDP (CommandInterpreter &interpreter) :
1021 CommandObjectMultiword (interpreter,
1022 "process plugin",
1023 "A set of commands for operating on a ProcessKDP process.",
1024 "process plugin <subcommand> [<subcommand-options>]")
1025 {
1026 LoadSubCommand ("packet", CommandObjectSP (new CommandObjectProcessKDPPacket (interpreter)));
1027 }
1028
1029 ~CommandObjectMultiwordProcessKDP ()
1030 {
1031 }
1032};
1033
1034CommandObject *
1035ProcessKDP::GetPluginCommandObject()
1036{
1037 if (!m_command_sp)
1038 m_command_sp.reset (new CommandObjectMultiwordProcessKDP (GetTarget().GetDebugger().GetCommandInterpreter()));
1039 return m_command_sp.get();
1040}
1041