blob: 2d3a617a239daaa45c88b6146b54c514cf7b5236 [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"
19#include "lldb/Core/State.h"
20#include "lldb/Host/Host.h"
Greg Clayton1e5b0212011-07-15 16:31:38 +000021#include "lldb/Target/Target.h"
Greg Clayton0fa51242011-07-19 03:57:15 +000022#include "lldb/Target/Thread.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000023
24// Project includes
25#include "ProcessKDP.h"
26#include "ProcessKDPLog.h"
Greg Clayton0fa51242011-07-19 03:57:15 +000027#include "ThreadKDP.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000028#include "StopInfoMachException.h"
29
30using namespace lldb;
31using namespace lldb_private;
32
33const char *
34ProcessKDP::GetPluginNameStatic()
35{
36 return "kdp-remote";
37}
38
39const char *
40ProcessKDP::GetPluginDescriptionStatic()
41{
42 return "KDP Remote protocol based debugging plug-in for darwin kernel debugging.";
43}
44
45void
46ProcessKDP::Terminate()
47{
48 PluginManager::UnregisterPlugin (ProcessKDP::CreateInstance);
49}
50
51
52Process*
53ProcessKDP::CreateInstance (Target &target, Listener &listener)
54{
55 return new ProcessKDP (target, listener);
56}
57
58bool
Greg Clayton8d2ea282011-07-17 20:36:25 +000059ProcessKDP::CanDebug(Target &target, bool plugin_specified_by_name)
Greg Clayton363be3f2011-07-15 03:27:12 +000060{
61 // For now we are just making sure the file exists for a given module
62 ModuleSP exe_module_sp(target.GetExecutableModule());
63 if (exe_module_sp.get())
64 {
65 const llvm::Triple &triple_ref = target.GetArchitecture().GetTriple();
66 if (triple_ref.getOS() == llvm::Triple::Darwin &&
67 triple_ref.getVendor() == llvm::Triple::Apple)
68 {
Greg Clayton363be3f2011-07-15 03:27:12 +000069 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile();
70 if (exe_objfile->GetType() == ObjectFile::eTypeExecutable &&
71 exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
72 return true;
73 }
Greg Clayton8d2ea282011-07-17 20:36:25 +000074 return false;
Greg Clayton363be3f2011-07-15 03:27:12 +000075 }
Greg Clayton8d2ea282011-07-17 20:36:25 +000076 // No target executable, assume we can debug if our plug-in was specified by name
77 return plugin_specified_by_name;
Greg Clayton363be3f2011-07-15 03:27:12 +000078}
79
80//----------------------------------------------------------------------
81// ProcessKDP constructor
82//----------------------------------------------------------------------
83ProcessKDP::ProcessKDP(Target& target, Listener &listener) :
84 Process (target, listener),
85 m_comm("lldb.process.kdp-remote.communication"),
86 m_async_broadcaster ("lldb.process.kdp-remote.async-broadcaster"),
87 m_async_thread (LLDB_INVALID_HOST_THREAD)
88{
89// m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit");
90// m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue");
91}
92
93//----------------------------------------------------------------------
94// Destructor
95//----------------------------------------------------------------------
96ProcessKDP::~ProcessKDP()
97{
98 Clear();
99}
100
101//----------------------------------------------------------------------
102// PluginInterface
103//----------------------------------------------------------------------
104const char *
105ProcessKDP::GetPluginName()
106{
107 return "Process debugging plug-in that uses the Darwin KDP remote protocol";
108}
109
110const char *
111ProcessKDP::GetShortPluginName()
112{
113 return GetPluginNameStatic();
114}
115
116uint32_t
117ProcessKDP::GetPluginVersion()
118{
119 return 1;
120}
121
122Error
123ProcessKDP::WillLaunch (Module* module)
124{
125 Error error;
126 error.SetErrorString ("launching not supported in kdp-remote plug-in");
127 return error;
128}
129
130Error
131ProcessKDP::WillAttachToProcessWithID (lldb::pid_t pid)
132{
133 Error error;
134 error.SetErrorString ("attaching to a by process ID not supported in kdp-remote plug-in");
135 return error;
136}
137
138Error
139ProcessKDP::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
140{
141 Error error;
142 error.SetErrorString ("attaching to a by process name not supported in kdp-remote plug-in");
143 return error;
144}
145
146Error
147ProcessKDP::DoConnectRemote (const char *remote_url)
148{
149 // TODO: fill in the remote connection to the remote KDP here!
150 Error error;
Greg Clayton8d2ea282011-07-17 20:36:25 +0000151
152 if (remote_url == NULL || remote_url[0] == '\0')
153 remote_url = "udp://localhost:41139";
154
155 std::auto_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
156 if (conn_ap.get())
157 {
158 // Only try once for now.
159 // TODO: check if we should be retrying?
160 const uint32_t max_retry_count = 1;
161 for (uint32_t retry_count = 0; retry_count < max_retry_count; ++retry_count)
162 {
163 if (conn_ap->Connect(remote_url, &error) == eConnectionStatusSuccess)
164 break;
165 usleep (100000);
166 }
167 }
168
169 if (conn_ap->IsConnected())
170 {
171 const uint16_t reply_port = conn_ap->GetReadPort ();
172
173 if (reply_port != 0)
174 {
175 m_comm.SetConnection(conn_ap.release());
176
177 if (m_comm.SendRequestReattach(reply_port))
178 {
179 if (m_comm.SendRequestConnect(reply_port, reply_port, "Greetings from LLDB..."))
180 {
181 m_comm.GetVersion();
182 uint32_t cpu = m_comm.GetCPUType();
183 uint32_t sub = m_comm.GetCPUSubtype();
184 ArchSpec kernel_arch;
185 kernel_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
186 m_target.SetArchitecture(kernel_arch);
Greg Clayton0fa51242011-07-19 03:57:15 +0000187 SetID (1);
188 UpdateThreadListIfNeeded ();
189 SetPrivateState (eStateStopped);
Greg Clayton234981a2011-07-20 03:41:06 +0000190 StreamSP async_strm_sp(m_target.GetDebugger().GetAsyncOutputStream());
191 if (async_strm_sp)
192 {
193 const char *kernel_version = m_comm.GetKernelVersion ();
194 if (kernel_version)
195 {
196 async_strm_sp->Printf ("KDP connected to %s\n", kernel_version);
197 async_strm_sp->Flush();
198 }
199 }
Greg Clayton8d2ea282011-07-17 20:36:25 +0000200 }
201 }
202 else
203 {
204 error.SetErrorString("KDP reattach failed");
205 }
206 }
207 else
208 {
209 error.SetErrorString("invalid reply port from UDP connection");
210 }
211 }
212 else
213 {
214 if (error.Success())
215 error.SetErrorStringWithFormat ("failed to connect to '%s'", remote_url);
216 }
217 if (error.Fail())
218 m_comm.Disconnect();
219
Greg Clayton363be3f2011-07-15 03:27:12 +0000220 return error;
221}
222
223//----------------------------------------------------------------------
224// Process Control
225//----------------------------------------------------------------------
226Error
227ProcessKDP::DoLaunch (Module* module,
228 char const *argv[],
229 char const *envp[],
230 uint32_t launch_flags,
231 const char *stdin_path,
232 const char *stdout_path,
233 const char *stderr_path,
234 const char *working_dir)
235{
236 Error error;
237 error.SetErrorString ("launching not supported in kdp-remote plug-in");
238 return error;
239}
240
241
242Error
243ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid)
244{
245 Error error;
246 error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging");
247 return error;
248}
249
Greg Clayton363be3f2011-07-15 03:27:12 +0000250Error
251ProcessKDP::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
252{
253 Error error;
254 error.SetErrorString ("attach to process by name is not suppported in kdp remote debugging");
255 return error;
256}
257
258
259void
260ProcessKDP::DidAttach ()
261{
262 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
263 if (log)
264 log->Printf ("ProcessKDP::DidLaunch()");
265 if (GetID() != LLDB_INVALID_PROCESS_ID)
266 {
267 // TODO: figure out the register context that we will use
268 }
269}
270
271Error
272ProcessKDP::WillResume ()
273{
274 return Error();
275}
276
277Error
278ProcessKDP::DoResume ()
279{
280 Error error;
Greg Clayton234981a2011-07-20 03:41:06 +0000281 if (!m_comm.SendRequestResume ())
282 error.SetErrorString ("KDP resume failed");
Greg Clayton363be3f2011-07-15 03:27:12 +0000283 return error;
284}
285
286uint32_t
287ProcessKDP::UpdateThreadListIfNeeded ()
288{
289 // locker will keep a mutex locked until it goes out of scope
290 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_THREAD));
291 if (log && log->GetMask().Test(KDP_LOG_VERBOSE))
292 log->Printf ("ProcessKDP::%s (pid = %i)", __FUNCTION__, GetID());
293
294 Mutex::Locker locker (m_thread_list.GetMutex ());
Greg Clayton363be3f2011-07-15 03:27:12 +0000295 const uint32_t stop_id = GetStopID();
Greg Clayton0fa51242011-07-19 03:57:15 +0000296 if (m_thread_list.GetSize(false) == 0)
Greg Clayton363be3f2011-07-15 03:27:12 +0000297 {
Greg Clayton0fa51242011-07-19 03:57:15 +0000298 // We currently are making only one thread per core and we
299 // actually don't know about actual threads. Eventually we
300 // want to get the thread list from memory and note which
301 // threads are on CPU as those are the only ones that we
302 // will be able to resume.
303 ThreadList curr_thread_list (this);
304 curr_thread_list.SetStopID(stop_id);
305 const uint32_t cpu_mask = m_comm.GetCPUMask();
306 for (uint32_t cpu_mask_bit = 1; cpu_mask_bit & cpu_mask; cpu_mask_bit <<= 1)
307 {
308 // The thread ID is currently the CPU mask bit
309 ThreadSP thread_sp (new ThreadKDP (*this, cpu_mask_bit));
310 curr_thread_list.AddThread(thread_sp);
311 }
312 m_thread_list = curr_thread_list;
Greg Clayton363be3f2011-07-15 03:27:12 +0000313 }
314 return GetThreadList().GetSize(false);
315}
316
317
318StateType
319ProcessKDP::SetThreadStopInfo (StringExtractor& stop_packet)
320{
321 // TODO: figure out why we stopped given the packet that tells us we stopped...
322 return eStateStopped;
323}
324
325void
326ProcessKDP::RefreshStateAfterStop ()
327{
328 // Let all threads recover from stopping and do any clean up based
329 // on the previous thread state (if any).
330 m_thread_list.RefreshStateAfterStop();
331 //SetThreadStopInfo (m_last_stop_packet);
332}
333
334Error
335ProcessKDP::DoHalt (bool &caused_stop)
336{
337 Error error;
338
339// bool timed_out = false;
340 Mutex::Locker locker;
341
342 if (m_public_state.GetValue() == eStateAttaching)
343 {
344 // We are being asked to halt during an attach. We need to just close
345 // our file handle and debugserver will go away, and we can be done...
346 m_comm.Disconnect();
347 }
348 else
349 {
Greg Clayton234981a2011-07-20 03:41:06 +0000350 if (!m_comm.SendRequestSuspend ())
351 error.SetErrorString ("KDP halt failed");
Greg Clayton363be3f2011-07-15 03:27:12 +0000352 }
353 return error;
354}
355
356Error
357ProcessKDP::InterruptIfRunning (bool discard_thread_plans,
358 bool catch_stop_event,
359 EventSP &stop_event_sp)
360{
361 Error error;
362
363 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
364
365 bool paused_private_state_thread = false;
366 const bool is_running = m_comm.IsRunning();
367 if (log)
368 log->Printf ("ProcessKDP::InterruptIfRunning(discard_thread_plans=%i, catch_stop_event=%i) is_running=%i",
369 discard_thread_plans,
370 catch_stop_event,
371 is_running);
372
373 if (discard_thread_plans)
374 {
375 if (log)
376 log->Printf ("ProcessKDP::InterruptIfRunning() discarding all thread plans");
377 m_thread_list.DiscardThreadPlans();
378 }
379 if (is_running)
380 {
381 if (catch_stop_event)
382 {
383 if (log)
384 log->Printf ("ProcessKDP::InterruptIfRunning() pausing private state thread");
385 PausePrivateStateThread();
386 paused_private_state_thread = true;
387 }
388
389 bool timed_out = false;
390// bool sent_interrupt = false;
391 Mutex::Locker locker;
392
393 // TODO: implement halt in CommunicationKDP
394// if (!m_comm.SendInterrupt (locker, 1, sent_interrupt, timed_out))
395// {
396// if (timed_out)
397// error.SetErrorString("timed out sending interrupt packet");
398// else
399// error.SetErrorString("unknown error sending interrupt packet");
400// if (paused_private_state_thread)
401// ResumePrivateStateThread();
402// return error;
403// }
404
405 if (catch_stop_event)
406 {
407 // LISTEN HERE
408 TimeValue timeout_time;
409 timeout_time = TimeValue::Now();
410 timeout_time.OffsetWithSeconds(5);
411 StateType state = WaitForStateChangedEventsPrivate (&timeout_time, stop_event_sp);
412
413 timed_out = state == eStateInvalid;
414 if (log)
415 log->Printf ("ProcessKDP::InterruptIfRunning() catch stop event: state = %s, timed-out=%i", StateAsCString(state), timed_out);
416
417 if (timed_out)
418 error.SetErrorString("unable to verify target stopped");
419 }
420
421 if (paused_private_state_thread)
422 {
423 if (log)
424 log->Printf ("ProcessKDP::InterruptIfRunning() resuming private state thread");
425 ResumePrivateStateThread();
426 }
427 }
428 return error;
429}
430
431Error
432ProcessKDP::WillDetach ()
433{
434 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
435 if (log)
436 log->Printf ("ProcessKDP::WillDetach()");
437
438 bool discard_thread_plans = true;
439 bool catch_stop_event = true;
440 EventSP event_sp;
441 return InterruptIfRunning (discard_thread_plans, catch_stop_event, event_sp);
442}
443
444Error
445ProcessKDP::DoDetach()
446{
447 Error error;
448 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
449 if (log)
450 log->Printf ("ProcessKDP::DoDetach()");
451
452 DisableAllBreakpointSites ();
453
454 m_thread_list.DiscardThreadPlans();
455
Greg Clayton8d2ea282011-07-17 20:36:25 +0000456 if (m_comm.IsConnected())
Greg Clayton363be3f2011-07-15 03:27:12 +0000457 {
Greg Clayton8d2ea282011-07-17 20:36:25 +0000458
459 m_comm.SendRequestDisconnect();
460
461 size_t response_size = m_comm.Disconnect ();
462 if (log)
463 {
464 if (response_size)
465 log->PutCString ("ProcessKDP::DoDetach() detach packet sent successfully");
466 else
467 log->PutCString ("ProcessKDP::DoDetach() detach packet send failed");
468 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000469 }
470 // Sleep for one second to let the process get all detached...
471 StopAsyncThread ();
472
473 m_comm.StopReadThread();
474 m_comm.Disconnect(); // Disconnect from the debug server.
475
476 SetPrivateState (eStateDetached);
477 ResumePrivateStateThread();
478
479 //KillDebugserverProcess ();
480 return error;
481}
482
483Error
484ProcessKDP::DoDestroy ()
485{
486 Error error;
487 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
488 if (log)
489 log->Printf ("ProcessKDP::DoDestroy()");
490
491 // Interrupt if our inferior is running...
492 if (m_comm.IsConnected())
493 {
Greg Clayton8d2ea282011-07-17 20:36:25 +0000494 m_comm.SendRequestDisconnect();
495
Greg Clayton363be3f2011-07-15 03:27:12 +0000496 if (m_public_state.GetValue() == eStateAttaching)
497 {
498 // We are being asked to halt during an attach. We need to just close
499 // our file handle and debugserver will go away, and we can be done...
500 m_comm.Disconnect();
501 }
502 else
503 {
504
505 StringExtractor response;
506 // TODO: Send kill packet?
507 SetExitStatus(SIGABRT, NULL);
508 }
509 }
510 StopAsyncThread ();
511 m_comm.StopReadThread();
512 m_comm.Disconnect(); // Disconnect from the debug server.
513 return error;
514}
515
516//------------------------------------------------------------------
517// Process Queries
518//------------------------------------------------------------------
519
520bool
521ProcessKDP::IsAlive ()
522{
523 return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited;
524}
525
526//------------------------------------------------------------------
527// Process Memory
528//------------------------------------------------------------------
529size_t
530ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error)
531{
Greg Clayton0fa51242011-07-19 03:57:15 +0000532 if (m_comm.IsConnected())
533 return m_comm.SendRequestReadMemory (addr, buf, size, error);
534 error.SetErrorString ("not connected");
Greg Clayton363be3f2011-07-15 03:27:12 +0000535 return 0;
536}
537
538size_t
539ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
540{
541 error.SetErrorString ("ProcessKDP::DoReadMemory not implemented");
542 return 0;
543}
544
545lldb::addr_t
546ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
547{
548 error.SetErrorString ("memory allocation not suppported in kdp remote debugging");
549 return LLDB_INVALID_ADDRESS;
550}
551
552Error
553ProcessKDP::DoDeallocateMemory (lldb::addr_t addr)
554{
555 Error error;
556 error.SetErrorString ("memory deallocation not suppported in kdp remote debugging");
557 return error;
558}
559
560Error
561ProcessKDP::EnableBreakpoint (BreakpointSite *bp_site)
562{
Greg Clayton234981a2011-07-20 03:41:06 +0000563 if (m_comm.LocalBreakpointsAreSupported ())
564 {
565 Error error;
566 if (!m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress()))
567 error.SetErrorString ("KDP set breakpoint failed");
568 return error;
569 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000570 return EnableSoftwareBreakpoint (bp_site);
571}
572
573Error
574ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site)
575{
Greg Clayton234981a2011-07-20 03:41:06 +0000576 if (m_comm.LocalBreakpointsAreSupported ())
577 {
578 Error error;
579 if (!m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress()))
580 error.SetErrorString ("KDP remove breakpoint failed");
581 return error;
582 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000583 return DisableSoftwareBreakpoint (bp_site);
584}
585
586Error
587ProcessKDP::EnableWatchpoint (WatchpointLocation *wp)
588{
589 Error error;
590 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
591 return error;
592}
593
594Error
595ProcessKDP::DisableWatchpoint (WatchpointLocation *wp)
596{
597 Error error;
598 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
599 return error;
600}
601
602void
603ProcessKDP::Clear()
604{
605 Mutex::Locker locker (m_thread_list.GetMutex ());
606 m_thread_list.Clear();
607}
608
609Error
610ProcessKDP::DoSignal (int signo)
611{
612 Error error;
613 error.SetErrorString ("sending signals is not suppported in kdp remote debugging");
614 return error;
615}
616
617void
618ProcessKDP::Initialize()
619{
620 static bool g_initialized = false;
621
622 if (g_initialized == false)
623 {
624 g_initialized = true;
625 PluginManager::RegisterPlugin (GetPluginNameStatic(),
626 GetPluginDescriptionStatic(),
627 CreateInstance);
628
629 Log::Callbacks log_callbacks = {
630 ProcessKDPLog::DisableLog,
631 ProcessKDPLog::EnableLog,
632 ProcessKDPLog::ListLogCategories
633 };
634
635 Log::RegisterLogChannel (ProcessKDP::GetPluginNameStatic(), log_callbacks);
636 }
637}
638
639bool
640ProcessKDP::StartAsyncThread ()
641{
642 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
643
644 if (log)
645 log->Printf ("ProcessKDP::%s ()", __FUNCTION__);
646
647 // Create a thread that watches our internal state and controls which
648 // events make it to clients (into the DCProcess event queue).
649 m_async_thread = Host::ThreadCreate ("<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this, NULL);
650 return IS_VALID_LLDB_HOST_THREAD(m_async_thread);
651}
652
653void
654ProcessKDP::StopAsyncThread ()
655{
656 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
657
658 if (log)
659 log->Printf ("ProcessKDP::%s ()", __FUNCTION__);
660
661 m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit);
662
663 // Stop the stdio thread
664 if (IS_VALID_LLDB_HOST_THREAD(m_async_thread))
665 {
666 Host::ThreadJoin (m_async_thread, NULL, NULL);
667 }
668}
669
670
671void *
672ProcessKDP::AsyncThread (void *arg)
673{
674 ProcessKDP *process = (ProcessKDP*) arg;
675
676 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
677 if (log)
678 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, arg, process->GetID());
679
680 Listener listener ("ProcessKDP::AsyncThread");
681 EventSP event_sp;
682 const uint32_t desired_event_mask = eBroadcastBitAsyncContinue |
683 eBroadcastBitAsyncThreadShouldExit;
684
685 if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask)
686 {
687 listener.StartListeningForEvents (&process->m_comm, Communication::eBroadcastBitReadThreadDidExit);
688
689 bool done = false;
690 while (!done)
691 {
692 if (log)
693 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID());
694 if (listener.WaitForEvent (NULL, event_sp))
695 {
696 const uint32_t event_type = event_sp->GetType();
697 if (event_sp->BroadcasterIs (&process->m_async_broadcaster))
698 {
699 if (log)
700 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) Got an event of type: %d...", __FUNCTION__, arg, process->GetID(), event_type);
701
702 switch (event_type)
703 {
704 case eBroadcastBitAsyncContinue:
705 {
706 const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event_sp.get());
707
708 if (continue_packet)
709 {
710 // TODO: do continue support here
711
712// const char *continue_cstr = (const char *)continue_packet->GetBytes ();
713// const size_t continue_cstr_len = continue_packet->GetByteSize ();
714// if (log)
715// log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr);
716//
717// if (::strstr (continue_cstr, "vAttach") == NULL)
718// process->SetPrivateState(eStateRunning);
719// StringExtractor response;
720// StateType stop_state = process->GetCommunication().SendContinuePacketAndWaitForResponse (process, continue_cstr, continue_cstr_len, response);
721//
722// switch (stop_state)
723// {
724// case eStateStopped:
725// case eStateCrashed:
726// case eStateSuspended:
727// process->m_last_stop_packet = response;
728// process->SetPrivateState (stop_state);
729// break;
730//
731// case eStateExited:
732// process->m_last_stop_packet = response;
733// response.SetFilePos(1);
734// process->SetExitStatus(response.GetHexU8(), NULL);
735// done = true;
736// break;
737//
738// case eStateInvalid:
739// process->SetExitStatus(-1, "lost connection");
740// break;
741//
742// default:
743// process->SetPrivateState (stop_state);
744// break;
745// }
746 }
747 }
748 break;
749
750 case eBroadcastBitAsyncThreadShouldExit:
751 if (log)
752 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID());
753 done = true;
754 break;
755
756 default:
757 if (log)
758 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type);
759 done = true;
760 break;
761 }
762 }
763 else if (event_sp->BroadcasterIs (&process->m_comm))
764 {
765 if (event_type & Communication::eBroadcastBitReadThreadDidExit)
766 {
767 process->SetExitStatus (-1, "lost connection");
768 done = true;
769 }
770 }
771 }
772 else
773 {
774 if (log)
775 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID());
776 done = true;
777 }
778 }
779 }
780
781 if (log)
782 log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID());
783
784 process->m_async_thread = LLDB_INVALID_HOST_THREAD;
785 return NULL;
786}
787
788