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