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