ProcessKDP.cpp revision 61ddf56b2526dab3f9485c87db414978cbd9e285
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
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
59ProcessKDP::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//----------------------------------------------------------------------
84ProcessKDP::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//----------------------------------------------------------------------
97ProcessKDP::~ProcessKDP()
98{
99    Clear();
100}
101
102//----------------------------------------------------------------------
103// PluginInterface
104//----------------------------------------------------------------------
105const char *
106ProcessKDP::GetPluginName()
107{
108    return "Process debugging plug-in that uses the Darwin KDP remote protocol";
109}
110
111const char *
112ProcessKDP::GetShortPluginName()
113{
114    return GetPluginNameStatic();
115}
116
117uint32_t
118ProcessKDP::GetPluginVersion()
119{
120    return 1;
121}
122
123Error
124ProcessKDP::WillLaunch (Module* module)
125{
126    Error error;
127    error.SetErrorString ("launching not supported in kdp-remote plug-in");
128    return error;
129}
130
131Error
132ProcessKDP::WillAttachToProcessWithID (lldb::pid_t pid)
133{
134    Error error;
135    error.SetErrorString ("attaching to a by process ID not supported in kdp-remote plug-in");
136    return error;
137}
138
139Error
140ProcessKDP::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
141{
142    Error error;
143    error.SetErrorString ("attaching to a by process name not supported in kdp-remote plug-in");
144    return error;
145}
146
147Error
148ProcessKDP::DoConnectRemote (const char *remote_url)
149{
150    // TODO: fill in the remote connection to the remote KDP here!
151    Error error;
152
153    if (remote_url == NULL || remote_url[0] == '\0')
154        remote_url = "udp://localhost:41139";
155
156    std::auto_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
157    if (conn_ap.get())
158    {
159        // Only try once for now.
160        // TODO: check if we should be retrying?
161        const uint32_t max_retry_count = 1;
162        for (uint32_t retry_count = 0; retry_count < max_retry_count; ++retry_count)
163        {
164            if (conn_ap->Connect(remote_url, &error) == eConnectionStatusSuccess)
165                break;
166            usleep (100000);
167        }
168    }
169
170    if (conn_ap->IsConnected())
171    {
172        const uint16_t reply_port = conn_ap->GetReadPort ();
173
174        if (reply_port != 0)
175        {
176            m_comm.SetConnection(conn_ap.release());
177
178            if (m_comm.SendRequestReattach(reply_port))
179            {
180                if (m_comm.SendRequestConnect(reply_port, reply_port, "Greetings from LLDB..."))
181                {
182                    m_comm.GetVersion();
183                    uint32_t cpu = m_comm.GetCPUType();
184                    uint32_t sub = m_comm.GetCPUSubtype();
185                    ArchSpec kernel_arch;
186                    kernel_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
187                    m_target.SetArchitecture(kernel_arch);
188                    SetID (1);
189                    GetThreadList ();
190                    SetPrivateState (eStateStopped);
191                    StreamSP async_strm_sp(m_target.GetDebugger().GetAsyncOutputStream());
192                    if (async_strm_sp)
193                    {
194                        const char *cstr;
195                        if ((cstr = m_comm.GetKernelVersion ()) != NULL)
196                        {
197                            async_strm_sp->Printf ("Version: %s\n", cstr);
198                            async_strm_sp->Flush();
199                        }
200//                      if ((cstr = m_comm.GetImagePath ()) != NULL)
201//                      {
202//                          async_strm_sp->Printf ("Image Path: %s\n", cstr);
203//                          async_strm_sp->Flush();
204//                      }
205                    }
206                }
207            }
208            else
209            {
210                error.SetErrorString("KDP reattach failed");
211            }
212        }
213        else
214        {
215            error.SetErrorString("invalid reply port from UDP connection");
216        }
217    }
218    else
219    {
220        if (error.Success())
221            error.SetErrorStringWithFormat ("failed to connect to '%s'", remote_url);
222    }
223    if (error.Fail())
224        m_comm.Disconnect();
225
226    return error;
227}
228
229//----------------------------------------------------------------------
230// Process Control
231//----------------------------------------------------------------------
232Error
233ProcessKDP::DoLaunch (Module* module,
234                      char const *argv[],
235                      char const *envp[],
236                      uint32_t launch_flags,
237                      const char *stdin_path,
238                      const char *stdout_path,
239                      const char *stderr_path,
240                      const char *working_dir)
241{
242    Error error;
243    error.SetErrorString ("launching not supported in kdp-remote plug-in");
244    return error;
245}
246
247
248Error
249ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid)
250{
251    Error error;
252    error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging");
253    return error;
254}
255
256Error
257ProcessKDP::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
258{
259    Error error;
260    error.SetErrorString ("attach to process by name is not suppported in kdp remote debugging");
261    return error;
262}
263
264
265void
266ProcessKDP::DidAttach ()
267{
268    LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
269    if (log)
270        log->Printf ("ProcessKDP::DidAttach()");
271    if (GetID() != LLDB_INVALID_PROCESS_ID)
272    {
273        // TODO: figure out the register context that we will use
274    }
275}
276
277Error
278ProcessKDP::WillResume ()
279{
280    return Error();
281}
282
283Error
284ProcessKDP::DoResume ()
285{
286    Error error;
287    if (!m_comm.SendRequestResume ())
288        error.SetErrorString ("KDP resume failed");
289    return error;
290}
291
292uint32_t
293ProcessKDP::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
294{
295    // locker will keep a mutex locked until it goes out of scope
296    LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_THREAD));
297    if (log && log->GetMask().Test(KDP_LOG_VERBOSE))
298        log->Printf ("ProcessKDP::%s (pid = %llu)", __FUNCTION__, GetID());
299
300    // We currently are making only one thread per core and we
301    // actually don't know about actual threads. Eventually we
302    // want to get the thread list from memory and note which
303    // threads are on CPU as those are the only ones that we
304    // will be able to resume.
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        lldb::tid_t tid = cpu_mask_bit;
309        ThreadSP thread_sp (old_thread_list.FindThreadByID (tid, false));
310        if (!thread_sp)
311            thread_sp.reset(new ThreadKDP (*this, tid));
312        new_thread_list.AddThread(thread_sp);
313    }
314    return new_thread_list.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    {
350        if (!m_comm.SendRequestSuspend ())
351            error.SetErrorString ("KDP halt failed");
352    }
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
456    if (m_comm.IsConnected())
457    {
458
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        }
469    }
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    {
494        if (m_public_state.GetValue() == eStateAttaching)
495        {
496            // We are being asked to halt during an attach. We need to just close
497            // our file handle and debugserver will go away, and we can be done...
498            m_comm.Disconnect();
499        }
500        else
501        {
502            DisableAllBreakpointSites ();
503
504            m_comm.SendRequestDisconnect();
505
506            StringExtractor response;
507            // TODO: Send kill packet?
508            SetExitStatus(SIGABRT, NULL);
509        }
510    }
511    StopAsyncThread ();
512    m_comm.StopReadThread();
513    m_comm.Disconnect();    // Disconnect from the debug server.
514    return error;
515}
516
517//------------------------------------------------------------------
518// Process Queries
519//------------------------------------------------------------------
520
521bool
522ProcessKDP::IsAlive ()
523{
524    return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited;
525}
526
527//------------------------------------------------------------------
528// Process Memory
529//------------------------------------------------------------------
530size_t
531ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error)
532{
533    if (m_comm.IsConnected())
534        return m_comm.SendRequestReadMemory (addr, buf, size, error);
535    error.SetErrorString ("not connected");
536    return 0;
537}
538
539size_t
540ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
541{
542    error.SetErrorString ("ProcessKDP::DoReadMemory not implemented");
543    return 0;
544}
545
546lldb::addr_t
547ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
548{
549    error.SetErrorString ("memory allocation not suppported in kdp remote debugging");
550    return LLDB_INVALID_ADDRESS;
551}
552
553Error
554ProcessKDP::DoDeallocateMemory (lldb::addr_t addr)
555{
556    Error error;
557    error.SetErrorString ("memory deallocation not suppported in kdp remote debugging");
558    return error;
559}
560
561Error
562ProcessKDP::EnableBreakpoint (BreakpointSite *bp_site)
563{
564    if (m_comm.LocalBreakpointsAreSupported ())
565    {
566        Error error;
567        if (!bp_site->IsEnabled())
568        {
569            if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress()))
570            {
571                bp_site->SetEnabled(true);
572                bp_site->SetType (BreakpointSite::eExternal);
573            }
574            else
575            {
576                error.SetErrorString ("KDP set breakpoint failed");
577            }
578        }
579        return error;
580    }
581    return EnableSoftwareBreakpoint (bp_site);
582}
583
584Error
585ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site)
586{
587    if (m_comm.LocalBreakpointsAreSupported ())
588    {
589        Error error;
590        if (bp_site->IsEnabled())
591        {
592            BreakpointSite::Type bp_type = bp_site->GetType();
593            if (bp_type == BreakpointSite::eExternal)
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            else
601            {
602                error = DisableSoftwareBreakpoint (bp_site);
603            }
604        }
605        return error;
606    }
607    return DisableSoftwareBreakpoint (bp_site);
608}
609
610Error
611ProcessKDP::EnableWatchpoint (Watchpoint *wp)
612{
613    Error error;
614    error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
615    return error;
616}
617
618Error
619ProcessKDP::DisableWatchpoint (Watchpoint *wp)
620{
621    Error error;
622    error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
623    return error;
624}
625
626void
627ProcessKDP::Clear()
628{
629    Mutex::Locker locker (m_thread_list.GetMutex ());
630    m_thread_list.Clear();
631}
632
633Error
634ProcessKDP::DoSignal (int signo)
635{
636    Error error;
637    error.SetErrorString ("sending signals is not suppported in kdp remote debugging");
638    return error;
639}
640
641void
642ProcessKDP::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
663bool
664ProcessKDP::StartAsyncThread ()
665{
666    LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
667
668    if (log)
669        log->Printf ("ProcessKDP::%s ()", __FUNCTION__);
670
671    // Create a thread that watches our internal state and controls which
672    // events make it to clients (into the DCProcess event queue).
673    m_async_thread = Host::ThreadCreate ("<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this, NULL);
674    return IS_VALID_LLDB_HOST_THREAD(m_async_thread);
675}
676
677void
678ProcessKDP::StopAsyncThread ()
679{
680    LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
681
682    if (log)
683        log->Printf ("ProcessKDP::%s ()", __FUNCTION__);
684
685    m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit);
686
687    // Stop the stdio thread
688    if (IS_VALID_LLDB_HOST_THREAD(m_async_thread))
689    {
690        Host::ThreadJoin (m_async_thread, NULL, NULL);
691    }
692}
693
694
695void *
696ProcessKDP::AsyncThread (void *arg)
697{
698    ProcessKDP *process = (ProcessKDP*) arg;
699
700    LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
701    if (log)
702        log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) thread starting...", __FUNCTION__, arg, process->GetID());
703
704    Listener listener ("ProcessKDP::AsyncThread");
705    EventSP event_sp;
706    const uint32_t desired_event_mask = eBroadcastBitAsyncContinue |
707                                        eBroadcastBitAsyncThreadShouldExit;
708
709    if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask)
710    {
711        listener.StartListeningForEvents (&process->m_comm, Communication::eBroadcastBitReadThreadDidExit);
712
713        bool done = false;
714        while (!done)
715        {
716            if (log)
717                log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID());
718            if (listener.WaitForEvent (NULL, event_sp))
719            {
720                const uint32_t event_type = event_sp->GetType();
721                if (event_sp->BroadcasterIs (&process->m_async_broadcaster))
722                {
723                    if (log)
724                        log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) Got an event of type: %d...", __FUNCTION__, arg, process->GetID(), event_type);
725
726                    switch (event_type)
727                    {
728                        case eBroadcastBitAsyncContinue:
729                        {
730                            const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event_sp.get());
731
732                            if (continue_packet)
733                            {
734                                // TODO: do continue support here
735
736//                                const char *continue_cstr = (const char *)continue_packet->GetBytes ();
737//                                const size_t continue_cstr_len = continue_packet->GetByteSize ();
738//                                if (log)
739//                                    log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr);
740//
741//                                if (::strstr (continue_cstr, "vAttach") == NULL)
742//                                    process->SetPrivateState(eStateRunning);
743//                                StringExtractor response;
744//                                StateType stop_state = process->GetCommunication().SendContinuePacketAndWaitForResponse (process, continue_cstr, continue_cstr_len, response);
745//
746//                                switch (stop_state)
747//                                {
748//                                    case eStateStopped:
749//                                    case eStateCrashed:
750//                                    case eStateSuspended:
751//                                        process->m_last_stop_packet = response;
752//                                        process->SetPrivateState (stop_state);
753//                                        break;
754//
755//                                    case eStateExited:
756//                                        process->m_last_stop_packet = response;
757//                                        response.SetFilePos(1);
758//                                        process->SetExitStatus(response.GetHexU8(), NULL);
759//                                        done = true;
760//                                        break;
761//
762//                                    case eStateInvalid:
763//                                        process->SetExitStatus(-1, "lost connection");
764//                                        break;
765//
766//                                    default:
767//                                        process->SetPrivateState (stop_state);
768//                                        break;
769//                                }
770                            }
771                        }
772                            break;
773
774                        case eBroadcastBitAsyncThreadShouldExit:
775                            if (log)
776                                log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID());
777                            done = true;
778                            break;
779
780                        default:
781                            if (log)
782                                log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type);
783                            done = true;
784                            break;
785                    }
786                }
787                else if (event_sp->BroadcasterIs (&process->m_comm))
788                {
789                    if (event_type & Communication::eBroadcastBitReadThreadDidExit)
790                    {
791                        process->SetExitStatus (-1, "lost connection");
792                        done = true;
793                    }
794                }
795            }
796            else
797            {
798                if (log)
799                    log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID());
800                done = true;
801            }
802        }
803    }
804
805    if (log)
806        log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) thread exiting...", __FUNCTION__, arg, process->GetID());
807
808    process->m_async_thread = LLDB_INVALID_HOST_THREAD;
809    return NULL;
810}
811
812
813